示例#1
0
 /**
  * Imports the post in your GitHub repo
  * into your WordPress blog
  *
  * ## OPTIONS
  *
  * <user_id>
  * : The user ID you'd like to save the commit as
  *
  * ## EXAMPLES
  *
  *     wp wpghs import 1
  *
  * @synopsis <user_id>
  */
 public function import($args, $assoc_args)
 {
     list($user_id) = $args;
     if (!is_numeric($user_id)) {
         WP_CLI::error(__('Invalid user ID', 'wordpress-github-sync'));
     }
     update_option('_wpghs_export_user_id', (int) $user_id);
     WP_CLI::line(__('Starting import from GitHub.', 'wordpress-github-sync'));
     $this->controller->import_master();
 }
 /**
  * Webhook callback as trigered from GitHub push
  */
 public function pull_posts()
 {
     # Prevent pushes on update
     $this->push_lock = true;
     $raw_data = file_get_contents('php://input');
     $headers = $this->headers();
     // validate secret
     $hash = hash_hmac('sha1', $raw_data, $this->secret());
     if ('sha1=' . $hash !== $headers['X-Hub-Signature']) {
         $msg = __('Failed to validate secret.', WordPress_GitHub_Sync::$text_domain);
         self::write_log($msg);
         wp_send_json(array('result' => 'error', 'message' => $msg));
     }
     $result = $this->controller->pull(json_decode($raw_data));
     wp_send_json($result);
 }