<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[53719] trunk/src: Coding Standards: Improve variable names in `wp-trackback.php`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/53719">53719</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/53719","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-07-19 14:00:35 +0000 (Tue, 19 Jul 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/changeset/172">[172]</a>, <a href="https://core.trac.wordpress.org/changeset/637">[637]</a>, <a href="https://core.trac.wordpress.org/changeset/1616">[1616]</a>,
See <a href="https://core.trac.wordpress.org/ticket/55647">#55647</a>, <a href="https://core.trac.wordpress.org/ticket/56244">#56244</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescommenttemplatephp">trunk/src/wp-includes/comment-template.php</a></li>
<li><a href="#trunksrcwptrackbackphp">trunk/src/wp-trackback.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescommenttemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/comment-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment-template.php 2022-07-19 13:22:31 UTC (rev 53718)
+++ trunk/src/wp-includes/comment-template.php 2022-07-19 14:00:35 UTC (rev 53719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1146,9 +1146,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_trackback_url() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( get_option( 'permalink_structure' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $trackback_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $trackback_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1156,9 +1156,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $tb_url The trackback URL.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $trackback_url The trackback URL.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return apply_filters( 'trackback_url', $tb_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'trackback_url', $trackback_url );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwptrackbackphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-trackback.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-trackback.php 2022-07-19 13:22:31 UTC (rev 53718)
+++ trunk/src/wp-trackback.php 2022-07-19 14:00:35 UTC (rev 53719)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,6 +26,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function trackback_response( $error = 0, $error_message = '' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $error ) {
</span><span class="cx" style="display: block; padding: 0 10px"> echo '<?xml version="1.0" encoding="utf-8"?' . ">\n";
</span><span class="cx" style="display: block; padding: 0 10px"> echo "<response>\n";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -45,12 +46,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $request_array = 'HTTP_POST_VARS';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $_GET['tb_id'] ) || ! $_GET['tb_id'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tb_id = explode( '/', $_SERVER['REQUEST_URI'] );
- $tb_id = (int) $tb_id[ count( $tb_id ) - 1 ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_id = explode( '/', $_SERVER['REQUEST_URI'] );
+ $post_id = (int) $post_id[ count( $post_id ) - 1 ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$tb_url = isset( $_POST['url'] ) ? $_POST['url'] : '';
-$charset = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$trackback_url = isset( $_POST['url'] ) ? $_POST['url'] : '';
+$charset = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // These three are stripslashed here so they can be properly escaped after mb_convert_encoding().
</span><span class="cx" style="display: block; padding: 0 10px"> $title = isset( $_POST['title'] ) ? wp_unslash( $_POST['title'] ) : '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,37 +82,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $blog_name = wp_slash( $blog_name );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_single() || is_page() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tb_id = $posts[0]->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_id = $posts[0]->ID;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! isset( $tb_id ) || ! (int) $tb_id ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! isset( $post_id ) || ! (int) $post_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> trackback_response( 1, __( 'I really need an ID for this to work.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( empty( $title ) && empty( $tb_url ) && empty( $blog_name ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( empty( $title ) && empty( $trackback_url ) && empty( $blog_name ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // If it doesn't look like a trackback at all.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_redirect( get_permalink( $tb_id ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_redirect( get_permalink( $post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> exit;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! empty( $tb_url ) && ! empty( $title ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! empty( $trackback_url ) && ! empty( $title ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires before the trackback is added to a post.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $tb_id Post ID related to the trackback.
- * @param string $tb_url Trackback URL.
- * @param string $charset Character Set.
- * @param string $title Trackback Title.
- * @param string $excerpt Trackback Excerpt.
- * @param string $blog_name Blog Name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $post_id Post ID related to the trackback.
+ * @param string $trackback_url Trackback URL.
+ * @param string $charset Character set.
+ * @param string $title Trackback title.
+ * @param string $excerpt Trackback excerpt.
+ * @param string $blog_name Blog name.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'pre_trackback_post', $post_id, $trackback_url, $charset, $title, $excerpt, $blog_name );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! pings_open( $tb_id ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! pings_open( $post_id ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,20 +119,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $title = wp_html_excerpt( $title, 250, '…' );
</span><span class="cx" style="display: block; padding: 0 10px"> $excerpt = wp_html_excerpt( $excerpt, 252, '…' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment_post_ID = (int) $tb_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comment_post_id = (int) $post_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> $comment_author = $blog_name;
</span><span class="cx" style="display: block; padding: 0 10px"> $comment_author_email = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment_author_url = $tb_url;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comment_author_url = $trackback_url;
</ins><span class="cx" style="display: block; padding: 0 10px"> $comment_content = "<strong>$title</strong>\n\n$excerpt";
</span><span class="cx" style="display: block; padding: 0 10px"> $comment_type = 'trackback';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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
+ )
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $dupe ) {
</span><span class="cx" style="display: block; padding: 0 10px"> trackback_response( 1, __( 'There is already a ping from that URL for this post.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $commentdata = array(
+ 'comment_post_ID' => $comment_post_id,
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $commentdata += compact(
+ 'comment_author',
+ 'comment_author_email',
+ 'comment_author_url',
+ 'comment_content',
+ 'comment_type'
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = wp_new_comment( $commentdata );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $result ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -148,5 +166,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $trackback_id Trackback ID.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'trackback_post', $trackback_id );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> trackback_response( 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>