Make WordPress Core

Changeset 53719


Ignore:
Timestamp:
07/19/2022 02:00:35 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Improve variable names in wp-trackback.php.

This fixes a Variable "$comment_post_ID" is not in valid snake_case format WPCS warning.

$comment_post_ID, while matching the database field of the same name, does not follow the WordPress coding standards, so the variable is now renamed to $comment_post_id.

Additionally, these variables are renamed for clarity:

  • $tb_id to $post_id (this was not the trackback ID)
  • $tb_url to $trackback_url

Follow-up to [172], [637], [1616],

See #55647, #56244.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r53715 r53719  
    11471147function get_trackback_url() {
    11481148        if ( get_option( 'permalink_structure' ) ) {
    1149                 $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
     1149                $trackback_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
    11501150        } else {
    1151                 $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
     1151                $trackback_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
    11521152        }
    11531153
     
    11571157         * @since 2.2.0
    11581158         *
    1159          * @param string $tb_url The trackback URL.
    1160          */
    1161         return apply_filters( 'trackback_url', $tb_url );
     1159         * @param string $trackback_url The trackback URL.
     1160         */
     1161        return apply_filters( 'trackback_url', $trackback_url );
    11621162}
    11631163
  • trunk/src/wp-trackback.php

    r53131 r53719  
    2727function trackback_response( $error = 0, $error_message = '' ) {
    2828        header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
     29
    2930        if ( $error ) {
    3031                echo '<?xml version="1.0" encoding="utf-8"?' . ">\n";
     
    4647
    4748if ( ! isset( $_GET['tb_id'] ) || ! $_GET['tb_id'] ) {
    48         $tb_id = explode( '/', $_SERVER['REQUEST_URI'] );
    49         $tb_id = (int) $tb_id[ count( $tb_id ) - 1 ];
     49        $post_id = explode( '/', $_SERVER['REQUEST_URI'] );
     50        $post_id = (int) $post_id[ count( $post_id ) - 1 ];
    5051}
    5152
    52 $tb_url = isset( $_POST['url'] ) ? $_POST['url'] : '';
    53 $charset = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
     53$trackback_url = isset( $_POST['url'] ) ? $_POST['url'] : '';
     54$charset       = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
    5455
    5556// These three are stripslashed here so they can be properly escaped after mb_convert_encoding().
     
    8283
    8384if ( is_single() || is_page() ) {
    84         $tb_id = $posts[0]->ID;
     85        $post_id = $posts[0]->ID;
    8586}
    8687
    87 if ( ! isset( $tb_id ) || ! (int) $tb_id ) {
     88if ( ! isset( $post_id ) || ! (int) $post_id ) {
    8889        trackback_response( 1, __( 'I really need an ID for this to work.' ) );
    8990}
    9091
    91 if ( empty( $title ) && empty( $tb_url ) && empty( $blog_name ) ) {
     92if ( empty( $title ) && empty( $trackback_url ) && empty( $blog_name ) ) {
    9293        // If it doesn't look like a trackback at all.
    93         wp_redirect( get_permalink( $tb_id ) );
     94        wp_redirect( get_permalink( $post_id ) );
    9495        exit;
    9596}
    9697
    97 if ( ! empty( $tb_url ) && ! empty( $title ) ) {
     98if ( ! empty( $trackback_url ) && ! empty( $title ) ) {
    9899        /**
    99100         * Fires before the trackback is added to a post.
     
    101102         * @since 4.7.0
    102103         *
    103          * @param int    $tb_id     Post ID related to the trackback.
    104          * @param string $tb_url    Trackback URL.
    105          * @param string $charset   Character Set.
    106          * @param string $title     Trackback Title.
    107          * @param string $excerpt   Trackback Excerpt.
    108          * @param string $blog_name Blog Name.
     104         * @param int    $post_id       Post ID related to the trackback.
     105         * @param string $trackback_url Trackback URL.
     106         * @param string $charset       Character set.
     107         * @param string $title         Trackback title.
     108         * @param string $excerpt       Trackback excerpt.
     109         * @param string $blog_name     Blog name.
    109110         */
    110         do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name );
     111        do_action( 'pre_trackback_post', $post_id, $trackback_url, $charset, $title, $excerpt, $blog_name );
    111112
    112113        header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
    113114
    114         if ( ! pings_open( $tb_id ) ) {
     115        if ( ! pings_open( $post_id ) ) {
    115116                trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
    116117        }
     
    119120        $excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
    120121
    121         $comment_post_ID      = (int) $tb_id;
     122        $comment_post_id      = (int) $post_id;
    122123        $comment_author       = $blog_name;
    123124        $comment_author_email = '';
    124         $comment_author_url   = $tb_url;
     125        $comment_author_url   = $trackback_url;
    125126        $comment_content      = "<strong>$title</strong>\n\n$excerpt";
    126127        $comment_type         = 'trackback';
    127128
    128         $dupe = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url ) );
     129        $dupe = $wpdb->get_results(
     130                $wpdb->prepare(
     131                        "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s",
     132                        $comment_post_id,
     133                        $comment_author_url
     134                )
     135        );
     136
    129137        if ( $dupe ) {
    130138                trackback_response( 1, __( 'There is already a ping from that URL for this post.' ) );
    131139        }
    132140
    133         $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type' );
     141        $commentdata = array(
     142                'comment_post_ID' => $comment_post_id,
     143        );
     144
     145        $commentdata += compact(
     146                'comment_author',
     147                'comment_author_email',
     148                'comment_author_url',
     149                'comment_content',
     150                'comment_type'
     151        );
    134152
    135153        $result = wp_new_comment( $commentdata );
     
    149167         */
    150168        do_action( 'trackback_post', $trackback_id );
     169
    151170        trackback_response( 0 );
    152171}
Note: See TracChangeset for help on using the changeset viewer.