diff --git a/admin/class-enqueue-admin.php b/admin/class-enqueue-admin.php index d3b7234d..f4c590bc 100644 --- a/admin/class-enqueue-admin.php +++ b/admin/class-enqueue-admin.php @@ -36,8 +36,8 @@ public static function enqueue() { */ public static function enqueue_styles() { wp_enqueue_style( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/admin.css', array(), EDAC_VERSION, 'all' ); - } - + } + /** * Enqueue the admin and editorApp scripts. * @@ -57,13 +57,23 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'accessibility_checker_ignored', ); - if ( is_array( $post_types ) && count( $post_types ) && ( in_array( $current_post_type, $post_types, true ) || in_array( $page, $enabled_pages, true ) ) || ( 'site-editor.php' !== $pagenow ) ) { + if ( + ( + is_array( $post_types ) && + count( $post_types ) && + ( + in_array( $current_post_type, $post_types, true ) || + in_array( $page, $enabled_pages, true ) + ) + ) || + 'site-editor.php' !== $pagenow + ) { global $post; $post_id = is_object( $post ) ? $post->ID : null; wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', array( 'jquery' ), EDAC_VERSION, false ); - + wp_localize_script( 'edac', 'edac_script_vars', @@ -74,26 +84,26 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'restNonce' => wp_create_nonce( 'wp_rest' ), ) ); - + if ( 'post.php' === $pagenow ) { - + // Is this posttype setup to be checked? $post_types = get_option( 'edac_post_types' ); $current_post_type = get_post_type(); $active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) ); - + $pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) && EDAC_KEY_VALID; - + if ( EDAC_DEBUG || strpos( EDAC_VERSION, '-beta' ) !== false ) { $debug = true; } else { $debug = false; } - + wp_enqueue_script( 'edac-editor-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/editorApp.bundle.js', false, EDAC_VERSION, false ); - + wp_localize_script( 'edac-editor-app', 'edac_editor_app', @@ -107,13 +117,13 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'authOk' => false === (bool) get_option( 'edac_password_protected', false ), 'debug' => $debug, 'scanUrl' => get_preview_post_link( - $post_id, + $post_id, array( 'edac_pageScanner' => 1 ) ), ) ); - - } + + } } } @@ -125,13 +135,13 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { public static function maybe_enqueue_email_opt_in_script() { $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. - if ( 'accessibility_checker' === $page - && true !== (bool) get_user_meta( get_current_user_id(), 'edac_email_optin', true ) + if ( 'accessibility_checker' === $page + && true !== (bool) get_user_meta( get_current_user_id(), 'edac_email_optin', true ) ) { wp_enqueue_style( 'email-opt-in-form', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/emailOptIn.css', false, EDAC_VERSION, 'all' ); wp_enqueue_script( 'email-opt-in-form', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/emailOptIn.bundle.js', false, EDAC_VERSION, true ); - + wp_localize_script( 'email-opt-in-form', 'edac_email_opt_in_form', @@ -140,7 +150,7 @@ public static function maybe_enqueue_email_opt_in_script() { 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); - + } } } diff --git a/includes/classes/class-enqueue-frontend.php b/includes/classes/class-enqueue-frontend.php index a78176a1..430e6847 100644 --- a/includes/classes/class-enqueue-frontend.php +++ b/includes/classes/class-enqueue-frontend.php @@ -26,20 +26,25 @@ public function __construct() { public static function enqueue() { self::maybe_enqueue_frontend_highlighter(); } - + /** * Enqueue the frontend highlighter. * * @return void */ public static function maybe_enqueue_frontend_highlighter() { - + // This loads on all pages, so bail as early as possible. Do checks that don't require DB calls first. // Don't load on admin pages in iframe that is running a pageScan. - // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( is_admin() || isset( $_GET['edac_pageScanner'] ) && '1' === $_GET['edac_pageScanner'] ) { + if ( + is_admin() || + ( + isset( $_GET['edac_pageScanner'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended + '1' === $_GET['edac_pageScanner'] // phpcs:ignore WordPress.Security.NonceVerification.Recommended + ) + ) { return; } @@ -55,17 +60,17 @@ public static function maybe_enqueue_frontend_highlighter() { if ( is_customize_preview() || ! ( $post_id && current_user_can( 'edit_post', $post_id ) ) ) { return; } - + // Don't load if this pagetype is not setup to be scanned. $post_types = get_option( 'edac_post_types' ); $current_post_type = get_post_type(); $active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) ); - + if ( $active ) { - + wp_enqueue_style( 'edac-frontend-highlighter-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/frontendHighlighterApp.css', false, EDAC_VERSION, 'all' ); wp_enqueue_script( 'edac-frontend-highlighter-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/frontendHighlighterApp.bundle.js', false, EDAC_VERSION, false ); diff --git a/includes/rules/empty_button.php b/includes/rules/empty_button.php index 459ba3d6..8781775c 100644 --- a/includes/rules/empty_button.php +++ b/includes/rules/empty_button.php @@ -41,7 +41,13 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is '' !== $error_code && ( ! isset( $image[0] ) || trim( $image[0]->getAttribute( 'alt' ) ) === '' ) && ( ! isset( $input[0] ) || trim( $input[0]->getAttribute( 'value' ) ) === '' ) - && ( ! isset( $i[0] ) || ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) + && ( + ! isset( $i[0] ) || + ( + ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && + ( trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) + ) + ) ) { $errors[] = $error_code; } diff --git a/includes/rules/img_alt_empty.php b/includes/rules/img_alt_empty.php index a277d227..a3ee5b60 100644 --- a/includes/rules/img_alt_empty.php +++ b/includes/rules/img_alt_empty.php @@ -23,15 +23,18 @@ function edac_rule_img_alt_empty( $content, $post ) { // phpcs:ignore -- $post i $elements = $dom->find( $tag ); foreach ( $elements as $element ) { if ( - isset( $element ) - && 'img' === $element->tag - && $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'alt' ) === '' - && $element->getAttribute( 'role' ) !== 'presentation' - || ( 'input' === $element->tag + ( + isset( $element ) + && 'img' === $element->tag + && $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'alt' ) === '' + && $element->getAttribute( 'role' ) !== 'presentation' + ) || ( + 'input' === $element->tag && $element->hasAttribute( 'alt' ) && $element->getAttribute( 'type' ) === 'image' - && $element->getAttribute( 'alt' ) === '' ) + && $element->getAttribute( 'alt' ) === '' + ) ) { $image_code = $element->outertext; diff --git a/includes/rules/img_alt_missing.php b/includes/rules/img_alt_missing.php index 5100b981..2d57b801 100644 --- a/includes/rules/img_alt_missing.php +++ b/includes/rules/img_alt_missing.php @@ -22,14 +22,20 @@ function edac_rule_img_alt_missing( $content, $post ) { // phpcs:ignore -- $post $elements = $dom->find( $tag ); foreach ( $elements as $element ) { - if ( isset( $element ) - && ( 'img' === $element->tag - && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'role' ) !== 'presentation' ) - && $element->getAttribute( 'aria-hidden' ) !== 'true' - || ( 'input' === $element->tag - && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'type' ) === 'image' ) + if ( + ( + isset( $element ) && + ( + 'img' === $element->tag + && ! $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'role' ) !== 'presentation' + ) + && $element->getAttribute( 'aria-hidden' ) !== 'true' + ) || ( + 'input' === $element->tag + && ! $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'type' ) === 'image' + ) ) { $image_code = $element->outertext; diff --git a/includes/rules/text_small.php b/includes/rules/text_small.php index 291ec039..abce7e85 100644 --- a/includes/rules/text_small.php +++ b/includes/rules/text_small.php @@ -43,8 +43,13 @@ function edac_rule_text_small( $content, $post ) { // phpcs:ignore -- $post is r preg_match_all( '!\d+!', $absolute_fontsize_errorcode, $matches ); if ( - stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && implode( ' ', $matches[0] ) <= 10 - || stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' && implode( ' ', $matches[0] ) <= 13 + ( + stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && + implode( ' ', $matches[0] ) <= 10 + ) || ( + ( stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' ) && + ( implode( ' ', $matches[0] ) <= 13 ) + ) ) { $errors[] = $element; } @@ -86,7 +91,10 @@ function ac_css_small_text_check( $content ) { $value = str_replace( '.', '', preg_replace( '/\d/', '', $rules['font-size'] ) ); - if ( 'px' === $value && $rules['font-size'] <= 10 || 'pt' === $value && $rules['font-size'] <= 13 ) { + if ( + ( 'px' === $value && $rules['font-size'] <= 10 ) || + ( 'pt' === $value && $rules['font-size'] <= 13 ) + ) { $error_code = $element . '{ '; foreach ( $rules as $key => $value ) {