Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18018 r18110  
    509509    break;
    510510case 'add-tag' :
    511     check_ajax_referer( 'add-tag' );
     511    check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
    512512    $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post';
    513513    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     
    610610        die('1');
    611611
    612     $comment_list_item = '';
    613612    $x = new WP_Ajax_Response();
     613    ob_start();
    614614    foreach ( $wp_list_table->items as $comment ) {
    615615        get_comment( $comment );
    616         ob_start();
    617             $wp_list_table->single_row( $comment );
    618             $comment_list_item .= ob_get_contents();
    619         ob_end_clean();
    620     }
     616        $wp_list_table->single_row( $comment );
     617    }
     618    $comment_list_item = ob_get_contents();
     619    ob_end_clean();
     620
    621621    $x->add( array(
    622622        'what' => 'comments',
     
    661661
    662662    $comment_parent = absint($_POST['comment_ID']);
     663    $comment_auto_approved = false;
    663664    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
    664665
     
    667668    if ( ! $comment ) die('1');
    668669
    669     $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    670 
    671     $x = new WP_Ajax_Response();
     670    $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
     671
     672
     673    // automatically approve parent comment
     674    if ( !empty($_POST['approve_parent']) ) {
     675        $parent = get_comment( $comment_parent );
     676
     677        if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
     678            if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
     679                $comment_auto_approved = true;
     680        }
     681    }
    672682
    673683    ob_start();
     
    686696    ob_end_clean();
    687697
    688     $x->add( array(
     698    $response = array(
    689699        'what' => 'comment',
    690700        'id' => $comment->comment_ID,
    691701        'data' => $comment_list_item,
    692702        'position' => $position
    693     ));
    694 
     703    );
     704
     705    if ( $comment_auto_approved )
     706        $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
     707
     708    $x = new WP_Ajax_Response();
     709    $x->add( $response );
    695710    $x->send();
    696711    break;
     
    845860        ) );
    846861    } else { // Update?
    847         $mid = (int) array_pop( $var_by_ref = array_keys($_POST['meta']) );
     862        $mid = (int) array_pop( array_keys($_POST['meta']) );
    848863        $key = $_POST['meta'][$mid]['key'];
    849864        $value = $_POST['meta'][$mid]['value'];
     
    919934    $do_lock = true;
    920935
    921     $data = '';
     936    $data = $alert = '';
    922937    /* translators: draft saved date format, see http://php.net/date */
    923938    $draft_saved_date_format = __('g:i:s a');
     
    927942    $supplemental = array();
    928943    if ( isset($login_grace_period) )
    929         $supplemental['session_expired'] = add_query_arg( 'interim-login', 1, wp_login_url() );
     944        $alert .= sprintf( __('Your login has expired. Please open a new browser window and <a href="%s" target="_blank">log in again</a>. '), add_query_arg( 'interim-login', 1, wp_login_url() ) );
    930945
    931946    $id = $revision_id = 0;
     
    942957        $last_user = get_userdata( $last );
    943958        $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
    944         $data = new WP_Error( 'locked', sprintf(
    945             $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ),
    946             esc_html( $last_user_name )
    947         ) );
     959        $data = __( 'Autosave disabled.' );
    948960
    949961        $supplemental['disable_autosave'] = 'disable';
     962        $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) );
    950963    }
    951964
     
    9921005        }
    9931006    }
     1007
     1008    if ( ! empty($alert) )
     1009        $supplemental['alert'] = $alert;
    9941010
    9951011    $x = new WP_Ajax_Response( array(
     
    14701486    die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
    14711487    break;
     1488case 'wp-fullscreen-save-post' :
     1489    if ( isset($_POST['post_ID']) )
     1490        $post_id = (int) $_POST['post_ID'];
     1491    else
     1492        $post_id = 0;
     1493
     1494    $post = null;
     1495    $post_type_object = null;
     1496    $post_type = null;
     1497    if ( $post_id ) {
     1498        $post = get_post($post_id);
     1499        if ( $post ) {
     1500            $post_type_object = get_post_type_object($post->post_type);
     1501            if ( $post_type_object ) {
     1502                $post_type = $post->post_type;
     1503                $current_screen->post_type = $post->post_type;
     1504                $current_screen->id = $current_screen->post_type;
     1505            }
     1506        }
     1507    } elseif ( isset($_POST['post_type']) ) {
     1508        $post_type_object = get_post_type_object($_POST['post_type']);
     1509        if ( $post_type_object ) {
     1510            $post_type = $post_type_object->name;
     1511            $current_screen->post_type = $post_type;
     1512            $current_screen->id = $current_screen->post_type;
     1513        }
     1514    }
     1515
     1516    check_ajax_referer('update-' . $post_type . '_' . $post_id, '_wpnonce');
     1517
     1518    $post_id = edit_post();
     1519
     1520    if ( is_wp_error($post_id) ) {
     1521        if ( $post_id->get_error_message() )
     1522            $message = $post_id->get_error_message();
     1523        else
     1524            $message = __('Save failed');
     1525
     1526        echo json_encode( array( 'message' => $message, 'last_edited' => '' ) );
     1527        die();
     1528    } else {
     1529        $message = __('Saved.');
     1530    }
     1531
     1532    if ( $post ) {
     1533        $last_date = mysql2date( get_option('date_format'), $post->post_modified );
     1534        $last_time = mysql2date( get_option('time_format'), $post->post_modified );
     1535    } else {
     1536        $last_date = date_i18n( get_option('date_format') );
     1537        $last_time = date_i18n( get_option('time_format') );
     1538    }
     1539
     1540    if ( $last_id = get_post_meta($post_id, '_edit_last', true) ) {
     1541        $last_user = get_userdata($last_id);
     1542        $last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time );
     1543    } else {
     1544        $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time );
     1545    }
     1546
     1547    echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
     1548    die();
     1549    break;
    14721550default :
    14731551    do_action( 'wp_ajax_' . $_POST['action'] );
Note: See TracChangeset for help on using the changeset viewer.