prefix . 'accessibility_checker'; $post_id = (int) $post_id; $siteid = get_current_blog_id(); $results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, rule, ignre, object, ruletype FROM %i where postid = %d and siteid = %d', $table_name, $post_id, $siteid ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name. if ( ! $results ) { return null; } return Helpers::filter_results_to_only_active_rules( $results ); } /** * AJAX handler function for frontend highlighting requests. */ public function ajax() { // nonce security. if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) { $error = new \WP_Error( '-1', 'Permission Denied' ); wp_send_json_error( $error ); } if ( ! isset( $_REQUEST['post_id'] ) ) { $error = new \WP_Error( '-2', 'The id value was not set' ); wp_send_json_error( $error ); } $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; $results = $this->get_issues( $post_id ); if ( ! $results ) { $error = new \WP_Error( '-3', 'Issue query returned no results' ); wp_send_json_error( $error ); } $rules = edac_register_rules(); $issues = []; $fixes = []; foreach ( $results as $result ) { $array = []; $rule = edac_filter_by_value( $rules, 'slug', $result['rule'] ); // When rules are filtered out, they are not in the rules array and this can be empty. Skip when the rule // is empty to avoid php warnings and passing null values to the frontend highlighter. if ( ! $rule ) { continue; } $rule_type = ( true === (bool) $result['ignre'] ) ? 'ignored' : $rule[0]['rule_type']; $array['rule_type'] = $rule_type; $array['slug'] = $rule[0]['slug']; $array['rule_title'] = $rule[0]['title']; $array['summary'] = $rule[0]['summary']; $array['link'] = edac_documentation_link( $rule[0] ); $array['object'] = html_entity_decode( esc_html( $result['object'] ) ); $array['id'] = $result['id']; $array['ignored'] = $result['ignre']; $issues[] = $array; if ( ! isset( $fixes[ $rule[0]['slug'] ] ) ) { $fixes_for_rule = $rule[0]['fixes'] ?? []; foreach ( $fixes_for_rule as $fix_for_rule ) { $fix = FixesManager::get_instance()->get_fix( $fix_for_rule ); if ( $fix && method_exists( $fix, 'get_fields_array' ) ) { $fixes[ $rule[0]['slug'] ] = isset( $fixes[ $rule[0]['slug'] ] ) ? array_merge( $fixes[ $rule[0]['slug'] ], $fix->get_fields_array() ) : $fix->get_fields_array(); } } } } if ( ! $issues ) { $error = new \WP_Error( '-5', 'Object query returned no results' ); wp_send_json_error( $error ); } // if we have fixes then create fields for each of the groups. if ( ! empty( $fixes ) ) { foreach ( $fixes as $key => $fix ) { // count the number of fields in the fix. $fields_count = count( $fix ); $itteration = 0; foreach ( $fix as $index => $field ) { ++$itteration; $field_type = $field['type'] ?? 'checkbox'; ob_start(); if ( isset( $field['group_name'] ) ) { // if this is anything other than the first field in the group then close the fieldset. if ( 1 !== $itteration ) { ?>
'; } } wp_send_json_success( wp_json_encode( [ 'issues' => $issues, 'fixes' => $fixes, ] ) ); } }