/**
  * Output the message
  *
  * @since 0.1.0
  *
  * @param string $message The text of the message.
  * @param bool $error Optional. Whether to show as error or update. Default is error.
  * @param string $cap_check Optional. Minimum user capability to show nag to. Default is "activate_plugins"
  * @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated.
  *
  * @return string|void Admin notice if is_admin() and not dismissed.
  */
 public static function notice($message, $error = true, $cap_check = 'activate_plugins', $ignore_key = false)
 {
     if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
         if (current_user_can($cap_check)) {
             $user_id = get_current_user_id();
             if (!is_string($ignore_key)) {
                 // cal_wd_ig_3911b2583433f696e5813a503bbb2e65
                 $ignore_key = 'cal_wd_ig_' . substr(md5($ignore_key), 0, 40);
             }
             self::$ignore_key = sanitize_key($ignore_key);
             $dissmised = get_user_meta($user_id, self::$ignore_key, true);
             if (!$dissmised) {
                 if ($error) {
                     $class = 'error';
                 } else {
                     $class = 'updated';
                 }
                 self::$nonce_field = wp_nonce_field(self::$nonce_action);
                 $out[] = sprintf('<div id="%1s" data-key="%2s" class="%3s notice is-dismissible"><p>', self::$ignore_key, self::$ignore_key, $class);
                 $out[] = $message;
                 $out[] = self::$nonce_field;
                 $out[] = '</p></div>';
                 add_action('admin_enqueue_scripts', array(__CLASS__, 'js_css'));
                 add_action('wp_ajax_caldera_warnings_dismissible_notice', array(__CLASS__, 'ajax_cb'));
                 return implode('', $out);
             }
         }
     }
 }
Example #2
0
function epoch_bootstrap()
{
    $message_class_file = EPOCH_PATH . 'vendor/calderawp/dismissible-notice/src/Caldera_Warnings_Dismissible_Notice.php';
    if (!version_compare(PHP_VERSION, '5.3.0', '>=')) {
        if (is_admin()) {
            //BIG nope nope nope!
            include_once $message_class_file;
            $message = __(sprintf('Epoch requires PHP version %1s or later. We strongly recommend PHP 5.4 or later for security and performance reasons. Current version is %2s.', '5.3.0', PHP_VERSION), 'epoch');
            echo Caldera_Warnings_Dismissible_Notice::notice($message, true, 'activate_plugins');
        }
    } else {
        //bootstrap plugin
        require_once EPOCH_PATH . 'bootstrap.php';
    }
}
 /**
  * Output the message
  *
  * @since 0.1.0
  *
  * @param string $message The text of the message.
  * @param bool $error Optional. Whether to show as error or update. Default is error.
  * @param string $cap_check Optional. Minimum user capability to show nag to. Default is "activate_plugins"
  * @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated.
  *
  * @return string|void Admin notice if is_admin() and not dismissed.
  */
 public static function notice($message, $error = true, $cap_check = 'activate_plugins', $ignore_key = false)
 {
     if (!current_user_can($cap_check)) {
         return;
     }
     $user_id = get_current_user_id();
     if (!is_string($ignore_key)) {
         // cal_wd_ig_3911b2583433f696e5813a503bbb2e65
         $ignore_key = 'cal_wd_ig_' . substr(md5($ignore_key), 0, 40);
     }
     self::$ignore_key = sanitize_key($ignore_key);
     $dissmised = time() - get_user_meta($user_id, self::$ignore_key, time()) < 60 * 60 * 24 * 30;
     // Nag every 30 days
     if ($dissmised) {
         return;
     }
     if ($error) {
         $class = 'error';
     } else {
         $class = 'update-nag';
     }
     self::$nonce_field = wp_nonce_field(self::$nonce_action);
     $out[] = sprintf('<div id="%1s" data-key="%2s" class="%3s notice is-dismissible">', self::$ignore_key, self::$ignore_key, $class);
     $out[] = $message;
     $out[] = self::$nonce_field;
     $out[] = '</div>';
     return implode('', $out);
 }
 /**
  * Create a dismissible notice.
  *
  * @since 0.2.0
  *
  * @param string $message The text of the message.
  * @param bool $error Optional. Whether to show as error or update. Default is error.
  * @param string $cap_check Optional. Minimum user capability to show nag to. Default is "activate_plugins"
  * @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated.
  *
  * @return string|void Admin notice if is_admin() and not dismissed.
  */
 function caldera_warnings_dismissible_notice($message, $error = true, $cap_check = 'activate_plugins', $ignore_key = false)
 {
     include_once dirname(__FILE__) . '/Caldera_Warnings_Dismissible_Notice.php';
     return Caldera_Warnings_Dismissible_Notice::notice($message, $error, $cap_check, $ignore_key);
 }
Example #5
0
 /**
  * Create a dismissible notice.
  *
  * @since 0.2.0
  *
  * @param string $message The text of the message.
  * @param bool $error Optional. Whether to show as error or update. Default is error.
  * @param string $cap_check Optional. Minimum user capability to show nag to. Default is "activate_plugins"
  * @param string|bool $ignore_key Optional. The user meta key to use for storing if this message has been dismissed by current user or not. If false, it will be generated.
  *
  * @return string|void Admin notice if is_admin() and not dismissed.
  */
 function caldera_warnings_dismissible_notice($message, $error = true, $cap_check = 'activate_plugins', $ignore_key = false)
 {
     return Caldera_Warnings_Dismissible_Notice::notice($message, $error, $cap_check, $ignore_key);
 }