• Resolved flynsarmy

    (@flynsarmy)


    We had an incredibly difficult to diagnose issue where featured images weren’t broadcasting. The Media post itself broadcast and created correctly the file was copied on disk correctly, it just wasn’t being attached to the broadcasted post. The problem only occurred when broadcasting via cron job – broadcasting with the Efficiency Pack’s Network Queue page worked fine.

    The problem turned out to be an incompatibility with the PublishPress Revisions plugin – specifically this action hook.

    I’m guessing the agp_user_can line returns true from the Network Queue page but false when a broadcast is triggered via cron – because cron jobs have no logged in user. As a result the _thumbnail_id meta is never attached to the broadcasted post.

    I added the following code in my functions.php file to fix the issue:

    add_action('threewp_broadcast_broadcasting_started', function(\threewp_broadcast\actions\broadcasting_started $action) {
        // This action will stop featured images being attached to broadcasted
        // posts when the broadcast is handled via cron.
        remove_action('update_post_metadata', '_rvy_limit_postmeta_update', 10);
    });

    After that, featured images broadcasted perfectly.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author edward_plainview

    (@edward_plainview)

    Good find! It’s stuff like that that absolutely infuriates me: why check for user caps if the post is already being updated?

    So what do you figure we do? Just keep it here for future use or bake it into a 3rd party add-on?

    Thread Starter flynsarmy

    (@flynsarmy)

    That action hook exists for users updating existing posts on the current blog – not what we’re doing. We probably always want broadcast to sync the featured image across blogs for new and existing posts.

    The correct course of action is probably to create a third party add-on that removes the filter on broadcasting_started then re-add it on broadcasting_finished I think.

    Something like so should work:

    add_action('threewp_broadcast_broadcasting_started', function (\threewp_broadcast\actions\broadcasting_started $action) {
        // This action will stop featured images being attached to broadcasted
        // posts when the broadcast is handled via cron.
        remove_action('update_post_metadata', '_rvy_limit_postmeta_update', 10);
    });
    
    add_action('threewp_broadcast_broadcasting_finished', function (\threewp_broadcast\actions\broadcasting_finished $action) {
        // Add the action back for any post-broadcast code that may run
        add_action('update_post_metadata', '_rvy_limit_postmeta_update', 10, 5);
    });
    Thread Starter flynsarmy

    (@flynsarmy)

    Is the threewp broadcast base plugin source available on Github? I’ll whip up a pull request for an improvement to your logging that helped me debug this issue.

    Plugin Author edward_plainview

    (@edward_plainview)

    The code is available on bitbucket: https://bitbucket.org/edward_electric/broadcast/src/master/

    If you don’t have an account at bitbucket, feel free to zip your BC directory and I can merge it myself.

    Plugin Author edward_plainview

    (@edward_plainview)

    Hah! I did an even smarter thing than creating a whole new add-on: I added the remove action to the queue add-on.

    src / queue / queue.php line 643 in the http_process function.

    Now the fix is automatic for all users of the queue.

    Thread Starter flynsarmy

    (@flynsarmy)

    Are cron broadcasts part of the base plugin? If so those users will be affected by the issue as well. If not then your solution should work fine!

    I’d recommend checking for function_exists() and adding the action back on broadcast finish as well just incase some users decide they want to do some post-broadcast modifying of posts in which case they WILL want the usual revisionary behaviour to take place.

    Thread Starter flynsarmy

    (@flynsarmy)

    I’ve discovered the line
    remove_action('delete_post_metadata', '_rvy_limit_postmeta_update', 10);
    is also required or removing featured images on existing brooadcasts when hitting update on a parent post won’t work.

    Plugin Author edward_plainview

    (@edward_plainview)

    I’ve put that in the queue add-on also.

    I love it when plugins hook into really, really basic things such as adding or removing postmeta calls.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Fix] Featured images not broadcasting’ is closed to new replies.