I think you are setting up the filter incorrectly, and that’s why it’s not getting called. That particular filter only accepts one parameter, but you’re indicating that it should accept two (the 10, 2 part).
Following the structure of your example, I created a sample filter that did work:
class AN_Test_Filter {
public function __construct() {
add_filter( 'apple_news_end_of_article_json', [ $this, 'apple_news_end_of_article_filter' ], 10, 1 );
}
public function apple_news_end_of_article_filter( $json ) {
return [
'role' => 'body',
'text' => 'test end of article',
];
}
}
$tt1_test_filter = new AN_Test_Filter();
You could also do the same thing outside of a class context, like this:
function my_theme_filter_apple_news_end_of_article_json( $json ) {
return [
'role' => 'body',
'text' => 'test end of article',
];
}
add_filter( 'apple_news_end_of_article_json', 'my_theme_filter_apple_news_end_of_article_json' );
In these examples, I’m just returning a static body for the end of article content, but you can modify the value of the $json variable and return it as well, if you want to do things like replacing placeholder values or adding a link to the web version of the article etc.
-
This reply was modified 3 years, 1 month ago by Kevin Fodness. Reason: formatting
-
This reply was modified 3 years, 1 month ago by Kevin Fodness. Reason: formatting, again