From da89de4958fcd10b54b5f263343ba8157438f04f Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 4 Jan 2010 16:58:43 +0000 Subject: [PATCH] More custom post type support. Props scribu. see #9674 git-svn-id: http://svn.automattic.com/wordpress/trunk@12597 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 2 +- wp-admin/admin-header.php | 9 ++++- wp-admin/edit-form-advanced.php | 43 +++++++++++----------- wp-admin/edit-tags.php | 14 ++++++- wp-admin/edit.php | 37 ++++++++++++++----- wp-admin/includes/meta-boxes.php | 6 ++- wp-admin/includes/plugin.php | 7 ++-- wp-admin/includes/post.php | 7 +++- wp-admin/includes/template.php | 21 +++++++++-- wp-admin/js/post.dev.js | 10 +++-- wp-admin/js/post.js | 2 +- wp-admin/menu-header.php | 2 +- wp-admin/menu.php | 19 ++++++++++ wp-admin/post-new.php | 21 ++++++++++- wp-admin/post.php | 14 ++++++- wp-includes/capabilities.php | 15 +++++--- wp-includes/link-template.php | 39 +++++--------------- wp-includes/post.php | 63 ++++++++++++++++++++++++++++---- wp-includes/query.php | 9 ++++- wp-includes/taxonomy.php | 54 +++++++++++++++++++++++++-- 20 files changed, 292 insertions(+), 102 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 5778a12e2..030e6b2e4 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1135,7 +1135,7 @@ case 'inline-save': if ( 'page' == $_POST['post_type'] ) { $post[] = get_post($_POST['post_ID']); page_rows($post); - } elseif ( 'post' == $_POST['post_type'] ) { + } elseif ( 'post' == $_POST['post_type'] || in_array($_POST['post_type'], get_post_types( array('_show' => true) ) ) ) { $mode = $_POST['post_view']; $post[] = get_post($_POST['post_ID']); post_rows($post); diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index 6a343fc9d..75db05c89 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -35,13 +35,20 @@ else if ( isset($plugin_page) ) else if ( isset($pagenow) ) $hook_suffix = $pagenow; +if ( isset($submenu_file) && (false !== $pos = strpos($submenu_file, 'post_type=')) ) + $typenow = substr($submenu_file, $pos + 10); +elseif ( isset($parent_file) && (false !== $pos = strpos($parent_file, 'post_type=')) ) + $typenow = substr($parent_file, $pos + 10); +else + $typenow = ''; + $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); ?> label) ? esc_attr($taxonomy->label) : $tax_name; - add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', 'post', 'side', 'core'); + add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core'); } } -add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core'); -if ( current_theme_supports( 'post-thumbnails', 'post' ) ) - add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', 'post', 'side', 'low'); -add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core'); -add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core'); -add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'normal', 'core'); +if ( is_object_in_taxonomy($post_type, 'category') ) + add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core'); +if ( current_theme_supports( 'post-thumbnails', $post_type ) ) + add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low'); +add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core'); +add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core'); +add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core'); do_action('dbx_post_advanced'); -add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'post', 'normal', 'core'); +add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core'); if ( 'publish' == $post->post_status || 'private' == $post->post_status ) - add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', 'post', 'normal', 'core'); + add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core'); if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) ) - add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', 'post', 'normal', 'core'); + add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core'); $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM if ( $post->post_author && !in_array($post->post_author, $authors) ) $authors[] = $post->post_author; if ( $authors && count( $authors ) > 1 ) - add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', 'post', 'normal', 'core'); + add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', $post_type, 'normal', 'core'); if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) - add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', 'post', 'normal', 'core'); + add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core'); -do_action('do_meta_boxes', 'post', 'normal', $post); -do_action('do_meta_boxes', 'post', 'advanced', $post); -do_action('do_meta_boxes', 'post', 'side', $post); +do_action('do_meta_boxes', $post_type, 'normal', $post); +do_action('do_meta_boxes', $post_type, 'advanced', $post); +do_action('do_meta_boxes', $post_type, 'side', $post); require_once('admin-header.php'); @@ -152,7 +153,7 @@ else - + - +
@@ -223,11 +224,11 @@ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index ef22aba19..f4761bb46 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -19,8 +19,18 @@ if ( empty($taxonomy) ) if ( !is_taxonomy($taxonomy) ) wp_die(__('Invalid taxonomy')); -$parent_file = 'edit.php'; -$submenu_file = "edit-tags.php?taxonomy=$taxonomy"; +if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) ) + $post_type = $_GET['post_type']; +else + $post_type = 'post'; + +if ( 'post' != $post_type ) { + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type"; +} else { + $parent_file = 'edit.php'; + $submenu_file = "edit-tags.php?taxonomy=$taxonomy"; +} if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) ) $action = 'bulk-delete'; diff --git a/wp-admin/edit.php b/wp-admin/edit.php index e64cc9d90..87b789326 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -20,17 +20,34 @@ if ( $_redirect = intval( max( @$_GET['p'], @$_GET['attachment_id'], @$_GET['pag unset( $_redirect ); } +if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) ) + $post_type = $_GET['post_type']; +else + $post_type = 'post'; + +$post_type_object = get_post_type_object($post_type); + +if ( 'post' != $post_type ) { + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "edit.php?post_type=$post_type"; + $post_new_file = "post-new.php?post_type=$post_type"; +} else { + $parent_file = 'edit.php'; + $submenu_file = 'edit.php'; + $post_new_file = 'post-new.php'; +} + // Handle bulk actions if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) { check_admin_referer('bulk-posts'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); if ( strpos($sendback, 'post.php') !== false ) - $sendback = admin_url('post-new.php'); + $sendback = admin_url($post_new_file); if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) { $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']); - $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) ); + $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) ); $doaction = 'delete'; } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) { $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']); @@ -107,14 +124,13 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet exit; } -if ( empty($title) ) - $title = __('Edit Posts'); -$parent_file = 'edit.php'; +$title = sprintf(__('Edit %s'), $post_type_object->label); + wp_enqueue_script('inline-edit-post'); $user_posts = false; if ( !current_user_can('edit_others_posts') ) { - $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) ); + $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) ); $user_posts = true; if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) ) $_GET['author'] = $current_user->ID; @@ -134,7 +150,7 @@ else
-

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

@@ -188,7 +204,7 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated' $label ) { if ( isset($_GET['post_status']) && $status == $_GET['post_status'] ) $class = ' class="current"'; - $status_links[] = "
  • " . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . ''; + $status_links[] = "
  • " . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . ''; } echo implode( " |
  • \n", $status_links ) . ''; unset( $status_links ); @@ -230,6 +246,7 @@ endif;

    + @@ -267,7 +284,7 @@ $is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash'; posts WHERE post_type = 'post' ORDER BY post_date DESC"; +$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); $arc_result = $wpdb->get_results( $arc_query ); diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 14052754b..380bbeace 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -13,7 +13,9 @@ function post_submit_meta_box($post) { global $action; $post_type = $post->post_type; - $can_publish = current_user_can("publish_${post_type}s"); + $post_type_object = get_post_type_object($post_type); + $type_cap = $post_type_object->capability_type; + $can_publish = current_user_can("publish_${type_cap}s"); ?>
    @@ -184,7 +186,7 @@ if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
    ID ) ) { +if ( current_user_can( "delete_${type_cap}", $post->ID ) ) { if ( !EMPTY_TRASH_DAYS ) { $delete_url = wp_nonce_url( add_query_arg( array('action' => 'delete', 'post' => $post->ID) ), "delete-${post_type}_{$post->ID}" ); $delete_text = __('Delete Permanently'); diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index da1e076a8..2ff9038aa 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -745,14 +745,15 @@ function get_admin_page_parent( $parent = '' ) { $parent = $_wp_real_parent_file[$parent]; return $parent; } -/* + + /* if ( !empty ( $parent_file ) ) { if ( isset( $_wp_real_parent_file[$parent_file] ) ) $parent_file = $_wp_real_parent_file[$parent_file]; return $parent_file; } -*/ + */ if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { foreach ( (array)$menu as $parent_menu ) { @@ -782,7 +783,7 @@ function get_admin_page_parent( $parent = '' ) { foreach ( $submenu[$parent] as $submenu_array ) { if ( isset( $_wp_real_parent_file[$parent] ) ) $parent = $_wp_real_parent_file[$parent]; - if ( $submenu_array[2] == $pagenow ) { + if ( $submenu_array[2] == $pagenow && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) { $parent_file = $parent; return $parent; } else diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 082f594f7..f9f2fde9f 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -846,12 +846,17 @@ function wp_edit_posts_query( $q = false ) { $orderby = 'date'; } + $post_type_q = 'post_type=post'; + if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types( array('_show' => true) ) ) ) + $post_type_q = 'post_type=' . $q['post_type']; + + $posts_per_page = (int) get_user_option( 'edit_per_page', 0, false ); if ( empty( $posts_per_page ) || $posts_per_page < 1 ) $posts_per_page = 15; $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page ); - wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby"); + wp("$post_type_q&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby"); return array($post_stati, $avail_post_stati); } diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 628a5378f..c62204027 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -3482,7 +3482,7 @@ function _post_states($post) { } function screen_meta($screen) { - global $wp_meta_boxes, $_wp_contextual_help; + global $wp_meta_boxes, $_wp_contextual_help, $typenow; $screen = str_replace('.php', '', $screen); $screen = str_replace('-new', '', $screen); @@ -3492,6 +3492,12 @@ function screen_meta($screen) { $column_screens = get_column_headers($screen); $meta_screens = array('index' => 'dashboard'); + // Give post_type pages their own screen + if ( 'post' == $screen ) { + if ( !empty($typenow) ) + $screen = $typenow; + } + if ( isset($meta_screens[$screen]) ) $screen = $meta_screens[$screen]; $show_screen = false; @@ -3675,6 +3681,11 @@ function screen_layout($screen) { global $screen_layout_columns; $columns = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2); + + // Add custom post types + foreach ( get_post_types( array('_show' => true) ) as $post_type ) + $columns[$post_type] = 2; + $columns = apply_filters('screen_layout_columns', $columns, $screen); if ( !isset($columns[$screen]) ) { @@ -3754,8 +3765,12 @@ function screen_icon($name = '') { global $parent_file, $hook_suffix; if ( empty($name) ) { - if ( isset($parent_file) && !empty($parent_file) ) - $name = substr($parent_file, 0, -4); + if ( isset($parent_file) && !empty($parent_file) ) { + $name = $parent_file; + if ( false !== $pos = strpos($name, '?post_type=') ) + $name = substr($name, 0, $pos); + $name = substr($name, 0, -4); + } else $name = str_replace(array('.php', '-new', '-add'), '', $hook_suffix); } diff --git a/wp-admin/js/post.dev.js b/wp-admin/js/post.dev.js index 662100369..d964261bd 100644 --- a/wp-admin/js/post.dev.js +++ b/wp-admin/js/post.dev.js @@ -231,10 +231,14 @@ jQuery(document).ready( function($) { var catAddAfter, stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow; // postboxes - if ( post ) - postboxes.add_postbox_toggles('post'); - else if ( page ) + if ( post ) { + type = 'post'; + if ( typenow ) + type = typenow; + postboxes.add_postbox_toggles(type); + } else if ( page ) { postboxes.add_postbox_toggles('page'); + } // multi-taxonomies if ( $('#tagsdiv-post_tag').length ) { diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 94da7e900..e6c3bba76 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -1 +1 @@ -var tagBox,commentsBox,editPermalink,makeSlugeditClickable,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail;function array_unique_noempty(b){var c=[];jQuery.each(b,function(a,d){d=jQuery.trim(d);if(d&&jQuery.inArray(d,c)==-1){c.push(d)}});return c}(function(a){tagBox={clean:function(b){return b.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"")},parseTags:function(e){var h=e.id,b=h.split("-check-num-")[1],d=a(e).closest(".tagsdiv"),g=d.find(".the-tags"),c=g.val().split(","),f=[];delete c[b];a.each(c,function(i,j){j=a.trim(j);if(j){f.push(j)}});g.val(this.clean(f.join(",")));this.quickClicks(d);return false},quickClicks:function(c){var e=a(".the-tags",c),d=a(".tagchecklist",c),b;if(!e.length){return}b=e.val().split(",");d.empty();a.each(b,function(h,i){var f,g,j=a(c).attr("id");i=a.trim(i);if(!i.match(/^\s+$/)&&""!=i){g=j+"-check-num-"+h;f='X '+i+" ";d.append(f);a("#"+g).click(function(){tagBox.parseTags(this)})}})},flushTags:function(e,b,g){b=b||false;var i,c=a(".the-tags",e),h=a("input.newtag",e),d;i=b?a(b).text():h.val();tagsval=c.val();d=tagsval?tagsval+","+i:i;d=this.clean(d);d=array_unique_noempty(d.split(",")).join(",");c.val(d);this.quickClicks(e);if(!b){h.val("")}if("undefined"==typeof(g)){h.focus()}return false},get:function(c){var b=c.substr(c.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:b},function(e,d){if(0==e||"success"!=d){e=wpAjax.broken}e=a('

    '+e+"

    ");a("a",e).click(function(){tagBox.flushTags(a(this).closest(".inside").children(".tagsdiv"),this);return false});a("#"+c).after(e)})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)});a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))});a("div.taghint",c).click(function(){a(this).css("visibility","hidden").siblings(".newtag").focus()});a("input.newtag",c).blur(function(){if(this.value==""){a(this).siblings(".taghint").css("visibility","")}}).focus(function(){a(this).siblings(".taghint").css("visibility","hidden")}).keyup(function(d){if(13==d.which){tagBox.flushTags(a(this).closest(".tagsdiv"));return false}}).keypress(function(d){if(13==d.which){d.preventDefault();return false}}).each(function(){var d=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+d,{delay:500,minchars:2,multiple:true,multipleSep:", "})});a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,false,1)})});a("a.tagcloud-link").click(function(){tagBox.get(a(this).attr("id"));a(this).unbind().click(function(){a(this).siblings(".the-tagcloud").toggle();return false});return false})}};commentsBox={st:0,get:function(d,c){var b=this.st,e;if(!c){c=20}this.st+=c;this.total=d;a("#commentsdiv img.waiting").show();e={action:"get-comments",mode:"single",_ajax_nonce:a("#add_comment_nonce").val(),post_ID:a("#post_ID").val(),start:b,num:c};a.post(ajaxurl,e,function(f){f=wpAjax.parseAjaxResponse(f);a("#commentsdiv .widefat").show();a("#commentsdiv img.waiting").hide();if("object"==typeof f&&f.responses[0]){a("#the-comment-list").append(f.responses[0].data);theList=theExtraList=null;a("a[className*=':']").unbind();setCommentsList();if(commentsBox.st>commentsBox.total){a("#show-comments").hide()}else{a("#show-comments").html(postL10n.showcomm)}return}else{if(1==f){a("#show-comments").parent().html(postL10n.endcomm);return}}a("#the-comment-list").append(''+wpAjax.broken+"")});return false}};WPSetThumbnailHTML=function(b){a(".inside","#postimagediv").html(b)};WPSetThumbnailID=function(c){var b=a("input[value=_thumbnail_id]","#list-table");if(b.size()>0){a("#meta\\["+b.attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(c)}};WPRemoveThumbnail=function(){a.post(ajaxurl,{action:"set-post-thumbnail",post_id:a("#post_ID").val(),thumbnail_id:-1,cookie:encodeURIComponent(document.cookie)},function(b){if(b=="0"){alert(setPostThumbnailL10n.error)}else{WPSetThumbnailHTML(b)}})}})(jQuery);jQuery(document).ready(function(f){var d,a,b,h="",i="post"==pagenow||"post-new"==pagenow,g="page"==pagenow||"page-new"==pagenow;if(i){postboxes.add_postbox_toggles("post")}else{if(g){postboxes.add_postbox_toggles("page")}}if(f("#tagsdiv-post_tag").length){tagBox.init()}else{f("#side-sortables, #normal-sortables, #advanced-sortables").children("div.postbox").each(function(){if(this.id.indexOf("tagsdiv-")===0){tagBox.init();return false}})}if(f("#categorydiv").length){f("a","#category-tabs").click(function(){var j=f(this).attr("href");f(this).parent().addClass("tabs").siblings("li").removeClass("tabs");f("#category-tabs").siblings(".tabs-panel").hide();f(j).show();if("#categories-all"==j){deleteUserSetting("cats")}else{setUserSetting("cats","pop")}return false});if(getUserSetting("cats")){f('a[href="#categories-pop"]',"#category-tabs").click()}f("#newcat").one("focus",function(){f(this).val("").removeClass("form-input-tip")});f("#category-add-sumbit").click(function(){f("#newcat").focus()});catAddBefore=function(j){if(!f("#newcat").val()){return false}j.data+="&"+f(":checked","#categorychecklist").serialize();return j};d=function(m,l){var k,j=f("#newcat_parent");if("undefined"!=l.parsed.responses[0]&&(k=l.parsed.responses[0].supplemental.newcat_parent)){j.before(k);j.remove()}};f("#categorychecklist").wpList({alt:"",response:"category-ajax-response",addBefore:catAddBefore,addAfter:d});f("#category-add-toggle").click(function(){f("#category-adder").toggleClass("wp-hidden-children");f('a[href="#categories-all"]',"#category-tabs").click();return false});f("#categorychecklist").children("li.popular-category").add(f("#categorychecklist-pop").children()).find(":checkbox").live("click",function(){var j=f(this),l=j.is(":checked"),k=j.val();f("#in-category-"+k+", #in-popular-category-"+k).attr("checked",l)})}if(f("#postcustom").length){f("#the-list").wpList({addAfter:function(j,k){f("table#list-table").show();if(typeof(autosave_update_post_ID)!="undefined"){autosave_update_post_ID(k.parsed.responses[0].supplemental.postid)}},addBefore:function(j){j.data+="&post_id="+f("#post_ID").val();return j}})}if(f("#submitdiv").length){a=f("#timestamp").html();b=f("#post-visibility-display").html();function e(){var j=f("#post-visibility-select");if(f("input:radio:checked",j).val()!="public"){f("#sticky").attr("checked",false);f("#sticky-span").hide()}else{f("#sticky-span").show()}if(f("input:radio:checked",j).val()!="password"){f("#password-span").hide()}else{f("#password-span").show()}}function c(){var q,r,k,t,s=f("#post_status"),l=f("option[value=publish]",s),j=f("#aa").val(),o=f("#mm").val(),p=f("#jj").val(),n=f("#hh").val(),m=f("#mn").val();q=new Date(j,o-1,p,n,m);r=new Date(f("#hidden_aa").val(),f("#hidden_mm").val()-1,f("#hidden_jj").val(),f("#hidden_hh").val(),f("#hidden_mn").val());k=new Date(f("#cur_aa").val(),f("#cur_mm").val()-1,f("#cur_jj").val(),f("#cur_hh").val(),f("#cur_mn").val());if(q.getFullYear()!=j||(1+q.getMonth())!=o||q.getDate()!=p||q.getMinutes()!=m){f(".timestamp-wrap","#timestampdiv").addClass("form-invalid");return false}else{f(".timestamp-wrap","#timestampdiv").removeClass("form-invalid")}if(q>k&&f("#original_post_status").val()!="future"){t=postL10n.publishOnFuture;f("#publish").val(postL10n.schedule)}else{if(q<=k&&f("#original_post_status").val()!="publish"){t=postL10n.publishOn;f("#publish").val(postL10n.publish)}else{t=postL10n.publishOnPast;if(g){f("#publish").val(postL10n.updatePage)}else{f("#publish").val(postL10n.updatePost)}}}if(r.toUTCString()==q.toUTCString()){f("#timestamp").html(a)}else{f("#timestamp").html(t+" "+f("option[value="+f("#mm").val()+"]","#mm").text()+" "+p+", "+j+" @ "+n+":"+m+" ")}if(f("input:radio:checked","#post-visibility-select").val()=="private"){if(g){f("#publish").val(postL10n.updatePage)}else{f("#publish").val(postL10n.updatePost)}if(l.length==0){s.append('")}else{l.html(postL10n.privatelyPublished)}f("option[value=publish]",s).attr("selected",true);f(".edit-post-status","#misc-publishing-actions").hide()}else{if(f("#original_post_status").val()=="future"||f("#original_post_status").val()=="draft"){if(l.length){l.remove();s.val(f("#hidden_post_status").val())}}else{l.html(postL10n.published)}if(s.is(":hidden")){f(".edit-post-status","#misc-publishing-actions").show()}}f("#post-status-display").html(f("option:selected",s).text());if(f("option:selected",s).val()=="private"||f("option:selected",s).val()=="publish"){f("#save-post").hide()}else{f("#save-post").show();if(f("option:selected",s).val()=="pending"){f("#save-post").show().val(postL10n.savePending)}else{f("#save-post").show().val(postL10n.saveDraft)}}return true}f(".edit-visibility","#visibility").click(function(){if(f("#post-visibility-select").is(":hidden")){e();f("#post-visibility-select").slideDown("normal");f(this).hide()}return false});f(".cancel-post-visibility","#post-visibility-select").click(function(){f("#post-visibility-select").slideUp("normal");f("#visibility-radio-"+f("#hidden-post-visibility").val()).attr("checked",true);f("#post_password").val(f("#hidden_post_password").val());f("#sticky").attr("checked",f("#hidden-post-sticky").attr("checked"));f("#post-visibility-display").html(b);f(".edit-visibility","#visibility").show();c();return false});f(".save-post-visibility","#post-visibility-select").click(function(){var j=f("#post-visibility-select");j.slideUp("normal");f(".edit-visibility","#visibility").show();c();if(f("input:radio:checked",j).val()!="public"){f("#sticky").attr("checked",false)}if(true==f("#sticky").attr("checked")){h="Sticky"}else{h=""}f("#post-visibility-display").html(postL10n[f("input:radio:checked",j).val()+h]);return false});f("input:radio","#post-visibility-select").change(function(){e()});f("#timestampdiv").siblings("a.edit-timestamp").click(function(){if(f("#timestampdiv").is(":hidden")){f("#timestampdiv").slideDown("normal");f(this).hide()}return false});f(".cancel-timestamp","#timestampdiv").click(function(){f("#timestampdiv").slideUp("normal");f("#mm").val(f("#hidden_mm").val());f("#jj").val(f("#hidden_jj").val());f("#aa").val(f("#hidden_aa").val());f("#hh").val(f("#hidden_hh").val());f("#mn").val(f("#hidden_mn").val());f("#timestampdiv").siblings("a.edit-timestamp").show();c();return false});f(".save-timestamp","#timestampdiv").click(function(){if(c()){f("#timestampdiv").slideUp("normal");f("#timestampdiv").siblings("a.edit-timestamp").show()}return false});f("#post-status-select").siblings("a.edit-post-status").click(function(){if(f("#post-status-select").is(":hidden")){f("#post-status-select").slideDown("normal");f(this).hide()}return false});f(".save-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("normal");f("#post-status-select").siblings("a.edit-post-status").show();c();return false});f(".cancel-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("normal");f("#post_status").val(f("#hidden_post_status").val());f("#post-status-select").siblings("a.edit-post-status").show();c();return false})}if(f("#edit-slug-box").length){editPermalink=function(j){var k,n=0,m=f("#editable-post-name"),o=m.html(),r=f("#post_name"),s=r.html(),p=f("#edit-slug-buttons"),q=p.html(),l=f("#editable-post-name-full").html();f("#view-post-btn").hide();p.html(''+postL10n.ok+' '+postL10n.cancel+"");p.children(".save").click(function(){var t=m.children("input").val();f.post(ajaxurl,{action:"sample-permalink",post_id:j,new_slug:t,new_title:f("#title").val(),samplepermalinknonce:f("#samplepermalinknonce").val()},function(u){f("#edit-slug-box").html(u);p.html(q);r.attr("value",t);makeSlugeditClickable();f("#view-post-btn").show()});return false});f(".cancel","#edit-slug-buttons").click(function(){f("#view-post-btn").show();m.html(o);p.html(q);r.attr("value",s);return false});for(k=0;kl.length/4)?"":l;m.html('').children("input").keypress(function(u){var t=u.keyCode||0;if(13==t){p.children(".save").click();return false}if(27==t){p.children(".cancel").click();return false}r.attr("value",this.value)}).focus()};makeSlugeditClickable=function(){f("#editable-post-name").click(function(){f("#edit-slug-buttons").children(".edit-slug").click()})};makeSlugeditClickable()}}); \ No newline at end of file +var tagBox,commentsBox,editPermalink,makeSlugeditClickable,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail;function array_unique_noempty(b){var c=[];jQuery.each(b,function(a,d){d=jQuery.trim(d);if(d&&jQuery.inArray(d,c)==-1){c.push(d)}});return c}(function(a){tagBox={clean:function(b){return b.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"")},parseTags:function(e){var h=e.id,b=h.split("-check-num-")[1],d=a(e).closest(".tagsdiv"),g=d.find(".the-tags"),c=g.val().split(","),f=[];delete c[b];a.each(c,function(i,j){j=a.trim(j);if(j){f.push(j)}});g.val(this.clean(f.join(",")));this.quickClicks(d);return false},quickClicks:function(c){var e=a(".the-tags",c),d=a(".tagchecklist",c),b;if(!e.length){return}b=e.val().split(",");d.empty();a.each(b,function(h,i){var f,g,j=a(c).attr("id");i=a.trim(i);if(!i.match(/^\s+$/)&&""!=i){g=j+"-check-num-"+h;f='X '+i+" ";d.append(f);a("#"+g).click(function(){tagBox.parseTags(this)})}})},flushTags:function(e,b,g){b=b||false;var i,c=a(".the-tags",e),h=a("input.newtag",e),d;i=b?a(b).text():h.val();tagsval=c.val();d=tagsval?tagsval+","+i:i;d=this.clean(d);d=array_unique_noempty(d.split(",")).join(",");c.val(d);this.quickClicks(e);if(!b){h.val("")}if("undefined"==typeof(g)){h.focus()}return false},get:function(c){var b=c.substr(c.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:b},function(e,d){if(0==e||"success"!=d){e=wpAjax.broken}e=a('

    '+e+"

    ");a("a",e).click(function(){tagBox.flushTags(a(this).closest(".inside").children(".tagsdiv"),this);return false});a("#"+c).after(e)})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)});a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))});a("div.taghint",c).click(function(){a(this).css("visibility","hidden").siblings(".newtag").focus()});a("input.newtag",c).blur(function(){if(this.value==""){a(this).siblings(".taghint").css("visibility","")}}).focus(function(){a(this).siblings(".taghint").css("visibility","hidden")}).keyup(function(d){if(13==d.which){tagBox.flushTags(a(this).closest(".tagsdiv"));return false}}).keypress(function(d){if(13==d.which){d.preventDefault();return false}}).each(function(){var d=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+d,{delay:500,minchars:2,multiple:true,multipleSep:", "})});a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,false,1)})});a("a.tagcloud-link").click(function(){tagBox.get(a(this).attr("id"));a(this).unbind().click(function(){a(this).siblings(".the-tagcloud").toggle();return false});return false})}};commentsBox={st:0,get:function(d,c){var b=this.st,e;if(!c){c=20}this.st+=c;this.total=d;a("#commentsdiv img.waiting").show();e={action:"get-comments",mode:"single",_ajax_nonce:a("#add_comment_nonce").val(),post_ID:a("#post_ID").val(),start:b,num:c};a.post(ajaxurl,e,function(f){f=wpAjax.parseAjaxResponse(f);a("#commentsdiv .widefat").show();a("#commentsdiv img.waiting").hide();if("object"==typeof f&&f.responses[0]){a("#the-comment-list").append(f.responses[0].data);theList=theExtraList=null;a("a[className*=':']").unbind();setCommentsList();if(commentsBox.st>commentsBox.total){a("#show-comments").hide()}else{a("#show-comments").html(postL10n.showcomm)}return}else{if(1==f){a("#show-comments").parent().html(postL10n.endcomm);return}}a("#the-comment-list").append(''+wpAjax.broken+"")});return false}};WPSetThumbnailHTML=function(b){a(".inside","#postimagediv").html(b)};WPSetThumbnailID=function(c){var b=a("input[value=_thumbnail_id]","#list-table");if(b.size()>0){a("#meta\\["+b.attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(c)}};WPRemoveThumbnail=function(){a.post(ajaxurl,{action:"set-post-thumbnail",post_id:a("#post_ID").val(),thumbnail_id:-1,cookie:encodeURIComponent(document.cookie)},function(b){if(b=="0"){alert(setPostThumbnailL10n.error)}else{WPSetThumbnailHTML(b)}})}})(jQuery);jQuery(document).ready(function(f){var d,a,b,h="",i="post"==pagenow||"post-new"==pagenow,g="page"==pagenow||"page-new"==pagenow;if(i){type="post";if(typenow){type=typenow}postboxes.add_postbox_toggles(type)}else{if(g){postboxes.add_postbox_toggles("page")}}if(f("#tagsdiv-post_tag").length){tagBox.init()}else{f("#side-sortables, #normal-sortables, #advanced-sortables").children("div.postbox").each(function(){if(this.id.indexOf("tagsdiv-")===0){tagBox.init();return false}})}if(f("#categorydiv").length){f("a","#category-tabs").click(function(){var j=f(this).attr("href");f(this).parent().addClass("tabs").siblings("li").removeClass("tabs");f("#category-tabs").siblings(".tabs-panel").hide();f(j).show();if("#categories-all"==j){deleteUserSetting("cats")}else{setUserSetting("cats","pop")}return false});if(getUserSetting("cats")){f('a[href="#categories-pop"]',"#category-tabs").click()}f("#newcat").one("focus",function(){f(this).val("").removeClass("form-input-tip")});f("#category-add-sumbit").click(function(){f("#newcat").focus()});catAddBefore=function(j){if(!f("#newcat").val()){return false}j.data+="&"+f(":checked","#categorychecklist").serialize();return j};d=function(m,l){var k,j=f("#newcat_parent");if("undefined"!=l.parsed.responses[0]&&(k=l.parsed.responses[0].supplemental.newcat_parent)){j.before(k);j.remove()}};f("#categorychecklist").wpList({alt:"",response:"category-ajax-response",addBefore:catAddBefore,addAfter:d});f("#category-add-toggle").click(function(){f("#category-adder").toggleClass("wp-hidden-children");f('a[href="#categories-all"]',"#category-tabs").click();return false});f("#categorychecklist").children("li.popular-category").add(f("#categorychecklist-pop").children()).find(":checkbox").live("click",function(){var j=f(this),l=j.is(":checked"),k=j.val();f("#in-category-"+k+", #in-popular-category-"+k).attr("checked",l)})}if(f("#postcustom").length){f("#the-list").wpList({addAfter:function(j,k){f("table#list-table").show();if(typeof(autosave_update_post_ID)!="undefined"){autosave_update_post_ID(k.parsed.responses[0].supplemental.postid)}},addBefore:function(j){j.data+="&post_id="+f("#post_ID").val();return j}})}if(f("#submitdiv").length){a=f("#timestamp").html();b=f("#post-visibility-display").html();function e(){var j=f("#post-visibility-select");if(f("input:radio:checked",j).val()!="public"){f("#sticky").attr("checked",false);f("#sticky-span").hide()}else{f("#sticky-span").show()}if(f("input:radio:checked",j).val()!="password"){f("#password-span").hide()}else{f("#password-span").show()}}function c(){var q,r,k,t,s=f("#post_status"),l=f("option[value=publish]",s),j=f("#aa").val(),o=f("#mm").val(),p=f("#jj").val(),n=f("#hh").val(),m=f("#mn").val();q=new Date(j,o-1,p,n,m);r=new Date(f("#hidden_aa").val(),f("#hidden_mm").val()-1,f("#hidden_jj").val(),f("#hidden_hh").val(),f("#hidden_mn").val());k=new Date(f("#cur_aa").val(),f("#cur_mm").val()-1,f("#cur_jj").val(),f("#cur_hh").val(),f("#cur_mn").val());if(q.getFullYear()!=j||(1+q.getMonth())!=o||q.getDate()!=p||q.getMinutes()!=m){f(".timestamp-wrap","#timestampdiv").addClass("form-invalid");return false}else{f(".timestamp-wrap","#timestampdiv").removeClass("form-invalid")}if(q>k&&f("#original_post_status").val()!="future"){t=postL10n.publishOnFuture;f("#publish").val(postL10n.schedule)}else{if(q<=k&&f("#original_post_status").val()!="publish"){t=postL10n.publishOn;f("#publish").val(postL10n.publish)}else{t=postL10n.publishOnPast;if(g){f("#publish").val(postL10n.updatePage)}else{f("#publish").val(postL10n.updatePost)}}}if(r.toUTCString()==q.toUTCString()){f("#timestamp").html(a)}else{f("#timestamp").html(t+" "+f("option[value="+f("#mm").val()+"]","#mm").text()+" "+p+", "+j+" @ "+n+":"+m+" ")}if(f("input:radio:checked","#post-visibility-select").val()=="private"){if(g){f("#publish").val(postL10n.updatePage)}else{f("#publish").val(postL10n.updatePost)}if(l.length==0){s.append('")}else{l.html(postL10n.privatelyPublished)}f("option[value=publish]",s).attr("selected",true);f(".edit-post-status","#misc-publishing-actions").hide()}else{if(f("#original_post_status").val()=="future"||f("#original_post_status").val()=="draft"){if(l.length){l.remove();s.val(f("#hidden_post_status").val())}}else{l.html(postL10n.published)}if(s.is(":hidden")){f(".edit-post-status","#misc-publishing-actions").show()}}f("#post-status-display").html(f("option:selected",s).text());if(f("option:selected",s).val()=="private"||f("option:selected",s).val()=="publish"){f("#save-post").hide()}else{f("#save-post").show();if(f("option:selected",s).val()=="pending"){f("#save-post").show().val(postL10n.savePending)}else{f("#save-post").show().val(postL10n.saveDraft)}}return true}f(".edit-visibility","#visibility").click(function(){if(f("#post-visibility-select").is(":hidden")){e();f("#post-visibility-select").slideDown("normal");f(this).hide()}return false});f(".cancel-post-visibility","#post-visibility-select").click(function(){f("#post-visibility-select").slideUp("normal");f("#visibility-radio-"+f("#hidden-post-visibility").val()).attr("checked",true);f("#post_password").val(f("#hidden_post_password").val());f("#sticky").attr("checked",f("#hidden-post-sticky").attr("checked"));f("#post-visibility-display").html(b);f(".edit-visibility","#visibility").show();c();return false});f(".save-post-visibility","#post-visibility-select").click(function(){var j=f("#post-visibility-select");j.slideUp("normal");f(".edit-visibility","#visibility").show();c();if(f("input:radio:checked",j).val()!="public"){f("#sticky").attr("checked",false)}if(true==f("#sticky").attr("checked")){h="Sticky"}else{h=""}f("#post-visibility-display").html(postL10n[f("input:radio:checked",j).val()+h]);return false});f("input:radio","#post-visibility-select").change(function(){e()});f("#timestampdiv").siblings("a.edit-timestamp").click(function(){if(f("#timestampdiv").is(":hidden")){f("#timestampdiv").slideDown("normal");f(this).hide()}return false});f(".cancel-timestamp","#timestampdiv").click(function(){f("#timestampdiv").slideUp("normal");f("#mm").val(f("#hidden_mm").val());f("#jj").val(f("#hidden_jj").val());f("#aa").val(f("#hidden_aa").val());f("#hh").val(f("#hidden_hh").val());f("#mn").val(f("#hidden_mn").val());f("#timestampdiv").siblings("a.edit-timestamp").show();c();return false});f(".save-timestamp","#timestampdiv").click(function(){if(c()){f("#timestampdiv").slideUp("normal");f("#timestampdiv").siblings("a.edit-timestamp").show()}return false});f("#post-status-select").siblings("a.edit-post-status").click(function(){if(f("#post-status-select").is(":hidden")){f("#post-status-select").slideDown("normal");f(this).hide()}return false});f(".save-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("normal");f("#post-status-select").siblings("a.edit-post-status").show();c();return false});f(".cancel-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("normal");f("#post_status").val(f("#hidden_post_status").val());f("#post-status-select").siblings("a.edit-post-status").show();c();return false})}if(f("#edit-slug-box").length){editPermalink=function(j){var k,n=0,m=f("#editable-post-name"),o=m.html(),r=f("#post_name"),s=r.html(),p=f("#edit-slug-buttons"),q=p.html(),l=f("#editable-post-name-full").html();f("#view-post-btn").hide();p.html(''+postL10n.ok+' '+postL10n.cancel+"");p.children(".save").click(function(){var t=m.children("input").val();f.post(ajaxurl,{action:"sample-permalink",post_id:j,new_slug:t,new_title:f("#title").val(),samplepermalinknonce:f("#samplepermalinknonce").val()},function(u){f("#edit-slug-box").html(u);p.html(q);r.attr("value",t);makeSlugeditClickable();f("#view-post-btn").show()});return false});f(".cancel","#edit-slug-buttons").click(function(){f("#view-post-btn").show();m.html(o);p.html(q);r.attr("value",s);return false});for(k=0;kl.length/4)?"":l;m.html('').children("input").keypress(function(u){var t=u.keyCode||0;if(13==t){p.children(".save").click();return false}if(27==t){p.children(".cancel").click();return false}r.attr("value",this.value)}).focus()};makeSlugeditClickable=function(){f("#editable-post-name").click(function(){f("#edit-slug-buttons").children(".edit-slug").click()})};makeSlugeditClickable()}}); \ No newline at end of file diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php index df97ad6ac..f7379e6af 100644 --- a/wp-admin/menu-header.php +++ b/wp-admin/menu-header.php @@ -45,7 +45,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { if ( !empty($submenu[$item[2]]) ) $class[] = 'wp-has-submenu'; - if ( ( $parent_file && $item[2] == $parent_file ) || strcmp($self, $item[2]) == 0 ) { + if ( ( $parent_file && $item[2] == $parent_file ) || ( false === strpos($parent_file, '?') && strcmp($self, $item[2]) == 0 ) ) { if ( !empty($submenu[$item[2]]) ) $class[] = 'wp-has-current-submenu wp-menu-open'; else diff --git a/wp-admin/menu.php b/wp-admin/menu.php index cac2be509..e34aa1ccc 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -65,6 +65,25 @@ $menu[25] = array( sprintf( __('Comments %s'), " true) ) as $ptype ) { + $_wp_last_object_menu++; + $ptype_obj = get_post_type_object($ptype); + $menu[$_wp_last_object_menu] = array(esc_attr($ptype_obj->label), 'edit_' . $ptype_obj->capability_type . 's', "edit.php?post_type=$ptype", '', 'menu-top', 'menu-posts', 'div'); + $submenu["edit.php?post_type=$ptype"][5] = array( __('Edit'), 'edit_posts', "edit.php?post_type=$ptype"); + /* translators: add new custom post type */ + $submenu["edit.php?post_type=$ptype"][10] = array( _x('Add New', 'post'), 'edit_posts', "post-new.php?post_type=$ptype" ); + + $i = 15; + foreach ( $wp_taxonomies as $tax ) { + if ( $tax->hierarchical || ! in_array($ptype, (array) $tax->object_type, true) ) + continue; + + $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&post_type=$ptype" ); + ++$i; + } +} +unset($ptype, $ptype_obj); + $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); $menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' ); diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 229f3d06c..1776329f1 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -8,8 +8,24 @@ /** Load WordPress Administration Bootstrap */ require_once('admin.php'); -$title = __('Add New Post'); -$parent_file = 'edit.php'; + +if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) ) + $post_type = $_GET['post_type']; +else + $post_type = 'post'; + +if ( 'post' != $post_type ) { + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "post-new.php?post_type=$post_type"; +} else { + $parent_file = 'edit.php'; + $submenu_file = 'post-new.php'; +} + +$post_type_object = get_post_type_object($post_type); + +$title = sprintf(__('Add New %s'), $post_type_object->label); + $editing = true; wp_enqueue_script('autosave'); wp_enqueue_script('post'); @@ -34,6 +50,7 @@ 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'); include('admin-footer.php'); diff --git a/wp-admin/post.php b/wp-admin/post.php index a8ccddaed..08596e594 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -126,6 +126,7 @@ case 'edit': } $post_ID = $p = (int) $_GET['post']; $post = get_post($post_ID); + $post_type_object = get_post_type_object($post->post_type); if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') ); @@ -136,11 +137,20 @@ case 'edit': if ( 'trash' == $post->post_status ) wp_die( __('You can’t edit this post because it is in the Trash. Please restore it and try again.') ); - if ( 'post' != $post->post_type ) { + if ( null == $post_type_object ) + wp_die( __('Unknown post type.') ); + + if ( 'post' != $post->post_type && $post_type_object->_builtin ) { wp_redirect( get_edit_post_link( $post->ID, 'url' ) ); exit(); } + $post_type = $post->post_type; + if ( 'post' != $post_type ) { + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "edit.php?post_type=$post_type"; + } + wp_enqueue_script('post'); if ( user_can_richedit() ) wp_enqueue_script('editor'); @@ -157,7 +167,7 @@ case 'edit': wp_enqueue_script('autosave'); } - $title = __('Edit Post'); + $title = sprintf(__('Edit %s'), $post_type_object->label); $post = get_post_to_edit($post_ID); include('edit-form-advanced.php'); diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 60374374b..ca6fedad3 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -779,8 +779,9 @@ function map_meta_cap( $cap, $user_id ) { $author_data = get_userdata( $user_id ); //echo "post ID: {$args[0]}
    "; $post = get_post( $args[0] ); - if ( 'page' == $post->post_type ) { - $args = array_merge( array( 'delete_page', $user_id ), $args ); + $post_type = get_post_type_object( $post->post_type ); + if ( $post_type && 'post' != $post_type->capability_type ) { + $args = array_merge( array( 'delete_' . $post_type->capability_type, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } @@ -855,8 +856,9 @@ function map_meta_cap( $cap, $user_id ) { $author_data = get_userdata( $user_id ); //echo "post ID: {$args[0]}
    "; $post = get_post( $args[0] ); - if ( 'page' == $post->post_type ) { - $args = array_merge( array( 'edit_page', $user_id ), $args ); + $post_type = get_post_type_object( $post->post_type ); + if ( $post_type && 'post' != $post_type->capability_type ) { + $args = array_merge( array( 'edit_' . $post_type->capability_type, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } $post_author_data = get_userdata( $post->post_author ); @@ -913,8 +915,9 @@ function map_meta_cap( $cap, $user_id ) { break; case 'read_post': $post = get_post( $args[0] ); - if ( 'page' == $post->post_type ) { - $args = array_merge( array( 'read_page', $user_id ), $args ); + $post_type = get_post_type_object( $post->post_type ); + if ( $post_type && 'post' != $post_type->capability_type ) { + $args = array_merge( array( 'read_' . $post_type->capability_type, $user_id ), $args ); return call_user_func_array( 'map_meta_cap', $args ); } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 83e3a998b..0937e818e 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -678,39 +678,18 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { return; if ( 'display' == $context ) - $action = 'action=edit&'; + $action = '&action=edit'; else - $action = 'action=edit&'; + $action = '&action=edit'; - switch ( $post->post_type ) : - case 'page' : - if ( !current_user_can( 'edit_page', $post->ID ) ) - return; - $file = 'page'; - $var = 'post'; - break; - case 'attachment' : - if ( !current_user_can( 'edit_post', $post->ID ) ) - return; - $file = 'media'; - $var = 'attachment_id'; - break; - case 'revision' : - if ( !current_user_can( 'edit_post', $post->ID ) ) - return; - $file = 'revision'; - $var = 'revision'; - $action = ''; - break; - default : - if ( !current_user_can( 'edit_post', $post->ID ) ) - return apply_filters( 'get_edit_post_link', '', $post->ID, $context ); - $file = 'post'; - $var = 'post'; - break; - endswitch; + $post_type_object = get_post_type_object( $post->post_type ); + if ( !$post_type_object ) + return; - return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context ); + if ( !current_user_can( $post_type_object->edit_cap, $post->ID ) ) + return; + + return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context ); } /** diff --git a/wp-includes/post.php b/wp-includes/post.php index 4e8bc7e9a..ed5441df9 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -15,10 +15,10 @@ * Creates the initial post types when 'init' action is fired. */ function create_initial_post_types() { - register_post_type( 'post', array('exclude_from_search' => false) ); - register_post_type( 'page', array('exclude_from_search' => false) ); - register_post_type( 'attachment', array('exclude_from_search' => false) ); - register_post_type( 'revision', array('exclude_from_search' => true) ); + register_post_type( 'post', array('label' => __('Posts'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false) ); + register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'page.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) ); + register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false) ); + register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) ); } add_action( 'init', 'create_initial_post_types', 0 ); // highest priority @@ -441,6 +441,28 @@ function get_post_type($post = false) { return false; } +/** + * Retrieve a post type object by name + * + * @package WordPress + * @subpackage Post + * @since 3.0 + * @uses $wp_post_types + * @see register_post_type + * @see get_post_types + * + * @param string $post_type The name of a registered post type + * @return object A post type object + */ +function get_post_type_object( $post_type ) { + global $wp_post_types; + + if ( empty($wp_post_types[$post_type]) ) + return null; + + return $wp_post_types[$post_type]; +} + /** * Get a list of all registered post type objects. * @@ -491,7 +513,12 @@ function get_post_types( $args = array(), $output = 'names' ) { * * Optional $args contents: * + * label - A descriptive name for the post type marked for translation. Defaults to $post_type. + * public - Whether posts of this type should be shown in the admin UI. Defaults to true. * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true. + * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. + * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". + * hierarchical - Whether the post type is hierarchical. Defaults to false. * * @package WordPress * @subpackage Post @@ -507,12 +534,31 @@ function register_post_type($post_type, $args = array()) { if (!is_array($wp_post_types)) $wp_post_types = array(); - $defaults = array('exclude_from_search' => true); + // Args prefixed with an underscore are reserved for internal use. + $defaults = array('label' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false); $args = wp_parse_args($args, $defaults); + $args = (object) $args; $post_type = sanitize_user($post_type, true); - $args['name'] = $post_type; - $wp_post_types[$post_type] = (object) $args; + $args->name = $post_type; + + if ( false === $args->label ) + $args->label = $post_type; + + if ( empty($args->capability_type) ) { + $args->edit_cap = ''; + $args->read_cap = ''; + } else { + $args->edit_cap = 'edit_' . $args->capability_type; + $args->read_cap = 'read_' . $args->capability_type; + } + + if ( !$args->_builtin && $args->public ) + $args->_show = true; + + $wp_post_types[$post_type] = $args; + + return $args; } /** @@ -1018,7 +1064,8 @@ function wp_count_posts( $type = 'post', $perm = '' ) { $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; if ( 'readable' == $perm && is_user_logged_in() ) { - if ( !current_user_can("read_private_{$type}s") ) { + $post_type_object = get_post_type_object($type); + if ( !current_user_can("read_private_{$post_type_object->capability_type}s") ) { $cache_key .= '_' . $perm . '_' . $user->ID; $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 7684b8c87..801336015 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2062,8 +2062,13 @@ class WP_Query { if ( is_array($post_type) ) $post_type_cap = 'multiple_post_type'; - else - $post_type_cap = $post_type; + else { + $post_type_object = get_post_type_object ( $post_type ); + if ( !empty($post_type_object) ) + $post_type_cap = $post_type_object->capability_type; + else + $post_type_cap = $post_type; + } $exclude_post_types = ''; foreach ( get_post_types( array('exclude_from_search' => true) ) as $_wp_post_type ) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 0a82eabb2..d88374bbf 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -180,20 +180,46 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { $wp->add_query_var($args['query_var']); } - if ( false !== $args['rewrite'] && !empty($wp_rewrite) ) { + if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) { if ( !is_array($args['rewrite']) ) $args['rewrite'] = array(); if ( !isset($args['rewrite']['slug']) ) $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=$term"); - $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%"); + $wp_rewrite->add_permastruct($taxonomy, "/{$args['rewrite']['slug']}/%$taxonomy%"); } $args['name'] = $taxonomy; - $args['object_type'] = $object_type; + $args['object_type'] = (array) $object_type; $wp_taxonomies[$taxonomy] = (object) $args; } +/** + * Add an already registered taxonomy to an object type. + * + * @package WordPress + * @subpackage Taxonomy + * @since 3.0 + * @uses $wp_taxonomies Modifies taxonomy object + * + * @param string $taxonomy Name of taxonomy object + * @param array|string $object_type Name of the object type + * @return bool True if successful, false if not + */ +function register_taxonomy_for_object_type( $taxonomy, $object_type) { + global $wp_taxonomies; + + if ( !isset($wp_taxonomies[$taxonomy]) ) + return false; + + if ( ! get_post_type_object($object_type) ) + return false; + + $wp_taxonomies[$taxonomy]->object_type[] = $object_type; + + return true; +} + // // Term API // @@ -2378,4 +2404,26 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { return false; } +/** + * Determine if the given object type is associated with the given taxonomy. + * + * @since 3.0 + * @uses get_object_taxonomies() + * + * @param string $object_type Object type string + * @param string $taxonomy. Single taxonomy name + * @return bool True if object is associated with the taxonomy, otherwise false. + */ +function is_object_in_taxonomy($object_type, $taxonomy) { + $taxonomies = get_object_taxonomies($object_type); + + if ( empty($taxonomies) ) + return false; + + if ( in_array($taxonomy, $taxonomies) ) + return true; + + return false; +} + ?>