| Server IP : 69.39.225.240 / Your IP : 216.73.216.138 Web Server : Apache System : Linux bronze7.serverhost.net 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : reademotions ( 1074) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/reademotions/www/wp-content/plugins/bb-plugin/classes/ |
Upload File : |
<?php
/**
* Class that handles showing admin notices.
*
* @since 2.5
*/
final class FLBuilderAdminNotices {
/**
* @since 2.5
* @var array $notices
*/
static private $notices = array();
static public function init() {
add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_scripts' );
add_action( 'admin_notices', __CLASS__ . '::render_notices' );
add_action( 'wp_ajax_dismiss_fl_notice', array( __CLASS__, 'dismiss_callback' ) );
}
/**
* Register a notice.
*
* @since 2.5
* @param array $notice
* @return void
*/
static public function register_notice( $args = array() ) {
$defaults = array(
'id' => false,
'cap' => 'edit_posts',
'content' => '',
'class' => 'notice-info',
'only' => 'options-general.php?page=fl-builder-settings',
);
$notice = wp_parse_args( $args, $defaults );
if ( $notice['id'] ) {
self::$notices[] = $notice;
}
}
static public function enqueue_scripts() {
$notices = array();
foreach ( self::$notices as $notice ) {
if ( ! current_user_can( $notice['cap'] ) || self::is_dismissed( $notice['id'] ) ) {
continue;
}
unset( $notice['content'] );
$notices[] = $notice;
}
if ( empty( $notices ) ) {
return;
}
wp_enqueue_script(
'fl-builder-admin-notices',
FL_BUILDER_URL . '/js/fl-builder-admin-notices.js',
array( 'jquery' ),
FL_BUILDER_VERSION,
true
);
wp_localize_script( 'fl-builder-admin-notices', 'FLBuilderAdminNoticesConfig', array(
'notices' => $notices,
'notice_nonce' => wp_create_nonce( 'dismiss_fl_notice', 'notice_nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
) );
}
static public function render_notices() {
$notices = array();
foreach ( self::$notices as $notice ) {
if ( ! current_user_can( $notice['cap'] ) || self::is_dismissed( $notice['id'] ) ) {
continue;
}
if ( $notice['only'] && basename( home_url( $_SERVER['REQUEST_URI'] ) ) !== $notice['only'] ) {
continue;
}
printf( '<div class="notice %s is-dismissible fl-notice notice-id-%s"><p>%s</p></div>', $notice['class'], $notice['id'], $notice['content'] );
}
}
static private function is_dismissed( $notice_id ) {
$dismissed = (array) get_user_meta( get_current_user_id(), 'fl_dismissed_wp_notices', true );
return in_array( $notice_id, $dismissed );
}
static public function dismiss_callback() {
if ( ! isset( $_POST['notice_nonce'] ) || ! wp_verify_nonce( $_POST['notice_nonce'], 'dismiss_fl_notice' )
) {
print 'Sorry, your nonce did not verify.';
exit;
} else {
$user_id = get_current_user_id();
$dismissed = (array) get_user_meta( $user_id, 'fl_dismissed_wp_notices', true );
$dismissed[] = $_POST['notice'];
update_user_meta( $user_id, 'fl_dismissed_wp_notices', $dismissed );
exit();
}
}
}
FLBuilderAdminNotices::init();