Make WordPress Core

Changeset 7527


Ignore:
Timestamp:
03/26/2008 06:55:24 PM (17 years ago)
Author:
ryan
Message:

Redirect consistency when saving pages and posts.

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r7485 r7527  
    66$messages[2] = __('Custom field updated.');
    77$messages[3] = __('Custom field deleted.');
     8$messages[4] = __('Post updated.');
    89?>
    910<?php if (isset($_GET['message'])) : ?>
  • trunk/wp-admin/edit-page-form.php

    r7490 r7527  
    33    $_GET['message'] = absint( $_GET['message'] );
    44$messages[1] = sprintf( __( 'Page updated. Continue editing below or <a href="%s">go back</a>.' ), attribute_escape( stripslashes( $_GET['_wp_original_http_referer'] ) ) );
     5$messages[2] = __('Custom field updated.');
     6$messages[3] = __('Custom field deleted.');
     7$messages[4] = __('Page updated.');
    58?>
    69<?php if (isset($_GET['message'])) : ?>
  • trunk/wp-admin/page.php

    r7438 r7527  
    66
    77wp_reset_vars(array('action'));
     8
     9function redirect_page($page_ID) {
     10    $referredby = '';
     11    if ( !empty($_POST['referredby']) )
     12        $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
     13    $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
     14
     15    if ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
     16        $location = $_POST['referredby'];
     17    } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
     18        $location = 'sidebar.php?a=b';
     19    } elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
     20        if ( $_POST['_wp_original_http_referer'] && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false )
     21            $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "page.php?action=edit&post=$page_ID&message=1" );
     22        else
     23            $location = "page.php?action=edit&post=$page_ID";
     24    } elseif ($_POST['addmeta']) {
     25        $location = add_query_arg( 'message', 2, wp_get_referer() );
     26        $location = explode('#', $location);
     27        $location = $location[0] . '#postcustom';
     28    } elseif ($_POST['deletemeta']) {
     29        $location = add_query_arg( 'message', 3, wp_get_referer() );
     30        $location = explode('#', $location);
     31        $location = $location[0] . '#postcustom';
     32    } elseif (!empty($referredby) && $referredby != $referer) {
     33        $location = $_POST['referredby'];
     34        if ( $_POST['referredby'] == 'redo' )
     35            $location = get_permalink( $page_ID );
     36        elseif ( false !== strpos($location, 'edit-pages.php') )
     37            $location = add_query_arg('posted', $page_ID, $location);
     38        elseif ( false !== strpos($location, 'wp-admin') )
     39            $location = "page-new.php?posted=$page_ID";
     40    } elseif ( isset($_POST['publish']) ) {
     41        $location = "page-new.php?posted=$page_ID";
     42    } elseif ($action == 'editattachment') {
     43        $location = 'attachments.php';
     44    } else {
     45        $location = "page.php?action=edit&post=$page_ID&message=4";
     46    }
     47
     48    wp_redirect($location);
     49}
    850
    951if (isset($_POST['deletepost'])) {
     
    1658    $page_ID = write_post();
    1759
    18     // Redirect.
    19     if (!empty($_POST['mode'])) {
    20     switch($_POST['mode']) {
    21         case 'bookmarklet':
    22             $location = $_POST['referredby'];
    23             break;
    24         case 'sidebar':
    25             $location = 'sidebar.php?a=b';
    26             break;
    27         default:
    28             $location = 'page-new.php';
    29             break;
    30         }
    31     } else {
    32         $location = "page-new.php?posted=$page_ID";
    33     }
     60    redirect_page($page_ID);
    3461
    35     if ( isset($_POST['save']) )
    36         $location = "page.php?action=edit&post=$page_ID";
    37 
    38     wp_redirect($location);
    3962    exit();
    4063    break;
     
    96119
    97120    $page_ID = edit_post();
    98     $page = get_post($page_ID);
    99121
    100     if ( 'post' == $_POST['originalaction'] ) {
    101         if (!empty($_POST['mode'])) {
    102         switch($_POST['mode']) {
    103             case 'bookmarklet':
    104                 $location = $_POST['referredby'];
    105                 break;
    106             case 'sidebar':
    107                 $location = 'sidebar.php?a=b';
    108                 break;
    109             default:
    110                 $location = 'page-new.php';
    111                 break;
    112             }
    113         } else {
    114             $location = "page-new.php?posted=$page_ID";
    115         }
    116 
    117         if ( isset($_POST['save']) )
    118             $location = "page.php?action=edit&post=$page_ID";
    119     } else {
    120         $referredby = '';
    121         if ( !empty($_POST['referredby']) )
    122             $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
    123         $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
    124 
    125         if ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
    126             if ( $_POST['_wp_original_http_referer'] && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false )
    127                 $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "page.php?action=edit&post=$page_ID&message=1" );
    128             else
    129                 $location = "page.php?action=edit&post=$page_ID";
    130         } elseif ($_POST['addmeta']) {
    131             $location = add_query_arg( 'message', 2, wp_get_referer() );
    132             $location = explode('#', $location);
    133             $location = $location[0] . '#postcustom';
    134         } elseif ($_POST['deletemeta']) {
    135             $location = add_query_arg( 'message', 3, wp_get_referer() );
    136             $location = explode('#', $location);
    137             $location = $location[0] . '#postcustom';
    138         } elseif (!empty($referredby) && $referredby != $referer) {
    139             $location = $_POST['referredby'];
    140             if ( $_POST['referredby'] == 'redo' )
    141                 $location = get_permalink( $page_ID );
    142             if ( false !== strpos($location, 'edit-pages.php') )
    143                 $location = add_query_arg('posted', $page_ID, $location);
    144         } elseif ( isset($_POST['publish']) ) {
    145             $location = "page-new.php?posted=$page_ID";
    146         } elseif ($action == 'editattachment') {
    147             $location = 'attachments.php';
    148         } else {
    149             $location = 'page-new.php';
    150         }
    151     }
    152     wp_redirect($location); // Send user on their way while we keep working
     122    redirect_page($page_ID);
    153123
    154124    exit();
  • trunk/wp-admin/post.php

    r7438 r7527  
    66
    77wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
     8
     9function redirect_post($post_ID = '') {
     10    global $action;
     11
     12    $referredby = '';
     13    if ( !empty($_POST['referredby']) )
     14        $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
     15    $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
     16
     17    if ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
     18        $location = $_POST['referredby'];
     19    } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
     20        $location = 'sidebar.php?a=b';
     21    } elseif ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
     22        if ( $_POST['_wp_original_http_referer'] && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false )
     23            $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
     24        else
     25            $location = "post.php?action=edit&post=$post_ID&message=4";
     26    } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
     27        $location = add_query_arg( 'message', 2, wp_get_referer() );
     28        $location = explode('#', $location);
     29        $location = $location[0] . '#postcustom';
     30    } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
     31        $location = add_query_arg( 'message', 3, wp_get_referer() );
     32        $location = explode('#', $location);
     33        $location = $location[0] . '#postcustom';
     34    } elseif (!empty($referredby) && $referredby != $referer) {
     35        $location = $_POST['referredby'];
     36        if ( $_POST['referredby'] == 'redo' )
     37            $location = get_permalink( $post_ID );
     38        elseif ( false !== strpos($location, 'edit.php') )
     39            $location = add_query_arg('posted', $post_ID, $location);       
     40        elseif ( false !== strpos($location, 'wp-admin') )
     41            $location = "post-new.php?posted=$post_ID";
     42    } elseif ( isset($_POST['publish']) ) {
     43        $location = "post-new.php?posted=$post_ID";
     44    } elseif ($action == 'editattachment') {
     45        $location = 'attachments.php';
     46    } else {
     47        $location = "post.php?action=edit&post=$post_ID&message=4";
     48    }
     49
     50    wp_redirect( $location );
     51}
    852
    953if ( isset( $_POST['deletepost'] ) )
     
    1761    $post_ID = 'post' == $action ? write_post() : edit_post();
    1862
    19     // Redirect.
    20     if ( !empty( $_POST['mode'] ) ) {
    21     switch($_POST['mode']) {
    22         case 'bookmarklet':
    23             $location = $_POST['referredby'];
    24             break;
    25         case 'sidebar':
    26             $location = 'sidebar.php?a=b';
    27             break;
    28         default:
    29             $location = 'post-new.php';
    30             break;
    31         }
    32     } else {
    33         $location = "post-new.php?posted=$post_ID";
    34     }
    35 
    36     if ( isset( $_POST['save'] ) )
    37         $location = "post.php?action=edit&post=$post_ID";
    38 
    39     if ( empty( $post_ID ) )
    40         $location = 'post-new.php';
    41 
    42     wp_redirect( $location );
     63    redirect_post($post_ID);
    4364    exit();
    4465    break;
     
    109130
    110131    $post_ID = edit_post();
    111     $post = get_post($post_ID);
    112132
    113     if ( 'post' == $_POST['originalaction'] ) {
    114         if (!empty($_POST['mode'])) {
    115         switch($_POST['mode']) {
    116             case 'bookmarklet':
    117                 $location = $_POST['referredby'];
    118                 break;
    119             case 'sidebar':
    120                 $location = 'sidebar.php?a=b';
    121                 break;
    122             default:
    123                 $location = 'post-new.php';
    124                 break;
    125             }
    126         } else {
    127             $location = "post-new.php?posted=$post_ID";
    128         }
    129 
    130         if ( isset($_POST['save']) )
    131             $location = "post.php?action=edit&post=$post_ID";
    132     } else {
    133         $referredby = '';
    134         if ( !empty($_POST['referredby']) )
    135             $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
    136         $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
    137 
    138         if ( isset($_POST['save']) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
    139             if ( $_POST['_wp_original_http_referer'] && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false )
    140                 $location = add_query_arg( '_wp_original_http_referer', urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), "post.php?action=edit&post=$post_ID&message=1" );
    141             else
    142                 $location = "post.php?action=edit&post=$post_ID";
    143         } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
    144             $location = add_query_arg( 'message', 2, wp_get_referer() );
    145             $location = explode('#', $location);
    146             $location = $location[0] . '#postcustom';
    147         } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
    148             $location = add_query_arg( 'message', 3, wp_get_referer() );
    149             $location = explode('#', $location);
    150             $location = $location[0] . '#postcustom';
    151         } elseif (!empty($referredby) && $referredby != $referer) {
    152             $location = $_POST['referredby'];
    153             if ( $_POST['referredby'] == 'redo' )
    154                 $location = get_permalink( $post_ID );
    155             if (false !== strpos($location, 'edit.php') )
    156                 $location = add_query_arg('posted', $post_ID, $location);
    157         } elseif ( isset($_POST['publish']) ) {
    158             $location = "post-new.php?posted=$post_ID";
    159         } elseif ($action == 'editattachment') {
    160             $location = 'attachments.php';
    161         } else {
    162             $location = "post.php?action=edit&post=$post_ID";
    163         }
    164     }
    165 
    166     wp_redirect($location); // Send user on their way while we keep working
     133    redirect_post($post_ID); // Send user on their way while we keep working
    167134
    168135    exit();
Note: See TracChangeset for help on using the changeset viewer.