Datasheet

Viewing popular plugin tags is a great way to get inspiration when developing new plugins
for WordPress.
ADVANTAGES OF PLUGINS
WordPress offers many advantages to using plugins. You need to understand the advantages
to building plugins to truly understand why you should build plugins. This can also help when
determining the need for a specifi c plugin in WordPress.
Not Modifying Core
One of the main advantages to plugins is the ability to modify the behavior of WordPress without
modifying any core fi les. Core fi les refer to any fi le that is a part of the default WordPress installation.
Hacking core fi les can make it dif cult to update WordPress when a new version is released. If you
made any modifi cations to a core fi le, that modifi cation would be overwritten when the update occurs.
Keeping WordPress up to date with the latest version is essential in keeping your web site secure.
Modifying core les can also lead to an unstable web site. Different areas of WordPress rely on
other areas to function as expected. If you modify a core fi le and it no longer works as expected, it
can cause instability and quite possibly break a completely unrelated feature in WordPress.
Why Reinvent the Wheel
Another advantage to building plugins is the structure that already exists for your plugin. Many
of the common features have already been developed and are ready for use in your plugin. For
example, you can take advantage of the built - in user roles in WordPress. Using the user roles you
can easily restrict your code to execute only if a user is an administrator. Look at an example:
< ?php
if ( current_user_can( ‘manage_options’ ) ) {
//any code entered here will only be executed IF
//user is an administrator
}
? >
As you can see it s easy to verify a user has proper permissions prior to executing any code in your
plugin. You learn about user accounts and roles in Chapter 8, Users.
As another example, look at sending an email in WordPress. Sure you could create a new function
in your plugin to send email, but why? WordPress has a handy function called
wp_mail() for
sending email. Look at an example:
< ?php
$email_to = ‘you@example.com’;
$email_subject = ‘Plugin email example’;
$email_message = ‘How do you like my new plugin?’;
wp_mail( $email_to, $email_subject, $email_message );
? >
Advantages of Plugins
5
CH001.indd 5CH001.indd 5 2/4/11 4:33:46 PM2/4/11 4:33:46 PM