PHP API Events 

PHP API events will trigger functions within a PHP API plugin when an event occurs within the construction or display of the editor. Functions inside a PHP API plugin that have the same name as an event will be triggered when that event is fired.

The functions are passed the current editor object which should be accepted by reference and optionally an associative array of data pertaining to the event. The function can then set properties and call methods of the editor object to alter its configuration and do something with any data passed to it in the array.

You can trigger an event by calling $editor->triggerEvent($name, $data); where $name is the name of the event you would like to trigger and $data is an associative array of data pertaining to the event. 

Example:

Lets image you want to create a PHP API plugin called 'myPlugin'

First create the plugin file:

wysiwygPro/plugins/myPlugin/plugin.php

if (!defined('IN_WPRO')) exit;

class
wproPlugin_myPlugin {

// place functions here for all the events you want
// Here are some examples:

// this event function will fire when the plugin is loaded
function init(&$editor) {
// ensure that the snippets button is shown on the toolbar.
$editor->snippets = true;
}

// this event function will fire before the links dialog looks for links
function onBeforeGetLinks(&$editor) {
// Add some links that you can choose from when inserting a hyperlink:
$editor->links = array(
array(
'title'=>'Home', 'URL'=>'/'),
array(
'title'=>'About Us','URL'=>'/about/', 'children'=>array(
array(
'title'=>'Company History','URL'=>'/about/history.php'),
array(
'title'=>'Franchise Information','URL'=>'/about/franchise.php'),
array(
'title'=>'Shareholders Information','URL'=>'/about/shareholders.php'),
)),
array(
'title'=>'Services', 'URL'=>'/services/'),
array(
'title'=>'Contact Us', 'URL'=>'/contact/'),
);
}

// this event function will fire before the snippets dialog loads snippets:
function onBeforeGetSnippets(&$editor) {
// Add some snippets:
$editor->snippets = array(
'Company Logo' => '',
'Company Address' => '2/99 Nowhere Sreet, Nowhereville',
);
}

}
?>

To load the plugin named 'myPlugin' you would use the loadPlugin function:

$editor->loadPlugin('myPlugin'); 

PHP API Events
The following table lists available events:

Event Name

Array Keys

Description 

onLoadDialog 

empty 

Fires when a dialog window is opened just before the dialog plugin is loaded.

onBeforeDisplayDialog 

empty 

Fires just before the dialog template is parsed. 

onAfterDisplayDialog 

empty 

Fires just after the dialog template is parsed and displayed. 

onBeforeMakeEditorProcess 

empty 

Called when display or fetch is called, before any of the editor's configuration is processed. 

onAfterFixHTML 

empty

 

onBeforeMakeEditor 

empty

Called after the editor configuration has been processed and just before the editor template is parsed. 

onAfterMakeEditor 

empty 

Called after the editor template has been parsed. 

onFileChooserButtonJS 

type
The type of file expected, it will be a value of 'link', 'image', 'document' or 'media'.

field
The name of the field that should be populated when a file is chosen.

Can be used to change the file browser to one of your design.

The function should return code for opening the browser suitable for placement within an onclick event handler.

Any other required JavaScript tags  can be output directly using an echo statement.


onBeforeGetLinks 

empty 

Called before the links dialog loads the links property. See links for an example.

onFileDelete 

directory
The full path of the directory

directoryURL
The URL of the directory

directoryObject
A wproDirectory object

files
An array of deleted files


onEditImage 

directory
The full path of the directory

directoryURL
The URL of the directory

directoryObject
A wproDirectory object

file
filename of image

tempFile
filename of temporary file

task
editing task performed

options
options for the editing task

 

onFileMove 

srcDirectory
Full path of the source directory

srcDirectoryURL
URL of the source directory

srcDirectoryObject
A wproDirectory object

destDirectory
The full path of the destination directory

destDirectoryURL
The URL of the destination directory

destDirectoryObject
A wproDirectory object

files
An array of moved files

 

onFileCopy 

srcDirectory
Full path of the source directory

srcDirectoryURL
URL of the source directory

srcDirectoryObject
A wproDirectory object

destDirectory
The full path of the destination directory

destDirectoryURL
The URL of the destination directory

destDirectoryObject
A wproDirectory object

files
An array of copied files

 

onNewFolder 

directory
The full path of the directory

directoryURL
The URL of the directory

directoryObject
A wproDirectory object

name
Name of new folder

 

onFileRename 

directory
The full path of the directory

directoryURL
The URL of the directory

directoryObject
A wproDirectory object

files
An associative array of renamed files where the key is the oldname and the value is the new

 

onUpload 

directory
The full path of the directory

directoryURL
The URL of the directory

directoryObject
A wproDirectory object

files
An array of uploaded files

 

onBeforeGetSnippets 

empty 

Called just before the snippet dialog loads the snippets. See snippets for an example.