Plugins

Plugins are similar to snippets in that they are snippets of code that have access to the Evo API - however the big difference is that plugins are associated to specific system events. For example, in an average Evo 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 Evo admin interface.

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;
}

Suggest an edit to this page.