get_plugin_name() ); } /** * Constructor to initialize the promotion notice. */ public function __construct() { add_action( 'current_screen', [ $this, 'register_promotion_hooks' ] ); add_action( 'wp_ajax_' . self::AJAX_ACTION, [ $this, 'dismiss_promotion_ajax_handler' ] ); } /** * Register hooks to display the promotion notice if conditions are met. */ public function register_promotion_hooks() { if ( $this->is_plugin_admin_screen() && ! $this->is_promotion_dismissed() ) { add_action( 'admin_notices', [ $this, 'display_promotion' ], 1 ); add_action( 'admin_print_styles', [ $this, 'print_promotion_styles' ] ); add_action( 'admin_print_footer_scripts', [ $this, 'print_dismiss_script' ], 99 ); } } /** * Determine if the current admin screen is one of the plugin's admin screens. * * @return bool True if it's a plugin admin screen, false otherwise. */ public function is_plugin_admin_screen(): bool { if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) { return false; } $current_screen = get_current_screen(); return $current_screen && in_array( $current_screen->id, $this->get_plugin_admin_screens(), true ); } /** * Check if the promotion has been dismissed by the current user. * * @return bool True if the promotion is dismissed, false otherwise. */ public function is_promotion_dismissed(): bool { if ( get_setting( 'general', 'hide_upgrade_menu' ) ) { return true; } $user_id = get_current_user_id(); if ( ! $user_id ) { return false; } $dismissed_promotions = get_user_meta( $user_id, self::USER_META_KEY, true ); return is_array( $dismissed_promotions ) && in_array( $this->get_plugin_slug(), $dismissed_promotions, true ); } /** * Print the CSS styles for the promotion notice. */ public function print_promotion_styles() { ?>
get_promotion_heading() ); ?>
get_promotion_message() ); ?>
print_promotion_buttons(); ?>