PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 6.5.4
LiteSpeed Cache v6.5.4
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / src / metabox.cls.php
litespeed-cache / src Last commit date
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
metabox.cls.php
181 lines
1 <?php
2 /**
3 * The class to operate post editor metabox settings
4 *
5 * @since 4.7
6 * @package Core
7 * @subpackage Core/inc
8 * @author LiteSpeed Technologies <info@litespeedtech.com>
9 */
10 namespace LiteSpeed;
11
12 defined('WPINC') || exit();
13
14 class Metabox extends Root
15 {
16 const LOG_TAG = '📦';
17
18 const POST_NONCE_ACTION = 'post_nonce_action';
19
20 private $_postmeta_settings;
21
22 /**
23 * Get the setting list
24 * @since 4.7
25 */
26 public function __construct()
27 {
28 // Append meta box
29 $this->_postmeta_settings = array(
30 'litespeed_no_cache' => __('Disable Cache', 'litespeed-cache'),
31 'litespeed_no_image_lazy' => __('Disable Image Lazyload', 'litespeed-cache'),
32 'litespeed_no_vpi' => __('Disable VPI', 'litespeed-cache'),
33 'litespeed_vpi_list' => __('Viewport Images', 'litespeed-cache'),
34 'litespeed_vpi_list_mobile' => __('Viewport Images', 'litespeed-cache') . ' - ' . __('Mobile', 'litespeed-cache'),
35 );
36 }
37
38 /**
39 * Register post edit settings
40 * @since 4.7
41 */
42 public function register_settings()
43 {
44 add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
45 add_action('save_post', array($this, 'save_meta_box_settings'), 15, 2);
46 add_action('attachment_updated', array($this, 'save_meta_box_settings'), 15, 2);
47 }
48
49 /**
50 * Register meta box
51 * @since 4.7
52 */
53 public function add_meta_boxes($post_type)
54 {
55 if (apply_filters('litespeed_bypass_metabox', false, $post_type)) {
56 return;
57 }
58 $post_type_obj = get_post_type_object($post_type);
59 if (!empty($post_type_obj) && !$post_type_obj->public) {
60 self::debug('post type public=false, bypass add_meta_boxes');
61 return;
62 }
63 add_meta_box('litespeed_meta_boxes', __('LiteSpeed Options', 'litespeed-cache'), array($this, 'meta_box_options'), $post_type, 'side', 'core');
64 }
65
66 /**
67 * Show meta box content
68 * @since 4.7
69 */
70 public function meta_box_options()
71 {
72 require_once LSCWP_DIR . 'tpl/inc/metabox.php';
73 }
74
75 /**
76 * Save settings
77 * @since 4.7
78 */
79 public function save_meta_box_settings($post_id, $post)
80 {
81 global $pagenow;
82
83 self::debug('Maybe save post2 [post_id] ' . $post_id);
84
85 if ($pagenow != 'post.php' || !$post || !is_object($post)) {
86 return;
87 }
88
89 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
90 return;
91 }
92
93 if (!$this->cls('Router')->verify_nonce(self::POST_NONCE_ACTION)) {
94 return;
95 }
96
97 self::debug('Saving post [post_id] ' . $post_id);
98
99 foreach ($this->_postmeta_settings as $k => $v) {
100 $val = isset($_POST[$k]) ? $_POST[$k] : false;
101 $this->save($post_id, $k, $val);
102 }
103 }
104
105 /**
106 * Load setting per post
107 * @since 4.7
108 */
109 public function setting($conf, $post_id = false)
110 {
111 // Check if has metabox non-cacheable setting or not
112 if (!$post_id) {
113 $home_id = get_option('page_for_posts');
114 if (is_singular()) {
115 $post_id = get_the_ID();
116 } elseif ($home_id > 0 && is_home()) {
117 $post_id = $home_id;
118 }
119 }
120
121 if ($post_id && ($val = get_post_meta($post_id, $conf, true))) {
122 return $val;
123 }
124
125 return null;
126 }
127
128 /**
129 * Save a metabox value
130 * @since 4.7
131 */
132 public function save($post_id, $name, $val, $is_append = false)
133 {
134 if (strpos($name, 'litespeed_vpi_list') !== false) {
135 $val = Utility::sanitize_lines($val, 'basename,drop_webp');
136 }
137
138 // Load existing data if has set
139 if ($is_append) {
140 $existing_data = $this->setting($name, $post_id);
141 if ($existing_data) {
142 $existing_data = Utility::sanitize_lines($existing_data, 'basename');
143 $val = array_unique(array_merge($val, $existing_data));
144 }
145 }
146
147 if ($val) {
148 update_post_meta($post_id, $name, $val);
149 } else {
150 delete_post_meta($post_id, $name);
151 }
152 }
153
154 /**
155 * Load exclude images per post
156 * @since 4.7
157 */
158 public function lazy_img_excludes($list)
159 {
160 $is_mobile = $this->_separate_mobile();
161 $excludes = $this->setting($is_mobile ? 'litespeed_vpi_list_mobile' : 'litespeed_vpi_list');
162 if ($excludes !== null) {
163 $excludes = Utility::sanitize_lines($excludes, 'basename');
164 if ($excludes) {
165 // Check if contains `data:` (invalid result, need to clear existing result) or not
166 if (Utility::str_hit_array('data:', $excludes)) {
167 $this->cls('VPI')->add_to_queue();
168 } else {
169 return array_merge($list, $excludes);
170 }
171 }
172
173 return $list;
174 }
175
176 $this->cls('VPI')->add_to_queue();
177
178 return $list;
179 }
180 }
181