Jump to content

4 Things You Must Be Versed With as a Wordpress Developer

0
  gyli's Photo
Posted Feb 05 2013 04:53 AM

Wordpress is the buzz word in the web development arena presently. You will see several multi-nationals boasting about their Wordpress plugins and websites supporting the most complex enterprise processes. If you are a wordpress developer, you must be aware about the entire craze that surrounds this highly proficient CMS. Being into wordpress development, you have to meet new requisites every passing day. You have to work your wits in developing new concepts every now and then and keeping clients satisfied with your deliverables. As you put in all your hard work in developing the new Wordpress portal, here are 4 things that you must be well-versed with:

1. Always Use Global Paths:

You can make your website functional by writing an error-free PHP code, but to make it look great you will need to add images, some Javascript and CSS. You are likely to organize these elements in their respective files namely images, js and css, which is a good practice. Have you, however, wondered how to code your site in such a manner that irrespective of the domain within which it is running, it can always find these files? Well, the simplest way to do so is to create your own global paths. Here is a code snippet that allows you to create global paths:

1. if (!defined('MYPLUGIN_THEME_DIR'))

2. define('MYPLUGIN_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());

3. 

4. if (!defined('MYPLUGIN_PLUGIN_NAME'))

5.  define('MYPLUGIN_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));

6.
 
7. if (!defined('MYPLUGIN_PLUGIN_DIR'))

8. define('MYPLUGIN_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . MYPLUGIN_PLUGIN_NAME);

9.

10 if (!defined('MYPLUGIN_PLUGIN_URL'))

11 define('MYPLUGIN_PLUGIN_URL', WP_PLUGIN_URL . '/' . MYPLUGIN_PLUGIN_NAME);

This code allows you to add four global variables, namely name of the plugin, path to the theme directory, url of the plugin and path to the plugin directory.

2. Enable Debugging As you Begin Coding:

As you start developing a Wordpress plugin, the first thing you must do is to turn on debugging and keep it on till the time you finish with the entire coding of your plugin. This will ensure that as and when anything goes wrong, Wordpress immediately alarms you by sending error messages. Furthermore, by enabling debugging you will get time to time notices from Wordpress informing you about any features that might be removed from Wordpress in the near future.

3. Add Prefix to Functions:

At times you might notice that several other developers are using the same name for their functions as you are. In order to get rid of this issue, you must name each function uniquely. The easiest way around is to add prefix to name of your functions. Here’s an example:

1 function myplugin_copy_file() {

2 }

3
 
4 function myplugin_save_data() {

5 }

6
 
7 function myplugin_database_table_exists() {

8 }

4. Create or Update Database Tables using dbDelta():

If you are using some database tables for your plugin you might need to update that table as and when you release an updated version of your plugin. Mainitaining databases can be tricky at times, but the dbDelta() function in Wordpress makes things easier for you. Here is an example where you can sue the function to create a table containing name, ID and an email:

1 function myplugin_create_database_table() {

2 global $wpdb;

3 $table = $wpdb->prefix . 'myplugin_table_name';

4
 
5 $sql = "CREATE TABLE " . $table . " (

6 id INT NOT NULL AUTO_INCREMENT,

7 name VARCHAR(100) NOT NULL DEFAULT '',

8 email VARCHAR(100) NOT NULL DEFAULT '',

09 UNIQUE KEY id (id)

10 ) ;";

11
 
12 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

13 dbDelta($sql);

14 }

Keeping in mind these tips you can develop high-end Wordpress plugins and provide great solutions to enterprises that hire wordpress developers for their plugin needs.

0 Replies