Skip to content

Add filters to post states function#10000

Closed
paulbonneau wants to merge 12 commits intoWordPress:trunkfrom
paulbonneau:add-filters-to-_post_states-function
Closed

Add filters to post states function#10000
paulbonneau wants to merge 12 commits intoWordPress:trunkfrom
paulbonneau:add-filters-to-_post_states-function

Conversation

@paulbonneau
Copy link
Copy Markdown

This PR aim to implement a new filter in _post_states as asked in the ticket linked below

Trac ticket: https://core.trac.wordpress.org/ticket/51403

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 22, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props paulbonneau, westonruter, mukesh27, sirlouen, dmsnell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@mukeshpanchal27
Copy link
Copy Markdown
Member

Thanks @paulbonneau, Left some final bit of feedbacks.

paulbonneau and others added 4 commits September 26, 2025 14:10
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Copy Markdown
Member

@SirLouen SirLouen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the src/wp-includes/compat-utf8.php

@paulbonneau
Copy link
Copy Markdown
Author

Remove the src/wp-includes/compat-utf8.php

done

$output = _post_states( $post, false );

$this->assertStringContainsString( $text_to_append, $output );
$this->assertStringContainsString( $original_output, $output );
Copy link
Copy Markdown
Member

@dmsnell dmsnell Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider using $this->assertStringStartsWith and $this->assertStringEndsWith here instead of contains?

Update: not a blocker, but also something that seems fine to change while merging if it’s useful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in dea8f00 I'm changing this to:

$this->assertSame( $original_output . $text_to_append, $output, 'Expected text to be appended to the original output.' );

When there are no post states, then the $original_output is an empty string.

* Default true.
* @return string Post states string.
*/
function _post_states( $post, $display = true ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same changes seem like they should be done to _media_states().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe later

pento pushed a commit that referenced this pull request Oct 20, 2025
… post states.

Developed in #10000

Props paulbonneau, mukesh27, westonruter, SirLouen, dmsnell, brandbrilliance, shsajalchowdhury, aialvi, ugyensupport.
Fixes #51403.


git-svn-id: https://develop.svn.wordpress.org/trunk@60986 602fd350-edb4-49c9-b593-d223f7449a82
@westonruter
Copy link
Copy Markdown
Member

Committed in r60986 (20b1cf6)

markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Oct 20, 2025
… post states.

Developed in WordPress/wordpress-develop#10000

Props paulbonneau, mukesh27, westonruter, SirLouen, dmsnell, brandbrilliance, shsajalchowdhury, aialvi, ugyensupport.
Fixes #51403.

Built from https://develop.svn.wordpress.org/trunk@60986


git-svn-id: http://core.svn.wordpress.org/trunk@60322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Oct 20, 2025
… post states.

Developed in WordPress/wordpress-develop#10000

Props paulbonneau, mukesh27, westonruter, SirLouen, dmsnell, brandbrilliance, shsajalchowdhury, aialvi, ugyensupport.
Fixes #51403.

Built from https://develop.svn.wordpress.org/trunk@60986


git-svn-id: https://core.svn.wordpress.org/trunk@60322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
*
* @param string $post_states_string The post states HTML string.
* @param string[] $post_states The post states.
* @param WP_Post $post The current post object.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can follow-up after merge, but it would be really handy to have some examples here so people know what to expect. I find the combination of _string and HTML string confusing, plus I don’t know what to expect for this or the following array. Which post states are these?

/**
 * @param string   $post_states_html All relevant post states combined into a an HTML string for display.
 *                                   E.g. ' &mdash; <span class="post-state">draft</span> &mdash; <span class="post-state">private</span>'
 * @param string[] $post_states.     All relevant posts states as an array of raw names.
 *                                   E.g. `array( "draft", "private" )`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmsnell Should we rename the filter to be post_states_html then too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter originally started to share here, but moved it to #51403 because I feel like it applies to the design of the request rather the implementation.

Since this does provide the array of $post_states I think it does serve the questions I raised, but I do believe we could better communicate what’s going on with the naming.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #10360 to iterate on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants