Support Center

About Koken

This Help Center provides support for Koken, a free content management system designed for photographers, artists and designers.

Building your first plugin

Building your first plugin

Last Updated: Jul 25, 2013 04:49PM EDT

To create your first plugin, create a folder inside the storage/plugins directory. Folder names should only contain alphanumeric characters, plus hyphens or underscores in place of spaces.

It is very important that you name your folder uniquely so it does not conflict with other plugins.

We recommend the following naming structure for your plugin folder:

company-name-plugin-name

Or:

your-name-plugin-name

For example, if Acme, Inc., were to write a plugin for widgets, the folder name would be:

acme-widgets

Or, if the plugin was authored by a single developer (John Smith), we would recommend:

john-smith-widgets

Once the folder is created, it will need two files: plugin.json and plugin.php.

plugin.json

Metadata about your plugin is stored in the plugin.json file. At minimum, it should contain the following:

{ 
  "name": "My plugin name",
  "version": "1.0",
  "description": "Brief description of this plugin.",
  "author": {
    "name": "Your Name",
    "link": "http://yoursite.com"
  }
}

Replace the values in plugin.json with your own details. This info will be used when displaying the plugin in Settings > Plugins.

plugin.php

The functionality of the plugin is implemented in the plugin.php file. Koken plugins are PHP classes that extend the base KokenPlugin class. Your PHP class name should follow the same guidelines as your folder name above. Returning to our "acme-widgets" example, the plugin.php file would look like this:

<?php

class AcmeWidgets extends KokenPlugin {

}

It is absolutely mandatory that your plugin extends the KokenPlugin class, otherwise it will not function properly.

Next, you need to register your class with the hooks or filters you wish interact with. This is done within your class's constructor.

<?php

class AcmeWidgets extends KokenPlugin {

  function __construct()
  {
    // Register our class's add_widget function with the before_closing_head hook.
    $this->register_hook('before_closing_head', 'add_widget');
  }

  // This function is called just before the closing </head> tag in the published site.
  function add_widget()
  {
    echo "<script>alert('Widgets, engage!');</script>";
  }
}

You can register as many hooks or filters as you would like in your class.

<?php

class AcmeWidgets extends KokenPlugin {

  function __construct()
  {
    // Register our class's add_widget function with the before_closing_head hook.
    $this->register_hook('before_closing_head', 'add_widget');

    // Register our class's remove_widget function with the before_closing_body hook.
    $this->register_hook('before_closing_body', 'remove_widget');
  }

  // This function is called just before the closing </head> tag in the published site.
  function add_widget()
  {
    echo "<script>alert('Widgets, engage!');</script>";
  }

  // This function is called just before the closing </body> tag in the published site.
  function remove_widget()
  {
    echo "<script>alert('Widgets, disengage!');</script>";
  }
}

Where to from here

Now that you have the basics down, we recommend reading through a real-world example of how the Google Analytics plugin for Koken was created.

support@koken.me
http://assets3.desk.com/
false
koken
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete