-
Notifications
You must be signed in to change notification settings - Fork 19
Add initial support for handling of virtual posts #1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
54eb791
d9439d5
99cbbde
c45b2f5
6e5703f
d983812
271affd
df67427
ab13da2
6142569
069d9e4
0873d1e
e345aed
6e5e3ed
f2bd12e
bc4bc75
0c5ff01
e4310ca
fd255b7
15e4287
0942007
8b7c400
1479e49
b42c504
cc29ba6
b926db8
f2c626e
7b2fe61
3da0f7a
6cd7e6c
7cf16c9
2841157
1fe997b
6b7f7d1
fe5688c
bc5c1ce
89d8213
b255202
ec9da2c
1a6228f
04d33f6
aa56926
93be94e
ab9bdb2
c150739
90aa188
96a5305
0e4b108
7622b19
953d1e9
800271c
c59d654
f4bf0b2
9d1d6af
23e8fe6
8a4c686
819c1c1
d99c4ca
0a3b14b
f5b5fea
a61432c
0ab9548
57cce49
4fc1925
e2dca0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,7 @@ public function init_hooks(): void { | |||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function register_meta_boxes(): void { | ||||||||||||
| $post_types = get_option( 'edac_post_types' ); | ||||||||||||
| $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', get_option( 'edac_post_types' ) ); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFilter name doesn't follow coding guidelines. The filter name uses Apply this diff to use the correct prefix: - $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', get_option( 'edac_post_types' ) );
+ $post_types = apply_filters( 'edac_fill_site_scan_scannable_post_types', get_option( 'edac_post_types' ) );Please verify that this filter name change is applied consistently across the codebase: 🏁 Script executed: #!/bin/bash
# Description: Check for consistent usage of the filter name across the codebase
# Expected: All occurrences should use the same filter name
echo "Searching for the current filter name with edacp_ prefix:"
rg "edacp_fill_site_scan_scannable_post_types" -A 2 -B 2
echo -e "\nSearching for similar filter names with edac_ prefix:"
rg "edac_fill_site_scan_scannable_post_types" -A 2 -B 2
echo -e "\nSearching for all edacp_ prefixed filters:"
rg "edacp_" -A 1 -B 1Length of output: 4640 Filter hook prefix should use Coding guidelines require a • includes/classes/class-rest-api.php Proposed diffs: diff --git a/includes/classes/class-rest-api.php b/includes/classes/class-rest-api.php
--- a/includes/classes/class-rest-api.php
+++ b/includes/classes/class-rest-api.php
- $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) );
+ $post_types = apply_filters( 'edac_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) );diff --git a/admin/class-meta-boxes.php b/admin/class-meta-boxes.php
--- a/admin/class-meta-boxes.php
+++ b/admin/class-meta-boxes.php
- $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', get_option( 'edac_post_types' ) );
+ $post_types = apply_filters( 'edac_fill_site_scan_scannable_post_types', get_option( 'edac_post_types' ) );Also, search the codebase for any remaining 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| if ( $post_types ) { | ||||||||||||
| foreach ( $post_types as $post_type ) { | ||||||||||||
| add_meta_box( | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,36 +39,34 @@ public static function get_scannable_post_statuses() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function get_scannable_post_types() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if the new settings class exists. This is added to allow for backwards compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // with the old settings class. The old settings class check should be removed after a few releases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $new_settings_class_exists = class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! class_exists( '\EDACP\Settings' ) && ! $new_settings_class_exists ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = Helpers::get_option_as_array( 'edac_post_types' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings', 'get_scannable_post_types' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Back-compat booby trap: calling Pro::get_scannable_post_types with an extra arg can fatally error If older Pro versions expose Proposed back-compat safe delegation: - public static function get_scannable_post_types( $skip_filtering = false ) {
-
- if (
- class_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings' ) &&
- method_exists( 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings', 'get_scannable_post_types' )
- ) {
- return \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types( $skip_filtering );
- }
+ public static function get_scannable_post_types( $skip_filtering = false ) {
+ $pro_class = '\EqualizeDigital\AccessibilityCheckerPro\Admin\Settings';
+ if ( class_exists( $pro_class ) && method_exists( $pro_class, 'get_scannable_post_types' ) ) {
+ // Back-compat: call with zero or one argument depending on the Pro signature.
+ try {
+ $ref = new \ReflectionMethod( $pro_class, 'get_scannable_post_types' );
+ if ( $ref->getNumberOfParameters() > 0 ) {
+ return $pro_class::get_scannable_post_types( $skip_filtering );
+ }
+ return $pro_class::get_scannable_post_types();
+ } catch ( \ReflectionException $e ) {
+ // Fall back to the safest call.
+ return $pro_class::get_scannable_post_types();
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = Helpers::get_option_as_array( 'edac_post_types' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // remove duplicates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = array_unique( $post_types ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // remove duplicates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = array_unique( $post_types ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // validate post types. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $args = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'public' => true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '_builtin' => true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $valid_post_types = get_post_types( $args, 'names', 'and' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unset( $valid_post_types['attachment'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // validate post types. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $args = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'public' => true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '_builtin' => true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $valid_post_types = get_post_types( $args, 'names', 'and' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unset( $valid_post_types['attachment'] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach ( $post_types as $key => $post_type ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach ( $post_types as $key => $post_type ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! post_type_exists( $post_type ) || ! array_key_exists( $post_type, $valid_post_types ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unset( $post_types[ $key ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! post_type_exists( $post_type ) || ! array_key_exists( $post_type, $valid_post_types ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unset( $post_types[ $key ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $post_types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $new_settings_class_exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? \EqualizeDigital\AccessibilityCheckerPro\Admin\Settings::get_scannable_post_types() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : \EDACP\Settings::get_scannable_post_types(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $post_types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ public static function maybe_enqueue_frontend_highlighter() { | |
|
|
||
| // Don't load on the frontend if we don't have a post to work with. | ||
| global $post; | ||
| $post_id = is_object( $post ) ? $post->ID : null; | ||
| $post_id = apply_filters( 'edac_filter_frontend_highlight_post_id', is_object( $post ) ? $post->ID : null ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add PHPDoc documentation for the new filter. The filter implementation is correct and follows WordPress conventions with the proper Add PHPDoc documentation above the filter: + /**
+ * Filter the post ID used for frontend highlighting.
+ *
+ * Allows external code to override which post ID is used for frontend
+ * highlighting functionality, supporting virtual posts for archive/taxonomy pages.
+ *
+ * @since 1.15.0
+ *
+ * @param int|null $post_id The post ID to use for frontend highlighting. Default is the current post ID or null.
+ */
$post_id = apply_filters( 'edac_filter_frontend_highlight_post_id', is_object( $post ) ? $post->ID : null );🤖 Prompt for AI Agents |
||
|
|
||
| if ( null === $post_id ) { | ||
|
Comment on lines
+55
to
57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Gate logic should use the filtered $post_id’s post type (and allow virtual pages). Right now you ask get_post_type() without an ID, which can mismatch on archives. That’s sloppy—use the post type for the post you actually intend to highlight; also allow virtual/ghost posts to activate the highlighter. - $post_types = Settings::get_scannable_post_types();
- $current_post_type = get_post_type();
- $active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) );
+ $post_types = Settings::get_scannable_post_types();
+ $current_post_type = $post_id ? get_post_type( $post_id ) : get_post_type();
+ $active = (
+ is_array( $post_types )
+ && (
+ in_array( $current_post_type, $post_types, true )
+ || ( function_exists( 'edac_is_virtual_page' ) && $post_id && edac_is_virtual_page( $post_id ) )
+ )
+ );Also applies to: 86-90 🤖 Prompt for AI Agents |
||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -225,7 +225,7 @@ public function clear_issues_for_post( $request ) { | |||||
| } | ||||||
|
|
||||||
| $post_type = get_post_type( $post ); | ||||||
| $post_types = Helpers::get_option_as_array( 'edac_post_types' ); | ||||||
| $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) ); | ||||||
| if ( empty( $post_types ) || ! in_array( $post_type, $post_types, true ) ) { | ||||||
| return new \WP_REST_Response( [ 'message' => 'The post type is not set to be scanned.' ], 400 ); | ||||||
| } | ||||||
|
|
@@ -297,7 +297,7 @@ public function set_post_scan_results( $request ) { | |||||
| } | ||||||
|
|
||||||
| $post_type = get_post_type( $post ); | ||||||
| $post_types = Helpers::get_option_as_array( 'edac_post_types' ); | ||||||
| $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) ); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filter name $post_types = apply_filters( 'edacp_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) );
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use The filter name Apply this diff to use the correct prefix: - $post_types = apply_filters( 'edacp_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) );
+ $post_types = apply_filters( 'edac_fill_site_scan_scannable_post_types', Helpers::get_option_as_array( 'edac_post_types' ) );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| if ( empty( $post_types ) || ! in_array( $post_type, $post_types, true ) ) { | ||||||
|
|
||||||
| return new \WP_REST_Response( [ 'message' => 'The post type is not set to be scanned.' ], 400 ); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,7 +162,10 @@ function edac_custom_post_types() { | |
| $output = 'names'; // names or objects, note names is the default. | ||
| $operator = 'and'; // Options 'and' or 'or'. | ||
|
|
||
| return get_post_types( $args, $output, $operator ); | ||
| return array_merge( | ||
| get_post_types( $args, $output, $operator ), | ||
| [ 'edac_virtual_page' => 'Archives' ] | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: edac_custom_post_types() returns mixed shapes (strings + associative array). You’re merging a list of slugs with ['edac_virtual_page' => 'Archives'] which breaks consumers expecting a list of slugs. Fix it and only add the CPT when it exists. -return array_merge(
- get_post_types( $args, $output, $operator ),
- [ 'edac_virtual_page' => 'Archives' ]
- );
+ $virtual = class_exists( '\EqualizeDigital\AccessibilityCheckerPro\VirtualContent\VirtualPageType' )
+ ? [ \EqualizeDigital\AccessibilityCheckerPro\VirtualContent\VirtualPageType::POST_TYPE ]
+ : [];
+ return array_merge( get_post_types( $args, $output, $operator ), $virtual ); |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -770,12 +773,17 @@ function edac_generate_landmark_link( $landmark, $landmark_selector, $post_id, $ | |
|
|
||
| // If we have both landmark and selector, create a link. | ||
| if ( ! empty( $landmark_selector ) ) { | ||
| $link = apply_filters( | ||
| 'edac_get_origin_url_for_virtual_page', | ||
| $post_id | ||
| ); | ||
|
|
||
|
Comment on lines
+773
to
+780
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use permalink as the filter’s default value and document the hook; remove type ambiguity and simplify fallback Passing Apply this diff: - $link = apply_filters(
- 'edac_get_origin_url_for_virtual_page',
- $post_id
- );
+ $base_link = get_the_permalink( $post_id );
+
+ /**
+ * Filter the base URL used for "View on page"/landmark links.
+ *
+ * Allows mapping virtual/ghost posts to their canonical origin URL (e.g., archives/taxonomies).
+ *
+ * @since 1.x.x
+ *
+ * @param string $base_link Default base URL (permalink for $post_id).
+ * @param int $post_id Post ID represented by the link (may be a virtual/ghost post).
+ * @param string $landmark_selector Unencoded CSS selector for the landmark being highlighted.
+ * @param string $landmark Human-readable landmark label.
+ *
+ * @return string Filtered base URL.
+ */
+ $link = apply_filters( 'edac_get_origin_url_for_virtual_page', $base_link, $post_id, $landmark_selector, $landmark );
+ if ( ! is_string( $link ) || '' === $link ) {
+ $link = $base_link;
+ }
@@
- is_string( $link ) ? $link : get_the_permalink( $post_id )
+ $linkNote: The hook name follows the edac_ prefix per team conventions (good). The added docblock aligns with “Document all custom hooks” guidance. Also applies to: 783-784 🤖 Prompt for AI Agents |
||
| $landmark_url = add_query_arg( | ||
| [ | ||
| 'edac_landmark' => base64_encode( $landmark_selector ), | ||
| 'edac_nonce' => wp_create_nonce( 'edac_highlight' ), | ||
| ], | ||
| get_the_permalink( $post_id ) | ||
| is_string( $link ) ? $link : get_the_permalink( $post_id ) | ||
| ); | ||
|
|
||
| // translators: %s is the landmark type (e.g., "Header", "Navigation", "Main"). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add PHPDoc documentation for the new filter hook.
The filter hook implementation is correct and follows the
edac_prefix convention, but it lacks proper documentation. According to the coding guidelines, all custom hooks should be documented with clear descriptions and parameter types.Add PHPDoc documentation above the filter:
📝 Committable suggestion
🤖 Prompt for AI Agents