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:

1
2
3
4
5
6
7
8
<div id="wphead-info">
 <div id="user_info">
  <p><?php printf(__('Howdy, <a href="%1$s" title="Edit your profile">%2$s</a>'), 'profile.php', $user_identity) ?>
  <?php if ( ! $is_opera ) { ?><span class="turbo-nag hidden"> | <a href="tools.php"><?php _e('Turbo') ?></a></span><?php } ?> |
  <a href="<?php echo wp_logout_url() ?>" title="<?php _e('Log Out') ?>"><?php _e('Log Out'); ?></a></p>
 </div>
 <?php favorite_actions(); ?>
</div>


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);

.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 '<div id="favorite-actions">';
	echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
	echo '<div id="favorite-inside">';
 
	array_shift($allowed_actions);
 
	foreach ( $allowed_actions as $action => $label) {
	echo "<div class='favorite-action'><a href='$action'>";
	echo $label;
	echo "</a></div>\n";
	}
	echo "</div></div>\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

<div id="wphead-info">

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.

VN:F [1.9.3_1094]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Adding menus to WordPress 2.7 admin header, 5.0 out of 5 based on 1 rating
Category : WordPress Plugins

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