WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 weeks ago

#21941 new enhancement

Deprecate get_post_format_slugs()

Reported by: F J Kaiser Owned by:
Milestone: 4.6 Priority: normal
Severity: minor Version:
Component: Post Formats Keywords: good-first-bug has-patch dev-feedback
Focuses: Cc:

Description

I just encountered the get_post_format_slugs() function, which is basically just wrapping get_post_format_strings() and setting the strings as keys too. So its output is an assoc array where the keys equal the values.

The three times core calls it, it does it the following:

// ~/wp-includes/posts.php -> set_post_format()
if ( 'standard' == $format || !in_array( $format, array_keys( get_post_format_slugs() ) ) )

// ~/wp-includes/posts.php -> _post_format_request()
$slugs = get_post_format_slugs();
if ( isset( $slugs[ $qvs['post_format'] ] ) )
	$qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];

// ~/wp-includes/theme.php -> add_theme_support()
switch ( $feature ) {
	case 'post-formats' :
		if ( is_array( $args[0] ) )
			$args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) );
		break;

So in every case it would've been enough to simply call get_post_format_strings().

Do we really need this function?

Attachments (5)

21941.diff (1.8 KB) - added by MikeHansenMe 19 months ago.
first pass.
21941.2.diff (1.8 KB) - added by MikeHansenMe 8 months ago.
21941.3.diff (2.5 KB) - added by lemacarl 3 weeks ago.
21941.3.2.diff (2.6 KB) - added by lemacarl 3 weeks ago.
21941.4.diff (2.6 KB) - added by mrahmadawais 2 weeks ago.
Updated the version from 4.5.0 to 4.6.0

Download all attachments as: .zip

Change History (15)

#1 @F J Kaiser
4 years ago

  • Severity changed from normal to minor

#2 @nacin
2 years ago

  • Component changed from General to Post Formats

@MikeHansenMe
19 months ago

first pass.

#3 @MikeHansenMe
19 months ago

  • Keywords has-patch needs-unit-tests added

#4 @MikeHansenMe
8 months ago

  • Keywords needs-unit-tests removed

21941.2.diff is a refresh. It looks like we now have tests for add_theme_support() and set_post_format(). I think these tests cover all the usage of get_post_format_slugs.

#5 @swissspidy
5 months ago

  • Keywords good-first-bug needs-patch added; 2nd-opinion has-patch removed

21941.2.diff needs a small refresh.

Deprecated functions are usually moved to wp-includes/deprecated.php. They also need proper inline docs, see https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#1-2-deprecated-functions

@lemacarl
3 weeks ago

#6 @lemacarl
3 weeks ago

  • Keywords has-patch added; needs-patch removed

@lemacarl
3 weeks ago

#7 follow-up: @lemacarl
3 weeks ago

Sorry I am new @ this. 21941.3.2.diff is pretty much the same as 21941.3.diff only I had missed out a couple of things

#8 @swissspidy
3 weeks ago

  • Milestone changed from Awaiting Review to 4.6

@lemacarl Thanks, that looks good! Just the version number needs to be updated, but fine otherwise.

I'll try to test it when I get the chance.

@mrahmadawais
2 weeks ago

Updated the version from 4.5.0 to 4.6.0

#9 in reply to: ↑ 7 @mrahmadawais
2 weeks ago

  • Keywords dev-feedback added

Replying to swissspidy:

@swissspidy Just tested and updated the version # in the patch. Fine at my end. 21941.4.diff https://core.trac.wordpress.org/attachment/ticket/21941/21941.4.diff

#10 @swissspidy
2 weeks ago

  • Summary changed from Remove get_post_format_slugs() to Deprecate get_post_format_slugs()
Note: See TracTickets for help on using tickets.