WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/04/2010 04:58:43 PM (10 years ago)
Author:
ryan
Message:

More custom post type support. Props scribu. see #9674

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit.php

    r12546 r12597  
    2121}
    2222
     23if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) )
     24    $post_type = $_GET['post_type'];
     25else
     26    $post_type = 'post';
     27
     28$post_type_object = get_post_type_object($post_type);
     29
     30if ( 'post' != $post_type ) {
     31    $parent_file = "edit.php?post_type=$post_type";
     32    $submenu_file = "edit.php?post_type=$post_type";
     33    $post_new_file = "post-new.php?post_type=$post_type";
     34} else {
     35    $parent_file = 'edit.php';
     36    $submenu_file = 'edit.php';
     37    $post_new_file = 'post-new.php';
     38}
     39
    2340// Handle bulk actions
    2441if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
     
    2744
    2845    if ( strpos($sendback, 'post.php') !== false )
    29         $sendback = admin_url('post-new.php');
     46        $sendback = admin_url($post_new_file);
    3047
    3148    if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
    3249        $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
    33         $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
     50        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
    3451        $doaction = 'delete';
    3552    } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) {
     
    108125}
    109126
    110 if ( empty($title) )
    111     $title = __('Edit Posts');
    112 $parent_file = 'edit.php';
     127$title = sprintf(__('Edit %s'), $post_type_object->label);
     128
    113129wp_enqueue_script('inline-edit-post');
    114130
    115131$user_posts = false;
    116132if ( !current_user_can('edit_others_posts') ) {
    117     $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = 'post' AND post_status != 'trash' AND post_author = %d", $current_user->ID) );
     133    $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = '%s' AND post_status != 'trash' AND post_author = %d", $post_type, $current_user->ID) );
    118134    $user_posts = true;
    119135    if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) )
     
    135151<div class="wrap">
    136152<?php screen_icon(); ?>
    137 <h2><?php echo esc_html( $title ); ?> <a href="post-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
     153<h2><?php echo esc_html( $title ); ?> <a href="<?php echo $post_new_file ?>" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
    138154if ( isset($_GET['s']) && $_GET['s'] )
    139155    printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
     
    189205if ( empty($locked_post_status) ) :
    190206$status_links = array();
    191 $num_posts = wp_count_posts( 'post', 'readable' );
     207$num_posts = wp_count_posts( $post_type, 'readable' );
    192208$class = '';
    193209$allposts = '';
     
    216232        $class = ' class="current"';
    217233
    218     $status_links[] = "<li><a href='edit.php?post_status=$status'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
     234    $status_links[] = "<li><a href='edit.php?post_status=$status&amp;post_type=$post_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
    219235}
    220236echo implode( " |</li>\n", $status_links ) . '</li>';
     
    231247
    232248<input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" />
     249<input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
    233250<input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
    234251
     
    268285<?php // view filters
    269286if ( !is_singular() ) {
    270 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
     287$arc_query = $wpdb->prepare("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = %s ORDER BY post_date DESC", $post_type);
    271288
    272289$arc_result = $wpdb->get_results( $arc_query );
Note: See TracChangeset for help on using the changeset viewer.