$version, 'dir' => $includes_dir, ); } /** * Read bundle version from fifty-three-minute-tools-version.php. * * @param string $includes_dir Includes directory path. * @return string */ function fifty_three_minute_tools_read_bundle_version( $includes_dir ) { $version_file = $includes_dir . '/fifty-three-minute-tools-version.php'; if ( ! is_readable( $version_file ) ) { return '0.0.0'; } $version = include $version_file; return is_string( $version ) ? $version : '0.0.0'; } /** * Pick the registered bundle with the highest version. * * @return array{version:string, dir:string}|null */ function fifty_three_minute_tools_select_bundle() { global $fifty_three_minute_tools_registered_bundles; if ( empty( $fifty_three_minute_tools_registered_bundles ) ) { return null; } $winner = null; foreach ( $fifty_three_minute_tools_registered_bundles as $bundle ) { if ( empty( $bundle['dir'] ) || ! is_dir( $bundle['dir'] ) ) { continue; } $menu_file = $bundle['dir'] . '/fifty-three-minute-tools-menu.php'; $submenu_file = $bundle['dir'] . '/class-fifty-three-minute-tools-submenu.php'; if ( ! is_readable( $menu_file ) || ! is_readable( $submenu_file ) ) { continue; } if ( null === $winner || version_compare( $bundle['version'], $winner['version'], '>' ) ) { $winner = $bundle; } } return $winner; } /** * Load the winning bundle once. * * If an older Fifty_Three_Minute_Tools_Submenu was required first, still load * the winning menu file so its versioned core can boot beside that class. */ function fifty_three_minute_tools_load_bundle() { if ( defined( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_LOADED' ) ) { return; } $bundle = fifty_three_minute_tools_select_bundle(); if ( null === $bundle ) { return; } if ( class_exists( 'Fifty_Three_Minute_Tools_Submenu', false ) ) { $loaded_version = Fifty_Three_Minute_Tools_Submenu::SUITE_VERSION; if ( version_compare( (string) $loaded_version, $bundle['version'], '>=' ) ) { if ( ! defined( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_LOADED' ) ) { define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_LOADED', true ); define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_VERSION', $loaded_version ); } return; } $menu_file = $bundle['dir'] . '/fifty-three-minute-tools-menu.php'; if ( ! is_readable( $menu_file ) ) { add_action( 'admin_notices', 'fifty_three_minute_tools_outdated_direct_load_notice' ); return; } require_once $menu_file; define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_LOADED', true ); define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_VERSION', $bundle['version'] ); define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_DIR', $bundle['dir'] ); return; } require_once $bundle['dir'] . '/fifty-three-minute-tools-menu.php'; require_once $bundle['dir'] . '/class-fifty-three-minute-tools-submenu.php'; define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_LOADED', true ); define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_VERSION', $bundle['version'] ); define( 'FIFTY_THREE_MINUTE_TOOLS_BUNDLE_DIR', $bundle['dir'] ); } /** * Admin notice when an old plugin loaded the suite files before the loader could pick the newest copy. */ function fifty_three_minute_tools_outdated_direct_load_notice() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } echo '
'; echo esc_html__( '53 Minute Tools: an older copy of the shared admin code loaded first. Update all 53mp plugins so they register the suite via fifty-three-minute-tools-loader.php only (do not require the menu files directly).', 'fifty-three-minute-tools' ); echo '