Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing clarifying parenthesis cs check #547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions admin/class-enqueue-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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 )
),
)
);
}

}
}
}

Expand All @@ -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',
Expand All @@ -140,7 +150,7 @@ public static function maybe_enqueue_email_opt_in_script() {
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);

}
}
}
19 changes: 12 additions & 7 deletions includes/classes/class-enqueue-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 );

Expand Down
8 changes: 7 additions & 1 deletion includes/rules/empty_button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 10 additions & 7 deletions includes/rules/img_alt_empty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions includes/rules/img_alt_missing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions includes/rules/text_small.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ) {
Expand Down
Loading