douzhi1972 2014-01-12 12:05
浏览 58

检查Wordpress主题中是否存在特定操作或过滤器

I want to check if any action/filter exists in the Wordpress theme.

I have tried has_action and has_filter. But the problem with these functions is that if the hook/filter exists and no callbacks are added to the hook or all callbacks are removed from the hook, these will return false.

  • 写回答

1条回答 默认 最新

  • dongyinglan8707 2014-11-18 19:28
    关注

    There is not an built-in Wordpress function that will check for this. But you would be able to check if a filter exists using the following code:

    // check for the existence of "the_content" filter
    if( array_key_exists( 'the_content' , $GLOBALS['wp_filter']) ) {
    }
    

    The problem with this is that it will only check if the filter exists at the point at which the above code runs. So if the above code runs in a plugin, and a filter is added in a theme template file (which happens later in execution order, it won't show up yet.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探