PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Helper.php

Helper.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.7, at Inc/Classes/Helper.php

295 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Classes;
4
5 // no direct access allowed
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 class Helper {
11
12 // Admin Path
13 public static function jltwp_adminify_admin_path( $path ) {
14 // Get custom filter path
15 if ( has_filter( 'jltwp_adminify_admin_path' ) ) {
16 return apply_filters( 'jltwp_adminify_admin_path', $path );
17 }
18
19 // Get plugin path
20 return plugins_url( $path, __DIR__ );
21 }
22
23 /**
24 * Get the editor/ builder of the given post.
25 *
26 * @param int $post_id ID of the post being checked.
27 * @return string The content editor name.
28 */
29 public static function get_content_editor( $post_id ) {
30 $content_editor = 'default';
31 $content_editor = apply_filters( 'udb_content_editor', $content_editor, $post_id );
32
33 return $content_editor;
34 }
35
36 /**
37 * Sanitize Checkbox.
38 *
39 * @param string|bool $checked Customizer option.
40 */
41 public function sanitize_checkbox( $checked ) {
42 return ( ( isset( $checked ) && true === $checked ) ? true : false );
43 }
44
45
46 /**
47 * Image sanitization callback.
48 *
49 * Checks the image's file extension and mime type against a whitelist. If they're allowed,
50 * send back the filename, otherwise, return the setting default.
51 *
52 * - Sanitization: image file extension
53 * - Control: text, WP_Customize_Image_Control
54 *
55 * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/
56 *
57 * @version 1.2.2
58 *
59 * @param string $image Image filename.
60 * @param WP_Customize_Setting $setting Setting instance.
61 *
62 * @return string The image filename if the extension is allowed; otherwise, the setting default.
63 */
64 public static function sanitize_image( $image, $setting ) {
65
66 /**
67 * Array of valid image file types.
68 *
69 * The array includes image mime types that are included in wp_get_mime_types()
70 */
71 $mimes = array(
72 'jpg|jpeg|jpe' => 'image/jpeg',
73 'gif' => 'image/gif',
74 'png' => 'image/png',
75 'bmp' => 'image/bmp',
76 'tif|tiff' => 'image/tiff',
77 'ico' => 'image/x-icon',
78 );
79
80 // Allowed svg mime type in version 1.2.2.
81 $allowed_mime = get_allowed_mime_types();
82 $svg_mime_check = isset( $allowed_mime['svg'] ) ? true : false;
83
84 if ( $svg_mime_check ) {
85 $allow_mime = array( 'svg' => 'image/svg+xml' );
86 $mimes = array_merge( $mimes, $allow_mime );
87 }
88
89 // Return an array with file extension and mime_type.
90 $file = wp_check_filetype( $image, $mimes );
91
92 // If $image has a valid mime_type, return it; otherwise, return the default.
93 return esc_url_raw( ( $file['ext'] ? $image : $setting->default ) );
94 }
95
96
97
98 /**
99 * Remove spaces from Plugin Slug
100 */
101 public static function jltwp_adminify_slug_cleanup() {
102 return str_replace( '-', '_', strtolower( WP_ADMINIFY_SLUG ) );
103 }
104
105 /**
106 * Function current_datetime() compability for wp version < 5.3
107 *
108 * @return DateTimeImmutable
109 */
110 public static function jltwp_adminify_current_datetime() {
111 if ( function_exists( 'current_datetime' ) ) {
112 return current_datetime();
113 }
114
115 return new \DateTimeImmutable( 'now', self::jltwp_adminify_wp_timezone() );
116 }
117
118 /**
119 * Function jltwp_adminify_wp_timezone() compability for wp version < 5.3
120 *
121 * @return DateTimeZone
122 */
123 public static function jltwp_adminify_wp_timezone() {
124 if ( function_exists( 'wp_timezone' ) ) {
125 return wp_timezone();
126 }
127
128 return new \DateTimeZone( self::jltwp_adminify_wp_timezone_string() );
129 }
130
131 /**
132 * API Endpoint
133 *
134 * @return string
135 */
136 public static function api_endpoint() {
137 $api_endpoint_url = 'https://bo.jeweltheme.com';
138 $api_endpoint = apply_filters( 'jltwp_adminify_endpoint', $api_endpoint_url );
139
140 return trailingslashit( $api_endpoint );
141 }
142
143 /**
144 * CRM Endpoint
145 *
146 * @return string
147 */
148 public static function crm_endpoint() {
149 $crm_endpoint_url = 'https://bo.jeweltheme.com/wp-json/jlt-api/v1/subscribe'; // Endpoint .
150 $crm_endpoint = apply_filters( 'jltwp_adminify_crm_crm_endpoint', $crm_endpoint_url );
151
152 return trailingslashit( $crm_endpoint );
153 }
154
155 /**
156 * CRM Endpoint
157 *
158 * @return string
159 */
160 public static function crm_survey_endpoint() {
161 $crm_feedback_endpoint_url = 'https://bo.jeweltheme.com/wp-json/jlt-api/v1/survey'; // Endpoint .
162 $crm_feedback_endpoint = apply_filters( 'jltwp_adminify_crm_crm_endpoint', $crm_feedback_endpoint_url );
163
164 return trailingslashit( $crm_feedback_endpoint );
165 }
166
167 /**
168 * Function jltwp_adminify_wp_timezone_string() compability for wp version < 5.3
169 *
170 * @return string
171 */
172 public static function jltwp_adminify_wp_timezone_string() {
173 $timezone_string = get_option( 'timezone_string' );
174
175 if ( $timezone_string ) {
176 return $timezone_string;
177 }
178
179 $offset = (float) get_option( 'gmt_offset' );
180 $hours = (int) $offset;
181 $minutes = ( $offset - $hours );
182
183 $sign = ( $offset < 0 ) ? '-' : '+';
184 $abs_hour = abs( $hours );
185 $abs_mins = abs( $minutes * 60 );
186 $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
187
188 return $tz_offset;
189 }
190
191 /**
192 * Get Merged Data
193 *
194 * @param [type] $data .
195 * @param string $start_date .
196 * @param string $end_data .
197 *
198 * @author Jewel Theme <support@jeweltheme.com>
199 */
200 public static function get_merged_data( $data, $start_date = '', $end_data = '' ) {
201 $_data = shortcode_atts(
202 array(
203 'image_url' => WP_ADMINIFY_ASSETS_IMAGE . '/promo-image.png',
204 'start_date' => $start_date,
205 'end_date' => $end_data,
206 'counter_time' => '',
207 'is_campaign' => 'false',
208 'button_text' => 'Get Premium',
209 'button_url' => 'https://wpadminify.com/pricing',
210 'btn_color' => '#CC22FF',
211 'notice' => '',
212 'notice_timestamp' => '',
213 ),
214 $data
215 );
216
217 if ( empty( $_data['image_url'] ) ) {
218 $_data['image_url'] = WP_ADMINIFY_ASSETS_IMAGE . '/promo-image.png';
219 }
220
221 return $_data;
222 }
223
224
225 /**
226 * wp_kses attributes map
227 *
228 * @param array $attrs .
229 *
230 * @author Jewel Theme <support@jeweltheme.com>
231 */
232 public static function wp_kses_atts_map( array $attrs ) {
233 return array_fill_keys( array_values( $attrs ), true );
234 }
235
236 /**
237 * Custom method
238 *
239 * @param [type] $content .
240 *
241 * @author Jewel Theme <support@jeweltheme.com>
242 */
243 public static function wp_kses_custom( $content ) {
244 $allowed_tags = wp_kses_allowed_html( 'post' );
245
246 $custom_tags = array(
247 'select' => self::wp_kses_atts_map( array( 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'multiple', 'required', 'size' ) ),
248 'input' => self::wp_kses_atts_map( array( 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'size', 'type', 'checked', 'readonly', 'placeholder', 'value', 'maxlength', 'min', 'max', 'multiple', 'pattern', 'step', 'autocomplete' ) ),
249 'textarea' => self::wp_kses_atts_map( array( 'class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'rows', 'cols', 'wrap', 'maxlength' ) ),
250 'option' => self::wp_kses_atts_map( array( 'class', 'id', 'label', 'disabled', 'label', 'selected', 'value' ) ),
251 'optgroup' => self::wp_kses_atts_map( array( 'disabled', 'label', 'class', 'id' ) ),
252 'form' => self::wp_kses_atts_map( array( 'class', 'id', 'data', 'style', 'width', 'height', 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'rel', 'target' ) ),
253 'svg' => self::wp_kses_atts_map( array( 'class', 'xmlns', 'viewbox', 'width', 'height', 'fill', 'aria-hidden', 'aria-labelledby', 'role' ) ),
254 'rect' => self::wp_kses_atts_map( array( 'rx', 'width', 'height', 'fill' ) ),
255 'path' => self::wp_kses_atts_map( array( 'd', 'fill' ) ),
256 'g' => self::wp_kses_atts_map( array( 'fill' ) ),
257 'defs' => self::wp_kses_atts_map( array( 'fill' ) ),
258 'linearGradient' => self::wp_kses_atts_map( array( 'id', 'x1', 'x2', 'y1', 'y2', 'gradientUnits' ) ),
259 'stop' => self::wp_kses_atts_map( array( 'stop-color', 'offset', 'stop-opacity' ) ),
260 'style' => self::wp_kses_atts_map( array( 'type' ) ),
261 'div' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
262 'ul' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
263 'li' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
264 'label' => self::wp_kses_atts_map( array( 'class', 'for' ) ),
265 'span' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
266 'h1' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
267 'h2' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
268 'h3' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
269 'h4' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
270 'h5' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
271 'h6' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
272 'a' => self::wp_kses_atts_map( array( 'class', 'href', 'target', 'rel' ) ),
273 'p' => self::wp_kses_atts_map( array( 'class', 'id', 'style', 'data' ) ),
274 'table' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
275 'thead' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
276 'tbody' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
277 'tr' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
278 'th' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
279 'td' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
280 'i' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
281 'button' => self::wp_kses_atts_map( array( 'class', 'id' ) ),
282 'nav' => self::wp_kses_atts_map( array( 'class', 'id', 'style' ) ),
283 'time' => self::wp_kses_atts_map( array( 'datetime' ) ),
284 'br' => array(),
285 'strong' => array(),
286 'style' => array(),
287 'img' => self::wp_kses_atts_map( array( 'class', 'src', 'alt', 'height', 'width', 'srcset', 'id', 'loading' ) ),
288 );
289
290 $allowed_tags = array_merge_recursive( $allowed_tags, $custom_tags );
291
292 return wp_kses( stripslashes_deep( $content ), $allowed_tags );
293 }
294 }
295