alleyinteractive / apple-news

The Publish to Apple News plugin enables your WordPress blog content to be published to your Apple News channel.
https://wordpress.org/plugins/publish-to-apple-news/
GNU General Public License v3.0
155 stars 71 forks source link

How to remove HTML from "article document title" before submitting to Apple News? #1191

Open newvision2112 opened 1 week ago

newvision2112 commented 1 week ago

Description of the bug

We are submitting our draft articles to Apple News. The issue is our post titles need to italicize names of magazines and newspapers so we have <I></I> and <em></em> tags in the title text. This works for WordPress showing the title on our website. But, it turns out Apple News will not accept "article document title" with HTML in them. This is not the title of the article that shows in Apple News.

How do I configure the plugin strip the HTML characters from the "article document title" before submitting the JSON to Apple News?

mogmarsh commented 6 days ago

@newvision2112 you should be able to use the apple_news_exporter_title filter

newvision2112 commented 6 days ago

@mogmarsh Thank you. So when I remove HTML tags on that:

$title_start = $post->post_title; 
$title_start_2 = strip_tags($title_start); 
$title = apply_filters( 'apple_news_exporter_title', $title_start_2, $post->ID );

It removes the html from ALL titles in the JSON. So it looks like we lose the ability to have italics tags in live article headline that people read in Apple News.

The article title JSON:

SCR-20241106-kpja

And the main headline:

SCR-20241106-kqje

Is there a way to only have the HTML removed from the "article document title"? But leave it in the regular title that shows up with the story on Apple News?

mogmarsh commented 6 days ago

@newvision2112 The apple_news_generate_json filter should work. It gives you an array representation of the json, so you would just change $json['title']

mogmarsh commented 6 days ago

@newvision2112 also, the tags should already be stripped: https://github.com/alleyinteractive/apple-news/blob/6eedc7922db8dac44a4191816a18a3b152492a8f/includes/apple-exporter/class-exporter.php#L212

newvision2112 commented 6 days ago

@mogmarsh Thank you. I will work on apple_news_generate_json filter.

I saw that code in the plugin 'title' => wp_strip_all_tags( $this->content_title() ), but it did not remove the html tags <I>title text</I> or <em>title text</em> from any of our JSON title fields in our submissions to Apple News drafts.

Apple News flagged the problem to us and halted our site going live until we fix it.

kevinfodness commented 5 days ago

You're right, this is a bug. I was able to reproduce this on a vanilla installation of the plugin. It appears that the HTML in the title is getting partially transformed which is interfering with strip tags, which results in this output:

"title": "Test &lt;i>italic title&lt;\/i>"
newvision2112 commented 5 days ago

Thank you Kevin! Please let me know if I can test anything, or what a timeline for the fix might be. All best, Dean

mogmarsh commented 5 days ago

@newvision2112 My suggestion above should work until we get the bug fixed. That filter runs at the very last minute and allows you to change almost anything.

newvision2112 commented 5 days ago

@mogmarsh Thank you, but I don't understand the code enough to use apple_news_generate_json.

For now, to get Apple News to approve us, I used the code above to strip all html from all titles