| @@ -1,51 +1,134 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | 3 | defined( 'ABSPATH' ) || exit; |
| 4 | 4 | |
| 5 | -class Blockspare_Upgrade_Notice extends Blockspare_Setup { | |
| 5 | +class Blockspare_Notice | |
| 6 | +{ | |
| 7 | + public $name; | |
| 8 | + public $type; | |
| 9 | + public $dismiss_url; | |
| 10 | + public $temporary_dismiss_url; | |
| 11 | + public $pricing_url; | |
| 12 | + public $current_user_id; | |
| 6 | 13 | |
| 7 | 14 | /** |
| 8 | - * Constructor. | |
| 15 | + * The constructor. | |
| 16 | + * | |
| 17 | + * @param string $name Notice Name. | |
| 18 | + * @param string $type Notice type. | |
| 19 | + * @param string $dismiss_url Notice permanent dismiss URL. | |
| 20 | + * @param string $temporary_dismiss_url Notice temporary dismiss URL. | |
| 21 | + * | |
| 22 | + * @since 1.4.7 | |
| 23 | + * | |
| 9 | 24 | */ |
| 25 | + public function __construct($name, $type, $dismiss_url, $temporary_dismiss_url) | |
| 26 | + { | |
| 27 | + $this->name = $name; | |
| 28 | + $this->type = $type; | |
| 29 | + $this->dismiss_url = $dismiss_url; | |
| 30 | + $this->temporary_dismiss_url = $temporary_dismiss_url; | |
| 31 | + $this->pricing_url = 'https://www.blockspare.com/pricing/'; | |
| 32 | + $this->current_user_id = get_current_user_id(); | |
| 33 | + | |
| 34 | + // Notice markup. | |
| 35 | + add_action('admin_notices', array($this, 'notice')); | |
| 36 | + | |
| 37 | + $this->dismiss_notice(); | |
| 38 | + $this->dismiss_notice_temporary(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public function notice() | |
| 42 | + { | |
| 43 | + if (!$this->is_dismiss_notice()) { | |
| 44 | + $this->notice_markup(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + private function is_dismiss_notice() | |
| 49 | + { | |
| 50 | + return apply_filters('blockspare_' . $this->name . '_notice_dismiss', true); | |
| 51 | + } | |
| 52 | + | |
| 53 | + public function notice_markup() | |
| 54 | + { | |
| 55 | + echo ''; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Hide a notice if the GET variable is set. | |
| 60 | + */ | |
| 61 | + public function dismiss_notice() | |
| 62 | + { | |
| 63 | + if (isset($_GET['blockspare_notice_dismiss']) && isset($_GET['_blockspare_upgrade_notice_dismiss_nonce'])) { // WPCS: input var ok. | |
| 64 | + if (!wp_verify_nonce(wp_unslash($_GET['_blockspare_upgrade_notice_dismiss_nonce']), 'blockspare_upgrade_notice_dismiss_nonce')) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized | |
| 65 | + wp_die(__('Action failed. Please refresh the page and retry.', 'blockspare')); // WPCS: xss ok. | |
| 66 | + } | |
| 67 | + | |
| 68 | + if (!current_user_can('publish_posts')) { | |
| 69 | + wp_die(__('Cheatin’ huh?', 'blockspare')); // WPCS: xss ok. | |
| 70 | + } | |
| 71 | + | |
| 72 | + $dismiss_notice = sanitize_text_field(wp_unslash($_GET['blockspare_notice_dismiss'])); | |
| 73 | + | |
| 74 | + // Hide. | |
| 75 | + if ($dismiss_notice === $_GET['blockspare_notice_dismiss']) { | |
| 76 | + add_user_meta(get_current_user_id(), 'blockspare_' . $dismiss_notice . '_notice_dismiss', 'yes', true); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + public function dismiss_notice_temporary() | |
| 82 | + { | |
| 83 | + if (isset($_GET['blockspare_notice_dismiss_temporary']) && isset($_GET['_blockspare_upgrade_notice_dismiss_temporary_nonce'])) { // WPCS: input var ok. | |
| 84 | + if (!wp_verify_nonce(wp_unslash($_GET['_blockspare_upgrade_notice_dismiss_temporary_nonce']), 'blockspare_upgrade_notice_dismiss_temporary_nonce')) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized | |
| 85 | + wp_die(__('Action failed. Please refresh the page and retry.', 'blockspare')); // WPCS: xss ok. | |
| 86 | + } | |
| 87 | + | |
| 88 | + if (!current_user_can('publish_posts')) { | |
| 89 | + wp_die(__('Cheatin’ huh?', 'blockspare')); // WPCS: xss ok. | |
| 90 | + } | |
| 91 | + | |
| 92 | + $dismiss_notice = sanitize_text_field(wp_unslash($_GET['blockspare_notice_dismiss_temporary'])); | |
| 93 | + | |
| 94 | + // Hide. | |
| 95 | + if ($dismiss_notice === $_GET['blockspare_notice_dismiss_temporary']) { | |
| 96 | + add_user_meta(get_current_user_id(), 'blockspare_' . $dismiss_notice . '_notice_dismiss_temporary', 'yes', true); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + } | |
| 100 | +} | |
| 101 | + | |
| 102 | + | |
| 103 | +class Blockspare_Upgrade_Notice extends Blockspare_Notice { | |
| 104 | + | |
| 10 | 105 | public function __construct() { |
| 106 | + if ( ! current_user_can( 'publish_posts' ) ) { | |
| 107 | + return; | |
| 108 | + } | |
| 11 | 109 | |
| 12 | - // FIX: Replaced 'blockspare_notice_dismiss' with 'blockspare_setup_notice_dismiss' to match parent architecture | |
| 13 | 110 | $dismiss_url = wp_nonce_url( |
| 14 | - add_query_arg( | |
| 15 | - 'blockspare_setup_notice_dismiss', | |
| 16 | - 'upgrade', | |
| 17 | - admin_url() | |
| 18 | - ), | |
| 111 | + add_query_arg( 'blockspare_notice_dismiss', 'upgrade', admin_url() ), | |
| 19 | 112 | 'blockspare_upgrade_notice_dismiss_nonce', |
| 20 | 113 | '_blockspare_upgrade_notice_dismiss_nonce' |
| 21 | 114 | ); |
| 22 | 115 | |
| 23 | 116 | $temporary_dismiss_url = wp_nonce_url( |
| 24 | - add_query_arg( | |
| 25 | - 'blockspare_setup_notice_dismiss_temporary', | |
| 26 | - 'upgrade', | |
| 27 | - admin_url() | |
| 28 | - ), | |
| 117 | + add_query_arg( 'blockspare_notice_dismiss_temporary', 'upgrade', admin_url() ), | |
| 29 | 118 | 'blockspare_upgrade_notice_dismiss_temporary_nonce', |
| 30 | 119 | '_blockspare_upgrade_notice_dismiss_temporary_nonce' |
| 31 | 120 | ); |
| 32 | 121 | |
| 33 | - parent::__construct( | |
| 34 | - 'upgrade', | |
| 35 | - 'info', | |
| 36 | - $dismiss_url, | |
| 37 | - $temporary_dismiss_url | |
| 38 | - ); | |
| 122 | + parent::__construct( 'upgrade', 'info', $dismiss_url, $temporary_dismiss_url ); | |
| 39 | 123 | |
| 40 | 124 | $this->set_notice_time(); |
| 125 | + | |
| 41 | 126 | $this->set_temporary_dismiss_notice_time(); |
| 127 | + | |
| 42 | 128 | $this->set_dismiss_notice(); |
| 43 | 129 | } |
| 44 | 130 | |
| 45 | - /** | |
| 46 | - * Set initial notice time. | |
| 47 | - */ | |
| 48 | 131 | private function set_notice_time() { |
| 49 | 132 | if ( ! get_option( 'blockspare_upgrade_notice_start_time' ) ) { |
| 50 | 133 | update_option( 'blockspare_upgrade_notice_start_time', time() ); |
| 51 | 134 | } |
| @@ -50,38 +133,27 @@ | ||
| 50 | 133 | update_option( 'blockspare_upgrade_notice_start_time', time() ); |
| 51 | 134 | } |
| 52 | 135 | } |
| 53 | 136 | |
| 54 | - /** | |
| 55 | - * Set temporary dismiss time. | |
| 56 | - */ | |
| 57 | 137 | private function set_temporary_dismiss_notice_time() { |
| 58 | - // FIX: Aligned parameter string check with parent class | |
| 59 | - if ( | |
| 60 | - isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) && | |
| 61 | - 'upgrade' === $_GET['blockspare_setup_notice_dismiss_temporary'] | |
| 62 | - ) { | |
| 63 | - update_user_meta( | |
| 64 | - $this->current_user_id, | |
| 65 | - 'blockspare_upgrade_notice_dismiss_temporary_start_time', | |
| 66 | - time() | |
| 67 | - ); | |
| 138 | + if ( isset( $_GET['blockspare_notice_dismiss_temporary'] ) && 'upgrade' === $_GET['blockspare_notice_dismiss_temporary'] ) { | |
| 139 | + update_user_meta( $this->current_user_id, 'blockspare_upgrade_notice_dismiss_temporary_start_time', time() ); | |
| 68 | 140 | } |
| 69 | 141 | } |
| 70 | 142 | |
| 71 | - /** | |
| 72 | - * Set dismiss conditions. | |
| 73 | - */ | |
| 74 | 143 | public function set_dismiss_notice() { |
| 75 | - $user_id = get_current_user_id(); | |
| 76 | 144 | |
| 77 | - $is_permanently_dismissed = ( 'yes' === get_user_meta( $user_id, 'blockspare_upgrade_notice_dismiss', true ) ); | |
| 78 | - | |
| 79 | - $temporary_dismiss_time = (int) get_user_meta( $user_id, 'blockspare_upgrade_notice_dismiss_temporary_start_time', true ); | |
| 80 | - $is_temporarily_dismissed = ( $temporary_dismiss_time > strtotime( '-2 days' ) ); | |
| 81 | - | |
| 82 | - // FIX: Evaluates user meta correctly without loops or instant expiration loops | |
| 83 | - if ( $is_permanently_dismissed || $is_temporarily_dismissed ) { | |
| 145 | + /** | |
| 146 | + * Do not show notice if: | |
| 147 | + * | |
| 148 | + * 1. It has not been 5 days since the plugin is activated. | |
| 149 | + * 2. If the user has ignored the message partially for 2 days. | |
| 150 | + * 3. Dismiss always if clicked on 'Dismiss' button. | |
| 151 | + */ | |
| 152 | + if ( get_option( 'blockspare_upgrade_notice_start_time' ) > strtotime( '-2 days' ) | |
| 153 | + || get_user_meta( get_current_user_id(), 'blockspare_upgrade_notice_dismiss', true ) | |
| 154 | + || get_user_meta( get_current_user_id(), 'blockspare_upgrade_notice_dismiss_temporary_start_time', true ) > strtotime( '-2 days' ) | |
| 155 | + ) { | |
| 84 | 156 | add_filter( 'blockspare_upgrade_notice_dismiss', '__return_true' ); |
| 85 | 157 | } else { |
| 86 | 158 | add_filter( 'blockspare_upgrade_notice_dismiss', '__return_false' ); |
| 87 | 159 | } |
| @@ -86,127 +158,58 @@ | ||
| 86 | 158 | add_filter( 'blockspare_upgrade_notice_dismiss', '__return_false' ); |
| 87 | 159 | } |
| 88 | 160 | } |
| 89 | 161 | |
| 90 | - /** | |
| 91 | - * Notice markup. | |
| 92 | - */ | |
| 93 | 162 | public function notice_markup() { |
| 94 | 163 | ?> |
| 95 | - <div class="notice notice-info blockspare-notice-upgrade" style="padding:24px; position:relative; border-left:4px solid #2271b1; background:#fff;"> | |
| 164 | + <div class="notice notice-success blockspare-notice" > | |
| 165 | + <div class="blockspare-notice__logo"> | |
| 166 | + <svg fill="url(#blockspare-gradient)" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" class="blockspare-svg blockspare-svg-blockspare" aria-hidden="true" focusable="false"><g class="blockspare-logo"><g><path class="st0" d="M1.6,9.2v21.4l18.3-9.2L20.2,0L1.6,9.2z M16.9,19.8L4.9,26V10.9l12-6.1V19.8z"></path><polygon id="XMLID_3_" class="st1" points="19.9,21.4 16.9,23 26,27.7 13.8,33.8 4.9,29 1.6,30.7 13.9,36.9 32.4,27.7 "></polygon></g><g><polygon id="XMLID_2_" class="st0" points="23,1.5 23,19.8 32.4,24.6 32.4,9.4 35.3,10.9 35.3,29 38.4,30.7 38.4,9.2 29.4,4.8 29.2,19.7 26,18.4 26,3.1 "></polygon><polygon id="XMLID_1_" class="st1" points="17,38.4 19.9,40 38.4,30.7 35.3,29 "></polygon></g></g></svg> | |
| 167 | + </div> | |
| 168 | + <div class="blockspare-notice__content"> | |
| 169 | + <?php | |
| 170 | + $current_user = wp_get_current_user(); | |
| 96 | 171 | |
| 97 | - <div style="display:flex; justify-content:space-between; gap:28px; align-items:flex-start; flex-wrap:wrap;"> | |
| 172 | + printf( | |
| 173 | + /* Translators: %1$s current user display name., %2$s this plugin name., %3$s discount coupon code., %4$s discount percentage. */ | |
| 174 | + esc_html__( | |
| 175 | + '%1$s %7$s We would appreciate it if you can %4$s rate us on WordPress.org%5$s! By spreading the love, we will continue to create thrilling new features for free in the future. Enjoy! %8$s', | |
| 176 | + 'blockspare' | |
| 177 | + ), | |
| 178 | + '<h2 class="blockspare-notice-title">Hello ' . esc_html( $current_user->display_name ) . ', you are awesome for using Blockspare Pro!</h2>', | |
| 179 | + '<p><strong>Blockspare</strong>', | |
| 180 | + '<strong><a target="_blank" href="https://www.blockspare.com/pricing/">Blockspare Pro</a></strong>', | |
| 181 | + '<strong><a href="https://wordpress.org/support/plugin/blockspare/reviews/?filter=5#new-post" target="_blank">', | |
| 182 | + '</a></strong>', | |
| 183 | + '<br>', | |
| 184 | + '<p class="blockspare-notice-description">', | |
| 185 | + '</p>', | |
| 186 | + ); | |
| 98 | 187 | |
| 99 | - <div style="flex:1; min-width:300px;"> | |
| 100 | - | |
| 101 | - <div style="display:inline-block; background:#e8f2ff; color:#2271b1; padding:4px 10px; border-radius:30px; font-size:12px; font-weight:600; margin-bottom:14px;"> | |
| 102 | - <?php esc_html_e( 'Upgrade Available', 'blockspare' ); ?> | |
| 103 | - </div> | |
| 104 | - | |
| 105 | - <h2 style="margin:0 0 12px; font-size:24px; line-height:1.4; font-weight:700;"> | |
| 106 | - <?php esc_html_e( 'Unlock More Power with Blockspare Pro', 'blockspare' ); ?> | |
| 107 | - </h2> | |
| 108 | - | |
| 109 | - <p style="margin:0 0 16px; font-size:14px; color:#555; max-width:920px; line-height:1.8;"> | |
| 110 | - <?php esc_html_e( 'Get access to premium templates, advanced post layouts, extra design blocks, and more control over how your content looks. Blockspare Pro helps you build faster and create richer pages with less effort.', 'blockspare' ); ?> | |
| 111 | - </p> | |
| 112 | - | |
| 113 | - <div style="display:flex; flex-wrap:wrap; gap:8px; margin-bottom:18px;"> | |
| 114 | - | |
| 115 | - <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> | |
| 116 | - <?php esc_html_e( 'Premium Templates', 'blockspare' ); ?> | |
| 117 | - </span> | |
| 118 | - | |
| 119 | - <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> | |
| 120 | - <?php esc_html_e( 'Advanced Post Layouts', 'blockspare' ); ?> | |
| 121 | - </span> | |
| 122 | - | |
| 123 | - <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> | |
| 124 | - <?php esc_html_e( 'More Blocks & Sections', 'blockspare' ); ?> | |
| 125 | - </span> | |
| 126 | - | |
| 127 | - <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> | |
| 128 | - <?php esc_html_e( 'Extra Design Controls', 'blockspare' ); ?> | |
| 129 | - </span> | |
| 130 | - | |
| 131 | - <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> | |
| 132 | - <?php esc_html_e( 'Faster Website Building', 'blockspare' ); ?> | |
| 133 | - </span> | |
| 134 | - | |
| 135 | - </div> | |
| 136 | - | |
| 137 | - <div style="display:flex; flex-wrap:wrap; gap:10px; align-items:center;"> | |
| 138 | - | |
| 139 | - <a | |
| 140 | - class="button button-primary" | |
| 141 | - href="<?php echo esc_url( $this->pricing_url ); ?>" | |
| 142 | - target="_blank" | |
| 143 | - rel="noopener noreferrer" | |
| 144 | - > | |
| 145 | - <?php esc_html_e( 'Upgrade to Pro', 'blockspare' ); ?> | |
| 146 | - </a> | |
| 147 | - | |
| 148 | - <a | |
| 149 | - class="button" | |
| 150 | - href="<?php echo esc_url( 'https://www.blockspare.com/' ); ?>" | |
| 151 | - target="_blank" | |
| 152 | - rel="noopener noreferrer" | |
| 153 | - > | |
| 154 | - <?php esc_html_e( 'View Features', 'blockspare' ); ?> | |
| 155 | - </a> | |
| 156 | - | |
| 157 | - <a | |
| 158 | - class="button button-secondary plain" | |
| 159 | - href="<?php echo esc_url( $this->temporary_dismiss_url ); ?>" | |
| 160 | - > | |
| 161 | - <?php esc_html_e( 'Maybe later', 'blockspare' ); ?> | |
| 162 | - </a> | |
| 163 | - | |
| 164 | - <a | |
| 165 | - class="button button-secondary plain" | |
| 166 | - href="<?php echo esc_url( 'https://afthemes.com/supports/' ); ?>" | |
| 167 | - target="_blank" | |
| 168 | - rel="noopener noreferrer" | |
| 169 | - > | |
| 170 | - <?php esc_html_e( 'Need help?', 'blockspare' ); ?> | |
| 171 | - </a> | |
| 172 | - | |
| 173 | - </div> | |
| 174 | - | |
| 188 | + ?> | |
| 189 | + <div class="links"> | |
| 190 | + <a href="https://wordpress.org/support/plugin/blockspare/reviews/?filter=5#new-post" class="button button-primary" target="_blank"> | |
| 191 | + <span><?php esc_html_e( 'Sure thing', 'blockspare' ); ?></span> | |
| 192 | + </a> | |
| 193 | + <a href="<?php echo esc_url( $this->pricing_url ); ?>" class="button button-secondary" target="_blank"> | |
| 194 | + <span><?php esc_html_e( 'Unlock All Templates', 'blockspare' ); ?></span> | |
| 195 | + </a> | |
| 196 | + | |
| 197 | + <a href="<?php echo esc_url( $this->temporary_dismiss_url ); ?>" class="button button-secondary plain"> | |
| 198 | + <span><?php esc_html_e( 'Maybe later', 'blockspare' ); ?></span> | |
| 199 | + </a> | |
| 200 | + | |
| 201 | + <a href="https://afthemes.com/supports/" class="button button-secondary plain" target="_blank"> | |
| 202 | + <span><?php esc_html_e( 'Need help?', 'blockspare' ); ?></span> | |
| 203 | + </a> | |
| 175 | 204 | </div> |
| 176 | - | |
| 177 | - <div style="width:240px; background:#f8fbff; border:1px solid #dcdcde; border-radius:12px; padding:18px;"> | |
| 178 | - | |
| 179 | - <div style="font-size:13px; font-weight:600; color:#2271b1; margin-bottom:12px;"> | |
| 180 | - <?php esc_html_e( 'Why upgrade?', 'blockspare' ); ?> | |
| 181 | - </div> | |
| 182 | - | |
| 183 | - <ul style="margin:0; padding-left:18px; color:#555; line-height:1.8; font-size:13px;"> | |
| 184 | - <li><?php esc_html_e( 'Access premium layouts and demos', 'blockspare' ); ?></li> | |
| 185 | - <li><?php esc_html_e( 'Create richer post displays', 'blockspare' ); ?></li> | |
| 186 | - <li><?php esc_html_e( 'Get more design flexibility', 'blockspare' ); ?></li> | |
| 187 | - <li><?php esc_html_e( 'Build pages faster with less effort', 'blockspare' ); ?></li> | |
| 188 | - </ul> | |
| 189 | - | |
| 190 | - </div> | |
| 191 | - | |
| 192 | 205 | </div> |
| 193 | - | |
| 206 | + <div class="bs-notice-image"> | |
| 207 | + <img src='<?php echo BLOCKSPARE_PLUGIN_URL ."admin/assets/images/review.webp";?>'/> | |
| 208 | + </div> | |
| 194 | 209 | <a class="blockspare-notice-dismiss notice-dismiss" href="<?php echo esc_url( $this->dismiss_url ); ?>"></a> |
| 195 | - </div> | |
| 210 | + </div> <!-- /blockspare-notice --> | |
| 196 | 211 | <?php |
| 197 | 212 | } |
| 198 | 213 | } |
| 199 | 214 | |
| 200 | -/** | |
| 201 | - * Initialize notice. | |
| 202 | - */ | |
| 203 | -function blockspare_upgrade_notice_init() { | |
| 204 | - | |
| 205 | - if ( ! is_admin() ) { | |
| 206 | - return; | |
| 207 | - } | |
| 208 | - | |
| 209 | - new Blockspare_Upgrade_Notice(); | |
| 210 | -} | |
| 211 | - | |
| 212 | -add_action( 'admin_init', 'blockspare_upgrade_notice_init' ); | |
| 215 | +new Blockspare_Upgrade_Notice(); | |