PluginProbe
WP EXtra – One Click Optimize / 8.7.1
WP EXtra – One Click Optimize v8.7.1
8.7.1 8.6.8 8.7.0 trunk 5.9 8.0 8.5.0 8.5.4 8.5.5 8.6.0 8.6.1 8.6.2 8.6.3 8.6.5
wp-extra / src / Helper.php

Helper.php in WP EXtra – One Click Optimize 8.7.1, at src/Helper.php

98 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPEXtra;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 use WPVNTeam\WPSettings\Helper as BaseHelper;
10
11 class Helper extends BaseHelper
12 {
13 /**
14 * Shorthand to get WP Extra option with dot notation support.
15 *
16 * Example: Helper::get('smtp_accounts.0.host')
17 */
18 public static function get($target = 'wp_extra', $key = null, $default = null)
19 {
20 if ($key === null && strpos($target, '.') === false && $target !== 'wp_extra') {
21 return parent::get('wp_extra', $target, $default);
22 }
23 return parent::get($target, $key, $default);
24 }
25
26 /**
27 * Backward-compatible get_option wrapper.
28 */
29 public static function get_option($key, $fallback = null)
30 {
31 $value = self::get('wp_extra', $key, $fallback);
32 $array_keys = ['smtp_options', 'no_emails', 'smtp_accounts', 'modules'];
33 if (is_array($fallback) || in_array($key, $array_keys, true)) {
34 return (array) $value;
35 }
36 return $value;
37 }
38
39 /**
40 * Backward-compatible get_all_options wrapper.
41 */
42 public static function get_all_options()
43 {
44 return parent::get_all('wp_extra');
45 }
46
47 /**
48 * Backward-compatible image URL resolver.
49 */
50 public static function get_image_url($key, $fallback = '')
51 {
52 $val = self::get_option($key, $fallback);
53 return parent::image($val, $fallback);
54 }
55
56 /**
57 * Check if a specific WP Extra feature is active.
58 */
59 public static function is_feature_active($key)
60 {
61 return parent::has('wp_extra', $key);
62 }
63
64 /**
65 * Minify CSS string.
66 */
67 public static function minifyCSS($css)
68 {
69 return parent::minify_css($css);
70 }
71
72 /**
73 * Check if WooCommerce is active.
74 */
75 public static function is_woo_active()
76 {
77 return class_exists('WooCommerce') || in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', (array) get_option('active_plugins', [])));
78 }
79
80 /**
81 * Normalize string for SEO friendly filenames.
82 */
83 public static function normalizeString($str = '')
84 {
85 $str = strip_tags($str);
86 $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
87 $str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
88 $str = strtolower($str);
89 $str = html_entity_decode($str, ENT_QUOTES, 'utf-8');
90 $str = htmlentities($str, ENT_QUOTES, 'utf-8');
91 $str = preg_replace('/(&)([a-z])([a-z]+;)/i', '$2', $str);
92 $str = str_replace(' ', '-', $str);
93 $str = rawurlencode($str);
94 $str = str_replace(['%', '.jpeg'], ['-', '.jpg'], $str);
95 return $str;
96 }
97 }
98