Giter Club home page Giter Club logo

Comments (10)

janboddez avatar janboddez commented on August 16, 2024

Hmm, I was just able to crosspost a featured image just fine, (even) from the WP app. (Force-enabled crossposting by adding add_filter( 'share_on_mastodon_enabled', '__return_true', 999 ); to a must-use plugin, but you got that part right or it wouldn't work at all ... [That prio number is pretty random, btw. Just didn't wanna take any risks.] Did not touch any of the other filters.)

Is your featured image correctly set, on the post itself?

Any idea what Mastodon version your instance is on? (I'm still on 3.2.2, I believe the latest one is 3.3.0.) One thing that comes to mind is the media endpoint I'm using was going to deprecated ... On 3.3.0 now, still works, I'm afraid: https://geekcompass.com/@ochtendgrijs/105510788586078078.

Another is that the image is too large or the request times out, although I set that to 15 seconds.

Would you mind enabling debug logging, by adding something like this to wp-config.php?

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

I'm pretty much writing the entire error/response to the debug log, but only when logging is enabled.

error_log( print_r( $response, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions

Then, if something isn't going as planned, it should show in the log.

from share-on-mastodon.

timnolte avatar timnolte commented on August 16, 2024

Yeah, I'll do some more testing tonight with debugging turned on. I'm wondering if for new posts there is a timing/order issue since the image may not actually but uploaded to the site yet when the post is uploaded/published.

from share-on-mastodon.

janboddez avatar janboddez commented on August 16, 2024

Just curious: any update on this?

I mostly use a Micropub app (which is somewhat similar), rather than the official WP app, and because it doesn't do Featured Images per se, I sort of am delaying crossposting till I've "fixed" that (force-set a Featured Image, in a way, but after the post's already published) later on in WordPress's sequence. So that would be kind of similar.

I guess what I'm saying is, you could also not use share_on_mastodon_enabled, but rather set the underlying post meta field after crossposting would normally take place, and only then "trigger" crossposting (or, perhaps, schedule it a couple minutes into the future).

Just a quick thought:

// This would run _after_ crossposting to Mastodon would normally take place.
add_action( 'publish_post', function( $post_id, $post ) {
  if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
    // Do nothing.
    return;
  }

  // Bluntly enable sharing to Mastodon for each and every post.
  update_post_meta( $post_id, '_share_on_mastodon', '1' );

  // Quick and dirty way to re-trigger Share on Mastodon's `Post_Handler::toot()` method.
  // do_action( 'transition_post_status', 'publish', 'publish', $post ); // Still too soon?

  wp_schedule_single_event( time() + 60, 'my_custom_event', array( $post ) ); // Or something like this.
}, 10, 2 );

add_action( 'my_custom_event', function( $post ) {
  // Quick and dirty way to re-trigger Share on Mastodon's `Post_Handler::toot()` method.
  do_action( 'transition_post_status', 'publish', 'publish', $post );
} );

Of course, publish_post works only for, well, posts. But there are ways around that as well. (Was hoping to avoid endless loops here by not reusing transition_post_status.)

from share-on-mastodon.

larsmagne avatar larsmagne commented on August 16, 2024

I ran into the same issue. I'm posting via xmlrpc, and I'm using a plugin to always set the first image as the featured image (and I've set Share on Mastodon to include the featured image, and no attached images). But perhaps that plugin is being run too late, so there's no featured image when Share on Mastodon is being triggered?

I wonder whether an alternate take on this would simplify things: I want the first image in the post to be included, so I could instead use share_on_mastodon_attached_images true -- if I could control the number of attached images to include. That's currently hardcoded at 4 (in post_to_mastodon). If that wasn't hardcoded, I could just change the number of images to 1, and things would presumably work as I want them to...

from share-on-mastodon.

janboddez avatar janboddez commented on August 16, 2024

But perhaps that plugin is being run too late, so there's no featured image when Share on Mastodon is being triggered?

I've been trying to replicate this behavior, unsuccessfully.

The latest version has an option for delayed posting. What happens when you use that? Set it to, e.g., 300 seconds or so?

You could even post a test post through XML-RPC, and then check in WP Admin (without saving anything, as that would trigger syndication) if the featured image is really there. If so, it should go through okay once the cron event is triggered.

Would that be something you're willing to give a try?

from share-on-mastodon.

larsmagne avatar larsmagne commented on August 16, 2024

Sure, I can give delayed posting a try. I had a peek at the documentation, but didn't see any mention of "delay" there -- what's the incantation to use?

from share-on-mastodon.

janboddez avatar janboddez commented on August 16, 2024

There should be a field on the settings page. Maybe try setting it to 300 seconds (or 120 or something, but, say, more than a minute)?

from share-on-mastodon.

larsmagne avatar larsmagne commented on August 16, 2024

Ah, right. I've now updated the setting and will be testing later today and get back to you on the results.

from share-on-mastodon.

larsmagne avatar larsmagne commented on August 16, 2024

I've now tried it, and it seems to work perfectly. I used a 30 second delay, but I can probably make that shorter.

from share-on-mastodon.

janboddez avatar janboddez commented on August 16, 2024

Ah, cool! Yeah, either it's something using a later hook than the one I use to trigger syndication, or some background process that hasn't yet finished. Glad it works this way. I should update the documentation now.

from share-on-mastodon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.