PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
← All changes | inc-setup/helping_hands.php +39 -150 1.11.5 → 1.9.1 View file →
@@ -1,14 +1,11 @@
1 1 <?php
2 2 /**
3 - * Helper functions.
4 - *
5 3 * @package Adminimize
6 4 * @subpackage Helping_Functions
7 5 * @author Frank Bültge <[email protected]
8 6 * @since 2016-01-22
9 7 */
10 -
11 8 if ( ! function_exists( 'add_action' ) ) {
12 9 die( "Hi there! I'm just a part of plugin, not much I can do when called directly." );
13 10 }
14 11
@@ -14,10 +11,10 @@
14 11
15 12 /**
16 13 * Recursive search in array.
17 14 *
18 - * @param string $needle
19 - * @param array $haystack
15 + * @param $needle
16 + * @param $haystack
20 17 *
21 18 * @return bool
22 19 */
23 20 function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
@@ -22,13 +19,13 @@
22 19 */
23 20 function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
24 21
25 22 if ( '' === $haystack ) {
26 - return false;
23 + return FALSE;
27 24 }
28 25
29 26 if ( ! $haystack ) {
30 - return false;
27 + return FALSE;
31 28 }
32 29
33 30 foreach ( $haystack as $stalk ) {
34 31 if ( $needle === $stalk
@@ -35,20 +32,20 @@
35 32 || ( is_array( $stalk )
36 33 && _mw_adminimize_recursive_in_array( $needle, $stalk )
37 34 )
38 35 ) {
39 - return true;
36 + return TRUE;
40 37 }
41 38 }
42 39
43 - return false;
40 + return FALSE;
44 41 }
45 42
46 43 /**
47 44 * Check if array contains all array values from another array.
48 45 *
49 - * @param array $array1
50 - * @param array $array2
46 + * @param $array1
47 + * @param $array2
51 48 *
52 49 * @return bool
53 50 */
54 51 function _mw_adminimize_in_arrays( $array1, $array2 ) {
@@ -55,175 +52,67 @@
55 52
56 53 return (bool) count( array_intersect( $array1, $array2 ) );
57 54 }
58 55
59 -/**
60 - * Check the role with the current user data.
61 - *
62 - * @param string $role
63 - *
64 - * @return bool
65 - */
66 -function _mw_adminimize_current_user_has_role( $role ) {
56 +// Fix some badly enqueued scripts with no sense of HTTPS.
57 +// Kudos to http://snippets.webaware.com.au/snippets/cleaning-up-wordpress-plugin-script-and-stylesheet-loads-over-ssl/
58 +add_action( 'wp_print_scripts', '_mw_adminimize_enqueueScriptsFix', 100 );
59 +add_action( 'wp_print_styles', '_mw_adminimize_enqueueStylesFix', 100 );
67 60
68 - $user = wp_get_current_user();
69 - if ( in_array( $role, (array) $user->roles, true ) ) {
70 - return true;
71 - }
72 -
73 - return false;
74 -}
75 -
76 61 /**
77 - * Simple helper to debug to the console of the browser.
78 - * Set WP_DEBUG_DISPLAY in your wp-config.php to true for view debug messages inside the console.
79 - *
80 - * @param string | array | object
81 - * @param string $description
82 - *
83 - * @return string|void
62 + * Force plugins to load scripts with SSL if page is SSL.
84 63 */
85 -function _mw_adminimize_debug( $data, $description = '' ) {
64 +function _mw_adminimize_enqueueScriptsFix() {
86 65
87 - // Don't run on export data of Adminimize settings.
88 - if ( isset( $_POST['_mw_adminimize_export'] ) ) {
66 + if ( is_admin() ) {
89 67 return;
90 68 }
91 69
92 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_debug' ) ) {
70 + $https_values = array( NULL, 'off' );
71 + if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
93 72 return;
94 73 }
95 74
96 - if ( '' === $description ) {
97 - $description = 'Debug in Console via Adminimize Plugin:';
98 - }
99 -
100 - // Buffering to solve problems with WP core, header() etc.
101 - ob_start();
102 - $output = 'console.info(' . json_encode( $description ) . ');';
103 - $output .= 'console.log(' . json_encode( $data ) . ');';
104 - $output = sprintf( '<script>%s</script>', $output );
105 -
106 - echo $output;
107 -}
108 -
109 -/**
110 - * Return duplicate items from array.
111 - *
112 - * @param $array
113 - *
114 - * @return array
115 - */
116 -function _mw_adminimize_get_duplicate( $array ) {
117 -
118 - return array_unique( array_map( 'unserialize', array_diff_assoc( array_map( 'serialize', $array), array_map( 'serialize', array_unique( $array, SORT_REGULAR ) ) ) ), SORT_REGULAR );
119 -}
120 -
121 -/**
122 - * Get intersection of a multiple array.
123 - *
124 - * @since 2016-06-28
125 - *
126 - * @param $array array Array with settings of all roles.
127 - *
128 - * @return array Data with only the data, there in each role active.
129 - */
130 -function _mw_adminimize_get_intersection( $array ) {
131 -
132 - return (array) call_user_func_array( 'array_intersect', $array );
133 -}
134 -
135 -/**
136 - * Flatten a multi-dimensional array in a simple array.
137 - *
138 - * @since 2016-11-19
139 - *
140 - * @param array $array
141 - *
142 - * @return array $flat
143 - */
144 -function _mw_adminimize_array_flatten( $array ) {
145 -
146 - $flat = array();
147 - foreach ( $array as $key => $value ) {
148 - if ( is_array( $value ) ) {
149 - $flat = array_merge( $flat, _mw_adminimize_array_flatten( $value ) );
150 - } else {
151 - $flat[ $key ] = $value;
75 + foreach ( (array) $GLOBALS[ 'wp_scripts' ]->registered as $script ) {
76 + if ( FALSE !== stripos( $script->src, 'http://', 0 ) ) {
77 + $script->src = str_replace( 'http://', 'https://', $script->src );
152 78 }
153 79 }
154 -
155 - return $flat;
156 80 }
157 81
158 82 /**
159 - * Break the access to a page.
160 - *
161 - * @param string $slug Slug of each menu item.
162 - *
163 - * @return bool If the check is true, return also true as bool.
83 + * Force plugins to load styles with SSL if page is SSL.
164 84 */
165 -function _mw_adminimize_check_page_access( $slug ) {
85 +function _mw_adminimize_enqueueStylesFix() {
166 86
167 - // If this default behavior is deactivated.
168 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_prevent_page_access' ) ) {
169 - return false;
87 + if ( is_admin() ) {
88 + return;
170 89 }
171 90
172 - $url = basename( esc_url_raw( $_SERVER['REQUEST_URI'] ) );
173 - $url = htmlspecialchars( $url );
174 -
175 - if ( ! isset( $url ) ) {
176 - return false;
91 + $https_values = array( NULL, 'off' );
92 + if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
93 + return;
177 94 }
178 95
179 - $uri = wp_parse_url( $url );
180 -
181 - if ( ! isset( $uri['path'] ) ) {
182 - return false;
96 + foreach ( (array) $GLOBALS[ 'wp_styles' ]->registered as $script ) {
97 + if ( FALSE !== stripos( $script->src, 'http://', 0 ) ) {
98 + $script->src = str_replace( 'http://', 'https://', $script->src );
99 + }
183 100 }
184 -
185 - // URI without query parameter, like WP core edit.php.
186 - if ( ! isset( $uri['query'] ) && strpos( $uri['path'], $slug ) !== false ) {
187 - add_action( 'load-' . $slug, '_mw_adminimize_block_page_access' );
188 - return true;
189 - }
190 -
191 - // URL is equal the slug of WP menu.
192 - if ( $slug === $url ) {
193 - add_action( 'load-' . basename( $uri['path'] ), '_mw_adminimize_block_page_access' );
194 - return true;
195 - }
196 101 }
197 102
198 103 /**
199 - * Break the access to a page.
104 + * Check the role with the current user data.
200 105 *
201 - * @wp-hook load-$page_slug
202 - */
203 -function _mw_adminimize_block_page_access() {
204 -
205 - $message = esc_attr__( 'Cheatin&#8217; uh? Sorry, you are not allowed to access this site.', 'adminimize' );
206 - $message = apply_filters( 'adminimize_nopage_access_message', $message );
207 - wp_die( esc_html( $message ) );
208 -}
209 -
210 -/**
211 - * Check option value string in array and get string back for active checkboxes.
106 + * @param string $role
212 107 *
213 - * @param string $option String of option to check.
214 - * @param array $haystack Array of all options.
215 - *
216 - * @return string String for checked input box or empty string.
108 + * @return bool
217 109 */
218 -function _mw_adminimize_is_checked( $option, $haystack ) {
110 +function _mw_adminimize_current_user_has_role( $role ) {
219 111
220 - if ( ! isset( $haystack ) ) {
221 - return '';
112 + $user = wp_get_current_user();
113 + if ( in_array( $role, (array) $user->roles ) ) {
114 + return TRUE;
222 115 }
223 116
224 - if ( in_array( htmlspecialchars_decode( $option ), $haystack, true ) ) {
225 - return ' checked="checked"';
226 - }
227 -
228 - return '';
117 + return FALSE;
229 118 }