From 0037085600d468fd24a60fa6928a99487529fced Mon Sep 17 00:00:00 2001 From: Armanul46 <47377178+Armanul46@users.noreply.github.com> Date: Wed, 22 Apr 2026 13:05:24 +0600 Subject: [PATCH 1/2] dashboard notice --- includes/classes/class-directorist-api.php | 16 ++++ includes/classes/class-upgrade.php | 105 +++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/includes/classes/class-directorist-api.php b/includes/classes/class-directorist-api.php index 22f8718b79..f926781a2e 100644 --- a/includes/classes/class-directorist-api.php +++ b/includes/classes/class-directorist-api.php @@ -31,6 +31,22 @@ public static function get_promotion() { return $promotion; } + public static function get_dashboard_promo() { + $promotion = get_transient( 'directorist_dashboard_promo' ); + + if ( ! empty( $promotion ) ) { + return $promotion; + } + + $promotion = static::get( 'v1/get-dashboard-notice' ); + $promotion = json_decode( $promotion ); + $end_time = static::get_promotion_end_time( $promotion ); + + set_transient( 'directorist_dashboard_promo', $promotion, $end_time ); + + return $promotion; + } + protected static function get_promotion_end_time( $promotion ) { if ( empty( $promotion ) || ( is_object( $promotion ) && empty( $promotion->promo_end_date ) ) || diff --git a/includes/classes/class-upgrade.php b/includes/classes/class-upgrade.php index aa2a5cf517..3216a004ee 100644 --- a/includes/classes/class-upgrade.php +++ b/includes/classes/class-upgrade.php @@ -33,6 +33,99 @@ public function __construct() { // Migrate assign_to to conditional logic (custom fields only) add_action( 'admin_init', [ $this, 'migrate_assign_to_conditional_logic' ] ); + + add_action( 'admin_notices', [ $this, 'dashboard_upgrade_notice' ] ); + + } + + public function dashboard_upgrade_notice() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + if ( ! function_exists( 'get_current_screen' ) ) { + return; + } + + $screen = get_current_screen(); + + if ( ! $screen || 'dashboard' !== $screen->base ) { + return; + } + + $data = API::get_dashboard_promo(); + + if ( empty( $data ) || empty( $data->display_notice ) ) { + return; + } + + $promo_version = ! empty( $data->promo_version ) ? sanitize_text_field( $data->promo_version ) : ''; + $closed_version = get_user_meta( get_current_user_id(), 'directorist_dashboard_promo_closed_version', true ); + $banner_title = ! empty( $data->banner_title ) ? sanitize_text_field( $data->banner_title ) : __( 'Directorist Pro', 'directorist' ); + $sale_text = ! empty( $data->sale_text ) ? sanitize_text_field( $data->sale_text ) : ''; + $upgrade_text = ! empty( $data->upgrade_now_text ) ? sanitize_text_field( $data->upgrade_now_text ) : __( 'Upgrade Now', 'directorist' ); + $upgrade_url = ! empty( $data->upgrade_now_text_link ) ? esc_url( $data->upgrade_now_text_link ) : ''; + $sale_button_url = ! empty( $data->sale_button_link ) ? esc_url( $data->sale_button_link ) : ''; + + if ( $promo_version && $closed_version === $promo_version ) { + return; + } + + if ( empty( $upgrade_url ) ) { + $upgrade_url = $sale_button_url; + } + + if ( empty( $upgrade_url ) ) { + return; + } + + $dismiss_url = add_query_arg( + array( + 'close-directorist-dashboard-promo-version' => $promo_version, + 'directorist_dashboard_promo_nonce' => wp_create_nonce( 'directorist_dashboard_promo_nonce' ), + ), + admin_url( 'index.php' ) + ); + ?> +
+
+

+ + + +

+ +

+ + + + + + + + + + +

+
+ + + + +
+ 403 ) ); + } + + update_user_meta( + get_current_user_id(), + 'directorist_dashboard_promo_closed_version', + directorist_clean( wp_unslash( $_GET['close-directorist-dashboard-promo-version'] ) ) + ); + } } public static function promo_link( $link ) { From 466654771b06c791d40956c5fca78315985652d4 Mon Sep 17 00:00:00 2001 From: Armanul46 <47377178+Armanul46@users.noreply.github.com> Date: Wed, 22 Apr 2026 13:18:54 +0600 Subject: [PATCH 2/2] improve notice --- includes/classes/class-upgrade.php | 77 ++---------------- .../admin-dashboard-notice.php | 78 +++++++++++++++++++ 2 files changed, 83 insertions(+), 72 deletions(-) create mode 100644 views/admin-templates/admin-dashboard-notice.php diff --git a/includes/classes/class-upgrade.php b/includes/classes/class-upgrade.php index 3216a004ee..59092b36d0 100644 --- a/includes/classes/class-upgrade.php +++ b/includes/classes/class-upgrade.php @@ -53,79 +53,8 @@ public function dashboard_upgrade_notice() { return; } - $data = API::get_dashboard_promo(); + ATBDP()->load_template( 'admin-templates/admin-dashboard-notice' ); - if ( empty( $data ) || empty( $data->display_notice ) ) { - return; - } - - $promo_version = ! empty( $data->promo_version ) ? sanitize_text_field( $data->promo_version ) : ''; - $closed_version = get_user_meta( get_current_user_id(), 'directorist_dashboard_promo_closed_version', true ); - $banner_title = ! empty( $data->banner_title ) ? sanitize_text_field( $data->banner_title ) : __( 'Directorist Pro', 'directorist' ); - $sale_text = ! empty( $data->sale_text ) ? sanitize_text_field( $data->sale_text ) : ''; - $upgrade_text = ! empty( $data->upgrade_now_text ) ? sanitize_text_field( $data->upgrade_now_text ) : __( 'Upgrade Now', 'directorist' ); - $upgrade_url = ! empty( $data->upgrade_now_text_link ) ? esc_url( $data->upgrade_now_text_link ) : ''; - $sale_button_url = ! empty( $data->sale_button_link ) ? esc_url( $data->sale_button_link ) : ''; - - if ( $promo_version && $closed_version === $promo_version ) { - return; - } - - if ( empty( $upgrade_url ) ) { - $upgrade_url = $sale_button_url; - } - - if ( empty( $upgrade_url ) ) { - return; - } - - $dismiss_url = add_query_arg( - array( - 'close-directorist-dashboard-promo-version' => $promo_version, - 'directorist_dashboard_promo_nonce' => wp_create_nonce( 'directorist_dashboard_promo_nonce' ), - ), - admin_url( 'index.php' ) - ); - ?> -
-
-

- - - -

- -

- - - - - - - - - - -

-
- - - - -
- display_notice ) ) { + return; +} + +$promo_version = ! empty( $data->promo_version ) ? sanitize_text_field( $data->promo_version ) : ''; +$closed_version = get_user_meta( get_current_user_id(), 'directorist_dashboard_promo_closed_version', true ); +$banner_title = ! empty( $data->banner_title ) ? sanitize_text_field( $data->banner_title ) : __( 'Directorist Pro', 'directorist' ); +$sale_text = ! empty( $data->sale_text ) ? sanitize_text_field( $data->sale_text ) : ''; +$upgrade_text = ! empty( $data->upgrade_now_text ) ? sanitize_text_field( $data->upgrade_now_text ) : __( 'Upgrade Now', 'directorist' ); +$upgrade_url = ! empty( $data->upgrade_now_text_link ) ? esc_url( $data->upgrade_now_text_link ) : ''; +$sale_button_url = ! empty( $data->sale_button_link ) ? esc_url( $data->sale_button_link ) : ''; + +if ( $promo_version && $closed_version === $promo_version ) { + return; +} + +if ( empty( $upgrade_url ) ) { + $upgrade_url = $sale_button_url; +} + +if ( empty( $upgrade_url ) ) { + return; +} + +$dismiss_url = add_query_arg( + array( + 'close-directorist-dashboard-promo-version' => $promo_version, + 'directorist_dashboard_promo_nonce' => wp_create_nonce( 'directorist_dashboard_promo_nonce' ), + ), + admin_url( 'index.php' ) +); +?> +
+
+

+ + + +

+ +

+ + + + + + + + + + +

+
+ + + + +