Thursday, 25 October 2012

word press doc



Table of Contents


Introduction of Word Press ..................................................................................................4

Installation of Word Press …................................................................................................5

Folder Structure of Word Press …......................................................................................14

Theme ….................................................................................................................................15

Default Types in Word Press …...........................................................................................16

            Post ….........................................................................................................................16

Page.............................................................................................................................16

Attachment ….............................................................................................................16

Revision.......................................................................................................................16

Nav Menus...................................................................................................................16

Administration  Dashboard ….............................................................................................17
Post...............................................................................................................................17

Description of Post Fields......................................................................................18

Process for creating Posts......................................................................................22
Media …......................................................................................................................24
Links ….......................................................................................................................24
Pages............................................................................................................................24
Appearance ….............................................................................................................24
Creating the Menus in Word Press …...................................................................26

Creating pages in Word Press …...........................................................................31

Creating a template in Word Press  …...................................................................33
Widget …...........…......................................................................................................38
Custom side bar creation …...................................................................................41
Custom widget creation …....................................................................................42

PlugIns …...............................................................................................................................47

PlugIn Installation …...................................................................................................48
Custom Plug In creation...............................................................................................50

Sample Custom PlugIn …...........................................................................................53
References …..........................................................................................................................56






























Introduction of Word Press :

Word Press  is a free  and open source blogging tool and content management system(CMS) based on PHP and MySQL. It has many features including a plug-in architecture and a template system.
If you plan to start your own blog website, the best choice for a blog application would be WordPress. Wordpress is an Open Source blog tool which offers a rich set of features as well as a large supporting community.WordPress has an intuitive administration interface which anyone can handle. In WordPress you will be able to compose a post and publish it on your website with just a few clicks! With WordPress you can easily customize the look of your website for there are lots of free WordPress themes available on the Net.

















Installation of Word Press :
We will download the latest version of Word Press from this below URL.
http://wordpress.org/ 
Place your Word Press folder in your project directory.If We run your project from browser , it will ask to configure.The installation process of Word Press is as below.



Please give your database details here.

































Please enter your Username and Password and Login to the admin side.








This is your back end of Word Press site. If we want to check the site front end, run your project from browser or else mouse over on wordpress on the top bar you will get visit site option click on it. You will get ,your site front end.








This is your site default theme . According to theme our site look will be changed. Before going to operate in Word Press, we should know what is theme and how we can activate the theme.
The folder structure of Word Press is as below:
Project(your wordpress project )
wp-admin
wp-content
wp-includes
(Files)
In  wp-content  folder we have Plugins and  themes folders. In themes  folder we  have twentyten and twentyeleven folders.These are the default themes available with Word Press.
















Theme:
A Word Press Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. A Theme modifies the way the site is displayed, without modifying the underlying software. Themes may include customized template files, image files (*.jpg,*.gif), style sheets (*.css), custom Pages, as well as any necessary code files (*.php). 

Get New Themes:
The Word Press Theme Directory's the official site for Word Press Themes which have been checked and inspected, and are free for downloading. The site features the ability to search by type and style, and offers a demonstration of the page view elements of the Theme.

Using Themes:
WordPress supplies a default theme (WordPress Twenty Eleven theme) in its distribution for your initial use. You can switch between Themes using the admin panel. Themes that you add to the theme directory will appear in the Administration Panels>Design>Themes as additional selections.You can select your own theme and activate it.We have different ways to post your content  in our website.
Defaultly  Twenty Eleven theme is activated.








Default Types in Word Press:

There are five major types that Word Press uses by default. 
Post :
A "post" in Word Press is the main type used by the blog. Posts are normally displayed in the blog in reverse sequential order by time (newest posts first). Posts are also used for creating the feeds. 

Page :
A "page" in Word Press is like a post, but it lives outside the normal time based structure of posts. They have their own URLs directly off the main site URL. They can also use special Page Templates to display them. Pages can also be organized in a hierarchical structure, with Pages being parents to other Pages. 

Attachment: 
An "attachment" is a special post that holds information about files uploaded through the Media upload system. They hold all the description and name and other information about uploaded files. For images, this is also linked to metadata information about the size of the images and thumbnails generated from the images, the location of the files, and even information obtained from EXIF data embedded in the images. 

Revisions:
A "revision" is used to hold draft posts as well as any past revisions of existing posts or pages. These are basically identical to the main post/page that they are for, but have that post/page as their parent. 

Nav Menus: 
The "nav_menu_item" type holds information about a single item in the Navigation Menu system. These are the first examples of entries in the posts table to be used for something other than an otherwise displayable content on the blog. 



Admin Dashboard:

1)Post :Posts are the entries that display in reverse chronological order on your home page. Creating the post in wordpress.







Descriptions of Post Fields:       
Title:

The title of your post. You can use any words or phrases. Avoid using the same title twice as that will cause problems. You can use commas, apostrophes, quotes, hypens/dashes, and other typical symbols in the post like "My Site - Here's Lookin' at You, Kid." Word Press will clean it up for the link to the post, called the post-slug. 
Post Editing Area:

The blank box where you enter your writing, links, links to images, and any information you want to display on your site. You can use either the Visual or the HTML view to compose your posts. For more on the HTML view, see the section below, Visual Versus HTML View. 

Preview button:

Allows you to view the post before officially publishing it. Publish box contains buttons that control the state of your post. The main states are Published, Pending Review, and Draft. 
A Published status means the post has been published on your blog for all to see. Pending Review means the draft is waiting for review by an editor prior to publication.
 Draft means the post has not been published and remains a draft for you. 
If you select a specific publish status and click the update post or Publish button, that status is applied to the post.
For example, to save a post in the Pending Review status, select Pending Review from the Publish Status drop-down box, and click Save As Pending. (You will see all posts organized by status by going to Posts > Edit). To schedule a post for publication on a future time or date, click "Edit" in the Publish area next to the words "Publish immediately". You can also change the publish date to a date in the past to back-date posts. Change the settings to the desired time and date. You must also hit the "Publish" button when you have completed the post to publish at the desired time and date. 


Visibility - This determines how your post appears to the world. Public posts will be visible by all website visitors once published. Password Protected posts are published to all, but visitors must know the password to view the post content. Private posts are visible only to you (and to other editors or admins within your site) 
Permalink:

After you save your post, the Permalink below the title shows the potential URL for the post, as long as you have permalinks enabled. (To enable permalinks, go to Settings > Permalinks.) The URL is generated from your title. In previous versions of WordPress, this was referred to as the "page-slug." The commas, quotes, apostrophes, and other non-HTML favorable characters are changed and a dash is put between each word. If your title is "My Site - Here's Lookin' at You, Kid", it will be cleaned up to be "my-site-heres-lookin-at-you-kid" as the title. You can manually change this, maybe shortening it to "my-site-lookin-at-you-kid". 
Save:

Allows you to save your post as a draft / pending review rather than immediately publishing it. To return to your drafts later, visit Posts - Edit in the menu bar, then select your post from the list. 
Publish:

Publishes your post on the site. You can edit the time when the post is published by clicking the Edit link above the Publish button and specifying the time you want the post to be published. By default, at the time the post is first auto-saved, that will be the date and time of the post within the database. 

Post Tags:

Refers to micro-categories for your blog, similar to including index entries for a page. Posts with similar tags are linked together when a user clicks one of the tags. Tags have to be enabled with the right code in your theme for them to appear in your post. Add new tags to the post by typing the tag into the box and clicking "Add". 



Categories:

The general topic the post can be classified in. Generally, bloggers have 7-10 categories for their content. Readers can browse specific categories to see all posts in the category. To add a new category, click the +Add New Category link in this section. You can manage your categories by going to Posts > Categories. 
Excerpt:

A summary or brief teaser of your posts featured on the front page of your site as well as on the category, archives, and search non-single post pages. Note that the Excerpt does not usually appear by default. It only appears in your post if you have changed the index.php template file to display the Excerpt instead of the full Content of a post. If so, Word Press will automatically use the first 55 words of your post as the Excerpt or up until the use of the More Quick tag mark. If you use an Explicit Excerpt, this will be used no matter what. For more information, see Excerpt. 

Send Trackbacks:

A way to notify legacy blog systems that you've linked to them. If you link other WordPress blogs, they'll be notified automatically using pingbacks. No other action is necessary. For those blogs that don't recognize pingbacks, you can send a trackback to the blog by entering the website address(es) in this box, separating each one by a space. See Trackbacks and Pingbacks for more information. 
Custom Fields:

Custom_Fields offer a way to add information to your site. In conjunction with extra code in your template files or plugins, Custom Fields can modify the way a post is displayed. These are primarily used by plugins, but you can manually edit that information in this section. 
Discussion:

Options to enable interactivity and notification of your posts. This section hosts two check boxes: Allow Comments on this post and Allow trackbacks and pingbacks on this post. If Allowing Comments is unchecked, no one can post comments to this particular post. If Allowing Pings is unchecked, no one can post pingbacks or trackbacks to this particular post. 


Password Protect This Post:

To password protect a post, click Edit next to Visibility in the Publish area to the top right, then click Password Protected, click Ok, and enter a password. Then click OK. Note - Editor and Admin users can see password protected or private posts in the edit view without knowing the password. 
Post Author:

A list of all blog authors you can select from to attribute as the post author. This section only shows if you have multiple users with authoring rights in your blog. To view your list of users, see Users tab on the far right. 
         WordPress Admin Writing Post Advanced Panel - Bottom of Page
   Note: You can set basic options for writing, such as the size of the post box, how    smiley tags are converted, and other details by going to Settings > Writing. See    Writing Options SubPanel. 












Process for creating Posts:



If we click on publish , our post will be published in our site. If we see in our site, it will  visible like below image. The theme Is twenty eleven theme.




















2) Media  in Administrative  panel:
Media is the images, video, recordings, and files, you upload and use in your blog. Media is typically uploaded and inserted into the content when writing a Post or writing a Page. 


3) Links  in Administrative  panel:
WordPress allows you to store a set of external links, also known as your blogroll. These links can be put into categories, imported, exported, added, deleted, and edited. The link categories can also be added, deleted, and edited. 


4) Pages:
In WordPress, you can write either posts or pages. When you're writing a regular blog entry, you write a post. Posts automatically appear in reverse chronological order on your blog's home page. Pages, on the other hand, are for content such as "About Me," "Contact Me," etc. Pages live outside of the normal blog chronology, and are often used to present information about yourself or your site that is somehow timeless -- information that is always applicable. You can use Pages to organize and manage any amount of content.Other examples of common pages include Copyright, Legal Information, Reprint Permissions, Company Information, and Accessibility Statement. In general, Pages are very similar to Posts in that they both have Titles and Content and can use your site's Presentation Templates to maintain a consistent look throughout your site. Pages, though, have several key distinctions that make them quite different from Posts.









Difference between page and post:
Posts: Pages:
We  can  categorize the posts. We cant categorize the pages.
We are unable to  use templates to display posts.      We can use templates to display posts.
Posts are mainly for blogs.      Pages are mainly for static type data.

5)Appearance:    
In appearance tab we have options like ,
Themes,
widgets,
Menus,
Theme Options,
Background,
Header,
Editor.






















Creating the  Menus in Word Press:
Go to Appearance tab from administrative panel  then  click on menus option.
Give your name of the menu in “menu name” text box.















I have given ' menu1' as menu name.
You can call the menu in your template files  with menu name (menu1) .
Now we are going to start creating a menu.
I will create 'About Us','Services','Solutions' as  menu items.
Go to “Custom links”  box and give your label name as 'About Us', and give the URL.
And click on Add to Menu. It will add to “menu1”.
In the same way you create 'Services' and 'solutions' menu items.
After creating menu items please click on Save Menu buttons. It will save Menu and Menu Items. It will be as like below figure.

We can call  this menu in our required template files by  using the method  wp_nav_menu().
To call this “menu1” we need to  give arguments to that method as like below.
wp_nav_menu(array('menu' => 'menu1'));




You can find our custom menu(menu1)  in the image above.To give sub menu  you just add menu links and drag to right side of to which menu you want to add this as sub menu. Then click on save menu.For example If you want to create 2 sub menus  for “About Us” link I.e  “Company Overview” and ”Vision and Mission”.
The procedure as shown below.















You can observe sub menus  under the “About Us” menu tab. If we want to add any link to that “About Us” we need to create a page.











Creating pages in Word Press:
To create a new Page, log in to your WordPress installation with sufficient admin privileges to create new articles. Select the Administration > Pages > Add New option to begin writing a new Page. 



I just created “about us”  page and publish it. We will get the permalink below that title of page. If you observe page attributes box  at right side of your administrative panel,
you can find  template select box.You can use any template to display the page content of “about-us”.We can organize our page content using templates.If we want to show our page content as per client requirement,by using template file only we can arrange content  in a specific way. For that purpose we need to place our html code in our template files.

If you check permalink of “aboutus” then we will get the page as shown in the below image.
Permalink of “aboutus” page is :  http://localhost/wordpress/about-us/ 


If we select different template from template drop down, then this “aboutus” page look will  change according to that template html code.I will explain how to use templates to display page type post contents.Before that I will explain what is template.


Template:
Templates are the files which control how  your WordPress site will be displayed on the Web. These files draw information from your WordPress MySQLdatabase and generate the HTML code which is sent to the web browser. Through its powerful Theme system, WordPress allows you to define as few or as many Templates as you like all under one Theme. Each of these Template files can be configured for use under specific situations .





Creating a template in Word Press :
 Create a file with php extension and give the required name for that file.
I want to create a “aboutus” name template. So that I create a php file in our theme directory and given name as aboutus.php.If you create any template you should mention comments for that template.
<?php
/*
 Template Name:AboutUs
 */
?>

If you don't mention the comments, then you dont get your template name  in page attributes of template select box.You can observe “AboutUs” template name in template drop downs in  page attributes section .Please select “AboutUs”  template from that template drop down.





















This means we are using ' About us'  template to display that post .Click on update for the post .Now we copy the permalink of “About-us” post and paste in the URL then we will find updated post like  as shown in the below image.


In the “aboutus” template we don't have any html code , so that we are getting plain content with any design.If you want to add any design for this content, then  we need to add html code in our   “about-us” template. In the above image we are getting page title as “About us” 
and content based on this following code.






<?php
/*
 Template Name:AboutUs
 */
?>
<?php 
if(have_posts()){
while(have_posts()) {
the_post();
the_title();
the_content();
}
}
?>

Upto now we don't have any header and footer to our template , so we are including header and footer in our template file .
The following two methods to display the header and footer in our template.
get_header();
get_footer();

If we add these two  methods to our template, then these methods automatically  includes header.php and footer.php template files  into our aboutus.php template file.

Now our template file looks like below:
<?php
/*
 Template Name:AboutUs
 */
get_header();
?>
<?php 
if(have_posts()){
while(have_posts()) {
the_post();
the_title();
the_content();
}
}
?>
<?php  get_footer();?>


Now our  “About-us”page looks like below,



In Word Press for every template you need to add header and footer .We can change beauty of our website by changing the theme. If we want to call this “about us” page as a menu , then we need to give this permalink as URL to that menu item.












Widget:

WordPress Widgets are WordPress Plugins that add visitor visual and interactivity options and features, such as sidebar widgets for post categories, tag clouds, navigation, search, etc. They were originally designed to provide a simple and easy-to-use way of giving design and structure control of the WordPress Theme to the user in the sidebar, which is now available on properly "widgetized" WordPress Themes to include the header, footer, and elsewhere in the WordPress design and structure. 
Widgets require no code experience or expertise. They can be added, removed, and rearranged on the WordPress Administration Appearance > Widgets panel. The order and placement is set by the WordPress Theme in the functions.php file. 
Some WordPress Widgets offer customization and options such as forms to fill out, includes or excludes of data and information, optional images, and other customization features. 













To active your WordPress Theme Widget options: 

1.1Go to Appearance > Widgets.

1.2Choose a Widget and drag it to the sidebar where you wish it to appear. There might be more than one sidebar option, so begin with the first one. Once in place, WordPress automatically updates the Theme.
1.3Preview the site. You should find that the "default" sidebar elements are now gone and only the new addition is visible. 
1.4Return to the Widgets Panel to continue adding Widgets.
1.5To arrange the Widgets within the sidebar or Widget area, click and drag it into place. 
1.6To customize the Widget features, click the down arrow in the upper right corner to expand the Widget's interface.
1.7To remove the Widget, click Remove or Delete. 

If you change WordPress Themes, the Widgets will return to the left side of the page in the Widget Archives or Available Widgets list. You may need to add them again and rearrangement depending upon the Theme's ability to preserve other Theme's Widgets. 










Custom Side Bar creation :
Custom Sidebars allows you to create all the widgetized areas we need .
Sometimes it is necessary to show different elements on the sidebars for some posts or pages. 
If we want to create a custom side bar ,then we need to add little bit of code in our functions.php file.
Example : 
function section_one() { 
register_sidebar(array(
'name' => __( 'SectionOne', 'tempaltename' ),
'id' => 'SectionOne',
'description' => __( 'SectionOne', 'tempaltename' ),
'before_widget' => '<div>',
'after_widget' =>'</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}

add_action( 'widgets_init', 'section_one');

In the above array we have 'name' => __( 'SectionOne', 'tempaltename' ).
Here name have two parameters.

1.”SectionOne”  is our custom sidebar name(position name).
2.”tempaltename”  is our template name.

before_widget,after_widget,before_title,after_title are the parameters for CSS. We will give css as  input, for these fields.

Finally we need to register this sidebar. For that purpose we are using :
add_action( 'widgets_init', 'section_one');

Now we have done our custom side bar creation. Now we need to call this side bar in to our web pages. If suppose we need this custom side bar in our index.php ,then just we will call like bellow:

<?php dynamic_sidebar('SectionOne');?>

Custom Widget Creation :

Wordpress Widget is also a plugin. So if we want to create a  Custom widget,then we need to create folder in Wordpress plugin folder.

Suppose if we want to create  a widget with the name of “example-widget”,then we need to create  a folder in plugin loctaion.

Like :  wp-content\plugins\example-widget

In this folder we have  file with the name of  “ example-widget.php”

The top of your Plugin's main PHP file must contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Here is the header format: 

<?php
/**
 * Plugin Name: Example Widget
 * Plugin URI: http://example.com/
 * Description: A widget that serves as an example for developing more advanced widgets.
 * Version: 0.1
 * Author: 
 * Author URI: 
 */
?>

Based  on this comment only wordpress will recognize this is a plugin.

Every widget have 4  mandatory  functions.

  1) Constructor ()
  2) Form()    : It is used to outputs the options form on admin
 3) Update() :  It is used to processes widget options to be saved
 4) Widget() :  It is used to outputs the content of the widget








“example-widget.php” file  :
<?php
/**
 * Plugin Name: Example Widget
 * Plugin URI: http://example.com/widget
 * Description: A widget that serves as an example for developing more advanced   widgets.
 * Version: 0.1
 * Author: 
 * Author URI: 
 */

/**
 * Add function to widgets_init that'll load our widget.
 * @since 0.1
 */
add_action( 'widgets_init', 'example_load_widgets' );

/**
 * Register our widget.
 * 'Example_Widget' is the widget class used below.
 *
 * @since 0.1
 */
function example_load_widgets() {
register_widget( 'Example_Widget' );
}

/**
 * Example Widget class.
 * This class handles everything that needs to be handled with the widget:
 * the settings, form, display, and update.
 *
 * @since 0.1
 */
class Example_Widget extends WP_Widget {

/**
* Widget setup.
*/
function Example_Widget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'example', 'description' => __('An example widget that displays a person\'s name and sex.', 'example') );

/* Widget control settings. */
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' );

/* Create the widget. */
$this->WP_Widget( 'example-widget', __('Example Widget', 'example'), $widget_ops, $control_ops );
}

/**
* How to display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );

/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title'] );
$name = $instance['name'];
$sex = $instance['sex'];
$show_sex = isset( $instance['show_sex'] ) ? $instance['show_sex'] : false;

/* Before widget (defined by themes). */
echo $before_widget;

/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;

/* Display name from widget settings if one was input. */
if ( $name )
printf( '<p>' . __('Hello. My name is %1$s.', 'example') . '</p>', $name );

/* If show sex was selected, display the user's sex. */
if ( $show_sex )
printf( '<p>' . __('I am a %1$s.', 'example.') . '</p>', $sex );

/* After widget (defined by themes). */
echo $after_widget;
}


/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;

/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['name'] = strip_tags( $new_instance['name'] );

/* No need to strip tags for sex and show_sex. */
$instance['sex'] = $new_instance['sex'];
$instance['show_sex'] = $new_instance['show_sex'];

return $instance;
}

/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {

/* Set up some default widget settings. */
$defaults = array( 'title' => __('Example', 'example'), 'name' => __('John Doe', 'example'), 'sex' => 'male', 'show_sex' => true );
$instance = wp_parse_args( (array) $instance, $defaults ); ?>

<!-- Widget Title: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>

<!-- Your Name: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Your Name:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" />
</p>

<!-- Sex: Select Box -->
<p>
<label for="<?php echo $this->get_field_id( 'sex' ); ?>"><?php _e('Sex:', 'example'); ?></label> 
<select id="<?php echo $this->get_field_id( 'sex' ); ?>" name="<?php echo $this->get_field_name( 'sex' ); ?>" class="widefat" style="width:100%;">
<option <?php if ( 'male' == $instance['format'] ) echo 'selected="selected"'; ?>>male</option>
<option <?php if ( 'female' == $instance['format'] ) echo 'selected="selected"'; ?>>female</option>
</select>
</p>

<!-- Show Sex? Checkbox -->
<p>
<input class="checkbox" type="checkbox" <?php checked( $instance['show_sex'], true ); ?> id="<?php echo $this->get_field_id( 'show_sex' ); ?>" name="<?php echo $this->get_field_name( 'show_sex' ); ?>" /> 
<label for="<?php echo $this->get_field_id( 'show_sex' ); ?>"><?php _e('Display sex publicly?', 'example'); ?></label>
</p>

<?php
}
}

?>


After that we will find this widget as a plugin in our Plugins section. So we will activate this plugin,then this widget will display in our widget's section.



Plugins: 

Plugins are tools which provide additional functionality to your application. To install a plugin you generally just need to put the plugin file into your 'wp-content/plugins' directory. Once a plugin is installed, you may activate it or deactivate it from the Plugins menu in your WP administration.

Plugin Installation process:






PlugIn Installation:
Generally the Plugin installation is a straight-forward process. In most cases it is enough to upload the plugin under the 'wp-content/plugins' directory for the WordPress installation and activate it from the administrator backend. 



The removal is also straight-forward in most cases. Simply remove the directory for the plugin you would like to uninstall and it will be automatically deactivated. 

Other wise First we need to “Deactivate” particular Plugin ,then we will get “delete” option for that plugin. By using that “Delete” link, we will uninstall that plugin.








Still always bear in mind that not all plugins are easy to install, so always refer to their documentation and installation instructions first. 






Custom Plugin Creation :

A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress Plugin Application Program Interface (API).


Plugin Name :
The first task in creating a WordPress Plugin is to think about what the Plugin will do, and make a (hopefully unique) name for your Plugin. Check out Plugins and the other repositories it refers to, to verify that your name is unique; you might also do a Google search on your proposed name. Most Plugin developers choose to use names that somewhat describe what the Plugin does; for instance, a weather-related Plugin would probably have the word "weather" in the name. The name can be multiple words. 


Plugin Files :
The next step is to create a PHP file with a name derived from your chosen Plugin name. For instance, if your Plugin will be called "Fabulous Functionality", you might call your PHP file fabfunc.php. Again, try to choose a unique name. People who install your Plugin will be putting this PHP file into the WordPress Plugin directory in their installation, wp-content/plugins/, so no two Plugins they are using can have the same PHP file name. 

Another option is to split your Plugin into multiple files. Your WordPress Plugin must have at least one PHP file; it could also contain JavaScript files, CSS files, image files, language files, etc. If there are multiple files, pick a unique name for a file directory and for the main PHP file, such as fabfunc and fabfunc.php in this example, put all your Plugin's files into that directory, and tell your Plugin users to install the whole directory under wp-content/plugins/. However, an installation can be configured for wp-content/plugins to be moved, so you must use plugin_dir_path() and plugins_url() for absolute paths and URLs. 











File Headers :
The top of your Plugin's main PHP file must contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Here is the header format: 

<?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
*/
?>
The minimum information WordPress needs to recognize your Plugin is the Plugin Name line. The rest of the information will be used to create the table of Plugins on the Plugin management screen. The order of the lines is not important. 
Wordpress Plugin Hooks :
Many WordPress Plugins accomplish their goals by connecting to one or more WordPress Plugin "hooks". The way Plugin hooks work is that at various times while WordPress is running, WordPress checks to see if any Plugins have registered functions to run at that time, and if so, the functions are run. These functions modify the default behavior of WordPress. 
For instance, before WordPress adds the title of a post to browser output, it first checks to see if any Plugin has registered a function for the "filter" hook called "the_title". If so, the title text is passed in turn through each registered function, and the final result is what is printed. So, if your Plugin needs to add some information to the printed title, it can register a "the_title" filter function. 
Another example is the "action" hook called "wp_footer". Just before the end of the HTML page WordPress is generating, it checks to see whether any Plugins have registered functions for the "wp_footer" action hook, and runs them in turn. 
You can learn more about wordpress hooks from Plugin API

Saving plug in Data to the Data Base :
Most WordPress Plugins will need to get some input from the site owner or blog users and save it between sessions, for use in its filter functions, action functions, and template functions. This information has to be saved in the WordPress database, in order to be persistent between sessions. There are three methods for saving Plugin data in the database: 
Use the WordPress "option" mechanism (described below). This method is appropriate for storing relatively small amounts of relatively static, named pieces of data -- the type of data you'd expect the site owner to enter when first setting up the Plugin, and rarely change thereafter. 
Post Meta (a.k.a. Custom Fields). Appropriate for data associated with individual posts, pages, or attachments. See post_meta Function Examples, add_post_meta(), and related functions. 

Create a new, custom database table. This method is appropriate for data not associated with individual posts, pages, attachments, or comments -- the type of data that will grow as time goes on, and that doesn't have individual names. See Creating Tables with Plugins for information on how to do this.
For more information about custom plugin creation, please find the bellow link :http://codex.wordpress.org/Writing_a_Plugin











Sample custom Plugin :
First create a folder “myplugin”  in \wp-content\plugins\ .
In this folder we are creating “myplugin.php” file,with bellow code.
<?php
/*
Plugin Name: myplugin
Description: This plugin will replace “example” word  with  , in all posts
Version: 1.0
Author: Team
*/
function my_function($text)
{
$text = str_replace('example','',$text);
return $text;
}
add_filter('the_content','my_function');
?>

Now we need to go to  administrator panel and enable this plugin.This  add_filter() method have a hook  “the_content ”.If suppose in any posts we will display the content by using  “the_content”  method ,in that case  automatically the above “my_function” will execute.
      After that this plugin will replace the “example” word with “” in all posts.
     Before execution of this plug-in we have posts as shown in below image.After execution of          this plug-in we will get the posts as shown in below image.
















Before executing of Plugin:
















After execution of plugIn:








Reference websites:

http://wordpress.org/ 

http://codex.wordpress.org/ 


For Plug-ins:

http://wordpress.org/extend/plugins/ 

No comments:

Post a Comment