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