Allowing arbitrary HTML in the Summary/Quote field in the Post Kinds Plugin

Now you can have richer reply contexts on your posts in WordPress

Reply contexts

One of my favorite parts of the Post Kinds plugin isn’t just that it provides me the flexibility to add a huge variety of post types to my website or the semantic HTML and microformats it provides to help my site dovetail into the IndieWeb. It’s that it allows me to quickly and easily provide very rich reply contexts to my posts so that I more easily know what I’ve bookmarked, liked, favorited, read, or replied to online. In some sense it helps guard against some of the problem of context collapse found in many social media sites on the internet. As my friend and foodie extraordinaire Jeremy Cherfas has said, “a reply without context is like an egg without salt.”

For a long time I had been wanting a bit more control of how the Post Kinds plugin presented some of the data it allows.1,2 After one inputs a URL, the plugin uses several methods to scrape the related web page and returns a lot of metadata about it including the title, a summary, the site name, tags, a featured image, publication date and time, the author and author’s website among others. The data returned depends on how the page is marked up and is generally based on available microformats or open graph protocol data when they’re provided.

The plugin has a setting to “Embed Sites into your Response” on its settings page, and this is generally okay, but it relies on sites to have some sort of oEmbed set up predefined. For bigger sites like YouTube and WordPress, this is generally alright, but it’s not always the case that any data is provided by the external site. Even in YouTube’s case you’ll only display the video with no other meta-data about it. As a result I leave it turned off.

Let’s take a quick look at what some of these default outputs for the reply context with a short comment underneath them look like.

This is the default  Post Kinds output for an automatically parsed YouTube video with the embed function off. While it’s a good start, it’s not necessarily inspiring or a good reminder of the content you watched. One could manually change or add some of the fields for additional data, but we would still be a bit limited.
This is what Post Kinds outputs for an automatically parsed YouTube video with the embed function turned on. It’s nice to have an embedded copy of the video, but where did it come from? What is it about? Why should we care? Is there any other metadata we can display?

With the embed option turned off the plugin will return a “Summary” of the parsed website page. This too is generally well supported in 90% of websites in my experience. But the data it returns is (smartly) filtered using wp_kses for security so that a malicious page couldn’t inject random html or code into your page. This means that useful functionality is often being stripped out of the “Summary/Quote” field in the reply context. I’d prefer to have the ability to have text with links, video, and audio to appear in-line in these contexts so that there’s a better representation of the actual post I’m reacting to.

The question then, is how can I make this happen?

In older versions of the plugin there was a setting for this feature, but it wasn’t well documented and most people didn’t know what the setting was or what it meant. For simpler UI and support it was ultimately stripped out although the raw code for it was left in. In fact, it’s literally the first short block of code within the plugin’s main code! It looks like this:

if ( ! defined( 'POST_KINDS_KSES' ) ) {
	define( 'POST_KINDS_KSES', false );
}

To enable the ability to manually add arbitrary html, links, audio, video, etc. you can go to your main administrative user interface in WordPress and go to Plugins >> Edit and then choose the Post Kinds option in the drop down selector in the top right hand corner and click select. Search for the code listed above (it should be right at the top, underneath the title and details for the plugin) and change the single word false to true. Next scroll down the page and click the Update File button.

Now you should be able to manually change any of the fields within the Response Properties metabox and they’d display in full HTML as you’d expect them to. (Caveat: because you’ve disabled a small layer of security, you should keep a close eye on what data appears in your “Summary/Quote” field and make sure you’re not allowing your site or your readers to be led astray or hacked. In my case, I’m almost always modifying it by hand, so it’s not a big issue. Your mileage may vary depending on what you’re posting.)

This is what Post Kinds outputs for a parsed YouTube video with the embed function off. We’ve gone in and manually tweaked the author name, URL, and photo and added manual HTML to render a sysnopsis with links and an in-line playable  iframed embed of the video. This is a much richer reply context! It doesn’t get much better than this. Thanks Post Kinds!!

Updates

But wait… What happens when I update the plugin? Won’t the update overwrite the change? Yes, you’re absolutely correct. You’ll have to remember to go back and make this change any time the plugin updates. To prevent this, you could instead modify your wp-config.php file in the root folder of your WordPress install. To do this add the following lines of code to the bottom of this file:

/** Sets up initial variable for the Post Kinds plugin to not filter the Summary/Quote field  */
if ( ! defined( 'POST_KINDS_KSES' ) ) 
	define(' POST_KIND_KSES', true );

Next save the file and upload it to your WordPress install. Now you should be all set.

References

1.
Aldrich C. Post Kinds Plugin for WordPress. BoffoSocko. https://boffosocko.com/2017/08/11/post-kinds-plugin-for-wordpress/. Published August 11, 2017. Accessed June 9, 2018.
2.
Aldrich C. Manually adding a new post kind to the Post Kinds Plugin for WordPress. BoffoSocko. https://boffosocko.com/2018/06/06/manually-adding-a-new-post-kind-to-the-post-kinds-plugin-for-wordpress/. Published June 7, 2018. Accessed June 9, 2018.
Syndicated copies to: