replace excerpt_more with custom filter activitypub_excerpt_more for better consistency (#610)

This commit is contained in:
Kan-Ru Chen 2023-12-16 15:36:45 +09:00 committed by GitHub
parent 97e2bbfe7a
commit a47c9cd7ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -127,8 +127,7 @@ class Shortcodes {
// Strip out any remaining tags.
$excerpt = \wp_strip_all_tags( $excerpt );
/** This filter is documented in wp-includes/formatting.php */
$excerpt_more = \apply_filters( 'excerpt_more', ' [...]' );
$excerpt_more = \apply_filters( 'activitypub_excerpt_more', ' […]' );
$excerpt_more_len = strlen( $excerpt_more );
// We now have a excerpt, but we need to check it's length, it may be longer than we want for two reasons:

View file

@ -62,4 +62,34 @@ class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
$this->assertEquals( '', $content );
Shortcodes::unregister();
}
public function test_excerpt() {
Shortcodes::register();
global $post;
$post_id = -97; // negative ID, to avoid clash with a valid post
$post = new stdClass();
$post->ID = $post_id;
$post->post_author = 1;
$post->post_date = current_time( 'mysql' );
$post->post_date_gmt = current_time( 'mysql', 1 );
$post->post_title = 'Some title or other';
$post->post_content = '<script>test</script>Lorem ipsum dolor sit amet, consectetur.<script type="javascript">{"asdf": "qwerty"}</script><style></style>';
$post->post_status = 'publish';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
$post->post_type = 'page';
$post->filter = 'raw'; // important!
$content = '[ap_excerpt length="25"]';
// Fill in the shortcodes.
setup_postdata( $post );
$content = do_shortcode( $content );
wp_reset_postdata();
$this->assertEquals( "<p>Lorem ipsum [&hellip;]</p>\n", $content );
Shortcodes::unregister();
}
}