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