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