/**
 * Metabox for assigning properties of a network
 *
 * @since 1.7.0
 *
 * @param WP_Network $network Results of get_blog_details()
 */
function wpmn_edit_network_details_metabox($network = null)
{
    // Domain
    $domain = !empty($network->domain) ? Requests_IDNAEncoder::encode($network->domain) : '';
    // Path
    $path = !empty($network->path) ? $network->path : '/';
    ?>

	<table class="edit-network form-table">
		<tr class="form-field form-required">
			<th scope="row">
				<label for="domain"><?php 
    esc_html_e('Domain', 'wp-multi-network');
    ?>
</label>
			</th>
			<td>
				<label for="domain">
					<span class="scheme"><?php 
    echo wp_get_scheme();
    ?>
</span>
					<input type="text" name="domain" id="domain" class="regular-text" value="<?php 
    echo esc_attr($domain);
    ?>
">
				</label>
			</td>
		</tr>
		<tr class="form-field form-required">
			<th scope="row">
				<label for="path"><?php 
    esc_html_e('Path', 'wp-multi-network');
    ?>
</label>
			</th>
			<td>
				<input type="text" name="path" id="path" class="regular-text" value="<?php 
    echo esc_attr($path);
    ?>
">
				<p class="description"><?php 
    esc_html_e('Use "/" if you are unsure.', 'wp-multi-network');
    ?>
</p>
			</td>
		</tr>
	</table>

<?php 
}
Exemple #2
0
 /**
  * Set the default values
  *
  * @param string $url URL to request
  * @param array $headers Extra headers to send with the request
  * @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
  * @param string $type HTTP request type
  * @param array $options Options for the request
  * @return array $options
  */
 protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options)
 {
     if (!preg_match('/^http(s)?:\\/\\//i', $url, $matches)) {
         throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
     }
     if (empty($options['hooks'])) {
         $options['hooks'] = new Requests_Hooks();
     }
     if (is_array($options['auth'])) {
         $options['auth'] = new Requests_Auth_Basic($options['auth']);
     }
     if ($options['auth'] !== false) {
         $options['auth']->register($options['hooks']);
     }
     if (!empty($options['proxy'])) {
         $options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
     }
     if ($options['proxy'] !== false) {
         $options['proxy']->register($options['hooks']);
     }
     if (is_array($options['cookies'])) {
         $options['cookies'] = new Requests_Cookie_Jar($options['cookies']);
     } elseif (empty($options['cookies'])) {
         $options['cookies'] = new Requests_Cookie_Jar();
     }
     if ($options['cookies'] !== false) {
         $options['cookies']->register($options['hooks']);
     }
     if ($options['idn'] !== false) {
         $iri = new Requests_IRI($url);
         $iri->host = Requests_IDNAEncoder::encode($iri->ihost);
         $url = $iri->uri;
     }
 }
 /**
  * Main interface for HTTP requests
  *
  * This method initiates a request and sends it via a transport before
  * parsing.
  *
  * The `$options` parameter takes an associative array with the following
  * options:
  *
  * - `timeout`: How long should we wait for a response?
  *    (integer, seconds, default: 10)
  * - `useragent`: Useragent to send to the server
  *    (string, default: php-requests/$version)
  * - `follow_redirects`: Should we follow 3xx redirects?
  *    (boolean, default: true)
  * - `redirects`: How many times should we redirect before erroring?
  *    (integer, default: 10)
  * - `blocking`: Should we block processing on this request?
  *    (boolean, default: true)
  * - `filename`: File to stream the body to instead.
  *    (string|boolean, default: false)
  * - `auth`: Authentication handler or array of user/password details to use
  *    for Basic authentication
  *    (Requests_Auth|array|boolean, default: false)
  * - `idn`: Enable IDN parsing
  *    (boolean, default: true)
  * - `transport`: Custom transport. Either a class name, or a
  *    transport object. Defaults to the first working transport from
  *    {@see getTransport()}
  *    (string|Requests_Transport, default: {@see getTransport()})
  *
  * @throws Requests_Exception On invalid URLs (`nonhttp`)
  *
  * @param string $url     URL to request
  * @param array  $headers Extra headers to send with the request
  * @param array  $data    Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
  * @param string $type    HTTP request type (use Requests constants)
  * @param array  $options Options for the request (see description for more information)
  *
  * @return Requests_Response
  */
 public static function request($url, $headers = [], $data = [], $type = self::GET, $options = [])
 {
     if (!preg_match('/^http(s)?:\\/\\//i', $url)) {
         throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
     }
     $defaults = ['timeout' => 10, 'useragent' => 'php-requests/' . self::VERSION, 'redirected' => 0, 'redirects' => 10, 'follow_redirects' => true, 'blocking' => true, 'type' => $type, 'filename' => false, 'auth' => false, 'idn' => true, 'hooks' => null, 'transport' => null];
     $options = array_merge($defaults, $options);
     if (empty($options['hooks'])) {
         $options['hooks'] = new Requests_Hooks();
     }
     // Special case for simple basic auth
     if (is_array($options['auth'])) {
         $options['auth'] = new Requests_Auth_Basic($options['auth']);
     }
     if ($options['auth'] !== false) {
         $options['auth']->register($options['hooks']);
     }
     $options['hooks']->dispatch('requests.before_request', [&$url, &$headers, &$data, &$type, &$options]);
     if ($options['idn'] !== false) {
         $iri = new Requests_IRI($url);
         $iri->host = Requests_IDNAEncoder::encode($iri->ihost);
         $url = $iri->uri;
     }
     if (!empty($options['transport'])) {
         $transport = $options['transport'];
         if (is_string($options['transport'])) {
             $transport = new $transport();
         }
     } else {
         $transport = self::get_transport();
     }
     $response = $transport->request($url, $headers, $data, $options);
     $options['hooks']->dispatch('requests.before_parse', [&$response, $url, $headers, $data, $type, $options]);
     return self::parse_response($response, $url, $headers, $data, $options);
 }
 /**
  * Handle the request to update a network
  *
  * @since 2.0.0
  */
 private function handle_update_network()
 {
     // Unslash posted data for sanitization
     $posted = wp_unslash($_POST);
     // Cast
     $network_id = !empty($posted['network_id']) ? (int) $posted['network_id'] : 0;
     // Bail if invalid network
     if (!get_network($network_id)) {
         wp_die(esc_html__('Invalid network id.', 'wp-multi-network'));
     }
     // Title
     $network_title = isset($posted['title']) ? sanitize_text_field($posted['title']) : '';
     // Domain
     $network_domain = isset($posted['domain']) ? str_replace(' ', '', strtolower(sanitize_text_field($posted['domain']))) : '';
     // Punycode support
     $network_domain = Requests_IDNAEncoder::encode($network_domain);
     // Path
     $network_path = isset($posted['path']) ? str_replace(' ', '', strtolower(sanitize_text_field($posted['path']))) : '';
     // Bail if missing fields
     if (empty($network_title) || empty($network_domain) || empty($network_path)) {
         $this->handle_redirect(array('id' => $network_id, 'action' => 'edit_network', 'network_updated' => '0'));
     }
     // Update domain & path
     $updated = update_network($network_id, $network_domain, $network_path);
     $success = '0';
     // Maybe update network title
     if (!is_wp_error($updated)) {
         update_network_option($network_id, 'site_name', $network_title);
         $success = '1';
     }
     // Handle redirect
     $this->handle_redirect(array('id' => $network_id, 'action' => 'edit_network', 'network_updated' => $success));
 }