author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
permissions | -rwxr-xr-x |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
19 | 2 |
/** |
3 |
* Get latest version |
|
4 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
|
16 | 6 |
if ( ! function_exists( 'bws_include_init' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
function bws_include_init( $base, $bws_menu_source = 'plugins' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_added_menu, $bstwbsftwppdtplgns_active_plugins; |
19 | 9 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
10 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
11 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
$wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
$wp_plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : $wp_content_dir . '/plugins'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
19 | 16 |
if ( 'plugins' === $bws_menu_source ) { |
17 |
$bws_menu_dir = $wp_plugins_dir . '/' . dirname( $base ) . '/bws_menu/bws_menu.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
$bstwbsftwppdtplgns_active_plugins[ $base ] = get_plugin_data( $wp_plugins_dir . '/' . $base ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
$bws_menu_dir = $wp_content_dir . '/themes/' . $base . '/inc/bws_menu/bws_menu.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
$bws_menu_info = get_plugin_data( $bws_menu_dir ); |
16 | 24 |
|
19 | 25 |
$is_pro_bws_menu = ( strpos( $bws_menu_info['Version'], 'pro' ) !== false ); |
26 |
$bws_menu_version = str_replace( '-pro', '', $bws_menu_info['Version'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
if ( ! isset( $bstwbsftwppdtplgns_options ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
19 | 30 |
if ( ! get_site_option( 'bstwbsftwppdtplgns_options' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
add_site_option( 'bstwbsftwppdtplgns_options', array() ); |
19 | 32 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
$bstwbsftwppdtplgns_options = get_site_option( 'bstwbsftwppdtplgns_options' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
} else { |
19 | 35 |
if ( ! get_option( 'bstwbsftwppdtplgns_options' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
add_option( 'bstwbsftwppdtplgns_options', array() ); |
19 | 37 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
$bstwbsftwppdtplgns_options = get_option( 'bstwbsftwppdtplgns_options' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
if ( isset( $bstwbsftwppdtplgns_options['bws_menu_version'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
$bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
unset( $bstwbsftwppdtplgns_options['bws_menu_version'] ); |
19 | 45 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 47 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 49 |
} |
50 |
require_once dirname( __FILE__ ) . '/bws_menu.php'; |
|
51 |
require_once dirname( __FILE__ ) . '/bws_functions.php'; |
|
52 |
require_once dirname( __FILE__ ) . '/class-bws-settings.php'; |
|
53 |
} elseif ( ! $is_pro_bws_menu && ( ! isset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ) || $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] !== $bws_menu_version ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
$bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version; |
19 | 55 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 57 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 59 |
} |
60 |
require_once dirname( __FILE__ ) . '/bws_menu.php'; |
|
61 |
require_once dirname( __FILE__ ) . '/bws_functions.php'; |
|
62 |
require_once dirname( __FILE__ ) . '/class-bws-settings.php'; |
|
63 |
} elseif ( $is_pro_bws_menu && ( ! isset( $bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $base ] ) || $bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $base ] !== $bws_menu_version ) ) { |
|
16 | 64 |
$bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $base ] = $bws_menu_version; |
19 | 65 |
|
66 |
if ( isset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ) ) { |
|
16 | 67 |
unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ); |
19 | 68 |
} |
69 |
||
70 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
|
16 | 71 |
update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 72 |
} else { |
16 | 73 |
update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 74 |
} |
75 |
require_once dirname( __FILE__ ) . '/bws_menu.php'; |
|
76 |
require_once dirname( __FILE__ ) . '/bws_functions.php'; |
|
77 |
require_once dirname( __FILE__ ) . '/class-bws-settings.php'; |
|
78 |
} elseif ( ! isset( $bstwbsftwppdtplgns_added_menu ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
$all_plugins = get_plugins(); |
19 | 81 |
$all_themes = wp_get_themes(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
|
16 | 83 |
if ( ! empty( $bstwbsftwppdtplgns_options['bws_menu']['version_pro'] ) ) { |
84 |
foreach ( $bstwbsftwppdtplgns_options['bws_menu']['version_pro'] as $key => $value ) { |
|
85 |
if ( array_key_exists( $key, $all_plugins ) || array_key_exists( $key, $all_themes ) ) { |
|
19 | 86 |
if ( $bws_menu_version <= $value && ( is_plugin_active( $key ) || preg_match( '|' . $key . '$|', get_template_directory() ) ) ) { |
87 |
if ( ! isset( $product_with_newer_menu ) ) { |
|
16 | 88 |
$product_with_newer_menu = $key; |
19 | 89 |
} elseif ( $bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $product_with_newer_menu ] <= $bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $key ] ) { |
16 | 90 |
$product_with_newer_menu = $key; |
19 | 91 |
} |
16 | 92 |
} |
93 |
} else { |
|
94 |
unset( $bstwbsftwppdtplgns_options['bws_menu']['version_pro'][ $key ] ); |
|
19 | 95 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
16 | 96 |
update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 97 |
} else { |
16 | 98 |
update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 99 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
} |
16 | 101 |
} |
102 |
} |
|
103 |
||
104 |
if ( ! isset( $product_with_newer_menu ) ) { |
|
105 |
if ( $is_pro_bws_menu ) { |
|
106 |
$product_with_newer_menu = $base; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
} else { |
16 | 108 |
foreach ( $bstwbsftwppdtplgns_options['bws_menu']['version'] as $key => $value ) { |
109 |
if ( array_key_exists( $key, $all_plugins ) || array_key_exists( $key, $all_themes ) ) { |
|
19 | 110 |
if ( $bws_menu_version <= $value && ( is_plugin_active( $key ) || preg_match( '|' . $key . '$|', get_template_directory() ) ) ) { |
111 |
if ( ! isset( $product_with_newer_menu ) ) { |
|
16 | 112 |
$product_with_newer_menu = $key; |
19 | 113 |
} elseif ( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $product_with_newer_menu ] <= $bstwbsftwppdtplgns_options['bws_menu']['version'][ $key ] ) { |
16 | 114 |
$product_with_newer_menu = $key; |
19 | 115 |
} |
16 | 116 |
} |
117 |
} else { |
|
118 |
unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $key ] ); |
|
19 | 119 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
16 | 120 |
update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 121 |
} else { |
16 | 122 |
update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
19 | 123 |
} |
16 | 124 |
} |
125 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
127 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
128 |
|
19 | 129 |
if ( ! isset( $product_with_newer_menu ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
$product_with_newer_menu = $base; |
19 | 131 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
$folder_with_newer_menu = explode( '/', $product_with_newer_menu ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
if ( array_key_exists( $product_with_newer_menu, $all_plugins ) ) { |
19 | 136 |
$bws_menu_source = 'plugins'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
137 |
$bws_menu_new_dir = $wp_plugins_dir . '/' . $folder_with_newer_menu[0]; |
19 | 138 |
} elseif ( array_key_exists( $product_with_newer_menu, $all_themes ) ) { |
139 |
$bws_menu_source = 'themes'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
$bws_menu_new_dir = $wp_content_dir . '/themes/' . $folder_with_newer_menu[0] . '/inc'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
141 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
$bws_menu_new_dir = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
145 |
if ( file_exists( $bws_menu_new_dir . '/bws_menu/bws_functions.php' ) ) { |
19 | 146 |
require_once $bws_menu_new_dir . '/bws_menu/bws_functions.php'; |
147 |
require_once $bws_menu_new_dir . '/bws_menu/bws_menu.php'; |
|
148 |
require_once $bws_menu_new_dir . '/bws_menu/class-bws-settings.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
149 |
} else { |
19 | 150 |
require_once dirname( __FILE__ ) . '/bws_menu.php'; |
151 |
require_once dirname( __FILE__ ) . '/bws_functions.php'; |
|
152 |
require_once dirname( __FILE__ ) . '/class-bws-settings.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
153 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
154 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
155 |
$bstwbsftwppdtplgns_added_menu = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
} |
19 | 158 |
} |