-
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 53 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,7 +48,7 @@ public static function enqueue_styles() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function maybe_enqueue_admin_and_editor_app_scripts() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global $pagenow; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = get_option( 'edac_post_types' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = Settings::get_scannable_post_types(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $current_post_type = get_post_type(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $page = self::get_current_page_slug(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $enabled_pages = apply_filters( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -82,18 +82,18 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edac', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edac_script_vars', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'postID' => $post_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'nonce' => wp_create_nonce( 'ajax-nonce' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'restNonce' => wp_create_nonce( 'wp_rest' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'fixesProUrl' => esc_url_raw( edac_generate_link_type( [ 'utm-content', '__fix__' ] ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'postID' => $post_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'nonce' => wp_create_nonce( 'ajax-nonce' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'restNonce' => wp_create_nonce( 'wp_rest' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'proUrl' => esc_url_raw( edac_generate_link_type( [ 'utm-content' => '__name__' ] ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Is this posttype setup to be checked? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_types = get_option( 'edac_post_types' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $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 ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -112,9 +112,16 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( (int) get_option( 'page_on_front' ) === $post_id || (int) get_option( 'page_for_posts' ) === $post_id ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $scan_url = add_query_arg( 'edac_pageScanner', 1, get_permalink( $post_id ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $scan_url = get_preview_post_link( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ 'edac_pageScanner' => 1 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_view_link = apply_filters( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edac_get_origin_url_for_virtual_page', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $post_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $scan_url = add_query_arg( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'edac_pageScanner' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_string( $post_view_link ) ? $post_view_link : get_preview_post_link( $post_id ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
126
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 Validate and document origin URL filter; block non-http(s) schemes. A malicious filter could feed a javascript: URL. Validate the scheme and document the hook. Don’t let bad URLs punk your editor. - $post_view_link = apply_filters(
- 'edac_get_origin_url_for_virtual_page',
- $post_id
- );
-
- $scan_url = add_query_arg(
- [
- 'edac_pageScanner' => 1,
- ],
- is_string( $post_view_link ) ? $post_view_link : get_preview_post_link( $post_id )
- );
+ $default_base = get_preview_post_link( $post_id );
+ /**
+ * Filter the base URL used when launching the page scanner from the editor.
+ *
+ * Allows mapping virtual/ghost posts to their canonical origin URL (e.g., archives/taxonomies).
+ *
+ * @since 1.29.0
+ *
+ * @param string $default_base Default preview URL for the post.
+ * @param int $post_id Current post ID (can be virtual/ghost).
+ * @return string Filtered base URL.
+ */
+ $post_view_link = apply_filters( 'edac_get_origin_url_for_virtual_page', $default_base, $post_id );
+ $scan_base = ( is_string( $post_view_link ) && '' !== $post_view_link ) ? $post_view_link : $default_base;
+ $parsed = wp_parse_url( $scan_base );
+ if ( empty( $parsed['scheme'] ) || ! in_array( $parsed['scheme'], [ 'http', 'https' ], true ) ) {
+ $scan_base = $default_base;
+ }
+ $scan_url = add_query_arg( [ 'edac_pageScanner' => 1 ], $scan_base );📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,40 +35,39 @@ public static function get_scannable_post_statuses() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Gets a list of post types that are scannable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param bool $skip_filtering Whether to skip filtering when passing through alternative settings class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function get_scannable_post_types() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function get_scannable_post_types( $skip_filtering = false ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 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 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $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 |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| namespace EDAC\Inc; | ||
|
|
||
| use EDAC\Admin\Settings; | ||
|
|
||
| /** | ||
| * Class that initializes and handles enqueueing styles and scripts for the frontend. | ||
| */ | ||
|
|
@@ -50,7 +52,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; | ||
|
|
@@ -82,7 +84,7 @@ public static function maybe_enqueue_frontend_highlighter() { | |
|
|
||
|
|
||
| // Don't load if this pagetype is not setup to be scanned. | ||
| $post_types = get_option( 'edac_post_types' ); | ||
| $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 ) ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| * @package Accessibility_Checker | ||
| */ | ||
|
|
||
| use EDAC\Admin\Settings; | ||
|
|
||
| /** | ||
| * Compare strings | ||
| * | ||
|
|
@@ -408,7 +410,7 @@ function edac_get_posts_count() { | |
|
|
||
| $output = []; | ||
|
|
||
| $post_types = get_option( 'edac_post_types' ); | ||
| $post_types = Settings::get_scannable_post_types(); | ||
| if ( $post_types ) { | ||
| foreach ( $post_types as $post_type ) { | ||
|
|
||
|
|
@@ -767,22 +769,27 @@ function edac_generate_landmark_link( $landmark, $landmark_selector, $post_id, $ | |
| } | ||
| $landmark = ucwords( $landmark ); | ||
| $landmark = esc_html( $landmark ); | ||
|
|
||
| // 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"). | ||
| $landmark_aria_label = sprintf( __( 'View %s landmark on website, opens a new window', 'accessibility-checker' ), $landmark ); | ||
|
|
||
| $target_attr = $target_blank ? ' target="_blank"' : ''; | ||
|
|
||
| return sprintf( | ||
| '<a href="%s" class="%s"%s aria-label="%s">%s</a>', | ||
| esc_url( $landmark_url ), | ||
|
|
@@ -792,7 +799,35 @@ function edac_generate_landmark_link( $landmark, $landmark_selector, $post_id, $ | |
| $landmark | ||
| ); | ||
| } | ||
|
|
||
| // If we only have landmark text, return it formatted. | ||
| return $landmark; | ||
| } | ||
|
|
||
| /** | ||
| * Check if a post is a virtual page. | ||
| * | ||
| * This function checks if a post is a virtual page using the pro plugin's | ||
| * VirtualPageType constant. | ||
| * | ||
| * @param int $post_id The post ID to check. | ||
| * @return bool True if the post is a virtual page, false otherwise. | ||
| */ | ||
| function edac_is_virtual_page( $post_id ) { | ||
| if ( class_exists( '\EqualizeDigital\AccessibilityCheckerPro\VirtualContent\PostType\VirtualItemType' ) ) { | ||
| $post_type = get_post_type( $post_id ); | ||
| $pro_post_type = \EqualizeDigital\AccessibilityCheckerPro\VirtualContent\PostType\VirtualItemType::POST_TYPE; | ||
| return $pro_post_type === $post_type; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
pattonwebz marked this conversation as resolved.
|
||
| /** | ||
| * Check if the Pro version of the plugin is active. | ||
| * | ||
| * @return bool True if Pro version is active, false otherwise. | ||
| */ | ||
| function edac_is_pro() { | ||
| return defined( 'EDACP_VERSION' ) && defined( 'EDAC_KEY_VALID' ) && EDAC_KEY_VALID; | ||
| } | ||
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