Support » Plugin: Better REST API Featured Images » Doesn’t work with WP REST API v 2.0-beta13

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

    (@braad)

    Hello samcalegari,

    Very interesting. My guess is that on the microplus.fr site where it’s not working, the custom post type “format” is being registered on a hook later than init at priority 12 (which is often the case if you use plugins to register CPTs like Pods).

    You can see here: https://github.com/BraadMartin/better-rest-api-featured-images/blob/master/better-rest-api-featured-images.php#L47 that the logic for including the better_featured_image field involves 2 checks. The first is a check for show_in_rest = true on the post type registration args, and the second is a check for whether featured images (thumbnail) are enabled on the post type.

    Can you try this, in the Better REST API Featured Images plugin, can you change the priority at which the plugin is registering the field from 12 to something like 99? You would do this on this line: https://github.com/BraadMartin/better-rest-api-featured-images/blob/master/better-rest-api-featured-images.php#L32

    If you change the priority to 99 and the field shows up, you’ll know that the issue is that the custom post type “format” is being registered too late. If changing to 99 doesn’t cause the field to show, you’ll know that it’s some other issue.

    If changing to 99 does make it show, then all you need to do is safely unhook and rehook the better_rest_api_featured_images_init() function. This can be done like this:

    
    add_action( 'plugins_loaded', function() {
        remove_action( 'init', 'better_rest_api_featured_images_init', 12 );
        add_action( 'rest_api_init', 'better_rest_api_featured_images_init' );
    });
    

    or like this:

    
    add_action( 'plugins_loaded', function() {
        remove_action( 'init', 'better_rest_api_featured_images_init', 12 );
        add_action( 'init', 'better_rest_api_featured_images_init', 99 );
    });
    

    ^Both of those should do the trick, and here’s a thread on the Github repo for the plugin where someone else ran into this exact issue, and there’s a more thorough discussion about it there: https://github.com/BraadMartin/better-rest-api-featured-images/issues/8

    Hopefully this works for you, but let me know if it doesn’t. I’m using the plugin with v2 Beta 13 of the REST API plugin and it’s working great, so I’m confident it’s not an issue with the plugin itself. :).

    -Braad

    • This reply was modified 3 years, 6 months ago by Braad.

    Perfect !
    It’s awesome !

    i use

    add_action( 'plugins_loaded', function() {
        remove_action( 'init', 'better_rest_api_featured_images_init', 12 );
        add_action( 'init', 'better_rest_api_featured_images_init', 99 );
    });

    in functions.php

    thanks a thousands for your reply !

    Plugin Author Braad

    (@braad)

    Glad it is now working for you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Doesn’t work with WP REST API v 2.0-beta13’ is closed to new replies.