@@ -2160,6 +2160,7 @@ private function setup_wizard_subscribe_process() {
21602160 if ( ! is_wp_error ( $ request_res ) ) {
21612161 $ body = json_decode ( wp_remote_retrieve_body ( $ request_res ) );
21622162 if ( 'success ' === $ body ->code ) {
2163+ update_option ( 'feedzy_onboarding_user_subscribed ' , 'yes ' );
21632164 $ this ->feedzy_dismiss_wizard ( false );
21642165 wp_send_json ( $ response );
21652166 }
@@ -2172,14 +2173,14 @@ private function setup_wizard_subscribe_process() {
21722173 )
21732174 );
21742175 } else {
2175- update_option ( ' feedzy_rss_feeds_skip_subscribe ' , ' yes ' );
2176+
21762177 $ this ->feedzy_dismiss_wizard ( false );
21772178 wp_send_json ( $ response );
21782179 }
21792180 }
21802181
21812182 /**
2182- * AJAX method to subscribe user to Feedzy newsletter.
2183+ * AJAX method to subscribe user to Feedzy newsletter via dashboard notice .
21832184 *
21842185 * @since 5.1.0
21852186 * @access public
@@ -2188,40 +2189,51 @@ private function setup_wizard_subscribe_process() {
21882189 public function feedzy_dashboard_subscribe () {
21892190 check_ajax_referer ( 'feedzy_subscribe_nonce ' , '_wpnonce ' );
21902191
2191- $ with_subscribe = ! empty ( $ _POST ['with_subscribe ' ] ) ? (bool ) $ _POST ['with_subscribe ' ] : false ;
2192- $ email = ! empty ( $ _POST ['email ' ] ) ? sanitize_email ( $ _POST ['email ' ] ) : '' ;
2193- $ integrate_with = ! empty ( $ _POST ['integrate_with ' ] ) ? sanitize_text_field ( $ _POST ['integrate_with ' ] ) : '' ;
2194-
2195- if ( $ with_subscribe && is_email ( $ email ) ) {
2196- update_option ( 'feedzy_rss_feeds_logger_flag ' , 'yes ' );
2197-
2198- $ request_res = wp_remote_post (
2199- FEEDZY_SUBSCRIBE_API ,
2192+ $ email = ! empty ( $ _POST ['email ' ] ) ? sanitize_email ( $ _POST ['email ' ] ) : '' ;
2193+ $ skip = ! empty ( $ _POST ['skip ' ] ) ? sanitize_text_field ( wp_unslash ( $ _POST ['skip ' ] ) ) : '' ;
2194+
2195+ if ( 'yes ' === $ skip ) {
2196+ $ this ->dismiss_subscribe_notice ();
2197+ wp_send_json_success ();
2198+ }
2199+
2200+ if ( empty ( $ email ) || ! is_email ( $ email ) ) {
2201+ wp_send_json_error (
22002202 array (
2201- 'timeout ' => 100 , // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
2202- 'headers ' => array (
2203- 'Content-Type ' => 'application/json ' ,
2204- ),
2205- 'body ' => wp_json_encode (
2206- array (
2207- 'slug ' => 'feedzy-rss-feeds ' ,
2208- 'site ' => home_url (),
2209- 'email ' => $ email ,
2210- 'data ' => array ( 'integration ' => $ integrate_with ),
2211- )
2212- ),
2203+ 'message ' => __ ( 'Validation failed ' , 'feedzy-rss-feeds ' ),
22132204 )
22142205 );
2215-
2216- if ( ! is_wp_error ( $ request_res ) ) {
2217- $ this ->dismiss_subscribe_notice ();
2218- wp_send_json_success ();
2219- } else {
2220- wp_send_json_error ();
2221- }
2222- } else {
2206+ }
2207+
2208+ update_option ( 'feedzy_rss_feeds_logger_flag ' , 'yes ' );
2209+
2210+ $ request_res = wp_remote_post (
2211+ FEEDZY_SUBSCRIBE_API ,
2212+ array (
2213+ 'timeout ' => 100 , // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
2214+ 'headers ' => array (
2215+ 'Content-Type ' => 'application/json ' ,
2216+ ),
2217+ 'body ' => wp_json_encode (
2218+ array (
2219+ 'slug ' => 'feedzy-rss-feeds ' ,
2220+ 'site ' => home_url (),
2221+ 'email ' => $ email ,
2222+ 'data ' => array ( 'source ' => 'dashboard-notice ' ),
2223+ )
2224+ ),
2225+ )
2226+ );
2227+
2228+ if ( ! is_wp_error ( $ request_res ) ) {
22232229 $ this ->dismiss_subscribe_notice ();
22242230 wp_send_json_success ();
2231+ } else {
2232+ wp_send_json_error (
2233+ array (
2234+ 'message ' => $ request_res ->get_error_message (),
2235+ )
2236+ );
22252237 }
22262238 }
22272239
@@ -2233,7 +2245,7 @@ public function feedzy_dashboard_subscribe() {
22332245 * @return void
22342246 */
22352247 public function dismiss_subscribe_notice () {
2236- update_option ( 'feedzy_rss_feeds_dismiss_subscribe_notice ' , 'yes ' );
2248+ update_option ( 'feedzy_dismiss_subscribe_notice_dashboard ' , 'yes ' );
22372249 }
22382250
22392251 /**
0 commit comments