Skip to content

Commit

Permalink
Merge pull request #538 from equalizedigital/release/v1.10.0
Browse files Browse the repository at this point in the history
Release/v1.10.0
  • Loading branch information
pattonwebz authored Mar 20, 2024
2 parents 5707277 + a5d9eef commit 869b61d
Show file tree
Hide file tree
Showing 23 changed files with 2,373 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run lint
npm run lint-staged-precommit
8 changes: 2 additions & 6 deletions accessibility-checker.php
100644 → 100755
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.9.3
* Version: 1.10.0
* 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.9.3' );
define( 'EDAC_VERSION', '1.10.0' );
}

// Current database version.
Expand Down Expand Up @@ -126,9 +126,6 @@
require_once plugin_dir_path( __FILE__ ) . 'includes/meta-boxes.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/options-page.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/validate.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/insert.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/purge.php';

/**
* Filters and Actions
*/
Expand All @@ -137,7 +134,6 @@
add_action( 'admin_init', 'edac_register_setting' );
add_action( 'admin_head', 'edac_post_on_load' );
add_filter( 'save_post', 'edac_save_post', 10, 3 );
add_action( 'wp_trash_post', 'edac_delete_post' );
add_action( 'pre_get_posts', 'edac_show_draft_posts' );
if ( is_plugin_active( 'oxygen/functions.php' ) ) {
add_action( 'added_post_meta', 'edac_oxygen_builder_save_post', 10, 4 );
Expand Down
6 changes: 4 additions & 2 deletions admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace EDAC\Admin;

use EDAC\Admin\SiteHealth\Information;
use EDAC\Admin\Purge_Post_Data;

/**
* Admin handling class.
Expand All @@ -29,8 +30,9 @@ public function init() {

$update_database = new Update_Database();
$update_database->init_hooks();

add_action( 'admin_enqueue_scripts', array( 'EDAC\Admin\Enqueue_Admin', 'enqueue' ) );
add_action( 'wp_trash_post', array( Purge_Post_Data::class, 'delete_post' ) );

$admin_notices = new Admin_Notices();
$admin_notices->init_hooks();
Expand All @@ -40,7 +42,7 @@ public function init() {

$site_health_info = new Information();
$site_health_info->init_hooks();

$this->init_ajax();
}

Expand Down
142 changes: 142 additions & 0 deletions admin/class-insert-rule-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* Inserts rule data about a post to the database
*
* @since 1.10.0
*
* @package Accessibility_Checker
*/

namespace EDAC\Admin;

/**
* Class for inserting rule data into the database
*
* @since 1.10.0
*/
class Insert_Rule_Data {

/**
* Insert rule data into database
*
* @since 1.10.0
*
* @param object $post The post object. Must have a valid ID.
* @param string $rule The rule.
* @param string $ruletype The rule type.
* @param string $rule_obj The object.
*
* @return void|int|\WP_Error The ID of the inserted record, void if no
* record was inserted or a WP_Error if the insert failed.
*/
public function insert( object $post, string $rule, string $ruletype, string $rule_obj ) {

if ( ! isset( $post->ID, $post->post_type )
|| empty( $rule )
|| empty( $ruletype )
|| empty( $rule_obj )
) {
return;
}

global $wpdb;
$table_name = $wpdb->prefix . 'accessibility_checker';

// set up rule data array.
$rule_data = array(
'postid' => $post->ID,
'siteid' => get_current_blog_id(),
'type' => $post->post_type,
'rule' => $rule,
'ruletype' => $ruletype,
'object' => esc_attr( $rule_obj ),
'recordcheck' => 1,
'user' => get_current_user_id(),
'ignre' => 0,
'ignre_user' => null,
'ignre_date' => null,
'ignre_comment' => null,
'ignre_global' => 0,
);

// return if revision.
if ( 'revision' === $rule_data['type'] ) {
return;
}

// Check if exists.
// 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.
$results = $wpdb->get_results(
$wpdb->prepare(
'SELECT postid, ignre FROM %i where type = %s and postid = %d and rule = %s and object = %s and siteid = %d',
$table_name,
$rule_data['type'],
$rule_data['postid'],
$rule_data['rule'],
$rule_data['object'],
$rule_data['siteid']
),
ARRAY_A
);

// Loop existing records.
if ( $results ) {
foreach ( $results as $row ) {

// if being ignored, don't overwrite value.
if ( true === (bool) $row['ignre'] ) {
$rule_data['ignre'] = 1;
}

// update existing record.
// 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.
$wpdb->query(
$wpdb->prepare(
'UPDATE %i SET recordcheck = %d, ignre = %d WHERE siteid = %d and postid = %d and rule = %s and object = %s and type = %s',
$table_name,
1,
$rule_data['ignre'],
$rule_data['siteid'],
$rule_data['postid'],
$rule_data['rule'],
$rule_data['object'],
$rule_data['type']
)
);

}
}

// Insert new records.
if ( ! $results ) {

// filter post types.
$rule_data = apply_filters( 'edac_filter_insert_rule_data', $rule_data );

// Sanitize rule data since it is filtered, and we can't be sure
// the data is still as valid as it was when it was first set.
// Sanitize the filtered data.
$rule_data_sanitized = array(
'postid' => absint( $rule_data['postid'] ),
'siteid' => absint( $rule_data['siteid'] ),
'type' => sanitize_text_field( $rule_data['type'] ),
'rule' => sanitize_text_field( $rule_data['rule'] ),
'ruletype' => sanitize_text_field( $rule_data['ruletype'] ),
'object' => esc_attr( $rule_data['object'] ),
'recordcheck' => absint( $rule_data['recordcheck'] ),
'user' => absint( $rule_data['user'] ),
'ignre' => absint( $rule_data['ignre'] ),
'ignre_user' => isset( $rule_data['ignre_user'] ) ? absint( $rule_data['ignre_user'] ) : null,
'ignre_date' => isset( $rule_data['ignre_date'] ) ? sanitize_text_field( $rule_data['ignre_date'] ) : null,
'ignre_comment' => isset( $rule_data['ignre_comment'] ) ? sanitize_text_field( $rule_data['ignre_comment'] ) : null,
'ignre_global' => absint( $rule_data['ignre_global'] ),
);

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Using direct query for adding data to database.
$wpdb->insert( $table_name, $rule_data_sanitized );

// Return insert id or error.
return $wpdb->insert_id;
}
}
}
96 changes: 96 additions & 0 deletions admin/class-purge-post-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Purge Post Data stored in the database that holds scan data about the posts.
*
* @package Accessibility_Checker
*/

namespace EDAC\Admin;

/**
* Uses sql queries to get and purge post data from the database for given post
* ids or for custom posts by post_type string.
*
* @since 1.10.0
*/
class Purge_Post_Data {

/**
* Purge deleted posts
*
* @since 1.10.0
*
* @param int $post_id ID of the post.
*
* @return void
*/
public static function delete_post( int $post_id ) {
global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i WHERE postid = %d and siteid = %d',
edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' ),
$post_id,
get_current_blog_id()
)
);

self::delete_post_meta( $post_id );
}

/**
* Delete post meta
*
* @since 1.10.0
*
* @param int $post_id ID of the post.
*
* @return void
*/
public static function delete_post_meta( int $post_id ) {

if ( ! $post_id ) {
return;
}

$post_meta = get_post_meta( $post_id );
if ( $post_meta ) {
foreach ( $post_meta as $key => $value ) {
if ( substr( $key, 0, 5 ) === '_edac' || substr( $key, 0, 6 ) === '_edacp' ) {
delete_post_meta( $post_id, $key );
}
}
}
}

/**
* Purge issues by post type
*
* @since 1.10.0
*
* @param string $post_type Post Type.
*
* @return bool|int|\mysqli_result|void
*/
public static function delete_cpt_posts( string $post_type ) {

if ( ! $post_type || ! post_type_exists( $post_type ) ) {
return;
}

global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
return $wpdb->query(
$wpdb->prepare(
"DELETE T1,T2 from $wpdb->postmeta as T1 JOIN %i as T2 ON T1.post_id = T2.postid WHERE T1.meta_key like %s and T2.siteid=%d and T2.type=%s",
edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' ),
'_edac%',
get_current_blog_id(),
$post_type
)
);
}
}
53 changes: 52 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
Newer versions can be found in readme.txt.

= 1.8.1 =
* Fixed: false positives on the incorrect heading order rule
* Added: fallback to determine ordinal when php intl extension is not installed

= 1.8.0 =
* Updated: heading order on welcome screen
* Updated: missing_title summary
* Updated: SQL prepare queries to use %i placeholder
* Updated: incorrect textdomains and made strings translatible
* Removed: single-use variables where possible
* Added: PHPUnit framework and workflow
* Added: unit test for the `edac_compare_strings` function
* Added: unit test for the `edac_parse_css` function
* Updated: the `edac_compare_strings` function to be more efficient, return the correct type, and fix the failing tests
* Updated: `readme.txt` to only have the latest major and minor changelog
* Added: `changelog.txt` file.
* Added: `includes/rules.php` file that contains all rules and returns them as an array
* Added a static var in the `edac_register_rules` function to avoid re-reading the `includes/rules.php` file every time the method is called
* Removed: `has_filter` check before calling `apply_filters`
* Added: `edac_register_rules` unit test
* Added: `edac_check_plugin_active` deprecated function
* Updated: `edac_check_plugin_active` calls with `is_plugin_active`
* Removed: calls to `add_option` and replaced with `update_option`
* Updated: Use of `else` statement and bailed early when needed
* Removed: `has_filter()` before applying apply_filters
* Removed: hooks from `EDAC\Admin_Notices` constructor and call them from the `init_hooks` method
* Added: `EDAC\Admin_Notices` unit tests
* Added: `EDAC\Ajax` class and moved AJAX functions into this class
* Removed: unnecessary `wp_ajax_nopriv_` hooks
* Added: namespace to `Frontend_Highlight` class and only instantiated on `DOING_AJAX`
* Removed: `EDAC_SVG_IGNORE_ICON` string and pulled it from the file
* Removed: `$plugin_check` global variable
* Removed: `$rules` global variable
* Updated: `edac_ordinal` function to support all locales, safeguards against improper inputs, number format
* Updated: JavaScript coding standards
* Added: `includes/classes` directory to autoloader
* Added: new directory admin to autoloader
* Removed: `require_once` class calls
* Created: `class-plugin.php` to load frontend classes
* Created: `class-admin.php` to load admin classes
* Updated: classes to follow new `EDAC\Admin` and `EDAC\Inc` namespaces
* Updated: accessibility statement functions to a class
* Updated: simplified summary functions to a class
* Updated: lazyload Filter function into a class
* Removed: removes calls to `add_post_meta` and uses `update_post_meta` where appropriate
* Added: `EDAC\Inc\Accessibility_Statement` unit test
* Added: `EDAC\Inc\Simplified_Summary` unit test
* Added: local PHPUnit to run on wp-env test
* Updated: enqueue scripts and styles setup to only load assets in the proper environments
* Updated: email signup form

= 1.7.1 =
* Fixed: classic editor save conflict
* Fixed: password protection message displaying repeatedly
Expand Down Expand Up @@ -273,7 +324,7 @@ Fixed: marketing notice logic
* Freemius Update

= 1.2.7 =
* Add accessibility statement page template
* Add accessibility statement page template

= 1.2.6 =
* Minor accessibility updates
Expand Down
6 changes: 3 additions & 3 deletions includes/classes/class-edac-dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public function find_linked_media( $include_audio = true ) {
$elements = array_filter(
$elements_with_href,
function ( $element ) use ( $extensions ) {
$count = 0;
str_ireplace( $extensions, '', $element->getAttribute( 'href' ), $count );
return $count > 0;
$href = $element->getAttribute( 'href' );
$extension = pathinfo( $href, PATHINFO_EXTENSION );
return in_array( '.' . $extension, $extensions, true );
}
);
}
Expand Down
Loading

0 comments on commit 869b61d

Please sign in to comment.