예제 #1
0
 /**
  * Checks if column-meta key exists
  *
  * @since     1.0
  */
 public static function is_column_meta($id = '')
 {
     return Codepress_Admin_Columns::is_column_meta($id);
 }
예제 #2
0
 /**
  * Orderby Posts column
  *
  * @since     1.3
  */
 private function get_orderby_posts_vars($vars)
 {
     $post_type = $vars['post_type'];
     // apply sorting preference
     $this->apply_sorting_preference($vars, $post_type);
     // no sorting
     if (empty($vars['orderby'])) {
         return $vars;
     }
     // Column
     $column = $this->get_orderby_type($vars['orderby'], $post_type);
     if (empty($column)) {
         return $vars;
     }
     // id
     $type = $id = key($column);
     // Check for taxonomies, such as column-taxonomy-[taxname]
     if (strpos($type, 'column-taxonomy-') !== false) {
         $type = 'column-taxonomy';
     }
     // Check for Custom Field
     if (Codepress_Admin_Columns::is_column_meta($type)) {
         $type = 'column-post-meta';
     }
     // var
     $cposts = array();
     switch ($type) {
         case 'column-postid':
             $vars['orderby'] = 'ID';
             break;
         case 'column-order':
             $vars['orderby'] = 'menu_order';
             break;
         case 'column-modified':
             $vars['orderby'] = 'modified';
             break;
         case 'column-comment-count':
             $vars['orderby'] = 'comment_count';
             break;
         case 'column-post-meta':
             $field = $column[$id]['field'];
             // orderby type
             $field_type = 'meta_value';
             if ($column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id') {
                 $field_type = 'meta_value_num';
             }
             $vars = array_merge($vars, array('meta_key' => $field, 'orderby' => $field_type));
             break;
         case 'column-excerpt':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $this->prepare_sort_string_value($p->post_content);
             }
             break;
         case 'column-word-count':
             $sort_flag = SORT_NUMERIC;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = str_word_count(Codepress_Admin_Columns::strip_trim($p->post_content));
             }
             break;
         case 'column-page-template':
             $sort_flag = SORT_STRING;
             $templates = get_page_templates();
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $page_template = get_post_meta($p->ID, '_wp_page_template', true);
                 $cposts[$p->ID] = array_search($page_template, $templates);
             }
             break;
         case 'column-post_formats':
             $sort_flag = SORT_REGULAR;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = get_post_format($p->ID);
             }
             break;
         case 'column-attachment':
         case 'column-attachment-count':
             $sort_flag = SORT_NUMERIC;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = count(Codepress_Admin_Columns::get_attachment_ids($p->ID));
             }
             break;
         case 'column-page-slug':
             $sort_flag = SORT_REGULAR;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->post_name;
             }
             break;
         case 'column-sticky':
             $sort_flag = SORT_REGULAR;
             $stickies = get_option('sticky_posts');
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->ID;
                 if (!empty($stickies) && in_array($p->ID, $stickies)) {
                     $cposts[$p->ID] = 0;
                 }
             }
             break;
         case 'column-featured_image':
             $sort_flag = SORT_REGULAR;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->ID;
                 $thumb = get_the_post_thumbnail($p->ID);
                 if (!empty($thumb)) {
                     $cposts[$p->ID] = 0;
                 }
             }
             break;
         case 'column-roles':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = 0;
                 $userdata = get_userdata($p->post_author);
                 if (!empty($userdata->roles[0])) {
                     $cposts[$p->ID] = $userdata->roles[0];
                 }
             }
             break;
         case 'column-status':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->post_status . strtotime($p->post_date);
             }
             break;
         case 'column-comment-status':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->comment_status;
             }
             break;
         case 'column-ping-status':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $cposts[$p->ID] = $p->ping_status;
             }
             break;
         case 'column-taxonomy':
             $sort_flag = SORT_STRING;
             // needed to sort
             $taxonomy = str_replace('column-taxonomy-', '', $id);
             $cposts = $this->get_posts_sorted_by_taxonomy($post_type, $taxonomy);
             break;
         case 'column-author-name':
             $sort_flag = SORT_STRING;
             $display_as = $column[$id]['display_as'];
             if ('userid' == $display_as) {
                 $sort_flag = SORT_NUMERIC;
             }
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 if (!empty($p->post_author)) {
                     $name = Codepress_Admin_Columns::get_author_field_by_nametype($display_as, $p->post_author);
                     $cposts[$p->ID] = $name;
                 }
             }
             break;
         case 'column-before-moretag':
             $sort_flag = SORT_STRING;
             foreach ($this->get_any_posts_by_posttype($post_type) as $p) {
                 $extended = get_extended($p->post_content);
                 $content = !empty($extended['extended']) ? $extended['main'] : '';
                 $cposts[$p->ID] = $this->prepare_sort_string_value($content);
             }
             break;
             /** native WP columns */
             // categories
         /** native WP columns */
         // categories
         case 'categories':
             $sort_flag = SORT_STRING;
             // needed to sort
             $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'category');
             break;
             // tags
         // tags
         case 'tags':
             $sort_flag = SORT_STRING;
             // needed to sort
             $cposts = $this->get_posts_sorted_by_taxonomy($post_type, 'post_tag');
             break;
     }
     // we will add the sorted post ids to vars['post__in'] and remove unused vars
     if (isset($sort_flag)) {
         $vars = $this->get_vars_post__in($vars, $cposts, $sort_flag);
     }
     return $vars;
 }