WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#16073 closed defect (bug) (fixed)

Unsupported post formats still visible

Reported by: ericmann Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: Themes Keywords: has-patch commit needs-testing
Focuses: Cc:

Description

Using the latest build (3.1 RC2), ff you add theme support for an unknown post-format it appears on the edit screen, but with a blank label.

Test with the following:

add_theme_support( 'post-formats', array( 'aside', 'gallery','bug' ) );

You will see 4 radio buttons and 3 visible labels: Standard, Aside, Gallery. The 4th label markup is there, but with no visible text.

Attachments (5)

meta-boxes.diff (1.0 KB) - added by ericmann 5 years ago.
Check to make sure the post format string exists ( != ) before adding its markup to the UI.
16073.patch (592 bytes) - added by SergeyBiryukov 5 years ago.
16073.2.patch (491 bytes) - added by garyc40 5 years ago.
use array_intersect() instead of foreach
16073.3.patch (539 bytes) - added by garyc40 5 years ago.
forgot to check is_array()
16073.4.patch (546 bytes) - added by garyc40 5 years ago.
final patch, fixed internationalization issue in 16073.3.patch

Download all attachments as: .zip

Change History (15)

@ericmann
5 years ago

Check to make sure the post format string exists ( != ) before adding its markup to the UI.

#1 @elfin
5 years ago

Tested and seems to work, but should this be 'patched' or should a check_post_formats function be created now for future usage.

#2 follow-up: @nacin
5 years ago

  • Milestone changed from Awaiting Review to 3.1

Maybe we can remove these at the add_theme_support level by doing a diff with get_post_format_slugs.

#3 @elfin
5 years ago

probably need to do something, the diff isn't taking into account options-writing.php which has a selection for the default post-format.

#4 @elfin
5 years ago

Suggestion then. in theme.php change the function add_theme_support to this:

function add_theme_support( $feature ) {
	global $_wp_theme_features;

	if ( func_num_args() == 1 )
		$_wp_theme_features[$feature] = true;
	else
		$_wp_theme_features[$feature] = array_slice( func_get_args(), 1 );
	
	if ( $feature == 'post-formats' ) 
		$_wp_theme_features[$feature] = check_post_format_support($_wp_theme_features[$feature]);

}

and add this function to that file:

function check_post_format_support( $theme_post_formats ) {
	$allowed_post_formats = array_keys(get_post_format_strings());
	$checked_post_formats =  array();
	foreach ( $theme_post_formats[0] as $check_format ) {
		if ( in_array ( $check_format, $allowed_post_formats ) ) {
			$checked_post_formats[] = $check_format;
		}
	}
	$return_post_formats[0]=$checked_post_formats;
	return $return_post_formats;
}

Although there is almost certainly an easier way of doing it.

#5 in reply to: ↑ 2 @SergeyBiryukov
5 years ago

Replying to nacin:

Maybe we can remove these at the add_theme_support level by doing a diff with get_post_format_slugs.

Done.

#6 follow-up: @elfin
5 years ago

Yeah much neater.

#7 in reply to: ↑ 6 @ericmann
5 years ago

Replying to elfin:

Yeah much neater.

Agreed.

Tested the patch and it works nicely, both in the situation previously explained in the ticket and on options-writing.php (as mentioned by @elfin in comment 3).

@garyc40
5 years ago

use array_intersect() instead of foreach

@garyc40
5 years ago

forgot to check is_array()

@garyc40
5 years ago

final patch, fixed internationalization issue in 16073.3.patch

#8 @garyc40
5 years ago

  • Keywords needs-testing added

#9 @nacin
5 years ago

  • Keywords commit added

#10 @ryan
5 years ago

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

(In [17213]) Ignore unsupported post types in add_theme_support(). Props garyc40. fixes #16073

Note: See TracTickets for help on using tickets.