3 ) { // Maximum class file path depth in this project is 3. $class_path = array_slice( $class_path, 0, 3 ); } $file_path = W3TC_LIB_DIR . DIRECTORY_SEPARATOR . implode( '/', $class_path ) . '.php'; if ( file_exists( $file_path ) ) { require $file_path; } return; } if ( substr( $class, 0, 6 ) == 'W3TCL\\' ) { $base = W3TC_LIB_DIR . DIRECTORY_SEPARATOR; $class = substr( $class, 6 ); // PSR loader. $file = $base . strtr( $class, '\\_', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) . '.php'; if ( file_exists( $file ) ) { require_once $file; } } } spl_autoload_register( 'w3tc_class_autoload' ); /** * W3 Total Cache plugins API */ /** * Returns config. * * !!! NOTICE !!! * 3rd party developers, please do not modify the plugin's configuration without * notifying the user beforehand. As an alternative, throw a notification to the * user like: "Configure W3 Total Cache for me" and allow the user to dismiss * the notification. * !!! NOTICE !!! */ function w3tc_config() { /* * Some plugins make incorrect decisions based on configuration * and force to disable modules working otherwise or * adds notices on each wp-admin page without ability to remove it. * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like. */ if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) { return new W3_Config(); } $config = \W3TC\Dispatcher::config(); return $config; } /** * Purges/Flushes everything. * * @param array $extras Extras. */ function w3tc_flush_all( $extras = null ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->flush_all( $extras ); } /** * Purges/Flushes post page. * * @param int $post_id Post id. * @param boolean $force Force flag (optional). * @param array $extras Extras. */ function w3tc_flush_post( $post_id, $force = false, $extras = null ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->flush_post( $post_id, $force, $extras ); } /** * Purges/Flushes all posts. * * @param array $extras Extras. */ function w3tc_flush_posts( $extras = null ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->flush_posts( $extras ); } /** * Purges/Flushes url. * * @param string $url URL. * @param array $extras Extras. */ function w3tc_flush_url( $url, $extras = null ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->flush_url( $url, $extras ); } /** * Purges/Flushes separate cache group. * * @param string $group Group. * @param array $extras Extras. */ function w3tc_flush_group( $group, $extras = null ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->flush_group( $group, $extras ); } /** * Deprecated. Shortcut for page cache flush. * * @return bool */ function w3tc_pgcache_flush() { return w3tc_flush_posts(); } /** * Deprecated. Shortcut for page post cache flush. * * @param int $post_id Post id. * @param boolean $force Force flag (optional). * * @return bool */ function w3tc_pgcache_flush_post( $post_id, $force = false ) { return w3tc_flush_post( $post_id, $force ); } /** * Deprecated. Shortcut for page post cache flush by url. * * @param int $url URL. * @return bool */ function w3tc_pgcache_flush_url( $url ) { return w3tc_flush_url( $url ); } /** * Deprecated. Shortcut for refreshing the media query string. * * @return null */ function w3tc_browsercache_flush() { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); return $o->browsercache_flush(); } /** * Deprecated. Shortcut for database cache flush. */ function w3tc_dbcache_flush() { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->dbcache_flush(); } /** * Deprecated. Shortcut for minify cache flush. */ function w3tc_minify_flush() { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->minifycache_flush(); } /** * Deprecated. Shortcut for objectcache cache flush. */ function w3tc_objectcache_flush() { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); $o->objectcache_flush(); } /** * Deprecated. Shortcut for CDN purge files. * * @param array $files Array consisting of uri paths (i.e wp-content/uploads/image.pnp). * @return mixed */ function w3tc_cdn_purge_files( $files ) { $o = \W3TC\Dispatcher::component( 'CacheFlush' ); return $o->cdn_purge_files( $files ); } /** * Deprecated. Prints script tag for scripts group. * * @param string $location Location. */ function w3tc_minify_script_group( $location ) { $o = \W3TC\Dispatcher::component( 'Minify_Plugin' ); $o->printed_scripts[] = $location; $r = $o->get_script_group( $location ); echo esc_html( $r['body'] ); } /** * Deprecated. Prints style tag for styles group. * * @param string $location Location. */ function w3tc_minify_style_group( $location ) { $o = \W3TC\Dispatcher::component( 'Minify_Plugin' ); $o->printed_styles[] = $location; $r = $o->get_style_group( $location ); echo esc_html( $r['body'] ); } /** * Deprecated. Prints style tag for custom styles. * * @param string|array $files Files. */ function w3tc_minify_style_custom( $files ) { $o = \W3TC\Dispatcher::component( 'Minify_Plugin' ); $r = $o->get_style_custom( $files ); echo esc_html( $r['body'] ); } /** * Deprecated. Use Util_Theme::get_themes() to get a list themenames to use with user agent groups. * * @param string $group_name Group name. * @param string $theme The themename default is default theme. For childtheme it should be parentthemename/childthemename. * @param string $redirect Redirect. * @param array $agents Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported. * @param bool $enabled Enabled. */ function w3tc_save_user_agent_group( $group_name, $theme = 'default', $redirect = '', $agents = array(), $enabled = false ) { $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' ); $o->save_group( $group_name, $theme, $redirect, $agents, $enabled ); } /** * Deprecated. * * @param string $group Group. */ function w3tc_delete_user_agent_group( $group ) { $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' ); $o->delete_group( $group ); } /** * Deprecated. * * @param string $group Group. * @return mixed */ function w3tc_get_user_agent_group( $group ) { $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' ); return $o->get_group_values( $group ); } /** * Deprecated. Use Util_Theme::get_themes() to get a list themenames to use with referrer groups. * * @param string $group_name Group name. * @param string $theme The themename default is default theme. For childtheme it should be parentthemename/childthemename. * @param string $redirect Redirect. * @param array $referrers Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported. * @param bool $enabled Enabled. */ function w3tc_save_referrer_group( $group_name, $theme = 'default', $redirect = '', $referrers = array(), $enabled = false ) { $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' ); $o->save_group( $group_name, $theme, $redirect, $referrers, $enabled ); } /** * Deprecated. * * @param string $group Group. */ function w3tc_delete_referrer_group( $group ) { $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' ); $o->delete_group( $group ); } /** * Deprecated. * * @param string $group Group. * @return mixed */ function w3tc_get_referrer_group( $group ) { $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' ); return $o->get_group_values( $group ); } /** * Deprecated. Retained for 3rd parties that used it. see w3tc_config(). * * Some plugins make incorrect decisions based on configuration * and force to disable modules working otherwise or * adds notices on each wp-admin page without ability to remove it. * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like. */ if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) { /** * Class: W3_Config */ class W3_Config { // phpcs:ignore /** * Constructor. * * @param bool $master Master. * @param int $blog_id Blog id. */ public function __construct( $master = false, $blog_id = null ) { } /** * Get string. * * @param string $key Key. * @param string $default Default. * @param boolean $trim Trim. * @return string */ public function get_string( $key, $default = '', $trim = true ) { return ''; } /** * Get integer. * * @param string $key Key. * @param int $default Default. */ public function get_integer( $key, $default = 0 ) { return 0; } /** * Get boolean. * * @param string $key Key. * @param bool $default Default. * @return bool */ public function get_boolean( $key, $default = false ) { return false; } } } else { /** * Class: W3_Config. */ class W3_Config extends \W3TC\Config { // phpcs:ignore /** * Constructor. * * @param bool $master Master. * @param int $blog_id Blog id. */ public function __construct( $master = false, $blog_id = null ) { if ( $master ) { $blog_id = 0; } return parent::__construct( $blog_id ); } } } /** * Class: W3_ConfigWriter. * * Deprecated. Retained for 3rd parties that use it. see w3tc_config(). */ class W3_ConfigWriter { // phpcs:ignore /** * Constructor. * * @param int $p1 P1. * @param int $p2 P2. */ public function __construct( $p1 = 0, $p2 = 0 ) { } /** * Set. * * @param int $p1 P1. * @param int $p2 P2. */ public function set( $p1 = 0, $p2 = 0 ) { } /** * Save. * * @param int $p1 P1. * @param int $p2 P2. */ public function save( $p1 = 0, $p2 = 0 ) { } /** * Refresh W3TC. */ public function refresh_w3tc() { } } /** * Deprecated. Retained for 3rd parties that use it. see w3tc_config(). * * @param string $class Class name. */ function w3_instance( $class ) { $legacy_class_name = null; switch ( $class ) { case 'W3_Config': if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) { return new W3_Config(); } $legacy_class_name = 'Config'; break; case 'W3_ObjectCacheBridge': $legacy_class_name = 'ObjectCache_WpObjectCache'; break; case 'W3_PgCache': $legacy_class_name = 'PgCache_ContentGrabber'; break; case 'W3_Redirect': $legacy_class_name = 'Mobile_Redirect'; break; default: return null; } return \W3TC\Dispatcher::component( $legacy_class_name ); } /** * Print a localized string. * * @param string $key Key name. * @param mixed $default_value Default value. */ function w3tc_e( $key, $default_value ) { $content = w3tc_er( $key, $default_value ); echo wp_kses( $content, \W3TC\Util_Ui::get_allowed_html_for_wp_kses_from_content( $content ) ); } /** * Get a localized string. * * @param string $key Key name. * @param mixed $default_value Default value. */ function w3tc_er( $key, $default_value ) { $v = get_site_option( 'w3tc_generic_widgetservices' ); try { $v = json_decode( $v, true ); if ( ! isset( $v['content'] ) ) { return $default_value; } $v = $v['content']; } catch ( \Exception $e ) { return $default_value; } global $w3tc_locale; if ( null === $w3tc_locale ) { if ( function_exists( 'get_user_locale' ) ) { $w3tc_locale = get_user_locale(); } else { $w3tc_locale = ''; } } if ( isset( $v[ "ui_strings.$w3tc_locale" ][ $key ] ) ) { return $v[ "ui_strings.$w3tc_locale" ][ $key ]; } if ( isset( $v['ui_strings'][ $key ] ) ) { return $v['ui_strings'][ $key ]; } return $default_value; } $w3tc_actions = array(); /** * An add_action alternative used by W3TC when WP core is not available. * * @param string $hook Hook/action name. * @param Callable $callback Callback function. */ function w3tc_add_action( $hook, $callback ) { global $w3tc_actions; if ( ! isset( $w3tc_actions[ $hook ] ) ) { $w3tc_actions[ $hook ] = array(); } $w3tc_actions[ $hook ][] = $callback; } /** * A do_action alternative used by W3TC when WP core is not available. * * @param string $hook Hook/action name. */ function w3tc_do_action( $hook ) { global $w3tc_actions; if ( ! empty( $w3tc_actions[ $hook ] ) ) { foreach ( $w3tc_actions[ $hook ] as $callback ) { call_user_func_array( $callback, array() ); } } } /** * An apply_filters alternative used by W3TC when WP core is not available. * * @param string $hook Hook/filter name. * @param mixed $value Value. */ function w3tc_apply_filters( $hook, $value ) { $args = func_get_args(); array_shift( $args ); global $w3tc_actions; if ( ! empty( $w3tc_actions[ $hook ] ) ) { foreach ( $w3tc_actions[ $hook ] as $callback ) { $value = call_user_func_array( $callback, $args ); $args[0] = $value; } } return $value; }