• Resolved maslk

    (@maslk)


    I am using a python script to generate and publish posts via api, rather than manually adding them in wordpress backend.

    I would like magic thumbnail to automatically generate a featured image at the same time as each post is published but at the moment it does not work.

    Is there a setting I need to change? or some way I can call this with the python script when generating the article?

    I can go in manually and select posts then bulk generate but I am looking for a way to do this automatically when each new post is added

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Alexandre Gaboriau

    (@mcurly)

    Hi maslk,
    This is not currently included in the plugin. I may add it in a future update.

    In the meantime, you can still generate the image with a few lines of php code using the post id.
    I’m not sure about this code but maybe you would reuse these lines :

    $plugin = new Magic_Post_Thumbnail();
    $plugin_admin = new Magic_Post_Thumbnail_Admin( $plugin->get_plugin_name(), $plugin->get_version() );
    $launch_plugin = $plugin_admin->MPT_trigger_wp_insert_post($post_id);
    Thread Starter maslk

    (@maslk)

    Thanks thats great. Managed to get it working creating a new endpoint and calling from python:

    <?php
    /*
    Plugin Name: Magic Post Thumbnail Trigger
    Description: Trigger Magic Post Thumbnail via REST API.
    */
    
    function trigger_magic_post_thumbnail($request) {
    ? ? $post_id = $request['id'];
    
    ? ? // Trigger Magic Post Thumbnail using the post ID.
    ? ? $plugin = new Magic_Post_Thumbnail();
    ? ? $plugin_admin = new Magic_Post_Thumbnail_Admin( $plugin->get_plugin_name(), $plugin->get_version() );
    ? ? $launch_plugin = $plugin_admin->MPT_trigger_wp_insert_post($post_id);
    
    ? ? return rest_ensure_response('Image generation triggered.');
    }
    
    add_action('rest_api_init', function () {
    ? ? register_rest_route('magic-post-thumbnail/v1', '/trigger/(?P<id>\d+)', array(
    ? ? ? ? 'methods' => 'GET',
    ? ? ? ? 'callback' => 'trigger_magic_post_thumbnail',
    ? ? ));
    });
    Plugin Author Alexandre Gaboriau

    (@mcurly)

    Glad to know it works with this code!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘API post generation, no images generated’ is closed to new replies.