Make WordPress Core

Opened 12 years ago

Closed 6 years ago

#21941 closed enhancement (maybelater)

Deprecate get_post_format_slugs()

Reported by: f-j-kaiser's profile F J Kaiser Owned by: ocean90's profile @…
Milestone: 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 9 years ago.
first pass.
21941.2.diff (1.8 KB) - added by MikeHansenMe 8 years ago.
21941.3.diff (2.5 KB) - added by lemacarl 8 years ago.
21941.3.2.diff (2.6 KB) - added by lemacarl 8 years ago.
21941.4.diff (2.6 KB) - added by mrahmadawais 8 years ago.
Updated the version from 4.5.0 to 4.6.0

Download all attachments as: .zip

Change History (22)

#1 @F J Kaiser
12 years ago

  • Severity changed from normal to minor

#2 @nacin
10 years ago

  • Component changed from General to Post Formats

@MikeHansenMe
9 years ago

first pass.

#3 @MikeHansenMe
9 years ago

  • Keywords has-patch needs-unit-tests added

@MikeHansenMe
8 years ago

#4 @MikeHansenMe
8 years 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
8 years 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
8 years ago

#6 @lemacarl
8 years ago

  • Keywords has-patch added; needs-patch removed

@lemacarl
8 years ago

#7 follow-up: @lemacarl
8 years 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
8 years 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
8 years ago

Updated the version from 4.5.0 to 4.6.0

#9 in reply to: ↑ 7 @mrahmadawais
8 years 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
8 years ago

  • Summary changed from Remove get_post_format_slugs() to Deprecate get_post_format_slugs()

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


8 years ago

#12 @ocean90
8 years ago

I don't see the need for deprecating the function. It looks like the function is used by some themes and plugins, see https://github.com/search?o=desc&q=get_post_format_slugs%28%29&s=indexed&type=Code&utf8=%E2%9C%93.

@ipstenu: Could you help us with slurping the plugin repo for get_post_format_slugs)?

#13 @chriscct7
8 years ago

  • Owner set to @…
  • Status changed from new to assigned

#14 @Ipstenu
8 years ago

Slurping....

18 plugins.

plugins/askapache-debug-viewer/askapache-debug-viewer.php:2442:			$d=get_post_format_slugs(); $out['get_post_format_slugs'] = $d;
plugins/bulk-convert-post-format/bulk-convert-post-format.php:74:		$formats = get_post_format_slugs();
plugins/custom-contact-forms/wp-api/lib/endpoints/class-wp-rest-posts-controller.php:1519:						'enum'        => array_values( get_post_format_slugs() ),
plugins/json-rest-api/lib/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/ozh-tweet-archiver/ozh-ta.php:128:		'post_format'            => 'standard', // can be any of the values returned by get_post_format_slugs()
plugins/post-format-permalink/post-format-permalink.php:91:		$post_format_slugs = implode('|', get_post_format_slugs());
plugins/postie/postie-functions.php:516:    } elseif (in_array($custom_post_type, array_keys(get_post_format_slugs()))) {
plugins/pressbooks/vendor/pressbooks/rest-api/lib/endpoints/class-wp-rest-posts-controller.php:1557:						'enum'        => array_values( get_post_format_slugs() ),
plugins/presstest/mocked/core.php:3739:if( !function_exists( 'get_post_format_slugs' ) ) { function get_post_format_slugs() { return PT_Mime::mime( func_get_args() );  } }
plugins/prograpper/wp-api/lib/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/reactor-core/json-rest-api/lib/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/rest-api/lib/endpoints/class-wp-rest-posts-controller.php:1557:						'enum'        => array_values( get_post_format_slugs() ),
plugins/rest-api-search/lib/class-wp-rest-search-controller.php:296:                        'enum'        => array_values ( get_post_format_slugs () ),
plugins/rest-json/include/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/set-aside/set-aside.php:68:      <?php if ( !function_exists('get_post_format_slugs') ) : ?>
plugins/set-aside/set-aside.php:89:                <?php foreach ( array_diff ( get_post_format_slugs(), $post_formats[0], array ( 'standard' ) ) as $format ) : ?>
plugins/set-aside/set-aside.php:97:      <?php endif; // !function_exists('get_post_format_slugs') ?>
plugins/the-pressengine/lib/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/worona/json-rest-api/lib/class-wp-json-posts.php:932:			$formats = get_post_format_slugs();
plugins/wp-bigapp/lib/json/class-wp-json-posts.php:955:			$formats = get_post_format_slugs();

This ticket was mentioned in Slack in #core by voldemortensen. View the logs.


8 years ago

#16 @voldemortensen
8 years ago

  • Keywords close added
  • Milestone changed from 4.6 to Future Release

#17 @flixos90
6 years ago

  • Keywords close removed
  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from assigned to closed

Given the feedback in https://core.trac.wordpress.org/ticket/21941#comment:12 and https://core.trac.wordpress.org/ticket/21941#comment:14, and given that the function does not have an adequate direct replacement (regardless of whether its existence is generally questionable), I agree it's not worth deprecating the function at this point. Maybe we can revisit this later.

Note: See TracTickets for help on using tickets.