wp_filter_oembed_result
函数
wp_filter_oembed_result ( $result, $data, $url )
- 参数
-
-
(string)
$result
The oEmbed HTML result.- Required: 是
-
(object)
$data
A data object result from an oEmbed provider.- Required: 是
-
(string)
$url
The URL of the content to be embedded.- Required: 是
-
(string)
- 返回值
-
- (string) The filtered and sanitized oEmbed result.
- 定义位置
-
-
wp-includes/embed.php
, line 909
-
wp-includes/embed.php
- 引入
- 4.4.0
- 弃用
- –
过滤给定的oEmbed HTML。
如果`$url`不在可信任的提供者名单上,我们需要对HTML进行严格的过滤以保证安全。
只过滤’rich’和’video’响应类型。
function wp_filter_oembed_result( $result, $data, $url ) { if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ), true ) ) { return $result; } $wp_oembed = _wp_oembed_get_object(); // Don't modify the HTML for trusted providers. if ( false !== $wp_oembed->get_provider( $url, array( 'discover' => false ) ) ) { return $result; } $allowed_html = array( 'a' => array( 'href' => true, ), 'blockquote' => array(), 'iframe' => array( 'src' => true, 'width' => true, 'height' => true, 'frameborder' => true, 'marginwidth' => true, 'marginheight' => true, 'scrolling' => true, 'title' => true, ), ); $html = wp_kses( $result, $allowed_html ); preg_match( '|(.*?)?.*()|ms', $html, $content ); // We require at least the iframe to exist. if ( empty( $content[2] ) ) { return false; } $html = $content[1] . $content[2]; preg_match( '/ src=(['"])(.*?)1/', $html, $results ); if ( ! empty( $results ) ) { $secret = wp_generate_password( 10, false ); $url = esc_url( "{$results[2]}#?secret=$secret" ); $q = $results[1]; $html = str_replace( $results[0], ' src=' . $q . $url . $q . ' data-secret=' . $q . $secret . $q, $html ); $html = str_replace( '
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。