Walking with 1.5

Had a chance to comb through some of the latest WordPress 1.5 code (through 2005-01-05) in CVS, both in the course of a fresh install and in the course of code analysis for development of some new plugins. Spotted a few things that would benefit from improvement (nothing critical).

All of the patches mentioned below can be retrieved en masse via this zip file.

  1. File: readme.html
    • Twice mentions the wiki but never states that Codex == wiki
    • Perhaps a link to Mosquito for bug submissions?
    • Twice mentions the version of WordPress as being 1.3
    • Update the “User Levels” section to indicate that “9+ – Admin; can post as another user”
  2. File: wp-admin/post.php v1.117Problem: Drafts get filters applied to them upon saving. By their very nature drafts are incomplete, and with certain filters (i.e. balanceTags()) the premature filtering of posts in the draft state can cause problems.
    Patch: Only apply filters to post content and excerpts when a post gets set to a status other than draft. [2005-01-06-post.diff]
  3. File: wp-includes/comment-functions.php v1.9Function: get_commentdata()
    Problem: The function still searches the comment content for <trackback /> and <pingback /> to determine the comment_type, which for this function should already be available thanks to the new comment_type field.Function: get_comment_excerpt()
    Function: get_comment_text()
    Problem: Functions still parse out the old-school <pingback /> and <trackback /> tags which is now unnecessary.

    Patch: This patch file takes into account all of the patches mentioned for comment-functions.php [2005-01-05-comment-functions.diff]

  4. File: xmlrpc.php v1.36Problem: Still parses old-school <pingback /> and <trackback /> tags which is now unnecessary.
    Patch: Don’t look for those tags anymore. [2005-01-05-xmlrpc.diff]
  5. File: wp-admin/import-mt.php v1.17Problem: The import routine inserts the old-school <trackback /> tag into the comment_content instead of setting the comment_type field to “trackback”
    Patch: Set the comment_type to “trackback” instead of modifying the comment_content. [2005-01-05-import-mt.diff]
  6. File: wp-comments-post.php v1.26Problem: The new “comment_type” db field is not given the value of “comment” for comments as they are posted, thus the field is left blank.
    Patch: Set the $comment_type variable to ‘comment’ instead of to ”. [2005-01-05-wp-comments-post.diff]
  7. File: wp-admin/upgrade-functions.php v1.84Function: upgrade_130()
    Problem: Though old comments are processed to set the new comment table db field “comment_type” to “pingback” or “trackback”, actual comments themselves are not assigned “comment”
    Patch: After doing the UPDATE to assign comment_types of “pingback” and “trackback”, add another UPDATE to set any comment with a comment_type of ” to be “comment”. [2005-01-05-upgrade-functions.diff]
  8. File: wp-content/hello.php v1.3Problem: The description for the Hello, Dolly plugin says that you will see a lyric on every page but the plugins page, but that is no longer true (lyrics now also appear on the plugins page).
    Patch: Remove the last part of the statement: When enabled you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page but the plugins page. [2005-01-04-hello.diff]
  9. File: wp-includes/functions-post.php v1.22Function: get_author_name()
    Problem: The switch case for “nickname” does not have a break (and it’s the first switch case)
    Patch: Add a break.Function: get_extended()
    Problem: The PHP function explode() will return an array of as many items as can be created via the defined explode() token. When dealing with <!–more–>, however, WP only uses the 0th and 1st elements, so if a post has more than one <!–more–> defined (for whatever reason), this function will only return the post content up to the 2nd <!–more–>.

    list($main,$extended) = explode('&lt;!--more-->',$post);

    Patch: As I suggested in the already implemented patch for another place where explode() was used (bug #113), simply add a third argument of the value 2 to indicate only two elements (if that many) should appear in the final array, thus preserving all post content.

    list($main,$extended) = explode('&lt;!--more-->',$post, 2);

    Patch: This patch takes both of the above fixes into consideration, [2005-01-04-functions-post.diff]

  10. File: wp-includes/template-functions-author.php v1.16Function: get_the_author()1
    Problem: The code inefficiently does checks through multiple if()’s instead of using switch() (or even if/else if).

    if ($idmode == 'nickname') $id = $authordata->user_nickname; if ($idmode == 'login') $id = $authordata->user_login; if ($idmode == 'firstname') $id = $authordata->user_firstname; if ($idmode == 'lastname') $id = $authordata->user_lastname; if ($idmode == 'namefl') $id = $authordata->user_firstname.' '.$authordata->user_lastname; if ($idmode == 'namelf') $id = $authordata->user_lastname.' '.$authordata->user_firstname; if (!$idmode) $id = $authordata->user_nickname;

    Patch: Use a switch(), such as is already done in get_author_name():

    switch($idmode) { case "nickname": $id = $authordata->user_nickname; break; case "login": $id = $authordata->user_login; break; case "firstname": $id = $authordata->user_firstname; break; case "lastname": $id = $authordata->user_lastname; break; case "namefl": $id = $authordata->user_firstname.' '.$authordata->user_lastname; break; case "namelf": $id = $authordata->user_lastname.' '.$authordata->user_firstname; break; }


3 thoughts on “Walking with 1.5

  1. If you hadnt already noticed, I’ve link-backed to your site.. and for quite some time I was having difficulty accessing it. It seems that your domain only loads when the “www” portion of the domain is in the URI. coffee2code.com doesnt work.
    more info.. no-www.org

    Also.. on a related note about your WP code changes (#10);
    How are using Switches more effecient than multiple IF statements?
    From what I can tell, the more efficient code is the one with lesser lines of code. IF statements only have 7 lines of code whereas the switch statements have 20. Can you explain?

  2. Yeah, I have some domain name handling issues. Haven’t looked into it much though. Thanks for pointing it out.

    As for the change I suggest in #10, it isn’t using SWITCH() versus IF() that is my intent, it is that the code ALWAYS performs the 6 IF() checks, even though it will only ever match 1. That is why I also suggest that the IF()/ELSE IF() construct would be be better (that’s what it’s meant for!). Using SWITCH() is, to my mind, just as good. But more specifically, it is the same manner in which the devs handle an identical situation in get_author_name() so I suggested SWITCH() to maintain consistency.

Comments are closed.