Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions includes/classes/class-directorist-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) ||
Expand Down
38 changes: 38 additions & 0 deletions includes/classes/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ 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;
}

ATBDP()->load_template( 'admin-templates/admin-dashboard-notice' );

}

/**
Expand Down Expand Up @@ -687,6 +709,10 @@ public static function promo_remote_get() {
return API::get_promotion();
}

public static function dashboard_promo_remote_get() {
return API::get_dashboard_promo();
}

public function upgrade_notice() {
if ( ! self::can_manage_plugins() ) {
return;
Expand Down Expand Up @@ -805,6 +831,18 @@ public function configure_notices() {
}
update_user_meta( get_current_user_id(), 'directorist_promo2_closed_version', directorist_clean( wp_unslash( $_GET['directorist_promo2_closed_version'] ) ) );
}

if ( isset( $_GET['close-directorist-dashboard-promo-version'] ) ) {
if ( empty( $_GET['directorist_dashboard_promo_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['directorist_dashboard_promo_nonce'] ) ), 'directorist_dashboard_promo_nonce' ) ) {
wp_die( esc_html__( 'Security check failed.', 'directorist' ), '', array( 'response' => 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 ) {
Expand Down
78 changes: 78 additions & 0 deletions views/admin-templates/admin-dashboard-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* @package Directorist
* @since 8.7.1
* @version 8.7.1
*/

$data = ATBDP_Upgrade::dashboard_promo_remote_get();
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' )
);
?>
<div
class="notice is-dismissible"
style="display: flex; flex-wrap:wrap; justify-content:space-between"
>
<div style="display: flex; flex-wrap:wrap; justify-content:space-between">
<p style="">
<span style="display: flex; flex-wrap:wrap; justify-content:space-between">
<?php echo esc_html( $banner_title ); ?>
</span>
</p>

<p style="display: flex; flex-wrap:wrap; justify-content:space-between">
<strong style="font-weight:700;">
<?php esc_html_e( 'Your directory is leaving money on the table,', 'directorist' ); ?>
</strong>
<?php esc_html_e( ' charges for listings, takes bookings, accepts payments & more.', 'directorist' ); ?>
<?php if ( $sale_text ) : ?>
<strong style="font-weight:700;"> <?php echo esc_html( $sale_text ); ?></strong>
<?php endif; ?>
<a
href="<?php echo esc_url( $upgrade_url ); ?>"
target="_blank"
rel="noopener noreferrer"
style="display:inline-block;margin-left:18px;color:#2563eb;font-weight:700;text-decoration:none;"
>
<?php echo esc_html( $upgrade_text ); ?> <span aria-hidden="true">&rarr;</span>
</a>
</p>
</div>

<a
class="notice-dismiss"
href="<?php echo esc_url( $dismiss_url ); ?>"
style="top:50%;right:22px;transform:translateY(-50%);width:32px;height:32px;text-decoration:none;color:#98a2b3;"
>
<span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'directorist' ); ?></span>
</a>
</div>
Loading