wp-graphql-acf
wp-graphql-acf copied to clipboard
oEmbed field returns URL and not embed HTML
E.g. will return https://vimeo.com/999999999
instead of
Would be nice to be able to query both
@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.
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.
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.
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!
👋🏻 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.