Make WordPress Core

Ticket #15327: ajax_die.2.patch

File ajax_die.2.patch, 28.6 KB (added by kurtpayne, 13 years ago)

Forgot check_ajax_referer

  • wordpress/wp-admin/includes/ajax-actions.php

     
    1414        $id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
    1515
    1616        if ( ! $id )
    17                 die('-1');
     17                wp_die('-1');
    1818
    1919        $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() );
    2020        $x = new WP_Ajax_Response( array(
     
    4141
    4242        $wp_list_table = _get_list_table( $list_class );
    4343        if ( ! $wp_list_table )
    44                 die( '0' );
     44                wp_die( '0' );
    4545
    4646        if ( ! $wp_list_table->ajax_user_can() )
    47                 die( '-1' );
     47                wp_die( '-1' );
    4848
    4949        $wp_list_table->ajax_response();
    5050
    51         die( '0' );
     51        wp_die( '0' );
    5252}
    5353function wp_ajax_ajax_tag_search() {
    5454        global $wpdb;
     
    5757                $taxonomy = sanitize_key( $_GET['tax'] );
    5858                $tax = get_taxonomy( $taxonomy );
    5959                if ( ! $tax )
    60                         die( '0' );
     60                        wp_die( '0' );
    6161                if ( ! current_user_can( $tax->cap->assign_terms ) )
    62                         die( '-1' );
     62                        wp_die( '-1' );
    6363        } else {
    64                 die('0');
     64                wp_die('0');
    6565        }
    6666
    6767        $s = stripslashes( $_GET['q'] );
     
    8282
    8383function wp_ajax_wp_compression_test() {
    8484        if ( !current_user_can( 'manage_options' ) )
    85                 die('-1');
     85                wp_die('-1');
    8686
    8787        if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) {
    8888                update_site_option('can_compress_scripts', 0);
    89                 die('0');
     89                wp_die('0');
    9090        }
    9191
    9292        if ( isset($_GET['test']) ) {
     
    103103                        die;
    104104                 } elseif ( 2 == $_GET['test'] ) {
    105105                        if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
    106                                 die('-1');
     106                                wp_die('-1');
    107107                        if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
    108108                                header('Content-Encoding: deflate');
    109109                                $out = gzdeflate( $test_str, 1 );
     
    111111                                header('Content-Encoding: gzip');
    112112                                $out = gzencode( $test_str, 1 );
    113113                        } else {
    114                                 die('-1');
     114                                wp_die('-1');
    115115                        }
    116116                        echo $out;
    117117                        die;
     
    122122                }
    123123        }
    124124
    125         die('0');
     125        wp_die('0');
    126126}
    127127
    128128function wp_ajax_imgedit_preview() {
    129129        $post_id = intval($_GET['postid']);
    130130        if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
    131                 die('-1');
     131                wp_die('-1');
    132132
    133133        check_ajax_referer( "image_editor-$post_id" );
    134134
    135135        include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
    136136        if ( ! stream_preview_image($post_id) )
    137                 die('-1');
     137                wp_die('-1');
    138138
    139         die();
     139        wp_die('');
    140140}
    141141
    142142function wp_ajax_oembed_cache() {
    143143        global $wp_embed;
    144144
    145145        $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
    146         die( $return );
     146        wp_die( $return );
    147147}
    148148
    149149/*
     
    167167        $url = esc_url_raw( @$_POST['_url'] );
    168168        // JS didn't send us everything we need to know. Just die with success message
    169169        if ( !$total || !$per_page || !$page || !$url )
    170                 die( (string) time() );
     170                wp_die( (string) time() );
    171171
    172172        $total += $delta;
    173173        if ( $total < 0 )
     
    217217        $taxonomy = get_taxonomy(substr($action, 4));
    218218        check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
    219219        if ( !current_user_can( $taxonomy->cap->edit_terms ) )
    220                 die('-1');
     220                wp_die('-1');
    221221        $names = explode(',', $_POST['new'.$taxonomy->name]);
    222222        $parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0;
    223223        if ( 0 > $parent )
     
    295295        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    296296
    297297        if ( !$comment = get_comment( $id ) )
    298                 die( (string) time() );
     298                wp_die( (string) time() );
    299299        if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )
    300                 die('-1');
     300                wp_die('-1');
    301301
    302302        check_ajax_referer( "delete-comment_$id" );
    303303        $status = wp_get_comment_status( $comment->comment_ID );
     
    305305        $delta = -1;
    306306        if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    307307                if ( 'trash' == $status )
    308                         die( (string) time() );
     308                        wp_die( (string) time() );
    309309                $r = wp_trash_comment( $comment->comment_ID );
    310310        } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
    311311                if ( 'trash' != $status )
    312                         die( (string) time() );
     312                        wp_die( (string) time() );
    313313                $r = wp_untrash_comment( $comment->comment_ID );
    314314                if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
    315315                        $delta = 1;
    316316        } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    317317                if ( 'spam' == $status )
    318                         die( (string) time() );
     318                        wp_die( (string) time() );
    319319                $r = wp_spam_comment( $comment->comment_ID );
    320320        } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
    321321                if ( 'spam' != $status )
    322                         die( (string) time() );
     322                        wp_die( (string) time() );
    323323                $r = wp_unspam_comment( $comment->comment_ID );
    324324                if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
    325325                        $delta = 1;
    326326        } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    327327                $r = wp_delete_comment( $comment->comment_ID );
    328328        } else {
    329                 die('-1');
     329                wp_die('-1');
    330330        }
    331331
    332332        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    333333                _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
    334         die( '0' );
     334        wp_die( '0' );
    335335}
    336336
    337337function wp_ajax_delete_tag() {
     
    342342        $tax = get_taxonomy($taxonomy);
    343343
    344344        if ( !current_user_can( $tax->cap->delete_terms ) )
    345                 die('-1');
     345                wp_die('-1');
    346346
    347347        $tag = get_term( $tag_id, $taxonomy );
    348348        if ( !$tag || is_wp_error( $tag ) )
    349                 die('1');
     349                wp_die('1');
    350350
    351351        if ( wp_delete_term($tag_id, $taxonomy))
    352                 die('1');
     352                wp_die('1');
    353353        else
    354                 die('0');
     354                wp_die('0');
    355355}
    356356
    357357function wp_ajax_delete_link() {
     
    359359
    360360        check_ajax_referer( "delete-bookmark_$id" );
    361361        if ( !current_user_can( 'manage_links' ) )
    362                 die('-1');
     362                wp_die('-1');
    363363
    364364        $link = get_bookmark( $id );
    365365        if ( !$link || is_wp_error( $link ) )
    366                 die('1');
     366                wp_die('1');
    367367
    368368        if ( wp_delete_link( $id ) )
    369                 die('1');
     369                wp_die('1');
    370370        else
    371                 die('0');
     371                wp_die('0');
    372372}
    373373
    374374function wp_ajax_delete_meta() {
     
    376376
    377377        check_ajax_referer( "delete-meta_$id" );
    378378        if ( !$meta = get_metadata_by_mid( 'post', $id ) )
    379                 die('1');
     379                wp_die('1');
    380380
    381381        if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta',  $meta->post_id, $meta->meta_key ) )
    382                 die('-1');
     382                wp_die('-1');
    383383        if ( delete_meta( $meta->meta_id ) )
    384                 die('1');
    385         die('0');
     384                wp_die('1');
     385        wp_die('0');
    386386}
    387387
    388388function wp_ajax_delete_post( $action ) {
     
    390390
    391391        check_ajax_referer( "{$action}_$id" );
    392392        if ( !current_user_can( 'delete_post', $id ) )
    393                 die('-1');
     393                wp_die('-1');
    394394
    395395        if ( !get_post( $id ) )
    396                 die('1');
     396                wp_die('1');
    397397
    398398        if ( wp_delete_post( $id ) )
    399                 die('1');
     399                wp_die('1');
    400400        else
    401                 die('0');
     401                wp_die('0');
    402402}
    403403
    404404function wp_ajax_trash_post( $action ) {
     
    406406
    407407        check_ajax_referer( "{$action}_$id" );
    408408        if ( !current_user_can( 'delete_post', $id ) )
    409                 die('-1');
     409                wp_die('-1');
    410410
    411411        if ( !get_post( $id ) )
    412                 die('1');
     412                wp_die('1');
    413413
    414414        if ( 'trash-post' == $action )
    415415                $done = wp_trash_post( $id );
     
    417417                $done = wp_untrash_post( $id );
    418418
    419419        if ( $done )
    420                 die('1');
     420                wp_die('1');
    421421
    422         die('0');
     422        wp_die('0');
    423423}
    424424
    425425function wp_ajax_untrash_post( $action ) {
     
    431431
    432432        check_ajax_referer( "{$action}_$id" );
    433433        if ( !current_user_can( 'delete_page', $id ) )
    434                 die('-1');
     434                wp_die('-1');
    435435
    436436        if ( !get_page( $id ) )
    437                 die('1');
     437                wp_die('1');
    438438
    439439        if ( wp_delete_post( $id ) )
    440                 die('1');
     440                wp_die('1');
    441441        else
    442                 die('0');
     442                wp_die('0');
    443443}
    444444
    445445function wp_ajax_dim_comment() {
     
    454454        }
    455455
    456456        if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) )
    457                 die('-1');
     457                wp_die('-1');
    458458
    459459        $current = wp_get_comment_status( $comment->comment_ID );
    460460        if ( $_POST['new'] == $current )
    461                 die( (string) time() );
     461                wp_die( (string) time() );
    462462
    463463        check_ajax_referer( "approve-comment_$id" );
    464464        if ( in_array( $current, array( 'unapproved', 'spam' ) ) )
     
    476476
    477477        // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    478478        _wp_ajax_delete_comment_response( $comment->comment_ID );
    479         die( '0' );
     479        wp_die( '0' );
    480480}
    481481
    482482function wp_ajax_add_link_category( $action ) {
    483483        check_ajax_referer( $action );
    484484        if ( !current_user_can( 'manage_categories' ) )
    485                 die('-1');
     485                wp_die('-1');
    486486        $names = explode(',', $_POST['newcat']);
    487487        $x = new WP_Ajax_Response();
    488488        foreach ( $names as $cat_name ) {
     
    516516        $tax = get_taxonomy($taxonomy);
    517517
    518518        if ( !current_user_can( $tax->cap->edit_terms ) )
    519                 die('-1');
     519                wp_die('-1');
    520520
    521521        $x = new WP_Ajax_Response();
    522522
     
    567567                $taxonomy = sanitize_key( $_POST['tax'] );
    568568                $tax = get_taxonomy( $taxonomy );
    569569                if ( ! $tax )
    570                         die( '0' );
     570                        wp_die( '0' );
    571571                if ( ! current_user_can( $tax->cap->assign_terms ) )
    572                         die( '-1' );
     572                        wp_die( '-1' );
    573573        } else {
    574                 die('0');
     574                wp_die('0');
    575575        }
    576576
    577577        $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
    578578
    579579        if ( empty( $tags ) )
    580                 die( isset( $tax->no_tagcloud ) ? $tax->no_tagcloud : __('No tags found!') );
     580                wp_die( isset( $tax->no_tagcloud ) ? $tax->no_tagcloud : __('No tags found!') );
    581581
    582582        if ( is_wp_error( $tags ) )
    583                 die( $tags->get_error_message() );
     583                wp_die( $tags->get_error_message() );
    584584
    585585        foreach ( $tags as $key => $tag ) {
    586586                $tags[ $key ]->link = '#';
     
    591591        $return = wp_generate_tag_cloud( $tags, array('filter' => 0) );
    592592
    593593        if ( empty($return) )
    594                 die('0');
     594                wp_die('0');
    595595
    596596        echo $return;
    597597
    598         exit;
     598        wp_die('');
    599599}
    600600
    601601function wp_ajax_get_comments( $action ) {
     
    608608        $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
    609609
    610610        if ( !current_user_can( 'edit_post', $post_id ) )
    611                 die('-1');
     611                wp_die('-1');
    612612
    613613        $wp_list_table->prepare_items();
    614614
    615615        if ( !$wp_list_table->has_items() )
    616                 die('1');
     616                wp_die('1');
    617617
    618618        $x = new WP_Ajax_Response();
    619619        ob_start();
     
    642642
    643643        $comment_post_ID = (int) $_POST['comment_post_ID'];
    644644        if ( !current_user_can( 'edit_post', $comment_post_ID ) )
    645                 die('-1');
     645                wp_die('-1');
    646646
    647647        $status = $wpdb->get_var( $wpdb->prepare("SELECT post_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) );
    648648
    649649        if ( empty($status) )
    650                 die('1');
     650                wp_die('1');
    651651        elseif ( in_array($status, array('draft', 'pending', 'trash') ) )
    652                 die( __('ERROR: you are replying to a comment on a draft post.') );
     652                wp_die( __('ERROR: you are replying to a comment on a draft post.') );
    653653
    654654        $user = wp_get_current_user();
    655655        if ( $user->ID ) {
     
    664664                        }
    665665                }
    666666        } else {
    667                 die( __('Sorry, you must be logged in to reply to a comment.') );
     667                wp_die( __('Sorry, you must be logged in to reply to a comment.') );
    668668        }
    669669
    670670        if ( '' == $comment_content )
    671                 die( __('ERROR: please type a comment.') );
     671                wp_die( __('ERROR: please type a comment.') );
    672672
    673673        $comment_parent = absint($_POST['comment_ID']);
    674674        $comment_auto_approved = false;
     
    676676
    677677        $comment_id = wp_new_comment( $commentdata );
    678678        $comment = get_comment($comment_id);
    679         if ( ! $comment ) die('1');
     679        if ( ! $comment ) wp_die('1');
    680680
    681681        $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
    682682
     
    729729
    730730        $comment_id = (int) $_POST['comment_ID'];
    731731        if ( ! current_user_can( 'edit_comment', $comment_id ) )
    732                 die('-1');
     732                wp_die('-1');
    733733
    734734        if ( '' == $_POST['content'] )
    735                 die( __('ERROR: please type a comment.') );
     735                wp_die( __('ERROR: please type a comment.') );
    736736
    737737        $_POST['comment_status'] = $_POST['status'];
    738738        edit_comment();
     
    764764
    765765function wp_ajax_add_menu_item() {
    766766        if ( ! current_user_can( 'edit_theme_options' ) )
    767                 die('-1');
     767                wp_die('-1');
    768768
    769769        check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    770770
     
    802802
    803803        $item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
    804804        if ( is_wp_error( $item_ids ) )
    805                 die('-1');
     805                wp_die('-1');
    806806
    807807        $menu_items = array();
    808808
     
    835835
    836836        if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
    837837                if ( !current_user_can( 'edit_post', $pid ) )
    838                         die('-1');
     838                        wp_die('-1');
    839839                if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
    840                         die('1');
     840                        wp_die('1');
    841841                if ( $post->post_status == 'auto-draft' ) {
    842842                        $save_POST = $_POST; // Backup $_POST
    843843                        $_POST = array(); // Make it empty for edit_post()
     
    858858                                }
    859859                                $_POST = $save_POST; // Now we can restore original $_POST again
    860860                                if ( !$mid = add_meta( $pid ) )
    861                                         die(__('Please provide a custom field value.'));
     861                                        wp_die(__('Please provide a custom field value.'));
    862862                        } else {
    863                                 die('0');
     863                                wp_die('0');
    864864                        }
    865865                } else if ( !$mid = add_meta( $pid ) ) {
    866                         die(__('Please provide a custom field value.'));
     866                        wp_die(__('Please provide a custom field value.'));
    867867                }
    868868
    869869                $meta = get_metadata_by_mid( 'post', $mid );
     
    881881                $key = stripslashes( $_POST['meta'][$mid]['key'] );
    882882                $value = stripslashes( $_POST['meta'][$mid]['value'] );
    883883                if ( '' == trim($key) )
    884                         die(__('Please provide a custom field name.'));
     884                        wp_die(__('Please provide a custom field name.'));
    885885                if ( '' == trim($value) )
    886                         die(__('Please provide a custom field value.'));
     886                        wp_die(__('Please provide a custom field value.'));
    887887                if ( ! $meta = get_metadata_by_mid( 'post', $mid ) )
    888                         die('0'); // if meta doesn't exist
     888                        wp_die('0'); // if meta doesn't exist
    889889                if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
    890890                        ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) ||
    891891                        ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) )
    892                         die('-1');
     892                        wp_die('-1');
    893893                if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
    894894                        if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) )
    895                                 die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
     895                                wp_die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
    896896                }
    897897
    898898                $x = new WP_Ajax_Response( array(
     
    915915
    916916        check_ajax_referer( $action );
    917917        if ( ! current_user_can('create_users') )
    918                 die('-1');
     918                wp_die('-1');
    919919        if ( ! $user_id = edit_user() ) {
    920                 die('0');
     920                wp_die('0');
    921921        } elseif ( is_wp_error( $user_id ) ) {
    922922                $x = new WP_Ajax_Response( array(
    923923                        'what' => 'user',
     
    986986
    987987        if ( 'page' == $post->post_type ) {
    988988                if ( !current_user_can('edit_page', $post_ID) )
    989                         die(__('You are not allowed to edit this page.'));
     989                        wp_die(__('You are not allowed to edit this page.'));
    990990        } else {
    991991                if ( !current_user_can('edit_post', $post_ID) )
    992                         die(__('You are not allowed to edit this post.'));
     992                        wp_die(__('You are not allowed to edit this post.'));
    993993        }
    994994
    995995        if ( $do_autosave ) {
     
    10531053        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    10541054
    10551055        if ( $page != sanitize_key( $page ) )
    1056                 die('0');
     1056                wp_die('0');
    10571057
    10581058        if ( ! $user = wp_get_current_user() )
    1059                 die('-1');
     1059                wp_die('-1');
    10601060
    10611061        if ( is_array($closed) )
    10621062                update_user_option($user->ID, "closedpostboxes_$page", $closed, true);
     
    10661066                update_user_option($user->ID, "metaboxhidden_$page", $hidden, true);
    10671067        }
    10681068
    1069         die('1');
     1069        wp_die('1');
    10701070}
    10711071
    10721072function wp_ajax_hidden_columns() {
     
    10761076        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    10771077
    10781078        if ( $page != sanitize_key( $page ) )
    1079                 die('0');
     1079                wp_die('0');
    10801080
    10811081        if ( ! $user = wp_get_current_user() )
    1082                 die('-1');
     1082                wp_die('-1');
    10831083
    10841084        if ( is_array($hidden) )
    10851085                update_user_option($user->ID, "manage{$page}columnshidden", $hidden, true);
    10861086
    1087         die('1');
     1087        wp_die('1');
    10881088}
    10891089
    10901090function wp_ajax_update_welcome_panel() {
    10911091        check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
    10921092
    10931093        if ( ! current_user_can( 'edit_theme_options' ) )
    1094                 die('-1');
     1094                wp_die('-1');
    10951095
    10961096        update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 );
    10971097
    1098         die('1');
     1098        wp_die('1');
    10991099}
    11001100
    11011101function wp_ajax_menu_get_metabox() {
    11021102        if ( ! current_user_can( 'edit_theme_options' ) )
    1103                 die('-1');
     1103                wp_die('-1');
    11041104
    11051105        require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    11061106
     
    11351135                ));
    11361136        }
    11371137
    1138         exit;
     1138        wp_die('');
    11391139}
    11401140
    11411141function wp_ajax_wp_link_ajax() {
     
    11511151        $results = _WP_Editors::wp_link_query( $args );
    11521152
    11531153        if ( ! isset( $results ) )
    1154                 die( '0' );
     1154                wp_die( '0' );
    11551155
    11561156        echo json_encode( $results );
    11571157        echo "\n";
    11581158
    1159         exit;
     1159        wp_die('');
    11601160}
    11611161
    11621162function wp_ajax_menu_locations_save() {
    11631163        if ( ! current_user_can( 'edit_theme_options' ) )
    1164                 die('-1');
     1164                wp_die('-1');
    11651165        check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    11661166        if ( ! isset( $_POST['menu-locations'] ) )
    1167                 die('0');
     1167                wp_die('0');
    11681168        set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
    1169         die('1');
     1169        wp_die('1');
    11701170}
    11711171
    11721172function wp_ajax_meta_box_order() {
     
    11801180        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    11811181
    11821182        if ( $page != sanitize_key( $page ) )
    1183                 die('0');
     1183                wp_die('0');
    11841184
    11851185        if ( ! $user = wp_get_current_user() )
    1186                 die('-1');
     1186                wp_die('-1');
    11871187
    11881188        if ( $order )
    11891189                update_user_option($user->ID, "meta-box-order_$page", $order, true);
     
    11911191        if ( $page_columns )
    11921192                update_user_option($user->ID, "screen_layout_$page", $page_columns, true);
    11931193
    1194         die('1');
     1194        wp_die('1');
    11951195}
    11961196
    11971197function wp_ajax_menu_quick_search() {
    11981198        if ( ! current_user_can( 'edit_theme_options' ) )
    1199                 die('-1');
     1199                wp_die('-1');
    12001200
    12011201        require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    12021202
    12031203        _wp_ajax_menu_quick_search( $_POST );
    12041204
    1205         exit;
     1205        wp_die('');
    12061206}
    12071207
    12081208function wp_ajax_get_permalink() {
    12091209        check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
    12101210        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    1211         die(add_query_arg(array('preview' => 'true'), get_permalink($post_id)));
     1211        wp_die(add_query_arg(array('preview' => 'true'), get_permalink($post_id)));
    12121212}
    12131213
    12141214function wp_ajax_sample_permalink() {
     
    12161216        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    12171217        $title = isset($_POST['new_title'])? $_POST['new_title'] : '';
    12181218        $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null;
    1219         die(get_sample_permalink_html($post_id, $title, $slug));
     1219        wp_die(get_sample_permalink_html($post_id, $title, $slug));
    12201220}
    12211221
    12221222function wp_ajax_inline_save() {
     
    12251225        check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
    12261226
    12271227        if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
    1228                 exit;
     1228                wp_die('');
    12291229
    12301230        if ( 'page' == $_POST['post_type'] ) {
    12311231                if ( ! current_user_can( 'edit_page', $post_ID ) )
    1232                         die( __('You are not allowed to edit this page.') );
     1232                        wp_die( __('You are not allowed to edit this page.') );
    12331233        } else {
    12341234                if ( ! current_user_can( 'edit_post', $post_ID ) )
    1235                         die( __('You are not allowed to edit this post.') );
     1235                        wp_die( __('You are not allowed to edit this post.') );
    12361236        }
    12371237
    12381238        set_current_screen( $_POST['screen'] );
     
    12411241                $last_user = get_userdata( $last );
    12421242                $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
    12431243                printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ),        esc_html( $last_user_name ) );
    1244                 exit;
     1244                wp_die('');
    12451245        }
    12461246
    12471247        $data = &$_POST;
     
    12771277        $mode = $_POST['post_view'];
    12781278        $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
    12791279
    1280         exit;
     1280        wp_die('');
    12811281}
    12821282
    12831283function wp_ajax_inline_save_tax() {
     
    12881288        $taxonomy = sanitize_key( $_POST['taxonomy'] );
    12891289        $tax = get_taxonomy( $taxonomy );
    12901290        if ( ! $tax )
    1291                 die( '0' );
     1291                wp_die( '0' );
    12921292
    12931293        if ( ! current_user_can( $tax->cap->edit_terms ) )
    1294                 die( '-1' );
     1294                wp_die( '-1' );
    12951295
    12961296        set_current_screen( 'edit-' . $taxonomy );
    12971297
    12981298        $wp_list_table = _get_list_table('WP_Terms_List_Table');
    12991299
    13001300        if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
    1301                 die(-1);
     1301                wp_die(-1);
    13021302
    13031303        $tag = get_term( $id, $taxonomy );
    13041304        $_POST['description'] = $tag->description;
     
    13081308                $tag = get_term( $updated['term_id'], $taxonomy );
    13091309                if ( !$tag || is_wp_error( $tag ) ) {
    13101310                        if ( is_wp_error($tag) && $tag->get_error_message() )
    1311                                 die( $tag->get_error_message() );
    1312                         die( __('Item not updated.') );
     1311                                wp_die( $tag->get_error_message() );
     1312                        wp_die( __('Item not updated.') );
    13131313                }
    13141314
    13151315                echo $wp_list_table->single_row( $tag );
    13161316        } else {
    13171317                if ( is_wp_error($updated) && $updated->get_error_message() )
    1318                         die( $updated->get_error_message() );
    1319                 die( __('Item not updated.') );
     1318                        wp_die( $updated->get_error_message() );
     1319                wp_die( __('Item not updated.') );
    13201320        }
    13211321
    1322         exit;
     1322        wp_die('');
    13231323}
    13241324
    13251325function wp_ajax_find_posts() {
     
    13281328        check_ajax_referer( 'find-posts' );
    13291329
    13301330        if ( empty($_POST['ps']) )
    1331                 exit;
     1331                wp_die('');
    13321332
    13331333        if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
    13341334                $what = $_POST['post_type'];
     
    14001400        check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    14011401
    14021402        if ( !current_user_can('edit_theme_options') )
    1403                 die('-1');
     1403                wp_die('-1');
    14041404
    14051405        unset( $_POST['savewidgets'], $_POST['action'] );
    14061406
     
    14211421                        $sidebars[$key] = $sb;
    14221422                }
    14231423                wp_set_sidebars_widgets($sidebars);
    1424                 die('1');
     1424                wp_die('1');
    14251425        }
    14261426
    1427         die('-1');
     1427        wp_die('-1');
    14281428}
    14291429
    14301430function wp_ajax_save_widget() {
     
    14331433        check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    14341434
    14351435        if ( !current_user_can('edit_theme_options') || !isset($_POST['id_base']) )
    1436                 die('-1');
     1436                wp_die('-1');
    14371437
    14381438        unset( $_POST['savewidgets'], $_POST['action'] );
    14391439
     
    14551455        if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
    14561456
    14571457                if ( !isset($wp_registered_widgets[$widget_id]) )
    1458                         die($error);
     1458                        wp_die($error);
    14591459
    14601460                $sidebar = array_diff( $sidebar, array($widget_id) );
    14611461                $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
    14621462        } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
    14631463                if ( !$multi_number )
    1464                         die($error);
     1464                        wp_die($error);
    14651465
    14661466                $_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
    14671467                $widget_id = $id_base . '-' . $multi_number;
     
    14861486                $sidebars[$sidebar_id] = $sidebar;
    14871487                wp_set_sidebars_widgets($sidebars);
    14881488                echo "deleted:$widget_id";
    1489                 die();
     1489                wp_die('');
    14901490        }
    14911491
    14921492        if ( !empty($_POST['add_new']) )
    1493                 die();
     1493                wp_die('');
    14941494
    14951495        if ( $form = $wp_registered_widget_controls[$widget_id] )
    14961496                call_user_func_array( $form['callback'], $form['params'] );
    14971497
    1498         die();
     1498        wp_die('');
    14991499}
    15001500
    15011501function wp_ajax_image_editor() {
    15021502        $attachment_id = intval($_POST['postid']);
    15031503        if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
    1504                 die('-1');
     1504                wp_die('-1');
    15051505
    15061506        check_ajax_referer( "image_editor-$attachment_id" );
    15071507        include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
     
    15111511                case 'save' :
    15121512                        $msg = wp_save_image($attachment_id);
    15131513                        $msg = json_encode($msg);
    1514                         die($msg);
     1514                        wp_die($msg);
    15151515                        break;
    15161516                case 'scale' :
    15171517                        $msg = wp_save_image($attachment_id);
     
    15221522        }
    15231523
    15241524        wp_image_editor($attachment_id, $msg);
    1525         die();
     1525        wp_die('');
    15261526}
    15271527
    15281528function wp_ajax_set_post_thumbnail() {
    15291529        $post_ID = intval( $_POST['post_id'] );
    15301530        if ( !current_user_can( 'edit_post', $post_ID ) )
    1531                 die( '-1' );
     1531                wp_die( '-1' );
    15321532        $thumbnail_id = intval( $_POST['thumbnail_id'] );
    15331533
    15341534        check_ajax_referer( "set_post_thumbnail-$post_ID" );
    15351535
    15361536        if ( $thumbnail_id == '-1' ) {
    15371537                if ( delete_post_thumbnail( $post_ID ) )
    1538                         die( _wp_post_thumbnail_html() );
     1538                        wp_die( _wp_post_thumbnail_html() );
    15391539                else
    1540                         die( '0' );
     1540                        wp_die( '0' );
    15411541        }
    15421542
    15431543        if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
    1544                 die( _wp_post_thumbnail_html( $thumbnail_id ) );
    1545         die( '0' );
     1544                wp_die( _wp_post_thumbnail_html( $thumbnail_id ) );
     1545        wp_die( '0' );
    15461546}
    15471547
    15481548function wp_ajax_date_format() {
    1549         die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
     1549        wp_die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
    15501550}
    15511551
    15521552function wp_ajax_time_format() {
    1553         die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
     1553        wp_die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
    15541554}
    15551555
    15561556function wp_ajax_wp_fullscreen_save_post() {
     
    15771577                        $message = __('Save failed');
    15781578
    15791579                echo json_encode( array( 'message' => $message, 'last_edited' => '' ) );
    1580                 die();
     1580                wp_die('');
    15811581        } else {
    15821582                $message = __('Saved.');
    15831583        }
     
    15981598        }
    15991599
    16001600        echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
    1601         die();
     1601        wp_die('');
    16021602}
    16031603
    16041604function wp_ajax_wp_remove_post_lock() {
    16051605        if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
    1606                 die( '0' );
     1606                wp_die( '0' );
    16071607        $post_id = (int) $_POST['post_ID'];
    16081608        if ( ! $post = get_post( $post_id ) )
    1609                 die( '0' );
     1609                wp_die( '0' );
    16101610
    16111611        check_ajax_referer( 'update-' . $post->post_type . '_' . $post_id );
    16121612
    16131613        if ( ! current_user_can( 'edit_post', $post_id ) )
    1614                 die( '-1' );
     1614                wp_die( '-1' );
    16151615
    16161616        $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
    16171617        if ( $active_lock[1] != get_current_user_id() )
    1618                 die( '0' );
     1618                wp_die( '0' );
    16191619
    16201620        $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1];
    16211621        update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
    1622         die( '1' );
     1622        wp_die( '1' );
    16231623}
    16241624
    16251625function wp_ajax_dismiss_wp_pointer() {
    16261626        $pointer = $_POST['pointer'];
    16271627        if ( $pointer != sanitize_key( $pointer ) )
    1628                 die( '0' );
     1628                wp_die( '0' );
    16291629
    16301630//      check_ajax_referer( 'dismiss-pointer_' . $pointer );
    16311631
    16321632        $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
    16331633
    16341634        if ( in_array( $pointer, $dismissed ) )
    1635                 die( '0' );
     1635                wp_die( '0' );
    16361636
    16371637        $dismissed[] = $pointer;
    16381638        $dismissed = implode( ',', $dismissed );
    16391639
    16401640        update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
    1641         die( '1' );
     1641        wp_die( '1' );
    16421642}
     1643 No newline at end of file
  • wordpress/wp-includes/class-wp-ajax-response.php

     
    131131                foreach ( (array) $this->responses as $response )
    132132                        echo $response;
    133133                echo '</wp_ajax>';
    134                 die();
     134                wp_die('');
    135135        }
    136136}
  • wordpress/wp-includes/functions.php

     
    20442044 * @param string|array $args Optional arguments to control behavior.
    20452045 */
    20462046function wp_die( $message, $title = '', $args = array() ) {
    2047         if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
    2048                 die('-1');
    2049 
    2050         if ( function_exists( 'apply_filters' ) ) {
     2047        if ( defined( 'DOING_AJAX' ) && DOING_AJAX && function_exists( 'apply_filters' ) ) {
     2048                $function = apply_filters( 'wp_die_ajax_handler' , '_default_wp_die_ajax_handler', -1 );
     2049        } elseif ( function_exists( 'apply_filters' ) ) {
    20512050                $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler');
    20522051        } else {
    20532052                $function = '_default_wp_die_handler';
    20542053        }
    2055 
    20562054        call_user_func( $function, $message, $title, $args );
    20572055}
    20582056
    20592057/**
     2058 * Kill WordPress ajax execution.
     2059 *
     2060 * @since 3.4.0
     2061 * @access private
     2062 *
     2063 * @param string $message Error message.
     2064 * @param string $title Error title.
     2065 * @param string|array $args Optional arguments to control behavior.
     2066 */
     2067function _default_wp_die_ajax_handler( $message, $title = '', $args = array() ) {
     2068        die( $message );
     2069}
     2070
     2071/**
    20602072 * Kill WordPress execution and display HTML message with error message.
    20612073 *
    20622074 * This is the default handler for wp_die if you want a custom one for your
  • wordpress/wp-includes/pluggable.php

     
    830830        $result = wp_verify_nonce( $nonce, $action );
    831831
    832832        if ( $die && false == $result )
    833                 die('-1');
     833                wp_die('-1');
    834834
    835835        do_action('check_ajax_referer', $action, $result);
    836836