Shared.php
182 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Includes\Traits; |
| 4 | |
| 5 | |
| 6 | if (!defined('ABSPATH')) { |
| 7 | exit; |
| 8 | } // Exit if accessed directly |
| 9 | use \EmbedPress\Includes\Classes\EmbedPress_Plugin_Usage_Tracker; |
| 10 | use \EmbedPress\Includes\Classes\EmbedPress_Notice; |
| 11 | |
| 12 | use PriyoMukul\WPNotice\Notices; |
| 13 | |
| 14 | use PriyoMukul\WPNotice\Utils\CacheBank; |
| 15 | use PriyoMukul\WPNotice\Utils\NoticeRemover; |
| 16 | |
| 17 | trait Shared |
| 18 | { |
| 19 | |
| 20 | private $insights = null; |
| 21 | |
| 22 | /** |
| 23 | * @var CacheBank |
| 24 | */ |
| 25 | private static $cache_bank; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Optional usage tracker |
| 30 | * |
| 31 | * @since v1.0.0 |
| 32 | */ |
| 33 | public function start_plugin_tracking() |
| 34 | { |
| 35 | $this->insights = $tracker = EmbedPress_Plugin_Usage_Tracker::get_instance(EMBEDPRESS_FILE, [ |
| 36 | 'opt_in' => true, |
| 37 | 'goodbye_form' => true, |
| 38 | 'item_id' => '98ba0ac16a4f7b3b940d' |
| 39 | ]); |
| 40 | $tracker->set_notice_options(array( |
| 41 | 'notice' => __('Want to help make <strong>EmbedPress</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Premium extensions if you allow us to track the usage.', 'embedpress'), |
| 42 | 'extra_notice' => __('We collect non-sensitive diagnostic data and plugin usage information. |
| 43 | Your site URL, WordPress & PHP version, plugins & themes and email address to send you the |
| 44 | discount coupon. This data lets us make sure this plugin always stays compatible with the most |
| 45 | popular plugins and themes. No spam, I promise.', 'embedpress'), |
| 46 | )); |
| 47 | $tracker->init(); |
| 48 | } |
| 49 | |
| 50 | public function admin_notice() |
| 51 | { |
| 52 | |
| 53 | self::$cache_bank = CacheBank::get_instance(); |
| 54 | |
| 55 | try { |
| 56 | $this->notices(); |
| 57 | } catch (Exception $e) { |
| 58 | unset($e); |
| 59 | } |
| 60 | |
| 61 | // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice) |
| 62 | NoticeRemover::get_instance('1.0.0'); |
| 63 | } |
| 64 | |
| 65 | public function notices() |
| 66 | { |
| 67 | $_assets_url = plugins_url('assets/', EMBEDPRESS_PLUGIN_BASENAME); |
| 68 | |
| 69 | $notices = new Notices([ |
| 70 | 'id' => 'embedpress', |
| 71 | 'storage_key' => 'notices', |
| 72 | 'lifetime' => 3, |
| 73 | 'stylesheet_url' => $_assets_url . 'css/admin-notices.css', |
| 74 | 'styles' => $_assets_url . 'css/admin-notices.css', |
| 75 | 'priority' => 6 |
| 76 | ]); |
| 77 | |
| 78 | /** |
| 79 | * This is review message and thumbnail. |
| 80 | */ |
| 81 | $_review_notice = [ |
| 82 | 'thumbnail' => $_assets_url . 'images/icon-128x128.png', |
| 83 | 'html' => '<p>' . __('We hope you\'re enjoying EmbedPress! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'embedpress') . '</p>', |
| 84 | 'links' => [ |
| 85 | 'later' => array( |
| 86 | 'link' => 'https://wordpress.org/support/plugin/embedpress/reviews/', |
| 87 | 'target' => '_blank', |
| 88 | 'label' => __('Ok, you deserve it!', 'wp-scheduled-posts'), |
| 89 | 'icon_class' => 'dashicons dashicons-external', |
| 90 | ), |
| 91 | 'allready' => array( |
| 92 | 'label' => __('I already did', 'wp-scheduled-posts'), |
| 93 | 'icon_class' => 'dashicons dashicons-smiley', |
| 94 | 'attributes' => [ |
| 95 | 'data-dismiss' => true |
| 96 | ], |
| 97 | ), |
| 98 | 'maybe_later' => array( |
| 99 | 'label' => __('Maybe Later', 'wp-scheduled-posts'), |
| 100 | 'icon_class' => 'dashicons dashicons-calendar-alt', |
| 101 | 'attributes' => [ |
| 102 | 'data-later' => true |
| 103 | ], |
| 104 | ), |
| 105 | 'support' => array( |
| 106 | 'link' => 'https://wpdeveloper.com/support', |
| 107 | 'label' => __('I need help', 'wp-scheduled-posts'), |
| 108 | 'icon_class' => 'dashicons dashicons-sos', |
| 109 | ), |
| 110 | 'never_show_again' => array( |
| 111 | 'label' => __('Never show again', 'wp-scheduled-posts'), |
| 112 | 'icon_class' => 'dashicons dashicons-dismiss', |
| 113 | 'attributes' => [ |
| 114 | 'data-dismiss' => true |
| 115 | ], |
| 116 | ), |
| 117 | ], |
| 118 | ]; |
| 119 | |
| 120 | $notices->add( |
| 121 | 'review', |
| 122 | $_review_notice, |
| 123 | [ |
| 124 | 'start' => $notices->strtotime('+15 day'), |
| 125 | 'recurrence' => 30, |
| 126 | 'dismissible' => true, |
| 127 | 'refresh' => EMBEDPRESS_VERSION, |
| 128 | ] |
| 129 | ); |
| 130 | |
| 131 | $notices->add( |
| 132 | 'optin', |
| 133 | [$this->insights, 'notice'], |
| 134 | [ |
| 135 | 'start' => $notices->strtotime('+10 day'), |
| 136 | 'recurrence' => 30, |
| 137 | 'dismissible' => true, |
| 138 | 'refresh' => EMBEDPRESS_VERSION, |
| 139 | 'do_action' => 'wpdeveloper_notice_clicked_for_embedpress', |
| 140 | 'display_if' => !is_array($notices->is_installed('embedpress-pro/embedpress-pro.php')) |
| 141 | ] |
| 142 | ); |
| 143 | |
| 144 | $b_message = '<p style="margin-top: 0; margin-bottom: 10px;">Black Friday Sale: Save up to 40% now & <strong>embed from 150+</strong> sources with advanced features ⚡</p><a class="button button-primary" href="https://wpdeveloper.com/upgrade/embedpress-bfcm" target="_blank">Upgrade to pro</a> <button data-dismiss="true" class="dismiss-btn button button-link">I don’t want to save money</button>'; |
| 145 | $_black_friday_notice = [ |
| 146 | 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 147 | 'html' => $b_message, |
| 148 | ]; |
| 149 | |
| 150 | $notices->add( |
| 151 | 'black_friday_notice', |
| 152 | $_black_friday_notice, |
| 153 | [ |
| 154 | 'start' => $notices->time(), |
| 155 | 'recurrence' => false, |
| 156 | 'dismissible' => true, |
| 157 | 'refresh' => EMBEDPRESS_VERSION, |
| 158 | "expire" => strtotime('11:59:59pm 2nd December, 2023'), |
| 159 | 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') |
| 160 | ] |
| 161 | ); |
| 162 | |
| 163 | $notices->init(); |
| 164 | |
| 165 | self::$cache_bank->create_account($notices); |
| 166 | self::$cache_bank->calculate_deposits($notices); |
| 167 | } |
| 168 | |
| 169 | public function is_pro_active() |
| 170 | { |
| 171 | return is_plugin_active('embedpress-pro/embedpress-pro.php'); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Show Admin notice when one of embedpress old plugin active |
| 176 | * |
| 177 | * @since 2.4.0 |
| 178 | */ |
| 179 | public function embedpress_admin_notice() |
| 180 | { } |
| 181 | } |
| 182 |