Exemplo n.º 1
0
         *
         * @since  1.0.0.
         *
         * @param  array     $args    The default args.
         * @param  string    $url     URL for the request.
         * @return array              Modified args.
         */
        public function http_request_args($args, $url)
        {
            if ($url === $this->get_download_link()) {
                $args['headers']['X-TTF-API-Key'] = get_option('ttf-api-key', '');
            }
            return $args;
        }
    }
}
if (!function_exists('ttf_get_updater')) {
    /**
     * Return the TTF_Updater instance.
     *
     * @since  1.0.0.
     *
     * @return TTF_Updater
     */
    function ttf_get_updater()
    {
        return TTF_Updater::instance();
    }
}
ttf_get_updater();
Exemplo n.º 2
0
 /**
  * Authorize the theme and save the auth status on submission.
  *
  * @since  1.0.0.
  *
  * @param  mixed    $value    The input value.
  * @return bool               The auth status.
  */
 public function authorize_theme_and_domain($value)
 {
     if (!isset($_POST['updater-email']) || !isset($_POST['updater-password'])) {
         return 0;
     }
     // Grab the auth details
     $email = $_POST['updater-email'];
     $password = $_POST['updater-password'];
     // Set the endpoint
     $auth_endpoint = 'https://thethemefoundry.com/key/auth';
     // Sometimes HTTP requests need a little extra time locally
     $timeout = defined('WP_DEBUG') && true === WP_DEBUG ? 20 : 5;
     // Make the request
     $response = wp_remote_post($auth_endpoint, array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'body' => array('email' => $email, 'password' => $password, 'domain' => str_replace(array('http://', 'https://'), array('', ''), get_option('siteurl')), 'item' => sanitize_title_with_dashes(ttf_get_updater()->config['slug'])), 'timeout' => $timeout));
     $response_code = (int) wp_remote_retrieve_response_code($response);
     $response_body = json_decode(wp_remote_retrieve_body($response));
     if (200 === $response_code && isset($response_body->key)) {
         $msg = array('status' => 'updated', 'message' => __('Your site is authorized for automatic updates from The Theme Foundry.', 'oxford'));
         // Record the key
         $key = $response_body->key;
         if ($key === preg_replace('/[^a-z0-9]/i', '', $key)) {
             $this->add_msg($msg);
             return $key;
         } else {
             $new_error = new stdClass();
             $new_error->code = '513';
             $new_error->msg = 'invalid key';
             $errors[] = $new_error;
             $msg = array('status' => 'error', 'message' => __('There was an error authorizing your site for automatic updates from The Theme Foundry.', 'oxford'), 'details' => $errors);
             $this->add_msg($msg);
             return false;
         }
     } else {
         if (is_wp_error($response)) {
             $errors = array();
             foreach ($response as $error) {
                 foreach ($error as $code => $data) {
                     $new_error = new stdClass();
                     $new_error->code = $code;
                     $new_error->msg = $data[0];
                     $errors[] = $new_error;
                 }
             }
         } else {
             $errors = (array) $response_body->errors;
         }
         $msg = array('status' => 'error', 'message' => __('There was an error authorizing your site for automatic updates from The Theme Foundry.', 'oxford'), 'details' => $errors);
         $this->add_msg($msg);
         return false;
     }
 }