Esempio n. 1
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;
    }
Esempio n. 2
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));
 }