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
adminimize / inc-setup / helping_hands.php

helping_hands.php in Adminimize 1.9.1, at inc-setup/helping_hands.php

119 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Adminimize
4 * @subpackage Helping_Functions
5 * @author Frank Bültge <[email protected]
6 * @since 2016-01-22
7 */
8 if ( ! function_exists( 'add_action' ) ) {
9 die( "Hi there! I'm just a part of plugin, not much I can do when called directly." );
10 }
11
12 /**
13 * Recursive search in array.
14 *
15 * @param $needle
16 * @param $haystack
17 *
18 * @return bool
19 */
20 function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
21
22 if ( '' === $haystack ) {
23 return FALSE;
24 }
25
26 if ( ! $haystack ) {
27 return FALSE;
28 }
29
30 foreach ( $haystack as $stalk ) {
31 if ( $needle === $stalk
32 || ( is_array( $stalk )
33 && _mw_adminimize_recursive_in_array( $needle, $stalk )
34 )
35 ) {
36 return TRUE;
37 }
38 }
39
40 return FALSE;
41 }
42
43 /**
44 * Check if array contains all array values from another array.
45 *
46 * @param $array1
47 * @param $array2
48 *
49 * @return bool
50 */
51 function _mw_adminimize_in_arrays( $array1, $array2 ) {
52
53 return (bool) count( array_intersect( $array1, $array2 ) );
54 }
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
61 /**
62 * Force plugins to load scripts with SSL if page is SSL.
63 */
64 function _mw_adminimize_enqueueScriptsFix() {
65
66 if ( is_admin() ) {
67 return;
68 }
69
70 $https_values = array( NULL, 'off' );
71 if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
72 return;
73 }
74
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 }
79 }
80 }
81
82 /**
83 * Force plugins to load styles with SSL if page is SSL.
84 */
85 function _mw_adminimize_enqueueStylesFix() {
86
87 if ( is_admin() ) {
88 return;
89 }
90
91 $https_values = array( NULL, 'off' );
92 if ( ! isset( $_SERVER[ 'HTTPS' ] ) || in_array( $_SERVER[ 'HTTPS' ], $https_values ) ) {
93 return;
94 }
95
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 }
100 }
101 }
102
103 /**
104 * Check the role with the current user data.
105 *
106 * @param string $role
107 *
108 * @return bool
109 */
110 function _mw_adminimize_current_user_has_role( $role ) {
111
112 $user = wp_get_current_user();
113 if ( in_array( $role, (array) $user->roles ) ) {
114 return TRUE;
115 }
116
117 return FALSE;
118 }
119