-
Notifications
You must be signed in to change notification settings - Fork 1
Creating A Custom Extension
This is a walkthrough of creating a custom extension.
Imagine you want to add a new language, for example Python.
First, you need the code for the Prism extension (some JavaScript and possibly CSS, too). We already gathered it and have the following files:
lang-python.js
lang-python.css
All extensions are stored in /vendor/extensions/
, every extension in a separate subdirectory.
We now create the directory /vendor/extensions/Language_Python/
for our extension.
- Your PHP class file must be named:
"Prism_Detached_Extension_" + EXTENSION_NAME + ".php"
- Your PHP class must be named:
"Prism_Detached_Extension_" + EXTENSION_NAME
For our example this will be:
- PHP class file:
Prism_Detached_Extension_Language_Python.php
- PHP class:
Prism_Detached_Extension_Language_Python
Your PHP class must inherit from the base class Prism_Detached_Extension_Base
.
For detailed explanations about the base class, please see the wiki page of Extension Base Class.
The extension directory structure currently looks like this:
+- Prism_Detached_Extension_Language_Python/
+- javascript/
+- lang-python.js
+- css/
+- lang-python.css
+- Prism_Detached_Extension_Language_Python.php
Your extension PHP class should look something like this (I removed the comments for the sake of brevity - please add at least PHPDoc to your code):
<?php
class Prism_Detached_Extension_Language_Python extends Prism_Detached_Extension_Base
{
public function getName ()
{
return "Language: Python";
}
public function getSortOrder ()
{
// all plugins are 50+ and the languages should be lower than that
return 20;
}
public function getCss ()
{
// you can access $this->theme for a stylesheet switch, depending on the chosen theme
return array(
"css/lang-python.css"
);
}
public function getJavascript ()
{
return array(
"javascript/lang-python.js"
);
}
}
Will My Custom Extension Still Be There After I Updated The Plugin Using The WordPress Plugin Mechanism?
WordPress will remove them. WordPress completely removes the old extension directory and recreates it with the new plugin files. So make a backup of your custom extensions before updating!