Make WordPress Core

Changeset 61224 for trunk


Ignore:
Timestamp:
11/12/2025 02:47:59 PM (9 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use more meaningful variable names in Admin Ajax actions.

Per the Naming Conventions:

Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.

This commit includes renaming of the following variables:

  • $post_ID to $post_id — “Use lowercase letters in variable, action/filter, and function names”.
  • $ext_type to $extension_type.
  • $ext to $extension.
  • $id3data to $id3_data — “Separate words via underscores”.
  • $msg to $message.
  • $sb to $sidebar.
  • $alt to $alternate.
  • $pid to $post_id.
  • $mid to $meta_id.
  • $menu_obj to $menu_object.
  • $noparents to $no_parents — “Separate words via underscores”.
  • $sup to $supplemental.
  • $cat_id to $category_id.
  • $cat_name to $category_name.
  • $out to $output.
  • $r to $edit_result.
  • $t to $taxonomy.
  • $u to $update_result.
  • $r to $result.
  • $response to $response_data.
  • $x to $response.

Follow-up to [53723], [55365].

Props costdev, mukesh27, SergeyBiryukov.
See #64226.

File:
1 edited

Legend:

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

    r60639 r61224  
    216216                        if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
    217217                                header( 'Content-Encoding: deflate' );
    218                                 $out = gzdeflate( $test_str, 1 );
     218                                $output = gzdeflate( $test_str, 1 );
    219219                        } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
    220220                                header( 'Content-Encoding: gzip' );
    221                                 $out = gzencode( $test_str, 1 );
     221                                $output = gzencode( $test_str, 1 );
    222222                        } else {
    223223                                wp_die( -1 );
    224224                        }
    225225
    226                         echo $out;
     226                        echo $output;
    227227                        wp_die();
    228228                } elseif ( 'no' === $_GET['test'] ) {
     
    481481                $counts = wp_count_comments();
    482482
    483                 $x = new WP_Ajax_Response(
     483                $response = new WP_Ajax_Response(
    484484                        array(
    485485                                'what'         => 'comment',
     
    505505                        )
    506506                );
    507                 $x->send();
     507                $response->send();
    508508        }
    509509
     
    553553        $counts  = wp_count_comments();
    554554
    555         $x = new WP_Ajax_Response(
     555        $response = new WP_Ajax_Response(
    556556                array(
    557557                        'what'         => 'comment',
     
    575575                )
    576576        );
    577         $x->send();
     577        $response->send();
    578578}
    579579
     
    613613        $popular_ids        = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
    614614
    615         foreach ( $names as $cat_name ) {
    616                 $cat_name          = trim( $cat_name );
    617                 $category_nicename = sanitize_title( $cat_name );
     615        foreach ( $names as $category_name ) {
     616                $category_name     = trim( $category_name );
     617                $category_nicename = sanitize_title( $category_name );
    618618
    619619                if ( '' === $category_nicename ) {
     
    621621                }
    622622
    623                 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
    624 
    625                 if ( ! $cat_id || is_wp_error( $cat_id ) ) {
     623                $category_id = wp_insert_term( $category_name, $taxonomy->name, array( 'parent' => $parent ) );
     624
     625                if ( ! $category_id || is_wp_error( $category_id ) ) {
    626626                        continue;
    627627                } else {
    628                         $cat_id = $cat_id['term_id'];
    629                 }
    630 
    631                 $checked_categories[] = $cat_id;
     628                        $category_id = $category_id['term_id'];
     629                }
     630
     631                $checked_categories[] = $category_id;
    632632
    633633                if ( $parent ) { // Do these all at once in a second.
     
    641641                        array(
    642642                                'taxonomy'             => $taxonomy->name,
    643                                 'descendants_and_self' => $cat_id,
     643                                'descendants_and_self' => $category_id,
    644644                                'selected_cats'        => $checked_categories,
    645645                                'popular_cats'         => $popular_ids,
     
    651651                $add = array(
    652652                        'what'     => $taxonomy->name,
    653                         'id'       => $cat_id,
     653                        'id'       => $category_id,
    654654                        'data'     => str_replace( array( "\n", "\t" ), '', $data ),
    655655                        'position' => -1,
     
    707707        wp_dropdown_categories( $parent_dropdown_args );
    708708
    709         $sup = ob_get_clean();
    710 
    711         $add['supplemental'] = array( 'newcat_parent' => $sup );
    712 
    713         $x = new WP_Ajax_Response( $add );
    714         $x->send();
     709        $supplemental = ob_get_clean();
     710
     711        $add['supplemental'] = array( 'newcat_parent' => $supplemental );
     712
     713        $response = new WP_Ajax_Response( $add );
     714        $response->send();
    715715}
    716716
     
    742742                }
    743743
    744                 $r = wp_trash_comment( $comment );
     744                $result = wp_trash_comment( $comment );
    745745        } elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {
    746746                if ( 'trash' !== $status ) {
     
    748748                }
    749749
    750                 $r = wp_untrash_comment( $comment );
     750                $result = wp_untrash_comment( $comment );
    751751
    752752                // Undo trash, not in Trash.
     
    759759                }
    760760
    761                 $r = wp_spam_comment( $comment );
     761                $result = wp_spam_comment( $comment );
    762762        } elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {
    763763                if ( 'spam' !== $status ) {
     
    765765                }
    766766
    767                 $r = wp_unspam_comment( $comment );
     767                $result = wp_unspam_comment( $comment );
    768768
    769769                // Undo spam, not in spam.
     
    772772                }
    773773        } elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {
    774                 $r = wp_delete_comment( $comment );
     774                $result = wp_delete_comment( $comment );
    775775        } else {
    776776                wp_die( -1 );
    777777        }
    778778
    779         if ( $r ) {
     779        if ( $result ) {
    780780                // Decide if we need to send back '1' or a more complicated response including page links and comment counts.
    781781                _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
     
    985985
    986986        if ( ! $comment ) {
    987                 $x = new WP_Ajax_Response(
     987                $response = new WP_Ajax_Response(
    988988                        array(
    989989                                'what' => 'comment',
     
    995995                        )
    996996                );
    997                 $x->send();
     997                $response->send();
    998998        }
    999999
     
    10171017
    10181018        if ( is_wp_error( $result ) ) {
    1019                 $x = new WP_Ajax_Response(
     1019                $response = new WP_Ajax_Response(
    10201020                        array(
    10211021                                'what' => 'comment',
     
    10231023                        )
    10241024                );
    1025                 $x->send();
     1025                $response->send();
    10261026        }
    10271027
     
    10511051        }
    10521052
    1053         $names = explode( ',', wp_unslash( $_POST['newcat'] ) );
    1054         $x    = new WP_Ajax_Response();
    1055 
    1056         foreach ( $names as $cat_name ) {
    1057                 $cat_name = trim( $cat_name );
    1058                 $slug     = sanitize_title( $cat_name );
     1053        $names    = explode( ',', wp_unslash( $_POST['newcat'] ) );
     1054        $response = new WP_Ajax_Response();
     1055
     1056        foreach ( $names as $category_name ) {
     1057                $category_name = trim( $category_name );
     1058                $slug          = sanitize_title( $category_name );
    10591059
    10601060                if ( '' === $slug ) {
     
    10621062                }
    10631063
    1064                 $cat_id = wp_insert_term( $cat_name, 'link_category' );
    1065 
    1066                 if ( ! $cat_id || is_wp_error( $cat_id ) ) {
     1064                $category_id = wp_insert_term( $category_name, 'link_category' );
     1065
     1066                if ( ! $category_id || is_wp_error( $category_id ) ) {
    10671067                        continue;
    10681068                } else {
    1069                         $cat_id = $cat_id['term_id'];
    1070                 }
    1071 
    1072                 $cat_name = esc_html( $cat_name );
    1073 
    1074                 $x->add(
     1069                        $category_id = $category_id['term_id'];
     1070                }
     1071
     1072                $category_name = esc_html( $category_name );
     1073
     1074                $response->add(
    10751075                        array(
    10761076                                'what'     => 'link-category',
    1077                                 'id'       => $cat_id,
    1078                                 '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>",
     1077                                'id'       => $category_id,
     1078                                'data'     => "<li id='link-category-$category_id'><label for='in-link-category-$category_id' class='selectit'><input value='" . esc_attr( $category_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$category_id'/> $category_name</label></li>",
    10791079                                'position' => -1,
    10801080                        )
    10811081                );
    10821082        }
    1083         $x->send();
     1083
     1084        $response->send();
    10841085}
    10851086
     
    10991100        }
    11001101
    1101         $x = new WP_Ajax_Response();
     1102        $response = new WP_Ajax_Response();
    11021103
    11031104        $tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
     
    11191120                }
    11201121
    1121                 $x->add(
     1122                $response->add(
    11221123                        array(
    11231124                                'what' => 'taxonomy',
     
    11251126                        )
    11261127                );
    1127                 $x->send();
     1128                $response->send();
    11281129        }
    11291130
    11301131        $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
    11311132
    1132         $level     = 0;
    1133         $noparents = '';
     1133        $level      = 0;
     1134        $no_parents = '';
    11341135
    11351136        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
     
    11371138                ob_start();
    11381139                $wp_list_table->single_row( $tag, $level );
    1139                 $noparents = ob_get_clean();
     1140                $no_parents = ob_get_clean();
    11401141        }
    11411142
     
    11531154        }
    11541155
    1155         $x->add(
     1156        $response->add(
    11561157                array(
    11571158                        'what'         => 'taxonomy',
     
    11591160                        'supplemental' => array(
    11601161                                'parents'   => $parents,
    1161                                 'noparents' => $noparents,
     1162                                'noparents' => $no_parents,
    11621163                                'notice'    => $message,
    11631164                        ),
     
    11651166        );
    11661167
    1167         $x->add(
     1168        $response->add(
    11681169                array(
    11691170                        'what'         => 'term',
     
    11731174        );
    11741175
    1175         $x->send();
     1176        $response->send();
    11761177}
    11771178
     
    12771278        }
    12781279
    1279         $x = new WP_Ajax_Response();
     1280        $response = new WP_Ajax_Response();
    12801281
    12811282        ob_start();
     
    12891290        $comment_list_item = ob_get_clean();
    12901291
    1291         $x->add(
     1292        $response->add(
    12921293                array(
    12931294                        'what' => 'comments',
     
    12961297        );
    12971298
    1298         $x->send();
     1299        $response->send();
    12991300}
    13001301
     
    14271428        $comment_list_item = ob_get_clean();
    14281429
    1429         $response = array(
     1430        $response_data = array(
    14301431                'what'     => 'comment',
    14311432                'id'       => $comment->comment_ID,
     
    14341435        );
    14351436
    1436         $counts                   = wp_count_comments();
    1437         $response['supplemental'] = array(
     1437        $counts = wp_count_comments();
     1438
     1439        $response_data['supplemental'] = array(
    14381440                'in_moderation'        => $counts->moderated,
    14391441                'i18n_comments_text'   => sprintf(
     
    14501452
    14511453        if ( $comment_auto_approved ) {
    1452                 $response['supplemental']['parent_approved'] = $parent->comment_ID;
    1453                 $response['supplemental']['parent_post_id']  = $parent->comment_post_ID;
    1454         }
    1455 
    1456         $x = new WP_Ajax_Response();
    1457         $x->add( $response );
    1458         $x->send();
     1454                $response_data['supplemental']['parent_approved'] = $parent->comment_ID;
     1455                $response_data['supplemental']['parent_post_id']  = $parent->comment_post_ID;
     1456        }
     1457
     1458        $response = new WP_Ajax_Response();
     1459        $response->add( $response_data );
     1460        $response->send();
    14591461}
    14601462
     
    15041506        $comment_list_item = ob_get_clean();
    15051507
    1506         $x = new WP_Ajax_Response();
    1507 
    1508         $x->add(
     1508        $response = new WP_Ajax_Response();
     1509
     1510        $response->add(
    15091511                array(
    15101512                        'what'     => 'edit_comment',
     
    15151517        );
    15161518
    1517         $x->send();
     1519        $response->send();
    15181520}
    15191521
     
    15761578
    15771579        foreach ( (array) $item_ids as $menu_item_id ) {
    1578                 $menu_obj = get_post( $menu_item_id );
    1579 
    1580                 if ( ! empty( $menu_obj->ID ) ) {
    1581                         $menu_obj        = wp_setup_nav_menu_item( $menu_obj );
    1582                         $menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title;
    1583                         $menu_obj->label = $menu_obj->title; // Don't show "(pending)" in ajax-added items.
    1584                         $menu_items[]    = $menu_obj;
     1580                $menu_object = get_post( $menu_item_id );
     1581
     1582                if ( ! empty( $menu_object->ID ) ) {
     1583                        $menu_object        = wp_setup_nav_menu_item( $menu_object );
     1584                        $menu_object->title = empty( $menu_object->title ) ? __( 'Menu Item' ) : $menu_object->title;
     1585                        $menu_object->label = $menu_object->title; // Don't show "(pending)" in ajax-added items.
     1586                        $menu_items[]       = $menu_object;
    15851587                }
    15861588        }
     
    16151617function wp_ajax_add_meta() {
    16161618        check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
    1617         $c    = 0;
    1618         $pid = (int) $_POST['post_id'];
    1619         $post = get_post( $pid );
     1619        $count   = 0;
     1620        $post_id = (int) $_POST['post_id'];
     1621        $post    = get_post( $post_id );
    16201622
    16211623        if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) {
    1622                 if ( ! current_user_can( 'edit_post', $pid ) ) {
     1624                if ( ! current_user_can( 'edit_post', $post_id ) ) {
    16231625                        wp_die( -1 );
    16241626                }
     
    16321634                        $post_data                = array();
    16331635                        $post_data['action']      = 'draft'; // Warning fix.
    1634                         $post_data['post_ID']     = $pid;
     1636                        $post_data['post_ID']     = $post_id;
    16351637                        $post_data['post_type']   = $post->post_type;
    16361638                        $post_data['post_status'] = 'draft';
     
    16441646                        );
    16451647
    1646                         $pid = edit_post( $post_data );
    1647 
    1648                         if ( $pid ) {
    1649                                 if ( is_wp_error( $pid ) ) {
    1650                                         $x = new WP_Ajax_Response(
     1648                        $post_id = edit_post( $post_data );
     1649
     1650                        if ( $post_id ) {
     1651                                if ( is_wp_error( $post_id ) ) {
     1652                                        $response = new WP_Ajax_Response(
    16511653                                                array(
    16521654                                                        'what' => 'meta',
    1653                                                         'data' => $pid,
     1655                                                        'data' => $post_id,
    16541656                                                )
    16551657                                        );
    1656                                         $x->send();
     1658                                        $response->send();
    16571659                                }
    16581660
    1659                                 $mid = add_meta( $pid );
    1660                                 if ( ! $mid ) {
     1661                                $meta_id = add_meta( $post_id );
     1662
     1663                                if ( ! $meta_id ) {
    16611664                                        wp_die( __( 'Please provide a custom field value.' ) );
    16621665                                }
     
    16651668                        }
    16661669                } else {
    1667                         $mid = add_meta( $pid );
    1668                         if ( ! $mid ) {
     1670                        $meta_id = add_meta( $post_id );
     1671
     1672                        if ( ! $meta_id ) {
    16691673                                wp_die( __( 'Please provide a custom field value.' ) );
    16701674                        }
    16711675                }
    16721676
    1673                 $meta = get_metadata_by_mid( 'post', $mid );
    1674                 $pid = (int) $meta->post_id;
    1675                 $meta = get_object_vars( $meta );
    1676 
    1677                 $x = new WP_Ajax_Response(
     1677                $meta    = get_metadata_by_mid( 'post', $meta_id );
     1678                $post_id = (int) $meta->post_id;
     1679                $meta    = get_object_vars( $meta );
     1680
     1681                $response = new WP_Ajax_Response(
    16781682                        array(
    16791683                                'what'         => 'meta',
    1680                                 'id'           => $mid,
    1681                                 'data'         => _list_meta_row( $meta, $c ),
     1684                                'id'           => $meta_id,
     1685                                'data'         => _list_meta_row( $meta, $count ),
    16821686                                'position'     => 1,
    1683                                 'supplemental' => array( 'postid' => $pid ),
     1687                                'supplemental' => array( 'postid' => $post_id ),
    16841688                        )
    16851689                );
    16861690        } else { // Update?
    1687                 $mid  = (int) key( $_POST['meta'] );
    1688                 $key   = wp_unslash( $_POST['meta'][ $mid ]['key'] );
    1689                 $value = wp_unslash( $_POST['meta'][ $mid ]['value'] );
     1691                $meta_id = (int) key( $_POST['meta'] );
     1692                $key     = wp_unslash( $_POST['meta'][ $meta_id ]['key'] );
     1693                $value   = wp_unslash( $_POST['meta'][ $meta_id ]['value'] );
    16901694
    16911695                if ( '' === trim( $key ) ) {
     
    16931697                }
    16941698
    1695                 $meta = get_metadata_by_mid( 'post', $mid );
     1699                $meta = get_metadata_by_mid( 'post', $meta_id );
    16961700
    16971701                if ( ! $meta ) {
     
    17081712
    17091713                if ( $meta->meta_value !== $value || $meta->meta_key !== $key ) {
    1710                         $u = update_metadata_by_mid( 'post', $mid, $value, $key );
    1711                         if ( ! $u ) {
     1714                        $update_result = update_metadata_by_mid( 'post', $meta_id, $value, $key );
     1715
     1716                        if ( ! $update_result ) {
    17121717                                wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
    17131718                        }
    17141719                }
    17151720
    1716                 $x = new WP_Ajax_Response(
     1721                $response = new WP_Ajax_Response(
    17171722                        array(
    17181723                                'what'         => 'meta',
    1719                                 'id'           => $mid,
    1720                                 'old_id'       => $mid,
     1724                                'id'           => $meta_id,
     1725                                'old_id'       => $meta_id,
    17211726                                'data'         => _list_meta_row(
    17221727                                        array(
    17231728                                                'meta_key'   => $key,
    17241729                                                'meta_value' => $value,
    1725                                                 'meta_id'    => $mid,
     1730                                                'meta_id'    => $meta_id,
    17261731                                        ),
    17271732                                        $c
     
    17321737                );
    17331738        }
    1734         $x->send();
     1739
     1740        $response->send();
    17351741}
    17361742
     
    17581764                wp_die( 0 );
    17591765        } elseif ( is_wp_error( $user_id ) ) {
    1760                 $x = new WP_Ajax_Response(
     1766                $response = new WP_Ajax_Response(
    17611767                        array(
    17621768                                'what' => 'user',
     
    17641770                        )
    17651771                );
    1766                 $x->send();
     1772                $response->send();
    17671773        }
    17681774
     
    17721778        $role = current( $user_object->roles );
    17731779
    1774         $x = new WP_Ajax_Response(
     1780        $response = new WP_Ajax_Response(
    17751781                array(
    17761782                        'what'         => 'user',
     
    17871793                )
    17881794        );
    1789         $x->send();
     1795        $response->send();
    17901796}
    17911797
     
    20812087
    20822088        $last = wp_check_post_lock( $post_id );
     2089
    20832090        if ( $last ) {
    20842091                $last_user      = get_userdata( $last );
     
    22622269        }
    22632270
    2264         $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>';
    2265         $alt  = '';
     2271        $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>';
     2272        $alternate = '';
    22662273        foreach ( $posts as $post ) {
    2267                 $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
    2268                 $alt   = ( 'alternate' === $alt ) ? '' : 'alternate';
     2274                $title     = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
     2275                $alternate = ( 'alternate' === $alternate ) ? '' : 'alternate';
    22692276
    22702277                switch ( $post->post_status ) {
     
    22912298                }
    22922299
    2293                 $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>';
     2300                $html .= '<tr class="' . trim( 'found-posts ' . $alternate ) . '"><td class="found-radio"><input type="radio" id="found-' . $post->ID . '" name="found_post_id" value="' . esc_attr( $post->ID ) . '"></td>';
    22942301                $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";
    22952302        }
     
    23192326
    23202327                foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
    2321                         $sb = array();
     2328                        $sidebar = array();
    23222329
    23232330                        if ( ! empty( $val ) ) {
     
    23292336                                        }
    23302337
    2331                                         $sb[ $k ] = substr( $v, strpos( $v, '_' ) + 1 );
     2338                                        $sidebar[ $k ] = substr( $v, strpos( $v, '_' ) + 1 );
    23322339                                }
    23332340                        }
    2334                         $sidebars[ $key ] = $sb;
     2341                        $sidebars[ $key ] = $sidebar;
    23352342                }
    23362343
     
    26892696        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    26902697
    2691         $msg = false;
     2698        $message = false;
    26922699
    26932700        switch ( $_POST['do'] ) {
    26942701                case 'save':
    2695                         $msg = wp_save_image( $attachment_id );
    2696                         if ( ! empty( $msg->error ) ) {
    2697                                 wp_send_json_error( $msg );
     2702                        $message = wp_save_image( $attachment_id );
     2703                        if ( ! empty( $message->error ) ) {
     2704                                wp_send_json_error( $message );
    26982705                        }
    26992706
    2700                         wp_send_json_success( $msg );
     2707                        wp_send_json_success( $message );
    27012708                        break;
    27022709                case 'scale':
    2703                         $msg = wp_save_image( $attachment_id );
     2710                        $message = wp_save_image( $attachment_id );
    27042711                        break;
    27052712                case 'restore':
    2706                         $msg = wp_restore_image( $attachment_id );
     2713                        $message = wp_restore_image( $attachment_id );
    27072714                        break;
    27082715        }
    27092716
    27102717        ob_start();
    2711         wp_image_editor( $attachment_id, $msg );
     2718        wp_image_editor( $attachment_id, $message );
    27122719        $html = ob_get_clean();
    27132720
    2714         if ( ! empty( $msg->error ) ) {
     2721        if ( ! empty( $message->error ) ) {
    27152722                wp_send_json_error(
    27162723                        array(
    2717                                 'message' => $msg,
     2724                                'message' => $message,
    27182725                                'html'    => $html,
    27192726                        )
     
    27232730        wp_send_json_success(
    27242731                array(
    2725                         'message' => $msg,
     2732                        'message' => $message,
    27262733                        'html'    => $html,
    27272734                )
     
    30403047        );
    30413048
    3042         foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
    3043                 if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
    3044                         $keys[] = $t->query_var;
     3049        foreach ( get_taxonomies_for_attachments( 'objects' ) as $taxonomy ) {
     3050                if ( $taxonomy->query_var && isset( $query[ $taxonomy->query_var ] ) ) {
     3051                        $keys[] = $taxonomy->query_var;
    30453052                }
    30463053        }
     
    31623169
    31633170        if ( wp_attachment_is( 'audio', $post['ID'] ) ) {
    3164                 $changed = false;
    3165                 $id3data = wp_get_attachment_metadata( $post['ID'] );
    3166 
    3167                 if ( ! is_array( $id3data ) ) {
    3168                         $changed = true;
    3169                         $id3data = array();
     3171                $changed  = false;
     3172                $id3_data = wp_get_attachment_metadata( $post['ID'] );
     3173
     3174                if ( ! is_array( $id3_data ) ) {
     3175                        $changed  = true;
     3176                        $id3_data = array();
    31703177                }
    31713178
    31723179                foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
    31733180                        if ( isset( $changes[ $key ] ) ) {
    3174                                 $changed         = true;
    3175                                 $id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) );
     3181                                $changed          = true;
     3182                                $id3_data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) );
    31763183                        }
    31773184                }
    31783185
    31793186                if ( $changed ) {
    3180                         wp_update_attachment_metadata( $id, $id3data );
     3187                        wp_update_attachment_metadata( $id, $id3_data );
    31813188                }
    31823189        }
     
    34333440
    34343441        // Figure out what filter to run:
    3435         $type = 'file';
    3436         $ext  = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );
    3437         if ( $ext ) {
    3438                 $ext_type = wp_ext2type( $ext );
    3439                 if ( 'audio' === $ext_type || 'video' === $ext_type ) {
    3440                         $type = $ext_type;
     3442        $type      = 'file';
     3443        $extension = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );
     3444        if ( $extension ) {
     3445                $extension_type = wp_ext2type( $extension );
     3446                if ( 'audio' === $extension_type || 'video' === $extension_type ) {
     3447                        $type = $extension_type;
    34413448                }
    34423449        }
     
    49004907 */
    49014908function wp_ajax_edit_theme_plugin_file() {
    4902         $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
    4903 
    4904         if ( is_wp_error( $r ) ) {
     4909        $edit_result = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
     4910
     4911        if ( is_wp_error( $edit_result ) ) {
    49054912                wp_send_json_error(
    49064913                        array_merge(
    49074914                                array(
    4908                                         'code'    => $r->get_error_code(),
    4909                                         'message' => $r->get_error_message(),
     4915                                        'code'    => $edit_result->get_error_code(),
     4916                                        'message' => $edit_result->get_error_message(),
    49104917                                ),
    4911                                 (array) $r->get_error_data()
     4918                                (array) $edit_result->get_error_data()
    49124919                        )
    49134920                );
Note: See TracChangeset for help on using the changeset viewer.