logo epowerpress.com
Submit Website Manage Directory Listings Edit Profile
Home | General Posts |

How to code a ePowerPress plugin

If you can code a PHP function, then you can as easily code a PowerPress plugin!

Note, if you code a PowerPress plugin, then let me know, and I can link to your website from mine where people can download your ePowerPress plugin. Simply start a new topic and use the tag #PowerPressPlugin

Please note, the core team of ePowerPress developers can provide you your custom plugin at a very affordable price. Get in touch with us here with your requirements, and allow us to give you an affordable price quote.

How ePowerPress Plugins work

ePowerPress uses a separate layer for processing code, and a separate layer for HTML display. This means that you can control the output displayed before the HTML layers are loaded. This is what your plugin will do. Using a plugin, you can:

  • Replace or add to output of core ePowerPress
  • Create custom hooks, thus creating a complete new section for the website.
  • Replace a core PowerPress function, and code up your own!

Replacing a core PowerPress function with your own custom function

"INDEX.PHP" is the primary file of ePowerPress, which loads all other files, including core ePowerPress files and plugin files.
Core PowerPress functions are in a PHP file inside "CODE/" folder, "00ini.php"
So, if you want to replace a core PowerPress function, then all you have to do is:

  1. Make a new PHP file, example "myFunction.php"
  2. Code your PHP function in this file, with the same name as PowerPress has for this function. You will need to pass the same number of parameters also (function signature must remain same)
  3. Now include/require this new PHP file just before PowerPress includes "code/00ini.php" file.

That's it, you have just replaced a core PowerPress function with your own, without touching the core code of PowerPress!
This is beneficial because this way you will not have to recode the whole function again when a PowerPress upgrade is available.
You can simply replace old PowerPress files with new upgraded files, and you will not have to worry about compatibility or Fatal errors.

Replacing or adding to output of ePowerPress

This is equally easy as replacing a core function.
There is only one additional step needed, which is, telling PowerPress to load your plugin.
This can be done by adding one line in your PHP plugin file, at the top, like this:
<?php //my new plugin
$rv['addOn'][] = "my_plugin_name";
//rest of plugin code
?>

Then include/require this PHP file "after" the "code/00ini.php" file is loaded.
Note, this is your plugin name, not your function name to call. Function name will appear later in the PHP file, in a minute about that.

What you did is, you loaded a "plugin" in PowerPress.
At different stages of processing, PowerPress looks for certain function names to call. It looks for these functions in its list of "loaded plugins".
By adding the above line in your PHP plugin file, you registered your plugin with PowerPress.
Now its time to code the actual function which replaces some core output.

List of plugin calls for ePowerPress

Suppose you want to add something to your homepage, before or after the blog posts are loaded.

Functions which PowerPress will look for these are:

  1. "{Your_plugin_name}_homepageTop";
  2. "{Your_plugin_name}_homepageBottom";

So if your loaded plugin has a function with any of those names, then ePowerPress will execute those functions.
Both those above functions do not have any parameters passed to them, so to replace or add to the output, you will have to write to a global variable "$co" and output of your PowerPress homepage will change.

Sample plugin to add to homepage output

<?php
$rv['addOn'][] = "myPlugin";

if( !function_exists("myPlugin_homepageBottom") ){
    function myPlugin_homepageBottom(){
    global $co;
    $co.="<p> This is plugin added text on homepage output at the bottom. </p>";
    }
}
?>

Copy that code in a PHP file, "code/plugin/someName.php", then include that file in index.php of PowerPress in the plugin section, like this:

//start plugins section

require_once( $ROOT. 'code/plugin/somename.php' );

//end plugin section

Then open your PowerPress homepage, and you will see the added line towards the end on the homepage below your blog posts.

Note, all the plugins that are not replacing a core PowerPress function, they must be loaded inside the "start and end" plugins section. Its better this way, and easier to manage.

If you need to create database tables for your plugin to store data, then you can either create a new "HOOK" for this, or use the existing "INSTALL" hook.

If using "INSTALL" hook, then you should be careful of a couple of things:

  • Password protect your entire table creation code, so that only site owner can run that code, and not just any hacker.
  • Identify your plugin tables with a proper name so that site owners can select your tables during install.

In the below sample code, the KEY of "$table" is what users will see when they will install your plugin from the "domain.com/install", so make sure that this KEY has your plugin name. This way users can know which tables they are about to recreate completely. Additionally, this prevents errors of replacing tables of a different plugin by mistake.

Creating hooks or using existing hooks

Suppose you want your code to be executed when "install" hook is loaded in browser like this:
domain.com/install
Then you can modify your plugin something like this below:

<?php
$rv['addOn'][] = "myPlugin";

if( !function_exists("myPlugin_homepageBottom") ){
    function myPlugin_homepageBottom(){
    global $co;
    $co.="<p> This is plugin added text on homepage output at the bottom. </p>";
    }
}

//identify your database table
$table['myPlugin_dataTable'] = 'myPlugin_table_name';

//using install hook

switch( $hook ){

    case "install":
      if( isset($_POST['pd']) && $_POST['pd'] == $dbp ){
      //do the install
      }
    break;

    case "someOtherHook":

      //code of hook
      $val1 = $load[1];
      echo "<p> $val1 </p>";
    break;
}//switch ends

?>

If you use an existing hook, then your code will get executed when that hook is opened in the browser on the domain.
It can be executed first, or last, depends where you included the plugin file.
In the above example, the "someOtherHook", will be a completely new page on your PowerPress installation, which can be opened like this:
domain.com/someOtherHook/
or like this with parameters:
domain.com/someOtherHook/val1/val2/
where va1 and val2 are additional parameters available to your code in the array "$load".

Above plugin file is a valid working plugin file. You can try loading this as a plugin in your PowerPress installation.

There is also a sample plugin file provided in "code/plugin/" folder.
Include that file in index.php in the plugins section, then open:
domain.com/sample
and you will see content here.
Remove the included PHP file from index.php, and the content will also be removed.
This is because the content for hook "sample" is in the sample plugin file, and its not a core hook.

List of plugin calls for ePowerPress

For any help, feel free to start a new topic and tag your post with #PowerPressPlugin and I will try to help as much as I can.

You might also be interested in :

Share on AtHashPal Reddit Digg LinkedIn StumbleUpon -->
Share on AtHashPal Reddit Digg LinkedIn StumbleUpon -->
Share on AtHashPal Reddit Digg LinkedIn StumbleUpon -->