Skip to content

Commit 5f704b5

Browse files
authored
Merge pull request #5282 from Automattic/fix/woothemes-sensei-detection
2 parents 4a70b24 + 6ef29d3 commit 5f704b5

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

assets/admin/editor-wizard/helpers.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { useSelect, useDispatch } from '@wordpress/data';
55
import { useEffect, useLayoutEffect, useState } from '@wordpress/element';
66
import { store as blockEditorStore } from '@wordpress/block-editor';
77
import { store as editorStore } from '@wordpress/editor';
8+
import { applyFilters } from '@wordpress/hooks';
9+
10+
/**
11+
* Internal dependencies
12+
*/
13+
import { EXTENSIONS_STORE } from '../../extensions/store';
814

915
/**
1016
* Update blocks content, replacing the placeholders with a content.
@@ -149,3 +155,32 @@ export const useLogEvent = () => {
149155
} );
150156
};
151157
};
158+
159+
/**
160+
* Hook to check if Sensei Pro is enabled or not, and hide the editor wizard accordingly.
161+
*
162+
* @return {boolean} If the editor wizard upsell should be hidden or not.
163+
*/
164+
export const useHideEditorWizardUpsell = () => {
165+
const { senseiProExtension } = useSelect(
166+
( select ) => ( {
167+
senseiProExtension: select(
168+
EXTENSIONS_STORE
169+
).getSenseiProExtension(),
170+
} ),
171+
[]
172+
);
173+
174+
/**
175+
* Filters if the editor wizard upsells should show or not
176+
*
177+
* @since 4.1.0
178+
*
179+
* @param {boolean} hideEditorWizardUpsell Whether to hide the editor wizard upsells.
180+
* @return {boolean} Whether to hide the editor wizard upsells.
181+
*/
182+
return applyFilters(
183+
'senseiEditorWizardUpsellHide',
184+
! senseiProExtension || senseiProExtension.is_activated === true
185+
);
186+
};

assets/admin/editor-wizard/steps/lesson-patterns-step.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
* WordPress dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { useSelect } from '@wordpress/data';
65
import { Fragment } from '@wordpress/element';
76

87
/**
98
* Internal dependencies
109
*/
1110
import PatternsStep from './patterns-step';
1211
import LogoTreeIcon from '../../../icons/logo-tree.svg';
13-
import { EXTENSIONS_STORE } from '../../../extensions/store';
12+
import { useHideEditorWizardUpsell } from '../helpers';
1413

1514
/**
1615
* Lesson patterns step.
@@ -19,23 +18,13 @@ import { EXTENSIONS_STORE } from '../../../extensions/store';
1918
* @param {Object} props.wizardData Wizard data.
2019
*/
2120
const LessonPatternsStep = ( { wizardData, ...props } ) => {
22-
const { senseiProExtension } = useSelect(
23-
( select ) => ( {
24-
senseiProExtension: select(
25-
EXTENSIONS_STORE
26-
).getSenseiProExtension(),
27-
} ),
28-
[]
29-
);
30-
3121
const replaces = {};
3222

3323
if ( wizardData.title ) {
3424
replaces[ 'sensei-content-title' ] = wizardData.title;
3525
}
3626

37-
const isSenseiProActivated =
38-
! senseiProExtension || senseiProExtension.is_activated === true;
27+
const shouldHideEditorWizardUpsell = useHideEditorWizardUpsell();
3928

4029
return (
4130
<Fragment>
@@ -45,7 +34,7 @@ const LessonPatternsStep = ( { wizardData, ...props } ) => {
4534
{ ...props }
4635
/>
4736
<PatternsStep.UpsellFill>
48-
{ isSenseiProActivated ? null : <UpsellBlock /> }
37+
{ shouldHideEditorWizardUpsell ? null : <UpsellBlock /> }
4938
</PatternsStep.UpsellFill>
5039
</Fragment>
5140
);

assets/admin/editor-wizard/use-editor-wizard-steps.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CourseUpgradeStep from './steps/course-upgrade-step';
1212
import CoursePatternsStep from './steps/course-patterns-step';
1313
import LessonDetailsStep from './steps/lesson-details-step';
1414
import LessonPatternsStep from './steps/lesson-patterns-step';
15-
import { EXTENSIONS_STORE } from '../../extensions/store';
15+
import { useHideEditorWizardUpsell } from './helpers';
1616

1717
/**
1818
* Returns the list of components (representing steps) for the Editor Wizard according to the post type and if
@@ -25,17 +25,16 @@ const useEditorWizardSteps = () => {
2525
course: [ CourseDetailsStep, CourseUpgradeStep, CoursePatternsStep ],
2626
lesson: [ LessonDetailsStep, LessonPatternsStep ],
2727
};
28-
const { postType, senseiProExtension } = useSelect(
28+
const { postType } = useSelect(
2929
( select ) => ( {
3030
postType: select( editorStore )?.getCurrentPostType(),
31-
senseiProExtension: select(
32-
EXTENSIONS_STORE
33-
).getSenseiProExtension(),
3431
} ),
3532
[]
3633
);
3734

38-
if ( ! senseiProExtension || senseiProExtension.is_activated === true ) {
35+
const shouldHideEditorWizardUpsell = useHideEditorWizardUpsell();
36+
37+
if ( shouldHideEditorWizardUpsell ) {
3938
stepsByPostType.course = stepsByPostType.course.filter(
4039
( step ) => step !== CourseUpgradeStep
4140
);

0 commit comments

Comments
 (0)