public static function sniff() { foreach (self::$plugins as $plugin => $codename) { if (is_plugin_active($plugin)) { PluginsConfig::notify($codename); } } }
public function ensure_standard_settings() { global $wpdb, $memcached_servers; // Compute some values $blog_url = home_url(); $sitename = "unknown: " . __FILE__; if (preg_match("#^/nas/wp/www/[^/]+/([^/]+)/#", __FILE__, $match)) { $sitename = $match[1]; } echo "Ensuring: {$sitename} - {$blog_url}\n"; add_filter('http_request_timeout', function () { return 30; }, 1); // some sites take FOREVER $http = new WP_Http(); $url = 'https://api.wpengine.com/1.2/?method=site&account_name=' . PWP_NAME . '&wpe_apikey=' . WPE_APIKEY; $msg = $http->get($url); if (!$msg || is_a($msg, 'WP_Error') || !isset($msg['body'])) { echo "### FAIL: Couldn't load site configuration! (from " . __FILE__ . ")\n"; echo $url . "\n"; echo "Server Response:\n"; var_export($msg); return; } $config = json_decode($msg['body'], TRUE); if (!$config || !is_array($config)) { echo "### FAIL: Couldn't decode site configuration! (from " . __FILE__ . ")\n"; echo $url . "\n"; echo "Server Response:\n"; var_export($msg); return; } $is_pod = WPE_CLUSTER_TYPE == "pod"; $cluster_id = WPE_CLUSTER_ID; $is_bpod = defined('WPE_BPOD') && WPE_BPOD; $lbmaster = $is_pod ? "localhost" : "lbmaster-{$cluster_id}"; $dbmaster = $is_pod ? "localhost" : "dbmaster-{$cluster_id}"; $is_high_traffic = el($config, 'high_traffic', false) || $is_pod; $all_varnish = true; // not having this has bit us before, and having it for small sites is fine. // If site has hyper db in place, turn of w3tc dbcache $hyperdb = el($config, 'hyperdb'); if ($is_pod) { $hyperdb = false; } if ($hyperdb) { $dbcache_enabled = false; } else { $dbcache_enabled = true; } // List of user-agent patterns where we shouldn't use the page cache. $no_cache_user_agents = array("X-WPE-Rewrite"); // List of cookie-patterns where we shouldn't use the page cache. $no_cache_cookies = array("wptouch_switch_cookie"); $is_nfs = !$is_pod; $allow_file_locking = !$is_nfs; // Should we allow W3TC Page Cache? // If we're sending all traffic to Varnish, then no it's just overlap. $pgcache_enabled = !$all_varnish; // Should we allow W3TC Object Cache? // It takes a *lot* more memory in memcached, but can significantly speed up a site. if (isset($config['use_object_cache'])) { $allowed_objectcache = $config['use_object_cache']; } else { $allowed_objectcache = ($is_high_traffic || $is_pod) && !$is_bpod; } // used to be slow on a pod, but now with unix sockets for memcached it's fast! // Should we cache database queries for logged-in users? // Normally no, but for high-admin sites it does help and might be worth the risk. $cache_database_for_logged_in = $is_high_traffic || $allowed_objectcache || el($config, 'cache_database_for_logged_in', false); if ($is_pod) { $cache_database_for_logged_in = false; } // How long to allow files to be cached before they're considered "stale" and should // be reaped by a cron task. This is extra slow on NFS, so keep it short so we do // not have to sift through too many files. Maybe this should be in memcached! $file_cache_seconds = $is_nfs ? 600 : 60 * 60; $memcached_file_ttl = $is_pod ? 24 * 60 * 60 : 60 * 60 * 2; // if in memcached we can leave around far longer than on disk // Which server should be used for database-related or file-related memcached? $file_memcached_server = $is_pod ? "unix:///tmp/memcached.sock" : ($cluster_id == 1 ? "localhost:11211" : "{$dbmaster}:11211"); $db_memcached_server = $file_memcached_server; $obj_memcached_server = $file_memcached_server; // Should we use the memcached-based file cache or the disk-based? Disk-based means // flushing only affects one blog, but memory-based is much faster to process. $pgcache_in_memcached = $is_pod ? false : true; $pgcache_cache_queries = $pgcache_in_memcached; // NetDNA CDN zone for this site // $cdn_domain = $this->get_cdn_domain( el( $config, 'netdna', array( ) ), $blog_url ); // Ensure WPEngine standard account. echo "Ensuring the WPEngine account...\n"; $wpe_user_id = username_exists('wpengine'); // get existing ID $wpe_user = array('user_login' => 'wpengine', 'user_pass' => md5(mt_rand() . mt_rand() . mt_rand() . mt_rand() . time() . gethostname() . WPE_APIKEY), 'user_email' => '*****@*****.**', 'user_url' => 'http://wpengine.com', 'role' => 'administrator', 'user_nicename' => 'wpengine', 'description' => 'This is the "wpengine" admin user that our staff uses to gain access to your admin area to provide support and troubleshooting. It can only be accessed by a button in our secure log that auto generates a password and dumps that password after the staff member has logged in. We have taken extreme measures to ensure that our own user is not going to be misused to harm any of our clients sites.'); if (!$wpe_user_id) { $wpe_user_id = wp_insert_user($wpe_user); // creates; returns new user ID } else { $wpe_user['ID'] = $wpe_user_id; wp_update_user($wpe_user); } if ($wpe_user_id) { // could be we tried to create it but failed; then don't run this code // Set the request variable because some plugins keyed on it during profile_update hook. $_REQUEST['user_id'] = $wpe_user_id; // Impersonate as the wpengine user. if (function_exists('wp_set_current_user')) { wp_set_current_user($wpe_user_id); } } // Make Multisite wpengine admin a Super Admin if ($wpe_user_id && function_exists('is_multisite') && is_multisite()) { require_once ABSPATH . '/wp-admin/includes/ms.php'; grant_super_admin($wpe_user_id); } // Empty caches echo "Emptying all caches...\n"; $this->empty_all_caches(); // Deactivate plugins we don't support. echo "Deactivating plugins: hello, migration, cachers...\n"; $plugins = array("hello.php", "wpengine-migrate/plugin.php", "wp-file-cache/file-cache.php", "wp-super-cache/wp-cache.php", "hyper-cache/plugin.php", "db-cache-reloaded/db-module.php", "db-cache-reloaded/db-cache-reloaded.php", "no-revisions/norevisions.php", "wp-phpmyadmin/wp-phpmyadmin.php", "wpengine-common/plugin.php"); $plugins[] = "w3-total-cache/w3-total-cache.php"; if (false == el($config, 'profiler')) { $plugins[] = "wpe-profiler/wpe-profiler.php"; } // Check if the plugin is active. If so, deactivate it and turn on the other plugin $required_plugins = array(); // If plugin is activated, turn it off and turn on the other one instead. $disable_sitemap = false; // This plugin is not in the repo anymore, but that doesn't mean that people won't bring it over from another host. if (is_plugin_active('google-xml-sitemaps-with-multisite-support/sitemap.php')) { echo "Turning off 'google-xml-sitemaps-with-multisite-support/sitemap.php' "; $plugins[] = 'google-xml-sitemaps-with-multisite-support/sitemap.php'; $disable_sitemap = true; } if ($disable_sitemap) { echo " ... Turning on 'bwp-google-xml-sitemaps/bwp-simple-gxs.php'\n"; // BWP sitemap installer uses wp_rewrite, but when this function runs, it's not instantiated yet in wp-settings.php global $wp_rewrite; if (NULL == $wp_rewrite) { $wp_rewrite = new WP_Rewrite(); } // Remove sitemap files $remove_file = array('sitemap.xml', 'sitemap.xml.gz'); foreach ($remove_file as $file) { if (file_exists(ABSPATH . "/{$file}")) { echo "Remove {$file}\n"; unlink(ABSPATH . "/{$file}"); } } } deactivate_plugins($plugins); //look for plugins that WP Engine Api needs to know about include_once __DIR__ . '/class.plugins.php'; PluginsConfig::sniff(); // Activate all the plugins we require. If already activated this won't do anything. if (el($config, 'profiler')) { $required_plugins[] = "wpe-profiler/wpe-profiler.php"; } foreach ($required_plugins as $path) { echo "Activating {$path}...\n"; $result = activate_plugin($path); if ($result) { die("Error activating {$path}: {$result}\n"); } } // Display info about Runkit $have_runkit = extension_loaded('runkit'); $have_preamble = el($config, 'use_preamble'); echo "Have Runkit: " . ($have_runkit ? "yes" : "no") . "; Have preamble: " . ($have_preamble ? "yes" : "no") . "\n"; // If first-run, do some extra config if (wpe_param('first-run')) { $this->ensure_account_user(); } // Clean-up echo "Emptying all caches...\n"; $this->empty_all_caches(); echo "Done!\n"; }