gwycon.com
Silverlight, WPF and C# .NET development
User NamePassword

19
Mar

I noticed from the documentation that you are supposed to be able to hook into the new WordPress 2.7 admin short cuts menu (but it doesn’t say how)!

Ok, so after a little digging around in the WordPress core, the admin-header.php file (in the wp-admin folder) contains the code for the admin header.

In the admin-header.php file there is a section of code:

%2$s'), 'profile.php', $user_identity) ?> |


that points to a

favorite_actions()

function.

Now, if we take a look at this function we see that we can add or remove existing items from the shortcuts menu as required by using the favorite_actions filter,

$actions = apply_filters('favorite_actions', $actions);

.

function favorite_actions() {
	$actions = array(
	'post-new.php' => array(__('New Post'), 'edit_posts'),
	'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
	'page-new.php' => array(__('New Page'), 'edit_pages'),
	'media-new.php' => array(__('Upload'), 'upload_files'),
	'edit-comments.php' => array(__('Comments'), 'moderate_comments')
	);

	$actions = apply_filters('favorite_actions', $actions);

	$allowed_actions = array();
	foreach ( $actions as $action => $data ) {
	if ( current_user_can($data[1]) )
         $allowed_actions[$action] = $data[0];
	}

	if ( empty($allowed_actions) )
	return;

	$first = array_keys($allowed_actions);
	$first = $first[0];
	echo '
'; echo '
'; echo '
'; array_shift($allowed_actions); foreach ( $allowed_actions as $action => $label) { echo " \n"; } echo "
\n"; }

Unfortunately there doesn’t seem to be any way to hook into the admin head using a WordPress hook as there is none defined there. See the above admin hear code. However, it is probably possible to do this without too much hard work if you were to use the admin header div id tag

and JavaScript, to hook into the required html position.

Then, you could add code from a Plugin to display new menus along side the existing short cuts menu. This is desirable over hacking the admin-header.php file directly to add your own menus! Although I must admit, as a quick solution it is tempting [evil grin].

Anyway, hopefully, in a future release of WordPress we will see a hook that allows developers a way of adding there own menus to the header bar, so a custom workaround would not be needed.

Category : WordPress Plugins

One Response to “Adding menus to WordPress 2.7 admin header”