Skip to content

Commit

Permalink
Merge pull request #456 from equalizedigital/hotfix/password-fix
Browse files Browse the repository at this point in the history
Auth issue fix
  • Loading branch information
SteveJonesDev authored Jan 20, 2024
2 parents 034feb0 + e782ad0 commit 2475396
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 101 deletions.
9 changes: 2 additions & 7 deletions accessibility-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,13 +834,8 @@ function edac_summary_ajax() {
$html['content'] = '';

// password check.
if (
! (
EDAC_KEY_VALID === true &&
edac_check_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' )
) &&
\EDAC\Helpers::is_basic_auth()
) {
$is_pasword_protected = (bool) get_option( 'edac_password_protected', false );
if ( $is_pasword_protected ) {
$admin_notices = new \EDAC\Admin_Notices();
$notice_text = $admin_notices->edac_password_protected_notice_text();
$html['password_protected'] = $notice_text;
Expand Down
37 changes: 0 additions & 37 deletions includes/classes/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,41 +207,4 @@ public static function is_domain_loopback( $domain ) {

return false;
}

/**
* Determine if this site is using basic auth.
*
* @return boolean
*/
public static function is_basic_auth() {

$key = 'edac_auth_type';

$status = get_transient( $key );

$status = false;

if ( false === $status ) {

//phpcs:disable WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
$response = wp_remote_get( home_url() );
if ( ! is_wp_error( $response ) ) {
$code = wp_remote_retrieve_response_code( $response );

if ( 401 === $code || 403 === $code ) {
$status = 'basic';
}
}

// cache results for up to 30 seconds.
set_transient( $key, $status, 30 );

}

if ( 'basic' === $status ) {
return true;
}

return false;
}
}
15 changes: 8 additions & 7 deletions includes/classes/class-scans-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
class Scans_Stats {


/**
* Number of seconds to return results from cache.
*
Expand Down Expand Up @@ -189,7 +190,7 @@ 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 @@ -247,9 +248,9 @@ function ( $item ) {



if ( $data['posts_scanned'] > 0 &&
! empty( Settings::get_scannable_post_types() ) &&
! empty( Settings::get_scannable_post_statuses() )
if ( $data['posts_scanned'] > 0
&& ! empty( Settings::get_scannable_post_types() )
&& ! empty( Settings::get_scannable_post_statuses() )
) {

$sql = "SELECT COUNT({$wpdb->posts}.ID) FROM {$wpdb->posts}
Expand All @@ -262,7 +263,7 @@ function ( $item ) {
Settings::get_scannable_post_statuses()
) . ')';

// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for adding data to database, caching not required for one time operation.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for adding data to database, caching not required for one time operation.
$data['posts_without_issues'] = $wpdb->get_var( $sql );

$data['avg_issues_per_post'] = round( ( $data['warnings'] + $data['errors'] ) / $data['posts_scanned'], 2 );
Expand Down Expand Up @@ -364,7 +365,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 Expand Up @@ -437,7 +438,7 @@ public function issues_summary_by_post_type( $post_type ) {
$data['cache_id'] = $transient_name;
$data['cached_at'] = time();
$data['expires_at'] = time() + $this->cache_time;
$cache['cache_hit'] = false;
$data['cache_hit'] = false;

set_transient( $transient_name, $data, $this->cache_time );

Expand Down
2 changes: 1 addition & 1 deletion includes/enqueue-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ function edac_admin_enqueue_scripts() {
'postID' => $post_id,
'edacUrl' => esc_url_raw( get_site_url() ),
'edacHeaders' => $headers,
'basicAuth' => true === $pro ? false : EDAC\Helpers::is_basic_auth(),
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
'baseurl' => plugin_dir_url( __DIR__ ),
'active' => $active,
'pro' => $pro,
'hasAuth' => (bool) get_option( 'edac_password_protected', false ),
'debug' => $debug,
'scanUrl' => get_preview_post_link(
$post_id,
Expand Down
56 changes: 7 additions & 49 deletions src/editorApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,21 @@ window.addEventListener('DOMContentLoaded', () => {

const SCANNABLE_POST_TYPE = edac_editor_app.active;

if (SCANNABLE_POST_TYPE && settings.JS_SCAN_ENABLED) {
if (SCANNABLE_POST_TYPE) {

if (edac_editor_app.pro === '1' || edac_editor_app.basicAuth !== '1') {
if (edac_editor_app.pro !== '1' && edac_editor_app.hasAuth === '1') {
return;
}


if (settings.JS_SCAN_ENABLED ){

setTimeout(function () {
initCheckPage();
}, 250); // Allow page load to fire before init, otherwise we'll have to wait for iframe to load.

} else {


//Listen for dispatches from the wp data store so we can trap the update/publish event
let saving = false;
let autosaving = false;


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


if (wp.data.select('core/editor').isAutosavingPost()) {
autosaving = true;
}

// Rescan the page if user saves post
if (wp.data.select('core/editor').isSavingPost()) {

saving = true;
} else {
if (saving) {
saving = false;

if (edac_editor_app.pro !== '1' || edac_editor_app.basicAuth === '1') {
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 {
debug("Gutenberg is not enabled.");
}



}


}


Expand Down

0 comments on commit 2475396

Please sign in to comment.