| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes\Notifications; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Classes\Notifications\Model\Notice; |
| 6 |
|
| 7 |
if (!class_exists('Latest_Updates')) { |
| 8 |
/** |
| 9 |
* Latest Pugin Updates Notice Class |
| 10 |
* |
| 11 |
* Jewel Theme <support@jeweltheme.com> |
| 12 |
*/ |
| 13 |
class Latest_Updates extends Notice |
| 14 |
{ |
| 15 |
|
| 16 |
/** |
| 17 |
* Latest Updates Notice |
| 18 |
* |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
parent::__construct(); |
| 24 |
if(is_admin()){ |
| 25 |
add_action( 'admin_footer', array( $this, 'jltwp_handle_plugin_update_notice_dismiss' ),99999 ); |
| 26 |
add_action( 'wp_ajax_jltwp_plugin_update_info', array( $this, 'jltwp_plugin_update_info' ) ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Handles the AJAX request for the plugin update info notice dismissal. |
| 32 |
* |
| 33 |
* Triggered when the user clicks the Dismiss button in the notice. |
| 34 |
* |
| 35 |
* @since 1.0 |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function jltwp_plugin_update_info() { |
| 40 |
if (!current_user_can('install_plugins')) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
// Verify nonce for security. |
| 45 |
check_ajax_referer( 'dismiss_notice_nonce', 'nonce' ); |
| 46 |
wp_send_json_success( array( 'message' => 'Notice dismissed.', 'data' => update_option('_wpadminify_plugin_update_info_notice', "dismissed" ) ) ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Notice Content |
| 52 |
* |
| 53 |
* @author Jewel Theme <support@jeweltheme.com> |
| 54 |
*/ |
| 55 |
public function notice_content() |
| 56 |
{ |
| 57 |
if("dismissed" !== get_option('_wpadminify_plugin_update_info_notice', true )){ |
| 58 |
$jltwp_adminify_changelog_message = sprintf( |
| 59 |
__('%3$s %4$s %5$s %6$s <br> <strong>Check Changelogs for </strong> <a href="%1$s" target="__blank">%2$s</a>', 'adminify'), |
| 60 |
esc_url_raw('https://wpadminify.com/changelogs'), |
| 61 |
__('More about Updates ', 'adminify'), |
| 62 |
/** Changelog Items |
| 63 |
* Starts from: %3$s |
| 64 |
*/ |
| 65 |
|
| 66 |
'<h3 class="adminify-update-head">' . WP_ADMINIFY . ' <span><small><em>v' . esc_html(WP_ADMINIFY_VER) . '</em></small>' . __(' has some updates..', 'adminify') . '</span></h3><br>', // %3$s |
| 67 |
__('<span class="dashicons dashicons-yes"></span> <span class="adminify-changes-list">Added addons plugin installer step into Adminify setup wizard </span><br>', 'adminify'), |
| 68 |
__('<span class="dashicons dashicons-yes"></span> <span class="adminify-changes-list"> UX Improved for adminify UI </span><br>', 'adminify'), |
| 69 |
__('<span class="dashicons dashicons-yes"></span> <span class="adminify-changes-list"> Security update . </span><br>', 'adminify'), |
| 70 |
); |
| 71 |
|
| 72 |
printf(wp_kses_post($jltwp_adminify_changelog_message)); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Notice Header |
| 78 |
* |
| 79 |
* @author Jewel Theme <support@jeweltheme.com> |
| 80 |
*/ |
| 81 |
public function notice_header() { |
| 82 |
if("dismissed" !== get_option('_wpadminify_plugin_update_info_notice', true )){ ?> |
| 83 |
<div class="hide-notice--ignored notice notice-wp-adminify is-dismissible notice-<?php echo esc_attr( $this->color ); ?> wp-adminify-notice-<?php echo esc_attr( $this->get_id() ); ?> notice-plugin-update-info"> |
| 84 |
<button type="button" class="notice-dismiss wp-adminify-notice-dismiss" data-notice-type="plugin_update_notice"></button> |
| 85 |
<div class="notice-content-box"> |
| 86 |
<?php |
| 87 |
}else{ echo '<div class="hide-notice--ignored customDiv" ><div>';} |
| 88 |
} |
| 89 |
|
| 90 |
public function jltwp_handle_plugin_update_notice_dismiss() { ?> |
| 91 |
|
| 92 |
<script> |
| 93 |
|
| 94 |
function jltwp_adminify_update_plugin_info_notice_action(evt, $this, action_type) { |
| 95 |
if (evt) evt.preventDefault(); |
| 96 |
$this.closest('.notice-plugin-update-info').slideUp(200); |
| 97 |
|
| 98 |
jQuery.post('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', { |
| 99 |
action: 'jltwp_plugin_update_info', |
| 100 |
_wpnonce: '<?php echo esc_js( wp_create_nonce( 'dismiss_notice_nonce' ) ); ?>', |
| 101 |
action_type: action_type, |
| 102 |
plugin_name: $this.data('noticetype') |
| 103 |
}).then(function(response) { |
| 104 |
console.log(response); |
| 105 |
}); |
| 106 |
} |
| 107 |
|
| 108 |
// Notice Dismiss |
| 109 |
jQuery('body').on('click', '.notice-wp-adminify.notice-plugin-update-info .wp-adminify-notice-dismiss', function(evt) { |
| 110 |
jltwp_adminify_update_plugin_info_notice_action(evt, jQuery(this), 'dismiss'); |
| 111 |
}); |
| 112 |
</script> |
| 113 |
|
| 114 |
<?php |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Intervals |
| 119 |
* |
| 120 |
* @author Jewel Theme <support@jeweltheme.com> |
| 121 |
*/ |
| 122 |
public function intervals() |
| 123 |
{ |
| 124 |
return array(0); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|