junaidbhura / auto-cloudinary

Super simple Cloudinary auto-upload implementation for WordPress.
https://wordpress.org/plugins/auto-cloudinary/
MIT License
40 stars 9 forks source link

Headless Wordpress #37

Closed djmtype closed 4 years ago

djmtype commented 4 years ago

Logically, plugins don't work with a headless Wordpress setup. But, is there anyway to leave Cloudinary's CDN URL intact when exporting a Gridsome/Gatsby site? Using the auto content images option BTW.

junaidbhura commented 4 years ago

Hey @djmtype this plugin loads when the front-end is ready to load: https://github.com/junaidbhura/auto-cloudinary/blob/master/inc/namespace.php#L53-L60

Maybe you could try that initialization code on init in your functions.php file and see if that works?

add_action(
    'init',
    function () {
        \JB\Cloudinary\Core::get_instance()->setup();
        \JB\Cloudinary\Frontend::get_instance()->setup();
    }
);

Note: I'd recommend testing this locally or on a dev environment.

djmtype commented 4 years ago

@junaidbhura Unfortunately, that didn't work. The image paths do not reference the Cloudinary paths in any of the endpoints within the API. For example, http://wp-site.com/wp-json/wp/v2/posts/

junaidbhura commented 4 years ago

Hey @djmtype in addition to the init hook above, could you also add this?

add_filter( 'cloudinary_allow_rest_api_call', '__return_true' );
djmtype commented 4 years ago

@junaidbhura Worked like a charm. Thank you very much!

junaidbhura commented 4 years ago

No worries @djmtype , happy to help :)

I think just to be safe, you could future-proof the code some more like so:

if ( class_exists( '\JB\Cloudinary\Core' ) ) {
    add_action(
        'init',
        function () {
            \JB\Cloudinary\Core::get_instance()->setup();
            \JB\Cloudinary\Frontend::get_instance()->setup();
        }
    );

    add_filter( 'cloudinary_allow_rest_api_call', '__return_true' );
}
djmtype commented 4 years ago

Of course, in case this plugin is disabled or doesn't exist, no fatal errors are thrown. Thanks again!

junaidbhura commented 4 years ago

That's right. Cheers!