wp-cli / embed-command
检查oEmbed提供者,清除嵌入缓存等。
Requires
- wp-cli/wp-cli: ^2.5
Requires (Dev)
- wp-cli/entity-command: ^1.3 || ^2
- wp-cli/wp-cli-tests: ^4
README
检查oEmbed提供者,清除嵌入缓存等。
使用
本包实现了以下命令
wp embed
检查oEmbed提供者,清除嵌入缓存等。
wp embed
示例
# 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 |
+----------+-------------------+
wp embed fetch
尝试将URL转换为嵌入HTML。
wp embed fetch <url> [--width=<width>] [--height=<height>] [--post-id=<id>] [--discover] [--skip-cache] [--skip-sanitization] [--do-shortcode] [--limit-response-size=<size>] [--raw] [--raw-format=<json|xml>]
在非原始模式下,首先将URL与已注册的嵌入处理程序的正则表达式进行匹配。如果没有匹配,并且已启用,则将URL提供给WP_oEmbed类。
在原始模式下,直接检查提供者并返回数据。
选项
<url>
URL to retrieve oEmbed data for.
[--width=<width>]
Width of the embed in pixels.
[--height=<height>]
Height of the embed in pixels.
[--post-id=<id>]
Cache oEmbed response for a given post.
[--discover]
Enable oEmbed discovery. Defaults to true.
[--skip-cache]
Ignore already cached oEmbed responses. Has no effect if using the 'raw' option, which doesn't use the cache.
[--skip-sanitization]
Remove the filter that WordPress from 4.4 onwards uses to sanitize oEmbed responses. Has no effect if using the 'raw' option, which by-passes sanitization.
[--do-shortcode]
If the URL is handled by a registered embed handler and returns a shortcode, do shortcode and return result. Has no effect if using the 'raw' option, which by-passes handlers.
[--limit-response-size=<size>]
Limit the size of the resulting HTML when using discovery. Default 150 KB (the standard WordPress limit). Not compatible with 'no-discover'.
[--raw]
Return the raw oEmbed response instead of the resulting HTML. Ignores the cache and does not sanitize responses or use registered embed handlers.
[--raw-format=<json|xml>]
Render raw oEmbed data in a particular format. Defaults to json. Can only be specified in conjunction with the 'raw' option.
---
options:
- json
- xml
---
示例
# 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" ...
# Get raw oEmbed data for a given URL.
$ wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ --raw
{"author_url":"https:\/\/www.youtube.com\/user\/RickAstleyVEVO","width":525,"version":"1.0", ...
wp embed provider
检索oEmbed提供者。
wp embed provider
示例
# 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
wp embed provider list
列出所有可用的oEmbed提供者。
wp embed provider list [--field=<field>] [--fields=<fields>] [--format=<format>] [--force-regex]
选项
[--field=<field>]
Display the value of a single field
[--fields=<fields>]
Limit the output to specific fields.
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
---
[--force-regex]
Turn the asterisk-type provider URLs into regexes.
可用的字段
以下字段将默认显示在每个提供者上
- 格式
- 端点
此字段为可选字段
- 正则表达式
示例
# List format,endpoint fields of available providers.
$ wp embed provider list --fields=format,endpoint
+------------------------------+-----------------------------------------+
| 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/ |
wp embed provider match
获取给定URL的匹配提供者。
wp embed provider match <url> [--discover] [--limit-response-size=<size>] [--link-type=<json|xml>]
选项
<url>
URL to retrieve provider for.
[--discover]
Whether to use oEmbed discovery or not. Defaults to true.
[--limit-response-size=<size>]
Limit the size of the resulting HTML when using discovery. Default 150 KB (the standard WordPress limit). Not compatible with 'no-discover'.
[--link-type=<json|xml>]
Whether to accept only a certain link type when using discovery. Defaults to any (json or xml), preferring json. Not compatible with 'no-discover'.
---
options:
- json
- xml
---
示例
# Get the matching provider for the URL.
$ wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/oembed
wp embed handler
检索嵌入处理程序。
wp embed handler
示例
# 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 |
wp embed handler list
列出所有可用的嵌入处理程序。
wp embed handler list [--field=<field>] [--fields=<fields>] [--format=<format>]
选项
[--field=<field>]
Display the value of a single field
[--fields=<fields>]
Limit the output to specific fields.
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
---
可用的字段
以下字段将默认显示在每个处理程序上
- id
- 正则表达式
以下字段为可选字段
- 回调
- 优先级
示例
# 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 |
wp embed cache
查找、触发和删除oEmbed缓存。
wp embed cache
示例
# 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!
wp embed cache clear
删除给定帖子的所有oEmbed缓存。
wp embed cache clear <post_id>
帖子的oEmbed缓存存储在帖子的元数据中。
选项
<post_id>
ID of the post to clear the cache for.
示例
# Clear cache for a post
$ wp embed cache clear 123
Success: Cleared oEmbed cache.
wp embed cache find
查找给定URL的oEmbed缓存帖子的ID。
wp embed cache find <url> [--width=<width>] [--height=<height>] [--discover]
从WordPress 4.9开始,与特定帖子不关联的嵌入将缓存在新oembed_cache帖子类型中。一个url可以有多个此类条目,具体取决于属性和上下文。
不要与存储在帖子元数据中的给定帖子的oEmbed缓存混淆。
选项
<url>
URL to retrieve oEmbed data for.
[--width=<width>]
Width of the embed in pixels. Part of cache key so must match. Defaults to `content_width` if set else 500px, so is theme and context dependent.
[--height=<height>]
Height of the embed in pixels. Part of cache key so must match. Defaults to 1.5 * default width (`content_width` or 500px), to a maximum of 1000px.
[--discover]
Whether to search with the discover attribute set or not. Part of cache key so must match. If not given, will search with attribute: unset, '1', '0', returning first.
示例
# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123
wp embed cache trigger
触发给定帖子的所有oEmbed结果的缓存。
wp embed cache trigger <post_id>
帖子的oEmbed缓存存储在帖子的元数据中。
选项
<post_id>
ID of the post to do the caching for.
示例
# Triggers cache for a post
$ wp embed cache trigger 456
Success: Caching triggered!
安装
本包包含在WP-CLI自身中,无需额外安装。
要安装此包的最新版本,覆盖WP-CLI中包含的版本,请运行
wp package install [email protected]:wp-cli/embed-command.git
贡献
我们感谢您主动为这个项目做出贡献。
贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如撰写教程、在当地聚会中进行演示、帮助其他用户解答支持问题或修订我们的文档。
要了解更多信息,请查看WP-CLI的贡献指南。本包遵循那些政策和指南。
报告错误
认为找到了一个错误?我们很高兴您能帮助我们修复它。
在创建新问题之前,您应该先搜索现有问题,看看是否已有针对该问题的解决方案,或者它是否已在较新版本中修复。
一旦您搜索了一下并发现您的错误没有开放或已修复的问题,请创建一个新问题。尽可能提供详细信息,如果可能的话,包括重现问题的清晰步骤。更多指导,请查看我们的错误报告文档。
创建拉取请求
想要贡献新功能?请首先打开一个新问题,讨论这个功能是否适合项目。
一旦您决定投入时间完成您的拉取请求,请遵循我们创建拉取请求的指南,确保它是一个愉快的体验。有关在本地处理此包的详细信息,请参阅"设置"。
支持
GitHub问题不是用于一般支持问题的,但您可以尝试其他途径:https://wp-cli.org/#support
此README.md文件是使用wp scaffold package-readme
(文档)从项目的代码库动态生成的。要提出建议,请提交针对代码库相应部分的拉取请求。