Skip to content

Commit

Permalink
Merge pull request #460 from equalizedigital/release/v1.7.1
Browse files Browse the repository at this point in the history
Release/v1.7.1
  • Loading branch information
SteveJonesDev authored Jan 23, 2024
2 parents 671403e + a5a695d commit 849f6bd
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 126 deletions.
4 changes: 2 additions & 2 deletions accessibility-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Accessibility Checker
* Plugin URI: https://a11ychecker.com
* Description: Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.
* Version: 1.7.0
* Version: 1.7.1
* Author: Equalize Digital
* Author URI: https://equalizedigital.com
* License: GPL-2.0+
Expand Down Expand Up @@ -41,7 +41,7 @@

// Current plugin version.
if ( ! defined( 'EDAC_VERSION' ) ) {
define( 'EDAC_VERSION', '1.7.0' );
define( 'EDAC_VERSION', '1.7.1' );
}

// Current database version.
Expand Down
27 changes: 10 additions & 17 deletions admin/class-enqueue-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {
$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 ) );

$headers = array(
'Content-Type' => 'application/json',
'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ),
'Authorization' => 'None',

);

$pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) && EDAC_KEY_VALID;

Expand All @@ -103,17 +96,17 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {

wp_localize_script(
'edac-editor-app',
'edacEditorApp',
'edac_editor_app',
array(
'postID' => $post_id,
'edacUrl' => esc_url_raw( get_site_url() ),
'edacHeaders' => $headers,
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
'baseurl' => plugin_dir_url( EDAC_PLUGIN_FILE ),
'active' => $active,
'pro' => $pro,
'debug' => $debug,
'scanUrl' => get_preview_post_link(
'postID' => $post_id,
'edacUrl' => esc_url_raw( get_site_url() ),
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
'baseurl' => plugin_dir_url( __DIR__ ),
'active' => $active,
'pro' => $pro,
'authOk' => false === (bool) get_option( 'edac_password_protected', false ),
'debug' => $debug,
'scanUrl' => get_preview_post_link(
$post_id,
array( 'edac_pageScanner' => 1 )
),
Expand Down
7 changes: 4 additions & 3 deletions admin/class-scans-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
class Scans_Stats {


/**
* Number of seconds to return results from cache.
*
Expand Down Expand Up @@ -175,8 +176,8 @@ function ( $item ) {
);

if ( $rule_query->count() ) {
++$data['rules_failed'];
}
++$data['rules_failed'];
}
}
$data['rules_passed'] = $this->rule_count - $data['rules_failed'];

Expand Down Expand Up @@ -332,7 +333,7 @@ function ( $item ) {
/**
* Gets issues summary information about a post type
*
* @param string $post_type post type.
* @param string $post_type post type.
* @return array .
*/
public function issues_summary_by_post_type( $post_type ) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"yoast/wp-test-utils": "^1.2",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"wp-coding-standards/wpcs": "^3.0",
"equalizedigital/accessibility-checker-wp-env": "1.0.1",
"equalizedigital/accessibility-checker-wp-env": "*",
"doctrine/instantiator": "^1.3.1",
"wp-phpunit/wp-phpunit": "*"
},
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions includes/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ function edac_validate( $post_ID, $post, $action ) {
if ( ! $content['html'] ) {
update_option( 'edac_password_protected', true );
return;
} else {
update_option( 'edac_password_protected', false );
}
delete_option( 'edac_password_protected' );

Expand Down
Empty file removed readme.txt
Empty file.
9 changes: 7 additions & 2 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ const getData = async ( url = '', data = {} ) => {
const response = await fetch( url, {
method: 'GET',
headers: {
'X-WP-Nonce': edacScriptVars.restNonce,
// eslint-disable-next-line camelcase
'X-WP-Nonce': edac_script_vars.restNonce,
'Content-Type': 'application/json',
},
} );
return response.json();
Expand All @@ -949,9 +951,12 @@ const postData = async ( url = '', data = {} ) => {
const response = await fetch( url, {
method: 'POST',
headers: {
'X-WP-Nonce': edacScriptVars.restNonce,
// eslint-disable-next-line camelcase
'X-WP-Nonce': edac_script_vars.restNonce,
'Content-Type': 'application/json',
},
body: JSON.stringify( data ),
} );
return response.json();
};

39 changes: 22 additions & 17 deletions src/editorApp/checkPage.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
/* eslint-disable padded-blocks, no-multiple-empty-lines */
/* global edacEditorApp, edacpFullSiteScanApp */
/* global edac_editor_app */

import { info, debug } from './helpers';
import { showNotice } from './../common/helpers';

const postData = async ( url = '', data = {} ) => {

let HEADERS;
if ( typeof ( edacpFullSiteScanApp ) === 'undefined' ) {
HEADERS = edacEditorApp.edacHeaders;
} else {
HEADERS = edacpFullSiteScanApp.edacpHeaders;
}

const postData = async ( url = '', data = {} ) => {
return await fetch( url, {
method: 'POST',
headers: HEADERS,
headers: {
// eslint-disable-next-line camelcase
'X-WP-Nonce': edac_script_vars.restNonce,
'Content-Type': 'application/json',
},
body: JSON.stringify( data ),
} ).then( ( res ) => {
return res.json();
} ).catch( () => {
return {};
} );
};

};

const saveScanResults = ( postId, violations ) => {
info( 'Saving ' + postId + ': started' );

document.querySelector( '.edac-panel' ).classList.add( 'edac-panel-loading' );

postData( edacEditorApp.edacApiUrl + '/post-scan-results/' + postId, {
// eslint-disable-next-line camelcase
postData( edac_editor_app.edacApiUrl + '/post-scan-results/' + postId, {
violations,
} ).then( ( data ) => {
info( 'Saving ' + postId + ': done' );
Expand Down Expand Up @@ -85,7 +81,8 @@ const injectIframe = ( previewUrl, postID ) => {
if ( iframeDocument ) {
// inject the scanner app.
const scannerScriptElement = iframeDocument.createElement( 'script' );
scannerScriptElement.src = edacEditorApp.baseurl + '/build/pageScanner.bundle.js';
// eslint-disable-next-line camelcase
scannerScriptElement.src = edac_editor_app.baseurl + '/build/pageScanner.bundle.js';
iframeDocument.head.appendChild( scannerScriptElement );
}
} );
Expand All @@ -111,8 +108,14 @@ export const init = () => {
let saving = false;
let autosaving = false;


if ( wp.data !== undefined && wp.data.subscribe !== undefined ) {
wp.data.subscribe( () => {

if ( wp.data.select( 'core/editor' ) === undefined ) {
return;
}

if ( wp.data.select( 'core/editor' ).isAutosavingPost() ) {
autosaving = true;
}
Expand All @@ -124,7 +127,8 @@ export const init = () => {
saving = false;

if ( ! autosaving ) {
injectIframe( edacEditorApp.scanUrl, edacEditorApp.postID );
// eslint-disable-next-line camelcase
injectIframe( edac_editor_app.scanUrl, edac_editor_app.postID );
} else {
autosaving = false;
}
Expand All @@ -134,6 +138,7 @@ export const init = () => {
debug( 'Gutenberg is not enabled.' );
}

injectIframe( edacEditorApp.scanUrl, edacEditorApp.postID );
// eslint-disable-next-line camelcase
injectIframe( edac_editor_app.scanUrl, edac_editor_app.postID );
};

75 changes: 6 additions & 69 deletions src/editorApp/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,17 @@
/* eslint-disable padded-blocks, no-multiple-empty-lines */
/* global edacEditorApp */
/* global edac_editor_app */

import { settings } from './settings';
import { debug } from './helpers';
import { showNotice } from './../common/helpers';
import { init as initCheckPage } from './checkPage';


window.addEventListener( 'DOMContentLoaded', () => {
// eslint-disable-next-line camelcase
const SCANNABLE_POST_TYPE = edac_editor_app.active;

const SCANNABLE_POST_TYPE = edacEditorApp.active;

if ( SCANNABLE_POST_TYPE && settings.JS_SCAN_ENABLED ) {

if ( edacEditorApp.pro === '1' ) {

// Use checkApi from pro instead.
if ( SCANNABLE_POST_TYPE ) {
// eslint-disable-next-line camelcase
if ( edac_editor_app.authOk === '1' ) {
setTimeout( function() {
initCheckPage();
}, 250 ); // Allow page load to fire before init, otherwise we'll have to wait for iframe to load.

} else {

const API_URL = edacEditorApp.edacApiUrl;
const HEADERS = edacEditorApp.edacHeaders;

const checkApi = async () => {
try {
const response = await fetch( API_URL + '/test', {
method: 'POST',
headers: HEADERS,
} );

return response.status;
} catch ( error ) {
return 401; // Default status for error
}
};

checkApi().then( ( status ) => {
if ( status > 400 ) {
if ( status === 401 ) {
showNotice( {
msg: 'Whoops! It looks like your website is currently password protected. The free version of Accessibility Checker can only scan live websites. To scan this website for accessibility problems either remove the password protection or follow the link below to upgrade to Accessibility Checker Pro.',
type: 'warning',
url: 'https://equalizedigital.com/accessibility-checker/pricing/',
label: 'Upgrade',
closeOthers: true,
} );
} else {
showNotice( {
msg: 'Whoops! It looks like there was a problem connecting to the WordPress REST API which is required by Accessibility Checker. Follow the link below for more information:',
type: 'warning',
url: 'https://developer.wordpress.org/rest-api/frequently-asked-questions',
label: 'Rest API',
closeOthers: true,
} );

debug( 'Error: Cannot connect to API. Status code is: ' + status );
}
} else {
setTimeout( function() {
initCheckPage();
}, 250 ); // Allow page load to fire before init, otherwise we'll have to wait for iframe to load.
}
} ).catch( ( error ) => {
showNotice( {
msg: 'Whoops! It looks like there was a problem connecting to the WordPress REST API which is required by Accessibility Checker. Follow the link below for more information:',
type: 'warning',
url: 'https://developer.wordpress.org/rest-api/frequently-asked-questions',
label: 'Rest API',
closeOthers: true,
} );

debug( error );
} );
}
}
} );
Expand Down
Loading

0 comments on commit 849f6bd

Please sign in to comment.