Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/litespee.../src
File: admin-display.cls.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* The admin-panel specific functionality of the plugin.
[3] Fix | Delete
*
[4] Fix | Delete
*
[5] Fix | Delete
* @since 1.0.0
[6] Fix | Delete
* @package LiteSpeed
[7] Fix | Delete
* @subpackage LiteSpeed/admin
[8] Fix | Delete
* @author LiteSpeed Technologies <info@litespeedtech.com>
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace LiteSpeed;
[12] Fix | Delete
[13] Fix | Delete
defined('WPINC') || exit();
[14] Fix | Delete
[15] Fix | Delete
class Admin_Display extends Base
[16] Fix | Delete
{
[17] Fix | Delete
const LOG_TAG = '👮‍♀️';
[18] Fix | Delete
[19] Fix | Delete
const NOTICE_BLUE = 'notice notice-info';
[20] Fix | Delete
const NOTICE_GREEN = 'notice notice-success';
[21] Fix | Delete
const NOTICE_RED = 'notice notice-error';
[22] Fix | Delete
const NOTICE_YELLOW = 'notice notice-warning';
[23] Fix | Delete
const DB_MSG = 'messages';
[24] Fix | Delete
const DB_MSG_PIN = 'msg_pin';
[25] Fix | Delete
[26] Fix | Delete
const PURGEBY_CAT = '0';
[27] Fix | Delete
const PURGEBY_PID = '1';
[28] Fix | Delete
const PURGEBY_TAG = '2';
[29] Fix | Delete
const PURGEBY_URL = '3';
[30] Fix | Delete
[31] Fix | Delete
const PURGEBYOPT_SELECT = 'purgeby';
[32] Fix | Delete
const PURGEBYOPT_LIST = 'purgebylist';
[33] Fix | Delete
[34] Fix | Delete
const DB_DISMISS_MSG = 'dismiss';
[35] Fix | Delete
const RULECONFLICT_ON = 'ExpiresDefault_1';
[36] Fix | Delete
const RULECONFLICT_DISMISSED = 'ExpiresDefault_0';
[37] Fix | Delete
[38] Fix | Delete
protected $messages = array();
[39] Fix | Delete
protected $default_settings = array();
[40] Fix | Delete
protected $_is_network_admin = false;
[41] Fix | Delete
protected $_is_multisite = false;
[42] Fix | Delete
[43] Fix | Delete
private $_btn_i = 0;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Initialize the class and set its properties.
[47] Fix | Delete
*
[48] Fix | Delete
* @since 1.0.7
[49] Fix | Delete
*/
[50] Fix | Delete
public function __construct()
[51] Fix | Delete
{
[52] Fix | Delete
// main css
[53] Fix | Delete
add_action('admin_enqueue_scripts', array($this, 'enqueue_style'));
[54] Fix | Delete
// Main js
[55] Fix | Delete
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
[56] Fix | Delete
[57] Fix | Delete
$this->_is_network_admin = is_network_admin();
[58] Fix | Delete
$this->_is_multisite = is_multisite();
[59] Fix | Delete
[60] Fix | Delete
// Quick access menu
[61] Fix | Delete
if (is_multisite() && $this->_is_network_admin) {
[62] Fix | Delete
$manage = 'manage_network_options';
[63] Fix | Delete
} else {
[64] Fix | Delete
$manage = 'manage_options';
[65] Fix | Delete
}
[66] Fix | Delete
if (current_user_can($manage)) {
[67] Fix | Delete
if (!defined('LITESPEED_DISABLE_ALL')) {
[68] Fix | Delete
add_action('wp_before_admin_bar_render', array(GUI::cls(), 'backend_shortcut'));
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// `admin_notices` is after `admin_enqueue_scripts`
[72] Fix | Delete
// @see wp-admin/admin-header.php
[73] Fix | Delete
add_action($this->_is_network_admin ? 'network_admin_notices' : 'admin_notices', array($this, 'display_messages'));
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* In case this is called outside the admin page
[78] Fix | Delete
* @see https://codex.wordpress.org/Function_Reference/is_plugin_active_for_network
[79] Fix | Delete
* @since 2.0
[80] Fix | Delete
*/
[81] Fix | Delete
if (!function_exists('is_plugin_active_for_network')) {
[82] Fix | Delete
require_once ABSPATH . '/wp-admin/includes/plugin.php';
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// add menus ( Also check for mu-plugins)
[86] Fix | Delete
if ($this->_is_network_admin && (is_plugin_active_for_network(LSCWP_BASENAME) || defined('LSCWP_MU_PLUGIN'))) {
[87] Fix | Delete
add_action('network_admin_menu', array($this, 'register_admin_menu'));
[88] Fix | Delete
} else {
[89] Fix | Delete
add_action('admin_menu', array($this, 'register_admin_menu'));
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
$this->cls('Metabox')->register_settings();
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Show the title of one line
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.0
[99] Fix | Delete
* @access public
[100] Fix | Delete
*/
[101] Fix | Delete
public function title($id)
[102] Fix | Delete
{
[103] Fix | Delete
echo Lang::title($id);
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Register the admin menu display.
[108] Fix | Delete
*
[109] Fix | Delete
* @since 1.0.0
[110] Fix | Delete
* @access public
[111] Fix | Delete
*/
[112] Fix | Delete
public function register_admin_menu()
[113] Fix | Delete
{
[114] Fix | Delete
$capability = $this->_is_network_admin ? 'manage_network_options' : 'manage_options';
[115] Fix | Delete
if (current_user_can($capability)) {
[116] Fix | Delete
// root menu
[117] Fix | Delete
add_menu_page('LiteSpeed Cache', 'LiteSpeed Cache', 'manage_options', 'litespeed');
[118] Fix | Delete
[119] Fix | Delete
// sub menus
[120] Fix | Delete
$this->_add_submenu(__('Dashboard', 'litespeed-cache'), 'litespeed', 'show_menu_dash');
[121] Fix | Delete
[122] Fix | Delete
!$this->_is_network_admin && $this->_add_submenu(__('Presets', 'litespeed-cache'), 'litespeed-presets', 'show_menu_presets');
[123] Fix | Delete
[124] Fix | Delete
$this->_add_submenu(__('General', 'litespeed-cache'), 'litespeed-general', 'show_menu_general');
[125] Fix | Delete
[126] Fix | Delete
$this->_add_submenu(__('Cache', 'litespeed-cache'), 'litespeed-cache', 'show_menu_cache');
[127] Fix | Delete
[128] Fix | Delete
!$this->_is_network_admin && $this->_add_submenu(__('CDN', 'litespeed-cache'), 'litespeed-cdn', 'show_menu_cdn');
[129] Fix | Delete
[130] Fix | Delete
$this->_add_submenu(__('Image Optimization', 'litespeed-cache'), 'litespeed-img_optm', 'show_img_optm');
[131] Fix | Delete
[132] Fix | Delete
!$this->_is_network_admin && $this->_add_submenu(__('Page Optimization', 'litespeed-cache'), 'litespeed-page_optm', 'show_page_optm');
[133] Fix | Delete
[134] Fix | Delete
$this->_add_submenu(__('Database', 'litespeed-cache'), 'litespeed-db_optm', 'show_db_optm');
[135] Fix | Delete
[136] Fix | Delete
!$this->_is_network_admin && $this->_add_submenu(__('Crawler', 'litespeed-cache'), 'litespeed-crawler', 'show_crawler');
[137] Fix | Delete
[138] Fix | Delete
$this->_add_submenu(__('Toolbox', 'litespeed-cache'), 'litespeed-toolbox', 'show_toolbox');
[139] Fix | Delete
[140] Fix | Delete
// sub menus under options
[141] Fix | Delete
add_options_page('LiteSpeed Cache', 'LiteSpeed Cache', $capability, 'litespeed-cache-options', array($this, 'show_menu_cache'));
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Helper function to set up a submenu page.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 1.0.4
[149] Fix | Delete
* @access private
[150] Fix | Delete
* @param string $menu_title The title that appears on the menu.
[151] Fix | Delete
* @param string $menu_slug The slug of the page.
[152] Fix | Delete
* @param string $callback The callback to call if selected.
[153] Fix | Delete
*/
[154] Fix | Delete
private function _add_submenu($menu_title, $menu_slug, $callback)
[155] Fix | Delete
{
[156] Fix | Delete
add_submenu_page('litespeed', $menu_title, $menu_title, 'manage_options', $menu_slug, array($this, $callback));
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Register the stylesheets for the admin area.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 1.0.14
[163] Fix | Delete
* @access public
[164] Fix | Delete
*/
[165] Fix | Delete
public function enqueue_style()
[166] Fix | Delete
{
[167] Fix | Delete
wp_enqueue_style(Core::PLUGIN_NAME, LSWCP_PLUGIN_URL . 'assets/css/litespeed.css', array(), Core::VER, 'all');
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Register the JavaScript for the admin area.
[172] Fix | Delete
*
[173] Fix | Delete
* @since 1.0.0
[174] Fix | Delete
* @access public
[175] Fix | Delete
*/
[176] Fix | Delete
public function enqueue_scripts()
[177] Fix | Delete
{
[178] Fix | Delete
wp_register_script(Core::PLUGIN_NAME, LSWCP_PLUGIN_URL . 'assets/js/litespeed-cache-admin.js', array(), Core::VER, false);
[179] Fix | Delete
[180] Fix | Delete
$localize_data = array();
[181] Fix | Delete
if (GUI::has_whm_msg()) {
[182] Fix | Delete
$ajax_url_dismiss_whm = Utility::build_url(Core::ACTION_DISMISS, GUI::TYPE_DISMISS_WHM, true);
[183] Fix | Delete
$localize_data['ajax_url_dismiss_whm'] = $ajax_url_dismiss_whm;
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
if (GUI::has_msg_ruleconflict()) {
[187] Fix | Delete
$ajax_url = Utility::build_url(Core::ACTION_DISMISS, GUI::TYPE_DISMISS_EXPIRESDEFAULT, true);
[188] Fix | Delete
$localize_data['ajax_url_dismiss_ruleconflict'] = $ajax_url;
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
$promo_tag = GUI::cls()->show_promo(true);
[192] Fix | Delete
if ($promo_tag) {
[193] Fix | Delete
$ajax_url_promo = Utility::build_url(Core::ACTION_DISMISS, GUI::TYPE_DISMISS_PROMO, true, null, array('promo_tag' => $promo_tag));
[194] Fix | Delete
$localize_data['ajax_url_promo'] = $ajax_url_promo;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
// Injection to LiteSpeed pages
[198] Fix | Delete
global $pagenow;
[199] Fix | Delete
if ($pagenow == 'admin.php' && !empty($_GET['page']) && (strpos($_GET['page'], 'litespeed-') === 0 || $_GET['page'] == 'litespeed')) {
[200] Fix | Delete
// Admin footer
[201] Fix | Delete
add_filter('admin_footer_text', array($this, 'admin_footer_text'), 1);
[202] Fix | Delete
[203] Fix | Delete
if ($_GET['page'] == 'litespeed-crawler' || $_GET['page'] == 'litespeed-cdn') {
[204] Fix | Delete
// Babel JS type correction
[205] Fix | Delete
add_filter('script_loader_tag', array($this, 'babel_type'), 10, 3);
[206] Fix | Delete
[207] Fix | Delete
wp_enqueue_script(Core::PLUGIN_NAME . '-lib-react', LSWCP_PLUGIN_URL . 'assets/js/react.min.js', array(), Core::VER, false);
[208] Fix | Delete
wp_enqueue_script(Core::PLUGIN_NAME . '-lib-babel', LSWCP_PLUGIN_URL . 'assets/js/babel.min.js', array(), Core::VER, false);
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
// Crawler Cookie Simulation
[212] Fix | Delete
if ($_GET['page'] == 'litespeed-crawler') {
[213] Fix | Delete
wp_enqueue_script(Core::PLUGIN_NAME . '-crawler', LSWCP_PLUGIN_URL . 'assets/js/component.crawler.js', array(), Core::VER, false);
[214] Fix | Delete
$localize_data['lang'] = array();
[215] Fix | Delete
$localize_data['lang']['cookie_name'] = __('Cookie Name', 'litespeed-cache');
[216] Fix | Delete
$localize_data['lang']['cookie_value'] = __('Cookie Values', 'litespeed-cache');
[217] Fix | Delete
$localize_data['lang']['one_per_line'] = Doc::one_per_line(true);
[218] Fix | Delete
$localize_data['lang']['remove_cookie_simulation'] = __('Remove cookie simulation', 'litespeed-cache');
[219] Fix | Delete
$localize_data['lang']['add_cookie_simulation_row'] = __('Add new cookie to simulate', 'litespeed-cache');
[220] Fix | Delete
empty($localize_data['ids']) && ($localize_data['ids'] = array());
[221] Fix | Delete
$localize_data['ids']['crawler_cookies'] = self::O_CRAWLER_COOKIES;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
// CDN mapping
[225] Fix | Delete
if ($_GET['page'] == 'litespeed-cdn') {
[226] Fix | Delete
$home_url = home_url('/');
[227] Fix | Delete
$parsed = parse_url($home_url);
[228] Fix | Delete
$home_url = str_replace($parsed['scheme'] . ':', '', $home_url);
[229] Fix | Delete
$cdn_url = 'https://cdn.' . substr($home_url, 2);
[230] Fix | Delete
[231] Fix | Delete
wp_enqueue_script(Core::PLUGIN_NAME . '-cdn', LSWCP_PLUGIN_URL . 'assets/js/component.cdn.js', array(), Core::VER, false);
[232] Fix | Delete
$localize_data['lang'] = array();
[233] Fix | Delete
$localize_data['lang']['cdn_mapping_url'] = Lang::title(self::CDN_MAPPING_URL);
[234] Fix | Delete
$localize_data['lang']['cdn_mapping_inc_img'] = Lang::title(self::CDN_MAPPING_INC_IMG);
[235] Fix | Delete
$localize_data['lang']['cdn_mapping_inc_css'] = Lang::title(self::CDN_MAPPING_INC_CSS);
[236] Fix | Delete
$localize_data['lang']['cdn_mapping_inc_js'] = Lang::title(self::CDN_MAPPING_INC_JS);
[237] Fix | Delete
$localize_data['lang']['cdn_mapping_filetype'] = Lang::title(self::CDN_MAPPING_FILETYPE);
[238] Fix | Delete
$localize_data['lang']['cdn_mapping_url_desc'] = sprintf(__('CDN URL to be used. For example, %s', 'litespeed-cache'), '<code>' . $cdn_url . '</code>');
[239] Fix | Delete
$localize_data['lang']['one_per_line'] = Doc::one_per_line(true);
[240] Fix | Delete
$localize_data['lang']['cdn_mapping_remove'] = __('Remove CDN URL', 'litespeed-cache');
[241] Fix | Delete
$localize_data['lang']['add_cdn_mapping_row'] = __('Add new CDN URL', 'litespeed-cache');
[242] Fix | Delete
$localize_data['lang']['on'] = __('ON', 'litespeed-cache');
[243] Fix | Delete
$localize_data['lang']['off'] = __('OFF', 'litespeed-cache');
[244] Fix | Delete
empty($localize_data['ids']) && ($localize_data['ids'] = array());
[245] Fix | Delete
$localize_data['ids']['cdn_mapping'] = self::O_CDN_MAPPING;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
// If on Server IP setting page, append getIP link
[249] Fix | Delete
if ($_GET['page'] == 'litespeed-general') {
[250] Fix | Delete
$localize_data['ajax_url_getIP'] = function_exists('get_rest_url') ? get_rest_url(null, 'litespeed/v1/tool/check_ip') : '/';
[251] Fix | Delete
$localize_data['nonce'] = wp_create_nonce('wp_rest');
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
// Activate or deactivate a specific crawler
[255] Fix | Delete
if ($_GET['page'] == 'litespeed-crawler') {
[256] Fix | Delete
$localize_data['ajax_url_crawler_switch'] = function_exists('get_rest_url') ? get_rest_url(null, 'litespeed/v1/toggle_crawler_state') : '/';
[257] Fix | Delete
$localize_data['nonce'] = wp_create_nonce('wp_rest');
[258] Fix | Delete
}
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
if ($localize_data) {
[262] Fix | Delete
wp_localize_script(Core::PLUGIN_NAME, 'litespeed_data', $localize_data);
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
wp_enqueue_script(Core::PLUGIN_NAME);
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* Babel type for crawler
[270] Fix | Delete
*
[271] Fix | Delete
* @since 3.6
[272] Fix | Delete
*/
[273] Fix | Delete
public function babel_type($tag, $handle, $src)
[274] Fix | Delete
{
[275] Fix | Delete
if ($handle != Core::PLUGIN_NAME . '-crawler' && $handle != Core::PLUGIN_NAME . '-cdn') {
[276] Fix | Delete
return $tag;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
return '<script src="' . $src . '" type="text/babel"></script>';
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Callback that adds LiteSpeed Cache's action links.
[284] Fix | Delete
*
[285] Fix | Delete
* @since 1.0.0
[286] Fix | Delete
* @access public
[287] Fix | Delete
* @param array $links Previously added links from other plugins.
[288] Fix | Delete
* @return array Links array with the litespeed cache one appended.
[289] Fix | Delete
*/
[290] Fix | Delete
public function add_plugin_links($links)
[291] Fix | Delete
{
[292] Fix | Delete
// $links[] = '<a href="' . admin_url('options-general.php?page=litespeed-cache') . '">' . __('Settings', 'litespeed-cache') . '</a>';
[293] Fix | Delete
$links[] = '<a href="' . admin_url('admin.php?page=litespeed-cache') . '">' . __('Settings', 'litespeed-cache') . '</a>';
[294] Fix | Delete
[295] Fix | Delete
return $links;
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
/**
[299] Fix | Delete
* Change the admin footer text on LiteSpeed Cache admin pages.
[300] Fix | Delete
*
[301] Fix | Delete
* @since 1.0.13
[302] Fix | Delete
* @param string $footer_text
[303] Fix | Delete
* @return string
[304] Fix | Delete
*/
[305] Fix | Delete
public function admin_footer_text($footer_text)
[306] Fix | Delete
{
[307] Fix | Delete
require_once LSCWP_DIR . 'tpl/inc/admin_footer.php';
[308] Fix | Delete
[309] Fix | Delete
return $footer_text;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Builds the html for a single notice.
[314] Fix | Delete
*
[315] Fix | Delete
* @since 1.0.7
[316] Fix | Delete
* @access public
[317] Fix | Delete
* @param string $color The color to use for the notice.
[318] Fix | Delete
* @param string $str The notice message.
[319] Fix | Delete
* @return string The built notice html.
[320] Fix | Delete
*/
[321] Fix | Delete
public static function build_notice($color, $str, $irremovable = false)
[322] Fix | Delete
{
[323] Fix | Delete
$cls = $color;
[324] Fix | Delete
if ($irremovable) {
[325] Fix | Delete
$cls .= ' litespeed-irremovable';
[326] Fix | Delete
} else {
[327] Fix | Delete
$cls .= ' is-dismissible';
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
// possible translation
[331] Fix | Delete
$str = Lang::maybe_translate($str);
[332] Fix | Delete
[333] Fix | Delete
return '<div class="litespeed_icon ' . $cls . '"><p>' . wp_kses_post($str) . '</p></div>';
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Display info notice
[338] Fix | Delete
*
[339] Fix | Delete
* @since 1.6.5
[340] Fix | Delete
* @access public
[341] Fix | Delete
*/
[342] Fix | Delete
public static function info($msg, $echo = false, $irremovable = false)
[343] Fix | Delete
{
[344] Fix | Delete
self::add_notice(self::NOTICE_BLUE, $msg, $echo, $irremovable);
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* Display note notice
[349] Fix | Delete
*
[350] Fix | Delete
* @since 1.6.5
[351] Fix | Delete
* @access public
[352] Fix | Delete
*/
[353] Fix | Delete
public static function note($msg, $echo = false, $irremovable = false)
[354] Fix | Delete
{
[355] Fix | Delete
self::add_notice(self::NOTICE_YELLOW, $msg, $echo, $irremovable);
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
/**
[359] Fix | Delete
* Display success notice
[360] Fix | Delete
*
[361] Fix | Delete
* @since 1.6
[362] Fix | Delete
* @access public
[363] Fix | Delete
*/
[364] Fix | Delete
public static function success($msg, $echo = false, $irremovable = false)
[365] Fix | Delete
{
[366] Fix | Delete
self::add_notice(self::NOTICE_GREEN, $msg, $echo, $irremovable);
[367] Fix | Delete
}
[368] Fix | Delete
/** @deprecated 4.7 */
[369] Fix | Delete
public static function succeed($msg, $echo = false, $irremovable = false)
[370] Fix | Delete
{
[371] Fix | Delete
self::success($msg, $echo, $irremovable);
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Display error notice
[376] Fix | Delete
*
[377] Fix | Delete
* @since 1.6
[378] Fix | Delete
* @access public
[379] Fix | Delete
*/
[380] Fix | Delete
public static function error($msg, $echo = false, $irremovable = false)
[381] Fix | Delete
{
[382] Fix | Delete
self::add_notice(self::NOTICE_RED, $msg, $echo, $irremovable);
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Add irremovable msg
[387] Fix | Delete
* @since 4.7
[388] Fix | Delete
*/
[389] Fix | Delete
public static function add_unique_notice($color_mode, $msgs, $irremovable = false)
[390] Fix | Delete
{
[391] Fix | Delete
if (!is_array($msgs)) {
[392] Fix | Delete
$msgs = array($msgs);
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
$color_map = array(
[396] Fix | Delete
'info' => self::NOTICE_BLUE,
[397] Fix | Delete
'note' => self::NOTICE_YELLOW,
[398] Fix | Delete
'success' => self::NOTICE_GREEN,
[399] Fix | Delete
'error' => self::NOTICE_RED,
[400] Fix | Delete
);
[401] Fix | Delete
if (empty($color_map[$color_mode])) {
[402] Fix | Delete
self::debug('Wrong admin display color mode!');
[403] Fix | Delete
return;
[404] Fix | Delete
}
[405] Fix | Delete
$color = $color_map[$color_mode];
[406] Fix | Delete
[407] Fix | Delete
// Go through to make sure unique
[408] Fix | Delete
$filtered_msgs = array();
[409] Fix | Delete
foreach ($msgs as $k => $str) {
[410] Fix | Delete
if (is_numeric($k)) {
[411] Fix | Delete
$k = md5($str);
[412] Fix | Delete
} // Use key to make it overwritable to previous same msg
[413] Fix | Delete
$filtered_msgs[$k] = $str;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
self::add_notice($color, $filtered_msgs, false, $irremovable);
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
/**
[420] Fix | Delete
* Adds a notice to display on the admin page
[421] Fix | Delete
*
[422] Fix | Delete
* @since 1.0.7
[423] Fix | Delete
* @access public
[424] Fix | Delete
*/
[425] Fix | Delete
public static function add_notice($color, $msg, $echo = false, $irremovable = false)
[426] Fix | Delete
{
[427] Fix | Delete
// self::debug("add_notice msg", $msg);
[428] Fix | Delete
// Bypass adding for CLI or cron
[429] Fix | Delete
if (defined('LITESPEED_CLI') || defined('DOING_CRON')) {
[430] Fix | Delete
// WP CLI will show the info directly
[431] Fix | Delete
if (defined('WP_CLI') && WP_CLI) {
[432] Fix | Delete
if (!is_array($msg)) {
[433] Fix | Delete
$msg = array($msg);
[434] Fix | Delete
}
[435] Fix | Delete
foreach ($msg as $v) {
[436] Fix | Delete
$v = strip_tags($v);
[437] Fix | Delete
if ($color == self::NOTICE_RED) {
[438] Fix | Delete
\WP_CLI::error($v, false);
[439] Fix | Delete
} else {
[440] Fix | Delete
\WP_CLI::success($v);
[441] Fix | Delete
}
[442] Fix | Delete
}
[443] Fix | Delete
}
[444] Fix | Delete
return;
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
if ($echo) {
[448] Fix | Delete
echo self::build_notice($color, $msg);
[449] Fix | Delete
return;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$msg_name = $irremovable ? self::DB_MSG_PIN : self::DB_MSG;
[453] Fix | Delete
[454] Fix | Delete
$messages = self::get_option($msg_name, array());
[455] Fix | Delete
if (!is_array($messages)) {
[456] Fix | Delete
$messages = array();
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
if (is_array($msg)) {
[460] Fix | Delete
foreach ($msg as $k => $str) {
[461] Fix | Delete
$messages[$k] = self::build_notice($color, $str, $irremovable);
[462] Fix | Delete
}
[463] Fix | Delete
} else {
[464] Fix | Delete
$messages[] = self::build_notice($color, $msg, $irremovable);
[465] Fix | Delete
}
[466] Fix | Delete
$messages = array_unique($messages);
[467] Fix | Delete
self::update_option($msg_name, $messages);
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
/**
[471] Fix | Delete
* Display notices and errors in dashboard
[472] Fix | Delete
*
[473] Fix | Delete
* @since 1.1.0
[474] Fix | Delete
* @access public
[475] Fix | Delete
*/
[476] Fix | Delete
public function display_messages()
[477] Fix | Delete
{
[478] Fix | Delete
if (!defined('LITESPEED_CONF_LOADED')) {
[479] Fix | Delete
$this->_in_upgrading();
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
if (GUI::has_whm_msg()) {
[483] Fix | Delete
$this->show_display_installed();
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
Data::cls()->check_upgrading_msg();
[487] Fix | Delete
[488] Fix | Delete
// If is in dev version, always check latest update
[489] Fix | Delete
Cloud::cls()->check_dev_version();
[490] Fix | Delete
[491] Fix | Delete
// One time msg
[492] Fix | Delete
$messages = self::get_option(self::DB_MSG, array());
[493] Fix | Delete
$added_thickbox = false;
[494] Fix | Delete
if (is_array($messages)) {
[495] Fix | Delete
foreach ($messages as $msg) {
[496] Fix | Delete
// Added for popup links
[497] Fix | Delete
if (strpos($msg, 'TB_iframe') && !$added_thickbox) {
[498] Fix | Delete
add_thickbox();
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function