Make WordPress Core


Ignore:
Timestamp:
09/11/2015 09:07:45 PM (10 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/async-upload.php

    r33842 r34059  
    77 */
    88
     9// `wp_validate_action()` isn't loaded yet
    910if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
    1011    define( 'DOING_AJAX', true );
     
    2021    require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    2122
    22 if ( ! ( isset( $_REQUEST['action'] ) && 'upload-attachment' == $_REQUEST['action'] ) ) {
     23if ( ! wp_validate_action( 'upload-attachment' ) ) {
    2324    // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
    2425    if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
     
    3536header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
    3637
    37 if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
     38if ( wp_validate_action( 'upload-attachment' ) ) {
    3839    include( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    3940
Note: See TracChangeset for help on using the changeset viewer.