希望阻止包含非https URL的oEmbed请求,但下面的代码对我没有帮助。不确定这是否是正确的钩子。有什么想法吗?
add_filter('pre_oembed_result', array($this, 'filter_oembed'), 5, 3);
function filter_oembed ($result, $url, $args) {
if (substr($url, 0, 7) === "http://") {
return null;
}
}我正在使用Wordpress 4.7.2。
发布于 2017-04-13 18:33:28
我没有太多的Wordpress经验,但是医生们让它听起来像是在期待某种返回,而且只有在URL以"http://"“开头时才返回。另外,我假设这是在某种类中运行的,否则在回调规范中使用$this将不能很好地工作。顺便说一句,PHP提供了内置函数来解析URL:
<?php
add_filter('pre_oembed_result', array($this, 'filter_oembed'), 5, 3);
function filter_oembed ($result, $url, $args) {
if (parse_url($url, PHP_URL_SCHEME) !== "https") {
$result = false;
}
return $result;
}禁用单个短代码或至少所有内部链接的oEmbed也可能会对事情有更多的了解。
https://stackoverflow.com/questions/43399018
复制相似问题