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