Introduce _draft_or_post_title() instead of lots of duplicated (no title) code. Fixes #7801.

git-svn-id: https://develop.svn.wordpress.org/trunk@9041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Westwood 2008-09-30 21:32:13 +00:00
parent cfbb4437e2
commit c6fae90a40
3 changed files with 22 additions and 18 deletions

View File

@ -30,9 +30,7 @@ while (have_posts()) : the_post();
$class = 'alternate' == $class ? '' : 'alternate';
global $current_user;
$post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
$att_title = get_the_title();
if ( empty($att_title) )
$att_title = __('(no title)');
$att_title = _draft_or_post_title();
?>
<tr id='post-<?php echo $id; ?>' class='<?php echo trim( $class . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
@ -140,12 +138,9 @@ foreach ($posts_columns as $column_name => $column_display_name ) {
break;
case 'parent':
$title = __('(no title)'); // override below
if ( $post->post_parent > 0 ) {
if ( get_post($post->post_parent) ) {
$parent_title = get_the_title($post->post_parent);
if ( !empty($parent_title) )
$title = $parent_title;
$title =_draft_or_post_title($post->post_parent);
}
?>
<td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?></td>

View File

@ -893,9 +893,7 @@ function get_inline_data($post) {
if ( ! current_user_can('edit_' . $post->post_type, $post->ID) )
return;
$title = apply_filters( 'the_title', $post->post_title );
if ( empty($title) )
$title = __('(no title)');
$title = _draft_or_post_title($post->ID);
echo '
<div class="hidden" id="inline_' . $post->ID . '">
@ -965,9 +963,7 @@ function _post_row($a_post, $pending_comments, $mode) {
global $current_user;
$post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
$edit_link = get_edit_post_link( $post->ID );
$title = get_the_title();
if ( empty($title) )
$title = __('(no title)');
$title = _draft_or_post_title();
?>
<tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $rowclass . ' author-' . $post_owner . ' status-' . $post->post_status ); ?> iedit' valign="top">
<?php
@ -1183,9 +1179,7 @@ function display_page_row( $page, $level = 0 ) {
$rowclass = 'alternate' == $rowclass ? '' : 'alternate';
$posts_columns = wp_manage_pages_columns();
$hidden = (array) get_user_option( 'manage-page-columns-hidden' );
$title = get_the_title();
if ( empty($title) )
$title = __('(no title)');
$title = _draft_or_post_title();
?>
<tr id="page-<?php echo $id; ?>" class="<?php echo $rowclass; ?> iedit">
<?php
@ -2500,5 +2494,20 @@ function favorite_actions() {
}
echo "</div></div>\n";
}
/**
* Get the post title.
*
* The post title is fetched and if it is blank then a default string is returned.
*
* @since 2.7.0
* @param int $id The post id. If not supplied the global $post is used..
*
*/
function _draft_or_post_title($post_id = 0)
{
$title = get_the_title($post_id);
if ( empty($title) )
$title = __('(no title)');
return $title;
}
?>

View File

@ -320,7 +320,7 @@ if ( $page_links )
if ( $orphans ) {
foreach ( $orphans as $post ) {
$class = 'alternate' == $class ? '' : 'alternate';
$att_title = empty($post->post_title) ? __('(no title)') : wp_specialchars( apply_filters('the_title', $post->post_title) );
$att_title = wp_specialchars( _draft_or_post_title($post->ID) );
?>
<tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top">
<th scope="row" class="check-column"><input type="checkbox" name="media[]" value="<?php echo $post->ID; ?>" /></th>