Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags in Wordpress article don't show up as hashtags #182

Closed
bocops opened this issue Nov 16, 2022 · 34 comments
Closed

Tags in Wordpress article don't show up as hashtags #182

bocops opened this issue Nov 16, 2022 · 34 comments
Labels
[Type] Bug Something isn't working

Comments

@bocops
Copy link
Contributor

bocops commented Nov 16, 2022

After installing the plugin, when writing an article on my Wordpress blog and adding tags to the article, no hashtags appear in the resulting post visible on Mastodon, not even as simple text.

Things I've already tried after consulting with Matthias directly:

  1. two different blogs on separate URLs
  2. viewing the resulting post with two different accounts on different Mastodon servers (one running v3.5.3, the other v4.0.2)
  3. plugin setting: changing custom text - it doesn't matter where %hashtags% is inserted and in what order relative to other placeholders, or whether it is surrounded by an HTML p-tag or not.
  4. plugin setting: toggling "Hashtags" option on or off
  5. viewing post content by appending "/activitypub" to the blog URL - hashtags appear defined there, both as text with link to my blog in the content as well as in the "tag" list.
  6. checking resulting Mastodon post using my browser's developer tools - there's simply nothing there
@bocops
Copy link
Contributor Author

bocops commented Nov 16, 2022

One thing I just noted is that the title, which is defined as <p><strong>%title%</strong></p> in the plugin, appears as <p>Title</p> in the resulting Mastodon post, with the <strong> tag missing.

It seems as if some sanitization or stripping of HTML tags is done before delivering these posts. Hashtags in <a> tags might simply be affected by that as well?

@mediaformat
Copy link
Collaborator

Mastodon has a very strict filter, and afaict strips out everything but <br> and <a>.

@pfefferle
Copy link
Member

@mediaformat the a tag is allowed! I have checked that with several blog posts.

@dustinrue
Copy link

I think it would be great to just have post tags added as hashtags in the ActivityPub post. This keeps your page content clean while still using hashtags on the ActivityPub side.

@pfefferle
Copy link
Member

You already can do that using the placeholders

@timnolte
Copy link

@bocops & @dustinrue if you go to the plugin settings you can control the output of the ActivityPub posts. Currently I'm using a Custom format as follows:

<p><strong>%title%</strong></p>

%excerpt%

<p>%hashtags%</p>

<p>%shortlink%</p>

My posts on Mastodon look like this:
image

@bocops
Copy link
Contributor Author

bocops commented Nov 28, 2022

@timnolte My custom format in Wordpress looks the same, but hashtags simply won't show up in the resulting post when viewed by different Mastodon users.

@dustinrue
Copy link

I didn't even think if custom formats, ty for the tip on that

@evilgeniuschronicles
Copy link

evilgeniuschronicles commented Jan 5, 2023

I am experiencing this currently. I use the %hashtags% in the template and get nothing. Just to test this out, I took your help text of existing template fields then cut-and-pasted into my format.

Here is the link to what happened.

https://elk.zone/mastodon.lol/@dave@evilgeniuschronicles.org/109637179720056151

Every other field was populated but the tags was empty. If you click through to the Wordpress post you will see there are definitely tags on the post.

@evilgeniuschronicles
Copy link

I am spending my Saturday night inserting logging code into the live plugin on my website. Hot times.

Here is what happens when I write a post. I see it going through all the steps in generate_the_content a few times. I suspect each of those is a time when the autosave happens. Then it goes through when I publish, generates content with no tags in it and that's what gets published to Mastodon followers. Then after all that it gets called again, gets the tags and generates the content again with the tags but it has already sent the toots off. This is why it is not working. What I don't understand is what is making this timing happen. Hopefully y'all (in particular @pfefferle ) have a better grasp of it.

I went back and added logging at the top of get_the_post_hashtags. It is getting called each time, but all the times before send_post_activity() that returns nothing. After it gets called again that last time, after the actual activity is sent, the tags exist.

[08-Jan-2023 02:23:15 UTC] Getting tags for 10265 
[08-Jan-2023 02:23:15 UTC] Getting tags for 10265 
[08-Jan-2023 02:23:15 UTC] Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p>
[08-Jan-2023 02:23:15 UTC] Filtered Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p>
[08-Jan-2023 02:23:15 UTC] Decoded Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p>
[08-Jan-2023 02:23:15 UTC] <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p>
[08-Jan-2023 02:24:12 UTC] Getting tags for 10265 
[08-Jan-2023 02:24:12 UTC] Getting tags for 10265 
[08-Jan-2023 02:24:12 UTC] Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being a
ssociated. Or something.</p>
[08-Jan-2023 02:24:12 UTC] Filtered Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tag
s being associated. Or something.</p>
[08-Jan-2023 02:24:12 UTC] Decoded Content: <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags
 being associated. Or something.</p>
[08-Jan-2023 02:24:12 UTC] <p></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being associated
. Or something.</p>

[08-Jan-2023 02:24:13 UTC] In send_post_activity: 2 {"@context":["https:\/\/www.w3.org\/ns\/activitystreams","https:\/\/w3id.org\/security\/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","PropertyValue":"schema:PropertyVal
ue","schema":"http:\/\/schema.org#","pt":"https:\/\/joinpeertube.org\/ns#","toot":"http:\/\/joinmastodon.org\/ns#","value":"schema:value","Hashtag":"as:Hashtag","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:f
eaturedTags","@type":"@id"}}],"published":"2023-01-08T02:24:12Z","id":"https:\/\/evilgeniuschronicles.org\/2023\/01\/07\/activitypub-tag-test-9\/?activity=create","type":"Create","actor":"https:\/\/evilgeniuschronicles.org\/author\/dave-s\
/","to":["https:\/\/mastodon.lol\/users\/geniodiabolico"],"cc":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/evilgeniuschronicles.org\/2023\/01\/07\/activitypub-tag-test-9\/","type":"Note","published":"2023
-01-08T02:24:12Z","attributedTo":"https:\/\/evilgeniuschronicles.org\/author\/dave-s\/","summary":null,"inReplyTo":null,"content":"\u003Cp\u003E\u003C\/p\u003E\u003Cp\u003E\u003Ca href=\u0022https:\/\/evilgeniuschronicles.org\/b\/2r5\u0022
\u003Ehttps:\/\/evilgeniuschronicles.org\/b\/2r5\u003C\/a\u003E\u003C\/p\u003E\u003Cp\u003EI think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.\u003C\/p\u003E","contentMap"
:{"en":"\u003Cp\u003E\u003C\/p\u003E\u003Cp\u003E\u003Ca href=\u0022https:\/\/evilgeniuschronicles.org\/b\/2r5\u0022\u003Ehttps:\/\/evilgeniuschronicles.org\/b\/2r5\u003C\/a\u003E\u003C\/p\u003E\u003Cp\u003EI think I have narrowed this dow
n to timing and things getting called prior to the tags being associated. Or something.\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"cc":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"attachment":[],"t
ag":[]}}
[08-Jan-2023 02:24:14 UTC] In send_post_activity: 2 {"@context":["https:\/\/www.w3.org\/ns\/activitystreams","https:\/\/w3id.org\/security\/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","PropertyValue":"schema:PropertyVal
ue","schema":"http:\/\/schema.org#","pt":"https:\/\/joinpeertube.org\/ns#","toot":"http:\/\/joinmastodon.org\/ns#","value":"schema:value","Hashtag":"as:Hashtag","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:f
eaturedTags","@type":"@id"}}],"published":"2023-01-08T02:24:12Z","id":"https:\/\/evilgeniuschronicles.org\/2023\/01\/07\/activitypub-tag-test-9\/?activity=create","type":"Create","actor":"https:\/\/evilgeniuschronicles.org\/author\/dave-s\
/","to":["https:\/\/masto.ai\/users\/mikewmerritt"],"cc":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"object":{"id":"https:\/\/evilgeniuschronicles.org\/2023\/01\/07\/activitypub-tag-test-9\/","type":"Note","published":"2023-01-08
T02:24:12Z","attributedTo":"https:\/\/evilgeniuschronicles.org\/author\/dave-s\/","summary":null,"inReplyTo":null,"content":"\u003Cp\u003E\u003C\/p\u003E\u003Cp\u003E\u003Ca href=\u0022https:\/\/evilgeniuschronicles.org\/b\/2r5\u0022\u003E
https:\/\/evilgeniuschronicles.org\/b\/2r5\u003C\/a\u003E\u003C\/p\u003E\u003Cp\u003EI think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.\u003C\/p\u003E","contentMap":{"en"
:"\u003Cp\u003E\u003C\/p\u003E\u003Cp\u003E\u003Ca href=\u0022https:\/\/evilgeniuschronicles.org\/b\/2r5\u0022\u003Ehttps:\/\/evilgeniuschronicles.org\/b\/2r5\u003C\/a\u003E\u003C\/p\u003E\u003Cp\u003EI think I have narrowed this down to t
iming and things getting called prior to the tags being associated. Or something.\u003C\/p\u003E"},"to":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"cc":["https:\/\/www.w3.org\/ns\/activitystreams#Public"],"attachment":[],"tag":[]
}}
[08-Jan-2023 02:24:15 UTC] Getting tags for 10265 Array
(
    [0] => WP_Term Object
        (
            [term_id] => 2702
            [name] => activitypub
            [slug] => activitypub
            [term_group] => 0
            [term_taxonomy_id] => 2700
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 12
            [filter] => raw
        )

    [1] => WP_Term Object
        (
            [term_id] => 2706
            [name] => debug
            [slug] => debug
            [term_group] => 0
            [term_taxonomy_id] => 2704
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 8
            [filter] => raw
        )

    [2] => WP_Term Object
        (
            [term_id] => 2700
            [name] => mastodon
            [slug] => mastodon
            [term_group] => 0
            [term_taxonomy_id] => 2698
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 13
            [filter] => raw
        )

)

[08-Jan-2023 02:24:15 UTC] Getting tags for 10265 Array
(
    [0] => WP_Term Object
        (
            [term_id] => 2702
            [name] => activitypub
            [slug] => activitypub
            [term_group] => 0
            [term_taxonomy_id] => 2700
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 12
            [filter] => raw
        )

    [1] => WP_Term Object
        (
            [term_id] => 2706
            [name] => debug
            [slug] => debug
            [term_group] => 0
            [term_taxonomy_id] => 2704
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 8
            [filter] => raw
        )

    [2] => WP_Term Object
        (
            [term_id] => 2700
            [name] => mastodon
            [slug] => mastodon
            [term_group] => 0
            [term_taxonomy_id] => 2698
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 13
            [filter] => raw
        )

)

[08-Jan-2023 02:24:15 UTC] Content: <p><a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/activitypub/">#activitypub</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/debug/">#debug</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/mastodon/">#mastodon</a></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.</p>
[08-Jan-2023 02:24:15 UTC] Filtered Content: <p><a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/activitypub/">#activitypub</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/debug/">#debug</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/mastodon/">#mastodon</a></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.</p>
[08-Jan-2023 02:24:15 UTC] Decoded Content: <p><a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/activitypub/">#activitypub</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/debug/">#debug</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/mastodon/">#mastodon</a></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.</p>
[08-Jan-2023 02:24:15 UTC] <p><a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/activitypub/">#activitypub</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/debug/">#debug</a> <a rel="tag" class="u-tag u-category" href="https://evilgeniuschronicles.org/tag/mastodon/">#mastodon</a></p><p><a href="https://evilgeniuschronicles.org/b/2r5">https://evilgeniuschronicles.org/b/2r5</a></p><p>I think I have narrowed this down to timing and things getting called prior to the tags being associated. Or something.</p>
[08-Jan-2023 02:24:19 UTC] []

@bocops
Copy link
Contributor Author

bocops commented Jan 11, 2023

I've talked to @evilgeniuschronicles the last few days and can confirm his findings.

For what it's worth, if I edit get_the_post_hashtags() in class-post.php to return some arbitrary string in case of not finding any post tags, like so:

if ( ! $tags ) {
    return 'This text should never appear for posts with tags!';
}

Then this string will appear in all resulting Mastodon statuses, even if the post did have tags. This means that the abovementioned placeholder replacement works, but that WP's get_the_tags($id) doesn't, at least not at that point and for some of us.

@bocops
Copy link
Contributor Author

bocops commented Jan 16, 2023

FWIW, @evilgeniuschronicles found a workaround and shared it with me that might help users encountering the same issue, and might also help track down why this bug exists in the first place:

If the Wordpress post isn't posted immediately, but instead scheduled (even just some minutes in the future is enough), then the resulting AcitivityPub post as viewed for example via Mastodon will contain the post tags as hashtags, as long as the template is set up correctly.

This, combined with the fact that this bug did not appear for all of us in the first place, seems to suggest that timing issues might be the cause, perhaps via the use of wp_schedule_single_event(...) for some of the internal scheduling this plugin does?

@pfefferle
Copy link
Member

pfefferle commented Jan 16, 2023

@bocops and @evilgeniuschronicles nice debugging! that helps a lot, I will have a look why the tags might not be included if the post is sent to quickly.

@pfefferle
Copy link
Member

I have one last question: How do you generate the tags? Are these the tags that are added via the classic tags frontend of the editor or the hashtag feature ActivityPub implements?

@evilgeniuschronicles
Copy link

In my case, it was the tag editor in the front end. Even when adding tags first before writing the post, I got the empty get_the_tags() behavior during publish.

pfefferle added a commit that referenced this issue Jan 16, 2023
because of #182
@bocops
Copy link
Contributor Author

bocops commented Jan 16, 2023

Same here, I added "tags" in the Wordpress editor for them to be added to the resulting ActivityPub object via %hashtags%.

Adding hashtags to the content directly still seems to have other issues. At least Mastodon doesn't seem to recognize them, and instead displays simple text. Not sure if this is a related issue or something else at the moment.

@pfefferle
Copy link
Member

Is this still an issue with version 0.16.1?

@bocops
Copy link
Contributor Author

bocops commented Feb 2, 2023

@pfefferle Just tested this once, but looks good to me! As far as I am concerned, this can be closed unless others still see the problem. Thanks for the fix! :)

@pfefferle
Copy link
Member

Thanks for your answer @bocops . I will close this issue for now, please re-open if still a problem.

@evilgeniuschronicles
Copy link

I tested on my blog with 0.16.1 . I still see the problem.

The wordpress posts have odd permalinks, but I did comment to Matthais' mastodon account in a reply to my test post. I set up the tags in the right-hand column of the post section prior to publishing. I did the immediate "Publish" and did not get the tags in the post when it arrived in Mastodon.

@pfefferle
Copy link
Member

What do you mean by "the permalinks are weird"? You seem to use shortlinks, if you want to have the permalinks, you have to change your settings.

@pfefferle
Copy link
Member

pfefferle commented Feb 2, 2023

@evilgeniuschronicles can you send me your message config?

Bildschirm­foto 2023-02-02 um 20 49 55

@evilgeniuschronicles
Copy link

image

@evilgeniuschronicles
Copy link

evilgeniuschronicles commented Feb 8, 2023

@pfefferle

What do you mean by "the permalinks are weird"? You seem to use shortlinks, if you want to have the permalinks, you have to change your settings.

I mean the permalink to the actual Mastodon post that results is weird. If there is a trick for finding the link in the Mastodon context I don't know it. The permalink points back to Wordpress.

@pfefferle
Copy link
Member

This is how the permalink should work! It should point to the WordPress post.

@evilgeniuschronicles
Copy link

That's fine. It just makes it difficult to point out to you how this problem gets realized, since it shows up in the Fediverse in a way that cannot be pointed to directly.

@evilgeniuschronicles
Copy link

evilgeniuschronicles commented Feb 8, 2023

Scheduled vs Immediate publish

I updated the screenshot. I guess it takes Elk a few seconds to generate the preview. This makes it more obvious the only parts that are different.

image

@pfefferle
Copy link
Member

Sorry, but I still see no problem.

@pfefferle
Copy link
Member

It looks like it should look like.

@evilgeniuschronicles
Copy link

evilgeniuschronicles commented Feb 8, 2023

Top post, the one that was scheduled has hashtags in it. The bottom one, published by hitting the "Publish" button, does not. Both posts had the same three hashtags added in Wordpress prior to publish/schedule.

@pfefferle
Copy link
Member

Ah, we are talking about the hashtags! I was confused because you always talked about the permalink!

@evilgeniuschronicles
Copy link

I only talked about the permalink because it makes it hard to show you the hashtag problem. AFAIK screenshotting is the only option because I can't otherwise show you how it shows up in Mastodon.

@pfefferle pfefferle reopened this Feb 8, 2023
@evilgeniuschronicles
Copy link

@pfefferle If you want to follow from your Mastodon account @dave@evilgeniuschronicles.org that will cut out a middleman and you'll see my tests directly.

I know this issue is me complaining but I do appreciate your efforts. This is not a super-high priority to me since there is a trivial workaround but I can see this confusing new installers.

@pfefferle
Copy link
Member

Should finally work with 1.0.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants