Step 2. Understanding The Plugin Object

There are two primary classes that control all plugins, and both can be found in the admin/cp-classes directory:

The plugin class is the primary tool for loading and setting up the plugin's environment, while the pluginLoader class gets extended into your plugin's custom classes, granting you access to the plugin class itself.

Class Overview

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Class Variables

// ID of the plugin
public $id;

// Absolutely path to the plugin directory.
public $path;

// Array containing information about the plugin
// taken directly from the database row in ppSD_widgets.
public $data = array();

// Array of config values
public $global = array();

// Array of options
public $options = array();

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Class Methods

// Add an entry into the activity feed on the administrative dashboard
public function feed($task, $user_id, $user_type, $act_id = '', $note = '', $owner = '2', $force_method = false);

// Get a config value
public function getGlobal($key);

// Loads a custom plugin class
public function load($id);

// Returns an instance of the ExtensionObject
public function getExtension();

// Renders a plugin template
public function renderTemplate($id, $changes, $headers = '1');

// Get an option
public function getOption($name);

// Updates a plugin option, invoking the custom option
// script, if available.
public function updateOption($key, $value);

// Connect to the plugin's database, if any.
public function connectLocal();

// Connect to the Zenbership database.
public function connectZen();

Using the Plugin Class

While you can technically run the code however you want, best practice is to create custom classes within your plugin's /custom/plugins/my_plugin_name/functions folder which extend the pluginLoader class, as follows:

<?php
/**
 * Because this extends the pluginLoader class, we
 * now have access to the plugin object using the 
 * $this->plugin object.
 */
class myCustomClass extends pluginLoader {
    public function myFunction()
    {
        var_dump($this->plugin);

        // $this->plugin->connectLocal();
        // $this->plugin->connectZen();
    }
}

Usage Within a Hook

A full example of how this can now be used within a hook can be found here.

Last modified 3 weeks ago.