WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/23/2012 07:12:04 PM (9 years ago)
Author:
nacin
Message:

Add 'ep_mask' as an argument to the 'rewrite' array for register_post_type() and register_taxonomy(). Keeps 'permalink_epmask' compatible as an argument for post type registrations. Fixes endpoints for category and tag pages. fixes #19275.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ajax-actions.php

    r19734 r19738  
    11<?php
    22/**
    3  * WordPress AJAX Process Execution.
     3 * WordPress Core Ajax Handlers.
    44 *
    55 * @package WordPress
     
    77 */
    88
    9 /**
    10  * Executing AJAX process.
    11  *
    12  * @since 2.1.0
     9/*
     10 * No-privilege Ajax handlers.
    1311 */
    14 define('DOING_AJAX', true);
    15 define('WP_ADMIN', true);
    16 
    17 if ( ! isset( $_REQUEST['action'] ) )
    18     die('-1');
    19 
    20 require_once('../wp-load.php');
    21 
    22 require_once('./includes/admin.php');
    23 @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
    24 send_nosniff_header();
    25 
    26 do_action('admin_init');
    27 
    28 if ( ! is_user_logged_in() ) {
    29 
    30     if ( isset( $_POST['action'] ) && $_POST['action'] == 'autosave' ) {
    31         $id = isset($_POST['post_ID'])? (int) $_POST['post_ID'] : 0;
    32 
    33         if ( ! $id )
    34             die('-1');
    35 
    36         $message = sprintf( __('<strong>ALERT: You are logged out!</strong> Could not save draft. <a href="%s" target="_blank">Please log in again.</a>'), wp_login_url() );
    37         $x = new WP_Ajax_Response( array(
    38             'what' => 'autosave',
    39             'id' => $id,
    40             'data' => $message
    41         ) );
    42         $x->send();
    43     }
    44 
    45     if ( !empty( $_REQUEST['action'] ) )
    46         do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
    47 
    48     die('-1');
    49 }
    50 
    51 if ( isset( $_GET['action'] ) ) :
    52 switch ( $action = $_GET['action'] ) :
    53 case 'fetch-list' :
     12
     13function wp_ajax_nopriv_autosave() {
     14    $id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
     15
     16    if ( ! $id )
     17        die('-1');
     18
     19    $message = sprintf( __('<strong>ALERT: You are logged out!</strong> Could not save draft. <a href="%s" target="_blank">Please log in again.</a>'), wp_login_url() );
     20    $x = new WP_Ajax_Response( array(
     21        'what' => 'autosave',
     22        'id' => $id,
     23        'data' => $message
     24    ) );
     25    $x->send();
     26}
     27
     28/*
     29 * GET-based Ajax handlers.
     30 */
     31function wp_ajax_fetch_list() {
     32    global $current_screen, $wp_list_table;
    5433
    5534    $list_class = $_GET['list_args']['class'];
     
    7150
    7251    die( '0' );
    73     break;
    74 case 'ajax-tag-search' :
     52}
     53function wp_ajax_ajax_tag_search() {
     54    global $wpdb;
     55
    7556    if ( isset( $_GET['tax'] ) ) {
    7657        $taxonomy = sanitize_key( $_GET['tax'] );
     
    9879    echo join( $results, "\n" );
    9980    die;
    100     break;
    101 case 'wp-compression-test' :
     81}
     82
     83function wp_ajax_wp_compression_test() {
    10284    if ( !current_user_can( 'manage_options' ) )
    10385        die('-1');
     
    142124
    143125    die('0');
    144     break;
    145 case 'imgedit-preview' :
     126}
     127
     128function wp_ajax_imgedit_preview() {
    146129    $post_id = intval($_GET['postid']);
    147130    if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
     
    155138
    156139    die();
    157     break;
    158 case 'menu-quick-search':
    159     if ( ! current_user_can( 'edit_theme_options' ) )
    160         die('-1');
    161 
    162     require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    163 
    164     _wp_ajax_menu_quick_search( $_REQUEST );
    165 
    166     exit;
    167     break;
    168 case 'oembed-cache' :
     140}
     141
     142function wp_ajax_oembed_cache() {
     143    global $wp_embed;
     144
    169145    $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
    170146    die( $return );
    171     break;
    172 default :
    173     do_action( 'wp_ajax_' . $_GET['action'] );
    174     die('0');
    175     break;
    176 endswitch;
    177 endif;
     147}
     148
     149/*
     150 * Ajax helper.
     151 */
    178152
    179153/**
     
    236210}
    237211
    238 function _wp_ajax_add_hierarchical_term() {
    239     $action = $_POST['action'];
     212/*
     213 * POST-based Ajax handlers.
     214 */
     215
     216function _wp_ajax_add_hierarchical_term( $action ) {
    240217    $taxonomy = get_taxonomy(substr($action, 4));
    241218    check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
     
    265242        if ( $parent ) // Do these all at once in a second
    266243            continue;
    267         $category = get_term( $cat_id, $taxonomy->name );
    268244        ob_start();
    269245            wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy->name, 'descendants_and_self' => $cat_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids ));
     
    314290}
    315291
    316 $id = isset($_POST['id'])? (int) $_POST['id'] : 0;
    317 switch ( $action = $_POST['action'] ) :
    318 case 'delete-comment' : // On success, die with time() instead of 1
     292function wp_ajax_delete_comment() {
     293    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     294
    319295    if ( !$comment = get_comment( $id ) )
    320296        die( (string) time() );
     
    355331        _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
    356332    die( '0' );
    357     break;
    358 case 'delete-tag' :
     333}
     334
     335function wp_ajax_delete_tag() {
    359336    $tag_id = (int) $_POST['tag_ID'];
    360337    check_ajax_referer( "delete-tag_$tag_id" );
     
    374351    else
    375352        die('0');
    376     break;
    377 case 'delete-link' :
     353}
     354
     355function wp_ajax_delete_link() {
     356    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     357
    378358    check_ajax_referer( "delete-bookmark_$id" );
    379359    if ( !current_user_can( 'manage_links' ) )
     
    388368    else
    389369        die('0');
    390     break;
    391 case 'delete-meta' :
     370}
     371
     372function wp_ajax_delete_meta() {
     373    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     374
    392375    check_ajax_referer( "delete-meta_$id" );
    393376    if ( !$meta = get_metadata_by_mid( 'post', $id ) )
     
    399382        die('1');
    400383    die('0');
    401     break;
    402 case 'delete-post' :
     384}
     385
     386function wp_ajax_delete_post( $action ) {
     387    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     388
    403389    check_ajax_referer( "{$action}_$id" );
    404390    if ( !current_user_can( 'delete_post', $id ) )
     
    412398    else
    413399        die('0');
    414     break;
    415 case 'trash-post' :
    416 case 'untrash-post' :
     400}
     401
     402function wp_ajax_trash_post( $action ) {
     403    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     404
    417405    check_ajax_referer( "{$action}_$id" );
    418406    if ( !current_user_can( 'delete_post', $id ) )
     
    431419
    432420    die('0');
    433     break;
    434 case 'delete-page' :
     421}
     422
     423function wp_ajax_untrash_post( $action ) {
     424    wp_ajax_trash_post( $action );
     425}
     426
     427function wp_ajax_delete_page( $action ) {
     428    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
     429
    435430    check_ajax_referer( "{$action}_$id" );
    436431    if ( !current_user_can( 'delete_page', $id ) )
     
    444439    else
    445440        die('0');
    446     break;
    447 case 'dim-comment' : // On success, die with time() instead of 1
     441}
     442
     443function wp_ajax_dim_comment() {
     444    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    448445
    449446    if ( !$comment = get_comment( $id ) ) {
     
    479476    _wp_ajax_delete_comment_response( $comment->comment_ID );
    480477    die( '0' );
    481     break;
    482 case 'add-link-category' : // On the Fly
     478}
     479
     480function wp_ajax_add_link_category( $action ) {
    483481    check_ajax_referer( $action );
    484482    if ( !current_user_can( 'manage_categories' ) )
     
    504502    }
    505503    $x->send();
    506     break;
    507 case 'add-tag' :
     504}
     505
     506function wp_ajax_add_tag() {
     507    global $wp_list_table;
     508
    508509    check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
    509510    $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post';
     
    556557        ) );
    557558    $x->send();
    558     break;
    559 case 'get-tagcloud' :
     559}
     560
     561function wp_ajax_get_tagcloud() {
    560562    if ( isset( $_POST['tax'] ) ) {
    561563        $taxonomy = sanitize_key( $_POST['tax'] );
     
    591593
    592594    exit;
    593     break;
    594 case 'get-comments' :
     595}
     596
     597function wp_ajax_get_comments( $action ) {
     598    global $wp_list_table, $post_id;
     599
    595600    check_ajax_referer( $action );
    596601
     
    623628    ) );
    624629    $x->send();
    625     break;
    626 case 'replyto-comment' :
     630}
     631
     632function wp_ajax_replyto_comment( $action ) {
     633    global $wp_list_table, $wpdb;
     634
    627635    check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
    628636
     
    707715    $x->add( $response );
    708716    $x->send();
    709     break;
    710 case 'edit-comment' :
     717}
     718
     719function wp_ajax_edit_comment() {
     720    global $wp_list_table;
     721
    711722    check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
    712723
     
    729740    $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table' );
    730741
     742    $comment = get_comment( $comment_id );
     743
    731744    ob_start();
    732         $wp_list_table->single_row( get_comment( $comment_id ) );
     745        $wp_list_table->single_row( $comment );
    733746        $comment_list_item = ob_get_contents();
    734747    ob_end_clean();
     
    744757
    745758    $x->send();
    746     break;
    747 case 'add-menu-item' :
     759}
     760
     761function wp_ajax_add_menu_item() {
    748762    if ( ! current_user_can( 'edit_theme_options' ) )
    749763        die('-1');
     
    787801        die('-1');
    788802
     803    $menu_items = array();
     804
    789805    foreach ( (array) $item_ids as $menu_item_id ) {
    790806        $menu_obj = get_post( $menu_item_id );
     
    806822        echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
    807823    }
    808     break;
    809 case 'add-meta' :
     824}
     825
     826function wp_ajax_add_meta() {
    810827    check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
    811828    $c = 0;
     
    888905    }
    889906    $x->send();
    890     break;
    891 case 'add-user' :
     907}
     908
     909function wp_ajax_add_user( $action ) {
     910    global $wp_list_table;
     911
    892912    check_ajax_referer( $action );
    893913    if ( ! current_user_can('create_users') )
     
    916936    ) );
    917937    $x->send();
    918     break;
    919 case 'autosave' : // The name of this action is hardcoded in edit_post()
     938}
     939
     940function wp_ajax_autosave() {
     941    global $login_grace_period;
     942
    920943    define( 'DOING_AUTOSAVE', true );
    921944
     
    10141037    ) );
    10151038    $x->send();
    1016     break;
    1017 case 'closed-postboxes' :
     1039}
     1040
     1041function wp_ajax_closed_postboxes() {
    10181042    check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
    10191043    $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed']) : array();
     
    10401064
    10411065    die('1');
    1042     break;
    1043 case 'hidden-columns' :
     1066}
     1067
     1068function wp_ajax_hidden_columns() {
    10441069    check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
    10451070    $hidden = isset( $_POST['hidden'] ) ? $_POST['hidden'] : '';
     
    10571082
    10581083    die('1');
    1059     break;
    1060 case 'update-welcome-panel' :
     1084}
     1085
     1086function wp_ajax_update_welcome_panel() {
    10611087    check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
    10621088
     
    10671093
    10681094    die('1');
    1069     break;
    1070 case 'menu-get-metabox' :
     1095}
     1096
     1097function wp_ajax_menu_get_metabox() {
    10711098    if ( ! current_user_can( 'edit_theme_options' ) )
    10721099        die('-1');
     
    11061133
    11071134    exit;
    1108     break;
    1109 case 'menu-quick-search':
    1110     if ( ! current_user_can( 'edit_theme_options' ) )
    1111         die('-1');
    1112 
    1113     require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    1114 
    1115     _wp_ajax_menu_quick_search( $_REQUEST );
    1116 
    1117     exit;
    1118     break;
    1119 case 'wp-link-ajax':
     1135}
     1136
     1137function wp_ajax_wp_link_ajax() {
    11201138    check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );
    11211139
     
    11361154
    11371155    exit;
    1138     break;
    1139 case 'menu-locations-save':
     1156}
     1157
     1158function wp_ajax_menu_locations_save() {
    11401159    if ( ! current_user_can( 'edit_theme_options' ) )
    11411160        die('-1');
     
    11451164    set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
    11461165    die('1');
    1147     break;
    1148 case 'meta-box-order':
     1166}
     1167
     1168function wp_ajax_meta_box_order() {
    11491169    check_ajax_referer( 'meta-box-order' );
    11501170    $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
     
    11691189
    11701190    die('1');
    1171     break;
    1172 case 'get-permalink':
     1191}
     1192
     1193function wp_ajax_menu_quick_search() {
     1194    if ( ! current_user_can( 'edit_theme_options' ) )
     1195        die('-1');
     1196
     1197    require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     1198
     1199    _wp_ajax_menu_quick_search( $_POST );
     1200
     1201    exit;
     1202}
     1203
     1204function wp_ajax_get_permalink() {
    11731205    check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
    11741206    $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    11751207    die(add_query_arg(array('preview' => 'true'), get_permalink($post_id)));
    1176 break;
    1177 case 'sample-permalink':
     1208}
     1209
     1210function wp_ajax_sample_permalink() {
    11781211    check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    11791212    $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
     
    11811214    $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null;
    11821215    die(get_sample_permalink_html($post_id, $title, $slug));
    1183 break;
    1184 case 'inline-save':
     1216}
     1217
     1218function wp_ajax_inline_save() {
     1219    global $wp_list_table;
     1220
    11851221    check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
    11861222
     
    12391275
    12401276    exit;
    1241     break;
    1242 case 'inline-save-tax':
     1277}
     1278
     1279function wp_ajax_inline_save_tax() {
     1280    global $wp_list_table;
     1281
    12431282    check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    12441283
     
    12781317
    12791318    exit;
    1280     break;
    1281 case 'find_posts':
     1319}
     1320
     1321function wp_ajax_find_posts() {
     1322    global $wpdb;
     1323
    12821324    check_ajax_referer( 'find-posts' );
    12831325
     
    13491391    $x->send();
    13501392
    1351     break;
    1352 case 'widgets-order' :
     1393}
     1394
     1395function wp_ajax_widgets_order() {
    13531396    check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    13541397
     
    13791422
    13801423    die('-1');
    1381     break;
    1382 case 'save-widget' :
     1424}
     1425
     1426function wp_ajax_save_widget() {
     1427    global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates;
     1428
    13831429    check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    13841430
     
    14471493
    14481494    die();
    1449     break;
    1450 case 'image-editor':
     1495}
     1496
     1497function wp_ajax_image_editor() {
    14511498    $attachment_id = intval($_POST['postid']);
    14521499    if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
     
    14731520    wp_image_editor($attachment_id, $msg);
    14741521    die();
    1475     break;
    1476 case 'set-post-thumbnail':
     1522}
     1523
     1524function wp_ajax_set_post_thumbnail() {
    14771525    $post_ID = intval( $_POST['post_id'] );
    14781526    if ( !current_user_can( 'edit_post', $post_ID ) )
     
    14921540        die( _wp_post_thumbnail_html( $thumbnail_id ) );
    14931541    die( '0' );
    1494     break;
    1495 case 'date_format' :
     1542}
     1543
     1544function wp_ajax_date_format() {
    14961545    die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
    1497     break;
    1498 case 'time_format' :
     1546}
     1547
     1548function wp_ajax_time_format() {
    14991549    die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
    1500     break;
    1501 case 'wp-fullscreen-save-post' :
     1550}
     1551
     1552function wp_ajax_wp_fullscreen_save_post() {
    15021553    $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
    15031554
     
    15451596    echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
    15461597    die();
    1547     break;
    1548 case 'wp-remove-post-lock' :
     1598}
     1599
     1600function wp_ajax_wp_remove_post_lock() {
    15491601    if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
    15501602        die( '0' );
     
    15651617    update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
    15661618    die( '1' );
    1567 case 'dismiss-wp-pointer' :
     1619}
     1620
     1621function wp_ajax_dismiss_wp_pointer() {
    15681622    $pointer = $_POST['pointer'];
    15691623    if ( $pointer != sanitize_key( $pointer ) )
     
    15821636    update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
    15831637    die( '1' );
    1584     break;
    1585 default :
    1586     do_action( 'wp_ajax_' . $_POST['action'] );
    1587     die('0');
    1588     break;
    1589 endswitch;
     1638}
Note: See TracChangeset for help on using the changeset viewer.