function load() { if (function_exists('wp_get_current_user')) { $current_user = wp_get_current_user(); } // If already loaded notices from cache or remote and stored in local variable, don't do again. if ($this->notices and is_array($this->notices)) { $this->notices['read'] = get_user_meta($current_user->ID, 'wpe_notices_read', true); return $this->notices; } // Don't make this request when in staging. if (is_wpe_snapshot()) { return array(); } $this->go_get_em(); return $this->notices; }
/** * Creates an HTTP request to a remote host, but doesn't wait for the result. * @param method HTTP method, e.g. "GET" or "POST" * @param domain server to hit, e.g. "api.foobar.com" * @param port e.g. 80 * @param hostname string to use for the "Host" header on the target machine (null to copy $domain) * @param url e.g. "/v2/do_thing?apikey=1234" * @param wait_ms time to wait for the request to get going, since it will be destroyed when the connection ends * @return true on "success". (No errors detected.) */ public static function http_request_async($method, $domain, $port, $hostname, $uri, $extra_headers = array(), $wait_ms = 100) { //don't do anything is on staging if (is_wpe_snapshot()) { return false; } // Construct the URL so that we can invoke the request with cURL. $protocol = 'http'; if (443 == $port) { $protocol = 'https'; } $url = "{$protocol}://{$domain}:{$port}{$uri}"; // Callers might not specify hostname if it doesn't differ from $domain: if (!$hostname) { $hostname = $domain; } $headers = array("Host: {$hostname}"); foreach ($extra_headers as $k => $v) { $headers[] = "{$k}: {$v}"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($wait_ms > 0) { curl_setopt($ch, CURLOPT_TIMEOUT_MS, $wait_ms); } $result = curl_exec($ch); if ($wait_ms > 0) { // Don't care what the result is in this case... curl_close($ch); return true; } // else: if (false === $result) { curl_close($ch); return false; } // else: $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (400 <= $httpCode) { return false; } // else: return true; }
} ?> <?php if (!empty($message)) { ?> <div class="updated fade"><p><?php echo $message; ?> </p></div> <?php } ?> <?php if (!is_wpe_snapshot()) { ?> <h2 class="nav-tab-wrapper"> <a class="nav-tab <?php if ($active_tab == 'general') { echo 'nav-tab-active'; } ?> " href="<?php echo add_query_arg(array('tab' => 'general')); ?> ">General Settings</a> <a class="nav-tab <?php if ($active_tab == 'staging') { echo 'nav-tab-active'; }
/** * Is this a WP Engine snapshot * * This looks for and uses the global is_wpe_snapshot() function * This function is in the Fe\Wpe_Srcset_Force_Https namespace, which * is why it came have the same name as the global function. * * @return bool */ function is_wpe_snapshot() { return function_exists('\\is_wpe_snapshot') && !\is_wpe_snapshot(); }
$snapshot_state['is_ready'] = false; } $have_snapshot = (bool) $snapshot_state['have_snapshot']; }?> <div class="wrap"> <?php if ( ! empty( $error ) ) : ?> <div class="error"><p><?php echo $error; ?></p></div> <?php endif; ?> <?php if ( ! empty( $message ) ) : ?> <div class="updated fade"><p><?php echo $message; ?></p></div> <?php endif; ?> <?php if ( ! is_wpe_snapshot() ) { ?> <h2 class="nav-tab-wrapper"> <a class="nav-tab <?php if($active_tab=='general') { echo 'nav-tab-active'; } ?>" href="<?php echo esc_url(add_query_arg(array('tab'=>'general'))); ?>">General Settings</a> <a class="nav-tab <?php if($active_tab=='staging') { echo 'nav-tab-active'; } ?>" href="<?php echo esc_url(add_query_arg(array('tab'=>'staging'))); ?>">Staging</a> </h2> <div class="wpe-content-wrapper"> <?php if( $active_tab == 'general'): ?> <div class="span-30"> <p><b>You should <a href="http://eepurl.com/i3HPf" target="_blank">subscribe to our customer announcement list</a></b> to get updates on new features, system developments, and account and billing information. You can of course unsubscribe at any time, and we use it only for infrequent but important announcements.</p> <?php if($env_ip_pairs) { ?> <p><b>The DNS for your domain(s) should be set to the following IP(s)</b></p> <?php foreach ($env_ip_pairs as $domain => $ip): ?> <blockquote><code><?= $domain ?></code> - <code><?= $ip ?></code></blockquote> <?php endforeach; ?> <? } else if ( (defined('WPE_CLUSTER_TYPE') && 'hapod' === WPE_CLUSTER_TYPE) || (defined('WPE_VENDOR') && 'amazon' === WPE_VENDOR) ) { ?>
/** * Creates an HTTP request to a remote host, but doesn't wait for the result. * @param method HTTP method, e.g. "GET" or "POST" * @param domain server to hit, e.g. "api.foobar.com" * @param port e.g. 80 * @param hostname string to use for the "Host" header on the target machine (null to copy $domain) * @param url e.g. "/v2/do_thing?apikey=1234" * @param wait_ms time to wait for the request to get going, since it will be destroyed when the connection ends * @return true on "success". (No errors detected.) */ public static function http_request_async($method, $domain, $port, $hostname, $uri, $extra_headers = array(), $wait_ms = 100) { //don't do anything is on staging if (is_wpe_snapshot()) { return; } if (!$hostname) { $hostname = $domain; } if (443 == $port) { $domain = "ssl://" . $hostname; } $fp = fsockopen($domain, $port, $errno, $errstr, 1.0); if (!$fp) { //error_log( "Async Request Error: $errno, $errstr: $domain:$port" ); return false; } $headers = "Host: {$hostname}\r\nConnection: close\r\n"; if (is_array($extra_headers)) { foreach ($extra_headers as $k => $v) { $headers .= "{$k}: {$v}\r\n"; } } $send = "{$method} {$uri} HTTP/1.0\r\n{$headers}\r\n"; fwrite($fp, $send); fflush($fp); // make sure that request got sent if ($wait_ms > 0) { usleep($wait_ms * 1000); } else { // actually wait for the response $response = ""; while (!!($line = fgets($fp))) { $response .= $line . "\n"; } // get past the HTTP header usleep(100); fgets($fp); // more stuff fclose($fp); // all done } return true; }
function is_staging() { return function_exists('is_wpe_snapshot') && is_wpe_snapshot(); }