Skip to content

Commit 58fea39

Browse files
authored
fix: Pro preview features showing when Pro plugin is active (#255)
* fix: Pro preview features showing when Pro plugin is active - Remove static isProLoaded check evaluated at script load time - Add dynamic runtime checks in all preview filters - Rename all callback names to avoid conflicts with Pro plugin - Add priority 5 to ensure Pro filters (priority 10) can override - Remove wedocs_register_menu_routes filter from free plugin Fixes issue where Permission Management, Assistant Widget, Layout & Styles, Social Share, and Contributors previews were still appearing in settings even when wedocs-pro plugin was active and licensed. The root cause was the isProLoaded check happening at script parse time before Pro plugin loaded, causing all preview filters to register even when Pro was present. * fix: pro preview
1 parent 841d939 commit 58fea39

File tree

6 files changed

+128
-83
lines changed

6 files changed

+128
-83
lines changed

src/components/App.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ const App = () => {
1919
{ path: 'settings', component: SettingsPage },
2020
{ path: 'section/:id', component: ListingPage },
2121
{ path: 'migrate', component: Migrate },
22-
{ path: 'permission_settings', component: PermissionSettingsDemo },
23-
{ path: '*', component: NotFound },
22+
// permission_settings route removed - Pro handles this via manager/:id
2423
];
2524

2625
routes = wp.hooks.applyFilters('wedocs_register_menu_routes', routes);
26+
27+
// Add wildcard NotFound route LAST so it doesn't catch Pro routes
28+
routes.push({ path: '*', component: NotFound });
2729
const router = createHashRouter(
2830
createRoutesFromElements(
2931
<>

src/components/PermissionSettingsDemo/PrivacySettings.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Badge from '../ProPreviews/common/Badge';
44
import UpgradePopup from '../ProPreviews/common/UpgradePopup';
55

66
const PrivacySettings = ( ) => {
7+
// Check if Pro is loaded dynamically
8+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
79

810
return (
911
<div className="privacy-settings mt-8">
@@ -19,12 +21,10 @@ const PrivacySettings = ( ) => {
1921
<input
2022
id="public"
2123
type="radio"
22-
name="publish"
23-
24-
defaultChecked={ true }
25-
className=
26-
'checked:!border-transparent checked:!bg-indigo-600 !mt-[.2rem] before:!bg-white before:!w-1.5 before:!h-1.5 before:!mt-1 before:!ml-1 place-content-center'
27-
24+
name="privacy"
25+
value="public"
26+
defaultChecked={ true }
27+
className='checked:!border-transparent checked:!bg-indigo-600 !mt-[.2rem] before:!bg-white before:!w-1.5 before:!h-1.5 before:!mt-1 before:!ml-1 place-content-center'
2828
/>
2929
<div className="ml-2 text-sm">
3030
<label
@@ -42,19 +42,29 @@ const PrivacySettings = ( ) => {
4242
</div>
4343
</div>
4444
<div className="field flex">
45-
<UpgradePopup>
46-
<input
47-
id="privacy"
48-
name="private"
49-
type="radio"
50-
className='!bg-transparent !border-[#8c8f94]
51-
!mt-[.2rem] before:!bg-white before:!w-1.5 before:!h-1.5 before:!mt-1 before:!ml-1 place-content-center'
52-
/>
53-
</UpgradePopup>
45+
{isProLoaded ? (
46+
<input
47+
id="private"
48+
name="privacy"
49+
type="radio"
50+
value="private"
51+
className='checked:!border-transparent checked:!bg-indigo-600 !mt-[.2rem] before:!bg-white before:!w-1.5 before:!h-1.5 before:!mt-1 before:!ml-1 place-content-center'
52+
/>
53+
) : (
54+
<UpgradePopup>
55+
<input
56+
id="private"
57+
name="privacy"
58+
type="radio"
59+
value="private"
60+
className='!bg-transparent !border-[#8c8f94] !mt-[.2rem] before:!bg-white before:!w-1.5 before:!h-1.5 before:!mt-1 before:!ml-1 place-content-center'
61+
/>
62+
</UpgradePopup>
63+
)}
5464

5565
<div className="ml-2 text-sm">
5666
<label
57-
htmlFor="privacy"
67+
htmlFor="private"
5868
className="font-medium text-gray-700 relative"
5969
>
6070
{ __( 'Private', 'wedocs' ) }
@@ -64,7 +74,9 @@ const PrivacySettings = ( ) => {
6474
'wedocs'
6575
) }
6676
</p>
67-
<Badge position='absolute' top="-5px" left="45px" heading="Permission Management is a Premium Feature" description="To see who contributed to the documents, you must upgrade to the pro edition."/>
77+
{!isProLoaded && (
78+
<Badge position='absolute' top="-5px" left="45px" heading="Permission Management is a Premium Feature" description="To see who contributed to the documents, you must upgrade to the pro edition."/>
79+
)}
6880
</label>
6981
</div>
7082
</div>

src/components/ProPreviews/index.js

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ import PreferenceSettings from './AssistantWidgetPanels/PreferencePanel';
1212
import SocialShareSettings from './SocialShareSettings';
1313
import Badge from './common/Badge';
1414

15-
const isProLoaded = wp.hooks.applyFilters(
16-
'wedocs_pro_loaded',
17-
false
18-
);
19-
20-
if ( !isProLoaded ) {
21-
wp.hooks.addFilter(
22-
'wedocs_settings_menu',
23-
'settings_menu_override',
24-
function ( menus ) {
15+
wp.hooks.addFilter(
16+
'wedocs_settings_menu',
17+
'wedocs_free_settings_menu_preview',
18+
function ( menus ) {
19+
// Check if Pro is loaded dynamically
20+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
21+
if (isProLoaded) return menus;
2522
menus.permission = {
2623
pro: true,
2724
text: __( 'Permission Management', 'wedocs' ),
@@ -168,14 +165,19 @@ if ( !isProLoaded ) {
168165
};
169166

170167
return menus;
171-
}
168+
},
169+
5
172170
);
173171

174-
wp.hooks.addFilter(
175-
'wedocs_settings_page_templates',
176-
'wedocs_settings_page_templates_callback',
177-
function ( templates, docSettings, setDocSettings, index ) {
178-
const assistantWidgetSubPanels = [
172+
wp.hooks.addFilter(
173+
'wedocs_settings_page_templates',
174+
'wedocs_free_settings_page_templates_preview',
175+
function ( templates, docSettings, setDocSettings, index ) {
176+
// Check if Pro is loaded dynamically
177+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
178+
if (isProLoaded) return templates;
179+
180+
const assistantWidgetSubPanels = [
179181
<AiChatBotSettings key={ index } />,
180182
<ExploreSettings key={ index } />,
181183
<MessageSettings key={ index } />,
@@ -202,23 +204,29 @@ if ( !isProLoaded ) {
202204
setSettings={ setDocSettings }
203205
/>,
204206
];
205-
}
207+
},
208+
5
206209
);
207210

208-
wp.hooks.addFilter(
209-
'wedocs_admin_article_restriction_action',
210-
'wedocs_admin_article_restriction_action_callback',
211-
function ( componentsArray, id, type ) {
212-
return (
211+
wp.hooks.addFilter(
212+
'wedocs_admin_article_restriction_action',
213+
'wedocs_free_article_restriction_preview',
214+
function ( componentsArray, id, type ) {
215+
// Check if Pro is loaded dynamically
216+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
217+
if (isProLoaded) return componentsArray;
218+
219+
return (
213220
<>
214221
{ userIsAdmin() && (
215222
<>
216223
{ type === 'doc' && (
217-
<a href={`${weDocsAdminVars.weDocsUrl}permission_settings`} className="group flex items-center py-2 px-4 text-sm font-medium text-gray-700 hover:bg-indigo-700 hover:text-white !shadow-none">
218-
<span>{ __( 'Permission Management', 'wedocs' ) }</span>
219-
<span className={ `crown cursor-pointer relative text-white text-[10px] py-[3px] px-[5px] leading-none ml-2.5` }>
224+
<UpgradePopup>
225+
<span className="group flex items-center py-2 px-4 text-sm font-medium text-gray-700 hover:bg-indigo-700 hover:text-white !shadow-none cursor-pointer">
226+
<span>{ __( 'Permission Management', 'wedocs' ) }</span>
227+
<Badge classes="opacity-0 group-hover:opacity-100 transition-opacity ml-2"/>
220228
</span>
221-
</a>
229+
</UpgradePopup>
222230
) }
223231
{ type === 'article' && (
224232

@@ -233,39 +241,57 @@ if ( !isProLoaded ) {
233241
) }
234242
</>
235243
);
236-
}
244+
},
245+
5
237246
);
238247

239-
wp.hooks.addFilter(
240-
'wedocs_documentation_contributors',
241-
'wedocs_documentation_contributors_callback',
242-
function () {
243-
if ( !userIsAdmin() ) return;
244-
if(!isProLoaded) return;
245-
246-
return <Contributors />;
247-
}
248-
);
248+
wp.hooks.addFilter(
249+
'wedocs_documentation_contributors',
250+
'wedocs_free_documentation_contributors_preview',
251+
function () {
252+
// Check if Pro is loaded dynamically
253+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
254+
if (isProLoaded) return;
255+
if ( !userIsAdmin() ) return;
249256

250-
wp.hooks.addFilter(
251-
'wedocs_article_contributors',
252-
'wedocs_article_contributors_callback',
253-
function () {
254-
if ( !userIsAdmin() ) return;
255-
if(!isProLoaded) return;
257+
return <Contributors />;
258+
},
259+
5
260+
);
256261

257-
return <Contributors />;
258-
}
259-
);
262+
wp.hooks.addFilter(
263+
'wedocs_article_contributors',
264+
'wedocs_free_article_contributors_preview',
265+
function () {
266+
// Check if Pro is loaded dynamically
267+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
268+
if (isProLoaded) return;
269+
if ( !userIsAdmin() ) return;
260270

271+
return <Contributors />;
272+
},
273+
5
274+
);
261275

262276
wp.hooks.addFilter(
263-
'wedocs_register_menu_routes',
264-
'wedocs_register_menu_routes_callback',
265-
function ( routes ) {
266-
const { weDocsSettingsPage: SettingsPage } = window;
267-
routes?.push( { path: 'settings/:panel', component: SettingsPage } );
268-
return routes;
269-
}
277+
'wedocs_article_restriction_menu',
278+
'wedocs_free_article_restriction_menu_preview',
279+
function ( menu ) {
280+
// Check if Pro is loaded dynamically
281+
const isProLoaded = wp.hooks.applyFilters('wedocs_pro_loaded', false);
282+
if (isProLoaded) return menu;
283+
284+
// Return PRO preview menu when Pro is not loaded
285+
return (
286+
<UpgradePopup>
287+
<a
288+
href="#"
289+
className="group flex items-center py-2 px-4 text-sm font-medium text-gray-700 hover:bg-indigo-700 hover:text-white !shadow-none"
290+
>
291+
<span>{ __( 'Permission Management', 'wedocs' ) }</span>
292+
</a>
293+
</UpgradePopup>
294+
);
295+
},
296+
5
270297
);
271-
}

src/data/docs/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const actions = {
7979
*updateDoc( docId, data ) {
8080
const getDocsPath = wp.hooks.applyFilters(
8181
'wedocs_documentation_fetching_path',
82-
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft' : ''}`
82+
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft,private' : ''}`
8383
);
8484
const path = '/wp/v2/docs/' + docId;
8585
yield { type: 'UPDATE_TO_API', path, data };
@@ -141,7 +141,7 @@ const actions = {
141141
*updateParentDocs() {
142142
const getDocsPath = wp.hooks.applyFilters(
143143
'wedocs_documentation_fetching_path',
144-
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft' : ''}`
144+
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft,private' : ''}`
145145
);
146146

147147
const response = yield actions.fetchFromAPI( getDocsPath );

src/data/docs/resolvers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import actions from './actions';
22

3-
const getDocsPath = wp.hooks.applyFilters(
4-
'wedocs_documentation_fetching_path',
5-
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft' : ''}`
6-
);
7-
83
const resolvers = {
94
*getDocs() {
5+
// Compute path at runtime to ensure Pro filters are applied
6+
const getDocsPath = wp.hooks.applyFilters(
7+
'wedocs_documentation_fetching_path',
8+
`/wp/v2/docs?per_page=-1&status=publish${ typeof weDocsAdminVars !== 'undefined' ? ',draft,private' : ''}`
9+
);
10+
1011
yield actions.setLoading( true );
1112
const response = yield actions.fetchFromAPI( getDocsPath );
1213
yield actions.setDocs( response );

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import './data/store';
22
import './assets/css/index.css';
33
import App from './components/App';
44
import menuFix from './utils/menuFix';
5-
import { render } from '@wordpress/element';
5+
import { createRoot } from '@wordpress/element';
66

7-
render( <App />, document.getElementById( 'wedocs-app' ) );
7+
// Wait for DOM and all scripts to be ready before rendering
8+
// This ensures Pro plugin filters are registered before App renders
89

9-
menuFix( 'wedocs' );
10+
const container = document.getElementById( 'wedocs-app' );
11+
const root = createRoot( container );
12+
root.render( <App /> );
13+
menuFix( 'wedocs' );

0 commit comments

Comments
 (0)