'Version'], false)['Version'], ); // Define the required MySQL version. define('REQUIRED_MYSQL_VERSION', '8.0'); define('REQUIRED_MARIADB_VERSION', '10.4'); // Load Composer dependencies when available. $maxi_autoload_path = MAXI_PLUGIN_DIR_PATH . 'vendor/autoload.php'; if (file_exists($maxi_autoload_path)) { require_once $maxi_autoload_path; } //====================================================================== // Translations //====================================================================== add_action('init', 'maxi_load_textdomain'); function maxi_load_textdomain() { // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- required to load bundled .mo translation files not hosted on WordPress.org load_plugin_textdomain( 'maxi-blocks', false, dirname(plugin_basename(__FILE__)) . '/languages', ); } function maxi_load_translations($mofile, $domain) { if ('maxi-blocks' === $domain) { $locale = apply_filters('plugin_locale', determine_locale(), $domain); $mofile_new = WP_PLUGIN_DIR . '/' . dirname(plugin_basename(__FILE__)) . '/languages/' . $domain . '-' . $locale . '.mo'; // Check if the new MO file exists if (file_exists($mofile_new)) { return $mofile_new; } } return $mofile; } add_filter('load_textdomain_mofile', 'maxi_load_translations', 10, 2); //====================================================================== // Plugin action links //====================================================================== function maxi_blocks_add_settings_link($links) { $settings_url = is_network_admin() ? network_admin_url('admin.php?page=maxi-blocks-dashboard') : admin_url('admin.php?page=maxi-blocks-dashboard&tab=maxi_blocks_settings'); $settings_link = '' . esc_html__('Settings', 'maxi-blocks') . ''; array_unshift($links, $settings_link); return $links; } add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'maxi_blocks_add_settings_link', ); //====================================================================== // Database version check //====================================================================== // Hook for checking the database version in the admin area add_action('admin_init', 'maxi_check_database_version'); /** * Check the required database version during admin initialization */ function maxi_check_database_version() { global $wpdb; // Check if the database is MariaDB $isMariaDB = strpos(strtolower($wpdb->db_server_info()), 'maria') !== false; $requiredVersion = $isMariaDB ? REQUIRED_MARIADB_VERSION : REQUIRED_MYSQL_VERSION; // Compare the current database version with the required version if (version_compare($wpdb->db_version(), $requiredVersion, '<')) { $plugin_file = plugin_basename(__FILE__); add_action( "after_plugin_row_{$plugin_file}", 'maxi_show_database_version_notice', 10, 3, ); add_action( 'admin_enqueue_scripts', 'maxi_blocks_enqueue_notice_scripts', ); } } /** * Enqueue JavaScript for the admin notice */ function maxi_blocks_enqueue_notice_scripts() { wp_enqueue_script( 'maxi-blocks-admin-notice', plugins_url('/core/admin/notices.js', __FILE__), [], MAXI_PLUGIN_VERSION, true, ); // Localize script with REST API URL and nonce wp_localize_script('maxi-blocks-admin-notice', 'maxiBlocks', [ 'rest_url' => rest_url('maxi-blocks/v1/dismiss-notice'), 'nonce' => wp_create_nonce('wp_rest'), ]); } /** * Show an admin notice under the plugin's name if the required database version is not met */ function maxi_show_database_version_notice() { if (get_option('maxi_blocks_db_notice_dismissed') === 'yes') { return; } global $wpdb; $isMariaDB = strpos(strtolower($wpdb->db_server_info()), 'maria') !== false; $requiredVersion = $isMariaDB ? REQUIRED_MARIADB_VERSION : REQUIRED_MYSQL_VERSION; $databaseType = $isMariaDB ? 'MariaDB' : 'MySQL'; $message = sprintf( /* translators: %1$s: database type, %2$s: required version, %3$s: link URL */ esc_html__( 'Highly recommend to update to %1$s %2$s+ for enhanced security, better performance, and full feature compatibility.', 'maxi-blocks', ), esc_html($databaseType), esc_html($requiredVersion), ) . ' ' . esc_html__('Learn more', 'maxi-blocks') . ''; echo ''; echo ''; echo '

'; echo wp_kses_post($message); echo '

'; } /** * Register REST API endpoint for dismissing the notice */ function maxi_blocks_register_rest_route() { register_rest_route('maxi-blocks/v1', '/dismiss-notice', [ 'methods' => 'POST', 'callback' => 'maxi_blocks_dismiss_notice', 'permission_callback' => function () { return current_user_can('manage_options'); }, ]); } add_action('rest_api_init', 'maxi_blocks_register_rest_route'); /** * Dismiss the notice and update the option in the database */ function maxi_blocks_dismiss_notice() { update_option('maxi_blocks_db_notice_dismissed', 'yes'); return new WP_REST_Response(null, 204); } function maxi_blocks_after_update($upgrader_object, $options) { // Check if required keys exist in the options array if ( !isset($options['action']) || !isset($options['type']) || !isset($options['plugins']) ) { return; } // Check if it's an update of plugins if ($options['action'] == 'update' && $options['type'] == 'plugin') { // Check if YOUR plugin is in the list of updated plugins foreach ($options['plugins'] as $plugin) { if ($plugin == plugin_basename(__FILE__)) { // Reset the dismissal option update_option('maxi_blocks_db_notice_dismissed', 'no'); break; } } } } add_action('upgrader_process_complete', 'maxi_blocks_after_update', 10, 2); //====================================================================== // Init //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/admin/maxi-allowed-html-tags.php'; // remove noopener noreferrer from gutenberg links function maxi_links_control($rel, $link) { return false; } add_filter('wp_targeted_link_rel', 'maxi_links_control', 10, 2); add_action('wp_ajax_maxi_get_option', 'maxi_get_option', 9, 1); //====================================================================== // MaxiBlocks Core //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-core.php'; if (class_exists('MaxiBlocks_Core')) { MaxiBlocks_Core::register(); } //====================================================================== // MaxiBlocks Custom Scripts //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-custom-scripts.php'; if (class_exists('MaxiBlocks_Custom_Scripts')) { MaxiBlocks_Custom_Scripts::register(); } //====================================================================== // MaxiBlocks DB //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-db.php'; if (class_exists('MaxiBlocks_DB')) { MaxiBlocks_DB::register(); } //====================================================================== // MaxiBlocks Blocks //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-blocks.php'; if (class_exists('MaxiBlocks_Blocks')) { MaxiBlocks_Blocks::register(); } //====================================================================== // MaxiBlocks Styles //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-styles.php'; if (class_exists('MaxiBlocks_Styles')) { MaxiBlocks_Styles::register(); } //====================================================================== // MaxiBlocks Style Cards //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-style-cards.php'; if (class_exists('MaxiBlocks_StyleCards')) { MaxiBlocks_StyleCards::register(); } //====================================================================== // MaxiBlocks Custom Fonts //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-custom-fonts.php'; //====================================================================== // MaxiBlocks Image Crop //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-image-crop.php'; if (class_exists('MaxiBlocks_ImageCrop')) { MaxiBlocks_ImageCrop::register(); } //====================================================================== // MaxiBlocks API //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-api.php'; MaxiBlocks_API::register(); if (class_exists('MaxiBlocks_API')) { add_action('plugins_loaded', ['MaxiBlocks_API', 'register']); } //====================================================================== // MaxiBlocks Page Template //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-page-template.php'; if (class_exists('MaxiBlocks_PageTemplate')) { add_action('plugins_loaded', ['MaxiBlocks_PageTemplate', 'register']); } //====================================================================== // MaxiBlocks Dashboard //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/admin/class-maxi-dashboard.php'; if (class_exists('MaxiBlocks_Dashboard')) { MaxiBlocks_Dashboard::register(); } //====================================================================== // MaxiBlocks Dynamic Content //====================================================================== require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-dynamic-content.php'; if (class_exists('MaxiBlocks_DynamicContent')) { MaxiBlocks_DynamicContent::register(); } //====================================================================== // MaxiBlocks Go //====================================================================== if (get_template() === 'maxiblocks-go') { $theme_version = wp_get_theme('maxiblocks-go')->get('Version'); if (version_compare($theme_version, '1.2.1', '>=')) { require_once MAXI_PLUGIN_DIR_PATH . 'core/maxiblocks-go/maxiblocks-go.php'; } } //====================================================================== // MaxiBlocks Onboarding //====================================================================== // Check if we're in a test environment using .env file $is_test_environment = false; $env_file = dirname(__FILE__) . '/.env'; if (file_exists($env_file)) { $env_config = @parse_ini_file($env_file); if ($env_config !== false) { $is_test_environment = isset($env_config['GITHUB_ENV_TEST']) && in_array( $env_config['GITHUB_ENV_TEST'], [1, '1', true, 'true'], true, ); } } if (!$is_test_environment) { require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-quick-start-register.php'; if (class_exists('MaxiBlocks_QuickStart_Register')) { MaxiBlocks_QuickStart_Register::register(); // Register activation hook register_activation_hook(__FILE__, [ 'MaxiBlocks_QuickStart_Register', 'activate', ]); // Handle redirect after activation add_action('admin_init', function () { if (get_transient('maxi_blocks_activation_redirect')) { delete_transient('maxi_blocks_activation_redirect'); if (!isset($_GET['activate-multi'])) { wp_safe_redirect( admin_url('admin.php?page=maxi-blocks-quick-start'), ); exit(); } } }); } }