- future list notice;

- admin notices dimissible feature;
This commit is contained in:
nikitozzzzzzz
2018-06-11 00:01:23 +03:00
parent 770a5f73af
commit 4feea4e9a6
3 changed files with 64 additions and 3 deletions
@@ -216,4 +216,22 @@ jQuery(document).ready(function() {
}
});
jQuery(document).on( 'click', '.um-admin-notice.is-dismissible .notice-dismiss', function(e) {
var notice_key = jQuery(this).parents('.um-admin-notice').data('key');
wp.ajax.send( 'um_dimiss_notice', {
data: {
key: notice_key,
nonce: um_admin_scripts.nonce
},
success: function( data ) {
return true;
},
error: function( data ) {
return false;
}
});
});
});
+1 -1
View File
@@ -302,7 +302,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) {
* Load jQuery custom code
*/
function load_custom_scripts() {
wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', '', '', true );
wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', array('jquery','wp-util'), '', true );
wp_enqueue_script( 'um_admin_scripts' );
}
+45 -2
View File
@@ -29,6 +29,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
add_action( 'admin_init', array( &$this, 'create_list' ), 10 );
add_action( 'admin_notices', array( &$this, 'render_notices' ), 1 );
//add_action( 'wp_ajax_um_dimiss_notice', array( &$this, 'dimiss_notice' ) );
}
@@ -42,6 +44,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
$this->need_upgrade();
$this->check_wrong_licenses();
//$this->future_changed();
/**
* UM hook
*
@@ -135,7 +140,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
$admin_notices = $this->get_admin_notices();
$hidden = get_user_meta( get_current_user_id(), 'um_hidden_admin_notices' );
$hidden = get_user_meta( get_current_user_id(), 'um_hidden_admin_notices', true );
$hidden = empty( $hidden ) ? array() : $hidden;
uasort( $admin_notices, array( &$this, 'notice_priority_sort' ) );
@@ -186,9 +191,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
$class = ! empty( $notice_data['class'] ) ? $notice_data['class'] : 'updated';
$dimissible = ! empty( $admin_notices[ $key ]['dimissible'] );
ob_start(); ?>
<div class="<?php echo esc_attr( $class ) ?> um-admin-notice">
<div class="<?php echo esc_attr( $class ) ?> um-admin-notice notice <?php echo $dimissible ? 'is-dismissible' : '' ?>" data-key="<?php echo $key ?>">
<?php echo ! empty( $notice_data['message'] ) ? $notice_data['message'] : '' ?>
</div>
@@ -595,5 +602,41 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
}
}
/**
* Check Future Changes notice
*/
function future_changed() {
ob_start(); ?>
<p>
<?php printf( __( '<strong>%s</strong> future plans! Detailed future list is <a href="%s" target="_blank">here</a>', 'ultimate-member' ), ultimatemember_plugin_name, '#' ); ?>
</p>
<?php $message = ob_get_clean();
$this->add_notice( 'future_changes', array(
'class' => 'updated',
'message' => $message,
//'dimissible' => true,
), 2 );
}
function dimiss_notice() {
if ( empty( $_POST['key'] ) ) {
wp_send_json_error( __( 'Wrong Data', 'ultimate-member' ) );
}
$hidden_notices = get_user_meta( get_current_user_id(), 'um_hidden_admin_notices', true );
$hidden_notices = empty( $hidden_notices ) ? array() : $hidden_notices;
$hidden_notices[] = $_POST['key'];
update_user_meta( get_current_user_id(), 'um_hidden_admin_notices', $hidden_notices );
wp_send_json_success();
}
}
}