Skip to content

Commit 5ad7c64

Browse files
authored
Merge pull request #1805 from equalizedigital/william/no-issue/fix-pro-detection-in-dismiss-panel-outside-post-editor
fix: expose pro status in edac_script_vars and widen isPro checks in DismissPanel
2 parents c2f3674 + 79916bd commit 5ad7c64

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

admin/class-enqueue-admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {
9393
'proUrl' => esc_url_raw( edac_generate_link_type( [ 'utm_content' => '__name__' ] ) ),
9494
'hasDismissEndpoint' => method_exists( \EDAC\Inc\REST_Api::class, 'dismiss_issue' ),
9595
'showMetaboxInBlockEditor' => ! Helpers::is_block_editor() || (bool) get_option( 'edac_show_metabox_in_block_editor', 1 ),
96+
'pro' => defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID,
9697
]
9798
);
9899

src/issueModal/components/DismissPanel.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ import { getDismissReasonOptions } from '../../sidebar/utils/dismissHelpers';
2727
* @param {boolean} props.forceGlobal - When true, the primary dismiss action targets all pages (global dismiss).
2828
* @param {boolean} props.isPro - Whether the current UI is running in Pro.
2929
*/
30-
const DismissPanel = ( { issue, isOpen, onToggle, onIgnore, onCloseModal, forceGlobal = false, isPro = typeof window !== 'undefined' && window.edac_editor_app?.pro === '1' } ) => {
30+
const DismissPanel = ( {
31+
issue,
32+
isOpen,
33+
onToggle,
34+
onIgnore,
35+
onCloseModal,
36+
forceGlobal = false,
37+
isPro = typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ),
38+
} ) => {
3139
const panelRef = useRef( null );
3240
const [ comment, setComment ] = useState( issue?.ignre_comment ? decodeEntities( issue.ignre_comment ) : '' );
3341
const [ dismissReason, setDismissReason ] = useState( issue?.ignre_reason || 'accessible' );
@@ -142,7 +150,7 @@ const DismissPanel = ( { issue, isOpen, onToggle, onIgnore, onCloseModal, forceG
142150
) }
143151
{ isIgnored ? (
144152
<>
145-
{ ( issue?.user || issue?.ignre_user_name || issue?.ignre_date || issue?.ignre_global ) && (
153+
{ ( issue?.user || issue?.ignre_user_name || issue?.ignre_date || isGloballyDismissed ) && (
146154
<dl className="edac-analysis__dismissed-meta">
147155

148156
{ ( issue?.ignre_global === 1 || issue?.ignre_global === '1' ) && (

src/issueModal/components/IssueDetailsModal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const IssueDetailsModal = ( { issue, rule, onClose, isOpen, focusSection,
328328
) }
329329

330330
{ /* How to Fix - Show detailed info for Pro, or just link for Free */ }
331-
{ window.edac_editor_app?.pro === '1' ? (
331+
{ ( typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ) ) ? (
332332
<div className="edac-analysis__issue-help-accordion">
333333
<PanelBody
334334
title={ __( 'Show explanation', 'accessibility-checker' ) }
@@ -406,7 +406,6 @@ export const IssueDetailsModal = ( { issue, rule, onClose, isOpen, focusSection,
406406
onToggle={ () => setIsDismissPanelOpen( ! isDismissPanelOpen ) }
407407
onIgnore={ onIgnore }
408408
onCloseModal={ onClose }
409-
isPro={ typeof window !== 'undefined' && window.edac_editor_app?.pro === '1' }
410409
/>
411410
</div>
412411
</div>

tests/phpunit/Admin/EnqueueAdminTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ public function testLocalizedAdminDataIncludesFixesRestUrl(): void {
125125
$this->assertStringContainsString( 'fixesRestUrl', $localized_data );
126126
}
127127

128+
/**
129+
* The pro flag in edac_script_vars reflects defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID,
130+
* so non-editor admin pages (e.g. the Issues Explorer) can gate pro-only UI without
131+
* relying on window.edac_editor_app, which is only localized on post.php/post-new.php.
132+
*/
133+
public function testLocalizedAdminDataIncludesProFlag(): void {
134+
global $wp_scripts;
135+
136+
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
137+
138+
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
139+
$expected_pro = defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID;
140+
141+
// wp_localize_script() stringifies booleans as "1" / "" (matching the
142+
// === '1' checks on the JS side), not JSON true/false.
143+
$this->assertStringContainsString( '"pro"', $localized_data );
144+
$this->assertMatchesRegularExpression(
145+
'/"pro"\s*:\s*"' . ( $expected_pro ? '1' : '' ) . '"/',
146+
$localized_data
147+
);
148+
}
149+
128150
/**
129151
* FixesRestUrl uses the edac/v1 namespace and matches rest_url().
130152
*/

0 commit comments

Comments
 (0)