Shared.php
302 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.', |
| 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.', |
| 46 | )); |
| 47 | |
| 48 | $tracker->init(); |
| 49 | } |
| 50 | |
| 51 | public function admin_notice() |
| 52 | { |
| 53 | |
| 54 | self::$cache_bank = CacheBank::get_instance(); |
| 55 | |
| 56 | try { |
| 57 | $this->notices(); |
| 58 | } catch (\Exception $e) { |
| 59 | unset($e); |
| 60 | } |
| 61 | |
| 62 | // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice) |
| 63 | NoticeRemover::get_instance('1.0.0'); |
| 64 | } |
| 65 | |
| 66 | public function notices() |
| 67 | { |
| 68 | $_assets_url = plugins_url('assets/', EMBEDPRESS_PLUGIN_BASENAME); |
| 69 | |
| 70 | $notices = new Notices([ |
| 71 | // 'dev_mode' => true, |
| 72 | 'id' => 'embedpress', |
| 73 | 'storage_key' => 'notices', |
| 74 | 'lifetime' => 3, |
| 75 | 'stylesheet_url' => $_assets_url . 'css/admin-notices.css', |
| 76 | 'styles' => $_assets_url . 'css/admin-notices.css', |
| 77 | 'priority' => 6 |
| 78 | ]); |
| 79 | |
| 80 | /** |
| 81 | * This is review message and thumbnail. |
| 82 | */ |
| 83 | $_review_notice = [ |
| 84 | 'thumbnail' => $_assets_url . 'images/icon-128x128.png', |
| 85 | '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>', |
| 86 | 'links' => [ |
| 87 | 'later' => array( |
| 88 | 'link' => 'https://wordpress.org/support/plugin/embedpress/reviews/', |
| 89 | 'target' => '_blank', |
| 90 | 'label' => __('Ok, you deserve it!', 'embedpress'), |
| 91 | 'icon_class' => 'dashicons dashicons-external', |
| 92 | ), |
| 93 | 'allready' => array( |
| 94 | 'label' => __('I already did', 'embedpress'), |
| 95 | 'icon_class' => 'dashicons dashicons-smiley', |
| 96 | 'attributes' => [ |
| 97 | 'data-dismiss' => true |
| 98 | ], |
| 99 | ), |
| 100 | 'maybe_later' => array( |
| 101 | 'label' => __('Maybe Later', 'embedpress'), |
| 102 | 'icon_class' => 'dashicons dashicons-calendar-alt', |
| 103 | 'attributes' => [ |
| 104 | 'data-later' => true |
| 105 | ], |
| 106 | ), |
| 107 | 'support' => array( |
| 108 | 'link' => 'https://wpdeveloper.com/support', |
| 109 | 'label' => __('I need help', 'embedpress'), |
| 110 | 'icon_class' => 'dashicons dashicons-sos', |
| 111 | ), |
| 112 | 'never_show_again' => array( |
| 113 | 'label' => __('Never show again', 'embedpress'), |
| 114 | 'icon_class' => 'dashicons dashicons-dismiss', |
| 115 | 'attributes' => [ |
| 116 | 'data-dismiss' => true |
| 117 | ], |
| 118 | ), |
| 119 | ], |
| 120 | ]; |
| 121 | |
| 122 | $notices->add( |
| 123 | 'review', |
| 124 | $_review_notice, |
| 125 | [ |
| 126 | 'start' => $notices->strtotime('+15 day'), |
| 127 | 'recurrence' => 30, |
| 128 | 'dismissible' => true, |
| 129 | 'refresh' => EMBEDPRESS_VERSION, |
| 130 | ] |
| 131 | ); |
| 132 | |
| 133 | $notices->add( |
| 134 | 'optin', |
| 135 | [$this->insights, 'notice'], |
| 136 | [ |
| 137 | 'start' => $notices->strtotime('+10 day'), |
| 138 | 'recurrence' => 30, |
| 139 | 'dismissible' => true, |
| 140 | 'refresh' => EMBEDPRESS_VERSION, |
| 141 | 'do_action' => 'wpdeveloper_notice_clicked_for_embedpress', |
| 142 | 'display_if' => !is_array($notices->is_installed('embedpress-pro/embedpress-pro.php')) |
| 143 | ] |
| 144 | ); |
| 145 | |
| 146 | // $b_message = '<p style="margin-top: 0; margin-bottom: 10px;">Black Friday Sale: Save up to 40% now & <strong>embed from 250+</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>'; |
| 147 | // $_black_friday_notice = [ |
| 148 | // 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 149 | // 'html' => $b_message, |
| 150 | // ]; |
| 151 | |
| 152 | // $notices->add( |
| 153 | // 'black_friday_notice', |
| 154 | // $_black_friday_notice, |
| 155 | // [ |
| 156 | // 'start' => $notices->time(), |
| 157 | // 'recurrence' => false, |
| 158 | // 'dismissible' => true, |
| 159 | // 'refresh' => EMBEDPRESS_VERSION, |
| 160 | // "expire" => strtotime('11:59:59pm 2nd December, 2023'), |
| 161 | // 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') |
| 162 | // ] |
| 163 | // ); |
| 164 | |
| 165 | // $b_message = '<p style="margin-top: 0; margin-bottom: 10px;"><strong>Akah Join Us in Celebrating 100K+ Users!</strong> Enjoy up to 30% OFF for EmbedPress PRO & embed from 250+ sources</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>'; |
| 166 | // $_black_friday_notice = [ |
| 167 | // 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 168 | // 'html' => $b_message, |
| 169 | // ]; |
| 170 | |
| 171 | // $notices->add( |
| 172 | // '100k_notice', |
| 173 | // $_black_friday_notice, |
| 174 | // [ |
| 175 | // 'start' => $notices->time(), |
| 176 | // 'recurrence' => false, |
| 177 | // 'dismissible' => true, |
| 178 | // 'refresh' => EMBEDPRESS_VERSION, |
| 179 | // "expire" => strtotime('11:59:59pm 12th September, 2024'), |
| 180 | // 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') |
| 181 | // ] |
| 182 | // ); |
| 183 | |
| 184 | // $b_message = '<div class="helloween_2024_notice"><p style="margin-top: 0; margin-bottom: 0px;">🎃 Unlock advanced embedding functionalities with EmbedPress PRO & enjoy <strong>Up to $150 Off</strong> this Halloween.</p><a class="button button-primary" href="https://embedpress.com/halloween-2024/" target="_blank"> |
| 185 | // <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m15.743 10.938.161-1.578c.086-.842.142-1.399.098-1.749h.015c.727 0 1.316-.622 1.316-1.389s-.589-1.389-1.315-1.389c-.727 0-1.316.622-1.316 1.39 0 .346.12.663.32.907-.287.186-.66.58-1.223 1.171-.434.456-.65.684-.893.72a.7.7 0 0 1-.394-.059c-.223-.104-.372-.385-.67-.95l-1.57-2.97a22 22 0 0 0-.476-.873c.569-.306.958-.93.958-1.65C10.754 1.496 9.97.667 9 .667s-1.754.829-1.754 1.852c0 .72.389 1.344.958 1.65-.139.234-.293.525-.476.873l-1.57 2.97c-.298.565-.447.846-.67.95a.7.7 0 0 1-.394.058c-.242-.035-.46-.263-.893-.719-.563-.592-.937-.985-1.223-1.171.2-.244.32-.56.32-.908 0-.767-.589-1.389-1.316-1.389-.726 0-1.315.622-1.315 1.39 0 .766.589 1.388 1.315 1.388h.016c-.045.35.012.906.098 1.749l.16 1.578c.09.876.164 1.71.255 2.46H15.49c.09-.75.165-1.584.254-2.46m-7.698 6.395h1.908c2.488 0 3.732 0 4.562-.784.362-.342.591-.959.757-1.762H2.727c.166.803.395 1.42.757 1.762.83.784 2.074.784 4.562.784" fill="#fff"/></svg> Upgrade to PRO</a></div>'; |
| 186 | // $_helloween_2024_notice = [ |
| 187 | // 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 188 | // 'html' => $b_message, |
| 189 | // ]; |
| 190 | |
| 191 | |
| 192 | // $notices->add( |
| 193 | // 'helloween_2024_notice', |
| 194 | // $_helloween_2024_notice, |
| 195 | // [ |
| 196 | // 'start' => $notices->time(), |
| 197 | // 'recurrence' => false, |
| 198 | // 'dismissible' => true, |
| 199 | // 'refresh' => EMBEDPRESS_VERSION, |
| 200 | // "expire" => strtotime('11:59:59pm 3rd November, 2024'), |
| 201 | // 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') && ($_SERVER['REQUEST_URI'] === '/wp-admin/' || $_SERVER['REQUEST_URI'] === '/wp-admin/index.php'), |
| 202 | // ] |
| 203 | // ); |
| 204 | |
| 205 | // $king_icon = '<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m15.743 10.938.161-1.578c.086-.842.142-1.399.098-1.749h.015c.727 0 1.316-.622 1.316-1.389s-.589-1.389-1.315-1.389c-.727 0-1.316.622-1.316 1.39 0 .346.12.663.32.907-.287.186-.66.58-1.223 1.171-.434.456-.65.684-.893.72a.7.7 0 0 1-.394-.059c-.223-.104-.372-.385-.67-.95l-1.57-2.97a22 22 0 0 0-.476-.873c.569-.306.958-.93.958-1.65C10.754 1.496 9.97.667 9 .667s-1.754.829-1.754 1.852c0 .72.389 1.344.958 1.65-.139.234-.293.525-.476.873l-1.57 2.97c-.298.565-.447.846-.67.95a.7.7 0 0 1-.394.058c-.242-.035-.46-.263-.893-.719-.563-.592-.937-.985-1.223-1.171.2-.244.32-.56.32-.908 0-.767-.589-1.389-1.316-1.389-.726 0-1.315.622-1.315 1.39 0 .766.589 1.388 1.315 1.388h.016c-.045.35.012.906.098 1.749l.16 1.578c.09.876.164 1.71.255 2.46H15.49c.09-.75.165-1.584.254-2.46m-7.698 6.395h1.908c2.488 0 3.732 0 4.562-.784.362-.342.591-.959.757-1.762H2.727c.166.803.395 1.42.757 1.762.83.784 2.074.784 4.562.784" fill="#fff"/></svg>'; |
| 206 | |
| 207 | |
| 208 | // $holiday_message = '<div class="bfriday_2025_notice"><p class="notice-message"><strong>Black Friday Mega Sale:</strong> Custom branding, ads, content protection, analytics and more – now <strong>up to $160 OFF!</strong> 🎁 </p> |
| 209 | // <div class="notice-links"> |
| 210 | // <a class="button button-primary" href="https://embedpress.com/bfcm2025-admin-notice" target="_blank">Upgrade to PRO</a> |
| 211 | // <a class="embedpress-notice-dismiss-button dismiss-btn" data-dismiss="true" href="#" target="_blank">I’ll Grab it Later</a> |
| 212 | |
| 213 | // </div> |
| 214 | // </div>'; |
| 215 | // $_bfriday_2025_notice = [ |
| 216 | // 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 217 | // 'html' => $holiday_message, |
| 218 | // ]; |
| 219 | |
| 220 | // $notices->add( |
| 221 | // 'bfriday_2025_notice', |
| 222 | // $_bfriday_2025_notice, |
| 223 | // [ |
| 224 | // 'start' => $notices->time(), |
| 225 | // 'recurrence' => false, |
| 226 | // 'dismissible' => true, |
| 227 | // 'refresh' => EMBEDPRESS_VERSION, |
| 228 | // "expire" => strtotime('11:59:59pm 4th December, 2026'), |
| 229 | // 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') && ($_SERVER['REQUEST_URI'] === '/wp-admin/' || $_SERVER['REQUEST_URI'] === '/wp-admin/index.php'), |
| 230 | // ] |
| 231 | // ); |
| 232 | |
| 233 | $holiday_message = '<div class="bfriday_2025_notice"><p class="notice-message"><strong>Season\'s Best Deal:</strong> Custom Branding, Ads, Content Protection, Analytics And More – Now <strong>Up To 25% OFF!</strong> ⚡</p> |
| 234 | <div class="notice-links"> |
| 235 | <a class="button button-primary" href="https://embedpress.com/bfcm2025-admin-notice" target="_blank">Upgrade To PRO</a> |
| 236 | <a class="embedpress-notice-dismiss-button dismiss-btn" data-dismiss="true" href="#" target="_blank">I\'ll Grab It Later</a> |
| 237 | |
| 238 | </div> |
| 239 | </div>'; |
| 240 | $_holyday_2025_notice = [ |
| 241 | 'thumbnail' => $_assets_url . 'images/full-logo.svg', |
| 242 | 'html' => $holiday_message, |
| 243 | ]; |
| 244 | |
| 245 | $notices->add( |
| 246 | '_holyday_2025_notice', |
| 247 | $_holyday_2025_notice, |
| 248 | [ |
| 249 | 'start' => strtotime('15th December 2025'), |
| 250 | 'recurrence' => false, |
| 251 | 'dismissible' => true, |
| 252 | 'refresh' => EMBEDPRESS_VERSION, |
| 253 | "expire" => strtotime('11:59:59pm 7th January 2026'), |
| 254 | 'display_if' => !is_plugin_active('embedpress-pro/embedpress-pro.php') && ($_SERVER['REQUEST_URI'] === '/wp-admin/' || $_SERVER['REQUEST_URI'] === '/wp-admin/index.php'), |
| 255 | ] |
| 256 | ); |
| 257 | |
| 258 | $notices->init(); |
| 259 | |
| 260 | self::$cache_bank->create_account($notices); |
| 261 | self::$cache_bank->calculate_deposits($notices); |
| 262 | } |
| 263 | |
| 264 | public function is_pro_active() |
| 265 | { |
| 266 | return is_plugin_active('embedpress-pro/embedpress-pro.php'); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Show Admin notice when one of embedpress old plugin active |
| 271 | * |
| 272 | * @since 2.4.0 |
| 273 | */ |
| 274 | public function embedpress_admin_notice() |
| 275 | { |
| 276 | $compatibility_message = '<p style="margin-top: 0; margin-bottom: 0px;"><strong style="color:#FF7369;">Action Needed:</strong> Please update <strong>EmbedPress Pro</strong> to the latest version (<strong>v3.6.5</strong>) for enhanced features and compatibility.</p>'; |
| 277 | |
| 278 | |
| 279 | if (is_plugin_active('embedpress-pro/embedpress-pro.php') && version_compare(EMBEDPRESS_PRO_PLUGIN_VERSION, '3.6.5', '<')) { |
| 280 | echo '<div class="notice notice-warning">' . $compatibility_message . '</div>'; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | |
| 285 | public function remove_admin_notice() |
| 286 | { |
| 287 | |
| 288 | $current_screen = get_current_screen(); |
| 289 | if ($current_screen->id == 'toplevel_page_embedpress' || $current_screen->id == 'embedpress_page_embedpress-analytics') { |
| 290 | |
| 291 | remove_all_actions('user_admin_notices'); |
| 292 | remove_all_actions('admin_notices'); |
| 293 | |
| 294 | // To showing notice in EA settings page we have to use 'eael_admin_notices' action hook |
| 295 | add_action('admin_notices', function () { |
| 296 | do_action('ep_admin_notices'); |
| 297 | }); |
| 298 | } |
| 299 | |
| 300 | } |
| 301 | } |
| 302 |