← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Promotions.php
+8
-118
3.10.1
→
3.9.7
View file →
| @@ -54,15 +54,8 @@ | ||
| 54 | 54 | */ |
| 55 | 55 | private $option_optimole = 'themeisle_sdk_promotions_optimole_installed'; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Option key for ROP promos. | |
| 59 | - * | |
| 60 | - * @var string | |
| 61 | - */ | |
| 62 | - private $option_rop = 'themeisle_sdk_promotions_rop_installed'; | |
| 63 | - | |
| 64 | - /** | |
| 65 | 58 | * Loaded promotion. |
| 66 | 59 | * |
| 67 | 60 | * @var string |
| 68 | 61 | */ |
| @@ -92,9 +85,8 @@ | ||
| 92 | 85 | |
| 93 | 86 | $this->debug = apply_filters( 'themeisle_sdk_promo_debug', $this->debug ); |
| 94 | 87 | $promotions_to_load = apply_filters( $product->get_key() . '_load_promotions', array() ); |
| 95 | 88 | $promotions_to_load[] = 'optimole'; |
| 96 | - $promotions_to_load[] = 'rop'; | |
| 97 | 89 | |
| 98 | 90 | $this->promotions = $this->get_promotions(); |
| 99 | 91 | |
| 100 | 92 | foreach ( $this->promotions as $slug => $data ) { |
| @@ -159,12 +151,8 @@ | ||
| 159 | 151 | |
| 160 | 152 | if ( isset( $_GET['optimole_reference_key'] ) ) { |
| 161 | 153 | update_option( 'optimole_reference_key', sanitize_key( $_GET['optimole_reference_key'] ) ); |
| 162 | 154 | } |
| 163 | - | |
| 164 | - if ( isset( $_GET['rop_reference_key'] ) ) { | |
| 165 | - update_option( 'rop_reference_key', sanitize_key( $_GET['rop_reference_key'] ) ); | |
| 166 | - } | |
| 167 | 155 | } |
| 168 | 156 | |
| 169 | 157 | /** |
| 170 | 158 | * Register Settings |
| @@ -202,18 +190,8 @@ | ||
| 202 | 190 | 'show_in_rest' => true, |
| 203 | 191 | 'default' => false, |
| 204 | 192 | ) |
| 205 | 193 | ); |
| 206 | - register_setting( | |
| 207 | - 'themeisle_sdk_settings', | |
| 208 | - $this->option_rop, | |
| 209 | - array( | |
| 210 | - 'type' => 'boolean', | |
| 211 | - 'sanitize_callback' => 'rest_sanitize_boolean', | |
| 212 | - 'show_in_rest' => true, | |
| 213 | - 'default' => false, | |
| 214 | - ) | |
| 215 | - ); | |
| 216 | 194 | } |
| 217 | 195 | |
| 218 | 196 | /** |
| 219 | 197 | * Get the SDK base url. |
| @@ -261,11 +239,10 @@ | ||
| 261 | 239 | * @return bool |
| 262 | 240 | */ |
| 263 | 241 | private function is_plugin_installed( $plugin ) { |
| 264 | 242 | static $allowed_keys = [ |
| 265 | - 'otter-blocks' => 'otter-blocks/otter-blocks.php', | |
| 266 | - 'optimole-wp' => 'optimole-wp/optimole-wp.php', | |
| 267 | - 'tweet-old-post' => 'tweet-old-post/tweet-old-post.php', | |
| 243 | + 'otter-blocks' => 'otter-blocks/otter-blocks.php', | |
| 244 | + 'optimole-wp' => 'optimole-wp/optimole-wp.php', | |
| 268 | 245 | ]; |
| 269 | 246 | |
| 270 | 247 | if ( ! isset( $allowed_keys[ $plugin ] ) ) { |
| 271 | 248 | return false; |
| @@ -287,13 +264,10 @@ | ||
| 287 | 264 | $has_otter = defined( 'OTTER_BLOCKS_VERSION' ) || $this->is_plugin_installed( 'otter-blocks' ); |
| 288 | 265 | $had_otter_from_promo = get_option( $this->option_otter, false ); |
| 289 | 266 | $has_optimole = defined( 'OPTIMOLE_VERSION' ) || $this->is_plugin_installed( 'optimole-wp' ); |
| 290 | 267 | $had_optimole_from_promo = get_option( $this->option_optimole, false ); |
| 291 | - $has_rop = defined( 'ROP_LITE_VERSION' ) || $this->is_plugin_installed( 'tweet-old-post' ); | |
| 292 | - $had_rop_from_promo = get_option( $this->option_rop, false ); | |
| 293 | 268 | $is_min_req_v = version_compare( get_bloginfo( 'version' ), '5.8', '>=' ); |
| 294 | 269 | $has_enough_attachments = $this->has_min_media_attachments(); |
| 295 | - $has_enough_old_posts = $this->has_old_posts(); | |
| 296 | 270 | |
| 297 | 271 | $all = [ |
| 298 | 272 | 'optimole' => [ |
| 299 | 273 | 'om-editor' => [ |
| @@ -330,14 +304,8 @@ | ||
| 330 | 304 | 'env' => ! $has_otter && $is_min_req_v && ! $had_otter_from_promo, |
| 331 | 305 | 'screen' => 'editor', |
| 332 | 306 | ], |
| 333 | 307 | ], |
| 334 | - 'rop' => [ | |
| 335 | - 'rop-posts' => [ | |
| 336 | - 'env' => ! $has_rop && ! $had_rop_from_promo && $has_enough_old_posts, | |
| 337 | - 'screen' => 'edit-post', | |
| 338 | - ], | |
| 339 | - ], | |
| 340 | 308 | ]; |
| 341 | 309 | |
| 342 | 310 | foreach ( $all as $slug => $data ) { |
| 343 | 311 | foreach ( $data as $key => $conditions ) { |
| @@ -364,9 +332,9 @@ | ||
| 364 | 332 | * Get the upsell dismiss time. |
| 365 | 333 | * |
| 366 | 334 | * @param string $key The upsell key. If empty will return all dismiss times. |
| 367 | 335 | * |
| 368 | - * @return false | string | array | |
| 336 | + * @return false | string | |
| 369 | 337 | */ |
| 370 | 338 | private function get_upsells_dismiss_time( $key = '' ) { |
| 371 | 339 | $old = get_option( 'themeisle_sdk_promotions_otter', '{}' ); |
| 372 | 340 | $data = get_option( $this->option_main, $old ); |
| @@ -382,20 +350,20 @@ | ||
| 382 | 350 | |
| 383 | 351 | /** |
| 384 | 352 | * Get the last dismiss time of a promotion. |
| 385 | 353 | * |
| 386 | - * @return int The timestamp of last dismiss, or install time - 4 days. | |
| 354 | + * @return false | |
| 387 | 355 | */ |
| 388 | 356 | private function get_last_dismiss_time() { |
| 389 | 357 | $dismissed = $this->get_upsells_dismiss_time(); |
| 390 | 358 | |
| 391 | 359 | if ( empty( $dismissed ) ) { |
| 392 | - // we return the product install time - 4 days because we want to show the upsell after 3 days, | |
| 393 | - // and we move the product install time 4 days in the past. | |
| 394 | - return $this->product->get_install_time() - 4 * DAY_IN_SECONDS; | |
| 360 | + return false; | |
| 395 | 361 | } |
| 396 | 362 | |
| 397 | - return max( array_values( $dismissed ) ); | |
| 363 | + $last_dismiss = max( array_values( $dismissed ) ); | |
| 364 | + | |
| 365 | + return $last_dismiss; | |
| 398 | 366 | } |
| 399 | 367 | |
| 400 | 368 | /** |
| 401 | 369 | * Filter by screen & merge into single array of keys. |
| @@ -406,9 +374,8 @@ | ||
| 406 | 374 | $current_screen = get_current_screen(); |
| 407 | 375 | |
| 408 | 376 | $is_elementor = isset( $_GET['action'] ) && $_GET['action'] === 'elementor'; |
| 409 | 377 | $is_media = isset( $current_screen->id ) && $current_screen->id === 'upload'; |
| 410 | - $is_posts = isset( $current_screen->id ) && $current_screen->id === 'edit-post'; | |
| 411 | 378 | $is_editor = method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor(); |
| 412 | 379 | |
| 413 | 380 | $return = []; |
| 414 | 381 | |
| @@ -434,13 +401,8 @@ | ||
| 434 | 401 | if ( ! $is_elementor ) { |
| 435 | 402 | unset( $this->promotions[ $slug ][ $key ] ); |
| 436 | 403 | } |
| 437 | 404 | break; |
| 438 | - case 'edit-post': | |
| 439 | - if ( ! $is_posts ) { | |
| 440 | - unset( $this->promotions[ $slug ][ $key ] ); | |
| 441 | - } | |
| 442 | - break; | |
| 443 | 405 | } |
| 444 | 406 | } |
| 445 | 407 | |
| 446 | 408 | $return = array_merge( $return, $this->promotions[ $slug ] ); |
| @@ -462,11 +424,8 @@ | ||
| 462 | 424 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 463 | 425 | if ( $this->get_upsells_dismiss_time( 'om-media' ) === false ) { |
| 464 | 426 | add_action( 'admin_notices', [ $this, 'render_optimole_dash_notice' ] ); |
| 465 | 427 | } |
| 466 | - if ( $this->get_upsells_dismiss_time( 'rop-posts' ) === false ) { | |
| 467 | - add_action( 'admin_notices', [ $this, 'render_rop_dash_notice' ] ); | |
| 468 | - } | |
| 469 | 428 | |
| 470 | 429 | return; |
| 471 | 430 | } |
| 472 | 431 | |
| @@ -484,12 +443,8 @@ | ||
| 484 | 443 | case 'om-media': |
| 485 | 444 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 486 | 445 | add_action( 'admin_notices', [ $this, 'render_optimole_dash_notice' ] ); |
| 487 | 446 | break; |
| 488 | - case 'rop-posts': | |
| 489 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); | |
| 490 | - add_action( 'admin_notices', [ $this, 'render_rop_dash_notice' ] ); | |
| 491 | - break; | |
| 492 | 447 | } |
| 493 | 448 | } |
| 494 | 449 | |
| 495 | 450 | /** |
| @@ -532,11 +487,9 @@ | ||
| 532 | 487 | 'assets' => $themeisle_sdk_src . 'assets/images/', |
| 533 | 488 | 'optimoleApi' => esc_url( rest_url( 'optml/v1/register_service' ) ), |
| 534 | 489 | 'optimoleActivationUrl' => $this->get_plugin_activation_link( 'optimole-wp' ), |
| 535 | 490 | 'otterActivationUrl' => $this->get_plugin_activation_link( 'otter-blocks' ), |
| 536 | - 'ropActivationUrl' => $this->get_plugin_activation_link( 'tweet-old-post' ), | |
| 537 | 491 | 'optimoleDash' => esc_url( add_query_arg( [ 'page' => 'optimole' ], admin_url( 'upload.php' ) ) ), |
| 538 | - 'ropDash' => esc_url( add_query_arg( [ 'page' => 'TweetOldPost' ], admin_url( 'admin.php' ) ) ), | |
| 539 | 492 | // translators: %s is the product name. |
| 540 | 493 | 'title' => esc_html( sprintf( __( 'Recommended by %s', 'textdomain' ), $this->product->get_name() ) ), |
| 541 | 494 | ] |
| 542 | 495 | ); |
| @@ -544,21 +497,8 @@ | ||
| 544 | 497 | wp_enqueue_style( $handle, $themeisle_sdk_src . 'assets/js/build/style-index.css', [ 'wp-components' ], $asset_file['version'] ); |
| 545 | 498 | } |
| 546 | 499 | |
| 547 | 500 | /** |
| 548 | - * Render rop notice. | |
| 549 | - */ | |
| 550 | - public function render_rop_dash_notice() { | |
| 551 | - $screen = get_current_screen(); | |
| 552 | - | |
| 553 | - if ( ! isset( $screen->id ) || $screen->id !== 'edit-post' ) { | |
| 554 | - return; | |
| 555 | - } | |
| 556 | - | |
| 557 | - echo '<div id="ti-rop-notice" class="notice notice-info ti-sdk-rop-notice"></div>'; | |
| 558 | - } | |
| 559 | - | |
| 560 | - /** | |
| 561 | 501 | * Add promo to attachment modal. |
| 562 | 502 | * |
| 563 | 503 | * @param array $fields Fields array. |
| 564 | 504 | * @param \WP_Post $post Post object. |
| @@ -643,56 +583,6 @@ | ||
| 643 | 583 | |
| 644 | 584 | set_transient( 'tsk_attachment_count', $attachment_count, DAY_IN_SECONDS ); |
| 645 | 585 | } |
| 646 | 586 | return $attachment_count > 50; |
| 647 | - } | |
| 648 | - | |
| 649 | - /** | |
| 650 | - * Check if the website has more than 100 posts and over 10 are over a year old. | |
| 651 | - * | |
| 652 | - * @return bool | |
| 653 | - */ | |
| 654 | - private function has_old_posts() { | |
| 655 | - if ( $this->debug ) { | |
| 656 | - return true; | |
| 657 | - } | |
| 658 | - | |
| 659 | - $posts_count = get_transient( 'tsk_posts_count' ); | |
| 660 | - | |
| 661 | - // Create a new WP_Query object to get all posts | |
| 662 | - $args = array( | |
| 663 | - 'post_type' => 'post', | |
| 664 | - 'posts_per_page' => 101, //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page | |
| 665 | - 'fields' => 'ids', | |
| 666 | - 'no_found_rows' => true, | |
| 667 | - ); | |
| 668 | - | |
| 669 | - if ( false === $posts_count ) { | |
| 670 | - $query = new \WP_Query( $args ); | |
| 671 | - $total_posts = $query->post_count; | |
| 672 | - wp_reset_postdata(); | |
| 673 | - | |
| 674 | - // Count the number of posts older than 1 year | |
| 675 | - $one_year_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-1 year' ) ); | |
| 676 | - $args['date_query'] = array( | |
| 677 | - array( | |
| 678 | - 'before' => $one_year_ago, | |
| 679 | - 'inclusive' => true, | |
| 680 | - ), | |
| 681 | - ); | |
| 682 | - | |
| 683 | - $query = new \WP_Query( $args ); | |
| 684 | - $old_posts = $query->post_count; | |
| 685 | - wp_reset_postdata(); | |
| 686 | - | |
| 687 | - $posts_count = array( | |
| 688 | - 'total_posts' => $total_posts, | |
| 689 | - 'old_posts' => $old_posts, | |
| 690 | - ); | |
| 691 | - | |
| 692 | - set_transient( 'tsk_posts_count', $posts_count, DAY_IN_SECONDS ); | |
| 693 | - } | |
| 694 | - | |
| 695 | - // Check if there are more than 100 posts and more than 10 old posts | |
| 696 | - return $posts_count['total_posts'] > 100 && $posts_count['old_posts'] > 10; | |
| 697 | 587 | } |
| 698 | 588 | } |