WordPress.org

Make WordPress Core

Ticket #13909: 13909.2.2.patch

File 13909.2.2.patch, 4.8 KB (added by hakre, 8 years ago)

full flavored implementation (corrected; 5)

  • wp-includes/default-filters.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress
     
    253253add_action( 'admin_init', 'register_admin_color_schemes', 1);
    254254add_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
    255255
     256// HTTP Redirect Hypertext
     257add_action( 'redirect_hypertext', 'wp_redirect_hypertext', 10, 3 );
     258
    256259?>
  • wp-includes/pluggable.php

     
    869869 *
    870870 * @param string $location The path to redirect to
    871871 * @param int $status Status code to use
     872 * @param bool $hyptertext Should a Hypertext Fragment be used?
    872873 * @return bool False if $location is not set
    873874 */
    874 function wp_redirect($location, $status = 302) {
     875function wp_redirect( $location, $status = 302, $hypertext = true ) {
    875876        global $is_IIS;
    876877
    877         $location = apply_filters('wp_redirect', $location, $status);
    878         $status = apply_filters('wp_redirect_status', $status, $location);
     878        $location  = apply_filters( 'wp_redirect', $location, $status );
     879        $status    = (int) apply_filters( 'wp_redirect_status', $status, $location );
     880        $hypertext = apply_filters( 'wp_redirect_hypertext', $hypertext, $status, $location);
    879881
    880882        if ( !$location ) // allows the wp_redirect filter to cancel a redirect
    881883                return false;
     884               
     885        if ( 3 != (int) ($status/100) ) // Handle HTTP redirect status 3xx only
     886                return false;
    882887
    883         $location = wp_sanitize_redirect($location);
     888        $location = wp_sanitize_redirect( $location );
    884889
    885890        if ( $is_IIS ) {
    886                 header("Refresh: 0;url=$location");
     891                header( "Refresh: 0;url=$location" );
    887892        } else {
    888893                if ( php_sapi_name() != 'cgi-fcgi' )
    889                         status_header($status); // This causes problems on IIS and some FastCGI setups
    890                 header("Location: $location", true, $status);
     894                        status_header( $status ); // This causes problems on IIS and some FastCGI setups
     895                header( "Location: $location", true, $status );
    891896        }
     897
     898        // output a hypertext fragment? - sometimes wordpress needs to ignore the
     899        // HTTP 1.1 suggestion to output a hypertext fragment on redirects, e.g. with
     900        // plugin activation checks.
     901        if ( !$hypertext )
     902                return;
     903
     904        // hyptertext should be output for certain methods / stati only
     905        $method = $_SERVER['REQUEST_METHOD'];
     906        $html   = ('HEAD' !== $method) && (301 === $status || 302 === $status || 303 === $status || 307 === $status);
     907               
     908        if ( !$html )
     909                return;
     910               
     911        $hypertext = sprintf( '%s %s: <a href="%s">%s</a>', $status, esc_html( get_status_header_desc( $status ) ), esc_attr( $location ), esc_html( $location ) );
     912        $hypertext = apply_filters( 'redirect_hypertext', $hypertext, $location, $status );
     913       
     914        echo $hypertext;
    892915}
    893916endif;
    894917
     918if ( !function_exists('wp_redirect_hypertext') ) :
     919/**
     920 * Generate a Hypertext Fragment for a HTTP Redirect
     921 *
     922 * @since 3.1
     923 *
     924 * @param
     925 * @return hypertext fragment
     926 */
     927function wp_redirect_hypertext($hypertext, $location, $status) {       
     928        $version = $GLOBALS['wp_version'];
     929        list($link, $title, $description, $charset) = array_map('get_bloginfo', array('wpurl', 'name', 'description', 'charset'));
     930       
     931        $homepage = sprintf('<a href="%s">%s - %s</a>', esc_attr( $link ), esc_html( $title ), esc_html( $description ) );
     932       
     933        ob_start();
     934?>
     935<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=<?php echo $charset; ?>">
     936<TITLE><?php echo $status; ?> Moved</TITLE></HEAD><BODY>
     937<H1><?php echo $status; ?> <?php echo get_status_header_desc( $status ); ?></H1>
     938The document has moved
     939<A HREF="<?php echo esc_attr( $location ); ?>">here</A>.
     940<HR>
     941<address>WordPress/<?php echo esc_html( $version ); ?> at <?php echo $homepage; ?>.</address>
     942</BODY></HTML>
     943<?php
     944        return ob_get_clean();
     945}
     946endif;
     947
    895948if ( !function_exists('wp_sanitize_redirect') ) :
    896949/**
    897950 * Sanitizes a URL for use in a redirect.
  • wp-admin/includes/plugin.php

     
    479479
    480480        if ( !in_array($plugin, $current) ) {
    481481                if ( !empty($redirect) )
    482                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
     482                        wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect), 302, false); // we'll override this later if the plugin can be included without fatal error
    483483                ob_start();
    484484                include(WP_PLUGIN_DIR . '/' . $plugin);
    485485                do_action( 'activate_plugin', trim( $plugin) );