diff --git a/classes/controllers/FrmDeactivationFeedbackController.php b/classes/controllers/FrmDeactivationFeedbackController.php new file mode 100644 index 0000000000..e853678224 --- /dev/null +++ b/classes/controllers/FrmDeactivationFeedbackController.php @@ -0,0 +1,131 @@ +id; + } + + /** + * Checks if feedback is expired. + * + * @return bool + */ + private static function feedback_is_expired() { + $feedback_expired = get_option( 'frm_feedback_expired' ); + if ( ! $feedback_expired ) { + return true; + } + + $expired_date = strtotime( $feedback_expired ); + if ( ! $expired_date ) { + return true; + } + + return $expired_date < time(); + } + + /** + * Sets feedback expired date. + * + * @param string $plugin Path to the plugin file relative to the plugins directory. + * + * @return void + */ + public static function set_feedback_expired_date( $plugin ) { + if ( empty( $_GET['frm_feedback_submitted'] ) ) { + return; + } + if ( ! strpos( $plugin, 'formidable.php' ) && ! strpos( $plugin, 'formidable-pro.php' ) ) { + return; + } + update_option( 'frm_feedback_expired', gmdate( 'Y-m-d', strtotime( '+ 1 day' ) ) ); + } + + /** + * Enqueues assets. + * + * @return void + */ + public static function enqueue_assets() { + if ( ! self::is_plugins_page() || ! self::feedback_is_expired() ) { + return; + } + + wp_enqueue_script( + 'frm-deactivation-feedback', + FrmAppHelper::plugin_url() . '/js/admin/deactivation-feedback.js', + array( 'formidable', 'formidable_dom', 'jquery' ), + FrmAppHelper::plugin_version(), + true + ); + + wp_enqueue_style( 'formidable-admin' ); + + wp_enqueue_style( + 'frm-deactivation-feedback', + FrmAppHelper::plugin_url() . '/css/admin/deactivation-feedback.css', + array( 'formidable-admin' ), + FrmAppHelper::plugin_version() + ); + + FrmAppHelper::localize_script( 'front' ); + + wp_localize_script( + 'frm-deactivation-feedback', + 'FrmDeactivationFeedbackI18n', + array( + 'skip_text' => __( 'Skip & Deactivate', 'formidable' ), + ) + ); + } + + /** + * Prints footer HTML. + * + * @return void + */ + public static function footer_html() { + if ( ! self::is_plugins_page() || ! self::feedback_is_expired() ) { + return; + } + ?> +