| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 |
|
| 4 |
class easy_basic_authentication_notice_class { |
| 5 |
public function __construct() { |
| 6 |
add_action('admin_notices', array($this, 'display_notice')); |
| 7 |
add_action('wp_ajax_easy_basic_authentication_dismiss_notice', array($this, 'dismiss_notice')); |
| 8 |
} |
| 9 |
|
| 10 |
public function display_notice() { |
| 11 |
$current_user = wp_get_current_user(); |
| 12 |
$user_language = esc_html(get_user_meta($current_user->ID, 'locale', true)); |
| 13 |
|
| 14 |
$notice_dismissed = get_user_meta($current_user->ID, '_easy_basic_authentication_notice_dismissed', true); |
| 15 |
|
| 16 |
if ($notice_dismissed) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
?> |
| 21 |
<div class="notice notice-info is-dismissible easy-basic-authentication-notice"> |
| 22 |
<p> |
| 23 |
<?php |
| 24 |
// Translators: 1: Link to profile, 2: User language, 3: Link to translation instructions |
| 25 |
printf( |
| 26 |
wp_kses( |
| 27 |
/* translators: 1: Link to profile, 2: User language, 3: Link to translation instructions */ |
| 28 |
__('Hi, I\'m <a href="%1$s">Matteo</a>, the developer of <b>Easy Basic Authentication</b>. If you are enjoying and finding this plugin useful, please consider helping us translate it into %2$s. Check if translations are available for your language and start contributing. <a href="%3$s">Click here to find out how you can help</a>.', 'easy-basic-authentication'), |
| 29 |
array( |
| 30 |
'a' => array( |
| 31 |
'href' => array(), |
| 32 |
), |
| 33 |
'b' => array(), |
| 34 |
) |
| 35 |
), |
| 36 |
esc_url('https://profiles.wordpress.org/matteoenna/'), |
| 37 |
esc_html($user_language ? $user_language : __('your language', 'easy-basic-authentication')), |
| 38 |
esc_url('https://make.wordpress.org/polyglots/handbook/translating/') |
| 39 |
); |
| 40 |
?> |
| 41 |
</p> |
| 42 |
</div> |
| 43 |
<script type="text/javascript"> |
| 44 |
jQuery(document).ready(function($) { |
| 45 |
$('.easy-basic-authentication-notice').on('click', '.notice-dismiss', function() { |
| 46 |
$.ajax({ |
| 47 |
url: ajaxurl, |
| 48 |
type: 'POST', |
| 49 |
data: { |
| 50 |
action: 'easy_basic_authentication_dismiss_notice' |
| 51 |
} |
| 52 |
}); |
| 53 |
}); |
| 54 |
}); |
| 55 |
</script> |
| 56 |
<?php |
| 57 |
} |
| 58 |
|
| 59 |
public function dismiss_notice() { |
| 60 |
$current_user = wp_get_current_user(); |
| 61 |
update_user_meta($current_user->ID, '_easy_basic_authentication_notice_dismissed', true); |
| 62 |
wp_die(); |
| 63 |
} |
| 64 |
} |