?' . '' . esc_html( $text ) . ''; } /** * Loads the classes that install and remove the cache. */ function gorilla_cache_load_installer() { require_once plugin_dir_path( __FILE__ ) . 'includes/engine/load.php'; // The engine, once (the drop-in may have loaded it). require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-environment.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-site.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-registry.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-integrations.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-preload.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-settings.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-explain.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-installer.php'; } /** * Loads clearing and its WordPress hooks. */ function gorilla_cache_boot_cache() { gorilla_cache_load_installer(); require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-purge.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-hooks.php'; GorillaCache_Hooks::register(); if ( defined( 'WP_CLI' ) && WP_CLI && class_exists( 'WP_CLI' ) ) { require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-cli.php'; WP_CLI::add_command( 'gorilla-cache', 'GorillaCache_CLI' ); } } add_action( 'plugins_loaded', 'gorilla_cache_boot_cache' ); /** * Clears the whole page cache at the end of this request. For themes and plugins that change what every * page shows; do_action( 'gorilla_cache_clear_all' ) does the same without depending on this plugin. * * @param string $cause Short reason, shown on the status screen. */ function gorilla_cache_clear_all( $cause = '' ) { if ( class_exists( 'GorillaCache_Purge' ) ) { GorillaCache_Purge::all( '' !== $cause ? $cause : __( 'cleared by a theme or plugin', 'gorilla-cache' ) ); } } /** * Activation: turns caching on, or records why it stays off. */ function gorilla_cache_activate() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-activator.php'; GorillaCache_Activator::activate(); } /** * The code that runs during plugin deactivation. */ function gorilla_cache_deactivate() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-deactivator.php'; GorillaCache_Deactivator::deactivate(); } register_activation_hook( __FILE__, 'gorilla_cache_activate' ); register_deactivation_hook( __FILE__, 'gorilla_cache_deactivate' ); /** * The core plugin class that is used to define internationalization, * admin-specific hooks, and public-facing site hooks. */ require plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-core.php'; /** * Get the plugin admin page URL based on menu location. * * Helper function to generate correct admin URL regardless of menu location. * Returns the correct parent page URL (admin.php, options-general.php, or tools.php) * based on the GORILLA_CACHE_MENU_LOCATION constant. * * @since 1.0.0 * @param string $hash Optional. Tab to open, with or without the # ('status' or '#status'). * @return string The admin page URL. */ function gorilla_cache_get_admin_url( $hash = '' ) { $menu_location = defined( 'GORILLA_CACHE_MENU_LOCATION' ) ? GORILLA_CACHE_MENU_LOCATION : 'top-level'; switch ( $menu_location ) { case 'settings': $base_url = admin_url( 'options-general.php?page=gorilla-cache' ); break; case 'tools': $base_url = admin_url( 'tools.php?page=gorilla-cache' ); break; case 'woocommerce': case 'top-level': default: $base_url = admin_url( 'admin.php?page=gorilla-cache' ); break; } $hash = (string) $hash; if ( '' !== $hash && '#' !== $hash[0] ) { $hash = '#' . $hash; // Tab names work with or without the #; without it the page slug would change. } return $base_url . $hash; } /** * Begins execution of the plugin. */ function gorilla_cache_run() { $plugin = new GorillaCache_Core(); $plugin->run(); } /** * Initialize admin functionality. * * Loads admin classes only when in admin area to optimize memory usage. * Follows memory-optimized pattern by deferring admin class loading until needed. * * @since 1.0.0 */ function gorilla_cache_init_admin() { // Only load admin classes when in admin area. if ( ! is_admin() ) { return; } // Load admin class. require_once plugin_dir_path( __FILE__ ) . 'admin/class-gorillacache-admin.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-settings.php'; require_once plugin_dir_path( __FILE__ ) . 'includes/class-gorillacache-loader.php'; // Initialize admin. $plugin_admin = new GorillaCache_Admin(); $plugin_settings = new GorillaCache_Settings(); $loader = new GorillaCache_Loader(); // Register admin hooks. $loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' ); $loader->add_action( 'wp_ajax_gorilla_cache_status', $plugin_admin, 'ajax_status' ); $loader->add_filter( 'plugin_row_meta', $plugin_admin, 'plugin_row_status', 10, 2 ); $loader->add_action( 'admin_notices', $plugin_admin, 'problem_notice' ); $loader->add_action( 'admin_notices', $plugin_admin, 'move_notice' ); $loader->add_action( 'admin_init', $plugin_settings, 'register_settings' ); // Add settings link to plugin page. $plugin_basename = plugin_basename( __FILE__ ); $loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_settings_link' ); // Preserve tab hash in Settings API redirects. $loader->add_filter( 'wp_redirect', $plugin_settings, 'preserve_tab_hash_in_redirect', 10, 1 ); // Run the loader. $loader->run(); } // Start the plugin. gorilla_cache_run(); // Initialize admin (only loads when is_admin() is true). add_action( 'plugins_loaded', 'gorilla_cache_init_admin' );