PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 7.3.0
Admin and Site Enhancements (ASE) v7.3.0
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-common-methods.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-columns-manager.php 2 years ago class-admin-menu-organizer.php 2 years ago class-auto-publish-posts-with-missed-schedule.php 2 years ago class-avif-upload.php 2 years ago class-change-login-url.php 2 years ago class-cleanup-admin-bar.php 2 years ago class-code-snippets-manager.php 2 years ago class-common-methods.php 2 years ago class-content-duplication.php 2 years ago class-content-order.php 2 years ago class-custom-admin-footer-text.php 2 years ago class-custom-body-class.php 2 years ago class-custom-content-types.php 2 years ago class-custom-css.php 2 years ago class-custom-nav-menu-items-in-new-tab.php 2 years ago class-deactivation.php 2 years ago class-disable-comments.php 2 years ago class-disable-dashboard-widgets.php 2 years ago class-disable-feeds.php 2 years ago class-disable-gutenberg.php 2 years ago class-disable-rest-api.php 2 years ago class-disable-smaller-components.php 2 years ago class-disable-updates.php 2 years ago class-disable-xml-rpc.php 2 years ago class-display-system-summary.php 2 years ago class-email-address-obfuscator.php 2 years ago class-email-delivery.php 2 years ago class-enhance-list-tables.php 2 years ago class-external-permalinks.php 2 years ago class-heartbeat-control.php 2 years ago class-hide-admin-bar.php 2 years ago class-hide-admin-notices.php 2 years ago class-image-sizes-panel.php 2 years ago class-image-upload-control.php 2 years ago class-insert-head-body-footer-code.php 2 years ago class-last-login-column.php 2 years ago class-limit-login-attempts.php 2 years ago class-login-id-type.php 2 years ago class-login-logout-menu.php 2 years ago class-maintenance-mode.php 2 years ago class-manage-ads-appads-txt.php 2 years ago class-manage-robots-txt.php 2 years ago class-media-replacement.php 2 years ago class-multiple-user-roles.php 2 years ago class-obfuscate-author-slugs.php 2 years ago class-open-external-links-in-new-tab.php 2 years ago class-password-protection.php 2 years ago class-redirect-after-login.php 2 years ago class-redirect-after-logout.php 2 years ago class-redirect-fourofour.php 2 years ago class-revisions-control.php 2 years ago class-search-engines-visibility.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-show-custom-taxonomy-filters.php 2 years ago class-site-identity-on-login-page.php 2 years ago class-svg-upload.php 2 years ago class-various-admin-ui-enhancements.php 2 years ago class-view-admin-as-role.php 2 years ago class-wider-admin-menu.php 2 years ago
class-common-methods.php
528 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 use WP_Query;
6 /**
7 * Class that provides common methods used throughout the plugin
8 *
9 * @since 2.5.0
10 */
11 class Common_Methods {
12 /**
13 * Get IP of the current visitor/user. In use by at least the Limit Login Attempts feature.
14 * This takes a best guess of the visitor's actual IP address.
15 * Takes into account numerous HTTP proxy headers due to variations
16 * in how different ISPs handle IP addresses in headers between hops.
17 *
18 * @link https://stackoverflow.com/q/1634782
19 * @since 2.5.0
20 */
21 public function get_user_ip_address( $return_type = 'ip', $for_which_module = 'limit-login-attempts' ) {
22 // Check for shared internet/ISP IP
23 if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) && $this->is_ip_valid( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24 switch ( $return_type ) {
25 case 'ip':
26 return sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
27 break;
28 case 'header':
29 return 'HTTP_CLIENT_IP';
30 break;
31 }
32 }
33 // Check if Cloudflare is used as a proxy
34 // Ref: https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#x-forwarded-for
35 if ( !empty( $_SERVER['CF_CONNECTING_IP'] ) && $this->is_ip_valid( $_SERVER['CF_CONNECTING_IP'] ) ) {
36 switch ( $return_type ) {
37 case 'ip':
38 return sanitize_text_field( $_SERVER['CF_CONNECTING_IP'] );
39 break;
40 case 'header':
41 return 'CF_CONNECTING_IP';
42 break;
43 }
44 }
45 if ( !empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) && $this->is_ip_valid( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
46 switch ( $return_type ) {
47 case 'ip':
48 return sanitize_text_field( $_SERVER['HTTP_CF_CONNECTING_IP'] );
49 break;
50 case 'header':
51 return 'HTTP_CF_CONNECTING_IP';
52 break;
53 }
54 }
55 if ( !empty( $_SERVER['TRUE_CLIENT_IP'] ) && $this->is_ip_valid( $_SERVER['TRUE_CLIENT_IP'] ) ) {
56 switch ( $return_type ) {
57 case 'ip':
58 return sanitize_text_field( $_SERVER['TRUE_CLIENT_IP'] );
59 break;
60 case 'header':
61 return 'TRUE_CLIENT_IP';
62 break;
63 }
64 }
65 if ( !empty( $_SERVER['HTTP_TRUE_CLIENT_IP'] ) && $this->is_ip_valid( $_SERVER['HTTP_TRUE_CLIENT_IP'] ) ) {
66 switch ( $return_type ) {
67 case 'ip':
68 return sanitize_text_field( $_SERVER['HTTP_TRUE_CLIENT_IP'] );
69 break;
70 case 'header':
71 return 'HTTP_TRUE_CLIENT_IP';
72 break;
73 }
74 }
75 // Check for IPs passing through proxies
76 if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
77 // Check if multiple IP addresses exist in var
78 $ip_list = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
79 if ( is_array( $ip_list ) && count( $ip_list ) > 1 ) {
80 foreach ( $ip_list as $ip ) {
81 if ( $this->is_ip_valid( trim( $ip ) ) ) {
82 switch ( $return_type ) {
83 case 'ip':
84 return sanitize_text_field( trim( $ip ) );
85 break;
86 case 'header':
87 return 'HTTP_X_FORWARDED_FOR (multiple IPs)';
88 break;
89 }
90 }
91 }
92 } else {
93 switch ( $return_type ) {
94 case 'ip':
95 return sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
96 break;
97 case 'header':
98 return 'HTTP_X_FORWARDED_FOR';
99 break;
100 }
101 }
102 }
103 if ( !empty( $_SERVER['HTTP_X_FORWARDED'] ) && $this->is_ip_valid( $_SERVER['HTTP_X_FORWARDED'] ) ) {
104 switch ( $return_type ) {
105 case 'ip':
106 return sanitize_text_field( $_SERVER['HTTP_X_FORWARDED'] );
107 break;
108 case 'header':
109 return 'HTTP_X_FORWARDED';
110 break;
111 }
112 }
113 if ( !empty( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] ) && $this->is_ip_valid( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] ) ) {
114 switch ( $return_type ) {
115 case 'ip':
116 return sanitize_text_field( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] );
117 break;
118 case 'header':
119 return 'HTTP_X_CLUSTER_CLIENT_IP';
120 break;
121 }
122 }
123 if ( !empty( $_SERVER['HTTP_FORWARDED_FOR'] ) && $this->is_ip_valid( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
124 switch ( $return_type ) {
125 case 'ip':
126 return sanitize_text_field( $_SERVER['HTTP_FORWARDED_FOR'] );
127 break;
128 case 'header':
129 return 'HTTP_FORWARDED_FOR';
130 break;
131 }
132 }
133 if ( !empty( $_SERVER['HTTP_FORWARDED'] ) && $this->is_ip_valid( $_SERVER['HTTP_FORWARDED'] ) ) {
134 switch ( $return_type ) {
135 case 'ip':
136 return sanitize_text_field( $_SERVER['HTTP_FORWARDED'] );
137 break;
138 case 'header':
139 return 'HTTP_FORWARDED';
140 break;
141 }
142 }
143 // Return unreliable IP address since all else failed
144 switch ( $return_type ) {
145 case 'ip':
146 return sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
147 break;
148 case 'header':
149 return 'REMOTE_ADDR';
150 break;
151 }
152 }
153
154 /**
155 * Check if the supplied IP address is valid or not
156 *
157 * @param string $ip an IP address
158 * @link https://stackoverflow.com/q/1634782
159 * @return boolean true if supplied address is valid IP, and false otherwise
160 */
161 public function is_ip_valid( $ip ) {
162 if ( empty( $ip ) ) {
163 return false;
164 }
165 // Ref: https://www.php.net/manual/en/filter.filters.validate.php
166 if ( false == filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
167 return false;
168 } else {
169 return true;
170 }
171 }
172
173 /**
174 * Convert number of seconds into hours, minutes, seconds. In use by at least the Limit Login Attempts feature.
175 *
176 * @since 2.5.0
177 */
178 public function seconds_to_period( $seconds, $conversion_type ) {
179 $period_start = new \DateTime('@0');
180 $period_end = new \DateTime("@{$seconds}");
181 if ( $conversion_type == 'to-days-hours-minutes-seconds' ) {
182 return $period_start->diff( $period_end )->format( '%a days, %h hours, %i minutes and %s seconds' );
183 } elseif ( $conversion_type == 'to-hours-minutes-seconds' ) {
184 return $period_start->diff( $period_end )->format( '%h hours, %i minutes and %s seconds' );
185 } elseif ( $conversion_type == 'to-minutes-seconds' ) {
186 return $period_start->diff( $period_end )->format( '%i minutes and %s seconds' );
187 } else {
188 return $period_start->diff( $period_end )->format( '%a days, %h hours, %i minutes and %s seconds' );
189 }
190 }
191
192 /**
193 * Remove html tags and content inside the tags from a string
194 *
195 * @since 3.0.3
196 */
197 public function strip_html_tags_and_content( $string ) {
198 // Strip HTML tags and content inside them. Ref: https://stackoverflow.com/a/39320168
199 if ( !is_null( $string ) ) {
200 if ( false === strpos( $string, 'fs-submenu-item' ) ) {
201 $string = preg_replace( '@<(\\w+)\\b.*?>.*?</\\1>@si', '', $string );
202 }
203 // Strip any remaining HTML or PHP tags
204 $string = strip_tags( $string );
205 }
206 return $string;
207 }
208
209 /**
210 * Get menu hidden by toggle
211 *
212 * @since 5.1.0
213 */
214 public function get_menu_hidden_by_toggle() {
215 $menu_hidden_by_toggle = array();
216 $options = get_option( ASENHA_SLUG_U, array() );
217 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
218 $menu_hidden = $options['custom_menu_hidden'];
219 $menu_hidden = explode( ',', $menu_hidden );
220 $menu_hidden_by_toggle = array();
221 foreach ( $menu_hidden as $menu_id ) {
222 $menu_hidden_by_toggle[] = $this->restore_menu_item_id( $menu_id );
223 }
224 }
225 return $menu_hidden_by_toggle;
226 }
227
228 /**
229 * Get user capabilities for which the "Show All/Less" menu toggle should be shown for
230 *
231 * @since 5.1.0
232 */
233 public function get_user_capabilities_to_show_menu_toggle_for() {
234 global $menu, $submenu;
235 $menu_always_hidden = array();
236 $user_capabilities_menus_are_hidden_for = array();
237 $menu_hidden_by_toggle = $this->get_menu_hidden_by_toggle();
238 // indexed array
239 foreach ( $menu as $menu_key => $menu_info ) {
240 foreach ( $menu_hidden_by_toggle as $hidden_menu_id ) {
241 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
242 $menu_item_id = $menu_info[2];
243 } else {
244 $menu_item_id = $menu_info[5];
245 }
246 if ( $menu_item_id == $hidden_menu_id ) {
247 $user_capabilities_menus_are_hidden_for[] = $menu_info[1];
248 }
249 }
250 }
251 $user_capabilities_menus_are_hidden_for = array_unique( $user_capabilities_menus_are_hidden_for );
252 return $user_capabilities_menus_are_hidden_for;
253 // indexed array
254 }
255
256 /**
257 * Transform menu item's ID
258 *
259 * @since 5.1.0
260 */
261 public function transform_menu_item_id( $menu_item_id ) {
262 // Transform e.g. edit.php?post_type=page ==> edit__php___post_type____page
263 $menu_item_id_transformed = str_replace( array(
264 ".",
265 "?",
266 "=/",
267 "=",
268 "&",
269 "/"
270 ), array(
271 "__",
272 "___",
273 "_______",
274 "____",
275 "_____",
276 "______"
277 ), $menu_item_id );
278 return $menu_item_id_transformed;
279 }
280
281 /**
282 * Transform menu item's ID
283 *
284 * @since 5.1.0
285 */
286 public function restore_menu_item_id( $menu_item_id_transformed ) {
287 // Transform e.g. edit__php___post_type____page ==> edit.php?post_type=page
288 $menu_item_id = str_replace( array(
289 "_______",
290 "______",
291 "_____",
292 "____",
293 "___",
294 "__"
295 ), array(
296 "=/",
297 "/",
298 "&",
299 "=",
300 "?",
301 "."
302 ), $menu_item_id_transformed );
303 return $menu_item_id;
304 }
305
306 /**
307 * Sanitize hexedecimal numbers used for colors
308 *
309 * @link https://plugins.trac.wordpress.org/browser/bm-custom-login/trunk/bm-custom-login.php
310 * @param string $color Hex number to sanitize.
311 * @return string
312 */
313 public function sanitize_hex_color( $color ) {
314 if ( '' === $color ) {
315 return '';
316 }
317 // Make sure the color starts with a hash.
318 $color = '#' . ltrim( $color, '#' );
319 // 3 or 6 hex digits, or the empty string.
320 if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
321 return $color;
322 }
323 return null;
324 }
325
326 /**
327 * Get the post ID of the most recent post in a custom post type
328 *
329 * @since 6.4.1
330 */
331 public function get_most_recent_post_id( $post_type ) {
332 $args = array(
333 'post_type' => $post_type,
334 'posts_per_page' => 1,
335 'orderby' => 'date',
336 'order' => 'DESC',
337 );
338 $query = new WP_Query($args);
339 if ( $query->have_posts() ) {
340 $query->the_post();
341 $post_id = get_the_ID();
342 wp_reset_postdata();
343 return $post_id;
344 }
345 return 0;
346 // Return 0 if no posts found
347 }
348
349 /**
350 * Extended ruleset for wp_kses() that includes SVG tag and it's children
351 *
352 * @since 6.8.3
353 */
354 public function get_kses_extended_ruleset() {
355 $kses_defaults = wp_kses_allowed_html( 'post' );
356 // For SVG icons
357 $svg_args = array(
358 'svg' => array(
359 'class' => true,
360 'aria-hidden' => true,
361 'aria-labelledby' => true,
362 'role' => true,
363 'xmlns' => true,
364 'width' => true,
365 'height' => true,
366 'viewbox' => true,
367 'viewBox' => true,
368 ),
369 'g' => array(
370 'fill' => true,
371 'fill-rule' => true,
372 'stroke' => true,
373 'stroke-linejoin' => true,
374 'stroke-width' => true,
375 'stroke-linecap' => true,
376 ),
377 'title' => array(
378 'title' => true,
379 ),
380 'path' => array(
381 'd' => true,
382 'fill' => true,
383 'stroke' => true,
384 'stroke-linejoin' => true,
385 'stroke-width' => true,
386 'stroke-linecap' => true,
387 ),
388 'rect' => array(
389 'width' => true,
390 'height' => true,
391 'x' => true,
392 'y' => true,
393 'rx' => true,
394 'ry' => true,
395 ),
396 'circle' => array(
397 'cx' => true,
398 'cy' => true,
399 'r' => true,
400 ),
401 );
402 $kses_with_extras = array_merge( $kses_defaults, $svg_args );
403 // For embedded PDF viewer
404 $style_script_args = array(
405 'style' => true,
406 'script' => array(
407 'src' => true,
408 ),
409 );
410 return array_merge( $kses_with_extras, $style_script_args );
411 }
412
413 /**
414 * Get the singular label from a $post object
415 *
416 * @since 6.9.3
417 */
418 function get_post_type_singular_label( $post ) {
419 $post_type_singular_label = '';
420 if ( property_exists( $post, 'post_type' ) ) {
421 $post_type_object = get_post_type_object( $post->post_type );
422 if ( is_object( $post_type_object ) && property_exists( $post_type_object, 'label' ) ) {
423 $post_type_singular_label = $post_type_object->labels->singular_name;
424 }
425 }
426 return $post_type_singular_label;
427 }
428
429 function is_in_block_editor() {
430 $current_screen = get_current_screen();
431 if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
432 return true;
433 } else {
434 return false;
435 }
436 }
437
438 /**
439 * Check if WooCommerce is active
440 *
441 * @since 6.9.9
442 */
443 public function is_woocommerce_active() {
444 if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
445 return true;
446 } else {
447 return false;
448 }
449 }
450
451 /**
452 * Convert HEX color to RGBA
453 *
454 * @link https://stackoverflow.com/a/31934345
455 * @since 7.0.0
456 */
457 public function hex_to_rgba( $hex, $alpha = false ) {
458 $hex = str_replace( '#', '', trim( $hex ) );
459 $length = strlen( $hex );
460 $rgb['r'] = hexdec( ( $length == 6 ? substr( $hex, 0, 2 ) : (( $length == 3 ? str_repeat( substr( $hex, 0, 1 ), 2 ) : 0 )) ) );
461 $rgb['g'] = hexdec( ( $length == 6 ? substr( $hex, 2, 2 ) : (( $length == 3 ? str_repeat( substr( $hex, 1, 1 ), 2 ) : 0 )) ) );
462 $rgb['b'] = hexdec( ( $length == 6 ? substr( $hex, 4, 2 ) : (( $length == 3 ? str_repeat( substr( $hex, 2, 1 ), 2 ) : 0 )) ) );
463 if ( false !== $alpha ) {
464 $rgb['a'] = $alpha;
465 }
466 // Return array of r, g, b and a
467 // return $rgb;
468 // Return rgb(255,255,255) or rgba(255,255,255,.5)
469 return implode( array_keys( $rgb ) ) . '(' . implode( ', ', $rgb ) . ')';
470 }
471
472 /**
473 * Detect if a color is light or dark
474 *
475 * @link https://stackoverflow.com/a/12228730
476 * @since 7.0.0
477 */
478 public function is_color_dark( $hex ) {
479 $hex = str_replace( '#', '', trim( $hex ) );
480 $r = hexdec( $hex[0] . $hex[1] );
481 $g = hexdec( $hex[2] . $hex[3] );
482 $b = hexdec( $hex[4] . $hex[5] );
483 $lightness = (max( $r, $g, $b ) + min( $r, $g, $b )) / 510.0;
484 // HSL algorithm
485 if ( $lightness > 0.8 ) {
486 return false;
487 } else {
488 return true;
489 }
490 }
491
492 /**
493 * Return SVG for small triangle in place of using &#9654; HTMl character
494 * which may be converted to emoticon by the browser or app
495 *
496 * @since 7.2.0
497 */
498 public function get_svg_triangle() {
499 return '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 16 16"><path fill="currentColor" d="M14.222 6.687a1.5 1.5 0 0 1 0 2.629l-10 5.499A1.5 1.5 0 0 1 2 13.5V2.502a1.5 1.5 0 0 1 2.223-1.314z"/></svg>';
500 }
501
502 /**
503 * Get an image URL from an ASE setting field, which could be an internal relative URL or an external URL
504 *
505 * @since 7.2.1
506 */
507 public function get_image_url( $ase_settings_field_name ) {
508 $options = get_option( ASENHA_SLUG_U, array() );
509 if ( isset( $options[$ase_settings_field_name] ) ) {
510 if ( false === strpos( $options[$ase_settings_field_name], 'http' ) && false !== strpos( $options[$ase_settings_field_name], '/uploads/' ) ) {
511 $logo_image = content_url() . $options[$ase_settings_field_name];
512 } else {
513 // $maybe_valid_url = filter_var( $options['admin_logo_image'], FILTER_SANITIZE_URL );
514 $maybe_valid_url = sanitize_url( $options[$ase_settings_field_name], array('http', 'https') );
515 if ( false !== filter_var( $maybe_valid_url, FILTER_VALIDATE_URL ) ) {
516 $logo_image = $maybe_valid_url;
517 } else {
518 $logo_image = '';
519 }
520 }
521 } else {
522 $logo_image = '';
523 }
524 return $logo_image;
525 }
526
527 }
528