Admin-only content visible in post topic

See my website here:

I am using a plug-in for Amazon product boxes which also show edit links visible for admins only in the content.

Unfortunately those links are also visible in the post’s connected topic (Produkt bearbeiten)

Ist there any way for the plug-in to use post content which is visible to visitors and not the “version” for admins?

That link didn’t make it into your post. Could you add it or PM it to me?

My guess is that the plugin that creates the Amazon product box is using javascript or CSS to hide the edit links from non-admins. If so, the link won’t be hidden when the post is published to Discourse. I assume you are pubishing the full post to Discourse. If so, are you able to try publishing excerpts instead? To do this you would deselect the ‘Use Full Post Content’ option on the plugin’s Publishing options tab. You would then need to make sure that the embed truncate site setting is enabled on Discourse.

Here is the WP post:


Here the connected topic:

the admin-only links don’t appear when visiting the wp post as a guest.
(As a sidenote, the TOC (plugin generated) also appears in topic and is not working since the h2 id’s are stripped)

I realized that publishing excerpts would solve that issue, yet I prefer having full posts in forum topics.
Maybe we can find a workaround.

1 Like

What is the text for the admin edit link? What happens if a non-admin clicks the admin edit link?

[Vorlage bearbeiten]|[Produkt bearbeiten]

It links to my wp-admin product post type edit page

What’s also interesting that it seems that some shortcodes are “processed” in the topic, others are not
In this case the TOC and the product box shortcodes are parsed into the discours topic while the [tablepress] shortcode isn’t

Unless the user has the permissions to edit the post, it probably links to a page that displays something like “Sorry, you are not allowed to edit this item.”

You could try hiding the link with CSS on Discourse by targeting the value of the link’s href. You could also try removing the link by adding a function on WordPress that ties into the wp_discourse_excerpt filter. Parsing HTML with PHP is fairly complicated, so I’d try the CSS option first.

1 Like

can you elaborate on this or point me to a direction how this function should look like?

You can access the post before it is published to Discourse by adding a function like this to your theme’s functions.php file, or to a plugin:

add_filter( 'wp_discourse_excerpt', 'wpdc_custom_discourse_excerpt' );
function wpdc_custom_discourse_excerpt( $post ) {

    // Make your changes to the post here.

    return $post;
}

To parse the post and remove the admin links is going to be tricky. You could take a look at this function that the plugin uses to replace polls in Discourse comments with a link: https://github.com/discourse/wp-discourse/blob/master/lib/template-functions.php#L126.

1 Like