WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/11/2015 09:07:45 PM (5 years ago)
Author:
wonderboymusic
Message:

Introduce wp_validate_action( $action = '' ), a helper function that checks $_REQUEST for action and returns it, or empty string if not present. If $action is passed, it checks to make sure they match before returning it, or an empty string. Strings are always returned to avoid returning multiple types.

Implementing this removes 27 uses of direct superglobal access in the admin.

For more reading:
https://codeclimate.com/github/WordPress/WordPress/wp-admin/edit-comments.php

See #33837.

File:
1 edited

Legend:

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

    r32642 r34059  
    359359}
    360360
    361 if ( ! empty( $_REQUEST['action'] ) ) {
     361$_action = wp_validate_action();
     362if ( ! empty( $_action ) ) {
    362363    /**
    363364     * Fires when an 'action' request variable is sent.
    364365     *
    365      * The dynamic portion of the hook name, `$_REQUEST['action']`,
     366     * The dynamic portion of the hook name, `$_action`,
    366367     * refers to the action derived from the `GET` or `POST` request.
    367368     *
    368369     * @since 2.6.0
    369370     */
    370     do_action( 'admin_action_' . $_REQUEST['action'] );
    371 }
     371    do_action( 'admin_action_' . $_action );
     372}
     373unset( $_action );
Note: See TracChangeset for help on using the changeset viewer.