-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from equalizedigital/release/v1.10.0
Release/v1.10.0
- Loading branch information
Showing
23 changed files
with
2,373 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
npm run lint | ||
npm run lint-staged-precommit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.