简体   繁体   English

WordPress的-插件。 使用remove_action作为收藏夹动作

[英]Wordpress - Plugin. using remove_action for favorite_actions

Learning php, figure as well as following tutorials doing some practical useful stuff is import. 学习php,图形以及后面的教程做一些实用的东西是很重要的。 So a wordpress plugin.... 所以一个WordPress插件...。

Trying to remove the favorite actions box that you get in the wordpress admin header. 尝试删除您在wordpress admin标头中获得的“收藏夹操作”框。

<?php
/*
Plugin Name: Hide Favorite Actions
Plugin URI: http://www.mysite.com
Description: Allows you to remove the Screen Options and Help tabs from view
Author: Tai Havard
Version: 1.0
Author URI: 
*/

add_action('admin_menu','removeHelpAndScreenOptions');

function removeHelpAndScreenOptions()
{
remove_action('favorite_actions');  
}

?>

Plugins activated, function runs, I'm just not sure how to get hold of the favorite_actions correctly and wether remove_action is the correct function for use with the favorite_actions hook. 插件已激活,函数可以运行,我只是不确定如何正确地掌握favourite_actions,而remove_action是与favourite_actions挂钩配合使用的正确函数。

Thanks 谢谢

Here's how remove action works: 移除动作的运作方式如下:

remove_action( 'hook_name', 'function_name' );

That says you want to remove the function function_name from the hook hook_name . 也就是说,您要从钩子hook_name删除功能function_name I don't know what the hook and function are fore removing help and screen options, though. 我不知道挂钩和功能在删除帮助和屏幕选项之前是什么。 If I remember correctly, those tabs are hardcoded into the actual admin pages. 如果我没记错的话,这些标签会硬编码到实际的管理页面中。

I used that code and got an error in a template.php (presumably expecting an array) The box disappears if you return with an empty element, something like this: 我使用了该代码,并在template.php中出错(大概是数组)。如果返回的元素为空,则该框消失,如下所示:

add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
    $actions = array(
        '' => array(__(''), '')
    );
    return $actions;
} 

I just deleted the strings, somebody could probably write a more elegant empty array. 我只是删除了字符串,所以有人可能会编写一个更优雅的空数组。

In your plugin just add 在您的插件中添加

function rb_ax() {
return;
}
add_filter( 'favorite_actions', 'rb_ax' );

And you're done. 而且你已经完成了。

this works for me, wp 3.0.5 这对我有效,wp 3.0.5

/**
 * Remove "Favorite actions" from Admin
 */
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
    return array();
} 

I put it in functions.php, but it would probably work fine as a plugin. 我将其放在functions.php中,但作为插件可能会正常工作。

returning nothing (void?) works, but writes Warning: Invalid argument supplied for foreach()... 不返回任何内容(无效?),但写Warning: Invalid argument supplied for foreach()...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM