Make WordPress Core


Ignore:
Timestamp:
07/23/2024 07:49:54 AM (10 months ago)
Author:
youknowriad
Message:

REST API: Remove post status prefix from REST API responses.

When using the /posts or /pages endpoints, for private posts or pages, you get the following title property: { raw: "Some title", rendered: "Private: Some title" }
this commit removes the prefix from rendered private posts titles (just like what we do for protected posts)

Props youknowriad, swissspidy, timothyblynjacobs, sergeybiryukov, ramonopoly.
Fixes #61639.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php

    r58706 r58783  
    133133            if ( post_type_supports( $post->post_type, 'title' ) ) {
    134134                add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
     135                add_filter( 'private_title_format', array( $this, 'protected_title_format' ) );
    135136                $data[ WP_REST_Search_Controller::PROP_TITLE ] = get_the_title( $post->ID );
    136137                remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
     138                remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) );
    137139            } else {
    138140                $data[ WP_REST_Search_Controller::PROP_TITLE ] = '';
     
    184186
    185187    /**
    186      * Overwrites the default protected title format.
    187      *
    188      * By default, WordPress will show password protected posts with a title of
    189      * "Protected: %s". As the REST API communicates the protected status of a post
    190      * in a machine-readable format, we remove the "Protected: " prefix.
    191      *
    192      * @since 5.0.0
    193      *
    194      * @return string Protected title format.
     188     * Overwrites the default protected and private title format.
     189     *
     190     * By default, WordPress will show password protected or private posts with a title of
     191     * "Protected: %s" or "Private: %s", as the REST API communicates the status of a post
     192     * in a machine-readable format, we remove the prefix.
     193     *
     194     * @since 5.0.0
     195     *
     196     * @return string Title format.
    195197     */
    196198    public function protected_title_format() {
Note: See TracChangeset for help on using the changeset viewer.