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 +36 -125 1.11.4 → 1.9.1 View file →
@@ -11,10 +11,10 @@
11 11
12 12 /**
13 13 * Recursive search in array.
14 14 *
15 - * @param string $needle
16 - * @param array $haystack
15 + * @param $needle
16 + * @param $haystack
17 17 *
18 18 * @return bool
19 19 */
20 20 function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
@@ -42,10 +42,10 @@
42 42
43 43 /**
44 44 * Check if array contains all array values from another array.
45 45 *
46 - * @param array $array1
47 - * @param array $array2
46 + * @param $array1
47 + * @param $array2
48 48 *
49 49 * @return bool
50 50 */
51 51 function _mw_adminimize_in_arrays( $array1, $array2 ) {
@@ -52,156 +52,67 @@
52 52
53 53 return (bool) count( array_intersect( $array1, $array2 ) );
54 54 }
55 55
56 -/**
57 - * Check the role with the current user data.
58 - *
59 - * @param string $role
60 - *
61 - * @return bool
62 - */
63 -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 );
64 60
65 - $user = wp_get_current_user();
66 - if ( in_array( $role, (array) $user->roles, FALSE ) ) {
67 - return TRUE;
68 - }
69 -
70 - return FALSE;
71 -}
72 -
73 61 /**
74 - * Simple helper to debug to the console of the browser.
75 - * Set WP_DEBUG_DISPLAY in your wp-config.php to true for view debug messages inside the console.
76 - *
77 - * @param string | array | object
78 - * @param string $description
79 - *
80 - * @return string|void
62 + * Force plugins to load scripts with SSL if page is SSL.
81 63 */
82 -function _mw_adminimize_debug( $data, $description = '' ) {
64 +function _mw_adminimize_enqueueScriptsFix() {
83 65
84 - // Don't run on export data of Adminimize settings.
85 - if ( isset( $_POST[ '_mw_adminimize_export' ] ) ) {
66 + if ( is_admin() ) {
86 67 return;
87 68 }
88 69
89 - 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 ) ) {
90 72 return;
91 73 }
92 74
93 - if ( '' === $description ) {
94 - $description = 'Debug in Console via Adminimize Plugin:';
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 );
78 + }
95 79 }
96 -
97 - // Buffering to solve problems with WP core, header() etc.
98 - ob_start();
99 - $output = 'console.info(' . json_encode( $description ) . ');';
100 - $output .= 'console.log(' . json_encode( $data ) . ');';
101 - $output = sprintf( '<script>%s</script>', $output );
102 -
103 - echo $output;
104 80 }
105 81
106 82 /**
107 - * Return duplicate items from array.
108 - *
109 - * @param $array
110 - *
111 - * @return array
83 + * Force plugins to load styles with SSL if page is SSL.
112 84 */
113 -function _mw_adminimize_get_duplicate( $array ) {
85 +function _mw_adminimize_enqueueStylesFix() {
114 86
115 - return array_unique(
116 - array_diff_assoc( $array, array_unique( $array ) )
117 - );
118 -}
87 + if ( is_admin() ) {
88 + return;
89 + }
119 90
120 -/**
121 - * Get intersection of a multiple array.
122 - *
123 - * @since 2016-06-28
124 - *
125 - * @param $array array Array with settings of all roles.
126 - *
127 - * @return array Data with only the data, there in each role active.
128 - */
129 -function _mw_adminimize_get_intersection( $array ) {
91 + $https_values = array( NULL, 'off' );
92 + if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
93 + return;
94 + }
130 95
131 - return (array) call_user_func_array( 'array_intersect', $array );
132 -}
133 -
134 -/**
135 - * Flatten a multi-dimensional array in a simple array.
136 - *
137 - * @since 2016-11-19
138 - *
139 - * @param array $array
140 - *
141 - * @return array $flat
142 - */
143 -function _mw_adminimize_array_flatten( $array ) {
144 -
145 - $flat = array();
146 - foreach ( $array as $key => $value ) {
147 - if ( is_array( $value ) ) {
148 - $flat = array_merge( $flat, _mw_adminimize_array_flatten( $value ) );
149 - } else {
150 - $flat[ $key ] = $value;
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 );
151 99 }
152 100 }
153 -
154 - return $flat;
155 101 }
156 102
157 103 /**
158 - * Break the access to a page.
104 + * Check the role with the current user data.
159 105 *
160 - * @param string $slug Slug of each menu item.
106 + * @param string $role
161 107 *
162 - * @return bool If the check is true, return also true as bool.
108 + * @return bool
163 109 */
164 -function _mw_adminimize_check_page_access( $slug ) {
110 +function _mw_adminimize_current_user_has_role( $role ) {
165 111
166 - // If this default behavior is deactivated.
167 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_prevent_page_access' ) ) {
168 - return FALSE;
169 - }
170 -
171 - $url = basename( esc_url_raw( $_SERVER[ 'REQUEST_URI' ] ) );
172 - $url = htmlspecialchars( $url );
173 -
174 - if ( ! isset( $url ) ) {
175 - return FALSE;
176 - }
177 -
178 - $uri = parse_url( $url );
179 -
180 - if ( ! isset( $uri[ 'path' ] ) ) {
181 - return FALSE;
182 - }
183 -
184 - // URI without query parameter, like WP core edit.php.
185 - if ( ! isset( $uri[ 'query' ] ) && strpos( $uri[ 'path' ], $slug ) !== FALSE ) {
186 - add_action( 'load-' . $slug, '_mw_adminimize_block_page_access' );
112 + $user = wp_get_current_user();
113 + if ( in_array( $role, (array) $user->roles ) ) {
187 114 return TRUE;
188 115 }
189 116
190 - // URL is equal the slug of WP menu.
191 - if ( $slug === $url ) {
192 - add_action( 'load-' . basename( $uri[ 'path' ] ), '_mw_adminimize_block_page_access' );
193 - return TRUE;
194 - }
117 + return FALSE;
195 118 }
196 -
197 -/**
198 - * Break the access to a page.
199 - *
200 - * @wp-hook load-$page_slug
201 - */
202 -function _mw_adminimize_block_page_access() {
203 -
204 - $message = esc_attr__( 'Cheatin&#8217; uh? Sorry, you are not allowed to access this site.', 'adminimize' );
205 - $message = apply_filters( 'adminimize_nopage_access_message', $message );
206 - wp_die( $message );
207 -}