setup-wizard
9 months ago
templates
9 months ago
admin-bar.php
9 months ago
admin-helper.php
9 months ago
admin-notices.php
9 months ago
beta-testers.php
9 months ago
duplicator.php
9 months ago
elements.php
9 months ago
feedback.php
9 months ago
keys.php
9 months ago
pa-rollback.php
9 months ago
admin-notices.php
614 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Admin Notices. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Admin\Includes; |
| 7 | |
| 8 | use PremiumAddons\Includes\Helper_Functions; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit(); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Class Admin_Notices |
| 16 | */ |
| 17 | class Admin_Notices { |
| 18 | |
| 19 | /** |
| 20 | * Premium Addons Stories |
| 21 | * |
| 22 | * @var stories |
| 23 | */ |
| 24 | private $stories = array(); |
| 25 | |
| 26 | /** |
| 27 | * Class object |
| 28 | * |
| 29 | * @var instance |
| 30 | */ |
| 31 | private static $instance = null; |
| 32 | |
| 33 | /** |
| 34 | * Elementor slug |
| 35 | * |
| 36 | * @var elementor |
| 37 | */ |
| 38 | private static $elementor = 'elementor'; |
| 39 | |
| 40 | /** |
| 41 | * PAPRO Slug |
| 42 | * |
| 43 | * @var papro |
| 44 | */ |
| 45 | private static $papro = 'premium-addons-pro'; |
| 46 | |
| 47 | /** |
| 48 | * Notices Keys |
| 49 | * |
| 50 | * @var notices |
| 51 | */ |
| 52 | private static $notices = null; |
| 53 | |
| 54 | /** |
| 55 | * Constructor for the class |
| 56 | */ |
| 57 | public function __construct() { |
| 58 | |
| 59 | add_action( 'admin_init', array( $this, 'init' ) ); |
| 60 | |
| 61 | add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 62 | |
| 63 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 64 | |
| 65 | add_action( 'wp_ajax_pa_reset_admin_notice', array( $this, 'reset_admin_notice' ) ); |
| 66 | |
| 67 | add_action( 'wp_ajax_pa_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ) ); |
| 68 | |
| 69 | self::$notices = array( |
| 70 | 'pa-review', |
| 71 | ); |
| 72 | |
| 73 | if ( Helper_Functions::check_hide_notifications() ) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | add_action( 'wp_dashboard_setup', array( $this, 'show_story_widget' ), 111 ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Init |
| 82 | * |
| 83 | * Init required functions |
| 84 | * |
| 85 | * The redirection happens on the first admin page after activation ( the plugins page ). |
| 86 | * |
| 87 | * @since 1.0.0 |
| 88 | * @access public |
| 89 | */ |
| 90 | public function init() { |
| 91 | |
| 92 | $this->handle_review_notice(); |
| 93 | |
| 94 | if ( defined( 'ELEMENTOR_VERSION' ) && get_transient( 'pa_activation_redirect' ) ) { |
| 95 | |
| 96 | delete_transient( 'pa_activation_redirect' ); |
| 97 | |
| 98 | $redirect = add_query_arg( |
| 99 | array( |
| 100 | 'page' => 'pa-setup-wizard', // this mean it should've been added first. |
| 101 | ), |
| 102 | admin_url( 'admin.php' ) |
| 103 | ); |
| 104 | |
| 105 | wp_safe_redirect( $redirect ); |
| 106 | |
| 107 | exit; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Init notices check functions. |
| 113 | */ |
| 114 | public function admin_notices() { |
| 115 | |
| 116 | $this->required_plugins_check(); |
| 117 | |
| 118 | // Make sure "Already did" was not clicked before. |
| 119 | $show_review = get_option( 'pa_review_notice' ); |
| 120 | if ( '1' !== $show_review ) { |
| 121 | |
| 122 | $cache_key = 'pa_review_notice'; |
| 123 | |
| 124 | $response = get_transient( $cache_key ); |
| 125 | |
| 126 | if ( false == $response ) { |
| 127 | $this->show_review_notice(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if ( Helper_Functions::check_hide_notifications() ) { |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Handle Review Notice |
| 139 | * |
| 140 | * Checks if review message is dismissed. |
| 141 | * |
| 142 | * @access public |
| 143 | * @return void |
| 144 | */ |
| 145 | public function handle_review_notice() { |
| 146 | |
| 147 | if ( ! isset( $_GET['pa_review'] ) ) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | if ( 'opt_out' === $_GET['pa_review'] ) { |
| 152 | check_admin_referer( 'opt_out' ); |
| 153 | |
| 154 | update_option( 'pa_review_notice', '1' ); |
| 155 | } |
| 156 | |
| 157 | wp_safe_redirect( remove_query_arg( 'pa_review' ) ); |
| 158 | |
| 159 | exit; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Required plugin check |
| 164 | * |
| 165 | * Shows an admin notice when Elementor is missing. |
| 166 | * |
| 167 | * @since 1.0.0 |
| 168 | * @access public |
| 169 | */ |
| 170 | public function required_plugins_check() { |
| 171 | |
| 172 | $elementor_path = sprintf( '%1$s/%1$s.php', self::$elementor ); |
| 173 | |
| 174 | if ( ! defined( 'ELEMENTOR_VERSION' ) ) { |
| 175 | |
| 176 | if ( ! Helper_Functions::is_plugin_installed( $elementor_path ) ) { |
| 177 | |
| 178 | if ( Admin_Helper::check_user_can( 'install_plugins' ) ) { |
| 179 | |
| 180 | $install_url = wp_nonce_url( self_admin_url( sprintf( 'update.php?action=install-plugin&plugin=%s', self::$elementor ) ), 'install-plugin_elementor' ); |
| 181 | |
| 182 | $message = sprintf( '<p>%s</p>', __( 'Premium Addons for Elementor is not working because you need to Install Elementor plugin.', 'premium-addons-for-elementor' ) ); |
| 183 | |
| 184 | $message .= sprintf( '<p><a href="%s" class="button-primary">%s</a></p>', $install_url, __( 'Install Now', 'premium-addons-for-elementor' ) ); |
| 185 | |
| 186 | } |
| 187 | } elseif ( Admin_Helper::check_user_can( 'activate_plugins' ) ) { |
| 188 | |
| 189 | $activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $elementor_path . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $elementor_path ); |
| 190 | |
| 191 | $message = '<p>' . __( 'Premium Addons for Elementor is not working because you need to activate Elementor plugin.', 'premium-addons-for-elementor' ) . '</p>'; |
| 192 | |
| 193 | $message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, __( 'Activate Now', 'premium-addons-for-elementor' ) ) . '</p>'; |
| 194 | } |
| 195 | $this->render_admin_notices( $message ); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Get Review Text |
| 201 | * |
| 202 | * Gets admin review notice HTML. |
| 203 | * |
| 204 | * @since 2.8.4 |
| 205 | * @access public |
| 206 | * |
| 207 | * @param string $review_url plugin page. |
| 208 | * @param string $optout_url redirect url. |
| 209 | */ |
| 210 | public function get_review_text( $review_url, $optout_url ) { |
| 211 | |
| 212 | $notice = sprintf( |
| 213 | '<p>' . __( 'Could we take just 2 minutes of your time? We\'d be incredibly grateful if you could give ', 'premium-addons-for-elementor' ) . |
| 214 | '<b>' . __( 'Premium Addons for Elementor', 'premium-addons-for-elementor' ) . '</b> a 5 Stars Rating on WordPress.org. Your support helps us continue creating even more amazing free features in the future!</p> |
| 215 | <div> |
| 216 | <a class="button pa-review-btn button-primary" href="%s" target="_blank"><span>' . __( 'Sure, leave a Review', 'premium-addons-for-elementor' ) . '</span></a> |
| 217 | <a class="button" href="%2$s"><span>' . __( 'I Already Did', 'premium-addons-for-elementor' ) . '</span></a> |
| 218 | <a class="button button-secondary pa-notice-reset"><span>' . __( 'Maybe Later', 'premium-addons-for-elementor' ) . '</span></a> |
| 219 | </div>', |
| 220 | $review_url, |
| 221 | $optout_url |
| 222 | ); |
| 223 | |
| 224 | return $notice; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Checks if review admin notice is dismissed |
| 229 | * |
| 230 | * @since 2.6.8 |
| 231 | * @return void |
| 232 | */ |
| 233 | public function show_review_notice() { |
| 234 | |
| 235 | $review_url = 'https://wordpress.org/support/plugin/premium-addons-for-elementor/reviews/#new-post'; |
| 236 | |
| 237 | $optout_url = wp_nonce_url( add_query_arg( 'pa_review', 'opt_out' ), 'opt_out' ); |
| 238 | ?> |
| 239 | |
| 240 | <div class="error pa-notice-wrap pa-review-notice" data-notice="pa-review"> |
| 241 | <div class="pa-img-wrap"> |
| 242 | <img src="<?php echo esc_url( PREMIUM_ADDONS_URL . 'admin/images/pa-logo-symbol.png' ); ?>"> |
| 243 | </div> |
| 244 | <div class="pa-text-wrap"> |
| 245 | <?php echo wp_kses_post( $this->get_review_text( $review_url, $optout_url ) ); ?> |
| 246 | </div> |
| 247 | <div class="pa-notice-close"> |
| 248 | <a href="<?php echo esc_url( $optout_url ); ?>"><span class="dashicons dashicons-dismiss"></span></a> |
| 249 | </div> |
| 250 | </div> |
| 251 | |
| 252 | <?php |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Renders an admin notice error message |
| 257 | * |
| 258 | * @since 1.0.0 |
| 259 | * @access private |
| 260 | * |
| 261 | * @param string $message notice text. |
| 262 | * @param string $class notice class. |
| 263 | * @param string $handle notice handle. |
| 264 | * |
| 265 | * @return void |
| 266 | */ |
| 267 | private function render_admin_notices( $message, $class = '', $handle = '' ) { |
| 268 | ?> |
| 269 | <div class="error pa-new-feature-notice <?php echo esc_attr( $class ); ?>" data-notice="<?php echo esc_attr( $handle ); ?>"> |
| 270 | <?php echo wp_kses_post( $message ); ?> |
| 271 | </div> |
| 272 | <?php |
| 273 | } |
| 274 | |
| 275 | |
| 276 | |
| 277 | /** |
| 278 | * Register admin scripts |
| 279 | * |
| 280 | * @since 3.2.8 |
| 281 | * @access public |
| 282 | */ |
| 283 | public function admin_enqueue_scripts() { |
| 284 | |
| 285 | wp_enqueue_script( |
| 286 | 'pa-dashboard', |
| 287 | PREMIUM_ADDONS_URL . 'admin/assets/js/pa-dashboard.js', |
| 288 | array( 'jquery' ), |
| 289 | PREMIUM_ADDONS_VERSION, |
| 290 | true |
| 291 | ); |
| 292 | |
| 293 | wp_localize_script( |
| 294 | 'pa-dashboard', |
| 295 | 'PaNoticeSettings', |
| 296 | array( |
| 297 | 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
| 298 | 'nonce' => wp_create_nonce( 'pa-notice-nonce' ), |
| 299 | ) |
| 300 | ); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Set transient for admin notice |
| 305 | * |
| 306 | * @since 3.2.8 |
| 307 | * @access public |
| 308 | * |
| 309 | * @return void |
| 310 | */ |
| 311 | public function reset_admin_notice() { |
| 312 | |
| 313 | check_ajax_referer( 'pa-notice-nonce', 'nonce' ); |
| 314 | |
| 315 | if ( ! Admin_Helper::check_user_can( 'manage_options' ) ) { |
| 316 | wp_send_json_error(); |
| 317 | } |
| 318 | |
| 319 | $key = isset( $_POST['notice'] ) ? sanitize_text_field( wp_unslash( $_POST['notice'] ) ) : ''; |
| 320 | |
| 321 | if ( ! empty( $key ) && in_array( $key, self::$notices, true ) ) { |
| 322 | |
| 323 | $cache_key = 'pa_review_notice'; |
| 324 | |
| 325 | set_transient( $cache_key, true, WEEK_IN_SECONDS ); |
| 326 | |
| 327 | wp_send_json_success(); |
| 328 | |
| 329 | } else { |
| 330 | |
| 331 | wp_send_json_error(); |
| 332 | |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Dismiss admin notice |
| 338 | * |
| 339 | * @since 3.11.7 |
| 340 | * @access public |
| 341 | * |
| 342 | * @return void |
| 343 | */ |
| 344 | public function dismiss_admin_notice() { |
| 345 | |
| 346 | check_ajax_referer( 'pa-notice-nonce', 'nonce' ); |
| 347 | |
| 348 | if ( ! current_user_can( 'manage_options' ) ) { |
| 349 | wp_send_json_error(); |
| 350 | } |
| 351 | |
| 352 | $key = isset( $_POST['notice'] ) ? sanitize_text_field( wp_unslash( $_POST['notice'] ) ) : ''; |
| 353 | |
| 354 | if ( ! empty( $key ) && in_array( $key, self::$notices, true ) ) { |
| 355 | |
| 356 | //Make sure new features notices will not appear again. |
| 357 | if( false != strpos( $key, 'not' ) ) { |
| 358 | update_option( $key, '1' ); |
| 359 | } else { |
| 360 | set_transient( $key, true, 20 * DAY_IN_SECONDS ); |
| 361 | |
| 362 | } |
| 363 | |
| 364 | wp_send_json_success(); |
| 365 | |
| 366 | } else { |
| 367 | |
| 368 | wp_send_json_error(); |
| 369 | |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Check Status |
| 375 | * |
| 376 | * @since 4.10.15 |
| 377 | * @access public |
| 378 | */ |
| 379 | public function check_status( $key ) { |
| 380 | |
| 381 | $status = false; |
| 382 | |
| 383 | $api_params = array( |
| 384 | 'edd_action' => 'check_license', |
| 385 | 'license' => $key, |
| 386 | 'item_id' => 361, |
| 387 | ); |
| 388 | |
| 389 | $response = wp_remote_get( |
| 390 | 'http://my.leap13.com', |
| 391 | array( |
| 392 | 'timeout' => 15, |
| 393 | 'sslverify' => false, |
| 394 | 'body' => $api_params, |
| 395 | ) |
| 396 | ); |
| 397 | |
| 398 | if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | $body = wp_remote_retrieve_body( $response ); |
| 403 | |
| 404 | $body = json_decode( $body, true ); |
| 405 | |
| 406 | if ( isset( $body['license'] ) && 'valid' === $body['license'] ) { |
| 407 | $status = true; |
| 408 | } |
| 409 | |
| 410 | return $status; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Get PA Stories |
| 415 | * |
| 416 | * Gets a list of the latest three blog posts |
| 417 | * |
| 418 | * @since 4.10.64 |
| 419 | * |
| 420 | * @access public |
| 421 | */ |
| 422 | public function get_pa_stories() { |
| 423 | |
| 424 | $stories = get_transient( 'pa_stories' ); |
| 425 | |
| 426 | if ( ! $stories ) { |
| 427 | |
| 428 | $api_url = 'https://premiumaddons.com/wp-json/stories/v2/get'; |
| 429 | |
| 430 | $response = wp_remote_get( |
| 431 | $api_url, |
| 432 | array( |
| 433 | 'timeout' => 15, |
| 434 | 'sslverify' => true, |
| 435 | ) |
| 436 | ); |
| 437 | |
| 438 | if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| 439 | set_transient( 'pa_stories', true, WEEK_IN_SECONDS ); |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | $body = wp_remote_retrieve_body( $response ); |
| 444 | $stories = json_decode( $body, true ); |
| 445 | |
| 446 | set_transient( 'pa_stories', $stories, WEEK_IN_SECONDS ); |
| 447 | |
| 448 | } |
| 449 | |
| 450 | $this->stories = $stories; |
| 451 | |
| 452 | return $stories; |
| 453 | } |
| 454 | |
| 455 | public function show_story_widget() { |
| 456 | |
| 457 | $stories = $this->get_pa_stories(); |
| 458 | |
| 459 | if ( ! is_array( $stories ) || empty( $stories ) ) { |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | wp_add_dashboard_widget( |
| 464 | 'pa-stories', |
| 465 | __( 'Premium Addons News', 'premium-addons-for-elementor' ), |
| 466 | array( $this, 'show' ), |
| 467 | null, |
| 468 | null, |
| 469 | 'column3', |
| 470 | 'core' |
| 471 | ); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | public function show() { |
| 476 | |
| 477 | $stories = $this->stories; |
| 478 | |
| 479 | $time = time(); |
| 480 | |
| 481 | $papro_path = 'premium-addons-pro/premium-addons-pro-for-elementor.php'; |
| 482 | |
| 483 | $is_papro_installed = Helper_Functions::is_plugin_installed( $papro_path ); |
| 484 | |
| 485 | ?> |
| 486 | <style> |
| 487 | .pa-banners-grid { |
| 488 | margin-bottom: 10px; |
| 489 | } |
| 490 | |
| 491 | .pa-stories-banner { |
| 492 | position: relative; |
| 493 | } |
| 494 | |
| 495 | .pa-stories-banner a { |
| 496 | position: absolute; |
| 497 | inset: 0; |
| 498 | } |
| 499 | |
| 500 | .pa-story-img-container img { |
| 501 | width: 100%; |
| 502 | display: block; |
| 503 | } |
| 504 | |
| 505 | .pa-news-post { |
| 506 | margin-bottom: 5px; |
| 507 | } |
| 508 | |
| 509 | .pa-news-post a { |
| 510 | font-weight: 500; |
| 511 | color: #0073aa; |
| 512 | text-decoration: none; |
| 513 | padding-bottom: 5px; |
| 514 | display: inline-block; |
| 515 | } |
| 516 | |
| 517 | .pa-dashboard-widget-block { |
| 518 | width: 100%; |
| 519 | } |
| 520 | |
| 521 | .pa-footer-bar { |
| 522 | border-top: 1px solid #eee; |
| 523 | padding-top: 1rem; |
| 524 | display: flex; |
| 525 | justify-content: space-between; |
| 526 | } |
| 527 | |
| 528 | .pa-dashboard-widget-block a { |
| 529 | text-decoration: none; |
| 530 | font-size: 13px; |
| 531 | color: #007cba; |
| 532 | } |
| 533 | |
| 534 | .pa-dashboard-widget-block .dashicons { |
| 535 | vertical-align: middle; |
| 536 | font-size: 17px; |
| 537 | } |
| 538 | </style> |
| 539 | |
| 540 | |
| 541 | <div class="pa-banners-grid"> |
| 542 | |
| 543 | <?php foreach ( $stories['banners'] as $index => $banner ) : ?> |
| 544 | |
| 545 | <?php if ( isset( $banner['end'] ) && $time < $banner['end'] ) : ?> |
| 546 | |
| 547 | <div class="pa-stories-banner"> |
| 548 | <div class="pa-story-img-container"> |
| 549 | <img src="<?php echo esc_url( $banner['image'] ); ?>" alt="<?php echo esc_attr( $banner['description'] ); ?>"> |
| 550 | </div> |
| 551 | <a href="<?php echo esc_url( Helper_Functions::get_campaign_link( $banner['link'], 'dash-widget', 'wp-dash', 'liquid-glass-dash' ) ); ?>" target="_blank" title="<?php echo esc_attr( $banner['description'] ); ?>"></a> |
| 552 | </div> |
| 553 | |
| 554 | <?php endif; ?> |
| 555 | |
| 556 | <?php endforeach; ?> |
| 557 | |
| 558 | </div> |
| 559 | |
| 560 | |
| 561 | <div class="pa-posts-grid"> |
| 562 | |
| 563 | <?php foreach ( $stories['posts'] as $index => $post ) : ?> |
| 564 | |
| 565 | <div class="pa-news-post"> |
| 566 | <a target="_blank" href="<?php echo esc_url( $post['link'] ); ?>"> |
| 567 | <?php echo wp_kses_post( $post['title'] ); ?> |
| 568 | </a> |
| 569 | </div> |
| 570 | |
| 571 | <?php endforeach; ?> |
| 572 | |
| 573 | </div> |
| 574 | |
| 575 | <div class="pa-dashboard-widget-block"> |
| 576 | <div class="pa-footer-bar"> |
| 577 | <a href="https://my.leap13.com/contact-support" target="_blank" style="color: #27ae60"> |
| 578 | Need Help? |
| 579 | <span aria-hidden="true" class="dashicons dashicons-external"></span> |
| 580 | </a> |
| 581 | <a href="https://www.youtube.com/leap13" target="_blank" style="color: #e1002d"> |
| 582 | YouTube Channel |
| 583 | <span aria-hidden="true" class="dashicons dashicons-youtube"></span> |
| 584 | </a> |
| 585 | <a href="https://www.facebook.com/groups/PremiumAddons" target="_blank" style="color: #1877F2;"> |
| 586 | Facebook Community |
| 587 | <span aria-hidden="true" class="dashicons dashicons-facebook-alt"></span> |
| 588 | </a> |
| 589 | </div> |
| 590 | </div> |
| 591 | |
| 592 | <?php |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Creates and returns an instance of the class |
| 597 | * |
| 598 | * @since 2.8.4 |
| 599 | * @access public |
| 600 | * |
| 601 | * @return object |
| 602 | */ |
| 603 | public static function get_instance() { |
| 604 | |
| 605 | if ( ! isset( self::$instance ) ) { |
| 606 | |
| 607 | self::$instance = new self(); |
| 608 | |
| 609 | } |
| 610 | |
| 611 | return self::$instance; |
| 612 | } |
| 613 | } |
| 614 |