Make WordPress Core

Ticket #15327: 15327.7.diff

File 15327.7.diff, 2.8 KB (added by sivel, 12 years ago)

Use multidimensional associative array for $core_actions instead of 2 arrays

  • wp-admin/admin-ajax.php

     
    3434
    3535do_action( 'admin_init' );
    3636
    37 $core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'compression-test', 'imgedit-preview', 'oembed_cache' );
    38 
    39 $core_actions_post = array(
    40         'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
    41         'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
    42         'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
    43         'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'autosave', 'closed-postboxes',
    44         'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
    45         'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
    46         'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    47         'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    48         'wp-remove-post-lock', 'dismiss-wp-pointer',
     37$core_actions = array(
     38        'GET'  => array( 'fetch-list', 'ajax-tag-search', 'compression-test', 'imgedit-preview', 'oembed_cache' ),
     39        'POST' => array(
     40                'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
     41                'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
     42                'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
     43                'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'autosave', 'closed-postboxes',
     44                'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
     45                'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
     46                'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
     47                'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
     48                'wp-remove-post-lock', 'dismiss-wp-pointer',
     49        )
    4950);
    5051
    5152// Register core Ajax calls.
    52 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )
    53         add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
     53$method =  ! empty ( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( $_SERVER['REQUEST_METHOD'] ) : 'NONE';
     54if ( array_key_exists( $method, $core_actions ) && ! empty( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $core_actions[$method] ) )
     55        add_action( 'wp_ajax_' . $_REQUEST['action'], 'wp_ajax_' . str_replace( '-', '_', $_REQUEST['action'] ), 1 );
    5456
    55 if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) )
    56         add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
    57 
    5857add_action( 'wp_ajax_nopriv_autosave', 'wp_ajax_nopriv_autosave', 1 );
    5958
    6059if ( is_user_logged_in() )