From 5316b4fc2d643732616cd9e8d90a81a10cf17059 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 12 Jan 2010 00:14:27 +0000 Subject: [PATCH] Merge page-new.php into post-new.php. Start abstracting column headers and prefs. see #9674 git-svn-id: http://svn.automattic.com/wordpress/trunk@12702 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-header.php | 2 +- wp-admin/edit-pages.php | 4 ++-- wp-admin/includes/post.php | 5 +++-- wp-admin/includes/template.php | 32 +++++++++++++++++++++++--------- wp-admin/menu.php | 2 +- wp-admin/page-new.php | 34 ---------------------------------- wp-admin/page.php | 2 +- wp-admin/post-new.php | 13 ++++++++----- 8 files changed, 39 insertions(+), 55 deletions(-) delete mode 100644 wp-admin/page-new.php diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index cab5125a0..3a97aa1df 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -55,7 +55,7 @@ var ajaxurl = '', pagenow = '
-

' . __('Search results for “%s”') . '', esc_html( get_search_query() ) ); ?>

diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 72fee6cb0..3f9f76de4 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -324,9 +324,10 @@ function bulk_edit_posts( $post_data = null ) { * * @since unknown * + *@param string A post type string, defaults to 'post'. * @return object stdClass object containing all the default post data as attributes */ -function get_default_post_to_edit() { +function get_default_post_to_edit( $post_type = 'post' ) { $post_title = ''; if ( !empty( $_REQUEST['post_title'] ) ) @@ -347,7 +348,7 @@ function get_default_post_to_edit() { $post->post_date_gmt = ''; $post->post_password = ''; $post->post_status = 'draft'; - $post->post_type = 'post'; + $post->post_type = $post_type; $post->to_ping = ''; $post->pinged = ''; $post->comment_status = get_option( 'default_comment_status' ); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index a12d6bb4d..ab737aa03 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -748,15 +748,19 @@ function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'po * @return unknown */ function wp_manage_posts_columns() { + global $typenow; + $posts_columns = array(); $posts_columns['cb'] = ''; /* translators: manage posts column name */ $posts_columns['title'] = _x('Post', 'column name'); $posts_columns['author'] = __('Author'); - $posts_columns['categories'] = __('Categories'); - $posts_columns['tags'] = __('Tags'); + if ( empty($typenow) || is_object_in_taxonomy($typenow, 'category') ) + $posts_columns['categories'] = __('Categories'); + if ( empty($typenow) || is_object_in_taxonomy($typenow, 'category') ) + $posts_columns['tags'] = __('Tags'); $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all'; - if ( !in_array( $post_status, array('pending', 'draft', 'future') ) ) + if ( !in_array( $post_status, array('pending', 'draft', 'future') ) && ( empty($typenow) || post_type_supports($typenow, 'comments') ) ) $posts_columns['comments'] = '
Comments
'; $posts_columns['date'] = __('Date'); $posts_columns = apply_filters('manage_posts_columns', $posts_columns); @@ -826,11 +830,16 @@ function get_column_headers($page) { if ( !isset($_wp_column_headers) ) $_wp_column_headers = array(); + $map_screen = $page; + $type = str_replace('edit-', '', $map_screen); + if ( in_array($type, get_post_types()) ) + $map_screen = 'edit'; + // Store in static to avoid running filters on each call if ( isset($_wp_column_headers[$page]) ) return $_wp_column_headers[$page]; - switch ($page) { + switch ($map_screen) { case 'edit': $_wp_column_headers[$page] = wp_manage_posts_columns(); break; @@ -924,10 +933,6 @@ function print_column_headers( $type, $id = true ) { $columns = get_column_headers( $type ); $hidden = get_hidden_columns($type); $styles = array(); -// $styles['tag']['posts'] = 'width: 90px;'; -// $styles['link-category']['links'] = 'width: 90px;'; -// $styles['category']['posts'] = 'width: 90px;'; -// $styles['link']['visible'] = 'text-align: center;'; foreach ( $columns as $column_key => $column_display_name ) { $class = ' class="manage-column'; @@ -3494,6 +3499,10 @@ function screen_meta($screen) { if ( !empty($typenow) ) $screen = $typenow; } + if ( 'edit' == $screen ) { + if ( !empty($typenow) ) + $screen = 'edit-' . $typenow; + } if ( isset($meta_screens[$screen]) ) $screen = $meta_screens[$screen]; @@ -3707,7 +3716,12 @@ function screen_layout($screen) { } function screen_options($screen) { - switch ( $screen ) { + $map_screen = $screen; + $type = str_replace('edit-', '', $map_screen); + if ( in_array($type, get_post_types()) ) + $map_screen = 'edit'; + + switch ( $map_screen ) { case 'edit': $per_page_label = __('Posts per page:'); break; diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 97f310119..8f68eb675 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -71,7 +71,7 @@ $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-to $menu[20] = array( __('Pages'), 'edit_pages', 'edit-pages.php', '', 'menu-top', 'menu-pages', 'div' ); $submenu['edit-pages.php'][5] = array( __('Edit'), 'edit_pages', 'edit-pages.php' ); /* translators: add new page */ - $submenu['edit-pages.php'][10] = array( _x('Add New', 'page'), 'edit_pages', 'page-new.php' ); + $submenu['edit-pages.php'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' ); $menu[25] = array( sprintf( __('Comments %s'), "" . number_format_i18n($awaiting_mod) . "" ), 'edit_posts', 'edit-comments.php', '', 'menu-top', 'menu-comments', 'div' ); diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php deleted file mode 100644 index 984c2c3e5..000000000 --- a/wp-admin/page-new.php +++ /dev/null @@ -1,34 +0,0 @@ - diff --git a/wp-admin/page.php b/wp-admin/page.php index f6ab7d947..e8af5b43f 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -73,7 +73,7 @@ elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) $action = 'preview'; $sendback = wp_get_referer(); -if ( strpos($sendback, 'page.php') !== false || strpos($sendback, 'page-new.php') !== false ) +if ( strpos($sendback, 'page.php') !== false || strpos($sendback, 'post-new.php') !== false ) $sendback = admin_url('edit-pages.php'); else $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 1776329f1..944fdb026 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -9,7 +9,7 @@ /** Load WordPress Administration Bootstrap */ require_once('admin.php'); -if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) ) +if ( isset($_GET['post_type']) && ( in_array( $_GET['post_type'], get_post_types( array('_show' => true ) ) ) || in_array( $_GET['post_type'], get_post_types( array('_builtin' => true ) ) ) ) ) $post_type = $_GET['post_type']; else $post_type = 'post'; @@ -17,6 +17,8 @@ else if ( 'post' != $post_type ) { $parent_file = "edit.php?post_type=$post_type"; $submenu_file = "post-new.php?post_type=$post_type"; + if ( 'page' == $post_type ) + $parent_file = 'edit-pages.php'; } else { $parent_file = 'edit.php'; $submenu_file = 'post-new.php'; @@ -35,7 +37,7 @@ add_thickbox(); wp_enqueue_script('media-upload'); wp_enqueue_script('word-count'); -if ( ! current_user_can('edit_posts') ) { +if ( 'post' == $post_type && !current_user_can('edit_posts') ) { require_once ('./admin-header.php'); ?>

edit_posts capability to your user, in order to be authorized to post.
@@ -49,9 +51,10 @@ When you’re promoted, just reload this page and you’ll be able to bl } // Show post form. -$post = get_default_post_to_edit(); -$post->post_type = $post_type; -include('edit-form-advanced.php'); +if ( current_user_can('edit_' . $post_type_object->capability_type . 's') ) { + $post = get_default_post_to_edit( $post_type ); + include('edit-form-advanced.php'); +} include('admin-footer.php'); ?>