Make WordPress Core


Ignore:
Timestamp:
07/12/2015 02:35:11 AM (11 years ago)
Author:
jeremyfelt
Message:

Add better handling for actions and messaging in MS Sites List Table row actions

  • Simplify URLs used for row actions to remove messaging and site domain/path.
  • Use confirmation messaging from a managed list of actions when handling the request.
  • Find the site address from the site ID rather than using information passed in the URL.

Fixes #32963.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/sites.php

    r33067 r33173  
    5353        do_action( 'wpmuadminedit' );
    5454
     55        // A list of valid actions and their associated messaging for confirmation output.
     56        $manage_actions = array(
     57                'activateblog'   => __( 'You are about to activate the site %s' ),
     58                'deactivateblog' => __( 'You are about to deactivate the site %s' ),
     59                'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
     60                'archiveblog'    => __( 'You are about to archive the site %s.' ),
     61                'unspamblog'     => __( 'You are about to unspam the site %s.' ),
     62                'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
     63                'deleteblog'     => __( 'You are about to delete the site %s.' ),
     64                'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
     65                'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
     66                'allblogs'       => '',
     67        );
     68
    5569        if ( 'confirm' === $_GET['action'] ) {
    56                 check_admin_referer( 'confirm' );
     70                // The action2 parameter contains the action being taken on the site.
     71                $site_action = $_GET['action2'];
     72
     73                if ( ! array_key_exists( $site_action, $manage_actions ) ) {
     74                        wp_die( __( 'The requested action is not valid.' ) );
     75                }
     76
     77                // The mature/unmature UI exists only as external code. Check the "confirm" nonce for backward compatibility.
     78                if ( 'matureblog' === $site_action || 'unmatureblog' === $site_action ) {
     79                        check_admin_referer( 'confirm' );
     80                } else {
     81                        check_admin_referer( $site_action . '_' . $id );
     82                }
    5783
    5884                if ( ! headers_sent() ) {
     
    6490                        wp_die( __( 'You are not allowed to change the current site.' ) );
    6591                }
     92
     93                $site_details = get_blog_details( $id );
     94                $site_address = untrailingslashit( $site_details->domain . $site_details->path );
    6695
    6796                require_once( ABSPATH . 'wp-admin/admin-header.php' );
     
    6998                        <div class="wrap">
    7099                                <h1><?php _e( 'Confirm your action' ); ?></h1>
    71                                 <form action="sites.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
    72                                         <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
     100                                <form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
     101                                        <input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
    73102                                        <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
    74103                                        <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
    75                                         <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
    76                                         <p><?php echo esc_html( wp_unslash( $_GET['msg'] ) ); ?></p>
     104                                        <?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
     105                                        <p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
    77106                                        <?php submit_button( __( 'Confirm' ), 'button' ); ?>
    78107                                </form>
     
    85114        $updated_action = '';
    86115
    87         $manage_actions = array( 'deleteblog', 'allblogs', 'archiveblog', 'unarchiveblog', 'activateblog', 'deactivateblog', 'unspamblog', 'spamblog', 'unmatureblog', 'matureblog' );
    88         if ( in_array( $_GET['action'], $manage_actions ) ) {
     116        if ( array_key_exists( $_GET['action'], $manage_actions ) ) {
    89117                $action = $_GET['action'];
    90                 if ( 'allblogs' === $action )
     118                if ( 'allblogs' === $action ) {
    91119                        $action = 'bulk-sites';
    92 
    93                 check_admin_referer( $action );
     120                }
     121
     122                check_admin_referer( $action . '_' . $id );
    94123        }
    95124
     
    179208        }
    180209
    181         if ( empty( $updated_action ) && in_array( $_GET['action'], $manage_actions ) )
     210        if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
    182211                $updated_action = $_GET['action'];
     212        }
    183213
    184214        if ( ! empty( $updated_action ) ) {
Note: See TracChangeset for help on using the changeset viewer.