Esempio n. 1
0
 /**
  * Get views from a post
  *
  * ## OPTIONS
  *
  * [<post_type>]
  * : The ID of the post to get.
  *
  * [--all]
  * : Loop over all posts
  */
 public function regenerate($args, $assoc_args)
 {
     $args = array('posts_per_page' => -1);
     if (!isset($assoc_args['all']) && empty($args)) {
         \WP_CLI::error(__("Please specify one or more post types, or use --all.", 'wp-piwik-more-stats'));
     }
     if (isset($assoc_args['all'])) {
         $args['post_type'] = get_post_types(array('public' => true), 'names');
     } else {
         $args['post_type'] = $args;
     }
     $posts = get_posts($args);
     foreach ($posts as $post) {
         WP_Piwik_More_Stats_API::get_count_from_post($post, true);
     }
     // Let the user know the results.
     $num_to_update = count($posts);
     \WP_CLI::success(__("Updated {$num_to_update} items.", 'wp-piwik-more-stats'));
 }
Esempio n. 2
0
 public function column_value($column, $post_id)
 {
     if ('piwik_count' == $column) {
         echo WP_Piwik_More_Stats_API::get_count_from_post($post_id);
     }
 }
 public function refresh_post_cache()
 {
     if (is_singular()) {
         WP_Piwik_More_Stats_API::get_count_from_post(get_the_ID());
     }
 }