示例#1
0
 /**
  * Add admin menu items
  */
 public function add_menu_items()
 {
     $count = wc_count_reviews();
     $moderated = $count->moderated;
     $label = __('Reviews', 'wc-product-reviews-pro');
     if ($moderated) {
         $label .= ' <span class="awaiting-mod count-' . $moderated . '"><span class="pending-count">' . $moderated . '</span></span>';
     }
     // Add reviews list table
     $page = add_submenu_page('woocommerce', __('Reviews', 'wc-product-reviews-pro'), $label, 'edit_posts', 'reviews', array($this, 'render_reviews_list_table'));
     // WordPress generates the page hook name automatically and there
     // is no way to manually set or filter it, so to be sure we use
     // the correct hook name, we store a reference to it.
     $this->reviews_page_hook = $page;
     // Hook screen options to edit reviews page load
     add_action("load-{$page}", array($this, 'load_reviews_screen'));
 }
 /**
  * Returns an associative array listing all the views that can be used with this table.
  *
  * @return array
  */
 function get_views()
 {
     global $post_id, $comment_status, $comment_type, $wpdb;
     $status_links = array();
     // Get commment (review) counts for eahc status
     $num_comments = $post_id ? wc_count_reviews($post_id) : wc_count_reviews();
     // Available status links, aka 'stati'
     $stati = array('all' => _nx_noop('All', 'All', 'comments', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'approved' => _n_noop('Approved', 'Approved', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>', WC_Product_Reviews_Pro::TEXT_DOMAIN));
     if (!EMPTY_TRASH_DAYS) {
         unset($stati['trash']);
     }
     // Prepare the base link
     $link = add_query_arg('page', 'reviews', 'admin.php');
     // Add comment type to the base link
     if (!empty($comment_type) && 'all' !== $comment_type) {
         $link = add_query_arg('comment_type', $comment_type, $link);
     }
     // Prepare status links and counts
     foreach ($stati as $status => $label) {
         $link = add_query_arg('comment_status', $status, $link);
         $class = $status == $comment_status ? ' class="current"' : '';
         if (!isset($num_comments->{$status})) {
             $num_comments->{$status} = 10;
         }
         // If viewing reviews for a specific product, add that to the link as well
         if ($post_id) {
             $link = add_query_arg('p', absint($post_id), $link);
         }
         // Translate and format link
         $status_links[$status] = "<a href='" . esc_url($link) . "'{$class}>" . sprintf(translate_nooped_plural($label, $num_comments->{$status}), number_format_i18n($num_comments->{$status})) . '</a>';
     }
     /**
      * Filter the review status links.
      *
      * @param array $status_links An array of fully-formed status links. Default 'All'.
      *                            Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
      */
     return apply_filters('review_status_links', $status_links);
 }