Skip to content

Commit

Permalink
Merge branch 'release/1.13.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Hemberger committed Apr 27, 2022
2 parents be58b9a + 19a4e50 commit 8ceacc1
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.13.1 (4/27/22)
* Fixed: Admin notice not staying dismissed after Dashboard page refresh in some scenarios.

## 1.13.0 (4/25/22)
* Added: Admin notice about WordPress ending support for the classic editor and upgrading to Mai Theme v2.
* Changed: Update CMB2 to 2.10.1.
Expand Down
106 changes: 97 additions & 9 deletions lib/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,62 @@
/**
* Add dismissible upgrade notice.
*
* @since TBD
* @since 1.13.0
*
* @return void
*/
add_action( 'admin_notices', 'mai_upgrade_notice', 4 );
function mai_upgrade_notice() {
$days = 14;
$dismissible = sprintf( 'mai_upgrade_notice-%s', $days );
$url = 'https://help.bizbudding.com/article/209-upgrade?utm_source=mai-theme-engine&utm_medium=link&utm_campaign=v1';

if ( class_exists( 'PAnD' ) && ! PAnD::is_admin_notice_active( $dismissible ) ) {
if ( ! current_user_can( 'switch_themes' ) ) {
return;
}

printf( '<div class="notice is-dismissible mai-upgrade-notice" data-dismissible="%s">', $dismissible );
$url = 'https://help.bizbudding.com/article/209-upgrade?utm_source=mai-theme-engine&utm_medium=link&utm_campaign=v1';
$timestamp = get_user_option( 'mai_upgrade_notice', get_current_user_id() );

// Bail if already dismissed.
if ( $timestamp && current_time( 'timestamp' ) < $timestamp ) {
return;
}
?>
<div class="notice mai-upgrade-notice">
<style>
.mai-upgrade-notice {
--bizbudding-green: #bcda83;
--bizbudding-green-dark: #a5ce5a;
position: relative;
display: grid;
gap: 24px;
gap: 16px;
grid-template-columns: 36px 1fr auto;
padding: 12px 18px;
padding: 24px 18px;
border-left: 8px solid var(--bizbudding-green);
border-radius: 4px;
box-shadow: 0px 14px 20px -8px rgba(0,0,0,0.1);
}
.mai-upgrade-actions {
position: absolute;
top: 8px;
right: 16px;
margin: 0 !important;
color rgba(0, 0, 0, 0.5);
}
.mai-upgrade-notice .mai-upgrade-dismiss {
color: currentColor;
font-variant: all-small-caps;
text-decoration: none;
transition: all 0.1s ease-in-out;
}
.mai-upgrade-notice .mai-upgrade-dismiss:hover,
.mai-upgrade-notice .mai-upgrade-dismiss:focus {
opacity: 1 !important;
}
.mai-upgrade-notice .mai-upgrade-dismiss-later:hover,
.mai-upgrade-notice .mai-upgrade-dismiss-later:focus {
color: var(--bizbudding-green-dark) !important;
}
.mai-upgrade-notice .mai-upgrade-dismiss::before {
display: none !important;
}
.mai-upgrade-notice img {
display: block;
max-width: 36px;
Expand Down Expand Up @@ -58,6 +86,11 @@ function mai_upgrade_notice() {
place-items: center;
}
</style>
<p class="mai-upgrade-actions">
<a class="mai-upgrade-dismiss" data-weeks="9999" role="button" href="#" style="opacity:0.5;"><?php echo __( 'Do not ask again', 'mai-theme-engine' ); ?></a>
<span style="margin:0 8px;opacity:0.5;">|</span>
<a class="mai-upgrade-dismiss mai-upgrade-dismiss-later" data-weeks="4" role="button" href="#"><?php echo __( 'Remind me later', 'mai-theme-engine' ); ?>&nbsp;<span class="dashicons dashicons-no-alt"></span></a>
</p>
<div class="mai-notice-col">
<?php printf( '<img width="36" height="36" src="%s">', MAI_THEME_ENGINE_PLUGIN_URL . 'assets/images/icon-128x128.png' ); ?>
</div>
Expand All @@ -70,6 +103,61 @@ function mai_upgrade_notice() {
</div>
</div>
<?php
/**
* Adds ajax script to the footer.
*
* @return void
*/
add_action( 'admin_footer', function() {
$ajaxurl = admin_url( 'admin-ajax.php' );
?>
<script>
jQuery(document).ready(function($) {
$( '.mai-upgrade-notice' ).on( 'click', '.mai-upgrade-dismiss', function(e) {
e.preventDefault();
jQuery.ajax({
type: 'post',
url: '<?php echo $ajaxurl; ?>',
data: {
action: 'mai_dismiss_upgrade_notice',
weeks: $(this).data( 'weeks' ),
},
success: function( response ) {
$( '.mai-upgrade-notice' ).fadeOut();
},
});
});
});
</script>
<?php
});
}

/**
* Adds user option to dismiss upgrade notice for set amount of time.
*
* @since 1.13.1
*
* @return void
*/
add_action( 'wp_ajax_mai_dismiss_upgrade_notice', 'mai_dismiss_upgrade_notice' );
function mai_dismiss_upgrade_notice() {
if ( ! current_user_can( 'switch_themes' ) ) {
wp_die(
__( 'You do not have permission.', 'mai-theme-engine' ),
__( 'Error', 'mai-theme-engine' ),
[
'response' => 403,
]
);
}

$weeks = filter_input( INPUT_POST, 'weeks', FILTER_SANITIZE_NUMBER_INT );
$weeks = $weeks ?: 4;
$now = current_time( 'timestamp' );
$again = strtotime( sprintf( '+%s weeks', $weeks ), $now );

update_user_option( get_current_user_id(), 'mai_upgrade_notice', $again );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions mai-theme-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://bizbudding.com/mai-theme/
* Description: The Mai Theme Engine plugin
*
* Version: 1.13.0
* Version: 1.13.1
*
* GitHub URI: maithemewp/mai-theme-engine
*
Expand Down Expand Up @@ -89,7 +89,7 @@ public function __wakeup() {
private function setup_constants() {

// Plugin version.
define( 'MAI_THEME_ENGINE_VERSION', '1.13.0' );
define( 'MAI_THEME_ENGINE_VERSION', '1.13.1' );

// DB version.
define( 'MAI_THEME_ENGINE_DB_VERSION', '1600' );
Expand Down

0 comments on commit 8ceacc1

Please sign in to comment.