Skip to content

Commit

Permalink
added - phpcs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveJonesDev committed Nov 29, 2023
1 parent 8c70a95 commit 963f545
Show file tree
Hide file tree
Showing 62 changed files with 990 additions and 992 deletions.
33 changes: 16 additions & 17 deletions accessibility-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
require_once plugin_dir_path( __FILE__ ) . 'includes/classes/class-playground-check.php';
$plugin_check = new EDAC\Playground_Check();
if ( ! $plugin_check->should_load ) {
return;
return;
}

// Include plugin dependency.
Expand Down Expand Up @@ -142,7 +142,7 @@
}
if ( ! class_exists( 'simple_html_dom' ) ) {
include_once plugin_dir_path( __FILE__ ) . 'includes/simplehtmldom/simple_html_dom.php';
include_once plugin_dir_path( __FILE__ ) . 'includes/classes/class_edac_dom.php';
include_once plugin_dir_path( __FILE__ ) . 'includes/classes/class-edac-dom.php';
}

require_once plugin_dir_path( __FILE__ ) . 'includes/classes/class-edac-frontend-highlight.php';
Expand Down Expand Up @@ -227,7 +227,7 @@ function edac_update_database() {
$table_name = $wpdb->prefix . 'accessibility_checker';

$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Prepare above, Safe variable used for table name, caching not required for one time operation.
if ( get_option( 'edac_db_version' ) !== EDAC_DB_VERSION || $wpdb->get_var( $query ) !== $table_name ) {

$charset_collate = $wpdb->get_charset_collate();
Expand Down Expand Up @@ -645,7 +645,6 @@ function edac_register_rules() {
'slug' => 'color_contrast_failure',
'rule_type' => 'error',
'summary' => esc_html( 'Insufficient Color Contrast errors means that we have identified that one or more of the color combinations on your post or page do not meet the minimum color contrast ratio of 4.5:1. Depending upon how your site is built there may be "false positives" for this error as some colors are contained in different HTML layers on the page. To fix an Insufficient Color Contrast error, you will need to ensure that flagged elements meet the minimum required ratio of 4.5:1. To do so, you will need to find the hexadecimal codes of your foreground and background color, and test them in a color contrast checker. If these color codes have a ratio of 4.5:1 or greater you can “Ignore” this error. If the color codes do not have a ratio of at least 4.5:1, you will need to make adjustments to your colors.' ),
// 'ruleset' => 'js',
)
);

Expand Down Expand Up @@ -958,7 +957,7 @@ function edac_summary( $post_id ) {
$postid = $post_id;
$siteid = get_current_blog_id();

// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$rule_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM {$table_name} where rule = %s and siteid = %d and postid = %d and ignre = %d", $rule['slug'], $siteid, $postid, 0 ) );

if ( ! $rule_count ) {
Expand All @@ -971,7 +970,7 @@ function edac_summary( $post_id ) {

// count errors.
$query = 'SELECT count(*) FROM ' . $table_name . ' where siteid = %d and postid = %d and ruletype = %s and ignre = %d';
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$summary['errors'] = intval( $wpdb->get_var( $wpdb->prepare( $query, get_current_blog_id(), $post_id, 'error', 0 ) ) );

// count warnings.
Expand All @@ -982,7 +981,7 @@ function edac_summary( $post_id ) {
$warnings_where .= ' and rule != %s';
}
$query = 'SELECT count(*) FROM ' . $table_name . ' ' . $warnings_where;
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$summary['warnings'] = intval( $wpdb->get_var( $wpdb->prepare( $query, $warnings_parameters ) ) );

// count ignored issues.
Expand All @@ -993,12 +992,12 @@ function edac_summary( $post_id ) {
$ignored_where .= ' and rule != %s';
}
$query = 'SELECT count(*) FROM ' . $table_name . ' ' . $ignored_where;
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$summary['ignored'] = intval( $wpdb->get_var( $wpdb->prepare( $query, $ignored_parameters ) ) );

// contrast errors.
$query = 'SELECT count(*) FROM ' . $table_name . ' where siteid = %d and postid = %d and rule = %s and ignre = %d';
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$summary['contrast_errors'] = intval( $wpdb->get_var( $wpdb->prepare( $query, get_current_blog_id(), $post_id, 'color_contrast_failure', 0 ) ) );

// remove color contrast from errors count.
Expand Down Expand Up @@ -1107,6 +1106,7 @@ function edac_update_post_meta( $rule ) {
global $wpdb;
$site_id = get_current_blog_id();

// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$posts = $wpdb->get_results( $wpdb->prepare( 'SELECT postid FROM ' . $wpdb->prefix . 'accessibility_checker WHERE rule = %s and siteid = %d', $rule, $site_id ), ARRAY_A );

if ( $posts ) {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ function edac_details_ajax() {
// add count, unset passed error rules and add passed rules to array.
if ( $error_rules ) {
foreach ( $error_rules as $key => $error_rule ) {
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$count = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment FROM ' . $table_name . ' where postid = %d and rule = %s and siteid = %d and ignre = %d', $postid, $error_rule['slug'], $siteid, 0 ), ARRAY_A ) );
if ( $count ) {
$error_rules[ $key ]['count'] = $count;
Expand All @@ -1205,7 +1205,7 @@ function edac_details_ajax() {
// add count, unset passed warning rules and add passed rules to array.
if ( $warning_rules ) {
foreach ( $warning_rules as $key => $error_rule ) {
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$count = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment FROM ' . $table_name . ' where postid = %d and rule = %s and siteid = %d and ignre = %d', $postid, $error_rule['slug'], $siteid, 0 ), ARRAY_A ) );
if ( $count ) {
$warning_rules[ $key ]['count'] = $count;
Expand Down Expand Up @@ -1256,7 +1256,7 @@ function ( $a, $b ) {
$ignore_permission = apply_filters( 'edac_ignore_permission', $ignore_permission );
}
foreach ( $rules as $rule ) {
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment, ignre_global FROM ' . $table_name . ' where postid = %d and rule = %s and siteid = %d', $postid, $rule['slug'], $siteid ), ARRAY_A );
$count_classes = ( 'error' === $rule['rule_type'] ) ? ' edac-details-rule-count-error' : ' edac-details-rule-count-warning';
$count_classes .= ( 0 !== $rule['count'] ) ? ' active' : '';
Expand All @@ -1271,7 +1271,7 @@ function ( $a, $b ) {
}
}

// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
$expand_rule = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM ' . $table_name . ' where postid = %d and rule = %s and siteid = %d', $postid, $rule['slug'], $siteid ), ARRAY_A ) );

$tool_tip_link = edac_documentation_link( $rule );
Expand Down Expand Up @@ -1417,7 +1417,6 @@ function ( $a, $b ) {
}

$html .= '</div>';

}
}

Expand Down Expand Up @@ -1459,7 +1458,7 @@ function edac_readability_ajax() {

$post_id = intval( $_REQUEST['post_id'] );
$html = '';
$simplified_summary = get_post_meta( $post_id, '_edac_simplified_summary', true ) ?: '';
$simplified_summary = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
$simplified_summary_position = get_option( 'edac_simplified_summary_position', $default = false );
$content_post = get_post( $post_id );
$content = $content_post->post_content;
Expand Down Expand Up @@ -1671,7 +1670,7 @@ function edac_get_simplified_summary( $post = null ) {
* @return string
*/
function edac_simplified_summary_markup( $post ) {
$simplified_summary = get_post_meta( $post, '_edac_simplified_summary', true ) ?: '';
$simplified_summary = get_post_meta( $post, '_edac_simplified_summary', true ) ? get_post_meta( $post, '_edac_simplified_summary', true ) : '';
$simplified_summary_heading = 'Simplified Summary';

// filter title.
Expand Down Expand Up @@ -1764,7 +1763,7 @@ function edac_email_opt_in() {
add_filter(
'perfmatters_lazyload',
function ( $lazyload ) {
if ( ! isset( $_GET['edac_nonce'] ) || ! wp_verify_nonce( $_GET['edac_nonce'], 'edac_highlight' ) ) {
if ( ! isset( $_GET['edac_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['edac_nonce'] ), 'edac_highlight' ) ) {
return $lazyload;
}
if ( isset( $_GET['edac'] ) ) {
Expand Down
13 changes: 8 additions & 5 deletions includes/activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ function edac_activation() {
add_option( 'edac_post_types', array( 'post', 'page' ) );
add_option( 'edac_simplified_summary_position', 'after' );

// Sanitize the input.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required.
$action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is not required.
$checked = isset( $_POST['checked'] ) ? array_map( 'sanitize_text_field', $_POST['checked'] ) : array();

// Redirect: Don't do redirects when multiple plugins are bulk activated.
if (
( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) &&
( isset( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) ) {
if ( 'activate-selected' === $action && count( $checked ) > 1 ) {
return;
}

edac_add_accessibility_statement_page();

}

/**
Expand All @@ -40,6 +43,7 @@ function edac_add_accessibility_statement_page() {

global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for adding data to database, caching not required for one time operation.
if ( null === $wpdb->get_row( "SELECT post_name FROM {$wpdb->prefix}posts WHERE post_name = 'accessibility-statement'", 'ARRAY_A' ) ) {

$current_user = wp_get_current_user();
Expand Down Expand Up @@ -95,5 +99,4 @@ function edac_add_accessibility_statement_page() {
wp_insert_post( $page );

}

}
1 change: 0 additions & 1 deletion includes/classes/class-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ public function edac_password_protected_notice_ajax() {

wp_send_json_success( wp_json_encode( $results ) );
}

}

new Admin_Notices();
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
*/
class EDAC_Dom extends simple_html_dom {

/** @var array $video_ext video extensions. */
/**
* Array of supported video extensions.
*
* @var array $video_ext Video extensions.
*/
protected $video_ext = array(
'.3gp',
'.asf',
Expand All @@ -35,7 +39,11 @@ class EDAC_Dom extends simple_html_dom {
'.wmx',
);

/** @var array $audio_ext audio extensions. */
/**
* List of supported audio file extensions.
*
* @var array $audio_ext Audio extensions.
*/
protected $audio_ext = array(
'.aif',
'.aiff',
Expand All @@ -50,7 +58,11 @@ class EDAC_Dom extends simple_html_dom {
'.wma',
);

/** @var array $embed_sources embed source urls. */
/**
* Array containing URLs of embed sources.
*
* @var array $embed_sources Embed source URLs.
*/
protected $embed_sources = array(
'mixcloud.com',
'reverbnation.com',
Expand Down Expand Up @@ -93,11 +105,11 @@ public function convert_tag_to_marker( $tags ) {
*/
public function text_around_element_contains( $element, $contains, $distance_after_element = 25 ) {
// to account for the start of the search term getting cut off add the length of the search to the distance.
$total_distance = $distance_after_element + strlen( $contains );
$marker = $element->plaintext;
$tag_end = stripos( $this->plaintext, $marker ) + strlen( $marker );
$next_marker_position = stripos( $this->plaintext, 'ac_element', $tag_end ) ?: strlen( $this->plaintext );
$found_position = stripos( $this->plaintext, $contains, $tag_end );
$total_distance = $distance_after_element + strlen( $contains );
$marker = $element->plaintext;
$tag_end = stripos( $this->plaintext, $marker ) + strlen( $marker );
$next_marker_position = stripos( $this->plaintext, 'ac_element', $tag_end ) !== false ? stripos( $this->plaintext, 'ac_element', $tag_end ) : strlen( $this->plaintext );
$found_position = stripos( $this->plaintext, $contains, $tag_end );

if ( false === $found_position || $found_position > $next_marker_position ) {
return false;
Expand All @@ -106,7 +118,6 @@ public function text_around_element_contains( $element, $contains, $distance_aft
$distance = $found_position - $tag_end;

return $distance < $total_distance;

}

/**
Expand All @@ -118,13 +129,13 @@ public function text_around_element_contains( $element, $contains, $distance_aft
public function find_media_embeds( $include_audio = true ) {
// all elements with sources.
$elements_with_src = $this->find( '[src]' );
$elements = array();
$audio = $include_audio ? $this->audio_ext : array();
$extensions = array_merge( $this->video_ext, $this->embed_sources, $audio );
$elements = array();
$audio = $include_audio ? $this->audio_ext : array();
$extensions = array_merge( $this->video_ext, $this->embed_sources, $audio );
if ( $elements_with_src ) {
$elements = array_filter(
$elements_with_src,
function( $element ) use ( $extensions ) {
function ( $element ) use ( $extensions ) {
$count = 0;
str_ireplace( $extensions, '', $element->getAttribute( 'src' ), $count );
return $count > 0;
Expand All @@ -143,13 +154,13 @@ function( $element ) use ( $extensions ) {
*/
public function find_linked_media( $include_audio = true ) {
$elements_with_href = $this->find( '[href]' );
$elements = array();
$audio = $include_audio ? $this->audio_ext : array();
$extensions = array_merge( $this->video_ext, $audio );
$elements = array();
$audio = $include_audio ? $this->audio_ext : array();
$extensions = array_merge( $this->video_ext, $audio );
if ( $elements_with_href ) {
$elements = array_filter(
$elements_with_href,
function( $element ) use ( $extensions ) {
function ( $element ) use ( $extensions ) {
$count = 0;
str_ireplace( $extensions, '', $element->getAttribute( 'href' ), $count );
return $count > 0;
Expand All @@ -159,5 +170,4 @@ function( $element ) use ( $extensions ) {

return $elements;
}

}
7 changes: 4 additions & 3 deletions includes/classes/class-edac-frontend-highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function get_issues( $post_id ) {
$table_name = $wpdb->prefix . 'accessibility_checker';
$post_id = intval( $post_id );
$siteid = get_current_blog_id();
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, rule, ignre, object, ruletype FROM ' . $table_name . ' where postid = %d and siteid = %d', $post_id, $siteid ), ARRAY_A );
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT id, rule, ignre, object, ruletype FROM ' . $table_name . ' where postid = %d and siteid = %d', $post_id, $siteid ), ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name.
if ( ! $results ) {
return null;
}
Expand All @@ -46,7 +46,7 @@ public function get_issues( $post_id ) {
public function ajax() {

// nonce security.
if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'ajax-nonce' ) ) {
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 );
}
Expand All @@ -56,7 +56,8 @@ public function ajax() {
wp_send_json_error( $error );
}

$results = $this->get_issues( $_REQUEST['post_id'] );
$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
$results = $this->get_issues( $post_id );

if ( ! $results ) {
$error = new WP_Error( '-3', 'Issue query returned no results' );
Expand Down
8 changes: 4 additions & 4 deletions includes/classes/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function ( $item ) {
/**
* Localizes the format of a number.
*
* @param [type] $number
* @param int $number number to format.
* @param integer $precision number of decimals.
* @return integer
*/
Expand All @@ -64,7 +64,7 @@ public static function format_number( $number, $precision = 0 ) {
/**
* Localizes the format of a percentage.
*
* @param [type] $number
* @param init $number number to format.
* @param integer $precision number of decimals.
* @return integer
*/
Expand Down Expand Up @@ -96,8 +96,8 @@ public static function format_percentage( $number, $precision = 2 ) {
/**
* Localizes the format of a date.
*
* @param [type] $number
* @param integer $precision number of decimals.
* @param string $date date to format.
* @param boolean $include_time whether to include time in the formatted date.
* @return integer
*/
public static function format_date( $date, $include_time = false ) {
Expand Down
Loading

0 comments on commit 963f545

Please sign in to comment.