Skip to content

Commit f9d822a

Browse files
authored
Merge pull request #1036 from Codeinwp/fix/issue-771
feat: add review modal
2 parents af6df21 + 956f2e9 commit f9d822a

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ js/FeedzyBlock
2121
js/Onboarding/
2222
js/ActionPopup/
2323
js/FeedBack/
24+
js/Review/
2425
webpack.config.js
2526
dist
2627
cypress

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ public function enqueue_styles_admin() {
247247
wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' );
248248
}
249249

250+
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base && feedzy_show_review_notice() ) {
251+
$asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php';
252+
wp_enqueue_script( $this->plugin_name . '_review', FEEDZY_ABSURL . 'build/review/index.js', $asset_file['dependencies'], $asset_file['version'], true );
253+
wp_set_script_translations( $this->plugin_name . '_review', 'feedzy-rss-feeds' );
254+
}
255+
250256
wp_enqueue_style( $this->plugin_name . '-settings', FEEDZY_ABSURL . 'css/settings.css', array(), $this->version );
251257
wp_enqueue_style( $this->plugin_name . '-metabox', FEEDZY_ABSURL . 'css/metabox-settings.css', array( $this->plugin_name . '-settings' ), $this->version );
252258
}
@@ -1968,4 +1974,19 @@ public function get_lang_list() {
19681974

19691975
return $target_lang;
19701976
}
1977+
1978+
/**
1979+
* Register settings.
1980+
*/
1981+
public function register_settings() {
1982+
register_setting(
1983+
'feedzy',
1984+
'feedzy_review_notice',
1985+
array(
1986+
'type' => 'string',
1987+
'default' => 'no',
1988+
'show_in_rest' => true
1989+
)
1990+
);
1991+
}
19711992
}

includes/feedzy-rss-feeds-feed-tweaks.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,41 @@ function feedzy_show_import_tour() {
567567
}
568568
return false;
569569
}
570+
571+
/**
572+
* Show review notice.
573+
*
574+
* @return bool
575+
*/
576+
function feedzy_show_review_notice() {
577+
$has_dismissed = get_option( 'feedzy_review_notice', 'no' );
578+
579+
if ( 'yes' === $has_dismissed ) {
580+
return false;
581+
}
582+
583+
$install_date = get_option( 'feedzy_rss_feeds_install', 0 );
584+
$days_since = ( time() - $install_date ) / DAY_IN_SECONDS;
585+
586+
if ( $days_since < 7 ) {
587+
return false;
588+
}
589+
590+
$args = array(
591+
'post_type' => 'feedzy_imports',
592+
'post_status' => 'publish',
593+
'posts_per_page' => 1,
594+
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
595+
array(
596+
'key' => 'imported_items_count',
597+
'value' => 100,
598+
'type' => 'numeric',
599+
'compare' => '>='
600+
)
601+
)
602+
);
603+
604+
$imported_posts = new WP_Query( $args );
605+
606+
return $imported_posts->have_posts();
607+
}

includes/feedzy-rss-feeds.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ private function define_admin_hooks() {
200200
self::$instance->loader->add_filter( 'feedzy_get_source_validity_error', self::$instance->admin, 'get_source_validity_error', 10, 3 );
201201
self::$instance->loader->add_filter( 'post_row_actions', self::$instance->admin, 'add_feedzy_category_actions', 10, 2 );
202202
self::$instance->loader->add_filter( 'admin_footer', self::$instance->admin, 'handle_upgrade_submenu' );
203+
self::$instance->loader->add_action( 'init', self::$instance->admin, 'register_settings' );
203204

204205
// do not load this with the loader as this will need a corresponding remove_filter also.
205206
add_filter( 'update_post_metadata', array( self::$instance->admin, 'validate_category_feeds' ), 10, 5 );

js/Review/index.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import {
5+
__,
6+
sprintf
7+
} from '@wordpress/i18n';
8+
9+
import apiFetch from '@wordpress/api-fetch';
10+
11+
import domReady from '@wordpress/dom-ready';
12+
13+
import {
14+
Button,
15+
Modal
16+
} from '@wordpress/components';
17+
18+
import {
19+
createRoot,
20+
useState
21+
} from '@wordpress/element';
22+
23+
const App = () => {
24+
const [ isOpen, setOpen ] = useState( true );
25+
26+
const closeModal = async () => {
27+
try {
28+
await apiFetch({
29+
path: '/wp/v2/settings',
30+
method: 'POST',
31+
data: {
32+
feedzy_review_notice: 'yes',
33+
},
34+
});
35+
} catch ( error ) {
36+
console.error( __( 'Error updating setting:', 'feedzy-rss-feeds' ), error );
37+
} finally {
38+
setOpen( false );
39+
}
40+
};
41+
42+
if ( ! isOpen ) {
43+
return null;
44+
}
45+
46+
return (
47+
<Modal
48+
title={ __( 'Congrats, You\'ve Reached an Impressive Milestone!', 'feedzy-rss-feeds' ) + ' 🎉' }
49+
size="medium"
50+
shouldCloseOnClickOutside={ false }
51+
onRequestClose={ closeModal }
52+
>
53+
<p
54+
dangerouslySetInnerHTML={{
55+
__html: sprintf(
56+
// translators: %1$s is an opening strong tag, %2$s is a closing strong tag, %3$s is the number of posts imported.
57+
__(
58+
"You've successfully imported %1$s more than %3$s posts %2$s using Feedzy!",
59+
'feedzy-rss-feeds'
60+
),
61+
'<strong>', // %1$s
62+
'</strong>', // %2$s
63+
100 // %3$s
64+
),
65+
}}
66+
/>
67+
68+
<p
69+
dangerouslySetInnerHTML={{
70+
__html: sprintf(
71+
// translators: %1$s is an opening strong tag, %2$s is a closing strong tag, %3$s is for the 5-star rating stars.
72+
__(
73+
"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.",
74+
'feedzy-rss-feeds'
75+
),
76+
'<strong>', // %1$s
77+
'</strong>', // %2$s
78+
'<span style="color:gold;">★★★★★</span>' // %3$s
79+
),
80+
}}
81+
/>
82+
83+
<div className="buttons-wrap" style={{ display: 'flex', gap: '10px', marginTop: '20px' }}>
84+
<Button
85+
href="https://wordpress.org/support/plugin/feedzy-rss-feeds/reviews/#new-post"
86+
target="_blank"
87+
variant="primary"
88+
className="fz-feedback-button"
89+
style={{ borderRadius: '5px' }}
90+
>
91+
{ __( 'Rate Feedzy on WordPress.org', 'feedzy-rss-feeds' ) }
92+
</Button>
93+
</div>
94+
</Modal>
95+
);
96+
};
97+
98+
domReady( () => {
99+
const modalContainer = document.createElement( 'div' );
100+
modalContainer.id = 'fz-review-modal';
101+
document.body.appendChild( modalContainer );
102+
const root = createRoot( document.getElementById( 'fz-review-modal' ) );
103+
root.render( <App /> );
104+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"build:onboarding": "wp-scripts build --webpack-src-dir=js/Onboarding --output-path=build/onboarding --output-filename=index.js",
2323
"build:feedback": "wp-scripts build --webpack-src-dir=js/FeedBack --output-path=build/feedback --output-filename=index.js",
2424
"build:actions": "wp-scripts build --webpack-src-dir=js/ActionPopup --output-path=build/action-popup --output-filename=index.js",
25+
"build:review": "wp-scripts build --webpack-src-dir=js/Review --output-path=build/review --output-filename=index.js",
2526
"dev": "npm-run-all --parallel dev:*",
2627
"dev:block": "wp-scripts start --webpack-src-dir=js/FeedzyBlock --output-path=build/block --output-filename=index.js",
2728
"dev:onboarding": "wp-scripts start --webpack-src-dir=js/Onboarding --output-path=build/onboarding --output-filename=index.js",

0 commit comments

Comments
 (0)