Skip to content

Commit

Permalink
Merge pull request #1036 from Codeinwp/fix/issue-771
Browse files Browse the repository at this point in the history
 feat: add review modal
  • Loading branch information
selul authored Dec 20, 2024
2 parents af6df21 + 956f2e9 commit f9d822a
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ js/FeedzyBlock
js/Onboarding/
js/ActionPopup/
js/FeedBack/
js/Review/
webpack.config.js
dist
cypress
Expand Down
21 changes: 21 additions & 0 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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
)
);
}
}
38 changes: 38 additions & 0 deletions includes/feedzy-rss-feeds-feed-tweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
104 changes: 104 additions & 0 deletions js/Review/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<Modal
title={ __( 'Congrats, You\'ve Reached an Impressive Milestone!', 'feedzy-rss-feeds' ) + ' 🎉' }
size="medium"
shouldCloseOnClickOutside={ false }
onRequestClose={ closeModal }
>
<p
dangerouslySetInnerHTML={{
__html: sprintf(
// translators: %1$s is an opening strong tag, %2$s is a closing strong tag, %3$s is the number of posts imported.
__(
"You've successfully imported %1$s more than %3$s posts %2$s using Feedzy!",
'feedzy-rss-feeds'
),
'<strong>', // %1$s
'</strong>', // %2$s
100 // %3$s
),
}}
/>

<p
dangerouslySetInnerHTML={{
__html: sprintf(
// translators: %1$s is an opening strong tag, %2$s is a closing strong tag, %3$s is for the 5-star rating stars.
__(
"If you're enjoying Feedzy, we'd be thrilled if you could leave us a %1$s5-star review%2$s (%3$s) on WordPress.org. Your support helps us grow and deliver even better features.",
'feedzy-rss-feeds'
),
'<strong>', // %1$s
'</strong>', // %2$s
'<span style="color:gold;">★★★★★</span>' // %3$s
),
}}
/>

<div className="buttons-wrap" style={{ display: 'flex', gap: '10px', marginTop: '20px' }}>
<Button
href="https://wordpress.org/support/plugin/feedzy-rss-feeds/reviews/#new-post"
target="_blank"
variant="primary"
className="fz-feedback-button"
style={{ borderRadius: '5px' }}
>
{ __( 'Rate Feedzy on WordPress.org', 'feedzy-rss-feeds' ) }
</Button>
</div>
</Modal>
);
};

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( <App /> );
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f9d822a

Please sign in to comment.