2017-04-13 48 views
1

想阻止包含非https网址的oEmbed请求,但以下代码无法帮助我。不知道这是否是正确的选择。有任何想法吗?如何屏蔽WordPress oEmbed HTTP网址

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。

回答

1

我没有太多的Wordpress体验,但the docs听起来像是期待某种回报,并且只有当URL以“http://”开头时才会返回。此外,我认为这是在某种类别中运行,否则在回调规范中使用$this将无法​​正常工作。顺便说一句,PHP提供a built-in function分析一个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; 
} 

Disable oEmbed for a Single Shortcode or at Least All Internal Links还可以揭示事物更多的光线。

+0

感谢链接你包括帮助..在你的答案应该返回false而不是返回null! – srvy

+0

好的,已更新。我不确定... – miken32