Posts Tagged Filter Function
How to make wordpress plugin: General
Posted by in PHP code, Wordpress plugin on July 21st, 2009
This article will present you with the basics of wordpress plugin. I have create a plugin to help you understand how to create a plugin. This simple plugin shows a digg button to all your post. You can download the full code here. Below is several code I use:
class diggme
{
function diggme() {
add_action(’init’, array($this, ‘init’));
add_action(’admin_menu’, array(&$this, ’setmenu’));
add_filter(’the_content’, array(&$this, ‘the_content_filter’));
}
function init()
{
?>
<link href=”<?php echo get_option(’siteurl’); ?>/wp-content/plugins/diggme/css.css” rel=”stylesheet” type=”text/css” />
<?php
}
function managepage(){
echo “<div id=’setting’>This is setting page. Just ignore this</div>”;
}
function setmenu () {
add_options_page(
‘DiggMe’,
‘DiggMe’,
‘manage_options’,
__FILE__,
array(&$this,’managepage’ ) );
}
function the_content_filter($content)
{
return $this->displaydigg() . $content;
}
function displaydigg()
{
global $post;
return “<div id=\”diggbutton\”><a href=\”http://digg.com/submit?phase=2&url=”.get_permalink($post->ID).”\”><img src=\”".get_settings(’siteurl’).”/wp-content/plugins/diggme/digg.png\”></a></div>”;
}
}
$diggme = new diggme();
- The code will first create a class called diggme. Every time the plugin loads it will create an object of this class using $diggme = new diggme();
The constructor
- add_action(’init’, array($this, ‘init’)); -> This will tell your blog to execute function init whenever it loads.
- add_action(’admin_menu’, array(&$this, ’setmenu’)); -> This will tell your blog to create menu at your admin page. You can place any settings here.
- add_filter(’the_content’, array(&$this, ‘the_content_filter’)); -> This will be executed every time when your post loads. In this example we will load function the_content_filter every time the page loads, read the post content and add a digg button to the post.
Other function is easy to understand if you have basic PHP skill. If you have any question just comment below.
Amp, Array, Blog, Constructor, Content Filter, CSS, Digg, Div Id, Echo, Filter Content, Filter Function, How To Make Wordpress Plugin, Img, Link Href, Lt, Options, Page Loads, Phase 2, Php Function, Png, Stylesheet
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ||||||||||||||
-
-
Archives
- July 2010 (2)
- June 2010 (2)
- May 2010 (1)
- March 2010 (2)
- February 2010 (2)
- January 2010 (6)
- December 2009 (9)
- November 2009 (6)
- October 2009 (4)
- September 2009 (3)
- August 2009 (7)
- July 2009 (19)
- June 2009 (7)
-
My links
-
Programming Books
- Add new tag Amazon Amp Api Array Blog Br Code Lt Css Style Current Demo Demo Download Div Id Domain Name Echo Endif Firefox Google Ie6 Images Input Type Internet Explorer Internet Marketing Jquery Lt Marketing Tool Money Options Parameters paypal Php PHP code Php Server Syntax Tag Text Javascript Type Button Web Service Wp Yahoo









