| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || die(); |
| 4 |
|
| 5 |
/** |
| 6 |
* Components class. |
| 7 |
* |
| 8 |
* @since 1.1.0 |
| 9 |
* @SuppressWarnings(PHPMD.NPathComplexity) |
| 10 |
*/ |
| 11 |
class Sellkit_Notices { |
| 12 |
|
| 13 |
/** |
| 14 |
* Sellkit_Notices constructor. |
| 15 |
* |
| 16 |
* @since 1.1.0 |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
$this->load_notices(); |
| 20 |
|
| 21 |
add_action( 'wp_ajax_sellkit_admin_notice_dismiss', [ $this, 'dismiss_notice' ] ); |
| 22 |
add_action( 'wp_ajax_sellkit_admin_notice_maybe_later', [ $this, 'handle_maybe_later_rating_btn' ] ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Handle maybe later button. |
| 27 |
* |
| 28 |
* @since 1.5.7 |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public function handle_maybe_later_rating_btn() { |
| 32 |
check_ajax_referer( 'sellkit_admin', 'nonce' ); |
| 33 |
|
| 34 |
sellkit_update_option( 'sellkit_rating_notice_trigger', time() + 48 * 60 * 60 ); |
| 35 |
wp_send_json_success( esc_html__( 'The operation was successful.', 'sellkit' ) ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Load notices. |
| 40 |
* |
| 41 |
* @since 1.1.0 |
| 42 |
* @param string $plugin_name Plugin name. |
| 43 |
*/ |
| 44 |
public function load_notices( $plugin_name = 'sellkit' ) { |
| 45 |
$path = trailingslashit( sellkit()->plugin_dir() . 'includes/admin/notices' ); |
| 46 |
|
| 47 |
if ( |
| 48 |
'sellkit-pro' === $plugin_name && |
| 49 |
sellkit()->has_pro && |
| 50 |
file_exists( sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php' ) |
| 51 |
) { |
| 52 |
$path = trailingslashit( sellkit_pro()->plugin_dir() . 'includes/admin/notices' ); |
| 53 |
require_once sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php'; |
| 54 |
} |
| 55 |
|
| 56 |
$file_paths = glob( $path . '*.php' ); |
| 57 |
|
| 58 |
foreach ( $file_paths as $file_path ) { |
| 59 |
if ( ! file_exists( $file_path ) ) { |
| 60 |
continue; |
| 61 |
} |
| 62 |
|
| 63 |
require_once $file_path; |
| 64 |
|
| 65 |
$file_name = str_replace( '.php', '', basename( $file_path ) ); |
| 66 |
$operator_class = str_replace( '-', ' ', $file_name ); |
| 67 |
$operator_class = str_replace( ' ', '_', ucwords( $operator_class ) ); |
| 68 |
|
| 69 |
if ( 'sellkit' === $plugin_name ) { |
| 70 |
$operator_class = "Sellkit\Admin\Notices\\{$operator_class}"; |
| 71 |
} |
| 72 |
|
| 73 |
if ( 'sellkit-pro' === $plugin_name && sellkit()->has_pro ) { |
| 74 |
$operator_class = "Sellkit_Pro\Admin\Notices\\{$operator_class}"; |
| 75 |
} |
| 76 |
|
| 77 |
if ( ! class_exists( $operator_class ) || 'notice-base' === $file_name ) { |
| 78 |
continue; |
| 79 |
} |
| 80 |
|
| 81 |
$notice = new $operator_class(); |
| 82 |
|
| 83 |
if ( $notice->is_valid() ) { |
| 84 |
add_action( 'admin_notices', [ $notice, 'notice_content_wrapper' ], $notice->priority() ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if ( sellkit()->has_pro && 'sellkit' === $plugin_name ) { |
| 89 |
$this->load_notices( 'sellkit-pro' ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Dismiss notice handler. |
| 95 |
* |
| 96 |
* @since 1.1.0 |
| 97 |
*/ |
| 98 |
public function dismiss_notice() { |
| 99 |
check_ajax_referer( 'sellkit_admin', 'nonce' ); |
| 100 |
|
| 101 |
$new_notice_key = ! empty( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : ''; |
| 102 |
$dismissed_notices = sellkit_get_option( 'dismissed_notices' ); |
| 103 |
$dismissed_notices = empty( $dismissed_notices ) ? [] : $dismissed_notices; |
| 104 |
$new_dismissed_notices = array_merge( $dismissed_notices, [ $new_notice_key ] ); |
| 105 |
|
| 106 |
sellkit_update_option( 'dismissed_notices', array_filter( array_unique( $new_dismissed_notices ) ) ); |
| 107 |
|
| 108 |
if ( 'sellkit-partners-theme-offer' === $new_notice_key ) { |
| 109 |
update_option( 'sellkit-partner-offer-theme-dismissed', time() ); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
new Sellkit_Notices(); |
| 115 |
|