cdn
1 year ago
data_structure
1 year ago
activation.cls.php
1 year ago
admin-display.cls.php
1 year ago
admin-settings.cls.php
1 year ago
admin.cls.php
1 year ago
api.cls.php
1 year ago
avatar.cls.php
1 year ago
base.cls.php
1 year ago
cdn-setup.cls.php
1 year ago
cdn.cls.php
1 year ago
cloud.cls.php
1 year ago
conf.cls.php
1 year ago
control.cls.php
1 year ago
core.cls.php
1 year ago
crawler-map.cls.php
1 year ago
crawler.cls.php
1 year ago
css.cls.php
1 year ago
data.cls.php
1 year ago
data.upgrade.func.php
1 year ago
db-optm.cls.php
1 year ago
debug2.cls.php
1 year ago
doc.cls.php
1 year ago
error.cls.php
1 year ago
esi.cls.php
1 year ago
file.cls.php
1 year ago
gui.cls.php
1 year ago
health.cls.php
1 year ago
htaccess.cls.php
1 year ago
img-optm.cls.php
1 year ago
import.cls.php
1 year ago
instance.cls.php
1 year ago
lang.cls.php
1 year ago
localization.cls.php
1 year ago
media.cls.php
1 year ago
metabox.cls.php
1 year ago
object-cache.cls.php
1 year ago
object.lib.php
1 year ago
optimize.cls.php
1 year ago
optimizer.cls.php
1 year ago
placeholder.cls.php
1 year ago
preset.cls.php
1 year ago
purge.cls.php
1 year ago
report.cls.php
1 year ago
rest.cls.php
1 year ago
root.cls.php
1 year ago
router.cls.php
1 year ago
str.cls.php
1 year ago
tag.cls.php
1 year ago
task.cls.php
1 year ago
tool.cls.php
1 year ago
ucss.cls.php
1 year ago
utility.cls.php
1 year ago
vary.cls.php
1 year ago
vpi.cls.php
1 year ago
admin.cls.php
190 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The admin-panel specific functionality of the plugin. |
| 4 | * |
| 5 | * |
| 6 | * @since 1.0.0 |
| 7 | * @package LiteSpeed_Cache |
| 8 | * @subpackage LiteSpeed_Cache/admin |
| 9 | * @author LiteSpeed Technologies <info@litespeedtech.com> |
| 10 | */ |
| 11 | namespace LiteSpeed; |
| 12 | |
| 13 | defined('WPINC') || exit(); |
| 14 | |
| 15 | class Admin extends Root |
| 16 | { |
| 17 | const LOG_TAG = '👮'; |
| 18 | |
| 19 | const PAGE_EDIT_HTACCESS = 'litespeed-edit-htaccess'; |
| 20 | |
| 21 | /** |
| 22 | * Initialize the class and set its properties. |
| 23 | * Run in hook `after_setup_theme` when is_admin() |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | public function __construct() |
| 28 | { |
| 29 | // Define LSCWP_MU_PLUGIN if is mu-plugins |
| 30 | if (defined('WPMU_PLUGIN_DIR') && dirname(LSCWP_DIR) == WPMU_PLUGIN_DIR) { |
| 31 | define('LSCWP_MU_PLUGIN', true); |
| 32 | } |
| 33 | |
| 34 | self::debug('No cache due to Admin page'); |
| 35 | defined('DONOTCACHEPAGE') || define('DONOTCACHEPAGE', true); |
| 36 | |
| 37 | // Additional litespeed assets on admin display |
| 38 | // Also register menu |
| 39 | $this->cls('Admin_Display'); |
| 40 | |
| 41 | // initialize admin actions |
| 42 | add_action('admin_init', array($this, 'admin_init')); |
| 43 | // add link to plugin list page |
| 44 | add_filter('plugin_action_links_' . LSCWP_BASENAME, array($this->cls('Admin_Display'), 'add_plugin_links')); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Callback that initializes the admin options for LiteSpeed Cache. |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | * @access public |
| 52 | */ |
| 53 | public function admin_init() |
| 54 | { |
| 55 | // Hook attachment upload |
| 56 | if ($this->conf(Base::O_IMG_OPTM_AUTO)) { |
| 57 | add_filter('wp_update_attachment_metadata', array($this, 'wp_update_attachment_metadata'), 9999, 2); |
| 58 | } |
| 59 | |
| 60 | $this->_proceed_admin_action(); |
| 61 | |
| 62 | // Terminate if user doesn't have the access to settings |
| 63 | if (is_network_admin()) { |
| 64 | $capability = 'manage_network_options'; |
| 65 | } else { |
| 66 | $capability = 'manage_options'; |
| 67 | } |
| 68 | if (!current_user_can($capability)) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Save setting from admin settings page |
| 73 | // NOTE: cli will call `validate_plugin_settings` manually. Cron activation doesn't need to validate |
| 74 | |
| 75 | // Add privacy policy |
| 76 | // @since 2.2.6 |
| 77 | if (function_exists('wp_add_privacy_policy_content')) { |
| 78 | wp_add_privacy_policy_content(Core::NAME, Doc::privacy_policy()); |
| 79 | } |
| 80 | |
| 81 | $this->cls('Media')->after_admin_init(); |
| 82 | |
| 83 | do_action('litspeed_after_admin_init'); |
| 84 | |
| 85 | if ($this->cls('Router')->esi_enabled()) { |
| 86 | add_action('in_widget_form', array($this->cls('Admin_Display'), 'show_widget_edit'), 100, 3); |
| 87 | add_filter('widget_update_callback', __NAMESPACE__ . '\Admin_Settings::validate_widget_save', 10, 4); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Handle attachment update |
| 93 | * @since 4.0 |
| 94 | */ |
| 95 | public function wp_update_attachment_metadata($data, $post_id) |
| 96 | { |
| 97 | $this->cls('Img_Optm')->wp_update_attachment_metadata($data, $post_id); |
| 98 | return $data; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Run litespeed admin actions |
| 103 | * |
| 104 | * @since 1.1.0 |
| 105 | */ |
| 106 | private function _proceed_admin_action() |
| 107 | { |
| 108 | // handle actions |
| 109 | switch (Router::get_action()) { |
| 110 | case Router::ACTION_SAVE_SETTINGS: |
| 111 | $this->cls('Admin_Settings')->save($_POST); |
| 112 | break; |
| 113 | |
| 114 | // Save network settings |
| 115 | case Router::ACTION_SAVE_SETTINGS_NETWORK: |
| 116 | $this->cls('Admin_Settings')->network_save($_POST); |
| 117 | break; |
| 118 | |
| 119 | default: |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Clean up the input string of any extra slashes/spaces. |
| 126 | * |
| 127 | * @since 1.0.4 |
| 128 | * @access public |
| 129 | * @param string $input The input string to clean. |
| 130 | * @return string The cleaned up input. |
| 131 | */ |
| 132 | public static function cleanup_text($input) |
| 133 | { |
| 134 | if (is_array($input)) { |
| 135 | return array_map(__CLASS__ . '::cleanup_text', $input); |
| 136 | } |
| 137 | |
| 138 | return stripslashes(trim($input)); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * After a LSCWP_CTRL action, need to redirect back to the same page |
| 143 | * without the nonce and action in the query string. |
| 144 | * |
| 145 | * If the redirect url cannot be determined, redirects to the homepage. |
| 146 | * |
| 147 | * @since 1.0.12 |
| 148 | * @access public |
| 149 | * @global string $pagenow |
| 150 | */ |
| 151 | public static function redirect($url = false) |
| 152 | { |
| 153 | global $pagenow; |
| 154 | |
| 155 | if (!empty($_GET['_litespeed_ori'])) { |
| 156 | wp_safe_redirect(wp_get_referer() ?: get_home_url()); |
| 157 | exit(); |
| 158 | } |
| 159 | |
| 160 | $qs = ''; |
| 161 | if (!$url) { |
| 162 | if (!empty($_GET)) { |
| 163 | if (isset($_GET[Router::ACTION])) { |
| 164 | unset($_GET[Router::ACTION]); |
| 165 | } |
| 166 | if (isset($_GET[Router::NONCE])) { |
| 167 | unset($_GET[Router::NONCE]); |
| 168 | } |
| 169 | if (isset($_GET[Router::TYPE])) { |
| 170 | unset($_GET[Router::TYPE]); |
| 171 | } |
| 172 | if (isset($_GET['litespeed_i'])) { |
| 173 | unset($_GET['litespeed_i']); |
| 174 | } |
| 175 | if (!empty($_GET)) { |
| 176 | $qs = '?' . http_build_query($_GET); |
| 177 | } |
| 178 | } |
| 179 | if (is_network_admin()) { |
| 180 | $url = network_admin_url($pagenow . $qs); |
| 181 | } else { |
| 182 | $url = admin_url($pagenow . $qs); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | wp_redirect($url); |
| 187 | exit(); |
| 188 | } |
| 189 | } |
| 190 |