Categories
WordPress

Patch: Balancing pre-‘more’ tags

One of my nits about WP, from my original formatting problems post, was that despite balancing tags for an entire post, WP wouldn’t do so for text appearing before a <!–more–> tag. Others have noted this in the support forums, and it was reported as bug 0000178, titled “WP doesn’t close tags when breaking a page with <!–more–>”. This fix is actually quite simple.

Categories
WordPress

Patch: Fixing balanceTags()

Continued from my previous post in which I examined, and provided examples for, various problems related to the WordPress core function balanceTags(), here’s an explanation of the changes I made to the function.

First, here is a copy of the original balanceTags() function.

Here is a copy of the modified balanceTags() function.

Here is a diff of the changes to the file wp-includes/functions-formatting.php diff of the changes to the file wp-includes/functions-formatting.php (modified from and then compared against the latest version as obtained from CVS for WP 1.3).

Here’s my justification for the changes I made. The first of my changes takes place early, in the while() where it iterates through all the functions in the text. The remaining fixes are in the function related to finding an open tag. These fixes address all issues I am aware of with the balanceTags() function (except for situations I mention at the very end).

Categories
WordPress

Examining balanceTags()

Prompted by WP Patch Day, I felt compelled to try to patch a bug with WordPress.

I choose one that has already caused me numerous headaches, bug 0000053, entitled “WordPress deletes some text when HTML tags incorrectly nested”.

In a nutshell… In the Admin sections “Options” menu, “Writing” submenu, a checkbutton exists to indicate if “WordPress should correct invalidly nested XHTML automatically”. This setting is active by default.

The thing is, not only does it not always correct invalidly nested XHTML, it can actually delete some of the text in the post. As the function operates on the post as the post is inserted into the database, that text is gone.

Categories
WordPress

Example: Output for Hide or Cut Plugin demo

This post demonstrates the Hide or Cut Post Text plugin. The content that generates this post can be found in the previous post.

Pay attention to the alphabet:

A

B


C

D

E (note that you’ll never see that C and D are actually in the post content)

F


G

H

I (note that G and H were cut from the non-permalink pages; click the default link to jump to G in the post’s permlink page)

J

K

L

M

N (note that L is only available on the permalink page and M is only available on non-permalink pages — you’ll never see the two letters on the same page…)

O

P


Q

R

S

T

U

V

W

X

Y

Z

Note that each cut link points to a unique anchor in the permalink page for the post.

I hope this example has sufficiently demonstrated the usage of the Hide or Cut Post Text plugin.

Categories
WordPress

Example: Post content for Hide or Cut Post Text demo

Below is the post content for an example post to demonstrate the use and results of the Hide or Cut Post Text plugin. The results of what the following post would yield are in the next post.

Categories
Package/plugin/module WordPress

Plugin: Hide or Cut Post Text

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/hide-or-cut-post-text
Name:
Hide or Cut Post Text
Author:
Scott Reilly
Version:
1.2
Last updated:
11 April 2005
Description:

Hide (so no one, or only users above a certain userlevel, can see) or cut (so only viewable on post’s permalink page) portion(s) of a post’s text. Link text for cuts can be defined per-cut or omitted, and if used, cut links are uniquely anchored. Quicktag buttons for the new tags are automatically created (but can be disabled).

Categories
Package/plugin/module WordPress

Plugin: Random File

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/random-file
Name:
Random File
Author:
Scott Reilly
Version:
1.0
Last updated:
25 March 2005
Description:

Retrieve the name of a randomly chosen file in a given directory. Useful for displaying random images/logos or including text from random files onto your site (writing excerpts, multi-line quotes, etc).

Categories
Package/plugin/module WordPress

Plugin: Auto-hyperlink URLs

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/auto-hyperlink-urls
Name:
Auto-hyperlink URLs
Author:
Scott Reilly
Version:
2.01
Last updated:
10 October 2004
Description:

Auto-hyperlink text URLs in post content and comment text to the URL they reference. Does NOT try to hyperlink already hyperlinked URLs. Improves upon WordPress’s default make_clickable function, along with adding some configuration options (such as link truncation).