AdminAjaxController.php
4 years ago
MetaController.php
4 years ago
NoticeController.php
4 years ago
PostTypeController.php
4 years ago
SettingsController.php
4 years ago
UpgradeController.php
4 years ago
NoticeController.php
359 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace RT\ThePostGrid\Controllers\Admin; |
| 5 | |
| 6 | |
| 7 | class NoticeController { |
| 8 | public function __construct() { |
| 9 | $current = time(); |
| 10 | $black_friday = mktime( 0, 0, 0, 11, 22, 2021 ) <= $current && $current <= mktime( 0, 0, 0, 12, 6, 2021 ); |
| 11 | |
| 12 | if ( $black_friday ) { |
| 13 | add_action( 'admin_init', [ $this, 'black_friday_notice' ] ); |
| 14 | } else { |
| 15 | register_activation_hook( RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME, [ $this, 'rttpg_activation_time' ] ); |
| 16 | add_action( 'admin_init', [ $this, 'rttpg_check_installation_time' ] ); |
| 17 | add_action( 'admin_init', [ __CLASS__, 'rttpg_spare_me' ], 5 ); |
| 18 | } |
| 19 | |
| 20 | add_action( 'admin_init', [ __CLASS__, 'rttpg_notice' ] ); |
| 21 | } |
| 22 | |
| 23 | public static function rttpg_notice() { |
| 24 | |
| 25 | |
| 26 | add_action( 'admin_notices', function () { |
| 27 | $settings = get_option( 'rt_the_post_grid_settings' ); |
| 28 | $screen = get_current_screen(); |
| 29 | |
| 30 | if ( isset( $settings['tpg_block_type'] ) ) { |
| 31 | if ( in_array( $screen->id, [ 'edit-rttpg','rttpg'] ) && $settings['tpg_block_type'] == 'elementor' ) { ?> |
| 32 | <div class="notice notice-for-warning"> |
| 33 | <p> |
| 34 | You have selected only Elementor method. To use Shortcode Generator please enable shortcode |
| 35 | or default from <a style="color: #fff;" |
| 36 | href="<?php echo esc_url( admin_url( 'edit.php?post_type=rttpg&page=rttpg_settings' ) ) ?>">Settings |
| 37 | => Common Settings => Resource Load Type</a> |
| 38 | </p> |
| 39 | </div> |
| 40 | <?php |
| 41 | } |
| 42 | |
| 43 | if ( $screen->id == 'edit-tpg_builder' && $settings['tpg_block_type'] == 'shortcode' ) { |
| 44 | ?> |
| 45 | <div class="notice notice-for-warning"> |
| 46 | <p> |
| 47 | You have selected only Shortcode Generator method. To use Elementor please enable Elementor |
| 48 | or default from <a style="color: #fff;" |
| 49 | href="<?php echo esc_url( admin_url( 'edit.php?post_type=rttpg&page=rttpg_settings§ion=common-settings' ) ) ?>">Settings |
| 50 | => Common Settings => Resource Load Type</a> |
| 51 | </p> |
| 52 | </div> |
| 53 | <?php |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } ); |
| 58 | } |
| 59 | |
| 60 | public static function black_friday_notice() { |
| 61 | if ( get_option( 'rttpg_bf_2021' ) != '1' ) { |
| 62 | if ( ! isset( $GLOBALS['rt_tpg_2021_notice'] ) ) { |
| 63 | $GLOBALS['rt_tpg_2021_notice'] = 'rttpg_bf_2021'; |
| 64 | self::notice(); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | static function notice() { |
| 70 | |
| 71 | add_action( 'admin_enqueue_scripts', function () { |
| 72 | wp_enqueue_script( 'jquery' ); |
| 73 | } ); |
| 74 | |
| 75 | add_action( 'admin_notices', function () { |
| 76 | $plugin_name = 'The Post Grid'; |
| 77 | $download_link = 'https://www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/'; ?> |
| 78 | <div class="notice notice-info is-dismissible" data-rttpg-dismissable="rttpg_bf_2021" |
| 79 | style="display:grid;grid-template-columns: 100px auto;padding-top: 25px; padding-bottom: 22px;"> |
| 80 | <img alt="<?php echo esc_attr( $plugin_name ) ?>" |
| 81 | src="<?php echo rtTPG()->get_assets_uri( 'images/icon-128x128.png' ); ?>" width="74px" |
| 82 | height="74px" style="grid-row: 1 / 4; align-self: center;justify-self: center"/> |
| 83 | <h3 style="margin:0;"><?php echo sprintf( '%s Black Friday Deal!!', $plugin_name ) ?></h3> |
| 84 | <p style="margin:0 0 2px;">Don't miss out on our biggest sale of the year! Get your |
| 85 | <b><?php echo $plugin_name; ?> plan</b> with <b>UPTO 50% OFF</b>! Limited time offer expires on |
| 86 | December 5. |
| 87 | </p> |
| 88 | <p style="margin:0;"> |
| 89 | <a class="button button-primary" |
| 90 | href="<?php echo esc_url( $download_link ) ?>" |
| 91 | target="_blank">Buy Now</a> |
| 92 | <a class="button button-dismiss" href="#">Dismiss</a> |
| 93 | </p> |
| 94 | </div> |
| 95 | <?php |
| 96 | } ); |
| 97 | |
| 98 | add_action( 'admin_footer', function () { |
| 99 | ?> |
| 100 | <script type="text/javascript"> |
| 101 | ( function ( $ ) { |
| 102 | $( function () { |
| 103 | setTimeout( function () { |
| 104 | $( 'div[data-rttpg-dismissable] .notice-dismiss, div[data-rttpg-dismissable] .button-dismiss' ) |
| 105 | .on( 'click', function ( e ) { |
| 106 | e.preventDefault(); |
| 107 | $.post( ajaxurl, { |
| 108 | 'action': 'rttpg_dismiss_admin_notice', |
| 109 | 'nonce': <?php echo json_encode( wp_create_nonce( 'rttpg-dismissible-notice' ) ); ?> |
| 110 | } ); |
| 111 | $( e.target ).closest( '.is-dismissible' ).remove(); |
| 112 | } ); |
| 113 | }, 1000 ); |
| 114 | } ); |
| 115 | } )( jQuery ); |
| 116 | </script> |
| 117 | <?php |
| 118 | } ); |
| 119 | |
| 120 | add_action( 'wp_ajax_rttpg_dismiss_admin_notice', function () { |
| 121 | check_ajax_referer( 'rttpg-dismissible-notice', 'nonce' ); |
| 122 | |
| 123 | update_option( 'rttpg_bf_2021', '1' ); |
| 124 | wp_die(); |
| 125 | } ); |
| 126 | } |
| 127 | |
| 128 | // add plugin activation time |
| 129 | public static function rttpg_activation_time() { |
| 130 | $get_activation_time = strtotime( "now" ); |
| 131 | add_option( 'rttpg_plugin_activation_time', $get_activation_time ); |
| 132 | } |
| 133 | |
| 134 | //check if review notice should be shown or not |
| 135 | public static function rttpg_check_installation_time() { |
| 136 | |
| 137 | // Added Lines Start |
| 138 | $nobug = get_option( 'rttpg_spare_me', "0" ); |
| 139 | |
| 140 | if ( $nobug == "1" || $nobug == "3" ) { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | $install_date = get_option( 'rttpg_plugin_activation_time' ); |
| 145 | $past_date = strtotime( '-10 days' ); |
| 146 | |
| 147 | $remind_time = get_option( 'rttpg_remind_me' ); |
| 148 | $remind_due = strtotime( '+15 days', $remind_time ); |
| 149 | $now = strtotime( "now" ); |
| 150 | |
| 151 | if ( $now >= $remind_due ) { |
| 152 | add_action( 'admin_notices', [ __CLASS__, 'rttpg_display_admin_notice' ] ); |
| 153 | } else if ( ( $past_date >= $install_date ) && $nobug !== "2" ) { |
| 154 | add_action( 'admin_notices', [ __CLASS__, 'rttpg_display_admin_notice' ] ); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Display Admin Notice, asking for a review |
| 160 | **/ |
| 161 | public static function rttpg_display_admin_notice() { |
| 162 | // wordpress global variable |
| 163 | global $pagenow; |
| 164 | |
| 165 | $exclude = [ |
| 166 | 'themes.php', |
| 167 | 'users.php', |
| 168 | 'tools.php', |
| 169 | 'options-general.php', |
| 170 | 'options-writing.php', |
| 171 | 'options-reading.php', |
| 172 | 'options-discussion.php', |
| 173 | 'options-media.php', |
| 174 | 'options-permalink.php', |
| 175 | 'options-privacy.php', |
| 176 | 'edit-comments.php', |
| 177 | 'upload.php', |
| 178 | 'media-new.php', |
| 179 | 'admin.php', |
| 180 | 'import.php', |
| 181 | 'export.php', |
| 182 | 'site-health.php', |
| 183 | 'export-personal-data.php', |
| 184 | 'erase-personal-data.php' |
| 185 | ]; |
| 186 | |
| 187 | if ( ! in_array( $pagenow, $exclude ) ) { |
| 188 | $dont_disturb = esc_url( add_query_arg( 'rttpg_spare_me', '1', self::rttpg_current_admin_url() ) ); |
| 189 | $remind_me = esc_url( add_query_arg( 'rttpg_remind_me', '1', self::rttpg_current_admin_url() ) ); |
| 190 | $rated = esc_url( add_query_arg( 'rttpg_rated', '1', self::rttpg_current_admin_url() ) ); |
| 191 | $reviewurl = esc_url( 'https://wordpress.org/support/plugin/the-post-grid/reviews/?filter=5#new-post' ); |
| 192 | |
| 193 | printf( __( '<div class="notice rttpg-review-notice rttpg-review-notice--extended"> |
| 194 | <div class="rttpg-review-notice_content"> |
| 195 | <h3>Enjoying The Post Grid?</h3> |
| 196 | <p>Thank you for choosing The Post Grid. If you have found our plugin useful and makes you smile, please consider giving us a 5-star rating on WordPress.org. It will help us to grow.</p> |
| 197 | <div class="rttpg-review-notice_actions"> |
| 198 | <a href="%s" class="rttpg-review-button rttpg-review-button--cta" target="_blank"><span>⭐ Yes, You Deserve It!</span></a> |
| 199 | <a href="%s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline"><span>😀 Already Rated!</span></a> |
| 200 | <a href="%s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--outline"><span>🔔 Remind Me Later</span></a> |
| 201 | <a href="%s" class="rttpg-review-button rttpg-review-button--cta rttpg-review-button--error rttpg-review-button--outline"><span>😐 No Thanks</span></a> |
| 202 | </div> |
| 203 | </div> |
| 204 | </div>' ), $reviewurl, $rated, $remind_me, $dont_disturb ); |
| 205 | |
| 206 | echo '<style> |
| 207 | .rttpg-review-button--cta { |
| 208 | --e-button-context-color: #4C6FFF; |
| 209 | --e-button-context-color-dark: #4C6FFF; |
| 210 | --e-button-context-tint: rgb(75 47 157/4%); |
| 211 | --e-focus-color: rgb(75 47 157/40%); |
| 212 | } |
| 213 | .rttpg-review-notice { |
| 214 | position: relative; |
| 215 | margin: 5px 20px 5px 2px; |
| 216 | border: 1px solid #ccd0d4; |
| 217 | background: #fff; |
| 218 | box-shadow: 0 1px 4px rgba(0,0,0,0.15); |
| 219 | font-family: Roboto, Arial, Helvetica, Verdana, sans-serif; |
| 220 | border-inline-start-width: 4px; |
| 221 | } |
| 222 | .rttpg-review-notice.notice { |
| 223 | padding: 0; |
| 224 | } |
| 225 | .rttpg-review-notice:before { |
| 226 | position: absolute; |
| 227 | top: -1px; |
| 228 | bottom: -1px; |
| 229 | left: -4px; |
| 230 | display: block; |
| 231 | width: 4px; |
| 232 | background: -webkit-linear-gradient(bottom, #4C6FFF 0%, #6939c6 100%); |
| 233 | background: linear-gradient(0deg, #4C6FFF 0%, #6939c6 100%); |
| 234 | content: ""; |
| 235 | } |
| 236 | .rttpg-review-notice_content { |
| 237 | padding: 20px; |
| 238 | } |
| 239 | .rttpg-review-notice_actions > * + * { |
| 240 | margin-inline-start: 8px; |
| 241 | -webkit-margin-start: 8px; |
| 242 | -moz-margin-start: 8px; |
| 243 | } |
| 244 | .rttpg-review-notice p { |
| 245 | margin: 0; |
| 246 | padding: 0; |
| 247 | line-height: 1.5; |
| 248 | } |
| 249 | p + .rttpg-review-notice_actions { |
| 250 | margin-top: 1rem; |
| 251 | } |
| 252 | .rttpg-review-notice h3 { |
| 253 | margin: 0; |
| 254 | font-size: 1.0625rem; |
| 255 | line-height: 1.2; |
| 256 | } |
| 257 | .rttpg-review-notice h3 + p { |
| 258 | margin-top: 8px; |
| 259 | } |
| 260 | .rttpg-review-button { |
| 261 | display: inline-block; |
| 262 | padding: 0.4375rem 0.75rem; |
| 263 | border: 0; |
| 264 | border-radius: 3px;; |
| 265 | background: var(--e-button-context-color); |
| 266 | color: #fff; |
| 267 | vertical-align: middle; |
| 268 | text-align: center; |
| 269 | text-decoration: none; |
| 270 | white-space: nowrap; |
| 271 | } |
| 272 | .rttpg-review-button:active { |
| 273 | background: var(--e-button-context-color-dark); |
| 274 | color: #fff; |
| 275 | text-decoration: none; |
| 276 | } |
| 277 | .rttpg-review-button:focus { |
| 278 | outline: 0; |
| 279 | background: var(--e-button-context-color-dark); |
| 280 | box-shadow: 0 0 0 2px var(--e-focus-color); |
| 281 | color: #fff; |
| 282 | text-decoration: none; |
| 283 | } |
| 284 | .rttpg-review-button:hover { |
| 285 | background: var(--e-button-context-color-dark); |
| 286 | color: #fff; |
| 287 | text-decoration: none; |
| 288 | } |
| 289 | .rttpg-review-button.focus { |
| 290 | outline: 0; |
| 291 | box-shadow: 0 0 0 2px var(--e-focus-color); |
| 292 | } |
| 293 | .rttpg-review-button--error { |
| 294 | --e-button-context-color: #d72b3f; |
| 295 | --e-button-context-color-dark: #ae2131; |
| 296 | --e-button-context-tint: rgba(215,43,63,0.04); |
| 297 | --e-focus-color: rgba(215,43,63,0.4); |
| 298 | } |
| 299 | .rttpg-review-button.rttpg-review-button--outline { |
| 300 | border: 1px solid; |
| 301 | background: 0 0; |
| 302 | color: var(--e-button-context-color); |
| 303 | } |
| 304 | .rttpg-review-button.rttpg-review-button--outline:focus { |
| 305 | background: var(--e-button-context-tint); |
| 306 | color: var(--e-button-context-color-dark); |
| 307 | } |
| 308 | .rttpg-review-button.rttpg-review-button--outline:hover { |
| 309 | background: var(--e-button-context-tint); |
| 310 | color: var(--e-button-context-color-dark); |
| 311 | } |
| 312 | </style>'; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | protected static function rttpg_current_admin_url() { |
| 317 | $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 318 | $uri = preg_replace( '|^.*/wp-admin/|i', '', $uri ); |
| 319 | |
| 320 | if ( ! $uri ) { |
| 321 | return ''; |
| 322 | } |
| 323 | |
| 324 | return remove_query_arg( [ |
| 325 | '_wpnonce', |
| 326 | '_wc_notice_nonce', |
| 327 | 'wc_db_update', |
| 328 | 'wc_db_update_nonce', |
| 329 | 'wc-hide-notice' |
| 330 | ], admin_url( $uri ) ); |
| 331 | } |
| 332 | |
| 333 | // remove the notice for the user if review already done or if the user does not want to |
| 334 | public static function rttpg_spare_me() { |
| 335 | if ( isset( $_GET['rttpg_spare_me'] ) && ! empty( $_GET['rttpg_spare_me'] ) ) { |
| 336 | $spare_me = $_GET['rttpg_spare_me']; |
| 337 | if ( 1 == $spare_me ) { |
| 338 | update_option( 'rttpg_spare_me', "1" ); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if ( isset( $_GET['rttpg_remind_me'] ) && ! empty( $_GET['rttpg_remind_me'] ) ) { |
| 343 | $remind_me = $_GET['rttpg_remind_me']; |
| 344 | if ( 1 == $remind_me ) { |
| 345 | $get_activation_time = strtotime( "now" ); |
| 346 | update_option( 'rttpg_remind_me', $get_activation_time ); |
| 347 | update_option( 'rttpg_spare_me', "2" ); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if ( isset( $_GET['rttpg_rated'] ) && ! empty( $_GET['rttpg_rated'] ) ) { |
| 352 | $rttpg_rated = $_GET['rttpg_rated']; |
| 353 | if ( 1 == $rttpg_rated ) { |
| 354 | update_option( 'rttpg_rated', 'yes' ); |
| 355 | update_option( 'rttpg_spare_me', "3" ); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } |