Dashboard > MODx 0.9.6 > ... > Developers Guide > Plugins

View Attachments (0) Info

Plugins

What is a Plugin? 

Plugins are similar to snippets in that they are snippets of code that have access to the MODx API - however the big difference is that plugins are associated to specific system events. For example, in an average MODx page request, several events happen at certain points within the page parsing process and plugins can be attached to any of these events to fulfill a desired function. Plugins aren't just limited to front-end processing though, there are many events that are available in the MODx Manager.

Plugin Examples 

Plugins can be used for a variety of different applications, below are a couple of examples:

Word Filter

Description: Filter words from a document before it's displayed on the web
System Events: OnWebPagePrerender

Plugin Code
$words = array("snippet", "template"); // words to filter

$e = &$modx->Event;
switch ($e->name) {
case "OnWebPagePrerender":
$o = &$modx->documentOutput; // get a reference of the output
$o = str_replace($words,"<b>[filtered]</b>",$o);
 break;
default :
return; // stop here - this is very important.
 break;
}


Page-Not-Found Redirector:

Description: Redirects a user to selected document and sends a message
System Events: OnPageNotFound
Config: String:

&pg=Error Page;int; &rep=Mail To;string;
Plugin Code
$e = &$modx->Event;
switch ($e->name) {
case "OnPageNotFound":
if(!$pg) $modx->sendErrorPage();
else {
if ($mid) {
// send a message to a local account
$docid = $modx->documentIdentifier;
$subject = "Page not found";
$msg = "Someone tried to access document id $docid";
$modx->sendAlert("Error",$mid,0,$subject,$msg,0);
}
$url=$this->makeUrl($pg);
$this->sendRedirect($url, 1);
exit;
}
break;

default :
return; // stop here
break;
}


Browse Space
- Pages
- Labels
- Attachments
- Mail
- Bookmarks
- News
- Activity
- Advanced

Explore Confluence
- Popular Labels
- Notation Guide

Your Account
Log In

Other Features

View a printable version of the current page.

Add Content


Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki.
Bug/feature request - Contact administrators