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

git-svn-id: http://svn.automattic.com/wordpress/trunk@12597 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-01-04 16:58:43 +00:00
parent e51341dc1d
commit da89de4958
20 changed files with 292 additions and 102 deletions

View File

@ -1135,7 +1135,7 @@ case 'inline-save':
if ( 'page' == $_POST['post_type'] ) { if ( 'page' == $_POST['post_type'] ) {
$post[] = get_post($_POST['post_ID']); $post[] = get_post($_POST['post_ID']);
page_rows($post); 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']; $mode = $_POST['post_view'];
$post[] = get_post($_POST['post_ID']); $post[] = get_post($_POST['post_ID']);
post_rows($post); post_rows($post);

View File

@ -35,13 +35,20 @@ else if ( isset($plugin_page) )
else if ( isset($pagenow) ) else if ( isset($pagenow) )
$hook_suffix = $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); $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
?> ?>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time() ?>'}; var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time() ?>'};
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = '<?php echo substr($pagenow, 0, -4); ?>', adminpage = '<?php echo $admin_body_class; ?>', thousandsSeparator = '<?php echo $wp_locale->number_format['thousands_sep']; ?>', decimalPoint = '<?php echo $wp_locale->number_format['decimal_point']; ?>'; var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = '<?php echo substr($pagenow, 0, -4); ?>', typenow = '<?php echo $typenow; ?>', adminpage = '<?php echo $admin_body_class; ?>', thousandsSeparator = '<?php echo $wp_locale->number_format['thousands_sep']; ?>', decimalPoint = '<?php echo $wp_locale->number_format['decimal_point']; ?>';
//]]> //]]>
</script> </script>
<?php <?php

View File

@ -85,45 +85,46 @@ if ( 0 == $post_ID ) {
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action). // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
require_once('includes/meta-boxes.php'); require_once('includes/meta-boxes.php');
add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'post', 'side', 'core'); add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'side', 'core');
// all tag-style post taxonomies // all tag-style post taxonomies
foreach ( get_object_taxonomies('post') as $tax_name ) { foreach ( get_object_taxonomies($post_type) as $tax_name ) {
if ( !is_taxonomy_hierarchical($tax_name) ) { if ( !is_taxonomy_hierarchical($tax_name) ) {
$taxonomy = get_taxonomy($tax_name); $taxonomy = get_taxonomy($tax_name);
$label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name; $label = isset($taxonomy->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 ( is_object_in_taxonomy($post_type, 'category') )
if ( current_theme_supports( 'post-thumbnails', 'post' ) ) add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', 'post', 'side', 'low'); if ( current_theme_supports( 'post-thumbnails', $post_type ) )
add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core'); add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core'); add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', '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'); 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 ) 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' ) ) ) 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 $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
if ( $post->post_author && !in_array($post->post_author, $authors) ) if ( $post->post_author && !in_array($post->post_author, $authors) )
$authors[] = $post->post_author; $authors[] = $post->post_author;
if ( $authors && count( $authors ) > 1 ) 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 ) ) 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_type, 'normal', $post);
do_action('do_meta_boxes', 'post', 'advanced', $post); do_action('do_meta_boxes', $post_type, 'advanced', $post);
do_action('do_meta_boxes', 'post', 'side', $post); do_action('do_meta_boxes', $post_type, 'side', $post);
require_once('admin-header.php'); require_once('admin-header.php');
@ -152,7 +153,7 @@ else
<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr($form_action) ?>" /> <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr($form_action) ?>" />
<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr($form_action) ?>" /> <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr($form_action) ?>" />
<input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr($post->post_type) ?>" /> <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr($post_type) ?>" />
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr($post->post_status) ?>" /> <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr($post->post_status) ?>" />
<input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" /> <input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" />
<?php <?php
@ -166,7 +167,7 @@ echo $form_extra ?>
<?php do_action('submitpost_box'); ?> <?php do_action('submitpost_box'); ?>
<?php $side_meta_boxes = do_meta_boxes('post', 'side', $post); ?> <?php $side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
</div> </div>
<div id="post-body"> <div id="post-body">
@ -223,11 +224,11 @@ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
<?php <?php
do_meta_boxes('post', 'normal', $post); do_meta_boxes($post_type, 'normal', $post);
do_action('edit_form_advanced'); do_action('edit_form_advanced');
do_meta_boxes('post', 'advanced', $post); do_meta_boxes($post_type, 'advanced', $post);
do_action('dbx_post_sidebar'); ?> do_action('dbx_post_sidebar'); ?>

View File

@ -19,8 +19,18 @@ if ( empty($taxonomy) )
if ( !is_taxonomy($taxonomy) ) if ( !is_taxonomy($taxonomy) )
wp_die(__('Invalid taxonomy')); wp_die(__('Invalid taxonomy'));
$parent_file = 'edit.php'; if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('_show' => true) ) ) )
$submenu_file = "edit-tags.php?taxonomy=$taxonomy"; $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'] ) ) if ( isset( $_GET['action'] ) && isset($_GET['delete_tags']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
$action = 'bulk-delete'; $action = 'bulk-delete';

View File

@ -20,17 +20,34 @@ if ( $_redirect = intval( max( @$_GET['p'], @$_GET['attachment_id'], @$_GET['pag
unset( $_redirect ); 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 // Handle bulk actions
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) { if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
check_admin_referer('bulk-posts'); check_admin_referer('bulk-posts');
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
if ( strpos($sendback, 'post.php') !== false ) 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']) ) { if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']); $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'; $doaction = 'delete';
} elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) { } 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']); $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; exit;
} }
if ( empty($title) ) $title = sprintf(__('Edit %s'), $post_type_object->label);
$title = __('Edit Posts');
$parent_file = 'edit.php';
wp_enqueue_script('inline-edit-post'); wp_enqueue_script('inline-edit-post');
$user_posts = false; $user_posts = false;
if ( !current_user_can('edit_others_posts') ) { 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; $user_posts = true;
if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) ) if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) )
$_GET['author'] = $current_user->ID; $_GET['author'] = $current_user->ID;
@ -134,7 +150,7 @@ else
<div class="wrap"> <div class="wrap">
<?php screen_icon(); ?> <?php screen_icon(); ?>
<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 <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
if ( isset($_GET['s']) && $_GET['s'] ) if ( isset($_GET['s']) && $_GET['s'] )
printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?> printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
</h2> </h2>
@ -188,7 +204,7 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated'
<?php <?php
if ( empty($locked_post_status) ) : if ( empty($locked_post_status) ) :
$status_links = array(); $status_links = array();
$num_posts = wp_count_posts( 'post', 'readable' ); $num_posts = wp_count_posts( $post_type, 'readable' );
$class = ''; $class = '';
$allposts = ''; $allposts = '';
@ -215,7 +231,7 @@ foreach ( $post_stati as $status => $label ) {
if ( isset($_GET['post_status']) && $status == $_GET['post_status'] ) if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
$class = ' class="current"'; $class = ' class="current"';
$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>'; $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>';
} }
echo implode( " |</li>\n", $status_links ) . '</li>'; echo implode( " |</li>\n", $status_links ) . '</li>';
unset( $status_links ); unset( $status_links );
@ -230,6 +246,7 @@ endif;
</p> </p>
<input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" /> <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" />
<input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
<input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" /> <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
<?php if ( have_posts() ) { ?> <?php if ( have_posts() ) { ?>
@ -267,7 +284,7 @@ $is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash';
<?php // view filters <?php // view filters
if ( !is_singular() ) { if ( !is_singular() ) {
$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"; $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 ); $arc_result = $wpdb->get_results( $arc_query );

View File

@ -13,7 +13,9 @@ function post_submit_meta_box($post) {
global $action; global $action;
$post_type = $post->post_type; $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");
?> ?>
<div class="submitbox" id="submitpost"> <div class="submitbox" id="submitpost">
@ -184,7 +186,7 @@ if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
<?php do_action('post_submitbox_start'); ?> <?php do_action('post_submitbox_start'); ?>
<div id="delete-action"> <div id="delete-action">
<?php <?php
if ( current_user_can( "delete_${post_type}", $post->ID ) ) { if ( current_user_can( "delete_${type_cap}", $post->ID ) ) {
if ( !EMPTY_TRASH_DAYS ) { if ( !EMPTY_TRASH_DAYS ) {
$delete_url = wp_nonce_url( add_query_arg( array('action' => 'delete', 'post' => $post->ID) ), "delete-${post_type}_{$post->ID}" ); $delete_url = wp_nonce_url( add_query_arg( array('action' => 'delete', 'post' => $post->ID) ), "delete-${post_type}_{$post->ID}" );
$delete_text = __('Delete Permanently'); $delete_text = __('Delete Permanently');

View File

@ -745,14 +745,15 @@ function get_admin_page_parent( $parent = '' ) {
$parent = $_wp_real_parent_file[$parent]; $parent = $_wp_real_parent_file[$parent];
return $parent; return $parent;
} }
/*
/*
if ( !empty ( $parent_file ) ) { if ( !empty ( $parent_file ) ) {
if ( isset( $_wp_real_parent_file[$parent_file] ) ) if ( isset( $_wp_real_parent_file[$parent_file] ) )
$parent_file = $_wp_real_parent_file[$parent_file]; $parent_file = $_wp_real_parent_file[$parent_file];
return $parent_file; return $parent_file;
} }
*/ */
if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {
foreach ( (array)$menu as $parent_menu ) { foreach ( (array)$menu as $parent_menu ) {
@ -782,7 +783,7 @@ function get_admin_page_parent( $parent = '' ) {
foreach ( $submenu[$parent] as $submenu_array ) { foreach ( $submenu[$parent] as $submenu_array ) {
if ( isset( $_wp_real_parent_file[$parent] ) ) if ( isset( $_wp_real_parent_file[$parent] ) )
$parent = $_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; $parent_file = $parent;
return $parent; return $parent;
} else } else

View File

@ -846,12 +846,17 @@ function wp_edit_posts_query( $q = false ) {
$orderby = 'date'; $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 ); $posts_per_page = (int) get_user_option( 'edit_per_page', 0, false );
if ( empty( $posts_per_page ) || $posts_per_page < 1 ) if ( empty( $posts_per_page ) || $posts_per_page < 1 )
$posts_per_page = 15; $posts_per_page = 15;
$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page ); $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); return array($post_stati, $avail_post_stati);
} }

View File

@ -3482,7 +3482,7 @@ function _post_states($post) {
} }
function screen_meta($screen) { 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('.php', '', $screen);
$screen = str_replace('-new', '', $screen); $screen = str_replace('-new', '', $screen);
@ -3492,6 +3492,12 @@ function screen_meta($screen) {
$column_screens = get_column_headers($screen); $column_screens = get_column_headers($screen);
$meta_screens = array('index' => 'dashboard'); $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]) ) if ( isset($meta_screens[$screen]) )
$screen = $meta_screens[$screen]; $screen = $meta_screens[$screen];
$show_screen = false; $show_screen = false;
@ -3675,6 +3681,11 @@ function screen_layout($screen) {
global $screen_layout_columns; global $screen_layout_columns;
$columns = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2); $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); $columns = apply_filters('screen_layout_columns', $columns, $screen);
if ( !isset($columns[$screen]) ) { if ( !isset($columns[$screen]) ) {
@ -3754,8 +3765,12 @@ function screen_icon($name = '') {
global $parent_file, $hook_suffix; global $parent_file, $hook_suffix;
if ( empty($name) ) { if ( empty($name) ) {
if ( isset($parent_file) && !empty($parent_file) ) if ( isset($parent_file) && !empty($parent_file) ) {
$name = substr($parent_file, 0, -4); $name = $parent_file;
if ( false !== $pos = strpos($name, '?post_type=') )
$name = substr($name, 0, $pos);
$name = substr($name, 0, -4);
}
else else
$name = str_replace(array('.php', '-new', '-add'), '', $hook_suffix); $name = str_replace(array('.php', '-new', '-add'), '', $hook_suffix);
} }

View File

@ -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; var catAddAfter, stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow;
// postboxes // postboxes
if ( post ) if ( post ) {
postboxes.add_postbox_toggles('post'); type = 'post';
else if ( page ) if ( typenow )
type = typenow;
postboxes.add_postbox_toggles(type);
} else if ( page ) {
postboxes.add_postbox_toggles('page'); postboxes.add_postbox_toggles('page');
}
// multi-taxonomies // multi-taxonomies
if ( $('#tagsdiv-post_tag').length ) { if ( $('#tagsdiv-post_tag').length ) {

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
if ( !empty($submenu[$item[2]]) ) if ( !empty($submenu[$item[2]]) )
$class[] = 'wp-has-submenu'; $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]]) ) if ( !empty($submenu[$item[2]]) )
$class[] = 'wp-has-current-submenu wp-menu-open'; $class[] = 'wp-has-current-submenu wp-menu-open';
else else

View File

@ -65,6 +65,25 @@ $menu[25] = array( sprintf( __('Comments %s'), "<span id='awaiting-mod' class='c
$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group $_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
foreach ( (array) get_post_types( array('_show' => 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&amp;post_type=$ptype" );
++$i;
}
}
unset($ptype, $ptype_obj);
$menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' ); $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' );
$menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' ); $menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top', 'menu-appearance', 'div' );

View File

@ -8,8 +8,24 @@
/** Load WordPress Administration Bootstrap */ /** Load WordPress Administration Bootstrap */
require_once('admin.php'); 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; $editing = true;
wp_enqueue_script('autosave'); wp_enqueue_script('autosave');
wp_enqueue_script('post'); wp_enqueue_script('post');
@ -34,6 +50,7 @@ When you&#8217;re promoted, just reload this page and you&#8217;ll be able to bl
// Show post form. // Show post form.
$post = get_default_post_to_edit(); $post = get_default_post_to_edit();
$post->post_type = $post_type;
include('edit-form-advanced.php'); include('edit-form-advanced.php');
include('admin-footer.php'); include('admin-footer.php');

View File

@ -126,6 +126,7 @@ case 'edit':
} }
$post_ID = $p = (int) $_GET['post']; $post_ID = $p = (int) $_GET['post'];
$post = get_post($post_ID); $post = get_post($post_ID);
$post_type_object = get_post_type_object($post->post_type);
if ( empty($post->ID) ) if ( empty($post->ID) )
wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') ); wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
@ -136,11 +137,20 @@ case 'edit':
if ( 'trash' == $post->post_status ) if ( 'trash' == $post->post_status )
wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please restore it and try again.') ); wp_die( __('You can&#8217;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' ) ); wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
exit(); 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'); wp_enqueue_script('post');
if ( user_can_richedit() ) if ( user_can_richedit() )
wp_enqueue_script('editor'); wp_enqueue_script('editor');
@ -157,7 +167,7 @@ case 'edit':
wp_enqueue_script('autosave'); wp_enqueue_script('autosave');
} }
$title = __('Edit Post'); $title = sprintf(__('Edit %s'), $post_type_object->label);
$post = get_post_to_edit($post_ID); $post = get_post_to_edit($post_ID);
include('edit-form-advanced.php'); include('edit-form-advanced.php');

View File

@ -779,8 +779,9 @@ function map_meta_cap( $cap, $user_id ) {
$author_data = get_userdata( $user_id ); $author_data = get_userdata( $user_id );
//echo "post ID: {$args[0]}<br />"; //echo "post ID: {$args[0]}<br />";
$post = get_post( $args[0] ); $post = get_post( $args[0] );
if ( 'page' == $post->post_type ) { $post_type = get_post_type_object( $post->post_type );
$args = array_merge( array( 'delete_page', $user_id ), $args ); 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 ); 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 ); $author_data = get_userdata( $user_id );
//echo "post ID: {$args[0]}<br />"; //echo "post ID: {$args[0]}<br />";
$post = get_post( $args[0] ); $post = get_post( $args[0] );
if ( 'page' == $post->post_type ) { $post_type = get_post_type_object( $post->post_type );
$args = array_merge( array( 'edit_page', $user_id ), $args ); 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 ); return call_user_func_array( 'map_meta_cap', $args );
} }
$post_author_data = get_userdata( $post->post_author ); $post_author_data = get_userdata( $post->post_author );
@ -913,8 +915,9 @@ function map_meta_cap( $cap, $user_id ) {
break; break;
case 'read_post': case 'read_post':
$post = get_post( $args[0] ); $post = get_post( $args[0] );
if ( 'page' == $post->post_type ) { $post_type = get_post_type_object( $post->post_type );
$args = array_merge( array( 'read_page', $user_id ), $args ); 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 ); return call_user_func_array( 'map_meta_cap', $args );
} }

View File

@ -678,39 +678,18 @@ function get_edit_post_link( $id = 0, $context = 'display' ) {
return; return;
if ( 'display' == $context ) if ( 'display' == $context )
$action = 'action=edit&amp;'; $action = '&amp;action=edit';
else else
$action = 'action=edit&'; $action = '&action=edit';
switch ( $post->post_type ) : $post_type_object = get_post_type_object( $post->post_type );
case 'page' : if ( !$post_type_object )
if ( !current_user_can( 'edit_page', $post->ID ) ) return;
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;
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 );
} }
/** /**

View File

@ -15,10 +15,10 @@
* Creates the initial post types when 'init' action is fired. * Creates the initial post types when 'init' action is fired.
*/ */
function create_initial_post_types() { function create_initial_post_types() {
register_post_type( 'post', array('exclude_from_search' => false) ); 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('exclude_from_search' => 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('exclude_from_search' => false) ); 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('exclude_from_search' => true) ); 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 add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
@ -441,6 +441,28 @@ function get_post_type($post = false) {
return 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. * Get a list of all registered post type objects.
* *
@ -491,7 +513,12 @@ function get_post_types( $args = array(), $output = 'names' ) {
* *
* Optional $args contents: * 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. * 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 * @package WordPress
* @subpackage Post * @subpackage Post
@ -507,12 +534,31 @@ function register_post_type($post_type, $args = array()) {
if (!is_array($wp_post_types)) if (!is_array($wp_post_types))
$wp_post_types = array(); $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 = wp_parse_args($args, $defaults);
$args = (object) $args;
$post_type = sanitize_user($post_type, true); $post_type = sanitize_user($post_type, true);
$args['name'] = $post_type; $args->name = $post_type;
$wp_post_types[$post_type] = (object) $args;
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"; $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ( 'readable' == $perm && is_user_logged_in() ) { 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; $cache_key .= '_' . $perm . '_' . $user->ID;
$query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))";
} }

View File

@ -2062,8 +2062,13 @@ class WP_Query {
if ( is_array($post_type) ) if ( is_array($post_type) )
$post_type_cap = 'multiple_post_type'; $post_type_cap = 'multiple_post_type';
else else {
$post_type_cap = $post_type; $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 = ''; $exclude_post_types = '';
foreach ( get_post_types( array('exclude_from_search' => true) ) as $_wp_post_type ) foreach ( get_post_types( array('exclude_from_search' => true) ) as $_wp_post_type )

View File

@ -180,20 +180,46 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$wp->add_query_var($args['query_var']); $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']) ) if ( !is_array($args['rewrite']) )
$args['rewrite'] = array(); $args['rewrite'] = array();
if ( !isset($args['rewrite']['slug']) ) if ( !isset($args['rewrite']['slug']) )
$args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); $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_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['name'] = $taxonomy;
$args['object_type'] = $object_type; $args['object_type'] = (array) $object_type;
$wp_taxonomies[$taxonomy] = (object) $args; $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 // Term API
// //
@ -2378,4 +2404,26 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) {
return false; 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;
}
?> ?>