Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#2585 closed defect (bug) (fixed)

Add is() function that checks for single object queries.

Reported by: ryan's profile ryan Owned by: ryan's profile ryan
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.1
Component: Administration Keywords: query bg|has-patch bg|needs-testing bg|2nd-opinion
Focuses: Cc:

Description

Perhaps call it is_singular().

is_singular() returns true if is_single(), is_page(), or is_attachment(). We check for ( is_single()
is_page() is_attachemnt() ) quite often. This would clean those checks up and make it easier to add new single object queries.

I wish we had called is_single() is_post() instead. Oh well.

Attachments (2)

single_objects.3658.diff (965 bytes) - added by abhay 16 years ago.
single_objects.2.r3661.diff (3.7 KB) - added by abhay 16 years ago.
collapsed some checks

Download all attachments as: .zip

Change History (10)

#1 @ryan
16 years ago

  • Version changed from 1.2 to 2.1

#2 @abhay
16 years ago

  • Keywords bg|has-patch bg|needs-testing added

Do we want to also change all the existing is_single(), is_attachment(), is_page() calls?

#3 @markjaquith
16 years ago

If you can find any calls that are like this:

if ( is_single() || is_page() || is_attachment() ) : 

Then yes, they should probably be collapsed.

#4 @ryan
16 years ago

We need to audit all is_single()
is_page() checks to determine if an is_attachment() check is needed too.

#5 @abhay
16 years ago

There are no calls like what markjaquith mentioned. There are, however, quite a few that ryan mentioned.

Here is a list of all calls that are associated with this patch:

./wp-commentsrss2.php:23:	<title><?php if (is_single() || is_page() ) { printf(__('Comments on: %s'), get_the_title_rss()); } else { printf(__('Comments for %s'), get_bloginfo_rss("name")); } ?></title>
./wp-commentsrss2.php:24:	<link><?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
./wp-commentsrss2.php:30:		if (is_single() || is_page()) {
./wp-commentsrss2.php:55:		<title><?php if ( ! (is_single() || is_page()) ) {
./wp-content/themes/default/header.php:7:<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>
./wp-content/themes/default/header.php:21:<?php /* Checks to see whether it needs a sidebar or not */ if ((! $withcomments) && (! is_single())) { ?>
./wp-trackback.php:50:if ( is_single() || is_page() ) 
./wp-includes/functions.php:1247:	if ( is_single() || is_page() )
./wp-includes/functions.php:2262:	if ( is_single() || (get_query_var('withcomments') == 1) ) {
./wp-includes/template-functions-general.php:189:	if ( is_single() || is_page() ) {
./wp-includes/template-functions-links.php:211:	if ( is_attachment() )
./wp-includes/template-functions-links.php:248:	if( !is_single() || is_attachment() )
./wp-includes/template-functions-links.php:281:	if( !is_single() || is_attachment() )
./wp-includes/template-functions-links.php:314:	if ( is_attachment() )
./wp-includes/template-functions-links.php:420:	if ( !is_single() ) {
./wp-includes/template-functions-links.php:437:	if ( (! is_single()) && (empty($paged) || $nextpage <= $max_page) ) {
./wp-includes/template-functions-links.php:448:	if ( !is_single() ) {
./wp-includes/template-functions-links.php:459:	if ( (!is_single())	&& ($paged > 1) ) {
./wp-includes/template-functions-links.php:487:	if ( !is_single() ) {
./wp-includes/template-loader.php:19:	} else if ( is_attachment() && $template = get_attachment_template() ) {
./wp-includes/template-loader.php:22:	} else if ( is_single() && $template = get_single_template() ) {
./wp-includes/template-loader.php:23:		if ( is_attachment() )
./wp-includes/template-loader.php:27:	} else if ( is_page() && $template = get_page_template() ) {
./wp-includes/template-loader.php:28:		if ( is_attachment() )
./wp-includes/template-loader.php:51:		if ( is_attachment() )
./wp-includes/comment-functions.php:8:	if ( is_single() || is_page() || $withcomments ) :
./wp-includes/comment-functions.php:297:	if (! is_single() && ! is_page()) {
./wp-includes/classes.php:299:		if ( is_single() || is_page() ) {
./wp-admin/edit.php:66:	if ( is_single() )

@abhay
16 years ago

collapsed some checks

#6 @abhay
16 years ago

  • Keywords bg|2nd-opinion added

collapsed some of the checks. I believe I have caught the right ones.

#7 @markjaquith
16 years ago

[4126] Add is_singular() convenience function

#8 @westi
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

I believe this is now fixed by [4126]

Note: See TracTickets for help on using tickets.