From 9f8bad3e8d5f11cf72748bac729ee8e0027df158 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 12 Dec 2023 13:58:44 +0100 Subject: [PATCH] Make Post-Template filterable (#597) * make template filterable prepare #596 also #519 * updated changelog --- README.md | 1 + includes/transformer/class-post.php | 27 ++++++++++++++++----------- readme.txt | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 193c081..2f7a22d 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Removed: Deprecated Classes * Fixed: Normalize attributes that can have mixed value types * Added: URL support for WebFinger +* Added: Make Post-Template filterable ### 1.3.0 ### diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index 721bbec..061be51 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -559,19 +559,24 @@ class Post { * @return string The Template. */ protected function get_post_content_template() { - if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_excerpt]\n\n[ap_permalink type=\"html\"]"; + $type = \get_option( 'activitypub_post_content_type', 'content' ); + + switch ( $type ) { + case 'excerpt': + $template = "[ap_excerpt]\n\n[ap_permalink type=\"html\"]"; + break; + case 'title': + $template = "[ap_title]\n\n[ap_permalink type=\"html\"]"; + break; + case 'content': + $template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]"; + break; + default: + $template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT ); + break; } - if ( 'title' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_title]\n\n[ap_permalink type=\"html\"]"; - } - - if ( 'content' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]"; - } - - return \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT ); + return apply_filters( 'activitypub_object_content_template', $template, $this->wp_post ); } /** diff --git a/readme.txt b/readme.txt index 26e92f5..51235c1 100644 --- a/readme.txt +++ b/readme.txt @@ -110,6 +110,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Removed: Deprecated Classes * Fixed: Normalize attributes that can have mixed value types * Added: URL support for WebFinger +* Added: Make Post-Template filterable = 1.3.0 =