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 +41 -148 1.11.9 → 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,171 +52,67 @@
55 52
56 53 return (bool) count( array_intersect( $array1, $array2 ) );
57 54 }
58 55
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 );
60 +
59 61 /**
60 - * Check the role with the current user data.
61 - *
62 - * @param string $role
63 - *
64 - * @return bool
62 + * Force plugins to load scripts with SSL if page is SSL.
65 63 */
66 -function _mw_adminimize_current_user_has_role( $role ) {
64 +function _mw_adminimize_enqueueScriptsFix() {
67 65
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 -/**
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
84 - */
85 -function _mw_adminimize_debug( $data, $description = '' ) {
86 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_debug' ) ) {
66 + if ( is_admin() ) {
87 67 return;
88 68 }
89 69
90 - if ( ! class_exists( 'DebugListener' ) ) {
70 + $https_values = array( NULL, 'off' );
71 + if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
91 72 return;
92 73 }
93 74
94 - // Buffering.
95 - ob_start();
96 - $output = '';
97 - $output .= 'console.info(' . json_encode( $description ) . ');';
98 - $output .= 'console.log(' . json_encode( $data ) . ');';
99 -
100 - echo sprintf( '<script>%s</script>', $output );
101 -
102 - do_action( 'adminimize.log', $description, $data );
103 -}
104 -
105 -/**
106 - * Return duplicate items from array.
107 - *
108 - * @param $array
109 - *
110 - * @return array
111 - */
112 -function _mw_adminimize_get_duplicate( $array ) {
113 -
114 - return array_unique( array_map( 'unserialize', array_diff_assoc( array_map( 'serialize', $array), array_map( 'serialize', array_unique( $array, SORT_REGULAR ) ) ) ), SORT_REGULAR );
115 -}
116 -
117 -/**
118 - * Get intersection of a multiple array.
119 - *
120 - * @since 2016-06-28
121 - *
122 - * @param $array array Array with settings of all roles.
123 - *
124 - * @return array Data with only the data, there in each role active.
125 - */
126 -function _mw_adminimize_get_intersection( $array ) {
127 -
128 - return (array) call_user_func_array( 'array_intersect', array_values( $array ) );
129 -}
130 -
131 -/**
132 - * Flatten a multi-dimensional array in a simple array.
133 - *
134 - * @since 2016-11-19
135 - *
136 - * @param array $array
137 - *
138 - * @return array $flat
139 - */
140 -function _mw_adminimize_array_flatten( $array ) {
141 -
142 - $flat = array();
143 - foreach ( $array as $key => $value ) {
144 - if ( is_array( $value ) ) {
145 - $flat = array_merge( $flat, _mw_adminimize_array_flatten( $value ) );
146 - } else {
147 - $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 );
148 78 }
149 79 }
150 -
151 - return $flat;
152 80 }
153 81
154 82 /**
155 - * Break the access to a page.
156 - *
157 - * @param string $slug Slug of each menu item.
158 - *
159 - * @return bool If the check is true, return also true as bool.
83 + * Force plugins to load styles with SSL if page is SSL.
160 84 */
161 -function _mw_adminimize_check_page_access( $slug ) {
85 +function _mw_adminimize_enqueueStylesFix() {
162 86
163 - // If this default behavior is deactivated.
164 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_prevent_page_access' ) ) {
165 - return false;
87 + if ( is_admin() ) {
88 + return;
166 89 }
167 90
168 - $url = basename( esc_url_raw( $_SERVER['REQUEST_URI'] ) );
169 - $url = htmlspecialchars( $url );
170 -
171 - if ( ! isset( $url ) ) {
172 - return false;
91 + $https_values = array( NULL, 'off' );
92 + if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
93 + return;
173 94 }
174 95
175 - $uri = wp_parse_url( $url );
176 -
177 - if ( ! isset( $uri['path'] ) ) {
178 - 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 + }
179 100 }
180 -
181 - // URI without query parameter, like WP core edit.php.
182 - if ( ! isset( $uri['query'] ) && strpos( $uri['path'], $slug ) !== false ) {
183 - add_action( 'load-' . $slug, '_mw_adminimize_block_page_access' );
184 - return true;
185 - }
186 -
187 - // URL is equal the slug of WP menu.
188 - if ( $slug === $url ) {
189 - add_action( 'load-' . basename( $uri['path'] ), '_mw_adminimize_block_page_access' );
190 - return true;
191 - }
192 101 }
193 102
194 103 /**
195 - * Break the access to a page.
104 + * Check the role with the current user data.
196 105 *
197 - * @wp-hook load-$page_slug
198 - */
199 -function _mw_adminimize_block_page_access() {
200 -
201 - $message = esc_attr__( 'Cheatin&#8217; uh? Sorry, you are not allowed to access this site.', 'adminimize' );
202 - $message = apply_filters( 'adminimize_nopage_access_message', $message );
203 - wp_die( esc_html( $message ) );
204 -}
205 -
206 -/**
207 - * Check option value string in array and get string back for active checkboxes.
106 + * @param string $role
208 107 *
209 - * @param string $option String of option to check.
210 - * @param array $haystack Array of all options.
211 - *
212 - * @return string String for checked input box or empty string.
108 + * @return bool
213 109 */
214 -function _mw_adminimize_is_checked( $option, $haystack ) {
110 +function _mw_adminimize_current_user_has_role( $role ) {
215 111
216 - if ( ! isset( $haystack ) ) {
217 - return '';
112 + $user = wp_get_current_user();
113 + if ( in_array( $role, (array) $user->roles ) ) {
114 + return TRUE;
218 115 }
219 116
220 - if ( in_array( htmlspecialchars_decode( $option ), $haystack, true ) ) {
221 - return ' checked="checked"';
222 - }
223 -
224 - return '';
225 -}
117 + return FALSE;
118 +}