Tuesday, June 7, 2011

How to create wordpress plugin

Writing a wordpress plugin is so easy..

At-first write plugin header :

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>

Then if you want to add a wordpress menu in wordpress admin panel ..Configuration of your plugin from wordpress admin panel by clicking this menu ..
<?php
add_action('admin_menu', 'my_plugin');
function my_plugin() {
add_menu_page('Page title', 'Plugin menu name', 8, __FILE__, 'plugin_function_name');

function 'plugin_function_name' () {

// Your Function program code here ….. You can call additional function from here
}

// Your additional function code here if needed……
?>

 

If you want to add wordpress option mechanism in your plugin ..

Wordpress option mechanism is

“WordPress has a mechanism for saving, updating, and retrieving individual, named pieces of data ("options") in the WordPress database. Option values can be strings, arrays, or PHP objects (they will be "serialized", or converted to a string, before storage, and unserialized when retrieved). Option names are strings, and they must be unique, so that they do not conflict with either WordPress or other Plugins.”

Here are the main functions your Plugin can use to access WordPress options.


add_option($name, $value, $deprecated, $autoload);


Creates a new option; does nothing if option already exists.

$name

Required (string). Name of the option to be added.

$value

Optional (mixed), defaults to empty string. The option value to be stored.

$deprecated

Optional (string), no longer used by WordPress, You may pass an empty string or null to this argument if you wish to use the following $autoload parameter.

$autoload

Optional, defaults to 'yes' (enum: 'yes' or 'no'). If set to 'yes' the setting is automatically retrieved by thewp_load_alloptions function.


get_option($option);


Retrieves an option value from the database.

$option

Required (string). Name of the option whose value you want returned. You can find a list of the default options that are installed with WordPress at the Option Reference.


update_option($option_name, $newvalue);


Updates or creates an option value in the database (note that add_option does not have to be called if you do not want to use the $deprecated or $autoload parameters).

$option_name

Required (string). Name of the option to update.

$newvalue

Required. (string|array|object) The new value for the option.

 

Here I write the basic mechanism to write a wordpress plugin ..

You can view this link to know more about writing wordpress plugin or creating a well-structured WordPress Plugin.

 

 

 

No comments:

Post a Comment