Modifications To WordPress

I can never leave things alone, and that includes my WordPress installation. I make a few changes to WordPress to get to to suit my needs and preferences a bit better than it does ‘out of the box’. For example, I don’t used the advanced editor (TinyMCE) because I prefer doing my markup by hand. But I do use some of the simple editor buttons on the basic editor, and I change them to better suit me – for example, I have the ‘img’ button prompt me not only for the URL and alt text, but also the width, height, and border, because I always include those. So I thought I’d share the diffs between WP2.5.1 and my changes, simple as they are. As well as some tweaks to the Sociable and reCAPTCHA plug-ins.

I’ll put this under a cut since it is long, and not interesting to most I suspect. Though I hope that this might encourage other WP users to try getting their hands dirty and tweaking things a bit.

Changing the editor buttons requires changes in two places:
wordpress/wp-includes/js/quicktags.js:

35a36
> // Modified by MegaZone / MZ
37c38
< new edButton('ed_strong'
---
> new edButton('ed_bold'
39,40c40,41
< ,'<strong>'
< ,'</strong>'
---
> ,'<b>'
> ,'</b>'
43a45
> // Modified by MegaZone / MZ
45c47
< new edButton('ed_em'
---
> new edButton('ed_italics'
47,48c49,50
< ,'<em>'
< ,'</em>'
---
> ,'<i>'
> ,'</i>'
51a54,89
> // Added by MegaZone / MZ
> edButtons[edButtons.length] =
> new edButton('ed_underline'
> ,'u'
> ,'<u>'
> ,'</u>'
> ,''
> );
>
> // Added by MegaZone / MZ
> edButtons[edButtons.length] =
> new edButton('ed_strikethrough'
> ,'s'
> ,'<s>'
> ,'</s>'
> ,'s'
> );
>
> // Added by MegaZone / MZ
> edButtons[edButtons.length] =
> new edButton('ed_big'
> ,'big'
> ,'<big>'
> ,'</big>'
> ,''
> );
>
> // Added by MegaZone / MZ
> edButtons[edButtons.length] =
> new edButton('ed_small'
> ,'small'
> ,'<small>'
> ,'</small>'
> ,''
> );
>
68c106
<
---
> /* Commented out by MegaZone / MZ
83a122
> */
117a157,165
> // Added by MegaZone / MZ
> edButtons[edButtons.length] =
> new edButton('ed_pre'
> ,'pre'
> ,'<pre>'
> ,'</pre>'
> ,''
> );
>
385a434,436
>                               + '" width="' + prompt(quicktagsL10n.enterImageWidth, '')
>                               + '" height="' + prompt(quicktagsL10n.enterImageHeight, '')
>                               + '" border="' + prompt(quicktagsL10n.enterImageBorder, '') 

wordpress/wp-includes/script-loader.php:

27,28c27,31
<                       'enterImageDescription' => __('Enter a description of the image')
<               ) );
---
>                       'enterImageDescription' => __('Enter a description of the image'),
>                         'enterImageWidth' => __('Enter image width'),
>                         'enterImageHeight' => __('Enter image height'),
>                         'enterImageBorder' => __('Enter image border weight')
>                       ) ); // MegaZone / MZ added image attributes

Another thing that I tweak is WP’s formatting code. I like having it check the XHTML nesting, etc. But for a while it drove me crazy because it would ‘correct’ perfectly valid XHTML, and often would produce invalid XHTML in the process! In the end I found that commenting out just one line and editing one other in formatting.php solved nearly all of the issues I was having.

wordpress/wp-includes/formatting.php:

64c64
<       $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
---
>       //MegaZone / MZ Removed $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
65a66
>       $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|fieldset|map|area|blockquote|address|math|style|p|h[1-6]|hr)'; //MegaZone / MZ edited list

With those small tweaks, I find WP to be a lot more usable for me. Someday I may get around to writing a plug-in to allow changing the buttons on the basic editor (I haven’t seen one, but if there is one out there let me know), but for now it is easy enough to re-apply these tweaks when I upgrade.

Now, I also make tweaks to two of my plug-ins – reCAPTCHA and Sociable. First up, reCAPTCHA. I love this plug-in, and it does an amazing job of controlling the spam comments I receive. But it had one flaw that annoyed me – it produces invalid XHTML. I strive to keep things on the site valid, so having a plug-in that produced invalid XHTML just didn’t sit well with me. I found one patch in their support group, but it had a flaw, so I used that as a starting point and created a new patch that worked correctly. That was on 2.6, and I re-implemented it on 2.7. I’ve submitted both of them back to reCAPTCHA, but they haven’t incorporated them yet, as far as I know. Oh, and one small mistake – they forgot to rev the version number in the file from 2.6 to 2.7 when they released 2.7, so I did that.

wordpress/wp-content/plugins/recaptcha/recaptcha.php:

6c6
< Version: 2.6
---
> Version: 2.7
51a52
>                       document.getElementById('submit').style.display = 'inline'; // MegaZone added
57,58c58,59
<                <style type='text/css'>#submit {display:none;}</style>
<                <input name="submit" type="submit" id="submit-alt" tabindex="6" value="Submit Comment"/>
---
>               <!-- MegaZone removed style element -->
>                <input name="submit" type="submit" id="submit-alt" tabindex="6" value="Submit Comment" />
63a65,74
> /*
> MegaZone added this function.  This will insert the style to hide the
> reCAPTCHA submit button in the header instead of the body, where it is
> invalid XHTML.  Since this disables the button even when scripting is
> turned on, there is a line of JavaScript inserted above which makes the
> button visible when scripting is on.
> */
> function recaptcha_wp_head () {
>   echo "<style type='text/css'>#submit { display: none; }</style>\n";
> }
64a76
> add_action( 'wp_head', 'recaptcha_wp_head' ); // MegaZone added
66d77
< 

And I made two really, really inconsequential changes in the name of XHTML->HTML compatibility in older browsers. I added spaces in two elements. You can really just ignore this, I was being anal.
wordpress/wp-content/plugins/recaptcha/recaptchalib.php:

125c125
<               <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
---
>               <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br />
127c127
<               <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
---
>               <input type="hidden" name="recaptcha_response_field" value="manual_challenge" />

With Sociable it was mainly an issue of appearance. I wanted to squeeze the icons into a small space, a single row at the bottom of the post. I fought with CSS for a while, but I never could quite get what I wanted, because of the underlaying XHTML. The plug-in normally creates the list of icons as an XHTML unordered list, with each icon within its own list item element. Trying to get it so the icons were in one solid row, with no gaps between them, just defeated me in CSS. But I knew I could make it work with small changes to the XHTML, to remove those unwanted list elements. In the process I also fixed one small bug in one of the site links in the plug-in.

wordpress/wp-content/plugins/sociable/sociable.php:

97c97
<               'url' => 'http://bluedot.us/Authoring.aspx?>u=PERMALINK&title=TITLE',
---
>               'url' => 'http://bluedot.us/Authoring.aspx?u=PERMALINK&title=TITLE',
501c501
< );
---
> ); /* Blue Dot URL fixed - MegaZone / MZ  modded */
633c633,635
<       $html .= "\n</span>\n<ul>\n";
---
>
>       /* $html .= "\n</span>\n<ul>\n"; MegaZone / MZ  modded */
>       $html .= "\n</span>\n";
653,654c655,656
<               $link = "<li>";
<               $link .= "<a rel=\"nofollow\" target=\"_blank\" href=\"$url\" title=\"$description\">";
---
>               /* $link = "<li>"; MegaZone / MZ modded */
>               $link = "<a rel=\"nofollow\" target=\"_blank\" href=\"$url\" title=\"$description\">"; /* MegaZone / MZ modded */
659c661,662
<               $link .= "</a></li>";
---
>               /* $link .= "</a></li>"; MegaZone / MZ modded */
>                 $link .= "</a>";
661c664,665
<               $html .= "\t".apply_filters('sociable_link',$link)."\n";
---
>               /* $html .= "\t".apply_filters('sociable_link',$link)."\n"; MegaZone / MZ modded */
>                 $html .= "".apply_filters('sociable_link',$link);
664c668,669
<       $html .= "</ul>\n</div>\n";
---
>       /* $html .= "</ul>\n</div>\n"; MegaZone / MZ modded */
>         $html .= "\n</div>\n";

And I do make some changes to the CSS as well, though some of them are just me being anal and adding units.

wordpress/wp-content/plugins/sociable/sociable.css:

1c1,2
< div.sociable { margin: 16px 0; }
---
> /* Modified by MegaZone */
> div.sociable { margin: 16px 0px; }
4c5
< span.sociable_tagline span { display: none; width: 14em; }
---
> span.sociable_tagline span { display: none; width: 28em; }
8,10c9,11
<       top: -5em;
<       background: #ffe;
<       border: 1px solid #ccc;
---
>       top: -3em;
>       background: #ffffee;
>       border: 1px solid #cccccc;
19,20c20,21
<       margin: 0 !important;
<       padding: 0 !important;
---
>       margin: 0px !important;
>       padding: 0px !important;
26c27
<       margin: 0;
---
>       margin: 0px;
34,36c35,37
<       border: 0;
<       margin: 0;
<       padding: 0;
---
>       border: 0px;
>       margin: 0px;
>       padding: 0px;
40,42c41,43
<       opacity: .4;
<       -moz-opacity: .4;
<       filter: alpha(opacity=40);
---
>       opacity: .6;
>       -moz-opacity: .6;
>       filter: alpha(opacity=60);

And that’s it. Just a handful of simple changes to make the platform work more to my liking. Very minor changes really. I know a lot of WP users are nervous about playing around in the code, but it isn’t that bad. Remember to make a backup of the files before you edit them, and if you have a problem just revert back. If you’re going to do anything major, backup your sites DB before trying the changes. You can always restore if you really blow things up – but that’s not easy to do.

About MegaZone

MegaZone is the Editor of Gizmo Lovers and the chief contributor. He's been online since 1989 and active in several generations of 'social media' - mailing lists, USENet groups, web forums, and since 2003, blogging.    MegaZone has a presence on several social platforms: Google+ / Facebook / Twitter / LinkedIn / LiveJournal / Web.    You can also follow Gizmo Lovers on other sites: Blog / Google+ / Facebook / Twitter.
This entry was posted in Blogs, General Tech, Site Updates and tagged , , , . Bookmark the permalink.