WordPress 2.2: Three Things Developers Will Like

by filosofo. Posted on May 16, 2007 at 2:10 am

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', 'http://www.ilfilosofo.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 the


    class-phpmailer.php
     
    and

    class-smtp.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.

    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 which wp_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:


    var wpJ = jQuery.noConflict();
     
    (from then on you could use wpJ instead of jQuery)

    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?

Nowadays lots of home based business options are available to the people. Especially internet has brought great revolutions in this field. Now anyone can make good earnings even with a small capital and excellent management skills. In this regard, establishment of a hosting company can be an excellent idea. Anyone new to this business can easily gain his market share by offering cheap web hosting packages. For this you need to hire web servers from a bigger company in the form of reseller hosting. Domain registration services can also prove a good earning source. Along with this, search engine optimization services can be a good idea. All you need to learn is good search engine marketing skills. In this regard affiliate marketing can work very handsomely as it is recommended the best internet marketing technique. Before starting this online business you must have a merchant account from dependable company and a good broadband connection for fast and secured transactions.

26 Trackbacks/Pingbacks

  1. [...] 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 [...]

  2. [...] 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 » [...]

  3. [...] : 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 [...]

  4. [...] 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 [...]

  5. [...] Relacionado: Diez características que deberíamos conocer 3 cosas de wp 2.2 que les gustarán a los desarrolladores [...]

  6. [...] Es más, los desarrolladores hemos encontrado 3 cosas que nos gustan de Wordpress 2.2 [...]

  7. [...] WordPress 2.2: Three Things Developers Will Like [...]

  8. [...] 2.2可以在wp-config.php中设置“home”、“siteurl” 两个值,使搬家变得很简单。 Tags: dreamhost, worpress Related [...]

  9. [...] 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 [...]

  10. [...] 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 [...]

  11. [...] 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 [...]

  12. [...] ĝ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 [...]

  13. [...] 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 [...]

  14. [...] 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 [...]

  15. [...] 這次更新版本與之前有較大的變動,以下整理一些網路上的文章: filosofo 的介紹 - WordPress 2.2: Three Things Developers Will Like [...]

  16. [...] 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) [...]

  17. [...] WordPress 2.2: Three Things Developers Will Like - Tre oversete forbedringer i WP 2.2 [...]

  18. [...] at TechnoSailor and filisofo at Il Filosofo document some of the cool features in Wordpress 2.2. Technorati Tags: blogging, [...]

  19. [...] 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 [...]

  20. [...] 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 [...]

  21. [...] 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: [...]

  22. [...] 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 [...]

  23. [...] wrote an article about three good changes to 2.2. While all three are useful changes, I think that the one people [...]

  24. [...] Ilfilosofo’s WordPress 2.2: Three Things Developers Will Like [...]

  25. [...] 10 things you should know about WordPress 2.2 and three things developers will like about it. [...]

  26. [...] 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 [...]

10 Comments

  1. Ronald Huereca commented on May 16, 2007 at 8:47 pm | Permalink
    Ronald Huereca

    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.

  2. Simon commented on May 17, 2007 at 8:44 am | Permalink
    Simon

    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)?

  3. filosofo commented on May 17, 2007 at 10:11 am | Permalink
    filosofo

    Simon,

    You just define the constants in your wp-config.php file, and they override any existing db option values.

  4. Morty commented on May 19, 2007 at 6:33 am | Permalink
    Morty

    wp_mail() is broken, though. It’s impossible to set the Content-Type. _Every_ plugin sending non-text mails is broken.

  5. filosofo commented on May 19, 2007 at 7:40 am | Permalink
    filosofo

    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

    [php]
    $phpmailer->ContentType = “text/plain”;
    [/php]

  6. Morty commented on May 19, 2007 at 7:47 am | Permalink
    Morty

    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.

  7. Douglas Karr commented on May 19, 2007 at 8:41 am | Permalink
    Douglas Karr

    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!

  8. Aaron commented on June 12, 2007 at 2:49 am | Permalink
    Aaron

    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

  9. filosofo commented on June 12, 2007 at 7:54 am | Permalink
    filosofo

    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

  10. houserocker commented on December 18, 2007 at 12:37 pm | Permalink
    houserocker

    Using PHPmail was a very importent step for wordpress! Hope the wp-guys take the innovativ way always in the future!!

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

Subscribe without commenting.

Comment moderation is enabled. Your comment may take some time to appear.