Exemple #1
0
 /**
  * Imports a Gist into Gistpen by ID
  *
  * @param  string             $gist_id    Gist ID
  * @return string|\WP_Error               Gist ID on success, WP_Error on failure
  * @since  0.5.0
  */
 public function import_gist($gist_id)
 {
     // Exit if this gist has already been imported
     $query = $this->database->query('head')->by_gist_id($gist_id);
     if ($query instanceof Zip) {
         return $query;
     }
     $response = $this->gist->get_gist($gist_id);
     if (is_wp_error($response)) {
         return $response;
     }
     $zip = $response['zip'];
     $version = $response['version'];
     unset($response);
     $result = $this->database->persist('head')->by_zip($zip);
     if (is_wp_error($result)) {
         return $result;
     }
     $ids = $result;
     unset($result);
     $result = $this->database->persist('commit')->by_ids($ids);
     if (is_wp_error($result)) {
         return $result;
     }
     $result = $this->database->persist('commit')->set_gist_id($result, $version);
     if (is_wp_error($result)) {
         return $result;
     }
     return $ids['zip'];
 }
Exemple #2
0
    /**
     * Validates the OAuth token and  before save.
     *
     * @param    null            $override_value null if validation fails
     * @param    string          $value          value to validate
     * @param    int             $object_id      CMB2_Options object id
     * @param    array           $args           CMB2 args
     * @param    \CMB2_Sanitize  $validation_obj validation object
     * @return   string|null                     string if success, null if fail
     * @since    0.5.0
     */
    public function validate_gist_token($override_value, $value, $object_id, $args, $validation_obj)
    {
        if ('wp-gistpen' !== $object_id || empty($value) || $validation_obj->value === $validation_obj->field->value) {
            return $value;
        }
        $this->client->authenticate($value);
        if (is_wp_error($error = $this->client->check_token())) {
            delete_transient('_wpgp_github_token_user_info');
            ?>

			<div class="error">
				<p>
					<?php 
            _e('Gist token failed to validate. Error message: ', $this->plugin_name);
            echo esc_html($error->get_error_message());
            ?>
				</p>
			</div><?php 
            $value = $override_value;
        }
        return $value;
    }
Exemple #3
0
 /**
  * Sets the Gist token.
  *
  * Get your Gist token by following
  * the instructions found here:
  * http://jamesdigioia.com/wp-gistpen/#gist-token
  *
  * ## OPTIONS
  *
  * <token>
  * : Your Gist token.
  *
  * ## EXAMPLES
  *
  *     wp wpgp set_token 123545678910abcde
  *
  * @synopsis <token>
  */
 function set_token($args, $assoc_args)
 {
     list($token) = $args;
     $client = new Gist(\WP_Gistpen::$plugin_name, \WP_Gistpen::$version);
     $client->authenticate($token);
     if (is_wp_error($error = $client->check_token())) {
         WP_CLI::error(__('Gist token failed to authenticate. Error: ', \WP_Gistpen::$plugin_name) . $error->get_error_message());
     }
     $success = cmb2_update_option(\WP_Gistpen::$plugin_name, '_wpgp_gist_token', $token);
     if (!$success) {
         WP_CLI::error(__('Gist token update failed.', \WP_Gistpen::$plugin_name));
     }
     WP_CLI::success(__('Gist token updated.', \WP_Gistpen::$plugin_name));
 }