diff --git a/includes/admin/feedzy-rss-feeds-admin.php b/includes/admin/feedzy-rss-feeds-admin.php index d2485023..9f541862 100644 --- a/includes/admin/feedzy-rss-feeds-admin.php +++ b/includes/admin/feedzy-rss-feeds-admin.php @@ -183,7 +183,7 @@ public function enqueue_styles_admin() { ); wp_enqueue_style( 'wp-block-editor' ); } - if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && get_option( 'feedzy_import_tour' ) ) ) { + if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) { wp_enqueue_script( $this->plugin_name . '_on_boarding', FEEDZY_ABSURL . 'js/Onboarding/import-onboarding.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true ); } diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index 0542084f..40f0d0b9 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -259,24 +259,26 @@ public function register_import_post_type() { $args = apply_filters( 'feedzy_imports_args', $args ); register_post_type( 'feedzy_imports', $args ); - // Register setting field. - register_setting( - 'feedzy_import_tour_settings', + // Register user meta field. + register_meta( + 'user', 'feedzy_import_tour', array( 'type' => 'boolean', 'description' => __( 'Show tour for Feedzy.', 'feedzy-rss-feeds' ), 'show_in_rest' => true, + 'single' => true, 'default' => true, ) ); - register_setting( - 'feedzy_import_actions_settings', + register_meta( + 'user', 'feedzy_hide_action_message', array( 'type' => 'boolean', 'description' => __( 'Show intro message for Feedzy action popup.', 'feedzy-rss-feeds' ), 'show_in_rest' => true, + 'single' => true, 'default' => false, ) ); diff --git a/includes/admin/feedzy-rss-feeds-ui.php b/includes/admin/feedzy-rss-feeds-ui.php index 3bd7859b..58866477 100644 --- a/includes/admin/feedzy-rss-feeds-ui.php +++ b/includes/admin/feedzy-rss-feeds-ui.php @@ -83,7 +83,7 @@ private function is_block_editor() { */ public function register_init() { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison - if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) { + if ( feedzy_current_user_can() && 'true' == get_user_option( 'rich_editing' ) ) { $this->loader->add_filter( 'mce_external_plugins', $this, 'feedzy_tinymce_plugin', 10, 1 ); $this->loader->add_filter( 'mce_buttons', $this, 'feedzy_register_mce_button', 10, 1 ); $this->loader->add_filter( 'mce_external_languages', $this, 'feedzy_add_tinymce_lang', 10, 1 ); diff --git a/includes/feedzy-rss-feeds-feed-tweaks.php b/includes/feedzy-rss-feeds-feed-tweaks.php index 21fa6ebe..6bd8198a 100644 --- a/includes/feedzy-rss-feeds-feed-tweaks.php +++ b/includes/feedzy-rss-feeds-feed-tweaks.php @@ -534,20 +534,13 @@ function feedzy_current_user_can() { } /** - * Handle user capability. + * Show import tour. + * + * @return bool */ -function feedzy_handle_user_cap() { - add_filter( - 'user_has_cap', - function ( $allcaps, $caps, $args, $user ) { - $capability = apply_filters( 'feedzy_admin_menu_capability', 'publish_posts' ); - if ( ! empty( $allcaps[ $capability ] ) ) { - $allcaps['manage_options'] = ! empty( $allcaps[ $capability ] ); - } - return $allcaps; - }, - 10, - 4 - ); +function feedzy_show_import_tour() { + if ( is_user_logged_in() && 'no' === get_option( 'feedzy_import_tour', 'no' ) ) { + return get_user_meta( get_current_user_id(), 'feedzy_import_tour', true ); + } + return false; } -add_action( 'rest_api_init', 'feedzy_handle_user_cap' ); diff --git a/includes/views/import-metabox-edit.php b/includes/views/import-metabox-edit.php index 6a699670..4a7490ac 100644 --- a/includes/views/import-metabox-edit.php +++ b/includes/views/import-metabox-edit.php @@ -8,7 +8,7 @@ global $post; ?> - +
diff --git a/js/ActionPopup/action-popup.js b/js/ActionPopup/action-popup.js index 6a7bdf24..3693441c 100644 --- a/js/ActionPopup/action-popup.js +++ b/js/ActionPopup/action-popup.js @@ -29,7 +29,7 @@ import { const ActionModal = () => { // useRef - const settingsRef = useRef(null); + const userRef = useRef(null); const feedzyImportRef = useRef(null); // State const [ isOpen, setOpen ] = useState(false); @@ -41,9 +41,9 @@ const ActionModal = () => { useEffect( () => { window.wp.api.loadPromise.then( () => { - // Fetch settings. - settingsRef.current = new window.wp.api.models.Settings(); - settingsRef.current.fetch(); + // Fetch user. + userRef.current = new window.wp.api.models.User( { id: 'me' } ); + userRef.current.fetch(); }); }, []); @@ -104,15 +104,18 @@ const ActionModal = () => { if ( isOpen ) { hideIntroMessage(false); } - const model = new window.wp.api.models.Settings({ + const model = new window.wp.api.models.User({ // eslint-disable-next-line camelcase - feedzy_hide_action_message: true + id: 'me', + meta: { + feedzy_hide_action_message: true + } }); const save = model.save(); save.success( () => { - settingsRef.current.fetch(); + userRef.current.fetch(); }); save.error( ( response ) => { @@ -162,8 +165,8 @@ const ActionModal = () => { document.querySelectorAll( '[data-action_popup]' ).forEach( actionItem => { actionItem.addEventListener( 'click', ( event ) => { event.preventDefault(); - if ( settingsRef.current ) { - if ( ! settingsRef.current.attributes.feedzy_hide_action_message ) { + if ( userRef.current ) { + if ( ! userRef.current.attributes.meta.feedzy_hide_action_message ) { hideActionIntroMessage(); } else { hideIntroMessage(true); diff --git a/js/ActionPopup/action-popup.min.js b/js/ActionPopup/action-popup.min.js index 008c34c7..b3b09ac3 100644 --- a/js/ActionPopup/action-popup.min.js +++ b/js/ActionPopup/action-popup.min.js @@ -49,4 +49,4 @@ t.read=function(e,t,n,r,o){var i,a,c=8*o-r-1,u=(1<