wp-graphql-acf icon indicating copy to clipboard operation
wp-graphql-acf copied to clipboard

oEmbed field returns URL and not embed HTML

Open elliott-w opened this issue 3 years ago • 4 comments

E.g. will return https://vimeo.com/999999999

instead of



Would be nice to be able to query both

elliott-w avatar Feb 25 '21 05:02 elliott-w

@Eltyo I'm not fully opposed to supporting this, but this seems a bit like something the client should do, not the API.

The client might not be an HTML rendering client, or might have a specific component that handles the markup, etc.

There's also a lot of things to consider, such as arguments, etc. Can the client specify a width and height and other options like frameborder, autoplay, etc? 🤔

This feels like plugin territory to start, I think.

I'll leave this issue open and flag as "needs discussion" and circle back on it.

jasonbahl avatar May 13 '21 18:05 jasonbahl

I think the main benefit of the embed HTML is the src is resolved to a different url by WP's oembed provider system. I think the resolved url could be returned in addition to the original url.

elliott-w avatar May 14 '21 03:05 elliott-w

I agree with Eltyo, we need the oembed url, not the url the user gives. It is very hard to implement oembed on the client side because of CORS.

casperleerink avatar Jun 16 '21 18:06 casperleerink

I've managed to filter the acf oembed field and return the embed code instead:

add_filter('wpgraphql_acf_register_graphql_field', function ($return, $type_name, $field_name, $config) {
    $acf_field = $config['acf_field'] ?? null;
    $acf_type = $acf_field['type'] ?? null;

    if ($acf_type === "oembed") {
        $return['resolve'] = function ($root) use ($acf_field) {
            if (isset($root[$acf_field['key']])) {
                $value = $root[$acf_field['key']];
                $embed = @wp_oembed_get($value);
                if ($embed) {
                    return $embed;
                }
            }

            return null;
        };
    }

    return $return;
}, 10, 4);

Hope that helps!

kpoelhekke avatar Oct 21 '21 08:10 kpoelhekke

👋🏻 We're re-building this plugin over here: https://github.com/wp-graphql/wpgraphql-acf

I've opened an issue over there to track this: https://github.com/wp-graphql/wpgraphql-acf/issues/106 and I have a PR in the works.

I'm going to close this issue in favor of the issue on the new repo.

This repo will be archived in the not-too-distant future and the new version of the plugin (complete re-architecture) will be released on WordPress.org shortly.

jasonbahl avatar Oct 31 '23 15:10 jasonbahl