How to create WP Plugins?

WordPress is the most popular open source content management system for blog. WordPress Plugins allow easy modification, customization, and enhancement to a WordPress blog. Instead of changing the core programming of WordPress, you can add functionality with WordPress Plugins. With their plugin management module, developers are free to build their own custom plugin to add new i have explained how to create the simple wp plugin with one example.

Please find the php file (marquee-xml-rss-feed-scroll.php) in the below link

Aim of this plugin is to create the simple marquee using fss feed

register_activation_hook(__FILE__, ‘mxrf_install’); (Line 344)

The register_activation_hook function registers a plugin into word press website. the second parameter of this method is the name of the function which we need to call when the time of plugin activation.
So in our case; we are calling “’mxrf_install’ this function at the time of plugin activation.

function mxrf_install() { } (Line 167)

We can add the database (create table) script in this method if we need new table for the plugin. In this example am initialling few variable using “add_option” method. This method will create the new record in “wp_options” table in the website database

add_option(‘mxrf_title’, “Marquee xml rss feed”); (Line 169)

First parameter is a caption and second parameter is value, so in the page if we need to retrive this value means we can use “get_option” this method.

get_option(‘mxrf_title’) // this will give the value “Marquee xml rss feed” ( In the above line 169 we are initializing the value here we are retrieving the same value)

register_deactivation_hook(__FILE__, ‘mxrf_deactivation’);

This method will execute when we deactivate the plugin from the website, the same way the second parameter is the name of the method. In our case we are calling “’mxrf_deactivation’” this method.

add_action(‘init’, ‘mxrf_widget_init’);

This method is to initialise the widget. In our case, am calling “’mxrf_widget_init’” this function to register the widget.

function mxrf_widget_init() (Line 210)

In this method we are registering the widget sidebar. register_widget_control this is for widget control. We can create the simply HTML form with the widget. See widget.png

add_action(‘admin_menu’, ‘mxrf_add_to_menu’); (line 342)

This is to add the menu for the plugin. function mxrf_add_to_menu() (see menu.png)

add_options_page(‘Marquee xml rss feed’, ‘Marquee xml rss feed’, ‘manage_options’, __FILE__, ‘mxrf_option’ );

In the above the last parameter is the function name “mxrf_option’”. In this method we have full plugin administration form. option.png

register_sidebar_widget(‘Marquee xml rss feed’, ‘mxrf_widget’);

In this line we are calling “mxrf_widget’” the method for front end display. So what are all the content in this “mxrf_widget” method will display in the front end.

rssshow(); (line 195)

This if our front end display. The method contain the Usual PHP code to read and display the rss feed.

How to add custom code with in the post

In this example using above steps we can add the marquee text in the sidebar widget, if we want to add the same marquee with in the post, please follow the below

add_filter(‘the_content’,’mxrf_show_filter’); (line 71)

This is filter the text from the post.
If any of the post contain this string [RSS-MARQUEE=] immediately the above method call the ‘mxrf_show_filter_callback’ this function

function mxrf_show_filter_callback($matches) (line 90)

This method contains the usual PHP code to read the rss feed and return the final result for display.

Leave a Reply

Your email address will not be published. Required fields are marked *


Proudly powered by WordPress   Premium Style Theme by