PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.6
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.6
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.6, at Inc/Classes/Helper.php

97 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 WPAdminify\Inc\Classes;
4
5 // no direct access allowed
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 class Helper {
11
12
13 // Admin Path
14 public static function jltwp_adminify_admin_path( $path ) {
15 // Get custom filter path
16 if ( has_filter( 'jltwp_adminify_admin_path' ) ) {
17 return apply_filters( 'jltwp_adminify_admin_path', $path );
18 }
19
20 // Get plugin path
21 return plugins_url( $path, __DIR__ );
22 }
23
24 /**
25 * Get the editor/ builder of the given post.
26 *
27 * @param int $post_id ID of the post being checked.
28 * @return string The content editor name.
29 */
30 public static function get_content_editor( $post_id ) {
31 $content_editor = 'default';
32 $content_editor = apply_filters( 'udb_content_editor', $content_editor, $post_id );
33
34 return $content_editor;
35 }
36
37 /**
38 * Sanitize Checkbox.
39 *
40 * @param string|bool $checked Customizer option.
41 */
42 public function sanitize_checkbox( $checked ) {
43 return ( ( isset( $checked ) && true === $checked ) ? true : false );
44 }
45
46
47 /**
48 * Image sanitization callback.
49 *
50 * Checks the image's file extension and mime type against a whitelist. If they're allowed,
51 * send back the filename, otherwise, return the setting default.
52 *
53 * - Sanitization: image file extension
54 * - Control: text, WP_Customize_Image_Control
55 *
56 * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/
57 *
58 * @version 1.2.2
59 *
60 * @param string $image Image filename.
61 * @param WP_Customize_Setting $setting Setting instance.
62 *
63 * @return string The image filename if the extension is allowed; otherwise, the setting default.
64 */
65 public static function sanitize_image( $image, $setting ) {
66
67 /**
68 * Array of valid image file types.
69 *
70 * The array includes image mime types that are included in wp_get_mime_types()
71 */
72 $mimes = [
73 'jpg|jpeg|jpe' => 'image/jpeg',
74 'gif' => 'image/gif',
75 'png' => 'image/png',
76 'bmp' => 'image/bmp',
77 'tif|tiff' => 'image/tiff',
78 'ico' => 'image/x-icon',
79 ];
80
81 // Allowed svg mime type in version 1.2.2.
82 $allowed_mime = get_allowed_mime_types();
83 $svg_mime_check = isset( $allowed_mime['svg'] ) ? true : false;
84
85 if ( $svg_mime_check ) {
86 $allow_mime = [ 'svg' => 'image/svg+xml' ];
87 $mimes = array_merge( $mimes, $allow_mime );
88 }
89
90 // Return an array with file extension and mime_type.
91 $file = wp_check_filetype( $image, $mimes );
92
93 // If $image has a valid mime_type, return it; otherwise, return the default.
94 return esc_url_raw( ( $file['ext'] ? $image : $setting->default ) );
95 }
96 }
97