-
Notifications
You must be signed in to change notification settings - Fork 0
Tribe Embeds Updates #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8c73f25
7ae2c74
490d7c4
beca8cd
218cd87
dd23899
6c8c198
66d8bc5
266e08e
50761ec
8d9f26c
5d1f523
9d61acd
b4325c0
656dd54
94386cd
d8d7e08
eb39aec
e1cfb18
0ad3f57
63299ff
634688f
1c60776
5d868f5
7ac3cbd
59a0a35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ excludes: | |
| - .github | ||
|
|
||
| config: | ||
| php: '8.0' | ||
| php: '8.3' | ||
| via: nginx | ||
| database: mysql | ||
| webroot: dev/public | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,39 +32,117 @@ If you need to rebuild the lando environment you will need to delete the `./dev/ | |
|
|
||
| This repo is setup to use the [WP CLI dist-archive](https://developer.wordpress.org/cli/commands/dist-archive/) command. To build the zip file for the make sure you have the dist-archive command package installed and run `wp dist-archive .` form the root folder. The zip file will be created one folder back form the root folder. | ||
|
|
||
| ### Vimeo | ||
|
|
||
| ### Providers | ||
| In order to make Vimeo provider thumbs work correctly create an access token https://help.vimeo.com/hc/en-us/articles/12427789081745-How-to-generate-a-personal-access-token | ||
| Use Tribe Embeds Settings page to store token via DB or set `VIMEO_ACCESS_TOKEN` in you wp-config.php | ||
|
|
||
| Each provider represents separate service(YouTube, Vimeo, etc). In order to provide ability extend list of providers use `tribe-embeds_video_provider` hook. | ||
| For proper use add new class in your theme or plugin. Each provider should extend `Tribe\Tribe_Embed\Provider` class | ||
| Usage example: | ||
|
|
||
| ## Hooks (filters & actions) | ||
|
|
||
| These are the **public** extension points intended for themes/plugins to customize behavior. Names and arguments are considered part of the API. | ||
|
|
||
| ### Filters | ||
|
|
||
| #### `tribe-embeds_allowed_provider_hosts` | ||
|
|
||
| Expand or restrict the whitelist of hostnames that can be handled by built-in or custom providers. | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe-embeds_allowed_provider_hosts', $allowed_hosts, $host )` | ||
| - **Args:** | ||
| - `$allowed_hosts` — array of allowed host strings (e.g. ['youtube.com', 'youtu.be', 'vimeo.com', 'dailymotion.com']) | ||
| - `$host` — the currently detected host | ||
| - **Return:** Modified array of allowed hosts. | ||
| - **Example:** | ||
| ```php | ||
| class TestProvider extends \Tribe\Tribe_Embed\Provider { | ||
| .... | ||
| } | ||
|
|
||
| function is_allowed_provider(): bool { | ||
| ... | ||
| } | ||
|
|
||
| /** | ||
| * @var mixed|null $provider | ||
| * @var array $video_url_data Video url parsed with parse_url | ||
| * @var array $block The full block, including name and attributes. | ||
| */ | ||
| add_filter( 'tribe-embeds_video_provider', function( $provider, $video_url_data, $block ) { | ||
| if ( is_allowed_provider( $video_url_data['host'] ) ) { | ||
| return $provider; | ||
| } | ||
| return ( new TestProvider( $video_url_data ) ); | ||
| }, 10, 3 ); | ||
| add_filter( 'tribe-embeds_allowed_provider_hosts', function ( array $hosts ) { | ||
| $hosts[] = 'videos.example.com'; | ||
| return $hosts; | ||
| }, 10 ); | ||
| ``` | ||
| A list of allowed providers can be updated via `tribe-embeds_allowed_provider_hosts` hook | ||
|
|
||
| #### `tribe_embeds_video_provider` | ||
|
|
||
| Allow short-circuit with a ready-made provider instance | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_video_provider', null, $video_url_data, $block )` | ||
| - **Args:** | ||
| - `null|<Provider object>` — if object provided resolves immediately and return provided object | ||
| - `$video_url_data` — embed video ulr | ||
| - `$block` — current embed block data | ||
| - **Return:** `null` or provided provider class | ||
| - **Example:** | ||
| ```php | ||
| /** | ||
| * Allows to inject custom provider hosts | ||
| * @var array $allowed_hosts List of allowed hosts | ||
| * @var string $host Current video hostname | ||
| */ | ||
| $allowed_hosts = apply_filters( 'tribe-embeds_allowed_provider_hosts', $allowed_hosts, $host ); | ||
| add_filter( 'tribe_embeds_video_provider', function ( $obj, $video_url_data, $block ) { | ||
| // Note: $video_url_data has parsed video url. Provider accepts url string | ||
| $provider = new CustomProvider( $video_url ); | ||
|
|
||
| return $provider; | ||
| }, 10 ); | ||
| ``` | ||
|
|
||
| #### `tribe_embeds_allowed_provider_hosts_<slug>` | ||
|
|
||
| Adjust allowed hosts for provider | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_allowed_provider_hosts_' . $slug, $base, $provider_class );` | ||
| - **Args:** | ||
| - `$base` — list of allowed hosts | ||
| - `$provider_class` — current provider class | ||
|
|
||
| #### `tribe_embeds_allowed_provider_hosts` | ||
|
|
||
| Adjust allowed hosts for provider | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_allowed_provider_hosts', $by_provider, $provider_class );` | ||
| - **Args:** | ||
| - `$by_provider` — List of hosts returned from `tribe_embeds_allowed_provider_hosts_<slug>` | ||
| - `$provider_class` — current provider class | ||
|
|
||
| #### `tribe_embeds_image_sizes_<slug>` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little confused on the intent and difference in the filter here and below.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This specific for provider. The below one is global version. In case you want catch all items one by one and not only the specific one |
||
|
|
||
| Get image sizes for a provider | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_image_sizes_' . $slug, $base, $provider_class );` | ||
| - **Args:** | ||
| - `$base` — list of image sizes | ||
| - `$provider_class` — current provider class | ||
|
|
||
| #### `tribe_embeds_image_sizes` | ||
|
|
||
| Get image sizes for a provider | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_image_sizes', $by_provider, $provider_class );` | ||
| - **Args:** | ||
| - `$by_provider` — list of image sizes `tribe_embeds_image_sizes` | ||
| - `$provider_class` — current provider class | ||
|
|
||
| #### `tribe_embeds_provider_classes` | ||
|
|
||
| Allow external override of provider class list | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_provider_classes', $provider_classes ?: $defaults );` | ||
| - **Args:** | ||
| - `$provider_classes` — list of existing providers classes | ||
|
|
||
| #### `tribe_embed_<video-provider>_video_thumbnail_url` | ||
|
|
||
| Allows adjusting image data for each provider. Use slug instead of `<video-provider>` e.g `tribe_embed_wistia_video_thumbnail_url` | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embed_wistia_video_thumbnail_url', $image_data, $video_id )` | ||
| - **Args:** | ||
| - `$image_data` — Thumbnail image data | ||
| - `$video_id` — current video id | ||
| - **Return:** Video thumbnail image data. | ||
|
|
||
| #### `tribe_embeds_facade_html` | ||
|
|
||
| Fires an action with the new block markup attached. | ||
|
|
||
| - **Signature:** `apply_filters( 'tribe_embeds_facade_html', $facade_html, $provider, $block, $html )` | ||
| - **Args:** | ||
| - `$facade_html` — Resulting html | ||
| - `$provider` — provider class | ||
| - `$block` — current block | ||
| - `$html` — original block html | ||
| - **Return:** Embed block markup | ||
Uh oh!
There was an error while loading. Please reload this page.