admin
2 months ago
register-hooks
3 years ago
class-wpel-front-ignore.php
3 years ago
class-wpel-front.php
4 months ago
class-wpel-link.php
3 years ago
class-wpel-plugin.php
1 year ago
class-wpel-register-scripts.php
2 months ago
class-wpel-template-tags.php
3 years ago
class-wpel-update.php
3 years ago
index.php
6 years ago
class-wpel-plugin.php
396 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class WPEL_Plugin |
| 5 | * |
| 6 | * @package WPEL |
| 7 | * @category WordPress Plugin |
| 8 | * @version 2.3 |
| 9 | * @link https://www.webfactoryltd.com/ |
| 10 | * @license Dual licensed under the MIT and GPLv2+ licenses |
| 11 | */ |
| 12 | final class WPEL_Plugin extends FWP_Plugin_Base_1x0x0 |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * Initialize plugin |
| 17 | * @param string $plugin_file |
| 18 | * @param string $plugin_dir |
| 19 | */ |
| 20 | protected function init($plugin_file, $plugin_dir) |
| 21 | { |
| 22 | parent::init($plugin_file, $plugin_dir); |
| 23 | $this->create_components(); |
| 24 | add_action('wp_ajax_wpel_dismiss_notice', array($this, 'ajax_dismiss_notice')); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Dismiss notice via AJAX call |
| 29 | * |
| 30 | * @return null |
| 31 | */ |
| 32 | function ajax_dismiss_notice() |
| 33 | { |
| 34 | check_ajax_referer('wpel_dismiss_notice'); |
| 35 | |
| 36 | if (!current_user_can('administrator')) { |
| 37 | wp_send_json_error('You are not allowed to run this action.'); |
| 38 | } |
| 39 | |
| 40 | if(!isset($_GET['notice_name'])){ |
| 41 | wp_send_json_error('Unknown action.'); |
| 42 | } |
| 43 | |
| 44 | $notice_name = sanitize_text_field(wp_unslash($_GET['notice_name'])); |
| 45 | $pointers = get_option('wpel-pointers', array()); |
| 46 | |
| 47 | if ($notice_name != 'welcome') { |
| 48 | wp_send_json_error('Unknown notice'); |
| 49 | } else { |
| 50 | $pointers['hide_welcome_pointer'] = true; |
| 51 | update_option('wpel-pointers', $pointers); |
| 52 | wp_send_json_success(); |
| 53 | } |
| 54 | } // ajax_dismiss_notice |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * Create components |
| 59 | */ |
| 60 | protected function create_components() |
| 61 | { |
| 62 | WPEL_Register_Scripts::create(); |
| 63 | |
| 64 | // network admin page |
| 65 | $network_page = WPEL_Network_Page::create(array( |
| 66 | 'network-settings' => WPEL_Network_Fields::create(), |
| 67 | 'network-admin-settings' => WPEL_Network_Admin_Fields::create(), |
| 68 | )); |
| 69 | |
| 70 | // admin settings page |
| 71 | $settings_page = WPEL_Settings_Page::create($network_page, array( |
| 72 | 'external-links' => WPEL_External_Link_Fields::create(), |
| 73 | 'internal-links' => WPEL_Internal_Link_Fields::create(), |
| 74 | 'excluded-links' => WPEL_Excluded_Link_Fields::create(), |
| 75 | 'admin' => WPEL_Admin_Fields::create(), |
| 76 | 'exceptions' => WPEL_Exceptions_Fields::create(), |
| 77 | 'exit-confirmation' => WPEL_Exit_Confirmation_Fields::create(), |
| 78 | )); |
| 79 | |
| 80 | // front site |
| 81 | if (!is_admin()) { |
| 82 | WPEL_Front::create($settings_page); |
| 83 | } |
| 84 | |
| 85 | // update procedures |
| 86 | WPEL_Update::create(); |
| 87 | } |
| 88 | |
| 89 | static function wp_kses_wf($html) |
| 90 | { |
| 91 | if(empty($html)){ |
| 92 | echo ''; |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | add_filter('safe_style_css', function ($styles) { |
| 97 | $styles_wf = array( |
| 98 | 'text-align', |
| 99 | 'margin', |
| 100 | 'color', |
| 101 | 'float', |
| 102 | 'border', |
| 103 | 'background', |
| 104 | 'background-color', |
| 105 | 'border-bottom', |
| 106 | 'border-bottom-color', |
| 107 | 'border-bottom-style', |
| 108 | 'border-bottom-width', |
| 109 | 'border-collapse', |
| 110 | 'border-color', |
| 111 | 'border-left', |
| 112 | 'border-left-color', |
| 113 | 'border-left-style', |
| 114 | 'border-left-width', |
| 115 | 'border-right', |
| 116 | 'border-right-color', |
| 117 | 'border-right-style', |
| 118 | 'border-right-width', |
| 119 | 'border-spacing', |
| 120 | 'border-style', |
| 121 | 'border-top', |
| 122 | 'border-top-color', |
| 123 | 'border-top-style', |
| 124 | 'border-top-width', |
| 125 | 'border-width', |
| 126 | 'caption-side', |
| 127 | 'clear', |
| 128 | 'cursor', |
| 129 | 'direction', |
| 130 | 'font', |
| 131 | 'font-family', |
| 132 | 'font-size', |
| 133 | 'font-style', |
| 134 | 'font-variant', |
| 135 | 'font-weight', |
| 136 | 'height', |
| 137 | 'letter-spacing', |
| 138 | 'line-height', |
| 139 | 'margin-bottom', |
| 140 | 'margin-left', |
| 141 | 'margin-right', |
| 142 | 'margin-top', |
| 143 | 'overflow', |
| 144 | 'padding', |
| 145 | 'padding-bottom', |
| 146 | 'padding-left', |
| 147 | 'padding-right', |
| 148 | 'padding-top', |
| 149 | 'text-decoration', |
| 150 | 'text-indent', |
| 151 | 'vertical-align', |
| 152 | 'width', |
| 153 | 'display', |
| 154 | ); |
| 155 | |
| 156 | foreach ($styles_wf as $style_wf) { |
| 157 | $styles[] = $style_wf; |
| 158 | } |
| 159 | return $styles; |
| 160 | }); |
| 161 | |
| 162 | $allowed_tags = wp_kses_allowed_html('post'); |
| 163 | $allowed_tags['input'] = array( |
| 164 | 'type' => true, |
| 165 | 'style' => true, |
| 166 | 'class' => true, |
| 167 | 'id' => true, |
| 168 | 'checked' => true, |
| 169 | 'disabled' => true, |
| 170 | 'name' => true, |
| 171 | 'size' => true, |
| 172 | 'placeholder' => true, |
| 173 | 'value' => true, |
| 174 | 'data-*' => true, |
| 175 | 'size' => true, |
| 176 | 'disabled' => true |
| 177 | ); |
| 178 | |
| 179 | $allowed_tags['textarea'] = array( |
| 180 | 'type' => true, |
| 181 | 'style' => true, |
| 182 | 'class' => true, |
| 183 | 'id' => true, |
| 184 | 'checked' => true, |
| 185 | 'disabled' => true, |
| 186 | 'name' => true, |
| 187 | 'size' => true, |
| 188 | 'placeholder' => true, |
| 189 | 'value' => true, |
| 190 | 'data-*' => true, |
| 191 | 'cols' => true, |
| 192 | 'rows' => true, |
| 193 | 'disabled' => true, |
| 194 | 'autocomplete' => true |
| 195 | ); |
| 196 | |
| 197 | $allowed_tags['select'] = array( |
| 198 | 'type' => true, |
| 199 | 'style' => true, |
| 200 | 'class' => true, |
| 201 | 'id' => true, |
| 202 | 'checked' => true, |
| 203 | 'disabled' => true, |
| 204 | 'name' => true, |
| 205 | 'size' => true, |
| 206 | 'placeholder' => true, |
| 207 | 'value' => true, |
| 208 | 'data-*' => true, |
| 209 | 'multiple' => true, |
| 210 | 'disabled' => true |
| 211 | ); |
| 212 | |
| 213 | $allowed_tags['option'] = array( |
| 214 | 'type' => true, |
| 215 | 'style' => true, |
| 216 | 'class' => true, |
| 217 | 'id' => true, |
| 218 | 'checked' => true, |
| 219 | 'disabled' => true, |
| 220 | 'name' => true, |
| 221 | 'size' => true, |
| 222 | 'placeholder' => true, |
| 223 | 'value' => true, |
| 224 | 'selected' => true, |
| 225 | 'data-*' => true |
| 226 | ); |
| 227 | $allowed_tags['optgroup'] = array( |
| 228 | 'type' => true, |
| 229 | 'style' => true, |
| 230 | 'class' => true, |
| 231 | 'id' => true, |
| 232 | 'checked' => true, |
| 233 | 'disabled' => true, |
| 234 | 'name' => true, |
| 235 | 'size' => true, |
| 236 | 'placeholder' => true, |
| 237 | 'value' => true, |
| 238 | 'selected' => true, |
| 239 | 'data-*' => true, |
| 240 | 'label' => true |
| 241 | ); |
| 242 | |
| 243 | $allowed_tags['a'] = array( |
| 244 | 'href' => true, |
| 245 | 'data-*' => true, |
| 246 | 'class' => true, |
| 247 | 'style' => true, |
| 248 | 'id' => true, |
| 249 | 'target' => true, |
| 250 | 'data-*' => true, |
| 251 | 'role' => true, |
| 252 | 'aria-controls' => true, |
| 253 | 'aria-selected' => true, |
| 254 | 'disabled' => true |
| 255 | ); |
| 256 | |
| 257 | $allowed_tags['div'] = array( |
| 258 | 'style' => true, |
| 259 | 'class' => true, |
| 260 | 'id' => true, |
| 261 | 'data-*' => true, |
| 262 | 'role' => true, |
| 263 | 'aria-labelledby' => true, |
| 264 | 'value' => true, |
| 265 | 'aria-modal' => true, |
| 266 | 'tabindex' => true |
| 267 | ); |
| 268 | |
| 269 | $allowed_tags['li'] = array( |
| 270 | 'style' => true, |
| 271 | 'class' => true, |
| 272 | 'id' => true, |
| 273 | 'data-*' => true, |
| 274 | 'role' => true, |
| 275 | 'aria-labelledby' => true, |
| 276 | 'value' => true, |
| 277 | 'aria-modal' => true, |
| 278 | 'tabindex' => true |
| 279 | ); |
| 280 | |
| 281 | $allowed_tags['span'] = array( |
| 282 | 'style' => true, |
| 283 | 'class' => true, |
| 284 | 'id' => true, |
| 285 | 'data-*' => true, |
| 286 | 'aria-hidden' => true |
| 287 | ); |
| 288 | |
| 289 | $allowed_tags['style'] = array( |
| 290 | 'class' => true, |
| 291 | 'id' => true, |
| 292 | 'type' => true |
| 293 | ); |
| 294 | |
| 295 | $allowed_tags['fieldset'] = array( |
| 296 | 'class' => true, |
| 297 | 'id' => true, |
| 298 | 'type' => true |
| 299 | ); |
| 300 | |
| 301 | $allowed_tags['link'] = array( |
| 302 | 'class' => true, |
| 303 | 'id' => true, |
| 304 | 'type' => true, |
| 305 | 'rel' => true, |
| 306 | 'href' => true, |
| 307 | 'media' => true |
| 308 | ); |
| 309 | |
| 310 | $allowed_tags['form'] = array( |
| 311 | 'style' => true, |
| 312 | 'class' => true, |
| 313 | 'id' => true, |
| 314 | 'method' => true, |
| 315 | 'action' => true, |
| 316 | 'data-*' => true |
| 317 | ); |
| 318 | |
| 319 | $allowed_tags['script'] = array( |
| 320 | 'class' => true, |
| 321 | 'id' => true, |
| 322 | 'type' => true, |
| 323 | 'src' => true |
| 324 | ); |
| 325 | |
| 326 | echo wp_kses($html, $allowed_tags); |
| 327 | |
| 328 | add_filter('safe_style_css', function ($styles) { |
| 329 | $styles_wf = array( |
| 330 | 'text-align', |
| 331 | 'margin', |
| 332 | 'color', |
| 333 | 'float', |
| 334 | 'border', |
| 335 | 'background', |
| 336 | 'background-color', |
| 337 | 'border-bottom', |
| 338 | 'border-bottom-color', |
| 339 | 'border-bottom-style', |
| 340 | 'border-bottom-width', |
| 341 | 'border-collapse', |
| 342 | 'border-color', |
| 343 | 'border-left', |
| 344 | 'border-left-color', |
| 345 | 'border-left-style', |
| 346 | 'border-left-width', |
| 347 | 'border-right', |
| 348 | 'border-right-color', |
| 349 | 'border-right-style', |
| 350 | 'border-right-width', |
| 351 | 'border-spacing', |
| 352 | 'border-style', |
| 353 | 'border-top', |
| 354 | 'border-top-color', |
| 355 | 'border-top-style', |
| 356 | 'border-top-width', |
| 357 | 'border-width', |
| 358 | 'caption-side', |
| 359 | 'clear', |
| 360 | 'cursor', |
| 361 | 'direction', |
| 362 | 'font', |
| 363 | 'font-family', |
| 364 | 'font-size', |
| 365 | 'font-style', |
| 366 | 'font-variant', |
| 367 | 'font-weight', |
| 368 | 'height', |
| 369 | 'letter-spacing', |
| 370 | 'line-height', |
| 371 | 'margin-bottom', |
| 372 | 'margin-left', |
| 373 | 'margin-right', |
| 374 | 'margin-top', |
| 375 | 'overflow', |
| 376 | 'padding', |
| 377 | 'padding-bottom', |
| 378 | 'padding-left', |
| 379 | 'padding-right', |
| 380 | 'padding-top', |
| 381 | 'text-decoration', |
| 382 | 'text-indent', |
| 383 | 'vertical-align', |
| 384 | 'width' |
| 385 | ); |
| 386 | |
| 387 | foreach ($styles_wf as $style_wf) { |
| 388 | if (($key = array_search($style_wf, $styles)) !== false) { |
| 389 | unset($styles[$key]); |
| 390 | } |
| 391 | } |
| 392 | return $styles; |
| 393 | }); |
| 394 | } |
| 395 | } |
| 396 |