Make WordPress Core

Ticket #37041: 37041.diff

File 37041.diff, 2.8 KB (added by rmccue, 9 years ago)
  • src/wp-admin/plugins.php

     
    3939
    4040                        check_admin_referer('activate-plugin_' . $plugin);
    4141
    42                         $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() );
     42                        $redirect_to = self_admin_url( 'plugins.php' );
     43                        if ( isset( $_REQUEST['redirect_to'] ) ) {
     44                                $redirect_to = wp_validate_redirect( wp_unslash( $_REQUEST['redirect_to'] ), $redirect_to );
     45                        }
     46
     47                        $error_redirect = add_query_arg( array( 'error' => 'true', 'plugin' => urlencode( $plugin ) ), $redirect_to );
     48                        $result = activate_plugin( $plugin, $error_redirect, is_network_admin() );
     49
    4350                        if ( is_wp_error( $result ) ) {
    4451                                if ( 'unexpected_output' == $result->get_error_code() ) {
    45                                         $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
    46                                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
     52                                        $redirect_args = array(
     53                                                'error'         => 'true',
     54                                                'charsout'      => strlen( $result->get_error_data() ),
     55                                                'plugin'        => $plugin,
     56                                                'plugin_status' => $status,
     57                                                'paged'         => $page,
     58                                                's'             => $s,
     59                                                '_error_nonce'  => wp_create_nonce( 'plugin-activation-error_' . $plugin )
     60                                        );
     61                                        $redirect = add_query_arg( urlencode_deep( $redirect_args ), $redirect_to );
     62                                        wp_redirect( $redirect );
    4763                                        exit;
    4864                                } else {
    4965                                        wp_die($result);
     
    6076                                update_site_option( 'recently_activated', $recent );
    6177                        }
    6278
    63                         if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
    64                                 wp_redirect( self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin))) ); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix
    65                         } else {
    66                                 wp_redirect( self_admin_url("plugins.php?activate=true&plugin_status=$status&paged=$page&s=$s") ); // overrides the ?error=true one above
     79                        $redirect_args = array(
     80                                'activate'      => 'true',
     81                                'plugin_status' => $status,
     82                                'paged'         => $page,
     83                                's'             => $s,
     84                        );
     85                        $redirect = add_query_arg( urlencode_deep( $redirect_args ), $redirect_to );
     86
     87                        if ( isset( $_GET['from'] ) && 'import' == $_GET['from'] ) {
     88                                // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix
     89                                $redirect = self_admin_url( "import.php?import=" . str_replace( '-importer', '', dirname( $plugin ) ) );
    6790                        }
     91
     92                        // This overrides the ?error=true redirect above
     93                        wp_safe_redirect( $redirect );
    6894                        exit;
    6995
    7096                case 'activate-selected':