Skip to content

Commit 50d352e

Browse files
authored
Merge pull request #1171 from equalizedigital/william/pro-169-filter-post-types-at-save-time
Add initial support for handling of virtual posts
2 parents 4720c6d + e2dca0b commit 50d352e

17 files changed

Lines changed: 661 additions & 73 deletions

admin/class-ajax.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public function summary() {
118118

119119
$html['content'] .= '</li>';
120120

121+
// if this is a virtual page, we don't show the readability section.
122+
$is_virtual_page = edac_is_virtual_page( $post_id );
123+
121124
$html['content'] .= '
122125
' . edac_generate_summary_stat(
123126
'edac-summary-errors',
@@ -145,7 +148,7 @@ public function summary() {
145148
) . '
146149
147150
</ul>
148-
<div class="edac-summary-readability">
151+
<div class="edac-summary-readability" ' . ( $is_virtual_page ? 'style="display: none;"' : '' ) . '>
149152
<div class="edac-summary-readability-level">
150153
<div><img src="' . EDAC_PLUGIN_URL . 'assets/images/readability-icon-navy.png" alt="" width="54"></div>
151154
<div class="edac-panel-number' . ( ( (int) $summary['content_grade'] <= 9 || 'none' === $simplified_summary_prompt ) ? ' passed-text-color' : ' failed-text-color' ) . '">
@@ -479,7 +482,7 @@ function ( $a, $b ) {
479482

480483
$landmark = isset( $row['landmark'] ) ? $row['landmark'] : '';
481484
$landmark_selector = isset( $row['landmark_selector'] ) ? $row['landmark_selector'] : '';
482-
485+
483486
$html .= edac_generate_landmark_link( $landmark, $landmark_selector, $postid );
484487

485488
$html .= '</div>';
@@ -488,12 +491,18 @@ function ( $a, $b ) {
488491

489492
if ( ! isset( $rule['viewable'] ) || $rule['viewable'] ) {
490493

494+
$post_view_link = apply_filters(
495+
'edac_get_origin_url_for_virtual_page',
496+
get_the_permalink( $postid ),
497+
$postid
498+
);
499+
491500
$url = add_query_arg(
492501
[
493502
'edac' => $id,
494503
'edac_nonce' => wp_create_nonce( 'edac_highlight' ),
495504
],
496-
get_the_permalink( $postid )
505+
$post_view_link
497506
);
498507

499508
// Translators: %d is the issue ID.

admin/class-enqueue-admin.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function enqueue_styles() {
4848
public static function maybe_enqueue_admin_and_editor_app_scripts() {
4949

5050
global $pagenow;
51-
$post_types = get_option( 'edac_post_types' );
51+
$post_types = Settings::get_scannable_post_types();
5252
$current_post_type = get_post_type();
5353
$page = self::get_current_page_slug();
5454
$enabled_pages = apply_filters(
@@ -82,18 +82,18 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {
8282
'edac',
8383
'edac_script_vars',
8484
[
85-
'postID' => $post_id,
86-
'nonce' => wp_create_nonce( 'ajax-nonce' ),
87-
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
88-
'restNonce' => wp_create_nonce( 'wp_rest' ),
89-
'fixesProUrl' => esc_url_raw( edac_generate_link_type( [ 'utm-content', '__fix__' ] ) ),
85+
'postID' => $post_id,
86+
'nonce' => wp_create_nonce( 'ajax-nonce' ),
87+
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
88+
'restNonce' => wp_create_nonce( 'wp_rest' ),
89+
'proUrl' => esc_url_raw( edac_generate_link_type( [ 'utm-content' => '__name__' ] ) ),
9090
]
9191
);
9292

9393
if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
9494

9595
// Is this posttype setup to be checked?
96-
$post_types = get_option( 'edac_post_types' );
96+
$post_types = Settings::get_scannable_post_types();
9797
$current_post_type = get_post_type();
9898
$active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) );
9999

@@ -112,9 +112,17 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {
112112
if ( (int) get_option( 'page_on_front' ) === $post_id || (int) get_option( 'page_for_posts' ) === $post_id ) {
113113
$scan_url = add_query_arg( 'edac_pageScanner', 1, get_permalink( $post_id ) );
114114
} else {
115-
$scan_url = get_preview_post_link(
116-
$post_id,
117-
[ 'edac_pageScanner' => 1 ]
115+
$post_view_link = apply_filters(
116+
'edac_get_origin_url_for_virtual_page',
117+
get_preview_post_link( $post_id ),
118+
$post_id
119+
);
120+
121+
$scan_url = add_query_arg(
122+
[
123+
'edac_pageScanner' => 1,
124+
],
125+
$post_view_link
118126
);
119127
}
120128

admin/class-meta-boxes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function init_hooks(): void {
3131
* @return void
3232
*/
3333
public function register_meta_boxes(): void {
34-
$post_types = get_option( 'edac_post_types' );
34+
$post_types = Settings::get_scannable_post_types();
3535
if ( $post_types ) {
3636
foreach ( $post_types as $post_type ) {
3737
add_meta_box(

admin/class-post-save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Post_Save {
3535
*/
3636
public static function delete_issue_data_on_post_trashing( $post_ID, $post, $update ) {
3737
// check post type.
38-
$post_types = get_option( 'edac_post_types' );
38+
$post_types = Settings::get_scannable_post_types();
3939
if ( is_array( $post_types ) && ! in_array( $post->post_type, $post_types, true ) ) {
4040
return;
4141
}

admin/class-purge-post-data.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public static function delete_cpt_posts( string $post_type ) {
8282

8383
global $wpdb;
8484

85+
/**
86+
* Fires before deleting posts of a specific post type.
87+
*
88+
* @since 1.31.0
89+
*
90+
* @param string $post_type Post Type.
91+
*/
92+
do_action( 'edac_before_delete_cpt_posts', $post_type );
93+
8594
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
8695
return $wpdb->query(
8796
$wpdb->prepare(

admin/class-scans-stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function summary( $skip_cache = false ) {
143143
$data['scannable_posts_count'] = (int) $scannable_posts_count;
144144
$data['rule_count'] = (int) $this->rule_count;
145145
$data['tests_count'] = (int) $tests_count;
146-
$data['scannable_post_types_count'] = (int) count( Settings::get_scannable_post_types() );
146+
$data['scannable_post_types_count'] = (int) count( Settings::get_scannable_post_types( true ) );
147147

148148
$post_types = get_post_types(
149149
[

admin/class-settings.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,39 @@ public static function get_scannable_post_statuses() {
3535
/**
3636
* Gets a list of post types that are scannable.
3737
*
38+
* @param bool $skip_filtering Whether to skip filtering when passing through alternative settings class.
39+
*
3840
* @return array
3941
*/
40-
public static function get_scannable_post_types() {
42+
public static function get_scannable_post_types( $skip_filtering = false ) {
4143

42-
// Check if the new settings class exists. This is added to allow for backwards compatibility
43-
// with the old settings class. The old settings class check should be removed after a few releases.
44-
$new_settings_class_exists = class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' );
45-
if ( ! class_exists( '\EDACP\Settings' ) && ! $new_settings_class_exists ) {
44+
if (
45+
class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' ) &&
46+
method_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings', 'get_scannable_post_types' )
47+
) {
48+
return \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types( $skip_filtering );
49+
}
4650

47-
$post_types = Helpers::get_option_as_array( 'edac_post_types' );
51+
$post_types = Helpers::get_option_as_array( 'edac_post_types' );
4852

49-
// remove duplicates.
50-
$post_types = array_unique( $post_types );
53+
// remove duplicates.
54+
$post_types = array_unique( $post_types );
5155

52-
// validate post types.
53-
$args = [
54-
'public' => true,
55-
'_builtin' => true,
56-
];
57-
$valid_post_types = get_post_types( $args, 'names', 'and' );
58-
unset( $valid_post_types['attachment'] );
56+
// validate post types.
57+
$args = [
58+
'public' => true,
59+
'_builtin' => true,
60+
];
61+
$valid_post_types = get_post_types( $args, 'names', 'and' );
62+
unset( $valid_post_types['attachment'] );
5963

60-
foreach ( $post_types as $key => $post_type ) {
64+
foreach ( $post_types as $key => $post_type ) {
6165

62-
if ( ! post_type_exists( $post_type ) || ! array_key_exists( $post_type, $valid_post_types ) ) {
63-
unset( $post_types[ $key ] );
64-
}
66+
if ( ! post_type_exists( $post_type ) || ! array_key_exists( $post_type, $valid_post_types ) ) {
67+
unset( $post_types[ $key ] );
6568
}
66-
return $post_types;
6769
}
68-
69-
return $new_settings_class_exists
70-
? \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types()
71-
: \EDACP\Settings::get_scannable_post_types();
70+
return $post_types;
7271
}
7372

7473

includes/activation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ function edac_activation() {
1919
update_option( 'edac_simplified_summary_position', 'after' );
2020

2121
Accessibility_Statement::add_page();
22+
23+
// This is an add_option on purpose to not overwrite user settings on update.
24+
add_option( 'edacp_ignore_user_roles', [ 'administrator' ] );
2225
}

includes/classes/class-enqueue-frontend.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace EDAC\Inc;
99

10+
use EDAC\Admin\Settings;
11+
1012
/**
1113
* Class that initializes and handles enqueueing styles and scripts for the frontend.
1214
*/
@@ -50,7 +52,7 @@ public static function maybe_enqueue_frontend_highlighter() {
5052

5153
// Don't load on the frontend if we don't have a post to work with.
5254
global $post;
53-
$post_id = is_object( $post ) ? $post->ID : null;
55+
$post_id = apply_filters( 'edac_filter_frontend_highlight_post_id', is_object( $post ) ? $post->ID : null );
5456

5557
if ( null === $post_id ) {
5658
return;
@@ -82,7 +84,7 @@ public static function maybe_enqueue_frontend_highlighter() {
8284

8385

8486
// Don't load if this pagetype is not setup to be scanned.
85-
$post_types = get_option( 'edac_post_types' );
87+
$post_types = Settings::get_scannable_post_types();
8688
$current_post_type = get_post_type();
8789
$active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) );
8890

includes/classes/class-rest-api.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace EDAC\Inc;
99

10-
use EDAC\Admin\Helpers;
1110
use EDAC\Admin\Insert_Rule_Data;
1211
use EDAC\Admin\Scans_Stats;
1312
use EDAC\Admin\Settings;
@@ -248,7 +247,7 @@ public function clear_issues_for_post( $request ) {
248247
}
249248

250249
$post_type = get_post_type( $post );
251-
$post_types = Helpers::get_option_as_array( 'edac_post_types' );
250+
$post_types = Settings::get_scannable_post_types();
252251
if ( empty( $post_types ) || ! in_array( $post_type, $post_types, true ) ) {
253252
return new \WP_REST_Response( [ 'message' => 'The post type is not set to be scanned.' ], 400 );
254253
}
@@ -320,7 +319,7 @@ public function set_post_scan_results( $request ) {
320319
}
321320

322321
$post_type = get_post_type( $post );
323-
$post_types = Helpers::get_option_as_array( 'edac_post_types' );
322+
$post_types = Settings::get_scannable_post_types();
324323
if ( empty( $post_types ) || ! in_array( $post_type, $post_types, true ) ) {
325324

326325
return new \WP_REST_Response( [ 'message' => 'The post type is not set to be scanned.' ], 400 );

0 commit comments

Comments
 (0)