如何使用Remove_action()从插件中删除类函数?

时间:2018-06-25 作者:Ray Macz

var\\u转储的结果(“parse\\u query”):

 WP_Hook::__set_state(array(
    \'callbacks\' => 
    array (
    10 => 
      array (
       \'0000000003c8dc5e000000004a442b5dsort_menu_item_queries_by_menu_order\' => 
      array (
         \'function\' => 
       array (
      0 => 
      WM_Nova_Restaurant::__set_state(array(
         \'version\' => \'0.1\',
         \'default_menu_item_loop_markup\' => 
        array (
          \'menu_tag\' => \'section\',
          \'menu_class\' => \'menu-items\',
          \'menu_header_tag\' => \'header\',
          \'menu_header_class\' => \'menu-group-header\',
          \'menu_title_tag\' => \'h1\',
          \'menu_title_class\' => \'menu-group-title\',
          \'menu_description_tag\' => \'div\',
          \'menu_description_class\' => \'menu-group-description\',
        ),
         \'menu_item_loop_markup\' => 
        array (
          \'menu_tag\' => \'section\',
          \'menu_class\' => \'menu-items\',
          \'menu_header_tag\' => \'header\',
          \'menu_header_class\' => \'menu-group-header\',
          \'menu_title_tag\' => \'h2\',
          \'menu_title_class\' => \'menu-group-title\',
          \'menu_description_tag\' => \'div\',
          \'menu_description_class\' => \'menu-group-description\',
        ),
         \'menu_item_loop_last_term_id\' => false,
         \'menu_item_loop_current_term\' => false,
      )),
      1 => \'sort_menu_item_queries_by_menu_order\',
    ),
    \'accepted_args\' => 1,
  ),
),
),
 \'iterations\' => 
  array (
   ),
  \'current_priority\' => 
 array (
  ),
   \'nesting_level\' => 0,
   \'doing_action\' => false,
  ))
我试过这些,但都不管用:

 function RBTM_my_func(){
  global $WM_Nova_Restaurant;
  remove_action(\'parse_query\',\'WM_Nova_Restaurant\', 10); 
  remove_action(\'parse_query\', \'WM_Nova_Restaurant>sort_menu_item_queries_by_menu_order\', 10); 
  remove_action(\'parse_query\',array("WM_Nova_Restaurant", "sort_menu_item_queries_by_menu_order"), 10); 
  remove_action(\'parse_query\', array("WM_Nova_Restaurant", "sort_menu_item_queries_by_menu_order"), 1);
  remove_action(\'parse_query\',array($WM_Nova_Restaurant, "sort_menu_item_queries_by_menu_order"), 10);
  do_hard_unregister_object_callback( \'parse_query\', 10, \'RBTM_my_func\');
 }
  add_action(\'parse_tax_query\', \'RBTM_my_func\', 10);
那么如何删除这个特定的类函数呢?WM_Nova_Restaurant->sort_menu_item_queries_by_menu_order link

我试图寻找答案,但什么也找不到。任何帮助都将不胜感激,谢谢!!!

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

[ Nova_Restaurant::init(), \'sort_menu_item_queries_by_menu_order\' ]
你想要类型的东西callable, 这与add_action.

只有少数几个有效的可调用项:

  • [ \'my_function_name\' ] 又称作my_function_name();
  • [ \'my_class_name\', \'my_static_function\' ] 又称作my_class_name::my_stati_function()
  • [ $object, \'the_objects_function\' ] 又称作$object->the_objects_function
  • [ function() {} ] 匿名函数或闭包,因此一些翻译:

    • remove_action(\'parse_query\',\'WM_Nova_Restaurant\', 10);<移除名为WM_Nova_Restaurantparse_query 挂钩remove_action(\'parse_query\', \'WM_Nova_Restaurant>sort_menu_item_queries_by_menu_order\', 10);<移除名为WM_Nova_Restaurant>sort_menu_item_queries_by_menu_orderparse_query 钩注意:这样的函数名是不可能的
  • remove_action(\'parse_query\',array("WM_Nova_Restaurant", "sort_menu_item_queries_by_menu_order"), 10);<移除静态方法sort_menu_item_queries_by_menu_orderWM_Nova_Restaurant 从挂钩上分类remove_action(\'parse_query\', array("WM_Nova_Restaurant", "sort_menu_item_queries_by_menu_order"), 1);<移除静态方法sort_menu_item_queries_by_menu_orderWM_Nova_Restaurant 从挂钩中初始化,优先级为1remove_action(\'parse_query\',array($WM_Nova_Restaurant, "sort_menu_item_queries_by_menu_order"), 10);<移除该方法sort_menu_item_queries_by_menu_order 在对象中$WM_Nova_Restaurant 从钩子上。请注意,此对象为空,因此也是无效的

    搜索它添加的位置阅读WP和PHP文档,而不是猜测和翻来覆去查看它添加在对象内部,并通过查看它是如何创建的来找出如何抓住该对象查看通过调用Nova_Restaurant::init()

结束