【问题标题】:Wordpress desactivate plugins on mobileWordpress 在移动设备上停用插件
【发布时间】:2023-03-11 17:16:01
【问题描述】:

我正在为 WordPress 构建一个移动插件,我想添加停用非移动兼容插件的可能性。

我发现了一些有帮助但不是我需要的代码。

 debug_filter("/^woocommerce/i");
 function debug_filter($regex_filter_action_to_match = "//"){
 global $wp_filter;
 $hook=$wp_filter;
 ksort($hook); 
 echo "<pre style='background-color:white;'>";
 foreach($hook as $tag => $priority){

  //check for a regex match of hook name
     if ( !preg_match($regex_filter_action_to_match, $tag) ) continue;

  echo "<br /><strong>$tag</strong><br />";
  ksort($priority);
  foreach($priority as $priority => $function){
  echo " $priority \n";
      foreach($function as $name => $properties) {


          echo "\t$name  ";

            if ( function_exists($name) ){
                $func = new ReflectionFunction($name);
                $filename = $func->getFileName();
                $start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
                $path_info = pathinfo($filename);
                print_r($func);
                    echo "<em style='font-size:90%;opacity:0.5;' title='{$filename}'> {$path_info[filename]}.{$path_info[extension]}: line {$start_line}</em>";
            }
          echo "<br />";
          remove_filter( $tag, $name, $priority);
            //remove_action( 'init', array( 'Jetpack_Likes', 'action_init' )    );
      }
  }
 }
 echo '</pre>';
 return;
}

有没有人设法构建或知道将使用 remove_filter 和 remove_action 停用插件的类。

感谢您的所有帮助。

  • 戴夫

【问题讨论】:

  • 我想我已经找到答案了,谢谢。测试后我会贴在下面。

标签: php wordpress mobile


【解决方案1】:

这是我想出的。它可能并不完美,但似乎有效。

wp_remove_filter("/^woocommerce/i");

 function wp_remove_filter($regex_filter_action_to_match = "//"){
 global $wp_filter, $wp_actions ;
 $hook=$wp_filter;

 ksort($hook);

 echo "<pre style='background-color:white;'>";
 foreach($hook as $tag => $priority){

     if ( !preg_match($regex_filter_action_to_match, $tag) ) continue;

  ksort($priority);
  foreach($priority as $priority => $function){

      foreach($function as $name => $properties) {

            if ( function_exists($name) ){
                $func = new ReflectionFunction($name);
                $filename = $func->getFileName();
                $start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
                $path_info = pathinfo($filename);

                if($priority ==""): 
                remove_action( $tag, $name);
                else:
                remove_action( $tag, $name, $priority);
                endif;

            }else{
                if($priority ==""): 
                remove_filter( $tag, $name);
                else:
                remove_filter( $tag, $name, $priority);
                endif;

            }
            //remove_action( 'init', array( 'Jetpack_Likes', 'action_init' ) );
      }
  }
 }
 echo '</pre>';
 return;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 2018-07-12
    • 2020-03-31
    • 2022-08-05
    • 2023-03-06
    • 1970-01-01
    • 2013-02-20
    相关资源
    最近更新 更多