My First WordPress Bug

Album Cover: Crash

"You wear nothing, but you wear it so well."
Dave Matthews Band / Crash Into Me

Posted on January 10, 2008 12:01 AM in Web Development
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

I was browsing through the functions.php file that comes with WordPress 2.3.2 tonight, and I spotted this function:

function xmlrpc_getposttitle($content) {
 global $post_default_title;
 if ( preg_match('/<title>(.+?)</title>/is', $content, $matchtitle) ) {
  $post_title = $matchtitle[0];
  $post_title = preg_replace('/<title>/si', '', $post_title);
  $post_title = preg_replace('/</title>/si', '', $post_title);
 } else {
  $post_title = $post_default_title;
 }
 return $post_title;
}

The two calls to preg_replace() immediately stood out, and upon closer inspection I realized that they are completely unnecessary.

Since preg_match(), which is called as part of the containing if statement, will store "the text that matched the first captured parenthesized subpattern" in $matchtitle[1], the two calls to preg_replace() can be removed completely as long as the following line:

$post_title = $matchtitle[0];

...is changed to:

$post_title = $matchtitle[1];

I just created a simplified test case and verified it, so I followed that up with a WordPress bug. I guess we'll see what happens.

Comments

manual Blog commenting on September 08, 2016 at 4:11 AM:

Much obliged for this incredible post, i discover it exceptionally fascinating and extremely well thoroughly considered and set up together. I anticipate perusing your work later on.

Permalink

تركيبات on April 07, 2017 at 9:36 AM:

I have a mission that Iím just now working on, and I have been at the look out for such information.

Permalink

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.

Name:

Email Address:

Website:

Comments:

Check this box if you hate spam.