Differentiate between edit and new via an action field for the screen. Fix favorite_actions(). fixes #13876

git-svn-id: http://svn.automattic.com/wordpress/trunk@15253 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-06-14 19:33:04 +00:00
parent 0575b7eba9
commit c735965594
1 changed files with 17 additions and 15 deletions

View File

@ -3316,22 +3316,17 @@ function the_post_password() {
* @since unknown * @since unknown
*/ */
function favorite_actions( $screen = null ) { function favorite_actions( $screen = null ) {
global $post_type_object;
$default_action = false; $default_action = false;
if ( is_string($screen) ) if ( is_string($screen) )
$screen = convert_to_screen($screen); $screen = convert_to_screen($screen);
if ( isset($post_type_object) ) { if ( isset($screen->post_type) ) {
switch ( $screen->id ) { $post_type_object = get_post_type_object($screen->post_type);
case $post_type_object->name: if ( 'add' != $screen->action )
$default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->cap->edit_posts)); $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
break; else
case "edit-{$post_type_object->name}": $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
$default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
break;
}
} }
if ( !$default_action ) { if ( !$default_action ) {
@ -3343,10 +3338,11 @@ function favorite_actions( $screen = null ) {
$default_action = array('upload.php' => array(__('Edit Media'), 'upload_files')); $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
break; break;
case 'link-manager': case 'link-manager':
$default_action = array('link-add.php' => array(__('New Link'), 'manage_links')); case 'link':
break; if ( 'add' != $screen->action )
case 'link-add': $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
$default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links')); else
$default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
break; break;
case 'users': case 'users':
$default_action = array('user-new.php' => array(__('New User'), 'create_users')); $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
@ -3902,9 +3898,13 @@ function compression_test() {
function set_current_screen( $id = '' ) { function set_current_screen( $id = '' ) {
global $current_screen, $hook_suffix, $typenow, $taxnow; global $current_screen, $hook_suffix, $typenow, $taxnow;
$action = '';
if ( empty($id) ) { if ( empty($id) ) {
$current_screen = $hook_suffix; $current_screen = $hook_suffix;
$current_screen = str_replace('.php', '', $current_screen); $current_screen = str_replace('.php', '', $current_screen);
if ( preg_match('/-add|-new$/', $current_screen) )
$action = 'add';
$current_screen = str_replace('-new', '', $current_screen); $current_screen = str_replace('-new', '', $current_screen);
$current_screen = str_replace('-add', '', $current_screen); $current_screen = str_replace('-add', '', $current_screen);
$current_screen = array('id' => $current_screen, 'base' => $current_screen); $current_screen = array('id' => $current_screen, 'base' => $current_screen);
@ -3923,6 +3923,8 @@ function set_current_screen( $id = '' ) {
$current_screen = (object) $current_screen; $current_screen = (object) $current_screen;
$current_screen->action = $action;
// Map index to dashboard // Map index to dashboard
if ( 'index' == $current_screen->base ) if ( 'index' == $current_screen->base )
$current_screen->base = 'dashboard'; $current_screen->base = 'dashboard';