More than 1000+ satisfied clients and counting, since 2010

Blog

10 things you should know as a WordPress Plugin Developer

WordPress is known as a powerful CMS tool that is flexible and the plugins and themes of WordPress make it the most preferred place to host sites or blogs by the online publishers. The official WordPress site lets the users take advantage of more than 21000 plugins for free. When you are plugin developer of WordPress, there are a few things, you should never forget.

Here are the 10 things you should know as a WordPress Plugin Developer.

Plugin Creation:

You need to start with creating a own Plugin folder in the path wp-content/plugins. Now, place your files in the folder. Create the files with simple names and hyphens for separating two words. Place the following sturcture in the main file:

<?php

/*Plugin Name : Sample Name

Plugin URI:

Description:

Version

Author URI

Author

License

*/

Activation and Deactivation of Plugin:

Use the activate link to activate the plugins. For advanced plugins, use the function, register_activation_hook. This gets triggered on plugin activation. The same way use the function register_deactivation_hook for deactivating the plugins.

Custom Tables Creation:

A flexible database table is available in WordPress. If you need to create a custom table, check if the table is available before creating it. Depending on the requirements, you can create the custom tables. Use $wpdb>query function for creating the custom tables. The following method lets you create a custom table:

global$wpdb

$wpdb->query(“DROP TABLE IF EXISTS($wpdb -> prefix}sample_table”);

$sq11 = “CREATE TABLE {$wpdb->prefix}sample_table(id int(11) NOT NULL AUTO_INCREMENT,

Activation code varchar(255) NOT NULL,

Email varchar (75) NOT NULL,

Status int(11) NOT NULL, PRIMARY KEY (id))

Require_once(ABSPATH. ‘wp admin/includes/upgrade.php)

dbDelta($sql1);

Scripts and Styles:

Use wp_register_style to register the style. Then to include the file, use wp_enqueue_style. You need to give a unique path and identifier to create a style. This includes the scripts. Use wp_enqueue _scripts for including scripts.

Creating Shortcodes:

Use this method to create shortcodes.

Add_shortcode(“shortcode_name”, “shortcode_function”);

Function shortcode_fucntion() {

Return “<input type =’button’ value=’share’/>”;

}

A HTML button is created by this and you can use this in various posts, pages and plugins.

Content Filtering:

It is important for a content to be filtered and a function can do this for you everytime.

Function sample_content_filter($content) {

If(is_single()){

Return $banners.content .$author;

}

}

Working With AJAX:

AJAX is useful when you want to provide interactive contents to the readers. Use the function to make it easy for you,

$.post(“admin-ajax.php”,{action:”sample_ajax_action”},

Function(result, textstatus) {

}, “json”);

SQL Queries Security:

It is important to consider the security of the SQL queries, because there are lots of injections. Use the prepare method for this.

$wpdb->query($wpdb->prepare(“update wp_sample_table set status = 1 where activation_code=%s and status=%d”,$activationCode,$status));

Options Boxes:

If you need additional behavior to be added to the existing options, then use the following method,

Add_action(‘add_meta_boxes’, ‘add_custom_fields_box’);

Function add_custom_fields_box() {

Add_meta_box(‘custom_fields_box_id’, ‘csutom info’, ‘display_custom_info_box’, ‘post’,’normal’, ‘high’);

}

Plugin Security and Nonces:

When you want plugins to be secured, use the nonce concept. A value is generated only when the form is generated for once. Use the following code:

Wp_nonce_field(‘sample_frm_nonce’, ‘sample_frm_nonce’

Written by

The author didnt add any Information to his profile yet