888888.888888.88""Yb..dP"Yb..8888b..Yb..dP.88b.88....db....8b....d8.88..dP""b8..dP"Y8
88__...88__...88__dP.dP...Yb..8I..Yb.YbdP..88Yb88...dPYb...88b..d88.88.dP...`".`Ybo."
88""...88""...88"Yb..Yb...dP..8I..dY..8P...88.Y88..dP__Yb..88YbdP88.88.Yb......o.`Y8b
88.....888888.88..Yb..YbodP..8888Y"..dP....88..Y8.dP""""Yb.88.YY.88.88..YboodP.8bodP'


88b.88.888888.888888.Yb........dP.dP"Yb..88""Yb.88..dP
88Yb88.88__.....88....Yb..db..dP.dP...Yb.88__dP.88odP.
88.Y88.88"".....88.....YbdPYbdP..Yb...dP.88"Yb..88"Yb.
88..Y8.888888...88......YP..YP....YbodP..88..Yb.88..Yb

January 23, 2008

Quick N Dirty

As this is the first of the Quick N Dirty plugin posts I’m going to explain the basic principles of WordPress plugins before getting to the plugin itself.

So what is a plugin?

At its most basic a WordPress plugin is just a PHP function that is called by WordPress during a specified process. As the plugin writer, you tell WordPress when you want your function to be called by adding your function to a list attached to one of a series of hooks. When WordPress gets to the point in the process that the hook applies to it will run all the functions in that list.

There are two types of hook: actions and filters.

Actions call the functions in the list without passing any data and without expecting any back. Often these are used to add content to the page in some way such as adding a copyright notice in the footer.

Filters are more involved. Filters pass data to the function and require that data, or an amended version, to be sent back. Filters are usually part of a data handling process such as outputing the content of a post to the screen.

For the first quick n’ dirty plugin I am going to use a filter: the_content.

This filter runs as part of the, the_content, template tag. When the tag is used in the template WordPress retrieves the content of the post, passes it through the filters that have hooked into the process, and then outputs it to screen. This means we can add anything we want, or amend anything we want, to the content of each post without altering the information in the database.

The fully commented plugin is included below. The plugin takes the content, retrieves all the links, checks ( using get_bloginfo ) it to see if the link points to my blog, or not, and then adds the links to the end of the post.

[php]
/*
Plugin Name: Quick N Dirty End of Post Links
Plugin URI: http://www.wp-fun.co.uk/2008/01/23/quick-n-dirty-links/
Description: Captures all the links within a post and lists them all at the end of the content.
Author: Andrew Rickmann
Version: 1
Author URI: http://www.wp-fun.co.uk
*/

//This is the line that adds your filter into the list.
// 'the_content' is the name of the filter
// 'qnd_end_of_post_links' is the name of the function, below
// 1 is the priority, 1 is called first, 10 last.
add_filter('the_content', 'qnd_end_of_post_links' , 1 );

//WordPress will call this function
//$content is the full content of the post
function qnd_end_of_post_links( $content ){

//a very basic regular expression to get the links
$regexlink = '/

Html 5 Gallery
Html5 image gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Display first image from post loop wordpress?
26 comments
page 1065
Post Image The Easy Peasy Way
Get image link de medium wordpress?
26 comments
page 1065
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
Wltc Plugin Competition Live Blogging Plugin
Wordpress liveblogging plugin?
2 comments
page 1258
Html 5 Gallery
Html gallery?
6 comments
page 1305
Using Your Own Url Shortener
Create your own url shortener in php?
4 comments
page 1190
Updating Code Snippets Here
Fun plugin wordpress?
no comment
page 1338
Write One Plugin Without Repetition Deviation Or Hesitation
Saveadminoptions wordpress?
2 comments
page 27
Updating Code Snippets Here
Wordpress fun themes?
no comment
page 1338
Html 5 Gallery
Html5 photo gallery?
6 comments
page 1305
Fun With Minimalism
Sidebartabs plugin?
no comment
page 248
Using Your Own Url Shortener
Htaccess shorten url?
4 comments
page 1190
Wordpress Chat
Wordpress chat?
3 comments
page 1308
Charcoal Theme Available For Wordpress
Simple charcoal wordpress themes?
2 comments
page 959
New Tabbed Widget Plugin
Tabbedwidget on wp 29?
no comment
page 333
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Post Image The Easy Peasy Way
Wordpress image link anchor tag?
26 comments
page 1065
Fun With Sidebar Tabs Styling
Image under sidebar css wordpress?
2 comments
page 336
Using Your Own Url Shortener
Url shortener?
4 comments
page 1190
Html 5 Gallery
Html 5 photo gallery?
6 comments
page 1305
Dont Mess With My Toot Toot
Wordpress create new post type?
16 comments
page 599
Wordpress Chat
Wordpress chat themes?
3 comments
page 1308
Wpunlimited The Ultimate Wordpress Theme
Wordpress html customisation?
3 comments
page 1141
Quick N Dirty Bookmark Navigation
Dirty bookmarking links?
no comment
page 127
Categories Vs Tags Either Neither Or Both
Both either neither image?
12 comments
page 7
My Experience Of Flexx
Flexx theme review?
4 comments
page 1026
3 Ways To Speed Up Your Blog Without A Cache Plugin
Comment on speed up your blog?
one comment
page 1321
Premium Ithemes Review Photo Gallery
Ithemes reviews?
4 comments
page 226
Wordpress 25 Exif Fields
Wordpress exif plugin?
12 comments
page 230
Adding Settings To Admin Pages
Wordpress addsettingsfield?
3 comments
page 793
  1 query every 1163 seconds, updated 1 seconds ago.
Post a comment?