Skip to content

Commit

Permalink
Update examples for embed commands (#75)
Browse files Browse the repository at this point in the history
* Update docs and examples

* Update readme to accommodate new changes in docs

* Fix CS error
  • Loading branch information
ernilambar authored Apr 4, 2024
1 parent 3987e20 commit edfa448
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,34 @@ Inspects oEmbed providers, clears embed cache, and more.
wp embed
~~~

**EXAMPLES**

# Get embed HTML for a given URL.
$ wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ
<iframe width="525" height="295" src="https://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed" ...

# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123

# List format,endpoint fields of available providers.
$ wp embed provider list
+------------------------------+-----------------------------------------+
| format | endpoint |
+------------------------------+-----------------------------------------+
| #https?://youtu\.be/.*#i | https://www.youtube.com/oembed |
| #https?://flic\.kr/.*#i | https://www.flickr.com/services/oembed/ |
| #https?://wordpress\.tv/.*#i | https://wordpress.tv/oembed/ |

# List id,regex,priority fields of available handlers.
$ wp embed handler list --fields=priority,id
+----------+-------------------+
| priority | id |
+----------+-------------------+
| 10 | youtube_embed_url |
| 9999 | audio |
| 9999 | video |
+----------+-------------------+



Expand Down Expand Up @@ -96,7 +123,20 @@ Retrieves oEmbed providers.
wp embed provider
~~~

**EXAMPLES**

# List format,endpoint fields of available providers.
$ wp embed provider list
+------------------------------+-----------------------------------------+
| format | endpoint |
+------------------------------+-----------------------------------------+
| #https?://youtu\.be/.*#i | https://www.youtube.com/oembed |
| #https?://flic\.kr/.*#i | https://www.flickr.com/services/oembed/ |
| #https?://wordpress\.tv/.*#i | https://wordpress.tv/oembed/ |

# Get the matching provider for the URL.
$ wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/oembed



Expand Down Expand Up @@ -196,7 +236,16 @@ Retrieves embed handlers.
wp embed handler
~~~

**EXAMPLES**

# List id,regex,priority fields of available handlers.
$ wp embed handler list --fields=priority,id
+----------+-------------------+
| priority | id |
+----------+-------------------+
| 10 | youtube_embed_url |
| 9999 | audio |
| 9999 | video |



Expand Down Expand Up @@ -259,7 +308,19 @@ Finds, triggers, and deletes oEmbed caches.
wp embed cache
~~~

**EXAMPLES**

# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123

# Clear cache for a post.
$ wp embed cache clear 123
Success: Cleared oEmbed cache.

# Triggers cache for a post.
$ wp embed cache trigger 456
Success: Caching triggered!



Expand Down
16 changes: 16 additions & 0 deletions src/Cache_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

/**
* Finds, triggers, and deletes oEmbed caches.
*
* ## EXAMPLES
*
* # Find cache post ID for a given URL.
* $ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
* 123
*
* # Clear cache for a post.
* $ wp embed cache clear 123
* Success: Cleared oEmbed cache.
*
* # Triggers cache for a post.
* $ wp embed cache trigger 456
* Success: Caching triggered!
*
* @package wp-cli
*/
class Cache_Command extends WP_CLI_Command {

Expand Down
29 changes: 29 additions & 0 deletions src/Embeds_Namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@
/**
* Inspects oEmbed providers, clears embed cache, and more.
*
* ## EXAMPLES
*
* # Get embed HTML for a given URL.
* $ wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ
* <iframe width="525" height="295" src="https://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed" ...
*
* # Find cache post ID for a given URL.
* $ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
* 123
*
* # List format,endpoint fields of available providers.
* $ wp embed provider list
* +------------------------------+-----------------------------------------+
* | format | endpoint |
* +------------------------------+-----------------------------------------+
* | #https?://youtu\.be/.*#i | https://www.youtube.com/oembed |
* | #https?://flic\.kr/.*#i | https://www.flickr.com/services/oembed/ |
* | #https?://wordpress\.tv/.*#i | https://wordpress.tv/oembed/ |
*
* # List id,regex,priority fields of available handlers.
* $ wp embed handler list --fields=priority,id
* +----------+-------------------+
* | priority | id |
* +----------+-------------------+
* | 10 | youtube_embed_url |
* | 9999 | audio |
* | 9999 | video |
* +----------+-------------------+
*
* @package wp-cli
*/
class Embeds_Namespace extends CommandNamespace {
Expand Down
2 changes: 1 addition & 1 deletion src/Fetch_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function ( $args ) use ( $response_size_limit ) {
remove_all_filters( 'oembed_dataparse' ); // Save a few cycles.
add_filter(
'oembed_dataparse',
function ( $ret, $data, $url ) {
function ( $ret, $data, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
return $data;
},
PHP_INT_MAX,
Expand Down
13 changes: 13 additions & 0 deletions src/Handler_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

/**
* Retrieves embed handlers.
*
* ## EXAMPLES
*
* # List id,regex,priority fields of available handlers.
* $ wp embed handler list --fields=priority,id
* +----------+-------------------+
* | priority | id |
* +----------+-------------------+
* | 10 | youtube_embed_url |
* | 9999 | audio |
* | 9999 | video |
*
* @package wp-cli
*/
class Handler_Command extends WP_CLI_Command {
protected $default_fields = array(
Expand Down
17 changes: 17 additions & 0 deletions src/Provider_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@

/**
* Retrieves oEmbed providers.
*
* ## EXAMPLES
*
* # List format,endpoint fields of available providers.
* $ wp embed provider list
* +------------------------------+-----------------------------------------+
* | format | endpoint |
* +------------------------------+-----------------------------------------+
* | #https?://youtu\.be/.*#i | https://www.youtube.com/oembed |
* | #https?://flic\.kr/.*#i | https://www.flickr.com/services/oembed/ |
* | #https?://wordpress\.tv/.*#i | https://wordpress.tv/oembed/ |
*
* # Get the matching provider for the URL.
* $ wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ
* https://www.youtube.com/oembed
*
* @package wp-cli
*/
class Provider_Command extends WP_CLI_Command {
protected $default_fields = array(
Expand Down

0 comments on commit edfa448

Please sign in to comment.