function icl_reset_wpml($blog_id = false) { global $wpdb, $sitepress_settings; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'resetwpml') { check_admin_referer('resetwpml'); } if (empty($blog_id)) { $blog_id = isset($_POST['id']) ? $_POST['id'] : $wpdb->blogid; } if ($blog_id || !function_exists('is_multisite') || !is_multisite()) { if (function_exists('is_multisite') && is_multisite()) { switch_to_blog($blog_id); } wp_clear_scheduled_hook('update_wpml_config_index'); $icl_tables = array($wpdb->prefix . 'icl_languages', $wpdb->prefix . 'icl_languages_translations', $wpdb->prefix . 'icl_translations', $wpdb->prefix . 'icl_translation_status', $wpdb->prefix . 'icl_translate_job', $wpdb->prefix . 'icl_translate', $wpdb->prefix . 'icl_locale_map', $wpdb->prefix . 'icl_flags', $wpdb->prefix . 'icl_content_status', $wpdb->prefix . 'icl_core_status', $wpdb->prefix . 'icl_node', $wpdb->prefix . 'icl_strings', $wpdb->prefix . 'icl_string_packages', $wpdb->prefix . 'icl_translation_batches', $wpdb->prefix . 'icl_string_translations', $wpdb->prefix . 'icl_string_status', $wpdb->prefix . 'icl_string_positions', $wpdb->prefix . 'icl_message_status', $wpdb->prefix . 'icl_reminders'); foreach ($icl_tables as $icl_table) { $wpdb->query("DROP TABLE IF EXISTS " . $icl_table); } delete_option('icl_sitepress_settings'); delete_option('icl_sitepress_version'); delete_option('_icl_cache'); delete_option('_icl_admin_option_names'); delete_option('wp_icl_translators_cached'); delete_option('wpml32_icl_non_translators_cached'); delete_option('WPLANG'); delete_option('wpml-package-translation-db-updates-run'); delete_option('wpml-package-translation-refresh-required'); delete_option('wpml-package-translation-string-packages-table-updated'); delete_option('wpml-package-translation-string-table-updated'); delete_option('icl_translation_jobs_basket'); delete_option('widget_icl_lang_sel_widget'); delete_option('icl_admin_messages'); delete_option('icl_adl_settings'); delete_option('wpml_tp_com_log'); delete_option('wpml_config_index'); delete_option('wpml_config_index_updated'); delete_option('wpml_config_files_arr'); $sitepress_settings = null; wp_cache_init(); $wpmu_sitewide_plugins = (array) maybe_unserialize(get_site_option('active_sitewide_plugins')); if (!isset($wpmu_sitewide_plugins[ICL_PLUGIN_FOLDER . '/sitepress.php'])) { $file = plugin_basename(WP_PLUGIN_DIR . '/' . ICL_PLUGIN_FOLDER . '/sitepress.php'); remove_action('deactivate_' . $file, 'icl_sitepress_deactivate'); deactivate_plugins(basename(ICL_PLUGIN_PATH) . '/sitepress.php'); $ra = get_option('recently_activated'); $ra[basename(ICL_PLUGIN_PATH) . '/sitepress.php'] = time(); update_option('recently_activated', $ra); } else { update_option('_wpml_inactive', true); } if (isset($_REQUEST['submit'])) { wp_redirect(network_admin_url('admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/network.php&updated=true&action=resetwpml')); } if (function_exists('is_multisite') && is_multisite()) { restore_current_blog(); } } }
/** * Runs various database repair and cleanup actions on icl_translations * * @return int Number of rows in icl_translations that were fixed */ public function repair_broken_assignments() { $rows_fixed = $this->fix_missing_original(); $rows_fixed += $this->fix_wrong_source_language(); $rows_fixed += $this->fix_broken_type_assignments(); $this->clear_cache(); wp_cache_init(); return $rows_fixed; }
/** * Runs various database repair and cleanup actions on icl_translations. * * @return int Number of rows in icl_translations that were fixed */ public function run() { $rows_fixed = $this->fix_missing_original(); $rows_fixed += $this->fix_wrong_source_language(); $rows_fixed += $this->fix_broken_taxonomy_assignments(); $rows_fixed += $this->fix_broken_post_assignments(); $rows_fixed += $this->fix_broken_type_assignments(); icl_cache_clear(); wp_cache_init(); return $rows_fixed; }
function ob($output) { if ($this->cancel !== false) { return $output; } // PHP5 and objects disappearing before output buffers? wp_cache_init(); // Remember, $wp_object_cache was clobbered in wp-settings.php so we have to repeat this. $this->configure_groups(); // Do not batcache blank pages (usually they are HTTP redirects) $output = trim($output); if (empty($output)) { return; } // Construct and save the batcache $cache = array('output' => $output, 'time' => time(), 'timer' => $this->timer_stop(false, 3), 'status_header' => $this->status_header, 'version' => $this->url_version); if (function_exists('apache_response_headers')) { $cache['headers'] = apache_response_headers(); if (!empty($this->uncached_headers)) { foreach ($cache['headers'] as $header => $value) { if (in_array(strtolower($header), $this->uncached_headers)) { unset($cache['headers'][$header]); } } } } wp_cache_set($this->key, $cache, $this->group, $this->max_age + $this->seconds + 30); // Unlock regeneration wp_cache_delete("{$this->url_key}_genlock", $this->group); if ($this->cache_control) { header('Last-Modified: ' . date('r', $cache['time']), true); header("Cache-Control: max-age={$this->max_age}, must-revalidate", false); } if (!empty($this->headers)) { foreach ($this->headers as $k => $v) { if (is_array($v)) { header("{$v[0]}: {$v[1]}", false); } else { header("{$k}: {$v}", true); } } } // Add some debug info just before </head> if ($this->debug) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; if (false !== ($tag_position = strpos($output, '</head>'))) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; $output = substr($output, 0, $tag_position) . $tag . substr($output, $tag_position); } } // Pass output to next ob handler return $output; }
public static function execute( $params ) { global $wp_version; // Set progress Ai1wm_Status::info( __( 'Adding configuration to archive...', AI1WM_PLUGIN_NAME ) ); // Initialize empty WP cache wp_cache_init(); // Get options $options = wp_load_alloptions(); // Set config $config = new Ai1wm_Config; // Set Site URL if ( isset( $options['siteurl'] ) ) { $config->SiteURL = untrailingslashit( $options['siteurl'] ); } else { $config->SiteURL = site_url(); } // Set Home URL if ( isset( $options['home'] ) ) { $config->HomeURL = untrailingslashit( $options['home'] ); } else { $config->HomeURL = home_url(); } // Set Plugin Version $config->Plugin = (object) array( 'Version' => AI1WM_VERSION ); // Set WordPress Version and Content $config->WordPress = (object) array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR ); // Save package.json file $handle = fopen( ai1wm_package_path( $params ), 'w' ); fwrite( $handle, json_encode( $config ) ); fclose( $handle ); // Add package.json file $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) ); $archive->add_file( ai1wm_package_path( $params ), AI1WM_PACKAGE_NAME ); $archive->close(); // Set progress Ai1wm_Status::info( __( 'Done adding configuration to archive.', AI1WM_PLUGIN_NAME ) ); return $params; }
private function sync_custom_field($term_id_from, $term_id_to, $meta_key) { $wpdb = $this->sitepress->wpdb(); $sql = "SELECT meta_value FROM {$wpdb->termmeta} WHERE term_id=%d AND meta_key=%s"; $values_from = $wpdb->get_col($wpdb->prepare($sql, array($term_id_from, $meta_key))); $values_to = $wpdb->get_col($wpdb->prepare($sql, array($term_id_to, $meta_key))); $removed = array_diff($values_to, $values_from); foreach ($removed as $v) { $delete_prepared = $wpdb->prepare("DELETE FROM {$wpdb->termmeta}\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE term_id=%d\n\t\t\t\t\t\t\t\t\t\t\t\tAND meta_key=%s\n\t\t\t\t\t\t\t\t\t\t\t\tAND meta_value=%s", array($term_id_to, $meta_key, $v)); $wpdb->query($delete_prepared); } $added = array_diff($values_from, $values_to); foreach ($added as $v) { $insert_prepared = $wpdb->prepare("INSERT INTO {$wpdb->termmeta}(term_id, meta_key, meta_value)\n\t\t\t\t\t\t\t\t\t\t\t\tVALUES(%d, %s, %s)", array($term_id_to, $meta_key, $v)); $wpdb->query($insert_prepared); } wp_cache_init(); }
public function loadWPCruft() { define('ABSPATH', dirname(__DIR__)); define('WPINC', '/wp-includes'); $dirname = dirname(__DIR__) . '/wp-includes/'; require_once $dirname . 'cache.php'; require_once $dirname . 'class-wp-customize-control.php'; require_once $dirname . 'class-wp-error.php'; require_once $dirname . 'class-wp-theme.php'; require_once $dirname . 'class-wp-walker.php'; require_once $dirname . 'class-wp-widget-factory.php'; require_once $dirname . 'class-wp-widget.php'; require_once $dirname . 'formatting.php'; require_once $dirname . 'kses.php'; require_once $dirname . 'nav-menu-template.php'; require_once $dirname . 'script-loader.php'; require_once $dirname . 'theme.php'; // require_once($dirname . 'query.php'); require_once $dirname . 'widgets.php'; require_once $dirname . 'general-template.php'; require_once $dirname . 'wp-functions.php'; require_once $dirname . 'wp-plugin.php'; wp_cache_init(); $app = ResourceManager::getApp(); chdir($app['paths']['themepath']); $GLOBALS['config'] = $app['config']; $GLOBALS['paths'] = $app['paths']; $GLOBALS['request'] = $app['request']; $GLOBALS['wp_widget_factory'] = new \WP_Widget_Factory(); if (file_exists('functions.php')) { require_once 'functions.php'; } // Get the theme.yml, if it exists. if (is_readable($app['paths']['themepath'] . '/theme.yml')) { $yaml = new \Symfony\Component\Yaml\Parser(); $GLOBALS['theme_config'] = $yaml->parse(file_get_contents($app['paths']['themepath'] . '/theme.yml')); } }
public static function execute( $params ) { global $wpdb; // Skip database import if ( ! is_file( ai1wm_database_path( $params ) ) ) { return $params; } // Read blogs.json file $handle = fopen( ai1wm_blogs_path( $params ), 'r' ); if ( $handle === false ) { throw new Ai1wm_Import_Exception( 'Unable to read blogs.json file' ); } // Parse blogs.json file $blogs = fread( $handle, filesize( ai1wm_blogs_path( $params ) ) ); $blogs = json_decode( $blogs ); // Close handle fclose( $handle ); // Read package.json file $handle = fopen( ai1wm_package_path( $params ), 'r' ); if ( $handle === false ) { throw new Ai1wm_Import_Exception( 'Unable to read package.json file' ); } // Parse package.json file $config = fread( $handle, filesize( ai1wm_package_path( $params ) ) ); $config = json_decode( $config ); // Close handle fclose( $handle ); // Set progress Ai1wm_Status::info( __( 'Restoring database...', AI1WM_PLUGIN_NAME ) ); $old_values = array(); $new_values = array(); // Get Blog URLs foreach ( $blogs as $blog ) { // Get Upload Path if ( ! in_array( ai1wm_uploads_path( $blog->Old->Id ), $old_values ) ) { $old_values[] = ai1wm_uploads_path( $blog->Old->Id ); $new_values[] = ai1wm_uploads_path( $blog->New->Id ); } // Get escaped Upload Path if ( ! in_array( addslashes( addcslashes( ai1wm_uploads_path( $blog->Old->Id ), '\/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog->Old->Id ), '\/' ) ); $new_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog->New->Id ), '\/' ) ); } // Get Site URL if ( isset( $blog->Old->SiteURL ) && ( $blog->Old->SiteURL !== $blog->New->SiteURL ) ) { // Get domain $old_domain = parse_url( $blog->Old->SiteURL, PHP_URL_HOST ); $new_domain = parse_url( $blog->New->SiteURL, PHP_URL_HOST ); // Get scheme $new_scheme = parse_url( $blog->New->SiteURL, PHP_URL_SCHEME ); // Replace Site URL scheme foreach ( array( 'http', 'https' ) as $old_scheme ) { // Add plain Site URL if ( ! in_array( set_url_scheme( $blog->Old->SiteURL, $old_scheme ), $old_values ) ) { $old_values[] = set_url_scheme( $blog->Old->SiteURL, $old_scheme ); $new_values[] = set_url_scheme( $blog->New->SiteURL, $new_scheme ); } // Add encoded Site URL if ( ! in_array( urlencode( set_url_scheme( $blog->Old->SiteURL, $old_scheme ) ), $old_values ) ) { $old_values[] = urlencode( set_url_scheme( $blog->Old->SiteURL, $old_scheme ) ); $new_values[] = urlencode( set_url_scheme( $blog->New->SiteURL, $new_scheme ) ); } // Add escaped Site URL if ( ! in_array( addslashes( addcslashes( set_url_scheme( $blog->Old->SiteURL, $old_scheme ), '/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( set_url_scheme( $blog->Old->SiteURL, $old_scheme ), '/' ) ); $new_values[] = addslashes( addcslashes( set_url_scheme( $blog->New->SiteURL, $new_scheme ), '/' ) ); } } // Add email if ( ! in_array( sprintf( "@%s", $old_domain ), $old_values ) ) { $old_values[] = sprintf( "@%s", $old_domain ); $new_values[] = sprintf( "@%s", $new_domain ); } } // Get Home URL if ( isset( $blog->Old->HomeURL ) && ( $blog->Old->HomeURL !== $blog->New->HomeURL ) ) { // Get domain $old_domain = parse_url( $blog->Old->HomeURL, PHP_URL_HOST ); $new_domain = parse_url( $blog->New->HomeURL, PHP_URL_HOST ); // Get scheme $new_scheme = parse_url( $blog->New->HomeURL, PHP_URL_SCHEME ); // Replace Home URL scheme foreach ( array( 'http', 'https' ) as $old_scheme ) { // Add plain Home URL if ( ! in_array( set_url_scheme( $blog->Old->HomeURL, $old_scheme ), $old_values ) ) { $old_values[] = set_url_scheme( $blog->Old->HomeURL, $old_scheme ); $new_values[] = set_url_scheme( $blog->New->HomeURL, $new_scheme ); } // Add encoded Home URL if ( ! in_array( urlencode( set_url_scheme( $blog->Old->HomeURL, $old_scheme ) ), $old_values ) ) { $old_values[] = urlencode( set_url_scheme( $blog->Old->HomeURL, $old_scheme ) ); $new_values[] = urlencode( set_url_scheme( $blog->New->HomeURL, $new_scheme ) ); } // Add escaped Home URL if ( ! in_array( addslashes( addcslashes( set_url_scheme( $blog->Old->HomeURL, $old_scheme ), '/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( set_url_scheme( $blog->Old->HomeURL, $old_scheme ), '/' ) ); $new_values[] = addslashes( addcslashes( set_url_scheme( $blog->New->HomeURL, $new_scheme ), '/' ) ); } } // Add email if ( ! in_array( sprintf( "@%s", $old_domain ), $old_values ) ) { $old_values[] = sprintf( "@%s", $old_domain ); $new_values[] = sprintf( "@%s", $new_domain ); } } } // Get Site URL if ( isset( $config->SiteURL ) && ( $config->SiteURL !== site_url() ) ) { // Get www URL if ( stripos( $config->SiteURL, '//www.' ) !== false ) { $www = str_ireplace( '//www.', '//', $config->SiteURL ); } else { $www = str_ireplace( '//', '//www.', $config->SiteURL ); } // Replace Site URL foreach ( array( $config->SiteURL, $www ) as $url ) { // Get domain $old_domain = parse_url( $url, PHP_URL_HOST ); $new_domain = parse_url( site_url(), PHP_URL_HOST ); // Get path $old_path = parse_url( $url, PHP_URL_PATH ); $new_path = parse_url( site_url(), PHP_URL_PATH ); // Get scheme $new_scheme = parse_url( site_url(), PHP_URL_SCHEME ); // Add domain and path if ( ! in_array( sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ), $old_values ) ) { $old_values[] = sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ); $new_values[] = sprintf( "%s','%s", $new_domain, trailingslashit( $new_path ) ); } // Replace Site URL scheme foreach ( array( 'http', 'https' ) as $old_scheme ) { // Add plain Site URL if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) { $old_values[] = set_url_scheme( $url, $old_scheme ); $new_values[] = set_url_scheme( site_url(), $new_scheme ); } // Add encoded Site URL if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) { $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) ); $new_values[] = urlencode( set_url_scheme( site_url(), $new_scheme ) ); } // Add escaped Site URL if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ); $new_values[] = addslashes( addcslashes( set_url_scheme( site_url(), $new_scheme ), '/' ) ); } } // Add email if ( ! in_array( sprintf( "@%s", $old_domain ), $old_values ) ) { $old_values[] = sprintf( "@%s", $old_domain ); $new_values[] = sprintf( "@%s", $new_domain ); } } } // Get Home URL if ( isset( $config->HomeURL ) && ( $config->HomeURL !== home_url() ) ) { // Get www URL if ( stripos( $config->HomeURL, '//www.' ) !== false ) { $www = str_ireplace( '//www.', '//', $config->HomeURL ); } else { $www = str_ireplace( '//', '//www.', $config->HomeURL ); } // Replace Home URL foreach ( array( $config->HomeURL, $www ) as $url ) { // Get domain $old_domain = parse_url( $url, PHP_URL_HOST ); $new_domain = parse_url( home_url(), PHP_URL_HOST ); // Get path $old_path = parse_url( $url, PHP_URL_PATH ); $new_path = parse_url( home_url(), PHP_URL_PATH ); // Get scheme $new_scheme = parse_url( home_url(), PHP_URL_SCHEME ); // Add domain and path if ( ! in_array( sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ), $old_values ) ) { $old_values[] = sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ); $new_values[] = sprintf( "%s','%s", $new_domain, trailingslashit( $new_path ) ); } // Replace Home URL scheme foreach ( array( 'http', 'https' ) as $old_scheme ) { // Add plain Home URL if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) { $old_values[] = set_url_scheme( $url, $old_scheme ); $new_values[] = set_url_scheme( home_url(), $new_scheme ); } // Add encoded Home URL if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) { $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) ); $new_values[] = urlencode( set_url_scheme( home_url(), $new_scheme ) ); } // Add escaped Home URL if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ); $new_values[] = addslashes( addcslashes( set_url_scheme( home_url(), $new_scheme ), '/' ) ); } } // Add email if ( ! in_array( sprintf( "@%s", $old_domain ), $old_values ) ) { $old_values[] = sprintf( "@%s", $old_domain ); $new_values[] = sprintf( "@%s", $new_domain ); } } } // Get WordPress Content if ( isset( $config->WordPress->Content ) && ( $config->WordPress->Content !== WP_CONTENT_DIR ) ) { // Add plain WordPress Content if ( ! in_array( $config->WordPress->Content, $old_values ) ) { $old_values[] = $config->WordPress->Content; $new_values[] = WP_CONTENT_DIR; } // Add encoded WordPress Content if ( ! in_array( urlencode( $config->WordPress->Content ), $old_values ) ) { $old_values[] = urlencode( $config->WordPress->Content ); $new_values[] = urlencode( WP_CONTENT_DIR ); } // Add escaped WordPress Content if ( ! in_array( addslashes( addcslashes( $config->WordPress->Content, '\/' ) ), $old_values ) ) { $old_values[] = addslashes( addcslashes( $config->WordPress->Content, '\/' ) ); $new_values[] = addslashes( addcslashes( WP_CONTENT_DIR, '\/' ) ); } } // Get URL IP $url_ip = get_option( AI1WM_URL_IP ); // Get URL transport $url_transport = get_option( AI1WM_URL_TRANSPORT ); // Get secret key $secret_key = get_option( AI1WM_SECRET_KEY ); // Get HTTP user $auth_user = get_option( AI1WM_AUTH_USER ); // Get HTTP password $auth_password = get_option( AI1WM_AUTH_PASSWORD ); // Get active ServMask plugins $active_servmask_plugins = ai1wm_active_servmask_plugins(); $old_prefixes = array(); $new_prefixes = array(); // Set main table prefixes $old_prefixes[] = ai1wm_servmask_prefix( 'mainsite' ); $new_prefixes[] = ai1wm_table_prefix(); // Set site table prefixes foreach ( $blogs as $blog ) { if ( ai1wm_main_site( $blog->Old->Id ) === false ) { $old_prefixes[] = ai1wm_servmask_prefix( $blog->Old->Id ); $new_prefixes[] = ai1wm_table_prefix( $blog->New->Id ); } } // Set base table prefixes foreach ( $blogs as $blog ) { if ( ai1wm_main_site( $blog->Old->Id ) === true ) { $old_prefixes[] = ai1wm_servmask_prefix( 'basesite' ); $new_prefixes[] = ai1wm_table_prefix( $blog->New->Id ); } } // Set site table prefixes foreach ( $blogs as $blog ) { if ( ai1wm_main_site( $blog->Old->Id ) === true ) { $old_prefixes[] = ai1wm_servmask_prefix( $blog->Old->Id ); $new_prefixes[] = ai1wm_table_prefix( $blog->New->Id ); } } // Set table prefixes $old_prefixes[] = ai1wm_servmask_prefix(); $new_prefixes[] = ai1wm_table_prefix(); // Get database client if ( empty( $wpdb->use_mysqli ) ) { $client = new Ai1wm_Database_Mysql( $wpdb ); } else { $client = new Ai1wm_Database_Mysqli( $wpdb ); } // Set database options $client->set_old_table_prefixes( $old_prefixes ) ->set_new_table_prefixes( $new_prefixes ) ->set_old_replace_values( $old_values ) ->set_new_replace_values( $new_values ); // Flush database if ( ( $version = $config->Plugin->Version ) ) { if ( $version !== 'develop' && version_compare( $version, '4.10', '<' ) ) { $client->set_include_table_prefixes( array( ai1wm_table_prefix() ) ); $client->flush(); } } // Import database $client->import( ai1wm_database_path( $params ) ); // Initialize empty WP cache wp_cache_init(); // Activate plugins activate_plugins( $active_servmask_plugins, null, is_multisite() ); // Set the new URL IP update_option( AI1WM_URL_IP, $url_ip ); // Set the new URL transport update_option( AI1WM_URL_TRANSPORT, $url_transport ); // Set the new secret key value update_option( AI1WM_SECRET_KEY, $secret_key ); // Set the new HTTP user update_option( AI1WM_AUTH_USER, $auth_user ); // Set the new HTTP password update_option( AI1WM_AUTH_PASSWORD, $auth_password ); return $params; }
function min_switch_to_blog($blogID) { if ($blogID == $GLOBALS['blog_id']) { return true; } //switch_to_blog($blogID); //return true; global $wpdb; $wpdb->set_blog_id($blogID); $GLOBALS['blog_id'] = $blogID; wp_cache_init(); return true; }
function icl_reset_wpml($blog_id = false) { global $wpdb, $sitepress_settings; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'resetwpml') { check_admin_referer('resetwpml'); } if (empty($blog_id)) { $filtered_id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE); $filtered_id = $filtered_id ? $filtered_id : filter_input(INPUT_GET, 'id', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE); $blog_id = $filtered_id !== false ? $filtered_id : $wpdb->blogid; } if ($blog_id || !function_exists('is_multisite') || !is_multisite()) { if (function_exists('is_multisite') && is_multisite()) { switch_to_blog($blog_id); } do_action('wpml_reset_plugins_before'); wp_clear_scheduled_hook('update_wpml_config_index'); $icl_tables = array($wpdb->prefix . 'icl_languages', $wpdb->prefix . 'icl_languages_translations', $wpdb->prefix . 'icl_translations', $wpdb->prefix . 'icl_translation_status', $wpdb->prefix . 'icl_translate_job', $wpdb->prefix . 'icl_translate', $wpdb->prefix . 'icl_locale_map', $wpdb->prefix . 'icl_flags', $wpdb->prefix . 'icl_content_status', $wpdb->prefix . 'icl_core_status', $wpdb->prefix . 'icl_node', $wpdb->prefix . 'icl_strings', $wpdb->prefix . 'icl_string_packages', $wpdb->prefix . 'icl_translation_batches', $wpdb->prefix . 'icl_string_translations', $wpdb->prefix . 'icl_string_status', $wpdb->prefix . 'icl_string_positions', $wpdb->prefix . 'icl_message_status', $wpdb->prefix . 'icl_reminders'); foreach ($icl_tables as $icl_table) { $wpdb->query("DROP TABLE IF EXISTS " . $icl_table); } delete_option('icl_sitepress_settings'); delete_option('icl_sitepress_version'); delete_option('_icl_cache'); delete_option('_icl_admin_option_names'); delete_option('wp_icl_translators_cached'); delete_option('wpml32_icl_non_translators_cached'); delete_option('WPLANG'); delete_option('wpml-package-translation-db-updates-run'); delete_option('wpml-package-translation-refresh-required'); delete_option('wpml-package-translation-string-packages-table-updated'); delete_option('wpml-package-translation-string-table-updated'); delete_option('icl_translation_jobs_basket'); delete_option('widget_icl_lang_sel_widget'); delete_option('icl_admin_messages'); delete_option('icl_adl_settings'); delete_option('wpml_tp_com_log'); delete_option('wpml_config_index'); delete_option('wpml_config_index_updated'); delete_option('wpml_config_files_arr'); $sitepress_settings = null; wp_cache_init(); $wpml_cache_directory = new WPML_Cache_Directory(new WPML_WP_API()); $wpml_cache_directory->remove(); do_action('wpml_reset_plugins_after'); $wpmu_sitewide_plugins = (array) maybe_unserialize(get_site_option('active_sitewide_plugins')); if (!isset($wpmu_sitewide_plugins[ICL_PLUGIN_FOLDER . '/sitepress.php'])) { $file = plugin_basename(WP_PLUGIN_DIR . '/' . ICL_PLUGIN_FOLDER . '/sitepress.php'); remove_action('deactivate_' . $file, 'icl_sitepress_deactivate'); deactivate_plugins(basename(ICL_PLUGIN_PATH) . '/sitepress.php'); $ra = get_option('recently_activated'); $ra[basename(ICL_PLUGIN_PATH) . '/sitepress.php'] = time(); update_option('recently_activated', $ra); } else { update_option('_wpml_inactive', true); } if (function_exists('is_multisite') && is_multisite()) { restore_current_blog(); } } }
public function test_wp_cache_init() { $new_blank_cache_object = new WP_Object_Cache(); wp_cache_init(); global $wp_object_cache; // Differs from core tests because we'll have two different Redis sockets $this->assertEquals($wp_object_cache->cache, $new_blank_cache_object->cache); }
/** * @depends test_save_verified_ip__overflow */ public function test_password_reset__normal() { global $wpdb; $ip = '3.4.5.6'; $_SERVER['REMOTE_ADDR'] = $ip; $actual = self::$lss->password_reset($this->user, 'some 1 Needs!'); $this->assertNull($actual, 'password_reset() should return null.'); // Check the outcome. $actual = self::$lss->get_verified_ips($this->user->ID); $this->assertSame(array(10 => $ip), $actual, 'Expected IP was not found.'); $wpdb->query('ROLLBACK TO empty'); wp_cache_init(); }
function test_wp_cache_init() { $new_blank_cache_object = new WP_Object_Cache(); wp_cache_init(); global $wp_object_cache; $this->assertEquals($wp_object_cache, $new_blank_cache_object); }
/** * Reset the WordPress test expectations. */ function _reset_wp() { global $wp_test_expectations; $wp_test_expectations = array('options' => array(), 'categories' => array(), 'post_categories' => array(), 'get_posts' => array(), 'admin_pages' => array(), 'pages' => array(), 'posts' => array(), 'comments' => array(), 'actions' => array(), 'filters' => array(), 'post_meta' => array(), 'themes' => array(), 'plugin_domains' => array(), 'enqueued_scripts' => array(), 'enqueued_styles' => array(), 'all_tags' => array(), 'post_tags' => array(), 'sidebar_widgets' => array(), 'widget_controls' => array(), 'nonce' => array(), 'wp_widgets' => array(), 'current' => array('is_feed' => false, 'is_home' => false), 'plugin_data' => array(), 'theme' => array('posts' => array()), 'bloginfo' => array(), 'user_capabilities' => array(), 'children' => array(), 'current_user' => null, 'users' => array(), 'user_meta' => array(), 'image_downsize' => array(), 'sites' => array()); wp_cache_init(); }
function restore_current_blog() { global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; if (!$switched) { return false; } if (!is_array($switched_stack)) { return false; } $blog = array_pop($switched_stack); if ($blog_id == $blog) { do_action('switch_blog', $blog, $blog); /* If we still have items in the switched stack, consider ourselves still 'switched' */ $switched = is_array($switched_stack) && count($switched_stack) > 0; return true; } $wpdb->set_blog_id($blog); $prev_blog_id = $blog_id; $blog_id = $blog; $table_prefix = $wpdb->prefix; if (is_object($wp_roles)) { $wpdb->suppress_errors(); if (method_exists($wp_roles, '_init')) { $wp_roles->_init(); } elseif (method_exists($wp_roles, '__construct')) { $wp_roles->__construct(); } $wpdb->suppress_errors(false); } if (did_action('init')) { $current_user = wp_get_current_user(); if (is_object($current_user)) { $current_user->for_blog($blog_id); } } if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) { $global_groups = $wp_object_cache->global_groups; } else { $global_groups = false; } wp_cache_init(); if (function_exists('wp_cache_add_global_groups')) { if (is_array($global_groups)) { wp_cache_add_global_groups($global_groups); } else { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts')); } wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } do_action('switch_blog', $blog_id, $prev_blog_id); /* If we still have items in the switched stack, consider ourselves still 'switched' */ $switched = is_array($switched_stack) && count($switched_stack) > 0; return true; }
private function updated_active_languages() { global $sitepress; wp_cache_init(); icl_cache_clear(); $this->refresh_active_lang_cache(wpml_get_setting_filter(false, 'default_language')); wpml_reload_active_languages_setting(true); $active_langs = $sitepress->get_active_languages(true); $this->maybe_move_setup(3); if (count($active_langs) > 1) { icl_set_setting('dont_show_help_admin_notice', true); } }
function wp_cache_get_ob(&$buffer) { global $cache_enabled, $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir; global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression; global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages; global $wp_cache_404, $gzsize, $supercacheonly; global $blog_cache_dir, $wp_cache_request_uri, $wp_supercache_cache_list; global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time; global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled; if (isset($wp_cache_mfunc_enabled) == false) { $wp_cache_mfunc_enabled = 0; } $new_cache = true; $wp_cache_meta = ''; /* Mode paranoic, check for closing tags * we avoid caching incomplete files */ if ($buffer == '') { $new_cache = false; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2); wp_cache_add_to_buffer($buffer, "Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins."); } } if ($wp_cache_404 && false == apply_filters('wpsupercache_404', false)) { $new_cache = false; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("404 file not found not cached", 2); wp_cache_add_to_buffer($buffer, "Page not cached by WP Super Cache. 404."); } } if (!preg_match(apply_filters('wp_cache_eof_tags', '/(<\\/html>|<\\/rss>|<\\/feed>|<\\/urlset|<\\?xml)/i'), $buffer)) { $new_cache = false; if (false === strpos($_SERVER['REQUEST_URI'], 'robots.txt')) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("No closing html tag. Not caching.", 2); wp_cache_add_to_buffer($buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme."); } } else { wp_cache_debug("robots.txt detected. Not caching.", 2); } } if (!$new_cache) { return wp_cache_maybe_dynamic($buffer); } $duration = wp_cache_microtime_diff($wp_start_time, microtime()); $duration = sprintf("%0.3f", $duration); wp_cache_add_to_buffer($buffer, "Dynamic page generated in {$duration} seconds."); if (!wp_cache_writers_entry()) { wp_cache_add_to_buffer($buffer, "Page not cached by WP Super Cache. Could not get mutex lock."); wp_cache_debug("Could not get mutex lock. Not caching.", 1); return wp_cache_maybe_dynamic($buffer); } if ($wp_cache_not_logged_in && is_feed()) { wp_cache_debug("Feed detected. Writing legacy cache files.", 5); $wp_cache_not_logged_in = false; } $home_url = parse_url(trailingslashit(get_bloginfo('url'))); $dir = get_current_url_supercache_dir(); $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url['host']); if (!empty($_GET) || is_feed() || $super_cache_enabled == true && is_dir(substr($supercachedir, 0, -1) . '.disabled')) { wp_cache_debug("Supercache disabled: GET or feed detected or disabled by config.", 2); $super_cache_enabled = false; } $tmp_wpcache_filename = $cache_path . uniqid(mt_rand(), true) . '.tmp'; $supercacheonly = false; if ($super_cache_enabled) { if (wp_cache_get_cookies_values() == '' && empty($_GET)) { wp_cache_debug("Anonymous user detected. Only creating Supercache file.", 3); $supercacheonly = true; } } $cache_error = ''; if ($wp_cache_not_logged_in && wp_cache_get_cookies_values() != '') { $super_cache_enabled = false; $cache_enabled = false; $cache_error = 'Not caching requests by known users. (See Advanced Settings page)'; wp_cache_debug('Not caching for known user.', 5); } if ($wp_cache_object_cache) { // half on mode when using the object cache if (wp_cache_get_cookies_values() != '') { $cache_enabled = false; $cache_error = 'Known User and using object. Only anonymous users cached.'; } $super_cache_enabled = false; $supercacheonly = false; wp_cache_init(); // PHP5 destroys objects during shutdown } if (!$cache_enabled) { wp_cache_debug('Cache is not enabled. Sending buffer to browser.', 5); wp_cache_writers_exit(); wp_cache_add_to_buffer($buffer, "Page not cached by WP Super Cache. Check your settings page. {$cache_error}"); if ($wp_cache_mfunc_enabled == 1) { global $wp_super_cache_late_init; if (false == isset($wp_super_cache_late_init) || isset($wp_super_cache_late_init) && $wp_super_cache_late_init == 0) { wp_cache_add_to_buffer($buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.'); } } return wp_cache_maybe_dynamic($buffer); } if (@is_dir($dir) == false) { @wp_mkdir_p($dir); } $fr = $fr2 = $gz = false; // Open wp-cache cache file if (false == $wp_cache_object_cache) { if (!$supercacheonly) { $fr = @fopen($tmp_wpcache_filename, 'w'); if (!$fr) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $cache_path) . $cache_filename, 1); wp_cache_add_to_buffer($buffer, "File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $cache_path) . $cache_filename); wp_cache_writers_exit(); return wp_cache_maybe_dynamic($buffer); } } else { $user_info = wp_cache_get_cookies_values(); $do_cache = apply_filters('do_createsupercache', $user_info); if ($super_cache_enabled && ($user_info == '' || $do_cache === true)) { $cache_fname = $dir . supercache_filename(); $tmp_cache_filename = $dir . uniqid(mt_rand(), true) . '.tmp'; $fr2 = @fopen($tmp_cache_filename, 'w'); if (!$fr2) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $tmp_cache_filename), 1); wp_cache_add_to_buffer($buffer, "File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $tmp_cache_filename)); @fclose($fr); @unlink($tmp_wpcache_filename); wp_cache_writers_exit(); return wp_cache_maybe_dynamic($buffer); } elseif ((!isset($wp_cache_mfunc_enabled) || $wp_cache_mfunc_enabled == 0) && $cache_compression) { // don't want to store compressed files if using dynamic content $gz = @fopen($tmp_cache_filename . ".gz", 'w'); if (!$gz) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $tmp_cache_filename) . ".gz", 1); wp_cache_add_to_buffer($buffer, "File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $tmp_cache_filename) . ".gz"); @fclose($fr); @unlink($tmp_wpcache_filename); @fclose($fr2); @unlink($tmp_cache_filename); wp_cache_writers_exit(); return wp_cache_maybe_dynamic($buffer); } } } } } $added_cache = 0; $oc_key = get_oc_key(); $buffer = apply_filters('wpsupercache_buffer', $buffer); wp_cache_append_tag($buffer); /* * Dynamic content enabled: write the buffer to a file and then process any templates found using * the wpsc_cachedata filter. Buffer is then returned to the visitor. */ if ($wp_cache_mfunc_enabled == 1) { if (preg_match('/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $buffer)) { //Dynamic content wp_cache_debug("mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates."); wp_cache_add_to_buffer($buffer, "Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information."); } global $wp_super_cache_late_init; if (false == isset($wp_super_cache_late_init) || isset($wp_super_cache_late_init) && $wp_super_cache_late_init == 0) { wp_cache_add_to_buffer($buffer, 'Super Cache dynamic page detected but late init not set. See the readme.txt for further details.'); } if ($fr) { // legacy caching wp_cache_debug("Writing dynamic buffer to legacy file."); wp_cache_add_to_buffer($buffer, "Dynamic Legacy Super Cache"); fputs($fr, $buffer); } elseif (isset($fr2)) { // supercache active wp_cache_debug("Writing dynamic buffer to supercache file."); wp_cache_add_to_buffer($buffer, "Dynamic Super Cache"); fputs($fr2, $buffer); } elseif (true == $wp_cache_object_cache) { wp_cache_set($oc_key, $buffer, 'supercache', $cache_max_time); } $wp_cache_meta['dynamic'] = true; if (do_cacheaction('wpsc_cachedata_safety', 0) === 1) { $buffer = do_cacheaction('wpsc_cachedata', $buffer); } // dynamic content for display if ($cache_compression && $wp_cache_gzip_encoding) { wp_cache_debug("Gzipping dynamic buffer for display.", 5); wp_cache_add_to_buffer($buffer, "Compression = gzip"); $gzdata = gzencode($buffer, 6, FORCE_GZIP); $gzsize = function_exists('mb_strlen') ? mb_strlen($gzdata, '8bit') : strlen($gzdata); } } else { if ($gz || $wp_cache_gzip_encoding) { wp_cache_debug("Gzipping buffer.", 5); wp_cache_add_to_buffer($buffer, "Compression = gzip"); $gzdata = gzencode($buffer, 6, FORCE_GZIP); $gzsize = function_exists('mb_strlen') ? mb_strlen($gzdata, '8bit') : strlen($gzdata); $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; $wp_cache_meta['headers']['Vary'] = 'Vary: Accept-Encoding, Cookie'; // Return uncompressed data & store compressed for later use if ($fr) { wp_cache_debug("Writing gzipped buffer to wp-cache cache file.", 5); fputs($fr, $gzdata); } elseif ($cache_enabled && $wp_cache_object_cache) { wp_cache_set($oc_key . ".gz", $gzdata, 'supercache', $cache_max_time); $added_cache = 1; } } else { // no compression $wp_cache_meta['headers']['Vary'] = 'Vary: Cookie'; if ($cache_enabled && $wp_cache_object_cache) { wp_cache_set($oc_key, $buffer, 'supercache', $cache_max_time); $added_cache = 1; } elseif ($fr) { wp_cache_debug("Writing non-gzipped buffer to wp-cache cache file."); fputs($fr, $buffer); } } if ($fr2) { wp_cache_debug("Writing non-gzipped buffer to supercache file."); wp_cache_add_to_buffer($buffer, "super cache"); fputs($fr2, $buffer); } if (isset($gzdata) && $gz) { wp_cache_debug("Writing gzipped buffer to supercache file."); fwrite($gz, $gzdata); } } $new_cache = true; if (false == $wp_cache_object_cache) { if ($fr) { $supercacheonly = false; fclose($fr); if (filesize($tmp_wpcache_filename) == 0) { wp_cache_debug("Warning! The file {$tmp_wpcache_filename} was empty. Did not rename to {$blog_cache_dir}{$cache_filename}", 5); @unlink($tmp_wpcache_filename); } else { if (!@rename($tmp_wpcache_filename, $blog_cache_dir . $cache_filename)) { if (false == is_dir($blog_cache_dir)) { @wp_mkdir_p($blog_cache_dir); } @unlink($blog_cache_dir . $cache_filename); @rename($tmp_wpcache_filename, $blog_cache_dir . $cache_filename); } wp_cache_debug("Renamed temp wp-cache file to {$blog_cache_dir}{$cache_filename}", 5); $added_cache = 1; } } if ($fr2) { fclose($fr2); if ($wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url['path'] . supercache_filename() && !$wp_cache_is_home) { wp_cache_writers_exit(); wp_cache_debug("Warning! Not writing another page to front page cache.", 1); return $buffer; } elseif (filesize($tmp_cache_filename) == 0) { wp_cache_debug("Warning! The file {$tmp_cache_filename} was empty. Did not rename to {$cache_fname}", 5); @unlink($tmp_cache_filename); } else { if (!@rename($tmp_cache_filename, $cache_fname)) { @unlink($cache_fname); @rename($tmp_cache_filename, $cache_fname); } wp_cache_debug("Renamed temp supercache file to {$cache_fname}", 5); $added_cache = 1; } } if ($gz) { fclose($gz); if (filesize($tmp_cache_filename . '.gz') == 0) { wp_cache_debug("Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5); @unlink($tmp_cache_filename . '.gz'); } else { if (!@rename($tmp_cache_filename . '.gz', $cache_fname . '.gz')) { @unlink($cache_fname . '.gz'); @rename($tmp_cache_filename . '.gz', $cache_fname . '.gz'); } wp_cache_debug("Renamed temp supercache gz file to {$cache_fname}.gz", 5); $added_cache = 1; } } } if ($added_cache && isset($wp_supercache_cache_list) && $wp_supercache_cache_list) { update_option('wpsupercache_count', get_option('wpsupercache_count') + 1); $last_urls = (array) get_option('supercache_last_cached'); if (count($last_urls) >= 10) { $last_urls = array_slice($last_urls, 1, 9); } $last_urls[] = array('url' => preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', $_SERVER['REQUEST_URI']), 'date' => date('Y-m-d H:i:s')); update_option('supercache_last_cached', $last_urls); } wp_cache_writers_exit(); if (!headers_sent() && $wp_cache_gzip_encoding && $gzdata) { wp_cache_debug("Writing gzip content headers. Sending buffer to browser", 5); header('Content-Encoding: ' . $wp_cache_gzip_encoding); header('Vary: Accept-Encoding, Cookie'); header('Content-Length: ' . $gzsize); return $gzdata; } else { wp_cache_debug("Sending buffer to browser", 5); return $buffer; } }
function test_wp_cache_init() { $new_blank_cache_object = new WP_Object_Cache(); wp_cache_init(); global $wp_object_cache; if (wp_using_ext_object_cache()) { // External caches will contain property values that contain non-matching resource IDs $this->assertInstanceOf('WP_Object_Cache', $wp_object_cache); } else { $this->assertEquals($wp_object_cache, $new_blank_cache_object); } }
public static function resolve( $url ) { // Reset IP address and transport layer delete_option( AI1WM_URL_IP ); delete_option( AI1WM_URL_TRANSPORT ); // Set secret $secret_key = get_option( AI1WM_SECRET_KEY ); // Set scheme $scheme = parse_url( $url, PHP_URL_SCHEME ); // Set host name $host = parse_url( $url, PHP_URL_HOST ); // Set server IP address if ( ! empty( $_SERVER['SERVER_ADDR'] ) ) { $ip = $_SERVER['SERVER_ADDR']; } else if ( ! empty( $_SERVER['LOCAL_ADDR'] ) ) { $ip = $_SERVER['LOCAL_ADDR']; } else { $ip = '127.0.0.1'; } // Set domain IP address $domain = gethostbyname( $host ); // HTTP resolve foreach ( array( 'ai1wm', 'curl' ) as $transport ) { foreach ( array( $ip, $domain, $host ) as $ip ) { // Set transport Ai1wm_Http::$transports = array( $transport ); // HTTP request Ai1wm_Http::request( $url, $ip, array( 'secret_key' => $secret_key, 'url_ip' => $ip, 'url_transport' => $transport ) ); // HTTP response for ( $i = 0; $i < 5; $i++, sleep( 1 ) ) { // Initialize empty WP cache wp_cache_init(); // Is valid transport layer? if ( get_option( AI1WM_URL_IP ) && get_option( AI1WM_URL_TRANSPORT ) ) { return; } } } } // No connection throw new Ai1wm_Http_Exception( __( 'There was a problem while reaching your server.<br />' . 'Contact <a href="mailto:support@servmask.com">support@servmask.com</a> for assistance.', AI1WM_PLUGIN_NAME ) ); }
function restore_current_blog() { global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $current_user; if (!$switched) { return false; } $blog = array_pop($switched_stack); if ($blog_id == $blog) { return false; } $wpdb->set_blog_id($blog); $prev_blog_id = $blog_id; $blog_id = $blog; $table_prefix = $wpdb->prefix; if (is_object($wp_roles)) { $wpdb->suppress_errors(); if (method_exists($wp_roles, '_init')) { $wp_roles->_init(); } elseif (method_exists($wp_roles, '__construct')) { $wp_roles->__construct(); } $wpdb->suppress_errors(false); } if (is_object($current_user)) { $current_user->_init_caps(); } wp_cache_init(); if (function_exists('wp_cache_add_global_groups')) { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } do_action('switch_blog', $blog_id, $prev_blog_id); $switched = false; return true; }
function ob($output) { if ($this->cancel !== false) { return $output; } // PHP5 and objects disappearing before output buffers? wp_cache_init(); // Remember, $wp_object_cache was clobbered in wp-settings.php so we have to repeat this. $this->configure_groups(); // Do not batcache blank pages unless they are HTTP redirects $output = trim($output); if ($output === '' && (!$this->redirect_status || !$this->redirect_location)) { return; } // Do not cache 5xx responses if (isset($this->status_code) && intval($this->status_code / 100) == 5) { return $output; } $this->do_variants($this->vary); $this->generate_keys(); // Construct and save the batcache $this->cache = array('output' => $output, 'time' => time(), 'timer' => $this->timer_stop(false, 3), 'headers' => array(), 'status_header' => $this->status_header, 'redirect_status' => $this->redirect_status, 'redirect_location' => $this->redirect_location, 'version' => $this->url_version); foreach (headers_list() as $header) { list($k, $v) = array_map('trim', explode(':', $header, 2)); $this->cache['headers'][$k][] = $v; } if (!empty($this->cache['headers']) && !empty($this->uncached_headers)) { foreach ($this->uncached_headers as $header) { unset($this->cache['headers'][$header]); } } foreach ($this->cache['headers'] as $header => $values) { // Do not cache if cookies were set if (strtolower($header) === 'set-cookie') { return $output; } foreach ((array) $values as $value) { if (preg_match('/^Cache-Control:.*max-?age=(\\d+)/i', "{$header}: {$value}", $matches)) { $this->max_age = intval($matches[1]); } } } $this->cache['max_age'] = $this->max_age; wp_cache_set($this->key, $this->cache, $this->group, $this->max_age + $this->seconds + 30); // Unlock regeneration wp_cache_delete("{$this->url_key}_genlock", $this->group); if ($this->cache_control) { // Don't clobber Last-Modified header if already set, e.g. by WP::send_headers() if (!isset($this->cache['headers']['Last-Modified'])) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->cache['time']) . ' GMT', true); } if (!isset($this->cache['headers']['Cache-Control'])) { header("Cache-Control: max-age={$this->max_age}, must-revalidate", false); } } $this->do_headers($this->headers); // Add some debug info just before <head if ($this->debug) { $this->add_debug_just_cached(); } // Pass output to next ob handler batcache_stats('batcache', 'total_page_views'); return $this->cache['output']; }
function ob($output) { if ($this->cancel !== false) { return $output; } // PHP5 and objects disappearing before output buffers? wp_cache_init(); // Remember, $wp_object_cache was clobbered in wp-settings.php so we have to repeat this. $this->configure_groups(); // Do not batcache blank pages unless they are HTTP redirects $output = trim($output); if ($output === '' && (!$this->redirect_status || !$this->redirect_location)) { return; } // Construct and save the batcache $cache = array('output' => $output, 'time' => isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(), 'timer' => $this->timer_stop(false, 3), 'status_header' => $this->status_header, 'redirect_status' => $this->redirect_status, 'redirect_location' => $this->redirect_location, 'version' => $this->url_version); if (function_exists('headers_list')) { foreach (headers_list() as $header) { list($k, $v) = array_map('trim', explode(':', $header, 2)); $cache['headers'][$k] = $v; } } elseif (function_exists('apache_response_headers')) { $cache['headers'] = apache_response_headers(); } if ($cache['headers'] && !empty($this->uncached_headers)) { foreach ($cache['headers'] as $header => $value) { if (in_array(strtolower($header), $this->uncached_headers)) { unset($cache['headers'][$header]); } } } wp_cache_set($this->key, $cache, $this->group, $this->max_age + $this->seconds + 30); // Unlock regeneration wp_cache_delete("{$this->url_key}_genlock", $this->group); if ($this->cache_control) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cache['time']) . ' GMT', true); header("Cache-Control: max-age={$this->max_age}, must-revalidate", false); } if (!empty($this->headers)) { foreach ($this->headers as $k => $v) { if (is_array($v)) { header("{$v[0]}: {$v[1]}", false); } else { header("{$k}: {$v}", true); } } } // Add some debug info just before </head> if ($this->debug) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; if (false !== ($tag_position = strpos($output, '</head>'))) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; $output = substr($output, 0, $tag_position) . $tag . substr($output, $tag_position); } } if ($this->debug_header) { header(sprintf("X-batcache: Caching, generated in %ums, expires in %us (%us TTL)", $cache['timer'] * 1000, $this->max_age, $this->max_age), true); } // Pass output to next ob handler return $output; }
/** * Starts the WordPress object cache. * * If an object-cache.php file exists in the wp-content directory, * it uses that drop-in as an external object cache. * * @access private * @since 3.0.0 */ function wp_start_object_cache() { global $_wp_using_ext_object_cache; $first_init = false; if (!function_exists('wp_cache_init')) { if (file_exists(WP_CONTENT_DIR . '/object-cache.php')) { require_once WP_CONTENT_DIR . '/object-cache.php'; $_wp_using_ext_object_cache = true; } else { require_once ABSPATH . WPINC . '/cache.php'; $_wp_using_ext_object_cache = false; } $first_init = true; } else { if (!$_wp_using_ext_object_cache && file_exists(WP_CONTENT_DIR . '/object-cache.php')) { // Sometimes advanced-cache.php can load object-cache.php before it is loaded here. // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache // being set incorrectly. Double check if an external cache exists. $_wp_using_ext_object_cache = true; } } // If cache supports reset, reset instead of init if already initialized. // Reset signals to the cache that global IDs have changed and it may need to update keys // and cleanup caches. if (!$first_init && function_exists('wp_cache_reset')) { wp_cache_reset(); } else { wp_cache_init(); } if (function_exists('wp_cache_add_global_groups')) { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts')); wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } }
/** * Start the WordPress object cache. * * If an object-cache.php file exists in the wp-content directory, * it uses that drop-in as an external object cache. * * @since 3.0.0 * @access private * * @global int $blog_id Blog ID. */ function wp_start_object_cache() { global $blog_id; $first_init = false; if (!function_exists('wp_cache_init')) { if (file_exists(WP_CONTENT_DIR . '/object-cache.php')) { require_once WP_CONTENT_DIR . '/object-cache.php'; if (function_exists('wp_cache_init')) { wp_using_ext_object_cache(true); } } $first_init = true; } elseif (!wp_using_ext_object_cache() && file_exists(WP_CONTENT_DIR . '/object-cache.php')) { /* * Sometimes advanced-cache.php can load object-cache.php before * it is loaded here. This breaks the function_exists check above * and can result in `$_wp_using_ext_object_cache` being set * incorrectly. Double check if an external cache exists. */ wp_using_ext_object_cache(true); } if (!wp_using_ext_object_cache()) { require_once ABSPATH . WPINC . '/cache.php'; } /* * If cache supports reset, reset instead of init if already * initialized. Reset signals to the cache that global IDs * have changed and it may need to update keys and cleanup caches. */ if (!$first_init && function_exists('wp_cache_switch_to_blog')) { wp_cache_switch_to_blog($blog_id); } elseif (function_exists('wp_cache_init')) { wp_cache_init(); } if (function_exists('wp_cache_add_global_groups')) { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache')); wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } }
add_option('cforms' . $FORMCOUNT . '_header_html', get_option('cforms' . $no . '_header_html')); add_option('cforms' . $FORMCOUNT . '_formdata', get_option('cforms' . $no . '_formdata')); add_option('cforms' . $FORMCOUNT . '_space', get_option('cforms' . $no . '_space')); add_option('cforms' . $FORMCOUNT . '_noattachments', get_option('cforms' . $no . '_noattachments')); add_option('cforms' . $FORMCOUNT . '_subject', get_option('cforms' . $no . '_subject')); add_option('cforms' . $FORMCOUNT . '_submit_text', get_option('cforms' . $no . '_submit_text')); add_option('cforms' . $FORMCOUNT . '_success', get_option('cforms' . $no . '_success')); add_option('cforms' . $FORMCOUNT . '_failure', get_option('cforms' . $no . '_failure')); add_option('cforms' . $FORMCOUNT . '_limittxt', get_option('cforms' . $no . '_limittxt')); add_option('cforms' . $FORMCOUNT . '_working', get_option('cforms' . $no . '_working')); add_option('cforms' . $FORMCOUNT . '_popup', get_option('cforms' . $no . '_popup')); add_option('cforms' . $FORMCOUNT . '_showpos', get_option('cforms' . $no . '_showpos')); add_option('cforms' . $FORMCOUNT . '_redirect', get_option('cforms' . $no . '_redirect')); add_option('cforms' . $FORMCOUNT . '_redirect_page', get_option('cforms' . $no . '_redirect_page')); add_option('cforms' . $FORMCOUNT . '_action', get_option('cforms' . $no . '_action')); add_option('cforms' . $FORMCOUNT . '_action_page', get_option('cforms' . $no . '_action_page')); add_option('cforms' . $FORMCOUNT . '_upload_dir', get_option('cforms' . $no . '_upload_dir')); add_option('cforms' . $FORMCOUNT . '_upload_ext', get_option('cforms' . $no . '_upload_ext')); add_option('cforms' . $FORMCOUNT . '_upload_size', get_option('cforms' . $no . '_upload_size')); add_option('cforms' . $FORMCOUNT . '_tracking', get_option('cforms' . $no . '_tracking')); add_option('cforms' . $FORMCOUNT . '_tellafriend', get_option('cforms' . $no . '_tellafriend')); add_option('cforms' . $FORMCOUNT . '_dashboard', get_option('cforms' . $no . '_dashboard')); add_option('cforms' . $FORMCOUNT . '_maxentries', get_option('cforms' . $no . '_maxentries')); echo '<div id="message" class="updated fade"><p>' . __('The form has been duplicated, you\'re now working on the copy.', 'cforms') . '</p></div>'; //sorry, but WP2.2 doesn quickly enough flush the cache! if (function_exists(wp_cache_init)) { wp_cache_init(); wp_cache_flush(); } //set $no afterwards: need it to duplicate fields $no = $noDISP = $FORMCOUNT;
/** * Starts the WordPress object cache. * * If an object-cache.php file exists in the wp-content directory, * it uses that drop-in as an external object cache. * * @access private * @since 3.0.0 */ function wp_start_object_cache() { $first_init = false; if (!function_exists('wp_cache_init')) { global $_wp_using_ext_object_cache; if (file_exists(WP_CONTENT_DIR . '/object-cache.php')) { require_once WP_CONTENT_DIR . '/object-cache.php'; $_wp_using_ext_object_cache = true; } else { require_once ABSPATH . WPINC . '/cache.php'; $_wp_using_ext_object_cache = false; } $first_init = true; } // If cache supports reset, reset instead of init if already initialized. // Reset signals to the cache that global IDs have changed and it may need to update keys // and cleanup caches. if (!$first_init && function_exists('wp_cache_reset')) { wp_cache_reset(); } else { wp_cache_init(); } if (function_exists('wp_cache_add_global_groups')) { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts')); wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } }
/** * Restore the current blog, after calling switch_to_blog() * * @see switch_to_blog() * @since MU * * @return bool True on success, false if we're already on the current blog */ function restore_current_blog() { global $wpdb, $wp_roles; if (empty($GLOBALS['_wp_switched_stack'])) { return false; } $blog = array_pop($GLOBALS['_wp_switched_stack']); if ($GLOBALS['blog_id'] == $blog) { /** This filter is documented in wp-includes/ms-blogs.php */ do_action('switch_blog', $blog, $blog); // If we still have items in the switched stack, consider ourselves still 'switched' $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']); return true; } $wpdb->set_blog_id($blog); $prev_blog_id = $GLOBALS['blog_id']; $GLOBALS['blog_id'] = $blog; $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); if (function_exists('wp_cache_switch_to_blog')) { wp_cache_switch_to_blog($blog); } else { global $wp_object_cache; if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) { $global_groups = $wp_object_cache->global_groups; } else { $global_groups = false; } wp_cache_init(); if (function_exists('wp_cache_add_global_groups')) { if (is_array($global_groups)) { wp_cache_add_global_groups($global_groups); } else { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache')); } wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); } } if (did_action('init')) { $wp_roles->reinit(); $current_user = wp_get_current_user(); $current_user->for_blog($blog); } /** This filter is documented in wp-includes/ms-blogs.php */ do_action('switch_blog', $blog, $prev_blog_id); // If we still have items in the switched stack, consider ourselves still 'switched' $GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']); return true; }
function wp_cache_get_ob(&$buffer) { global $wpsc_settings; global $cache_enabled, $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir; global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression; global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages; global $wp_cache_404, $gzsize, $supercacheonly; global $blog_cache_dir, $wp_cache_request_uri, $wp_supercache_cache_list; global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time; global $wp_cache_is_home, $wp_cache_front_page_checks; $new_cache = true; $wp_cache_meta = ''; /* Mode paranoic, check for closing tags * we avoid caching incomplete files */ if ($buffer == '') { $new_cache = false; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2); $buffer .= "\n<!-- Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins. -->\n"; } } if ($wp_cache_404 && false == apply_filters('wpsupercache_404', false)) { $new_cache = false; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("404 file not found not cached", 2); $buffer .= "\n<!-- Page not cached by WP Super Cache. 404. -->\n"; } } if (!preg_match('/(<\\/html>|<\\/rss>|<\\/feed>|<\\/urlset)/i', $buffer)) { $new_cache = false; if (false === strpos($_SERVER['REQUEST_URI'], 'robots.txt')) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("No closing html tag. Not caching.", 2); $buffer .= "\n<!-- Page not cached by WP Super Cache. No closing HTML tag. Check your theme. -->\n"; } } else { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("robots.txt detected. Not caching.", 2); } } } if (!$new_cache) { return $buffer; } $duration = wp_cache_microtime_diff($wp_start_time, microtime()); $duration = sprintf("%0.3f", $duration); $buffer .= "\n<!-- Dynamic page generated in {$duration} seconds. -->\n"; if (!wp_cache_writers_entry()) { $buffer .= "\n<!-- Page not cached by WP Super Cache. Could not get mutex lock. -->\n"; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Could not get mutex lock. Not caching.", 1); } return $buffer; } if ($wp_cache_not_logged_in && is_feed()) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Feed detected. Writing legacy cache files.", 5); } $wp_cache_not_logged_in = false; } $home_url = parse_url(trailingslashit(get_bloginfo('url'))); $dir = get_current_url_supercache_dir(); $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url['host']); if (!empty($_GET) || is_feed() || $super_cache_enabled == true && is_dir(substr($supercachedir, 0, -1) . '.disabled')) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Supercache disabled: GET or feed detected or disabled by config.", 2); } $super_cache_enabled = false; } $tmp_wpcache_filename = $cache_path . uniqid(mt_rand(), true) . '.tmp'; $supercacheonly = false; if ($super_cache_enabled) { if (wp_cache_get_cookies_values() == '') { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Anonymous user detected. Only creating Supercache file.", 3); } $supercacheonly = true; } } $cache_error = ''; if ($wp_cache_not_logged_in && wp_cache_get_cookies_values() != '') { $super_cache_enabled = false; $cache_enabled = false; $cache_error = 'Not caching requests by known users. (See Advanced Settings page)'; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug('Not caching for known user.', 5); } } if ($wp_cache_object_cache) { // half on mode when using the object cache if (wp_cache_get_cookies_values() != '') { $cache_enabled = false; $cache_error = 'Known User and using object. Only anonymous users cached.'; } $super_cache_enabled = false; $supercacheonly = false; wp_cache_init(); // PHP5 destroys objects during shutdown } if (!$cache_enabled) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug('', 5); } wp_cache_writers_exit(); return $buffer . "\n<!-- Page not cached by WP Super Cache. Check your settings page. {$cache_error} -->"; } if (@is_dir($dir) == false) { @wp_mkdir_p($dir); } $fr = $fr2 = $gz = false; // Open wp-cache cache file if (!$supercacheonly) { if (false == $wp_cache_object_cache) { $fr = @fopen($tmp_wpcache_filename, 'w'); if (!$fr) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $cache_path) . $cache_filename, 1); } $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $cache_path) . $cache_filename . " -->\n"; wp_cache_writers_exit(); return $buffer; } } } else { $user_info = wp_cache_get_cookies_values(); $do_cache = apply_filters('do_createsupercache', $user_info); if ($super_cache_enabled && ($user_info == '' || $do_cache === true)) { $cache_fname = $dir . supercache_filename(); $tmp_cache_filename = $dir . uniqid(mt_rand(), true) . '.tmp'; $fr2 = @fopen($tmp_cache_filename, 'w'); if (!$fr2) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $tmp_cache_filename), 1); } $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $tmp_cache_filename) . " -->\n"; @fclose($fr); @unlink($tmp_wpcache_filename); wp_cache_writers_exit(); return $buffer; } elseif ($cache_compression) { $gz = @fopen($tmp_cache_filename . ".gz", 'w'); if (!$gz) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $tmp_cache_filename) . ".gz", 1); } $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace(ABSPATH, '', $tmp_cache_filename) . ".gz -->\n"; @fclose($fr); @unlink($tmp_wpcache_filename); @fclose($fr2); @unlink($tmp_cache_filename); wp_cache_writers_exit(); return $buffer; } } } } $added_cache = 0; $oc_key = get_oc_key(); if (preg_match('/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $buffer)) { //Dynamic content if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Dynamic content found in buffer.", 4); } $store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', "<!--mclude-->\n<?php include_once('" . ABSPATH . "\$1'); ?>\n<!--/mclude-->", $buffer); $store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', "<!--mfunc-->\n<?php \$1 ;?>\n<!--/mfunc-->", $store); $store = preg_replace('|<!--dynamic-cached-content-->(.*?)<!--(.*?)--><!--/dynamic-cached-content-->|is', "<!--dynamic-cached-content-->\n<?php\$2?>\n<!--/dynamic-cached-content-->", $store); $wp_cache_meta['dynamic'] = true; /* Clean function calls in tag */ $buffer = preg_replace('|<!--mclude (.*?)-->|is', '<!--mclude-->', $buffer); $buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); $buffer = preg_replace('|<!--dynamic-cached-content-->(.*?)<!--(.*?)--><!--/dynamic-cached-content-->|is', "<!--dynamic-cached-content-->\$1<!--/dynamic-cached-content-->", $buffer); $store = apply_filters('wpsupercache_buffer', $store); // Append WP Super Cache or Live page comment tag wp_cache_append_tag($buffer); wp_cache_append_tag($store); global $wp_super_cache_late_init; if (false == isset($wp_super_cache_late_init) || isset($wp_super_cache_late_init) && $wp_super_cache_late_init == 0) { $buffer .= '<!-- Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details. -->'; } if (false == $wp_cache_object_cache) { if ($fr) { // legacy caching fputs($fr, $store); } elseif (isset($fr2)) { // supercache active $php_fname = "{$dir}" . supercache_filename() . ".php"; $tmp_php_filename = $dir . uniqid(mt_rand(), true) . '.tmp'; $php_fd = @fopen($tmp_php_filename, 'w'); if (!$php_fd) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Error. Supercache could not write to " . str_replace(ABSPATH, '', $tmp_php_filename), 1); } $buffer .= "<!-- File not cached! Super Cache couldn't write to: " . str_replace(ABSPATH, '', $tmp_php_filename) . " -->\n"; @fclose($php_fd); @unlink($tmp_php_filename); wp_cache_writers_exit(); return $buffer; } fputs($php_fd, $store); } } else { wp_cache_set($oc_key, $store, 'supercache', $cache_max_time); } if ($cache_compression && $wp_cache_gzip_encoding) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Gzipping dynamic buffer.", 5); } $gzdata = gzencode($buffer . "<!-- Compression = gzip -->", 6, FORCE_GZIP); $gzsize = function_exists('mb_strlen') ? mb_strlen($gzdata, '8bit') : strlen($gzdata); } } else { $buffer = apply_filters('wpsupercache_buffer', $buffer); // Append WP Super Cache or Live page comment tag wp_cache_append_tag($buffer); if ($gz || $wp_cache_gzip_encoding) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Gzipping buffer.", 5); } $gzdata = gzencode($buffer . "<!-- Compression = gzip -->", 6, FORCE_GZIP); $gzsize = function_exists('mb_strlen') ? mb_strlen($gzdata, '8bit') : strlen($gzdata); } if ($wp_cache_gzip_encoding) { $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; $wp_cache_meta['headers']['Vary'] = 'Vary: Accept-Encoding, Cookie'; // Return uncompressed data & store compressed for later use if (false == $wp_cache_object_cache) { if ($fr) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing gzipped buffer to wp-cache cache file.", 5); } fputs($fr, $gzdata); } } elseif ($cache_enabled) { wp_cache_set($oc_key . ".gz", $gzdata, 'supercache', $cache_max_time); $added_cache = 1; } } else { // no compression $wp_cache_meta['headers']['Vary'] = 'Vary: Cookie'; if (false == $wp_cache_object_cache) { if ($fr) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing non-gzipped buffer to wp-cache cache file.", 5); } fputs($fr, $buffer); } } elseif ($cache_enabled) { wp_cache_set($oc_key, $buffer, 'supercache', $cache_max_time); $added_cache = 1; } } if (false == $wp_cache_object_cache) { if ($fr2) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing non-gzipped buffer to supercache file.", 5); } fputs($fr2, $buffer . '<!-- super cache -->'); } if ($gz) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing gzipped buffer to supercache file.", 5); } fwrite($gz, $gzdata); } } } $new_cache = true; if (false == $wp_cache_object_cache) { if ($fr) { $supercacheonly = false; fclose($fr); if (filesize($tmp_wpcache_filename) == 0) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! The file {$tmp_wpcache_filename} was empty. Did not rename to {$blog_cache_dir}{$cache_filename}", 5); } @unlink($tmp_wpcache_filename); } else { if (!rename($tmp_wpcache_filename, $blog_cache_dir . $cache_filename)) { unlink($blog_cache_dir . $cache_filename); rename($tmp_wpcache_filename, $blog_cache_dir . $cache_filename); } if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Renamed temp wp-cache file to {$blog_cache_dir}{$cache_filename}", 5); } $added_cache = 1; } } if ($fr2) { fclose($fr2); if ($wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url['path'] . supercache_filename() && !$wp_cache_is_home) { wp_cache_writers_exit(); if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! Not writing another page to front page cache.", 1); } return $buffer; } elseif (filesize($tmp_cache_filename) == 0) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! The file {$tmp_cache_filename} was empty. Did not rename to {$cache_fname}", 5); } @unlink($tmp_cache_filename); } else { if (!@rename($tmp_cache_filename, $cache_fname)) { @unlink($cache_fname); @rename($tmp_cache_filename, $cache_fname); } if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Renamed temp supercache file to {$cache_fname}", 5); } $added_cache = 1; } } if ($php_fd) { fclose($php_fd); if ($php_fname == $supercachedir . $home_url['path'] . supercache_filename() . '.php' && !$wp_cache_is_home) { wp_cache_writers_exit(); if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! Not writing another page to front page cache.", 1); } return $buffer; } elseif (filesize($tmp_php_filename) == 0) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! The file {$tmp_php_filename} was empty. Did not rename to {$php_fname}", 5); } @unlink($tmp_php_filename); } else { if (!@rename($tmp_php_filename, $php_fname)) { @unlink($php_fname); @rename($tmp_php_filename, $php_fname); } if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Renamed temp supercache file to {$php_fname}", 5); } $added_cache = 1; } } if ($gz) { fclose($gz); if (filesize($tmp_cache_filename . '.gz') == 0) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5); } @unlink($tmp_cache_filename . '.gz'); } else { if (!@rename($tmp_cache_filename . '.gz', $cache_fname . '.gz')) { @unlink($cache_fname . '.gz'); @rename($tmp_cache_filename . '.gz', $cache_fname . '.gz'); } if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Renamed temp supercache gz file to {$cache_fname}.gz", 5); } $added_cache = 1; } } } if ($added_cache && isset($wp_supercache_cache_list) && $wp_supercache_cache_list) { update_option('wpsupercache_count', get_option('wpsupercache_count') + 1); $last_urls = (array) get_option('supercache_last_cached'); if (count($last_urls) >= 10) { $last_urls = array_slice($last_urls, 1, 9); } $last_urls[] = array('url' => $_SERVER['REQUEST_URI'], 'date' => date('Y-m-d H:i:s')); update_option('supercache_last_cached', $last_urls); } wp_cache_writers_exit(); if (!headers_sent() && $wp_cache_gzip_encoding && $gzdata) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing gzip content headers. Sending buffer to browser", 5); } header('Content-Encoding: ' . $wp_cache_gzip_encoding); header('Vary: Accept-Encoding, Cookie'); header('Content-Length: ' . $gzsize); return $gzdata; } else { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Sending buffer to browser", 5); } return $buffer; } }
/** * Add's 'bp' to global group of network wide cachable objects * * @package BuddyPress Core */ function bp_core_add_global_group() { wp_cache_init(); wp_cache_add_global_groups(array('bp')); }
/** * Flush WP options cache * * @return void */ function ai1wm_cache_flush() { // Initialize WP cache wp_cache_init(); // Flush WP cache wp_cache_flush(); // Set WP cache wp_cache_set('alloptions', array(), 'options'); wp_cache_set('notoptions', array(), 'options'); // Delete WP cache wp_cache_delete('alloptions', 'options'); wp_cache_delete('notoptions', 'options'); }