Creating A Custom Extension

Jannik Zschiesche edited this page Jul 30, 2013 · 3 revisions
Clone this wiki locally

This is a walkthrough of creating a custom extension.

1. Intro

Imagine you want to add a new language, for example Python.

2. Gather The Prism Extension Files

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

3. Create The Extension Directory

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.

4. Add The Extension PHP Class

  • 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):


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(

    public function getJavascript ()
        return array(

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!