Make WordPress Core

Changeset 33173


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.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-ms-sites-list-table.php

    r33097 r33173  
    502502                        if ( get_current_site()->blog_id != $blog['blog_id'] ) {
    503503                                if ( $blog['deleted'] == '1' ) {
    504                                         $actions['activate']   = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>';
     504                                        $actions['activate']   = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a></span>';
    505505                                } else {
    506                                         $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Deactivate' ) . '</a></span>';
     506                                        $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a></span>';
    507507                                }
    508508
    509509                                if ( $blog['archived'] == '1' ) {
    510                                         $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Unarchive' ) . '</a></span>';
     510                                        $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a></span>';
    511511                                } else {
    512                                         $actions['archive']   = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ), 'confirm' ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
     512                                        $actions['archive']   = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
    513513                                }
    514514
    515515                                if ( $blog['spam'] == '1' ) {
    516                                         $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ), 'confirm' ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
     516                                        $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
    517517                                } else {
    518                                         $actions['spam']   = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ), 'confirm' ) ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
     518                                        $actions['spam']   = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
    519519                                }
    520520
    521521                                if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
    522                                         $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Delete' ) . '</a></span>';
     522                                        $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] ), 'deleteblog_' . $blog['blog_id'] ) ) . '">' . __( 'Delete' ) . '</a></span>';
    523523                                }
    524524                        }
  • 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.