Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42228 r42343  
    2424
    2525        // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    26         if ( ! empty($_POST['screen_id']) )
    27                 $screen_id = sanitize_key($_POST['screen_id']);
    28         else
     26        if ( ! empty( $_POST['screen_id'] ) ) {
     27                $screen_id = sanitize_key( $_POST['screen_id'] );
     28        } else {
    2929                $screen_id = 'front';
    30 
    31         if ( ! empty($_POST['data']) ) {
     30        }
     31
     32        if ( ! empty( $_POST['data'] ) ) {
    3233                $data = wp_unslash( (array) $_POST['data'] );
    3334
     
    6970        $response['server_time'] = time();
    7071
    71         wp_send_json($response);
     72        wp_send_json( $response );
    7273}
    7374
     
    110111
    111112        $taxonomy = sanitize_key( $_GET['tax'] );
    112         $tax = get_taxonomy( $taxonomy );
     113        $tax      = get_taxonomy( $taxonomy );
    113114        if ( ! $tax ) {
    114115                wp_die( 0 );
     
    122123
    123124        $comma = _x( ',', 'tag delimiter' );
    124         if ( ',' !== $comma )
     125        if ( ',' !== $comma ) {
    125126                $s = str_replace( $comma, ',', $s );
     127        }
    126128        if ( false !== strpos( $s, ',' ) ) {
    127129                $s = explode( ',', $s );
    128                 $s = $s[count( $s ) - 1];
     130                $s = $s[ count( $s ) - 1 ];
    129131        }
    130132        $s = trim( $s );
     
    145147         * ensure it's a non-negative, non-zero integer.
    146148         */
    147         if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){
     149        if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) {
    148150                wp_die();
    149151        }
    150152
    151         $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );
     153        $results = get_terms(
     154                $taxonomy, array(
     155                        'name__like' => $s,
     156                        'fields'     => 'names',
     157                        'hide_empty' => false,
     158                )
     159        );
    152160
    153161        echo join( $results, "\n" );
     
    161169 */
    162170function wp_ajax_wp_compression_test() {
    163         if ( !current_user_can( 'manage_options' ) )
     171        if ( ! current_user_can( 'manage_options' ) ) {
    164172                wp_die( -1 );
    165 
    166         if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) {
    167                 update_site_option('can_compress_scripts', 0);
     173        }
     174
     175        if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' == ini_get( 'output_handler' ) ) {
     176                update_site_option( 'can_compress_scripts', 0 );
    168177                wp_die( 0 );
    169178        }
    170179
    171         if ( isset($_GET['test']) ) {
     180        if ( isset( $_GET['test'] ) ) {
    172181                header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
    173182                header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
    174183                header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    175                 header('Content-Type: application/javascript; charset=UTF-8');
    176                 $force_gzip = ( defined('ENFORCE_GZIP') && ENFORCE_GZIP );
    177                 $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
     184                header( 'Content-Type: application/javascript; charset=UTF-8' );
     185                $force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
     186                $test_str   = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
    178187
    179188                if ( 1 == $_GET['test'] ) {
    180                         echo $test_str;
    181                         wp_die();
     189                        echo $test_str;
     190                        wp_die();
    182191                } elseif ( 2 == $_GET['test'] ) {
    183                         if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
     192                        if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
    184193                                wp_die( -1 );
    185                         if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
    186                                 header('Content-Encoding: deflate');
     194                        }
     195                        if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
     196                                header( 'Content-Encoding: deflate' );
    187197                                $out = gzdeflate( $test_str, 1 );
    188                         } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
    189                                 header('Content-Encoding: gzip');
     198                        } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
     199                                header( 'Content-Encoding: gzip' );
    190200                                $out = gzencode( $test_str, 1 );
    191201                        } else {
     
    196206                } elseif ( 'no' == $_GET['test'] ) {
    197207                        check_ajax_referer( 'update_can_compress_scripts' );
    198                         update_site_option('can_compress_scripts', 0);
     208                        update_site_option( 'can_compress_scripts', 0 );
    199209                } elseif ( 'yes' == $_GET['test'] ) {
    200210                        check_ajax_referer( 'update_can_compress_scripts' );
    201                         update_site_option('can_compress_scripts', 1);
     211                        update_site_option( 'can_compress_scripts', 1 );
    202212                }
    203213        }
     
    212222 */
    213223function wp_ajax_imgedit_preview() {
    214         $post_id = intval($_GET['postid']);
    215         if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
     224        $post_id = intval( $_GET['postid'] );
     225        if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
    216226                wp_die( -1 );
     227        }
    217228
    218229        check_ajax_referer( "image_editor-$post_id" );
    219230
    220231        include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
    221         if ( ! stream_preview_image($post_id) )
     232        if ( ! stream_preview_image( $post_id ) ) {
    222233                wp_die( -1 );
     234        }
    223235
    224236        wp_die();
     
    243255 */
    244256function wp_ajax_autocomplete_user() {
    245         if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) )
     257        if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) {
    246258                wp_die( -1 );
     259        }
    247260
    248261        /** This filter is documented in wp-admin/user-new.php */
    249         if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) )
     262        if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) {
    250263                wp_die( -1 );
     264        }
    251265
    252266        $return = array();
     
    275289        }
    276290
    277         $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
    278         $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
    279 
    280         $users = get_users( array(
    281                 'blog_id' => false,
    282                 'search'  => '*' . $_REQUEST['term'] . '*',
    283                 'include' => $include_blog_users,
    284                 'exclude' => $exclude_blog_users,
    285                 'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
    286         ) );
     291        $include_blog_users = ( $type == 'search' ? get_users(
     292                array(
     293                        'blog_id' => $id,
     294                        'fields'  => 'ID',
     295                )
     296        ) : array() );
     297        $exclude_blog_users = ( $type == 'add' ? get_users(
     298                array(
     299                        'blog_id' => $id,
     300                        'fields'  => 'ID',
     301                )
     302        ) : array() );
     303
     304        $users = get_users(
     305                array(
     306                        'blog_id'        => false,
     307                        'search'         => '*' . $_REQUEST['term'] . '*',
     308                        'include'        => $include_blog_users,
     309                        'exclude'        => $exclude_blog_users,
     310                        'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
     311                )
     312        );
    287313
    288314        foreach ( $users as $user ) {
     
    316342
    317343        if ( is_wp_error( $events ) ) {
    318                 wp_send_json_error( array(
    319                         'error' => $events->get_error_message(),
    320                 ) );
     344                wp_send_json_error(
     345                        array(
     346                                'error' => $events->get_error_message(),
     347                        )
     348                );
    321349        } else {
    322350                if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
     
    361389
    362390        switch ( $_GET['widget'] ) {
    363                 case 'dashboard_primary' :
     391                case 'dashboard_primary':
    364392                        wp_dashboard_primary();
    365393                        break;
     
    393421 */
    394422function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
    395         $total    = isset( $_POST['_total'] )    ? (int) $_POST['_total']    : 0;
     423        $total    = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0;
    396424        $per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0;
    397         $page     = isset( $_POST['_page'] )     ? (int) $_POST['_page']    : 0;
    398         $url      = isset( $_POST['_url'] )      ? esc_url_raw( $_POST['_url'] ) : '';
     425        $page     = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0;
     426        $url      = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : '';
    399427
    400428        // JS didn't send us everything we need to know. Just die with success message
     
    415443                $counts = wp_count_comments();
    416444
    417                 $x = new WP_Ajax_Response( array(
    418                         'what' => 'comment',
    419                         // Here for completeness - not used.
    420                         'id' => $comment_id,
    421                         'supplemental' => array(
    422                                 'status' => $comment_status,
    423                                 'postId' => $comment ? $comment->comment_post_ID : '',
    424                                 'time' => $time,
    425                                 'in_moderation' => $counts->moderated,
    426                                 'i18n_comments_text' => sprintf(
    427                                         _n( '%s Comment', '%s Comments', $counts->approved ),
    428                                         number_format_i18n( $counts->approved )
     445                $x = new WP_Ajax_Response(
     446                        array(
     447                                'what'         => 'comment',
     448                                // Here for completeness - not used.
     449                                'id'           => $comment_id,
     450                                'supplemental' => array(
     451                                        'status'               => $comment_status,
     452                                        'postId'               => $comment ? $comment->comment_post_ID : '',
     453                                        'time'                 => $time,
     454                                        'in_moderation'        => $counts->moderated,
     455                                        'i18n_comments_text'   => sprintf(
     456                                                _n( '%s Comment', '%s Comments', $counts->approved ),
     457                                                number_format_i18n( $counts->approved )
     458                                        ),
     459                                        'i18n_moderation_text' => sprintf(
     460                                                _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
     461                                                number_format_i18n( $counts->moderated )
     462                                        ),
     463                                        'comment_link'         => $comment_link,
    429464                                ),
    430                                 'i18n_moderation_text' => sprintf(
    431                                         _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
    432                                         number_format_i18n( $counts->moderated )
    433                                 ),
    434                                 'comment_link' => $comment_link,
    435465                        )
    436                 ) );
     466                );
    437467                $x->send();
    438468        }
    439469
    440470        $total += $delta;
    441         if ( $total < 0 )
     471        if ( $total < 0 ) {
    442472                $total = 0;
     473        }
    443474
    444475        // Only do the expensive stuff on a page-break, and about 1 other time per page
     
    450481                if ( isset( $parsed['query'] ) ) {
    451482                        parse_str( $parsed['query'], $query_vars );
    452                         if ( !empty( $query_vars['comment_status'] ) )
     483                        if ( ! empty( $query_vars['comment_status'] ) ) {
    453484                                $status = $query_vars['comment_status'];
    454                         if ( !empty( $query_vars['p'] ) )
     485                        }
     486                        if ( ! empty( $query_vars['p'] ) ) {
    455487                                $post_id = (int) $query_vars['p'];
    456                         if ( ! empty( $query_vars['comment_type'] ) )
     488                        }
     489                        if ( ! empty( $query_vars['comment_type'] ) ) {
    457490                                $type = $query_vars['comment_type'];
     491                        }
    458492                }
    459493
    460494                if ( empty( $type ) ) {
    461495                        // Only use the comment count if not filtering by a comment_type.
    462                         $comment_count = wp_count_comments($post_id);
     496                        $comment_count = wp_count_comments( $post_id );
    463497
    464498                        // We're looking for a known type of comment count.
     
    471505
    472506        // The time since the last comment count.
    473         $time = time();
     507        $time    = time();
    474508        $comment = get_comment( $comment_id );
    475509
    476         $x = new WP_Ajax_Response( array(
    477                 'what' => 'comment',
    478                 // Here for completeness - not used.
    479                 'id' => $comment_id,
    480                 'supplemental' => array(
    481                         'status' => $comment ? $comment->comment_approved : '',
    482                         'postId' => $comment ? $comment->comment_post_ID : '',
    483                         'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
    484                         'total_pages' => ceil( $total / $per_page ),
    485                         'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
    486                         'total' => $total,
    487                         'time' => $time
     510        $x = new WP_Ajax_Response(
     511                array(
     512                        'what'         => 'comment',
     513                        // Here for completeness - not used.
     514                        'id'           => $comment_id,
     515                        'supplemental' => array(
     516                                'status'           => $comment ? $comment->comment_approved : '',
     517                                'postId'           => $comment ? $comment->comment_post_ID : '',
     518                                'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
     519                                'total_pages'      => ceil( $total / $per_page ),
     520                                'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
     521                                'total'            => $total,
     522                                'time'             => $time,
     523                        ),
    488524                )
    489         ) );
     525        );
    490526        $x->send();
    491527}
     
    502538 */
    503539function _wp_ajax_add_hierarchical_term() {
    504         $action = $_POST['action'];
    505         $taxonomy = get_taxonomy(substr($action, 4));
     540        $action   = $_POST['action'];
     541        $taxonomy = get_taxonomy( substr( $action, 4 ) );
    506542        check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
    507         if ( !current_user_can( $taxonomy->cap->edit_terms ) )
     543        if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
    508544                wp_die( -1 );
    509         $names = explode(',', $_POST['new'.$taxonomy->name]);
    510         $parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0;
    511         if ( 0 > $parent )
     545        }
     546        $names  = explode( ',', $_POST[ 'new' . $taxonomy->name ] );
     547        $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0;
     548        if ( 0 > $parent ) {
    512549                $parent = 0;
    513         if ( $taxonomy->name == 'category' )
    514                 $post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array();
    515         else
    516                 $post_category = ( isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy->name]) ) ? (array) $_POST['tax_input'][$taxonomy->name] : array();
     550        }
     551        if ( $taxonomy->name == 'category' ) {
     552                $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array();
     553        } else {
     554                $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array();
     555        }
    517556        $checked_categories = array_map( 'absint', (array) $post_category );
    518         $popular_ids = wp_popular_terms_checklist($taxonomy->name, 0, 10, false);
     557        $popular_ids        = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
    519558
    520559        foreach ( $names as $cat_name ) {
    521                 $cat_name = trim($cat_name);
    522                 $category_nicename = sanitize_title($cat_name);
    523                 if ( '' === $category_nicename )
     560                $cat_name          = trim( $cat_name );
     561                $category_nicename = sanitize_title( $cat_name );
     562                if ( '' === $category_nicename ) {
    524563                        continue;
     564                }
    525565
    526566                $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
     
    531571                }
    532572                $checked_categories[] = $cat_id;
    533                 if ( $parent ) // Do these all at once in a second
     573                if ( $parent ) { // Do these all at once in a second
    534574                        continue;
     575                }
    535576
    536577                ob_start();
    537578
    538                 wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy->name, 'descendants_and_self' => $cat_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids ));
     579                wp_terms_checklist(
     580                        0, array(
     581                                'taxonomy'             => $taxonomy->name,
     582                                'descendants_and_self' => $cat_id,
     583                                'selected_cats'        => $checked_categories,
     584                                'popular_cats'         => $popular_ids,
     585                        )
     586                );
    539587
    540588                $data = ob_get_clean();
    541589
    542590                $add = array(
    543                         'what' => $taxonomy->name,
    544                         'id' => $cat_id,
    545                         'data' => str_replace( array("\n", "\t"), '', $data),
    546                         'position' => -1
     591                        'what'     => $taxonomy->name,
     592                        'id'       => $cat_id,
     593                        'data'     => str_replace( array( "\n", "\t" ), '', $data ),
     594                        'position' => -1,
    547595                );
    548596        }
    549597
    550598        if ( $parent ) { // Foncy - replace the parent and all its children
    551                 $parent = get_term( $parent, $taxonomy->name );
     599                $parent  = get_term( $parent, $taxonomy->name );
    552600                $term_id = $parent->term_id;
    553601
    554602                while ( $parent->parent ) { // get the top parent
    555603                        $parent = get_term( $parent->parent, $taxonomy->name );
    556                         if ( is_wp_error( $parent ) )
     604                        if ( is_wp_error( $parent ) ) {
    557605                                break;
     606                        }
    558607                        $term_id = $parent->term_id;
    559608                }
     
    561610                ob_start();
    562611
    563                 wp_terms_checklist( 0, array('taxonomy' => $taxonomy->name, 'descendants_and_self' => $term_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids));
     612                wp_terms_checklist(
     613                        0, array(
     614                                'taxonomy'             => $taxonomy->name,
     615                                'descendants_and_self' => $term_id,
     616                                'selected_cats'        => $checked_categories,
     617                                'popular_cats'         => $popular_ids,
     618                        )
     619                );
    564620
    565621                $data = ob_get_clean();
    566622
    567623                $add = array(
    568                         'what' => $taxonomy->name,
    569                         'id' => $term_id,
    570                         'data' => str_replace( array("\n", "\t"), '', $data),
    571                         'position' => -1
     624                        'what'     => $taxonomy->name,
     625                        'id'       => $term_id,
     626                        'data'     => str_replace( array( "\n", "\t" ), '', $data ),
     627                        'position' => -1,
    572628                );
    573629        }
     
    575631        ob_start();
    576632
    577         wp_dropdown_categories( array(
    578                 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name',
    579                 'hierarchical' => 1, 'show_option_none' => '&mdash; '.$taxonomy->labels->parent_item.' &mdash;'
    580         ) );
     633        wp_dropdown_categories(
     634                array(
     635                        'taxonomy'         => $taxonomy->name,
     636                        'hide_empty'       => 0,
     637                        'name'             => 'new' . $taxonomy->name . '_parent',
     638                        'orderby'          => 'name',
     639                        'hierarchical'     => 1,
     640                        'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
     641                )
     642        );
    581643
    582644        $sup = ob_get_clean();
     
    596658        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    597659
    598         if ( !$comment = get_comment( $id ) )
     660        if ( ! $comment = get_comment( $id ) ) {
    599661                wp_die( time() );
    600         if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )
     662        }
     663        if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    601664                wp_die( -1 );
     665        }
    602666
    603667        check_ajax_referer( "delete-comment_$id" );
     
    605669
    606670        $delta = -1;
    607         if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    608                 if ( 'trash' == $status )
     671        if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) {
     672                if ( 'trash' == $status ) {
    609673                        wp_die( time() );
     674                }
    610675                $r = wp_trash_comment( $comment );
    611         } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
    612                 if ( 'trash' != $status )
     676        } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) {
     677                if ( 'trash' != $status ) {
    613678                        wp_die( time() );
     679                }
    614680                $r = wp_untrash_comment( $comment );
    615                 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
     681                if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash
    616682                        $delta = 1;
    617         } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    618                 if ( 'spam' == $status )
     683                }
     684        } elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) {
     685                if ( 'spam' == $status ) {
    619686                        wp_die( time() );
     687                }
    620688                $r = wp_spam_comment( $comment );
    621         } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
    622                 if ( 'spam' != $status )
     689        } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) {
     690                if ( 'spam' != $status ) {
    623691                        wp_die( time() );
     692                }
    624693                $r = wp_unspam_comment( $comment );
    625                 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
     694                if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam
    626695                        $delta = 1;
    627         } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
     696                }
     697        } elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) {
    628698                $r = wp_delete_comment( $comment );
    629699        } else {
     
    631701        }
    632702
    633         if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     703        if ( $r ) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    634704                _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
     705        }
    635706        wp_die( 0 );
    636707}
     
    649720        }
    650721
    651         $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
    652         $tag = get_term( $tag_id, $taxonomy );
    653         if ( !$tag || is_wp_error( $tag ) )
     722        $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
     723        $tag      = get_term( $tag_id, $taxonomy );
     724        if ( ! $tag || is_wp_error( $tag ) ) {
    654725                wp_die( 1 );
    655 
    656         if ( wp_delete_term($tag_id, $taxonomy))
     726        }
     727
     728        if ( wp_delete_term( $tag_id, $taxonomy ) ) {
    657729                wp_die( 1 );
    658         else
     730        } else {
    659731                wp_die( 0 );
     732        }
    660733}
    661734
     
    669742
    670743        check_ajax_referer( "delete-bookmark_$id" );
    671         if ( !current_user_can( 'manage_links' ) )
     744        if ( ! current_user_can( 'manage_links' ) ) {
    672745                wp_die( -1 );
     746        }
    673747
    674748        $link = get_bookmark( $id );
    675         if ( !$link || is_wp_error( $link ) )
     749        if ( ! $link || is_wp_error( $link ) ) {
    676750                wp_die( 1 );
    677 
    678         if ( wp_delete_link( $id ) )
     751        }
     752
     753        if ( wp_delete_link( $id ) ) {
    679754                wp_die( 1 );
    680         else
     755        } else {
    681756                wp_die( 0 );
     757        }
    682758}
    683759
     
    691767
    692768        check_ajax_referer( "delete-meta_$id" );
    693         if ( !$meta = get_metadata_by_mid( 'post', $id ) )
     769        if ( ! $meta = get_metadata_by_mid( 'post', $id ) ) {
    694770                wp_die( 1 );
    695 
    696         if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta',  $meta->post_id, $meta->meta_key ) )
     771        }
     772
     773        if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) {
    697774                wp_die( -1 );
    698         if ( delete_meta( $meta->meta_id ) )
     775        }
     776        if ( delete_meta( $meta->meta_id ) ) {
    699777                wp_die( 1 );
     778        }
    700779        wp_die( 0 );
    701780}
     
    709788 */
    710789function wp_ajax_delete_post( $action ) {
    711         if ( empty( $action ) )
     790        if ( empty( $action ) ) {
    712791                $action = 'delete-post';
     792        }
    713793        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    714794
    715795        check_ajax_referer( "{$action}_$id" );
    716         if ( !current_user_can( 'delete_post', $id ) )
     796        if ( ! current_user_can( 'delete_post', $id ) ) {
    717797                wp_die( -1 );
    718 
    719         if ( !get_post( $id ) )
     798        }
     799
     800        if ( ! get_post( $id ) ) {
    720801                wp_die( 1 );
    721 
    722         if ( wp_delete_post( $id ) )
     802        }
     803
     804        if ( wp_delete_post( $id ) ) {
    723805                wp_die( 1 );
    724         else
     806        } else {
    725807                wp_die( 0 );
     808        }
    726809}
    727810
     
    734817 */
    735818function wp_ajax_trash_post( $action ) {
    736         if ( empty( $action ) )
     819        if ( empty( $action ) ) {
    737820                $action = 'trash-post';
     821        }
    738822        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    739823
    740824        check_ajax_referer( "{$action}_$id" );
    741         if ( !current_user_can( 'delete_post', $id ) )
     825        if ( ! current_user_can( 'delete_post', $id ) ) {
    742826                wp_die( -1 );
    743 
    744         if ( !get_post( $id ) )
     827        }
     828
     829        if ( ! get_post( $id ) ) {
    745830                wp_die( 1 );
    746 
    747         if ( 'trash-post' == $action )
     831        }
     832
     833        if ( 'trash-post' == $action ) {
    748834                $done = wp_trash_post( $id );
    749         else
     835        } else {
    750836                $done = wp_untrash_post( $id );
    751 
    752         if ( $done )
     837        }
     838
     839        if ( $done ) {
    753840                wp_die( 1 );
     841        }
    754842
    755843        wp_die( 0 );
     
    764852 */
    765853function wp_ajax_untrash_post( $action ) {
    766         if ( empty( $action ) )
     854        if ( empty( $action ) ) {
    767855                $action = 'untrash-post';
     856        }
    768857        wp_ajax_trash_post( $action );
    769858}
     
    775864 */
    776865function wp_ajax_delete_page( $action ) {
    777         if ( empty( $action ) )
     866        if ( empty( $action ) ) {
    778867                $action = 'delete-page';
     868        }
    779869        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    780870
    781871        check_ajax_referer( "{$action}_$id" );
    782         if ( !current_user_can( 'delete_page', $id ) )
     872        if ( ! current_user_can( 'delete_page', $id ) ) {
    783873                wp_die( -1 );
    784 
    785         if ( ! get_post( $id ) )
     874        }
     875
     876        if ( ! get_post( $id ) ) {
    786877                wp_die( 1 );
    787 
    788         if ( wp_delete_post( $id ) )
     878        }
     879
     880        if ( wp_delete_post( $id ) ) {
    789881                wp_die( 1 );
    790         else
     882        } else {
    791883                wp_die( 0 );
     884        }
    792885}
    793886
     
    800893        $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    801894
    802         if ( !$comment = get_comment( $id ) ) {
    803                 $x = new WP_Ajax_Response( array(
    804                         'what' => 'comment',
    805                         'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))
    806                 ) );
     895        if ( ! $comment = get_comment( $id ) ) {
     896                $x = new WP_Ajax_Response(
     897                        array(
     898                                'what' => 'comment',
     899                                'id'   => new WP_Error( 'invalid_comment', sprintf( __( 'Comment %d does not exist' ), $id ) ),
     900                        )
     901                );
    807902                $x->send();
    808903        }
    809904
    810         if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) )
     905        if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) {
    811906                wp_die( -1 );
     907        }
    812908
    813909        $current = wp_get_comment_status( $comment );
    814         if ( isset( $_POST['new'] ) && $_POST['new'] == $current )
     910        if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) {
    815911                wp_die( time() );
     912        }
    816913
    817914        check_ajax_referer( "approve-comment_$id" );
     
    822919        }
    823920
    824         if ( is_wp_error($result) ) {
    825                 $x = new WP_Ajax_Response( array(
    826                         'what' => 'comment',
    827                         'id' => $result
    828                 ) );
     921        if ( is_wp_error( $result ) ) {
     922                $x = new WP_Ajax_Response(
     923                        array(
     924                                'what' => 'comment',
     925                                'id'   => $result,
     926                        )
     927                );
    829928                $x->send();
    830929        }
     
    843942 */
    844943function wp_ajax_add_link_category( $action ) {
    845         if ( empty( $action ) )
     944        if ( empty( $action ) ) {
    846945                $action = 'add-link-category';
     946        }
    847947        check_ajax_referer( $action );
    848948        $tax = get_taxonomy( 'link_category' );
     
    850950                wp_die( -1 );
    851951        }
    852         $names = explode(',', wp_unslash( $_POST['newcat'] ) );
    853         $x = new WP_Ajax_Response();
     952        $names = explode( ',', wp_unslash( $_POST['newcat'] ) );
     953        $x     = new WP_Ajax_Response();
    854954        foreach ( $names as $cat_name ) {
    855                 $cat_name = trim($cat_name);
    856                 $slug = sanitize_title($cat_name);
    857                 if ( '' === $slug )
     955                $cat_name = trim( $cat_name );
     956                $slug     = sanitize_title( $cat_name );
     957                if ( '' === $slug ) {
    858958                        continue;
     959                }
    859960
    860961                $cat_id = wp_insert_term( $cat_name, 'link_category' );
     
    865966                }
    866967                $cat_name = esc_html( $cat_name );
    867                 $x->add( array(
    868                         'what' => 'link-category',
    869                         'id' => $cat_id,
    870                         'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr($cat_id) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>",
    871                         'position' => -1
    872                 ) );
     968                $x->add(
     969                        array(
     970                                'what'     => 'link-category',
     971                                'id'       => $cat_id,
     972                                'data'     => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr( $cat_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>",
     973                                'position' => -1,
     974                        )
     975                );
    873976        }
    874977        $x->send();
     
    882985function wp_ajax_add_tag() {
    883986        check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
    884         $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
    885         $tax = get_taxonomy($taxonomy);
    886 
    887         if ( !current_user_can( $tax->cap->edit_terms ) )
     987        $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
     988        $tax      = get_taxonomy( $taxonomy );
     989
     990        if ( ! current_user_can( $tax->cap->edit_terms ) ) {
    888991                wp_die( -1 );
     992        }
    889993
    890994        $x = new WP_Ajax_Response();
    891995
    892         $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
    893 
    894         if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
    895                 $message = __('An error has occurred. Please reload the page and try again.');
    896                 if ( is_wp_error($tag) && $tag->get_error_message() )
     996        $tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
     997
     998        if ( ! $tag || is_wp_error( $tag ) || ( ! $tag = get_term( $tag['term_id'], $taxonomy ) ) ) {
     999                $message = __( 'An error has occurred. Please reload the page and try again.' );
     1000                if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
    8971001                        $message = $tag->get_error_message();
    898 
    899                 $x->add( array(
    900                         'what' => 'taxonomy',
    901                         'data' => new WP_Error('error', $message )
    902                 ) );
     1002                }
     1003
     1004                $x->add(
     1005                        array(
     1006                                'what' => 'taxonomy',
     1007                                'data' => new WP_Error( 'error', $message ),
     1008                        )
     1009                );
    9031010                $x->send();
    9041011        }
     
    9071014
    9081015        $level = 0;
    909         if ( is_taxonomy_hierarchical($taxonomy) ) {
     1016        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    9101017                $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
    9111018                ob_start();
     
    9181025        $parents = ob_get_clean();
    9191026
    920         $x->add( array(
    921                 'what' => 'taxonomy',
    922                 'supplemental' => compact('parents', 'noparents')
    923         ) );
    924         $x->add( array(
    925                 'what' => 'term',
    926                 'position' => $level,
    927                 'supplemental' => (array) $tag
    928         ) );
     1027        $x->add(
     1028                array(
     1029                        'what'         => 'taxonomy',
     1030                        'supplemental' => compact( 'parents', 'noparents' ),
     1031                )
     1032        );
     1033        $x->add(
     1034                array(
     1035                        'what'         => 'term',
     1036                        'position'     => $level,
     1037                        'supplemental' => (array) $tag,
     1038                )
     1039        );
    9291040        $x->send();
    9301041}
     
    9411052
    9421053        $taxonomy = sanitize_key( $_POST['tax'] );
    943         $tax = get_taxonomy( $taxonomy );
     1054        $tax      = get_taxonomy( $taxonomy );
    9441055        if ( ! $tax ) {
    9451056                wp_die( 0 );
     
    9501061        }
    9511062
    952         $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
    953 
    954         if ( empty( $tags ) )
     1063        $tags = get_terms(
     1064                $taxonomy, array(
     1065                        'number'  => 45,
     1066                        'orderby' => 'count',
     1067                        'order'   => 'DESC',
     1068                )
     1069        );
     1070
     1071        if ( empty( $tags ) ) {
    9551072                wp_die( $tax->labels->not_found );
    956 
    957         if ( is_wp_error( $tags ) )
     1073        }
     1074
     1075        if ( is_wp_error( $tags ) ) {
    9581076                wp_die( $tags->get_error_message() );
     1077        }
    9591078
    9601079        foreach ( $tags as $key => $tag ) {
    9611080                $tags[ $key ]->link = '#';
    962                 $tags[ $key ]->id = $tag->term_id;
     1081                $tags[ $key ]->id   = $tag->term_id;
    9631082        }
    9641083
    9651084        // We need raw tag names here, so don't filter the output
    966         $return = wp_generate_tag_cloud( $tags, array( 'filter' => 0, 'format' => 'list' ) );
    967 
    968         if ( empty($return) )
     1085        $return = wp_generate_tag_cloud(
     1086                $tags, array(
     1087                        'filter' => 0,
     1088                        'format' => 'list',
     1089                )
     1090        );
     1091
     1092        if ( empty( $return ) ) {
    9691093                wp_die( 0 );
     1094        }
    9701095
    9711096        echo $return;
     
    10161141        ob_start();
    10171142        foreach ( $wp_list_table->items as $comment ) {
    1018                 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved )
     1143                if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) {
    10191144                        continue;
     1145                }
    10201146                get_comment( $comment );
    10211147                $wp_list_table->single_row( $comment );
     
    10231149        $comment_list_item = ob_get_clean();
    10241150
    1025         $x->add( array(
    1026                 'what' => 'comments',
    1027                 'data' => $comment_list_item
    1028         ) );
     1151        $x->add(
     1152                array(
     1153                        'what' => 'comments',
     1154                        'data' => $comment_list_item,
     1155                )
     1156        );
    10291157        $x->send();
    10301158}
     
    10381166 */
    10391167function wp_ajax_replyto_comment( $action ) {
    1040         if ( empty( $action ) )
     1168        if ( empty( $action ) ) {
    10411169                $action = 'replyto-comment';
     1170        }
    10421171
    10431172        check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
    10441173
    10451174        $comment_post_ID = (int) $_POST['comment_post_ID'];
    1046         $post = get_post( $comment_post_ID );
    1047         if ( ! $post )
     1175        $post            = get_post( $comment_post_ID );
     1176        if ( ! $post ) {
    10481177                wp_die( -1 );
    1049 
    1050         if ( !current_user_can( 'edit_post', $comment_post_ID ) )
     1178        }
     1179
     1180        if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) {
    10511181                wp_die( -1 );
    1052 
    1053         if ( empty( $post->post_status ) )
     1182        }
     1183
     1184        if ( empty( $post->post_status ) ) {
    10541185                wp_die( 1 );
    1055         elseif ( in_array($post->post_status, array('draft', 'pending', 'trash') ) )
    1056                 wp_die( __('ERROR: you are replying to a comment on a draft post.') );
     1186        } elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ) ) ) {
     1187                wp_die( __( 'ERROR: you are replying to a comment on a draft post.' ) );
     1188        }
    10571189
    10581190        $user = wp_get_current_user();
    10591191        if ( $user->exists() ) {
    1060                 $user_ID = $user->ID;
     1192                $user_ID              = $user->ID;
    10611193                $comment_author       = wp_slash( $user->display_name );
    10621194                $comment_author_email = wp_slash( $user->user_email );
     
    10651197                $comment_type         = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
    10661198                if ( current_user_can( 'unfiltered_html' ) ) {
    1067                         if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) )
     1199                        if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) {
    10681200                                $_POST['_wp_unfiltered_html_comment'] = '';
     1201                        }
    10691202
    10701203                        if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
     
    10771210        }
    10781211
    1079         if ( '' == $comment_content )
     1212        if ( '' == $comment_content ) {
    10801213                wp_die( __( 'ERROR: please type a comment.' ) );
     1214        }
    10811215
    10821216        $comment_parent = 0;
    1083         if ( isset( $_POST['comment_ID'] ) )
     1217        if ( isset( $_POST['comment_ID'] ) ) {
    10841218                $comment_parent = absint( $_POST['comment_ID'] );
     1219        }
    10851220        $comment_auto_approved = false;
    1086         $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
     1221        $commentdata           = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' );
    10871222
    10881223        // Automatically approve parent comment.
    1089         if ( !empty($_POST['approve_parent']) ) {
     1224        if ( ! empty( $_POST['approve_parent'] ) ) {
    10901225                $parent = get_comment( $comment_parent );
    10911226
     
    10951230                        }
    10961231
    1097                         if ( wp_set_comment_status( $parent, 'approve' ) )
     1232                        if ( wp_set_comment_status( $parent, 'approve' ) ) {
    10981233                                $comment_auto_approved = true;
     1234                        }
    10991235                }
    11001236        }
     
    11061242        }
    11071243
    1108         $comment = get_comment($comment_id);
    1109         if ( ! $comment ) wp_die( 1 );
    1110 
    1111         $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
     1244        $comment = get_comment( $comment_id );
     1245        if ( ! $comment ) {
     1246                wp_die( 1 );
     1247        }
     1248
     1249        $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
    11121250
    11131251        ob_start();
     
    11171255        } else {
    11181256                if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
    1119                         $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     1257                        $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    11201258                } else {
    1121                         $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
     1259                        $wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    11221260                }
    11231261                $wp_list_table->single_row( $comment );
     
    11251263        $comment_list_item = ob_get_clean();
    11261264
    1127         $response =  array(
    1128                 'what' => 'comment',
    1129                 'id' => $comment->comment_ID,
    1130                 'data' => $comment_list_item,
    1131                 'position' => $position
     1265        $response = array(
     1266                'what'     => 'comment',
     1267                'id'       => $comment->comment_ID,
     1268                'data'     => $comment_list_item,
     1269                'position' => $position,
    11321270        );
    11331271
    1134         $counts = wp_count_comments();
     1272        $counts                   = wp_count_comments();
    11351273        $response['supplemental'] = array(
    1136                 'in_moderation' => $counts->moderated,
    1137                 'i18n_comments_text' => sprintf(
     1274                'in_moderation'        => $counts->moderated,
     1275                'i18n_comments_text'   => sprintf(
    11381276                        _n( '%s Comment', '%s Comments', $counts->approved ),
    11391277                        number_format_i18n( $counts->approved )
     
    11421280                        _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
    11431281                        number_format_i18n( $counts->moderated )
    1144                 )
     1282                ),
    11451283        );
    11461284
    11471285        if ( $comment_auto_approved ) {
    11481286                $response['supplemental']['parent_approved'] = $parent->comment_ID;
    1149                 $response['supplemental']['parent_post_id'] = $parent->comment_post_ID;
     1287                $response['supplemental']['parent_post_id']  = $parent->comment_post_ID;
    11501288        }
    11511289
     
    11641302
    11651303        $comment_id = (int) $_POST['comment_ID'];
    1166         if ( ! current_user_can( 'edit_comment', $comment_id ) )
     1304        if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    11671305                wp_die( -1 );
    1168 
    1169         if ( '' == $_POST['content'] )
     1306        }
     1307
     1308        if ( '' == $_POST['content'] ) {
    11701309                wp_die( __( 'ERROR: please type a comment.' ) );
    1171 
    1172         if ( isset( $_POST['status'] ) )
     1310        }
     1311
     1312        if ( isset( $_POST['status'] ) ) {
    11731313                $_POST['comment_status'] = $_POST['status'];
     1314        }
    11741315        edit_comment();
    11751316
    1176         $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    1177         $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
     1317        $position      = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
     1318        $checkbox      = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0;
    11781319        $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    11791320
    11801321        $comment = get_comment( $comment_id );
    1181         if ( empty( $comment->comment_ID ) )
     1322        if ( empty( $comment->comment_ID ) ) {
    11821323                wp_die( -1 );
     1324        }
    11831325
    11841326        ob_start();
     
    11881330        $x = new WP_Ajax_Response();
    11891331
    1190         $x->add( array(
    1191                 'what' => 'edit_comment',
    1192                 'id' => $comment->comment_ID,
    1193                 'data' => $comment_list_item,
    1194                 'position' => $position
    1195         ));
     1332        $x->add(
     1333                array(
     1334                        'what'     => 'edit_comment',
     1335                        'id'       => $comment->comment_ID,
     1336                        'data'     => $comment_list_item,
     1337                        'position' => $position,
     1338                )
     1339        );
    11961340
    11971341        $x->send();
     
    12061350        check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    12071351
    1208         if ( ! current_user_can( 'edit_theme_options' ) )
     1352        if ( ! current_user_can( 'edit_theme_options' ) ) {
    12091353                wp_die( -1 );
     1354        }
    12101355
    12111356        require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     
    12211366                        ! empty( $menu_item_data['menu-item-object-id'] )
    12221367                ) {
    1223                         switch( $menu_item_data['menu-item-type'] ) {
    1224                                 case 'post_type' :
     1368                        switch ( $menu_item_data['menu-item-type'] ) {
     1369                                case 'post_type':
    12251370                                        $_object = get_post( $menu_item_data['menu-item-object-id'] );
    1226                                 break;
    1227 
    1228                                 case 'post_type_archive' :
     1371                                        break;
     1372
     1373                                case 'post_type_archive':
    12291374                                        $_object = get_post_type_object( $menu_item_data['menu-item-object'] );
    1230                                 break;
    1231 
    1232                                 case 'taxonomy' :
     1375                                        break;
     1376
     1377                                case 'taxonomy':
    12331378                                        $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
    1234                                 break;
     1379                                        break;
    12351380                        }
    12361381
    12371382                        $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
    1238                         $_menu_item = reset( $_menu_items );
     1383                        $_menu_item  = reset( $_menu_items );
    12391384
    12401385                        // Restore the missing menu item properties
     
    12461391
    12471392        $item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
    1248         if ( is_wp_error( $item_ids ) )
     1393        if ( is_wp_error( $item_ids ) ) {
    12491394                wp_die( 0 );
     1395        }
    12501396
    12511397        $menu_items = array();
     
    12541400                $menu_obj = get_post( $menu_item_id );
    12551401                if ( ! empty( $menu_obj->ID ) ) {
    1256                         $menu_obj = wp_setup_nav_menu_item( $menu_obj );
     1402                        $menu_obj        = wp_setup_nav_menu_item( $menu_obj );
    12571403                        $menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
    1258                         $menu_items[] = $menu_obj;
     1404                        $menu_items[]    = $menu_obj;
    12591405                }
    12601406        }
     
    12631409        $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] );
    12641410
    1265         if ( ! class_exists( $walker_class_name ) )
     1411        if ( ! class_exists( $walker_class_name ) ) {
    12661412                wp_die( 0 );
     1413        }
    12671414
    12681415        if ( ! empty( $menu_items ) ) {
    12691416                $args = array(
    1270                         'after' => '',
    1271                         'before' => '',
    1272                         'link_after' => '',
     1417                        'after'       => '',
     1418                        'before'      => '',
     1419                        'link_after'  => '',
    12731420                        'link_before' => '',
    1274                         'walker' => new $walker_class_name,
     1421                        'walker'      => new $walker_class_name,
    12751422                );
    12761423                echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
     
    12861433function wp_ajax_add_meta() {
    12871434        check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
    1288         $c = 0;
    1289         $pid = (int) $_POST['post_id'];
     1435        $c    = 0;
     1436        $pid  = (int) $_POST['post_id'];
    12901437        $post = get_post( $pid );
    12911438
    1292         if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
    1293                 if ( !current_user_can( 'edit_post', $pid ) )
     1439        if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) {
     1440                if ( ! current_user_can( 'edit_post', $pid ) ) {
    12941441                        wp_die( -1 );
    1295                 if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
     1442                }
     1443                if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
    12961444                        wp_die( 1 );
     1445                }
    12971446
    12981447                // If the post is an autodraft, save the post as a draft and then attempt to save the meta.
    12991448                if ( $post->post_status == 'auto-draft' ) {
    1300                         $post_data = array();
    1301                         $post_data['action'] = 'draft'; // Warning fix
    1302                         $post_data['post_ID'] = $pid;
    1303                         $post_data['post_type'] = $post->post_type;
     1449                        $post_data                = array();
     1450                        $post_data['action']      = 'draft'; // Warning fix
     1451                        $post_data['post_ID']     = $pid;
     1452                        $post_data['post_type']   = $post->post_type;
    13041453                        $post_data['post_status'] = 'draft';
    1305                         $now = current_time('timestamp', 1);
     1454                        $now                      = current_time( 'timestamp', 1 );
    13061455                        /* translators: 1: Post creation date, 2: Post creation time */
    13071456                        $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) );
     
    13101459                        if ( $pid ) {
    13111460                                if ( is_wp_error( $pid ) ) {
    1312                                         $x = new WP_Ajax_Response( array(
    1313                                                 'what' => 'meta',
    1314                                                 'data' => $pid
    1315                                         ) );
     1461                                        $x = new WP_Ajax_Response(
     1462                                                array(
     1463                                                        'what' => 'meta',
     1464                                                        'data' => $pid,
     1465                                                )
     1466                                        );
    13161467                                        $x->send();
    13171468                                }
    13181469
    1319                                 if ( !$mid = add_meta( $pid ) )
     1470                                if ( ! $mid = add_meta( $pid ) ) {
    13201471                                        wp_die( __( 'Please provide a custom field value.' ) );
     1472                                }
    13211473                        } else {
    13221474                                wp_die( 0 );
     
    13271479
    13281480                $meta = get_metadata_by_mid( 'post', $mid );
    1329                 $pid = (int) $meta->post_id;
     1481                $pid  = (int) $meta->post_id;
    13301482                $meta = get_object_vars( $meta );
    1331                 $x = new WP_Ajax_Response( array(
    1332                         'what' => 'meta',
    1333                         'id' => $mid,
    1334                         'data' => _list_meta_row( $meta, $c ),
    1335                         'position' => 1,
    1336                         'supplemental' => array('postid' => $pid)
    1337                 ) );
     1483                $x    = new WP_Ajax_Response(
     1484                        array(
     1485                                'what'         => 'meta',
     1486                                'id'           => $mid,
     1487                                'data'         => _list_meta_row( $meta, $c ),
     1488                                'position'     => 1,
     1489                                'supplemental' => array( 'postid' => $pid ),
     1490                        )
     1491                );
    13381492        } else { // Update?
    1339                 $mid = (int) key( $_POST['meta'] );
    1340                 $key = wp_unslash( $_POST['meta'][$mid]['key'] );
    1341                 $value = wp_unslash( $_POST['meta'][$mid]['value'] );
    1342                 if ( '' == trim($key) )
     1493                $mid   = (int) key( $_POST['meta'] );
     1494                $key   = wp_unslash( $_POST['meta'][ $mid ]['key'] );
     1495                $value = wp_unslash( $_POST['meta'][ $mid ]['value'] );
     1496                if ( '' == trim( $key ) ) {
    13431497                        wp_die( __( 'Please provide a custom field name.' ) );
    1344                 if ( '' == trim($value) )
     1498                }
     1499                if ( '' == trim( $value ) ) {
    13451500                        wp_die( __( 'Please provide a custom field value.' ) );
    1346                 if ( ! $meta = get_metadata_by_mid( 'post', $mid ) )
     1501                }
     1502                if ( ! $meta = get_metadata_by_mid( 'post', $mid ) ) {
    13471503                        wp_die( 0 ); // if meta doesn't exist
     1504                }
    13481505                if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
    13491506                        ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) ||
    1350                         ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) )
     1507                        ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) ) {
    13511508                        wp_die( -1 );
     1509                }
    13521510                if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
    1353                         if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) )
     1511                        if ( ! $u = update_metadata_by_mid( 'post', $mid, $value, $key ) ) {
    13541512                                wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
    1355                 }
    1356 
    1357                 $x = new WP_Ajax_Response( array(
    1358                         'what' => 'meta',
    1359                         'id' => $mid, 'old_id' => $mid,
    1360                         'data' => _list_meta_row( array(
    1361                                 'meta_key' => $key,
    1362                                 'meta_value' => $value,
    1363                                 'meta_id' => $mid
    1364                         ), $c ),
    1365                         'position' => 0,
    1366                         'supplemental' => array('postid' => $meta->post_id)
    1367                 ) );
     1513                        }
     1514                }
     1515
     1516                $x = new WP_Ajax_Response(
     1517                        array(
     1518                                'what'         => 'meta',
     1519                                'id'           => $mid,
     1520                                'old_id'       => $mid,
     1521                                'data'         => _list_meta_row(
     1522                                        array(
     1523                                                'meta_key'   => $key,
     1524                                                'meta_value' => $value,
     1525                                                'meta_id'    => $mid,
     1526                                        ), $c
     1527                                ),
     1528                                'position'     => 0,
     1529                                'supplemental' => array( 'postid' => $meta->post_id ),
     1530                        )
     1531                );
    13681532        }
    13691533        $x->send();
     
    13831547
    13841548        check_ajax_referer( $action );
    1385         if ( ! current_user_can('create_users') )
     1549        if ( ! current_user_can( 'create_users' ) ) {
    13861550                wp_die( -1 );
     1551        }
    13871552        if ( ! $user_id = edit_user() ) {
    13881553                wp_die( 0 );
    13891554        } elseif ( is_wp_error( $user_id ) ) {
    1390                 $x = new WP_Ajax_Response( array(
    1391                         'what' => 'user',
    1392                         'id' => $user_id
    1393                 ) );
     1555                $x = new WP_Ajax_Response(
     1556                        array(
     1557                                'what' => 'user',
     1558                                'id'   => $user_id,
     1559                        )
     1560                );
    13941561                $x->send();
    13951562        }
    13961563        $user_object = get_userdata( $user_id );
    13971564
    1398         $wp_list_table = _get_list_table('WP_Users_List_Table');
     1565        $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
    13991566
    14001567        $role = current( $user_object->roles );
    14011568
    1402         $x = new WP_Ajax_Response( array(
    1403                 'what' => 'user',
    1404                 'id' => $user_id,
    1405                 'data' => $wp_list_table->single_row( $user_object, '', $role ),
    1406                 'supplemental' => array(
    1407                         'show-link' => sprintf(
    1408                                 /* translators: %s: the new user */
    1409                                 __( 'User %s added' ),
    1410                                 '<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
     1569        $x = new WP_Ajax_Response(
     1570                array(
     1571                        'what'         => 'user',
     1572                        'id'           => $user_id,
     1573                        'data'         => $wp_list_table->single_row( $user_object, '', $role ),
     1574                        'supplemental' => array(
     1575                                'show-link' => sprintf(
     1576                                        /* translators: %s: the new user */
     1577                                        __( 'User %s added' ),
     1578                                        '<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
     1579                                ),
     1580                                'role'      => $role,
    14111581                        ),
    1412                         'role' => $role,
    14131582                )
    1414         ) );
     1583        );
    14151584        $x->send();
    14161585}
     
    14231592function wp_ajax_closed_postboxes() {
    14241593        check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
    1425         $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed']) : array();
    1426         $closed = array_filter($closed);
    1427 
    1428         $hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden']) : array();
    1429         $hidden = array_filter($hidden);
     1594        $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed'] ) : array();
     1595        $closed = array_filter( $closed );
     1596
     1597        $hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
     1598        $hidden = array_filter( $hidden );
    14301599
    14311600        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    14321601
    1433         if ( $page != sanitize_key( $page ) )
     1602        if ( $page != sanitize_key( $page ) ) {
    14341603                wp_die( 0 );
    1435 
    1436         if ( ! $user = wp_get_current_user() )
     1604        }
     1605
     1606        if ( ! $user = wp_get_current_user() ) {
    14371607                wp_die( -1 );
    1438 
    1439         if ( is_array($closed) )
    1440                 update_user_option($user->ID, "closedpostboxes_$page", $closed, true);
    1441 
    1442         if ( is_array($hidden) ) {
    1443                 $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu') ); // postboxes that are always shown
    1444                 update_user_option($user->ID, "metaboxhidden_$page", $hidden, true);
     1608        }
     1609
     1610        if ( is_array( $closed ) ) {
     1611                update_user_option( $user->ID, "closedpostboxes_$page", $closed, true );
     1612        }
     1613
     1614        if ( is_array( $hidden ) ) {
     1615                $hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); // postboxes that are always shown
     1616                update_user_option( $user->ID, "metaboxhidden_$page", $hidden, true );
    14451617        }
    14461618
     
    14571629        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    14581630
    1459         if ( $page != sanitize_key( $page ) )
     1631        if ( $page != sanitize_key( $page ) ) {
    14601632                wp_die( 0 );
    1461 
    1462         if ( ! $user = wp_get_current_user() )
     1633        }
     1634
     1635        if ( ! $user = wp_get_current_user() ) {
    14631636                wp_die( -1 );
     1637        }
    14641638
    14651639        $hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
     
    14771651        check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
    14781652
    1479         if ( ! current_user_can( 'edit_theme_options' ) )
     1653        if ( ! current_user_can( 'edit_theme_options' ) ) {
    14801654                wp_die( -1 );
     1655        }
    14811656
    14821657        update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 );
     
    14911666 */
    14921667function wp_ajax_menu_get_metabox() {
    1493         if ( ! current_user_can( 'edit_theme_options' ) )
     1668        if ( ! current_user_can( 'edit_theme_options' ) ) {
    14941669                wp_die( -1 );
     1670        }
    14951671
    14961672        require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    14971673
    14981674        if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
    1499                 $type = 'posttype';
     1675                $type     = 'posttype';
    15001676                $callback = 'wp_nav_menu_item_post_type_meta_box';
    1501                 $items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
     1677                $items    = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
    15021678        } elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
    1503                 $type = 'taxonomy';
     1679                $type     = 'taxonomy';
    15041680                $callback = 'wp_nav_menu_item_taxonomy_meta_box';
    1505                 $items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
    1506         }
    1507 
    1508         if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) {
     1681                $items    = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
     1682        }
     1683
     1684        if ( ! empty( $_POST['item-object'] ) && isset( $items[ $_POST['item-object'] ] ) ) {
    15091685                $menus_meta_box_object = $items[ $_POST['item-object'] ];
    15101686
     
    15121688                $item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
    15131689                ob_start();
    1514                 call_user_func_array($callback, array(
    1515                         null,
     1690                call_user_func_array(
     1691                        $callback, array(
     1692                                null,
     1693                                array(
     1694                                        'id'       => 'add-' . $item->name,
     1695                                        'title'    => $item->labels->name,
     1696                                        'callback' => $callback,
     1697                                        'args'     => $item,
     1698                                ),
     1699                        )
     1700                );
     1701
     1702                $markup = ob_get_clean();
     1703
     1704                echo wp_json_encode(
    15161705                        array(
    1517                                 'id' => 'add-' . $item->name,
    1518                                 'title' => $item->labels->name,
    1519                                 'callback' => $callback,
    1520                                 'args' => $item,
     1706                                'replace-id' => $type . '-' . $item->name,
     1707                                'markup'     => $markup,
    15211708                        )
    1522                 ));
    1523 
    1524                 $markup = ob_get_clean();
    1525 
    1526                 echo wp_json_encode(array(
    1527                         'replace-id' => $type . '-' . $item->name,
    1528                         'markup' => $markup,
    1529                 ));
     1709                );
    15301710        }
    15311711
     
    15591739        $results = _WP_Editors::wp_link_query( $args );
    15601740
    1561         if ( ! isset( $results ) )
     1741        if ( ! isset( $results ) ) {
    15621742                wp_die( 0 );
     1743        }
    15631744
    15641745        echo wp_json_encode( $results );
     
    15741755 */
    15751756function wp_ajax_menu_locations_save() {
    1576         if ( ! current_user_can( 'edit_theme_options' ) )
     1757        if ( ! current_user_can( 'edit_theme_options' ) ) {
    15771758                wp_die( -1 );
     1759        }
    15781760        check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    1579         if ( ! isset( $_POST['menu-locations'] ) )
     1761        if ( ! isset( $_POST['menu-locations'] ) ) {
    15801762                wp_die( 0 );
     1763        }
    15811764        set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
    15821765        wp_die( 1 );
     
    15901773function wp_ajax_meta_box_order() {
    15911774        check_ajax_referer( 'meta-box-order' );
    1592         $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
     1775        $order        = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
    15931776        $page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
    15941777
    1595         if ( $page_columns != 'auto' )
     1778        if ( $page_columns != 'auto' ) {
    15961779                $page_columns = (int) $page_columns;
     1780        }
    15971781
    15981782        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    15991783
    1600         if ( $page != sanitize_key( $page ) )
     1784        if ( $page != sanitize_key( $page ) ) {
    16011785                wp_die( 0 );
    1602 
    1603         if ( ! $user = wp_get_current_user() )
     1786        }
     1787
     1788        if ( ! $user = wp_get_current_user() ) {
    16041789                wp_die( -1 );
    1605 
    1606         if ( $order )
    1607                 update_user_option($user->ID, "meta-box-order_$page", $order, true);
    1608 
    1609         if ( $page_columns )
    1610                 update_user_option($user->ID, "screen_layout_$page", $page_columns, true);
     1790        }
     1791
     1792        if ( $order ) {
     1793                update_user_option( $user->ID, "meta-box-order_$page", $order, true );
     1794        }
     1795
     1796        if ( $page_columns ) {
     1797                update_user_option( $user->ID, "screen_layout_$page", $page_columns, true );
     1798        }
    16111799
    16121800        wp_die( 1 );
     
    16191807 */
    16201808function wp_ajax_menu_quick_search() {
    1621         if ( ! current_user_can( 'edit_theme_options' ) )
     1809        if ( ! current_user_can( 'edit_theme_options' ) ) {
    16221810                wp_die( -1 );
     1811        }
    16231812
    16241813        require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     
    16361825function wp_ajax_get_permalink() {
    16371826        check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
    1638         $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
     1827        $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
    16391828        wp_die( get_preview_post_link( $post_id ) );
    16401829}
     
    16471836function wp_ajax_sample_permalink() {
    16481837        check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    1649         $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    1650         $title = isset($_POST['new_title'])? $_POST['new_title'] : '';
    1651         $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null;
     1838        $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
     1839        $title   = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
     1840        $slug    = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
    16521841        wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
    16531842}
     
    16651854        check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
    16661855
    1667         if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
     1856        if ( ! isset( $_POST['post_ID'] ) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) {
    16681857                wp_die();
     1858        }
    16691859
    16701860        if ( 'page' == $_POST['post_type'] ) {
    1671                 if ( ! current_user_can( 'edit_page', $post_ID ) )
     1861                if ( ! current_user_can( 'edit_page', $post_ID ) ) {
    16721862                        wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
     1863                }
    16731864        } else {
    1674                 if ( ! current_user_can( 'edit_post', $post_ID ) )
     1865                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    16751866                        wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
     1867                }
    16761868        }
    16771869
    16781870        if ( $last = wp_check_post_lock( $post_ID ) ) {
    1679                 $last_user = get_userdata( $last );
     1871                $last_user      = get_userdata( $last );
    16801872                $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
    1681                 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 ) );
     1873                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 ) );
    16821874                wp_die();
    16831875        }
     
    16881880
    16891881        // Since it's coming from the database.
    1690         $post = wp_slash($post);
     1882        $post = wp_slash( $post );
    16911883
    16921884        $data['content'] = $post['post_content'];
     
    16961888        $data['user_ID'] = get_current_user_id();
    16971889
    1698         if ( isset($data['post_parent']) )
     1890        if ( isset( $data['post_parent'] ) ) {
    16991891                $data['parent_id'] = $data['post_parent'];
     1892        }
    17001893
    17011894        // Status.
     
    17071900        }
    17081901
    1709         if ( empty($data['comment_status']) )
     1902        if ( empty( $data['comment_status'] ) ) {
    17101903                $data['comment_status'] = 'closed';
    1711         if ( empty($data['ping_status']) )
     1904        }
     1905        if ( empty( $data['ping_status'] ) ) {
    17121906                $data['ping_status'] = 'closed';
     1907        }
    17131908
    17141909        // Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
     
    17261921        if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) {
    17271922                $post['post_status'] = 'publish';
    1728                 $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
     1923                $data['post_name']   = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
    17291924        }
    17301925
     
    17621957
    17631958        $taxonomy = sanitize_key( $_POST['taxonomy'] );
    1764         $tax = get_taxonomy( $taxonomy );
    1765         if ( ! $tax )
     1959        $tax      = get_taxonomy( $taxonomy );
     1960        if ( ! $tax ) {
    17661961                wp_die( 0 );
     1962        }
    17671963
    17681964        if ( ! isset( $_POST['tax_ID'] ) || ! ( $id = (int) $_POST['tax_ID'] ) ) {
     
    17761972        $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );
    17771973
    1778         $tag = get_term( $id, $taxonomy );
     1974        $tag                  = get_term( $id, $taxonomy );
    17791975        $_POST['description'] = $tag->description;
    17801976
    1781         $updated = wp_update_term($id, $taxonomy, $_POST);
    1782         if ( $updated && !is_wp_error($updated) ) {
     1977        $updated = wp_update_term( $id, $taxonomy, $_POST );
     1978        if ( $updated && ! is_wp_error( $updated ) ) {
    17831979                $tag = get_term( $updated['term_id'], $taxonomy );
    1784                 if ( !$tag || is_wp_error( $tag ) ) {
    1785                         if ( is_wp_error($tag) && $tag->get_error_message() )
     1980                if ( ! $tag || is_wp_error( $tag ) ) {
     1981                        if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
    17861982                                wp_die( $tag->get_error_message() );
     1983                        }
    17871984                        wp_die( __( 'Item not updated.' ) );
    17881985                }
    17891986        } else {
    1790                 if ( is_wp_error($updated) && $updated->get_error_message() )
     1987                if ( is_wp_error( $updated ) && $updated->get_error_message() ) {
    17911988                        wp_die( $updated->get_error_message() );
     1989                }
    17921990                wp_die( __( 'Item not updated.' ) );
    17931991        }
    1794         $level = 0;
     1992        $level  = 0;
    17951993        $parent = $tag->parent;
    17961994        while ( $parent > 0 ) {
    17971995                $parent_tag = get_term( $parent, $taxonomy );
    1798                 $parent = $parent_tag->parent;
     1996                $parent     = $parent_tag->parent;
    17991997                $level++;
    18001998        }
     
    18162014        unset( $post_types['attachment'] );
    18172015
    1818         $s = wp_unslash( $_POST['ps'] );
     2016        $s    = wp_unslash( $_POST['ps'] );
    18192017        $args = array(
    1820                 'post_type' => array_keys( $post_types ),
    1821                 'post_status' => 'any',
     2018                'post_type'      => array_keys( $post_types ),
     2019                'post_status'    => 'any',
    18222020                'posts_per_page' => 50,
    18232021        );
    1824         if ( '' !== $s )
     2022        if ( '' !== $s ) {
    18252023                $args['s'] = $s;
     2024        }
    18262025
    18272026        $posts = get_posts( $args );
     
    18312030        }
    18322031
    1833         $html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>';
    1834         $alt = '';
     2032        $html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>' . __( 'Title' ) . '</th><th class="no-break">' . __( 'Type' ) . '</th><th class="no-break">' . __( 'Date' ) . '</th><th class="no-break">' . __( 'Status' ) . '</th></tr></thead><tbody>';
     2033        $alt  = '';
    18352034        foreach ( $posts as $post ) {
    18362035                $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
    1837                 $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
     2036                $alt   = ( 'alternate' == $alt ) ? '' : 'alternate';
    18382037
    18392038                switch ( $post->post_status ) {
    1840                         case 'publish' :
    1841                         case 'private' :
    1842                                 $stat = __('Published');
     2039                        case 'publish':
     2040                        case 'private':
     2041                                $stat = __( 'Published' );
    18432042                                break;
    1844                         case 'future' :
    1845                                 $stat = __('Scheduled');
     2043                        case 'future':
     2044                                $stat = __( 'Scheduled' );
    18462045                                break;
    1847                         case 'pending' :
    1848                                 $stat = __('Pending Review');
     2046                        case 'pending':
     2047                                $stat = __( 'Pending Review' );
    18492048                                break;
    1850                         case 'draft' :
    1851                                 $stat = __('Draft');
     2049                        case 'draft':
     2050                                $stat = __( 'Draft' );
    18522051                                break;
    18532052                }
     
    18572056                } else {
    18582057                        /* translators: date format in table columns, see https://secure.php.net/date */
    1859                         $time = mysql2date(__('Y/m/d'), $post->post_date);
    1860                 }
    1861 
    1862                 $html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
    1863                 $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n";
     2058                        $time = mysql2date( __( 'Y/m/d' ), $post->post_date );
     2059                }
     2060
     2061                $html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-' . $post->ID . '" name="found_post_id" value="' . esc_attr( $post->ID ) . '"></td>';
     2062                $html .= '<td><label for="found-' . $post->ID . '">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[ $post->post_type ]->labels->singular_name ) . '</td><td class="no-break">' . esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ) . ' </td></tr>' . "\n\n";
    18642063        }
    18652064
     
    18772076        check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    18782077
    1879         if ( !current_user_can('edit_theme_options') )
     2078        if ( ! current_user_can( 'edit_theme_options' ) ) {
    18802079                wp_die( -1 );
     2080        }
    18812081
    18822082        unset( $_POST['savewidgets'], $_POST['action'] );
    18832083
    18842084        // Save widgets order for all sidebars.
    1885         if ( is_array($_POST['sidebars']) ) {
     2085        if ( is_array( $_POST['sidebars'] ) ) {
    18862086                $sidebars = array();
    18872087                foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
    18882088                        $sb = array();
    1889                         if ( !empty($val) ) {
    1890                                 $val = explode(',', $val);
     2089                        if ( ! empty( $val ) ) {
     2090                                $val = explode( ',', $val );
    18912091                                foreach ( $val as $k => $v ) {
    1892                                         if ( strpos($v, 'widget-') === false )
     2092                                        if ( strpos( $v, 'widget-' ) === false ) {
    18932093                                                continue;
    1894 
    1895                                         $sb[$k] = substr($v, strpos($v, '_') + 1);
     2094                                        }
     2095
     2096                                        $sb[ $k ] = substr( $v, strpos( $v, '_' ) + 1 );
    18962097                                }
    18972098                        }
    1898                         $sidebars[$key] = $sb;
    1899                 }
    1900                 wp_set_sidebars_widgets($sidebars);
     2099                        $sidebars[ $key ] = $sb;
     2100                }
     2101                wp_set_sidebars_widgets( $sidebars );
    19012102                wp_die( 1 );
    19022103        }
     
    19192120        check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    19202121
    1921         if ( !current_user_can('edit_theme_options') || !isset($_POST['id_base']) )
     2122        if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['id_base'] ) ) {
    19222123                wp_die( -1 );
     2124        }
    19232125
    19242126        unset( $_POST['savewidgets'], $_POST['action'] );
     
    19412143        do_action( 'sidebar_admin_setup' );
    19422144
    1943         $id_base = wp_unslash( $_POST['id_base'] );
    1944         $widget_id = wp_unslash( $_POST['widget-id'] );
    1945         $sidebar_id = $_POST['sidebar'];
    1946         $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
    1947         $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
    1948         $error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>';
     2145        $id_base      = wp_unslash( $_POST['id_base'] );
     2146        $widget_id    = wp_unslash( $_POST['widget-id'] );
     2147        $sidebar_id   = $_POST['sidebar'];
     2148        $multi_number = ! empty( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : 0;
     2149        $settings     = isset( $_POST[ 'widget-' . $id_base ] ) && is_array( $_POST[ 'widget-' . $id_base ] ) ? $_POST[ 'widget-' . $id_base ] : false;
     2150        $error        = '<p>' . __( 'An error has occurred. Please reload the page and try again.' ) . '</p>';
    19492151
    19502152        $sidebars = wp_get_sidebars_widgets();
    1951         $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
     2153        $sidebar  = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array();
    19522154
    19532155        // Delete.
    1954         if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
    1955 
    1956                 if ( !isset($wp_registered_widgets[$widget_id]) )
     2156        if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
     2157
     2158                if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) {
    19572159                        wp_die( $error );
    1958 
    1959                 $sidebar = array_diff( $sidebar, array($widget_id) );
    1960                 $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
     2160                }
     2161
     2162                $sidebar = array_diff( $sidebar, array( $widget_id ) );
     2163                $_POST   = array(
     2164                        'sidebar'            => $sidebar_id,
     2165                        'widget-' . $id_base => array(),
     2166                        'the-widget-id'      => $widget_id,
     2167                        'delete_widget'      => '1',
     2168                );
    19612169
    19622170                /** This action is documented in wp-admin/widgets.php */
    19632171                do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base );
    19642172
    1965         } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
    1966                 if ( !$multi_number )
     2173        } elseif ( $settings && preg_match( '/__i__|%i%/', key( $settings ) ) ) {
     2174                if ( ! $multi_number ) {
    19672175                        wp_die( $error );
     2176                }
    19682177
    19692178                $_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) );
    1970                 $widget_id = $id_base . '-' . $multi_number;
    1971                 $sidebar[] = $widget_id;
     2179                $widget_id                     = $id_base . '-' . $multi_number;
     2180                $sidebar[]                     = $widget_id;
    19722181        }
    19732182        $_POST['widget-id'] = $sidebar;
     
    19762185
    19772186                if ( $name == $id_base ) {
    1978                         if ( !is_callable( $control['callback'] ) )
     2187                        if ( ! is_callable( $control['callback'] ) ) {
    19792188                                continue;
     2189                        }
    19802190
    19812191                        ob_start();
     
    19862196        }
    19872197
    1988         if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
    1989                 $sidebars[$sidebar_id] = $sidebar;
    1990                 wp_set_sidebars_widgets($sidebars);
     2198        if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
     2199                $sidebars[ $sidebar_id ] = $sidebar;
     2200                wp_set_sidebars_widgets( $sidebars );
    19912201                echo "deleted:$widget_id";
    19922202                wp_die();
    19932203        }
    19942204
    1995         if ( !empty($_POST['add_new']) )
     2205        if ( ! empty( $_POST['add_new'] ) ) {
    19962206                wp_die();
    1997 
    1998         if ( $form = $wp_registered_widget_controls[$widget_id] )
     2207        }
     2208
     2209        if ( $form = $wp_registered_widget_controls[ $widget_id ] ) {
    19992210                call_user_func_array( $form['callback'], $form['params'] );
     2211        }
    20002212
    20012213        wp_die();
     
    20372249
    20382250        foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) {
    2039                 $pieces = explode( '-', $widget_id );
     2251                $pieces       = explode( '-', $widget_id );
    20402252                $multi_number = array_pop( $pieces );
    2041                 $id_base = implode( '-', $pieces );
    2042                 $widget = get_option( 'widget_' . $id_base );
    2043                 unset( $widget[$multi_number] );
     2253                $id_base      = implode( '-', $pieces );
     2254                $widget       = get_option( 'widget_' . $id_base );
     2255                unset( $widget[ $multi_number ] );
    20442256                update_option( 'widget_' . $id_base, $widget );
    2045                 unset( $sidebars_widgets['wp_inactive_widgets'][$key] );
     2257                unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] );
    20462258        }
    20472259
     
    20652277
    20662278        if ( ! current_user_can( 'upload_files' ) ) {
    2067                 echo wp_json_encode( array(
    2068                         'success' => false,
    2069                         'data'    => array(
    2070                                 'message'  => __( 'Sorry, you are not allowed to upload files.' ),
    2071                                 'filename' => $_FILES['async-upload']['name'],
     2279                echo wp_json_encode(
     2280                        array(
     2281                                'success' => false,
     2282                                'data'    => array(
     2283                                        'message'  => __( 'Sorry, you are not allowed to upload files.' ),
     2284                                        'filename' => $_FILES['async-upload']['name'],
     2285                                ),
    20722286                        )
    2073                 ) );
     2287                );
    20742288
    20752289                wp_die();
     
    20792293                $post_id = $_REQUEST['post_id'];
    20802294                if ( ! current_user_can( 'edit_post', $post_id ) ) {
    2081                         echo wp_json_encode( array(
    2082                                 'success' => false,
    2083                                 'data'    => array(
    2084                                         'message'  => __( 'Sorry, you are not allowed to attach files to this post.' ),
    2085                                         'filename' => $_FILES['async-upload']['name'],
     2295                        echo wp_json_encode(
     2296                                array(
     2297                                        'success' => false,
     2298                                        'data'    => array(
     2299                                                'message'  => __( 'Sorry, you are not allowed to attach files to this post.' ),
     2300                                                'filename' => $_FILES['async-upload']['name'],
     2301                                        ),
    20862302                                )
    2087                         ) );
     2303                        );
    20882304
    20892305                        wp_die();
     
    20992315                $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
    21002316                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
    2101                         echo wp_json_encode( array(
     2317                        echo wp_json_encode(
     2318                                array(
     2319                                        'success' => false,
     2320                                        'data'    => array(
     2321                                                'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
     2322                                                'filename' => $_FILES['async-upload']['name'],
     2323                                        ),
     2324                                )
     2325                        );
     2326
     2327                        wp_die();
     2328                }
     2329        }
     2330
     2331        $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
     2332
     2333        if ( is_wp_error( $attachment_id ) ) {
     2334                echo wp_json_encode(
     2335                        array(
    21022336                                'success' => false,
    21032337                                'data'    => array(
    2104                                         'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
     2338                                        'message'  => $attachment_id->get_error_message(),
    21052339                                        'filename' => $_FILES['async-upload']['name'],
    2106                                 )
    2107                         ) );
    2108 
    2109                         wp_die();
    2110                 }
    2111         }
    2112 
    2113         $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
    2114 
    2115         if ( is_wp_error( $attachment_id ) ) {
    2116                 echo wp_json_encode( array(
    2117                         'success' => false,
    2118                         'data'    => array(
    2119                                 'message'  => $attachment_id->get_error_message(),
    2120                                 'filename' => $_FILES['async-upload']['name'],
     2340                                ),
    21212341                        )
    2122                 ) );
     2342                );
    21232343
    21242344                wp_die();
     
    21262346
    21272347        if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
    2128                 if ( 'custom-background' === $post_data['context'] )
     2348                if ( 'custom-background' === $post_data['context'] ) {
    21292349                        update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
    2130 
    2131                 if ( 'custom-header' === $post_data['context'] )
     2350                }
     2351
     2352                if ( 'custom-header' === $post_data['context'] ) {
    21322353                        update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
    2133         }
    2134 
    2135         if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
     2354                }
     2355        }
     2356
     2357        if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) {
    21362358                wp_die();
    2137 
    2138         echo wp_json_encode( array(
    2139                 'success' => true,
    2140                 'data'    => $attachment,
    2141         ) );
     2359        }
     2360
     2361        echo wp_json_encode(
     2362                array(
     2363                        'success' => true,
     2364                        'data'    => $attachment,
     2365                )
     2366        );
    21422367
    21432368        wp_die();
     
    21502375 */
    21512376function wp_ajax_image_editor() {
    2152         $attachment_id = intval($_POST['postid']);
    2153         if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
     2377        $attachment_id = intval( $_POST['postid'] );
     2378        if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
    21542379                wp_die( -1 );
     2380        }
    21552381
    21562382        check_ajax_referer( "image_editor-$attachment_id" );
     
    21592385        $msg = false;
    21602386        switch ( $_POST['do'] ) {
    2161                 case 'save' :
    2162                         $msg = wp_save_image($attachment_id);
    2163                         $msg = wp_json_encode($msg);
     2387                case 'save':
     2388                        $msg = wp_save_image( $attachment_id );
     2389                        $msg = wp_json_encode( $msg );
    21642390                        wp_die( $msg );
    21652391                        break;
    2166                 case 'scale' :
    2167                         $msg = wp_save_image($attachment_id);
     2392                case 'scale':
     2393                        $msg = wp_save_image( $attachment_id );
    21682394                        break;
    2169                 case 'restore' :
    2170                         $msg = wp_restore_image($attachment_id);
     2395                case 'restore':
     2396                        $msg = wp_restore_image( $attachment_id );
    21712397                        break;
    21722398        }
    21732399
    2174         wp_image_editor($attachment_id, $msg);
     2400        wp_image_editor( $attachment_id, $msg );
    21752401        wp_die();
    21762402}
     
    21852411
    21862412        $post_ID = intval( $_POST['post_id'] );
    2187         if ( ! current_user_can( 'edit_post', $post_ID ) )
     2413        if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    21882414                wp_die( -1 );
     2415        }
    21892416
    21902417        $thumbnail_id = intval( $_POST['thumbnail_id'] );
    21912418
    2192         if ( $json )
     2419        if ( $json ) {
    21932420                check_ajax_referer( "update-post_$post_ID" );
    2194         else
     2421        } else {
    21952422                check_ajax_referer( "set_post_thumbnail-$post_ID" );
     2423        }
    21962424
    21972425        if ( $thumbnail_id == '-1' ) {
     
    23172545        $post = null;
    23182546
    2319         if ( $post_id )
     2547        if ( $post_id ) {
    23202548                $post = get_post( $post_id );
    2321 
    2322         check_ajax_referer('update-post_' . $post_id, '_wpnonce');
     2549        }
     2550
     2551        check_ajax_referer( 'update-post_' . $post_id, '_wpnonce' );
    23232552
    23242553        $post_id = edit_post();
     
    23372566
    23382567        if ( $last_id = get_post_meta( $post_id, '_edit_last', true ) ) {
    2339                 $last_user = get_userdata( $last_id );
    2340                 $last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time );
     2568                $last_user   = get_userdata( $last_id );
     2569                $last_edited = sprintf( __( 'Last edited by %1$s on %2$s at %3$s' ), esc_html( $last_user->display_name ), $last_date, $last_time );
    23412570        } else {
    2342                 $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time );
     2571                $last_edited = sprintf( __( 'Last edited on %1$s at %2$s' ), $last_date, $last_time );
    23432572        }
    23442573
     
    23522581 */
    23532582function wp_ajax_wp_remove_post_lock() {
    2354         if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
     2583        if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) {
    23552584                wp_die( 0 );
     2585        }
    23562586        $post_id = (int) $_POST['post_ID'];
    2357         if ( ! $post = get_post( $post_id ) )
     2587        if ( ! $post = get_post( $post_id ) ) {
    23582588                wp_die( 0 );
     2589        }
    23592590
    23602591        check_ajax_referer( 'update-post_' . $post_id );
    23612592
    2362         if ( ! current_user_can( 'edit_post', $post_id ) )
     2593        if ( ! current_user_can( 'edit_post', $post_id ) ) {
    23632594                wp_die( -1 );
     2595        }
    23642596
    23652597        $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
    2366         if ( $active_lock[1] != get_current_user_id() )
     2598        if ( $active_lock[1] != get_current_user_id() ) {
    23672599                wp_die( 0 );
     2600        }
    23682601
    23692602        /**
     
    23872620function wp_ajax_dismiss_wp_pointer() {
    23882621        $pointer = $_POST['pointer'];
    2389         if ( $pointer != sanitize_key( $pointer ) )
     2622        if ( $pointer != sanitize_key( $pointer ) ) {
    23902623                wp_die( 0 );
    2391 
    2392 //      check_ajax_referer( 'dismiss-pointer_' . $pointer );
     2624        }
     2625
     2626        //  check_ajax_referer( 'dismiss-pointer_' . $pointer );
    23932627
    23942628        $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
    23952629
    2396         if ( in_array( $pointer, $dismissed ) )
     2630        if ( in_array( $pointer, $dismissed ) ) {
    23972631                wp_die( 0 );
     2632        }
    23982633
    23992634        $dismissed[] = $pointer;
    2400         $dismissed = implode( ',', $dismissed );
     2635        $dismissed   = implode( ',', $dismissed );
    24012636
    24022637        update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
     
    24102645 */
    24112646function wp_ajax_get_attachment() {
    2412         if ( ! isset( $_REQUEST['id'] ) )
     2647        if ( ! isset( $_REQUEST['id'] ) ) {
    24132648                wp_send_json_error();
    2414 
    2415         if ( ! $id = absint( $_REQUEST['id'] ) )
     2649        }
     2650
     2651        if ( ! $id = absint( $_REQUEST['id'] ) ) {
    24162652                wp_send_json_error();
    2417 
    2418         if ( ! $post = get_post( $id ) )
     2653        }
     2654
     2655        if ( ! $post = get_post( $id ) ) {
    24192656                wp_send_json_error();
    2420 
    2421         if ( 'attachment' != $post->post_type )
     2657        }
     2658
     2659        if ( 'attachment' != $post->post_type ) {
    24222660                wp_send_json_error();
    2423 
    2424         if ( ! current_user_can( 'upload_files' ) )
     2661        }
     2662
     2663        if ( ! current_user_can( 'upload_files' ) ) {
    24252664                wp_send_json_error();
    2426 
    2427         if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
     2665        }
     2666
     2667        if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
    24282668                wp_send_json_error();
     2669        }
    24292670
    24302671        wp_send_json_success( $attachment );
     
    24372678 */
    24382679function wp_ajax_query_attachments() {
    2439         if ( ! current_user_can( 'upload_files' ) )
     2680        if ( ! current_user_can( 'upload_files' ) ) {
    24402681                wp_send_json_error();
     2682        }
    24412683
    24422684        $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
    2443         $keys = array(
    2444                 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
    2445                 'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
     2685        $keys  = array(
     2686                's',
     2687                'order',
     2688                'orderby',
     2689                'posts_per_page',
     2690                'paged',
     2691                'post_mime_type',
     2692                'post_parent',
     2693                'post__in',
     2694                'post__not_in',
     2695                'year',
     2696                'monthnum',
    24462697        );
    24472698        foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
     
    24512702        }
    24522703
    2453         $query = array_intersect_key( $query, array_flip( $keys ) );
     2704        $query              = array_intersect_key( $query, array_flip( $keys ) );
    24542705        $query['post_type'] = 'attachment';
    24552706        if ( MEDIA_TRASH
     
    24612712        }
    24622713
    2463         if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) )
     2714        if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
    24642715                $query['post_status'] .= ',private';
     2716        }
    24652717
    24662718        // Filter query clauses to include filenames.
     
    24942746 */
    24952747function wp_ajax_save_attachment() {
    2496         if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) )
     2748        if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) {
    24972749                wp_send_json_error();
    2498 
    2499         if ( ! $id = absint( $_REQUEST['id'] ) )
     2750        }
     2751
     2752        if ( ! $id = absint( $_REQUEST['id'] ) ) {
    25002753                wp_send_json_error();
     2754        }
    25012755
    25022756        check_ajax_referer( 'update-post_' . $id, 'nonce' );
    25032757
    2504         if ( ! current_user_can( 'edit_post', $id ) )
     2758        if ( ! current_user_can( 'edit_post', $id ) ) {
    25052759                wp_send_json_error();
     2760        }
    25062761
    25072762        $changes = $_REQUEST['changes'];
    25082763        $post    = get_post( $id, ARRAY_A );
    25092764
    2510         if ( 'attachment' != $post['post_type'] )
     2765        if ( 'attachment' != $post['post_type'] ) {
    25112766                wp_send_json_error();
    2512 
    2513         if ( isset( $changes['parent'] ) )
     2767        }
     2768
     2769        if ( isset( $changes['parent'] ) ) {
    25142770                $post['post_parent'] = $changes['parent'];
    2515 
    2516         if ( isset( $changes['title'] ) )
     2771        }
     2772
     2773        if ( isset( $changes['title'] ) ) {
    25172774                $post['post_title'] = $changes['title'];
    2518 
    2519         if ( isset( $changes['caption'] ) )
     2775        }
     2776
     2777        if ( isset( $changes['caption'] ) ) {
    25202778                $post['post_excerpt'] = $changes['caption'];
    2521 
    2522         if ( isset( $changes['description'] ) )
     2779        }
     2780
     2781        if ( isset( $changes['description'] ) ) {
    25232782                $post['post_content'] = $changes['description'];
    2524 
    2525         if ( MEDIA_TRASH && isset( $changes['status'] ) )
     2783        }
     2784
     2785        if ( MEDIA_TRASH && isset( $changes['status'] ) ) {
    25262786                $post['post_status'] = $changes['status'];
     2787        }
    25272788
    25282789        if ( isset( $changes['alt'] ) ) {
     
    25432804                foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
    25442805                        if ( isset( $changes[ $key ] ) ) {
    2545                                 $changed = true;
     2806                                $changed         = true;
    25462807                                $id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) );
    25472808                        }
     
    25682829 */
    25692830function wp_ajax_save_attachment_compat() {
    2570         if ( ! isset( $_REQUEST['id'] ) )
     2831        if ( ! isset( $_REQUEST['id'] ) ) {
    25712832                wp_send_json_error();
    2572 
    2573         if ( ! $id = absint( $_REQUEST['id'] ) )
     2833        }
     2834
     2835        if ( ! $id = absint( $_REQUEST['id'] ) ) {
    25742836                wp_send_json_error();
    2575 
    2576         if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) )
     2837        }
     2838
     2839        if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
    25772840                wp_send_json_error();
     2841        }
    25782842        $attachment_data = $_REQUEST['attachments'][ $id ];
    25792843
    25802844        check_ajax_referer( 'update-post_' . $id, 'nonce' );
    25812845
    2582         if ( ! current_user_can( 'edit_post', $id ) )
     2846        if ( ! current_user_can( 'edit_post', $id ) ) {
    25832847                wp_send_json_error();
     2848        }
    25842849
    25852850        $post = get_post( $id, ARRAY_A );
    25862851
    2587         if ( 'attachment' != $post['post_type'] )
     2852        if ( 'attachment' != $post['post_type'] ) {
    25882853                wp_send_json_error();
     2854        }
    25892855
    25902856        /** This filter is documented in wp-admin/includes/media.php */
     
    25992865
    26002866        foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
    2601                 if ( isset( $attachment_data[ $taxonomy ] ) )
     2867                if ( isset( $attachment_data[ $taxonomy ] ) ) {
    26022868                        wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
    2603         }
    2604 
    2605         if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
     2869                }
     2870        }
     2871
     2872        if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
    26062873                wp_send_json_error();
     2874        }
    26072875
    26082876        wp_send_json_success( $attachment );
     
    26152883 */
    26162884function wp_ajax_save_attachment_order() {
    2617         if ( ! isset( $_REQUEST['post_id'] ) )
     2885        if ( ! isset( $_REQUEST['post_id'] ) ) {
    26182886                wp_send_json_error();
    2619 
    2620         if ( ! $post_id = absint( $_REQUEST['post_id'] ) )
     2887        }
     2888
     2889        if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) {
    26212890                wp_send_json_error();
    2622 
    2623         if ( empty( $_REQUEST['attachments'] ) )
     2891        }
     2892
     2893        if ( empty( $_REQUEST['attachments'] ) ) {
    26242894                wp_send_json_error();
     2895        }
    26252896
    26262897        check_ajax_referer( 'update-post_' . $post_id, 'nonce' );
     
    26282899        $attachments = $_REQUEST['attachments'];
    26292900
    2630         if ( ! current_user_can( 'edit_post', $post_id ) )
     2901        if ( ! current_user_can( 'edit_post', $post_id ) ) {
    26312902                wp_send_json_error();
     2903        }
    26322904
    26332905        foreach ( $attachments as $attachment_id => $menu_order ) {
    2634                 if ( ! current_user_can( 'edit_post', $attachment_id ) )
     2906                if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
    26352907                        continue;
    2636                 if ( ! $attachment = get_post( $attachment_id ) )
     2908                }
     2909                if ( ! $attachment = get_post( $attachment_id ) ) {
    26372910                        continue;
    2638                 if ( 'attachment' != $attachment->post_type )
     2911                }
     2912                if ( 'attachment' != $attachment->post_type ) {
    26392913                        continue;
    2640 
    2641                 wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) );
     2914                }
     2915
     2916                wp_update_post(
     2917                        array(
     2918                                'ID'         => $attachment_id,
     2919                                'menu_order' => $menu_order,
     2920                        )
     2921                );
    26422922        }
    26432923
     
    26612941        $id = intval( $attachment['id'] );
    26622942
    2663         if ( ! $post = get_post( $id ) )
     2943        if ( ! $post = get_post( $id ) ) {
    26642944                wp_send_json_error();
    2665 
    2666         if ( 'attachment' != $post->post_type )
     2945        }
     2946
     2947        if ( 'attachment' != $post->post_type ) {
    26672948                wp_send_json_error();
     2949        }
    26682950
    26692951        if ( current_user_can( 'edit_post', $id ) ) {
    26702952                // If this attachment is unattached, attach it. Primarily a back compat thing.
    26712953                if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) {
    2672                         wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) );
     2954                        wp_update_post(
     2955                                array(
     2956                                        'ID'          => $id,
     2957                                        'post_parent' => $insert_into_post_id,
     2958                                )
     2959                        );
    26732960                }
    26742961        }
    26752962
    26762963        $url = empty( $attachment['url'] ) ? '' : $attachment['url'];
    2677         $rel = ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url );
     2964        $rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $id ) == $url );
    26782965
    26792966        remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
     
    26812968        if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
    26822969                $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
    2683                 $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
    2684                 $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
     2970                $size  = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
     2971                $alt   = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
    26852972
    26862973                // No whitespace-only captions.
     
    26912978
    26922979                $title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
    2693                 $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt );
    2694         } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post )  ) {
     2980                $html  = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt );
     2981        } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) {
    26952982                $html = stripslashes_deep( $_POST['html'] );
    26962983        } else {
    26972984                $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
    2698                 $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized
     2985                $rel  = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized
    26992986
    27002987                if ( ! empty( $url ) ) {
     
    27293016        check_ajax_referer( 'media-send-to-editor', 'nonce' );
    27303017
    2731         if ( ! $src = wp_unslash( $_POST['src'] ) )
     3018        if ( ! $src = wp_unslash( $_POST['src'] ) ) {
    27323019                wp_send_json_error();
    2733 
    2734         if ( ! strpos( $src, '://' ) )
     3020        }
     3021
     3022        if ( ! strpos( $src, '://' ) ) {
    27353023                $src = 'http://' . $src;
    2736 
    2737         if ( ! $src = esc_url_raw( $src ) )
     3024        }
     3025
     3026        if ( ! $src = esc_url_raw( $src ) ) {
    27383027                wp_send_json_error();
    2739 
    2740         if ( ! $link_text = trim( wp_unslash( $_POST['link_text'] ) ) )
     3028        }
     3029
     3030        if ( ! $link_text = trim( wp_unslash( $_POST['link_text'] ) ) ) {
    27413031                $link_text = wp_basename( $src );
     3032        }
    27423033
    27433034        $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
    27443035
    27453036        // Ping WordPress for an embed.
    2746         $check_embed = $wp_embed->run_shortcode( '[embed]'. $src .'[/embed]' );
     3037        $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
    27473038
    27483039        // Fallback that WordPress creates when no oEmbed was found.
     
    27613052        $type = 'file';
    27623053        if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
    2763                 && ( 'audio' == $ext_type || 'video' == $ext_type ) )
     3054                && ( 'audio' == $ext_type || 'video' == $ext_type ) ) {
    27643055                        $type = $ext_type;
     3056        }
    27653057
    27663058        /** This filter is documented in wp-admin/includes/media.php */
     
    27823074        }
    27833075
    2784         $response = $data = array();
     3076        $response    = $data = array();
    27853077        $nonce_state = wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' );
    27863078
    27873079        // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    27883080        if ( ! empty( $_POST['screen_id'] ) ) {
    2789                 $screen_id = sanitize_key($_POST['screen_id']);
     3081                $screen_id = sanitize_key( $_POST['screen_id'] );
    27903082        } else {
    27913083                $screen_id = 'front';
     
    28553147        require ABSPATH . 'wp-admin/includes/revision.php';
    28563148
    2857         if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) )
     3149        if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) ) {
    28583150                wp_send_json_error();
    2859 
    2860         if ( ! current_user_can( 'edit_post', $post->ID ) )
     3151        }
     3152
     3153        if ( ! current_user_can( 'edit_post', $post->ID ) ) {
    28613154                wp_send_json_error();
     3155        }
    28623156
    28633157        // Really just pre-loading the cache here.
    2864         if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) )
     3158        if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) ) {
    28653159                wp_send_json_error();
     3160        }
    28663161
    28673162        $return = array();
     
    28723167
    28733168                $return[] = array(
    2874                         'id' => $compare_key,
     3169                        'id'     => $compare_key,
    28753170                        'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ),
    28763171                );
     
    29013196        update_user_meta( get_current_user_id(), 'admin_color', $color_scheme );
    29023197
    2903         wp_send_json_success( array(
    2904                 'previousScheme' => 'admin-color-' . $previous_color_scheme,
    2905                 'currentScheme'  => 'admin-color-' . $color_scheme
    2906         ) );
     3198        wp_send_json_success(
     3199                array(
     3200                        'previousScheme' => 'admin-color-' . $previous_color_scheme,
     3201                        'currentScheme'  => 'admin-color-' . $color_scheme,
     3202                )
     3203        );
    29073204}
    29083205
     
    29223219        }
    29233220
    2924         $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array(
    2925                 'per_page' => 20,
    2926                 'fields'   => $theme_field_defaults
    2927         ) );
     3221        $args = wp_parse_args(
     3222                wp_unslash( $_REQUEST['request'] ), array(
     3223                        'per_page' => 20,
     3224                        'fields'   => $theme_field_defaults,
     3225                )
     3226        );
    29283227
    29293228        if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) {
     
    29473246        $update_php = network_admin_url( 'update.php?action=install-theme' );
    29483247        foreach ( $api->themes as &$theme ) {
    2949                 $theme->install_url = add_query_arg( array(
    2950                         'theme'    => $theme->slug,
    2951                         '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug )
    2952                 ), $update_php );
     3248                $theme->install_url = add_query_arg(
     3249                        array(
     3250                                'theme'    => $theme->slug,
     3251                                '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ),
     3252                        ), $update_php
     3253                );
    29533254
    29543255                if ( current_user_can( 'switch_themes' ) ) {
    29553256                        if ( is_multisite() ) {
    2956                                 $theme->activate_url = add_query_arg( array(
    2957                                         'action'   => 'enable',
    2958                                         '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ),
    2959                                         'theme'    => $theme->slug,
    2960                                 ), network_admin_url( 'themes.php' ) );
     3257                                $theme->activate_url = add_query_arg(
     3258                                        array(
     3259                                                'action'   => 'enable',
     3260                                                '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ),
     3261                                                'theme'    => $theme->slug,
     3262                                        ), network_admin_url( 'themes.php' )
     3263                                );
    29613264                        } else {
    2962                                 $theme->activate_url = add_query_arg( array(
    2963                                         'action'     => 'activate',
    2964                                         '_wpnonce'   => wp_create_nonce( 'switch-theme_' . $theme->slug ),
    2965                                         'stylesheet' => $theme->slug,
    2966                                 ), admin_url( 'themes.php' ) );
     3265                                $theme->activate_url = add_query_arg(
     3266                                        array(
     3267                                                'action'     => 'activate',
     3268                                                '_wpnonce'   => wp_create_nonce( 'switch-theme_' . $theme->slug ),
     3269                                                'stylesheet' => $theme->slug,
     3270                                        ), admin_url( 'themes.php' )
     3271                                );
    29673272                        }
    29683273                }
    29693274
    29703275                if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    2971                         $theme->customize_url = add_query_arg( array(
    2972                                 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
    2973                         ), wp_customize_url( $theme->slug ) );
     3276                        $theme->customize_url = add_query_arg(
     3277                                array(
     3278                                        'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
     3279                                ), wp_customize_url( $theme->slug )
     3280                        );
    29743281                }
    29753282
     
    29783285                $theme->version     = wp_kses( $theme->version, $themes_allowedtags );
    29793286                $theme->description = wp_kses( $theme->description, $themes_allowedtags );
    2980                 $theme->stars       = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) );
     3287                $theme->stars       = wp_star_rating(
     3288                        array(
     3289                                'rating' => $theme->rating,
     3290                                'type'   => 'percent',
     3291                                'number' => $theme->num_ratings,
     3292                                'echo'   => false,
     3293                        )
     3294                );
    29813295                $theme->num_ratings = number_format_i18n( $theme->num_ratings );
    29823296                $theme->preview_url = set_url_scheme( $theme->preview_url );
     
    30023316                wp_send_json_error();
    30033317        }
    3004         $post_id = isset( $_POST[ 'post_ID' ] ) ? intval( $_POST[ 'post_ID' ] ) : 0;
     3318        $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0;
    30053319        if ( $post_id > 0 ) {
    30063320                $post = get_post( $post_id );
     
    30253339        }
    30263340
    3027         $parsed = false;
     3341        $parsed                         = false;
    30283342        $wp_embed->return_false_on_fail = true;
    30293343
     
    30413355                // Check if the provider supports ssl embeds and use that for the preview.
    30423356                $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode );
    3043                 $parsed = $wp_embed->run_shortcode( $ssl_shortcode );
     3357                $parsed        = $wp_embed->run_shortcode( $ssl_shortcode );
    30443358
    30453359                if ( ! $parsed ) {
     
    30623376
    30633377        if ( ! $parsed ) {
    3064                 wp_send_json_error( array(
    3065                         'type' => 'not-embeddable',
    3066                         'message' => sprintf( __( '%s failed to embed.' ), '<code>' . esc_html( $url ) . '</code>' ),
    3067                 ) );
     3378                wp_send_json_error(
     3379                        array(
     3380                                'type'    => 'not-embeddable',
     3381                                'message' => sprintf( __( '%s failed to embed.' ), '<code>' . esc_html( $url ) . '</code>' ),
     3382                        )
     3383                );
    30683384        }
    30693385
    30703386        if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) {
    3071                 $styles = '';
     3387                $styles     = '';
    30723388                $mce_styles = wpview_media_sandbox_styles();
    30733389                foreach ( $mce_styles as $style ) {
     
    30913407                preg_match( '%<link [^>]*href="http://%', $parsed ) ) ) ) {
    30923408                // Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked.
    3093                 wp_send_json_error( array(
    3094                         'type' => 'not-ssl',
    3095                         'message' => __( 'This preview is unavailable in the editor.' ),
    3096                 ) );
     3409                wp_send_json_error(
     3410                        array(
     3411                                'type'    => 'not-ssl',
     3412                                'message' => __( 'This preview is unavailable in the editor.' ),
     3413                        )
     3414                );
    30973415        }
    30983416
    30993417        $return = array(
    31003418                'body' => $parsed,
    3101                 'attr' => $wp_embed->last_attr
     3419                'attr' => $wp_embed->last_attr,
    31023420        );
    31033421
     
    31093427                }
    31103428
    3111                 $return['head'] = '<script src="' . $script_src . '"></script>';
     3429                $return['head']    = '<script src="' . $script_src . '"></script>';
    31123430                $return['sandbox'] = true;
    31133431        }
     
    31443462        }
    31453463
    3146         $parsed = do_shortcode( $shortcode  );
     3464        $parsed = do_shortcode( $shortcode );
    31473465
    31483466        if ( empty( $parsed ) ) {
    3149                 wp_send_json_error( array(
    3150                         'type' => 'no-items',
    3151                         'message' => __( 'No items found.' ),
    3152                 ) );
    3153         }
    3154 
    3155         $head = '';
     3467                wp_send_json_error(
     3468                        array(
     3469                                'type'    => 'no-items',
     3470                                'message' => __( 'No items found.' ),
     3471                        )
     3472                );
     3473        }
     3474
     3475        $head   = '';
    31563476        $styles = wpview_media_sandbox_styles();
    31573477
     
    31763496        }
    31773497
    3178         wp_send_json_success( array(
    3179                 'head' => $head,
    3180                 'body' => ob_get_clean()
    3181         ) );
     3498        wp_send_json_success(
     3499                array(
     3500                        'head' => $head,
     3501                        'body' => ob_get_clean(),
     3502                )
     3503        );
    31823504}
    31833505
     
    31983520
    31993521        if ( ! $user ) {
    3200                 wp_send_json_error( array(
    3201                         'message' => __( 'Could not log out user sessions. Please try again.' ),
    3202                 ) );
     3522                wp_send_json_error(
     3523                        array(
     3524                                'message' => __( 'Could not log out user sessions. Please try again.' ),
     3525                        )
     3526                );
    32033527        }
    32043528
     
    32693593
    32703594                default:
    3271 
    32723595                        /**
    32733596                         * Fires before a cropped image is saved.
     
    33013624
    33023625                        $attachment_id = wp_insert_attachment( $object, $cropped );
    3303                         $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
     3626                        $metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );
    33043627
    33053628                        /**
     
    33723695
    33733696        if ( empty( $_POST['slug'] ) ) {
    3374                 wp_send_json_error( array(
    3375                         'slug'         => '',
    3376                         'errorCode'    => 'no_theme_specified',
    3377                         'errorMessage' => __( 'No theme specified.' ),
    3378                 ) );
     3697                wp_send_json_error(
     3698                        array(
     3699                                'slug'         => '',
     3700                                'errorCode'    => 'no_theme_specified',
     3701                                'errorMessage' => __( 'No theme specified.' ),
     3702                        )
     3703                );
    33793704        }
    33803705
     
    33943719        include_once( ABSPATH . 'wp-admin/includes/theme.php' );
    33953720
    3396         $api = themes_api( 'theme_information', array(
    3397                 'slug'   => $slug,
    3398                 'fields' => array( 'sections' => false ),
    3399         ) );
     3721        $api = themes_api(
     3722                'theme_information', array(
     3723                        'slug'   => $slug,
     3724                        'fields' => array( 'sections' => false ),
     3725                )
     3726        );
    34003727
    34013728        if ( is_wp_error( $api ) ) {
     
    34413768        if ( current_user_can( 'switch_themes' ) ) {
    34423769                if ( is_multisite() ) {
    3443                         $status['activateUrl'] = add_query_arg( array(
    3444                                 'action'   => 'enable',
    3445                                 '_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ),
    3446                                 'theme'    => $slug,
    3447                         ), network_admin_url( 'themes.php' ) );
     3770                        $status['activateUrl'] = add_query_arg(
     3771                                array(
     3772                                        'action'   => 'enable',
     3773                                        '_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ),
     3774                                        'theme'    => $slug,
     3775                                ), network_admin_url( 'themes.php' )
     3776                        );
    34483777                } else {
    3449                         $status['activateUrl'] = add_query_arg( array(
    3450                                 'action'     => 'activate',
    3451                                 '_wpnonce'   => wp_create_nonce( 'switch-theme_' . $slug ),
    3452                                 'stylesheet' => $slug,
    3453                         ), admin_url( 'themes.php' ) );
     3778                        $status['activateUrl'] = add_query_arg(
     3779                                array(
     3780                                        'action'     => 'activate',
     3781                                        '_wpnonce'   => wp_create_nonce( 'switch-theme_' . $slug ),
     3782                                        'stylesheet' => $slug,
     3783                                ), admin_url( 'themes.php' )
     3784                        );
    34543785                }
    34553786        }
    34563787
    34573788        if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
    3458                 $status['customizeUrl'] = add_query_arg( array(
    3459                         'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
    3460                 ), wp_customize_url( $slug ) );
     3789                $status['customizeUrl'] = add_query_arg(
     3790                        array(
     3791                                'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
     3792                        ), wp_customize_url( $slug )
     3793                );
    34613794        }
    34623795
     
    34813814
    34823815        if ( empty( $_POST['slug'] ) ) {
    3483                 wp_send_json_error( array(
    3484                         'slug'         => '',
    3485                         'errorCode'    => 'no_theme_specified',
    3486                         'errorMessage' => __( 'No theme specified.' ),
    3487                 ) );
     3816                wp_send_json_error(
     3817                        array(
     3818                                'slug'         => '',
     3819                                'errorCode'    => 'no_theme_specified',
     3820                                'errorMessage' => __( 'No theme specified.' ),
     3821                        )
     3822                );
    34883823        }
    34893824
     
    35743909
    35753910        if ( empty( $_POST['slug'] ) ) {
    3576                 wp_send_json_error( array(
    3577                         'slug'         => '',
    3578                         'errorCode'    => 'no_theme_specified',
    3579                         'errorMessage' => __( 'No theme specified.' ),
    3580                 ) );
     3911                wp_send_json_error(
     3912                        array(
     3913                                'slug'         => '',
     3914                                'errorCode'    => 'no_theme_specified',
     3915                                'errorMessage' => __( 'No theme specified.' ),
     3916                        )
     3917                );
    35813918        }
    35823919
     
    36443981
    36453982        if ( empty( $_POST['slug'] ) ) {
    3646                 wp_send_json_error( array(
    3647                         'slug'         => '',
    3648                         'errorCode'    => 'no_plugin_specified',
    3649                         'errorMessage' => __( 'No plugin specified.' ),
    3650                 ) );
     3983                wp_send_json_error(
     3984                        array(
     3985                                'slug'         => '',
     3986                                'errorCode'    => 'no_plugin_specified',
     3987                                'errorMessage' => __( 'No plugin specified.' ),
     3988                        )
     3989                );
    36513990        }
    36523991
     
    36644003        include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    36654004
    3666         $api = plugins_api( 'plugin_information', array(
    3667                 'slug'   => sanitize_key( wp_unslash( $_POST['slug'] ) ),
    3668                 'fields' => array(
    3669                         'sections' => false,
    3670                 ),
    3671         ) );
     4005        $api = plugins_api(
     4006                'plugin_information', array(
     4007                        'slug'   => sanitize_key( wp_unslash( $_POST['slug'] ) ),
     4008                        'fields' => array(
     4009                                'sections' => false,
     4010                        ),
     4011                )
     4012        );
    36724013
    36734014        if ( is_wp_error( $api ) ) {
     
    37124053
    37134054        $install_status = install_plugin_install_status( $api );
    3714         $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
     4055        $pagenow        = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
    37154056
    37164057        // If installation request is coming from import page, do not return network activation link.
     
    37184059
    37194060        if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
    3720                 $status['activateUrl'] = add_query_arg( array(
    3721                         '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
    3722                         'action'   => 'activate',
    3723                         'plugin'   => $install_status['file'],
    3724                 ), $plugins_url );
     4061                $status['activateUrl'] = add_query_arg(
     4062                        array(
     4063                                '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
     4064                                'action'   => 'activate',
     4065                                'plugin'   => $install_status['file'],
     4066                        ), $plugins_url
     4067                );
    37254068        }
    37264069
     
    37454088
    37464089        if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) {
    3747                 wp_send_json_error( array(
    3748                         'slug'         => '',
    3749                         'errorCode'    => 'no_plugin_specified',
    3750                         'errorMessage' => __( 'No plugin specified.' ),
    3751                 ) );
     4090                wp_send_json_error(
     4091                        array(
     4092                                'slug'         => '',
     4093                                'errorCode'    => 'no_plugin_specified',
     4094                                'errorMessage' => __( 'No plugin specified.' ),
     4095                        )
     4096                );
    37524097        }
    37534098
     
    38504195
    38514196        if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
    3852                 wp_send_json_error( array(
    3853                         'slug'         => '',
    3854                         'errorCode'    => 'no_plugin_specified',
    3855                         'errorMessage' => __( 'No plugin specified.' ),
    3856                 ) );
     4197                wp_send_json_error(
     4198                        array(
     4199                                'slug'         => '',
     4200                                'errorCode'    => 'no_plugin_specified',
     4201                                'errorMessage' => __( 'No plugin specified.' ),
     4202                        )
     4203                );
    38574204        }
    38584205
     
    39264273
    39274274        /** @var WP_Plugins_List_Table $wp_list_table */
    3928         $wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array(
    3929                 'screen' => get_current_screen(),
    3930         ) );
     4275        $wp_list_table = _get_list_table(
     4276                'WP_Plugins_List_Table', array(
     4277                        'screen' => get_current_screen(),
     4278                )
     4279        );
    39314280
    39324281        $status = array();
     
    39384287
    39394288        // Set the correct requester, so pagination works.
    3940         $_SERVER['REQUEST_URI'] = add_query_arg( array_diff_key( $_POST, array(
    3941                 '_ajax_nonce' => null,
    3942                 'action'      => null,
    3943         ) ), network_admin_url( 'plugins.php', 'relative' ) );
     4289        $_SERVER['REQUEST_URI'] = add_query_arg(
     4290                array_diff_key(
     4291                        $_POST, array(
     4292                                '_ajax_nonce' => null,
     4293                                'action'      => null,
     4294                        )
     4295                ), network_admin_url( 'plugins.php', 'relative' )
     4296        );
    39444297
    39454298        $GLOBALS['s'] = wp_unslash( $_POST['s'] );
     
    39694322
    39704323        /** @var WP_Plugin_Install_List_Table $wp_list_table */
    3971         $wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table', array(
    3972                 'screen' => get_current_screen(),
    3973         ) );
     4324        $wp_list_table = _get_list_table(
     4325                'WP_Plugin_Install_List_Table', array(
     4326                        'screen' => get_current_screen(),
     4327                )
     4328        );
    39744329
    39754330        $status = array();
     
    39814336
    39824337        // Set the correct requester, so pagination works.
    3983         $_SERVER['REQUEST_URI'] = add_query_arg( array_diff_key( $_POST, array(
    3984                 '_ajax_nonce' => null,
    3985                 'action'      => null,
    3986         ) ), network_admin_url( 'plugin-install.php', 'relative' ) );
     4338        $_SERVER['REQUEST_URI'] = add_query_arg(
     4339                array_diff_key(
     4340                        $_POST, array(
     4341                                '_ajax_nonce' => null,
     4342                                'action'      => null,
     4343                        )
     4344                ), network_admin_url( 'plugin-install.php', 'relative' )
     4345        );
    39874346
    39884347        $wp_list_table->prepare_items();
     
    40054364        $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
    40064365        if ( is_wp_error( $r ) ) {
    4007                 wp_send_json_error( array_merge(
     4366                wp_send_json_error(
     4367                        array_merge(
     4368                                array(
     4369                                        'code'    => $r->get_error_code(),
     4370                                        'message' => $r->get_error_message(),
     4371                                ),
     4372                                (array) $r->get_error_data()
     4373                        )
     4374                );
     4375        } else {
     4376                wp_send_json_success(
    40084377                        array(
    4009                                 'code' => $r->get_error_code(),
    4010                                 'message' => $r->get_error_message(),
    4011                         ),
    4012                         (array) $r->get_error_data()
    4013                 ) );
    4014         } else {
    4015                 wp_send_json_success( array(
    4016                         'message' => __( 'File edited successfully.' ),
    4017                 ) );
    4018         }
    4019 }
     4378                                'message' => __( 'File edited successfully.' ),
     4379                        )
     4380                );
     4381        }
     4382}
Note: See TracChangeset for help on using the changeset viewer.