diff --git a/.distignore b/.distignore index 2f996a02..f6d0eb29 100755 --- a/.distignore +++ b/.distignore @@ -21,6 +21,7 @@ js/FeedzyBlock js/Onboarding/ js/ActionPopup/ js/FeedBack/ +js/Review/ webpack.config.js dist cypress diff --git a/includes/admin/feedzy-rss-feeds-admin.php b/includes/admin/feedzy-rss-feeds-admin.php index c6f7ed23..08d01d70 100644 --- a/includes/admin/feedzy-rss-feeds-admin.php +++ b/includes/admin/feedzy-rss-feeds-admin.php @@ -247,6 +247,12 @@ public function enqueue_styles_admin() { wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' ); } + if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base && feedzy_show_review_notice() ) { + $asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php'; + wp_enqueue_script( $this->plugin_name . '_review', FEEDZY_ABSURL . 'build/review/index.js', $asset_file['dependencies'], $asset_file['version'], true ); + wp_set_script_translations( $this->plugin_name . '_review', 'feedzy-rss-feeds' ); + } + wp_enqueue_style( $this->plugin_name . '-settings', FEEDZY_ABSURL . 'css/settings.css', array(), $this->version ); wp_enqueue_style( $this->plugin_name . '-metabox', FEEDZY_ABSURL . 'css/metabox-settings.css', array( $this->plugin_name . '-settings' ), $this->version ); } @@ -1968,4 +1974,19 @@ public function get_lang_list() { return $target_lang; } + + /** + * Register settings. + */ + public function register_settings() { + register_setting( + 'feedzy', + 'feedzy_review_notice', + array( + 'type' => 'string', + 'default' => 'no', + 'show_in_rest' => true + ) + ); + } } diff --git a/includes/feedzy-rss-feeds-feed-tweaks.php b/includes/feedzy-rss-feeds-feed-tweaks.php index 5b536e3e..5302fa86 100644 --- a/includes/feedzy-rss-feeds-feed-tweaks.php +++ b/includes/feedzy-rss-feeds-feed-tweaks.php @@ -567,3 +567,41 @@ function feedzy_show_import_tour() { } return false; } + +/** + * Show review notice. + * + * @return bool + */ +function feedzy_show_review_notice() { + $has_dismissed = get_option( 'feedzy_review_notice', 'no' ); + + if ( 'yes' === $has_dismissed ) { + return false; + } + + $install_date = get_option( 'feedzy_rss_feeds_install', 0 ); + $days_since = ( time() - $install_date ) / DAY_IN_SECONDS; + + if ( $days_since < 7 ) { + return false; + } + + $args = array( + 'post_type' => 'feedzy_imports', + 'post_status' => 'publish', + 'posts_per_page' => 1, + 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + array( + 'key' => 'imported_items_count', + 'value' => 100, + 'type' => 'numeric', + 'compare' => '>=' + ) + ) + ); + + $imported_posts = new WP_Query( $args ); + + return $imported_posts->have_posts(); +} diff --git a/includes/feedzy-rss-feeds.php b/includes/feedzy-rss-feeds.php index 9369c298..e24c781c 100644 --- a/includes/feedzy-rss-feeds.php +++ b/includes/feedzy-rss-feeds.php @@ -200,6 +200,7 @@ private function define_admin_hooks() { self::$instance->loader->add_filter( 'feedzy_get_source_validity_error', self::$instance->admin, 'get_source_validity_error', 10, 3 ); self::$instance->loader->add_filter( 'post_row_actions', self::$instance->admin, 'add_feedzy_category_actions', 10, 2 ); self::$instance->loader->add_filter( 'admin_footer', self::$instance->admin, 'handle_upgrade_submenu' ); + self::$instance->loader->add_action( 'init', self::$instance->admin, 'register_settings' ); // do not load this with the loader as this will need a corresponding remove_filter also. add_filter( 'update_post_metadata', array( self::$instance->admin, 'validate_category_feeds' ), 10, 5 ); diff --git a/js/Review/index.js b/js/Review/index.js new file mode 100644 index 00000000..40bb3afd --- /dev/null +++ b/js/Review/index.js @@ -0,0 +1,104 @@ +/** + * WordPress dependencies. + */ +import { + __, + sprintf +} from '@wordpress/i18n'; + +import apiFetch from '@wordpress/api-fetch'; + +import domReady from '@wordpress/dom-ready'; + +import { + Button, + Modal +} from '@wordpress/components'; + +import { + createRoot, + useState +} from '@wordpress/element'; + +const App = () => { + const [ isOpen, setOpen ] = useState( true ); + + const closeModal = async () => { + try { + await apiFetch({ + path: '/wp/v2/settings', + method: 'POST', + data: { + feedzy_review_notice: 'yes', + }, + }); + } catch ( error ) { + console.error( __( 'Error updating setting:', 'feedzy-rss-feeds' ), error ); + } finally { + setOpen( false ); + } + }; + + if ( ! isOpen ) { + return null; + } + + return ( + +

', // %1$s + '', // %2$s + 100 // %3$s + ), + }} + /> + +

', // %1$s + '', // %2$s + '★★★★★' // %3$s + ), + }} + /> + +

+ +
+
+ ); +}; + +domReady( () => { + const modalContainer = document.createElement( 'div' ); + modalContainer.id = 'fz-review-modal'; + document.body.appendChild( modalContainer ); + const root = createRoot( document.getElementById( 'fz-review-modal' ) ); + root.render( ); +}); diff --git a/package.json b/package.json index 894d8314..23427e01 100755 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "build:onboarding": "wp-scripts build --webpack-src-dir=js/Onboarding --output-path=build/onboarding --output-filename=index.js", "build:feedback": "wp-scripts build --webpack-src-dir=js/FeedBack --output-path=build/feedback --output-filename=index.js", "build:actions": "wp-scripts build --webpack-src-dir=js/ActionPopup --output-path=build/action-popup --output-filename=index.js", + "build:review": "wp-scripts build --webpack-src-dir=js/Review --output-path=build/review --output-filename=index.js", "dev": "npm-run-all --parallel dev:*", "dev:block": "wp-scripts start --webpack-src-dir=js/FeedzyBlock --output-path=build/block --output-filename=index.js", "dev:onboarding": "wp-scripts start --webpack-src-dir=js/Onboarding --output-path=build/onboarding --output-filename=index.js",