< Back to Extending


Plugins allow you to override WSN functions with customized versions. Any file uploaded to the /plugins/ subdirectory will be able to override these functions with a custom version you write. The following functions can be replaced by plugins -- except where otherwise noted, they can be found in includes/pluggables.php:

beforeaddition - Perform any desired changes to any sort of object just before it gets added to the database.
afterapplyinput - Do something after the user submits the data for a new submission or an update, before the data is saved to the database but after it's applied to the object.
afteraddition - Do something after submission is added to the database.
afterapplyedits - Do something after edits have been applied to the object (but not the database).
afterlogin - Do something after user logs in.
afterlogout - Do something after user logs out.
afterban - Do something after member is banned.
checkincompletes - Trigger an incomplete prompt when the submitted data isn't valid.
afterpayment - Do whatever you want after the successful processing of a sponsorship or item purchase payment.
aftermembersponsor - After a member buys usergroup sponsorship.
aftermembersponsorend - After a member's sponsorship expires.
changeredirectdestination - Changes the destination URL of a redirect page.
onunpaidsubmit (includes/addeditfuncs.php) - What to do when submitting to a paid type and we haven't paid in advance.
aftersetup - Do whatever you want after installation is completed.
afterhitout - Do whatever you like after a hit out is counted.
regenerateplugin - Do something when the article is regenerated.
securityimagevalue (includes/commonfuncs.php) - Returns characters for security image.
catselector (includes/commonfuncs.php) - Gives category selector dropdown.
redirect (includes/commonfuncs.php) - Redirects from one page to another.
markrequired (includes/addeditfuncs.php) - Marks required fields in red outline.
reciprocates (includes/addeditfuncs.php) - Determines whether a link is considered reciprocated.
typeselector (includes/addeditfuncs.php) - Gives article type selector options.
alterhtaccess - Changes the .htaccess content before writing.
googlemap (includes/googlemapfunc.php) - Generates google or sitemaps.org sitemap.
latextohtml (includes/commonfuncs.php) - Renders latex codes.
protecttext (includes/commonfuncs.php) - Disguises email addresses.
showfeeds (includes/commonfuncs.php) - Shows RSS feed data associated with item.
pluralize (includes/pluralize.php) - Attempts to pluralize/singularize words appropriately.
geofromaddr (includes/commonfuncs.php) - Finds latitude and longitude for an address.
geofromip (includes/commonfuncs.php) - Finds latitude and longitude from an IP.
urlchanger - Manipulates URLs for rewriting.
changeoutgoingurl - Changes the outgoing link URL for rewriting.
adjustpreviews - Adjusts the preview page content.
adjustpagination - Adjusts the pagination HTML, useful for new forms of URL rewriting.
afterusergroupchange - Do stuff when a member's usergroup is manually altered on the edit member page, like maybe send them an email.
mlstransformations - Does manipulations before processing MLS real estate import articles.
beforemoderation - Called before any moderation is performed, with the first parameter being the moderator action and the second being the reason.
preprocessaddition - Called just before we process adding a new article.
modifyendoutput - Change the final page HTML just before output.
changeallowselfmoderating - Change whether member can moderate own threads.
customcanbump - Determine whether article can be bumped to appear to be submitted right now.
customcanautobump - Determine whether article can be autobumped daily to appear to be submitted right now.
afterapplygroupbits - Modify a member object just after the usergroup permission properties have been added to it, in order to override permissions. To override just viewing member be sure to use if ($object->isthismem)
transformtemplates - Modify templates at creation time, before they get used. Useful for making something change in all themes without having to edit every theme.
docreadychanger - Alters the jquery document ready function content.
addtohtaccessextras - Adds programmatically-generated .htaccess rules to to extra .htaccess content slot.
preemptlocalzipcoords - For distance range searches, this function can resolve the source location to coordinates overriding normal resolution, in case you want to search by distance from a listing title or the like.
custompadextractions - Get more data out of software PAD files.
choosecustomglyphicon - For bootstrap themes, this function allows you to change the glyphs which are set in the PHP.
alterdisplayedsearchterm - Allows you to change the value shown by {SEARCHTERM} in the search results template and title (doesn't change the actual search term, just the displayed search term).
altersearchorder - Allows you to change the ORDER BY part of the search query.

The file listed inside the parenthetical has the original version of each function (includes/pluggables.php being the location for those not otherwise specified). Don't edit those files -- copy and paste the function out of that file into a new .php file in your /plugins/ subdirectory. Any of these functions placed in files in the /plugins/ directory will automatically override the shipped versions. This way your site will upgrade cleanly without losing anything when the standard files are overwritten with new versions.

If you'd like another function to become pluggable, just ask and your wish will almost certainly be granted.

The most useful pluggable function will probably be beforeaddition. Use it to perform any desired changes to any sort of object just before it gets added to the database. For example:
function beforeaddition(&$object)
if ($object->objecttype == 'link') $object->title = ucwords($object->title); // capitalize first letter of each word in link titles

Note how the objecttype property of $object allows you to determine what sort of object you're dealing with. Don't hesitate to ask support if you need help understanding how the WSN objects work.

The afteraddition() function is the same as beforeddition() except it executes after the item has been added to the database (though it hasn't necessarily been validated). afterapplyedits() allows you to manipulate edits before they're saved.

The function afterpayment() is similar, but it allows you to do whatever you want after the sucessful processing of a sponsorship payment. See the dummy in commonfuncs.php for a short list of useful inputs.

The checkincompletes() function, added in 5.0, allows you to trigger an incomplete prompt when the submitted data isn't valid. For example, I use this on the WSN suppport forums to make sure the version field is filled with a valid number:
function checkincompletes($object)
global $incomplete, $incompletemessage;
// $incomplete should be set as true when it's incomplete. $incompletemessage is an array containing a list of prompts for the user.

if ($object->objecttype == 'link')
$pattern = "/(WSN (Links|Gallery|KB|Forum|Classifieds|Guest|FormEmail)?)?( )?[0-9]+\.[0-9]+\.[0-9]+( (Alpha|Beta|RC) [0-9]+)?/i";
$check = preg_match($pattern, $object->sversion);
if (!$check)
$incomplete = true;
$incompletemessage[] = "A valid version number would be, for example, 5.0.1. ".$object->sversion." is not valid.";
return true;

The aftersetup() function lets you run code after a successful new installation completes. This may help simplify the task of a large-scale deployment where alterations need to be performed or default data needs to be inserted after installation.

If your plugin needs to do one time setup activities, you may register a plugin setup function. At the top of your plugin file, add a line
$pluginsetupfunctions[] = 'myplugin_setup';
And then anywhere in the file create the function you've specified:
function myplugin_setup()
// create database tables. or whatever else your setup does

WSN will run your plugin setup function just once, then it will remember not to call it again. Similarly you can register a function to run during WSN version upgrades with $pluginupgradefunctions[] = 'myplugin_upgrade'; -- if you need to manually invoke it, simply loading upgrade.php in your browser will do so. Make sure you use a unique name for your setup and upgrade functions that won't conflict with another plugin.

To add functions that will create new template variables or modify an object, use pseudomethods.

Note that plugins execute very early in the script. if you want to do stuff toward the end of the page construction you will find the modifications directory more useful. For login-related modifications see member system integration.