[wp-trac] [WordPress Trac] #35308: get_the_excerpt: For protected posts the output should be able to be filtered
WordPress Trac
noreply at wordpress.org
Mon Jan 4 20:47:26 UTC 2016
#35308: get_the_excerpt: For protected posts the output should be able to be
filtered
-------------------------------+-----------------------------
Reporter: emanaku | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 4.3.1
Severity: normal | Keywords:
Focuses: |
-------------------------------+-----------------------------
If I want to show an excerpt of a protected post, then I have to search
the output of get_the_excerpt for a string like "There is no excerpt
because this is a protected post." and replace this string by the actual
excerpt.
In a multilanguage environment this creates a source of possible errors.
I would like to see that the filter "get_the_excerpt" is also applied to
the "There is no excerpt ..." message.
Code in the function get_the_excerpt could look like this:
{{{#!php
<?php
function get_the_excerpt( $deprecated = '' ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '2.3' );
$post = get_post();
if ( empty( $post ) ) {
return '';
}
$excerpt = '';
// emanaku new
if ( post_password_required() ) {
// return __( 'There is no excerpt because this is a
protected post.' ); // emanaku replace with next line
$excerpt = __( 'There is no excerpt because this is a
protected post.' ); // emanaku new
}
else { $excerpt = $post->post_excerpt; };
// emanaku new
/**
* Filter the retrieved post excerpt.
*
* @since 1.2.0
*
* @param string $post_excerpt The post excerpt.
*/
// return apply_filters( 'get_the_excerpt', $post->post_excerpt );
// emanaku replace with next line
return apply_filters( 'get_the_excerpt', $excerpt ); // emanaku
changed
}
}}}
With this change a filter asking for protected content can hook into
get_the_excerpt and can deliver any kind of excerpt (the real excerpt, a
customized protected text, a form to give the password etc.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35308>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list