In the newly released WordPress 2.2 the built-in widget support is likely to get most of the attention. Here are three things you as a WordPress plugin or theme developer might also find useful.
You can now set your site’s “home” and “siteurl” values in the wp-config.php file
Say you have a production site and a mirror development site. Before 2.2, if you copied the database from one to the other, you’d have to edit the database to change the url options. Now, you can set the “home” and “siteurl” options in the wp-config.php file:
define('WP_HOME', 'http://www.ilfilosofo.com');
define('WP_SITEURL', 'https://austinmatzko.com/wordpress');
That means that if you use different config files, you can dump the database from one site to the other without making any option changes. It’s going to be a big time-saver for me.
WordPress now uses PHPMailer for email
PHPMailer is a nifty mail class. You can use it independently of the
wp_mail
function (but if you do that you’ll need to include theand
class-phpmailer.php
files manually). A simpler way to use it is to access the $phpmailer object as it’s passed by reference to the ‘phpmailer_init’ action hook.
class-smtp.php
For example, say you want to add an attachment to an email you’re about to send using
wp_mail
. You would set up a callback function to add the attachment, using PHPMailer’s AddAttachment method:
function lets_add_an_attachment(&$phpmailer) {
$phpmailer->AddAttachment('/path/to/attachment/picture.jpg');
}
Then hook in the callback function:
add_action('phpmailer_init', 'lets_add_an_attachment');
If that doesn’t seem easy enough, you should try using PHP’s
mail
function (for whichwp_mail
used to be basically just a wrapper) to send an attachment. First, you’d need to read in the file to be attached, encode it to base 64, split it up into chunks, then pass it to the header parameter, of course setting the correct Content-Type and MIME-Version and indicating the boundary. PHPMailer takes care of that headache for you.WordPress Now Includes the jQuery JavaScript library
WordPress has been including the robust Prototype and Scriptaculous JavaScript libraries since 2.1 for various admin panel JS effects. But now the admin panel is being transferred to jQuery. jQuery has the advantage of packing a lot of cool features into a small size (19kb).
Although the only place jQuery appears in 2.2 is the new Blogger importer, you can use jQuery on any WordPress page. All you have to do is call
wp_enqueue_script('jquery');
before the page’s header prints.jQuery as bundled with WordPress is running in “no-conflict” mode. That’s so that jQuery will play nice with Prototype, which would otherwise conflict over the ‘$’ function. Whereas normally you could use ‘$’ as a shortcut for ‘jQuery,’ in no-conflict mode you either need to call jQuery directly or create your own alias, like so:
(from then on you could use
var wpJ = jQuery.noConflict();
wpJ
instead ofjQuery
)One of my favorite features of jQuery is its compact way of selecting DOM elements. For example, the following code finds all text input fields named “s” (i.e. the WordPress search fields), sets their value to “Search text,” then clears their value if someone clicks in them.
jQuery('input[@type="text"][@name="s"]').each(
function() {
jQuery(this).attr('value','Search text');
jQuery(this).focus(function() {jQuery(this).attr('value','')});
}
);
Elegant, huh?
10 Comments
That config file feature is awesome. I recently switched hosts and had a hard time testing my installation because it would have been a pain in the *** to manually edit the database and then have to switch back with the nameservers finally kicked in.
The new constants seem like a great idea… can’t get them to work though, and can’t find any docs
Do they work if the site’s already been setup (i.e. if those option values have already been set in the DB)?
Simon,
You just define the constants in your wp-config.php file, and they override any existing db option values.
wp_mail() is broken, though. It’s impossible to set the Content-Type. _Every_ plugin sending non-text mails is broken.
Morty,
For anything beyond a plain-text message, you have to use the PHPMailer API. So to set the content-type (although you probably won’t need to do that directly now), you would do something like
$phpmailer->ContentType = "text/plain";
Actually it’s
$phpmailer->IsHTML(true)
but I wrote a plugin to fix the wp_mail() – function. One good reason to use mp_mail() instead of the phpmailer API is, that it’s a plugable function, and it might be overwritten by a plugin. E.g. because the Admin wants to use a totally different way of sending mails.
Great info. I’m disappointed that they didn’t actually include the phpmailer and smtp classes in the build for folks who wish to utilize them for plugin and theme use. Oh well!
Hi,
When will you be updating your plug-in to support WP 2.2. I’ve found that your db backup plugin, when activated, causes user registration emails to be sent with a blank body in the message. Do you have a fix or suggestions for making a fix for this?
Thanks,
Aaron
http://www.takbax.com
Aaron,
If you’re having trouble with the wp-db-backup plugin, please open a ticket in my support forum (and let me know which version of the plugin you’re using).
Thanks
Using PHPmail was a very importent step for wordpress! Hope the wp-guys take the innovativ way always in the future!!
28 Trackbacks
[…] Ilfiloso clarifies in comments and on his very cool post that delves deeper into things developers will like about WP 2.2, that jQuery is still not […]
[…] WordPress 2.2: Three Things Developers Will Like. Also check out Aaron’s 10 things you should know about 2.2. « 2.2 Dropped Comment » […]
[…] : http://technosailor.com/10-things-you-should-know-about-wordpress-22/ http://www.ilfilosofo.com/blog/2007/05/16/wordpress-22-three-things-developers-will-like/ : http://trac.wordpress.org/chan…ranches%2F2.2&new=5464 […]
[…] Con la salida de la nueva versión hay un par de entradas dignas de comentar. Por un lado 3 cosas de wp 2.2 que les gustarán a los desarrolladores, por el otro lado se hace un recuento de diez características que deberíamos conocer de la nueva […]
[…] Relacionado: Diez características que deberíamos conocer 3 cosas de wp 2.2 que les gustarán a los desarrolladores […]
[…] Es más, los desarrolladores hemos encontrado 3 cosas que nos gustan de WordPress 2.2 […]
[…] WordPress 2.2: Three Things Developers Will Like […]
[…] 2.2可以在wp-config.php中设置“home”、“siteurl” 两个值,使搬家变得很简单。 Tags: dreamhost, worpress Related […]
[…] 2.2 di WordPress sul mio server a carbone, indago un attimo sulle novit di questa versione e noto tre-dici cosette abbastanza interessanti, che, forse, potranno interessare eventualmente anche voi che […]
[…] see Aaron Brazell’s 10 Things You Should Know About 2.2, Ilfilosofo’s WordPress 2.2: Three Things Developers Will Like, and Wired’s WordPress Update Integrates Widgets, Boosts […]
[…] being said, there is one compelling feature that I found at Il Filosofo: You can now set your site’s “home” and “siteurl” values in the wp-config.php file Say […]
[…] ĝisdatigita eldono havas iuj sekurecaj riparoj. Ankaŭ ekzistas tri utilaj plibonigoj por alĝustigantoj. La plej escita el tiuj estas la konstantoj WP_HOME kaj WP_SITEURL por faciligi la movon al aliaj […]
[…] are included with this version 2.2 and on the other side, Austin Matzko has made a post on topic – WordPress 2.2: Three Things Developers Will Like which the developers may find it […]
[…] you thought built-in widgets were all you got with WordPress 2.2, Austin Matzko of Il Filosofo has some details that might interest you. You can now set your site’s “home” and […]
[…] 這次更新版本與之前有較大的變動,以下整理一些網路上的文章: filosofo 的介紹 – WordPress 2.2: Three Things Developers Will Like […]
[…] WordPress 2.2: Three Things Developers Will Like In the newly released WordPress 2.2 the built-in widget support is likely to get most of the attention. Here are three things you as a WordPress plugin or theme developer might also find useful. (tags: wordpress wordpress2.2 phpmailer) […]
[…] WordPress 2.2: Three Things Developers Will Like – Tre oversete forbedringer i WP 2.2 […]
[…] at TechnoSailor and filisofo at Il Filosofo document some of the cool features in WordPress 2.2. Technorati Tags: blogging, […]
[…] that should be of interest to most WordPress users. Austin Matzko, on the other hand, published WordPress 2.2: Three Things Developers Will Like – you get three guesses as to who that one’s […]
[…] following two posts – 10 Things You Should Know About WordPress 2.2, an elaboration of the new, and WordPress 2.2: Three Things Developers Will Like – you get three guesses as to who that one’s […]
[…] Il Filosofo a descoperit însă un lucru mai interesant (de fapt trei lucruri dar doar unul m-a entuziasmat pe mine): se pot defini în fişierul wp-config.php variabilele home şi siteurl după exemplu următor: […]
[…] you thought built-in widgets were all you got with WordPress 2.2, Austin Matzko of Il Filosofo has some details that might interest you. You can now set your site’s “home” and […]
[…] wrote an article about three good changes to 2.2. While all three are useful changes, I think that the one people […]
[…] Ilfilosofo’s WordPress 2.2: Three Things Developers Will Like […]
[…] 10 things you should know about WordPress 2.2 and three things developers will like about it. […]
[…] release. Aaron Brazell has this post which covers all of the major changes in the release, while this post from Austin Matzko covers a few of the changes in more […]
[…] 这批篇文章翻译自 WordPress 2.2: Three Things Developers Will Like,如果你对我们的翻译或者这个主题有什么意见,欢迎给我们留言。 […]
[…] Welcome to my blog, please feel free to subscribe to my RSS feed or leave a comment.May 16th 2007 in review. I wanted to point to K2 for WordPress 2.2 Compatibility. WordPress 2.2 Is Now Available! shouldn’t be missed. wordpress.com was valuable today. wordpress 2.2 Take a look at The why and how of establishing your web persona. It was worth reading WordPress 2.2: Three Things Developers Will Like. […]