GWP_Plugin

GWP_Plugin Class that implements common functions of a WordPress plugin in an effort to reduce the amount of functions written in the global namespace and redundant code.

Requires PHP 5.3.0 and above

version 0.1
package

GWP_Plugin

link

http://gholme4.github.io/GWP_Plugin/classes/GWP_Plugin.html

copyright

Copyright (c) 2014 George Holmes II

license

GPLv2 or later

Methods

Constructor

__construct(string $path) 
since

GWP_Plugin (0.1)

Arguments

$path

string

File path of plugin

Determines if user's device is handheld or desktop.

is_mobile() : boolean
static

Returns true if user is on a mobile device and false if user is on a desktop device.

Usage

<?php if (GWP_Plugin::is_mobile() == true) {    // do stuff exclusive to mobile devices } ?>
since

GWP_Plugin (0.1)

static

Response

boolean

Validates array of styles to get registered

add_styles(array $styles, string $location) 
since

GWP_Plugin (0.1)

Arguments

$styles

array

$location

string

Add front end styles to be registered

add_front_end_styles(array $styles, int $priority = 10) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->add_front_end_styles(array ( array ( array( "handle" => "another-style", "src" => plugins_url('/css/another-style.css?rand=' . rand(), __FILE__) ), array( "handle" => "yet-another-style", "src" => plugins_url('/css/yet-another-style.css?rand=' . rand(), __FILE__) ) ), 15 ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

Arguments

$styles

array

$priority

int

Add admin styles to be registered

add_admin_styles(array $styles, int $priority = 10) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->add_admin_styles(array ( array ( array( "handle" => "another-style", "src" => plugins_url('/css/another-style.css?rand=' . rand(), __FILE__) ), array( "handle" => "yet-another-style", "src" => plugins_url('/css/yet-another-style.css?rand=' . rand(), __FILE__) ) ), 15 ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

Arguments

$styles

array

$priority

int

Validates array of scripts to get registered

add_scripts(array $scripts, string $location) 
since

GWP_Plugin (0.1)

Arguments

$scripts

array

$location

string

Add front end scripts to be registered

add_front_end_scripts(array $scripts, int $priority = 10) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->add_front_end_scripts(array ( array ( array( "handle" => "another-script", "src" => plugins_url('/js/another-script.js', __FILE__) ), array( "handle" => "yet-another-style", "src" => plugins_url('/js/yet-another-script.js', __FILE__) ) ), 15 ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

Arguments

$scripts

array

$priority

int

Add admin scripts to be registered

add_admin_scripts(array $scripts, int $priority = 10) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->add_admin_scripts(array ( array ( array( "handle" => "another-script", "src" => plugins_url('/css/another-script.js', __FILE__) ), array( "handle" => "yet-another-script", "src" => plugins_url('/css/yet-another-script.js', __FILE__) ) ), 15 ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

Arguments

$scripts

array

$priority

int

Add custom image sizes

image_sizes(array $sizes) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->image_sizes( array ( array("name" => "wide-small", "width" => 320, "height" => 240, "crop" => true), array("name" => "wide-medium", "width" => 640, "height" => 480, "crop" => true), ) ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

Arguments

$sizes

array

Create a custom menu page in the WordPress admin

single_menu_page(array $single_page) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->single_menu_page( array ( "page_title" => "My Plugin Page", "menu_title" => "My Plugin Page", "menu_slug" => "my_plugin_page", "icon" => plugins_url('/images/menu-icon.png', __FILE__), "position" => 100, "page_content" => function () { echo "<h1>My Plugin Page</h1>"; } ) ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1.1)

Arguments

$single_page

array

Create a custom group of menu pages in the WordPress admin

group_menu_pages(array $group_pages) 

Usage

<?php $my_plugin = new GWP_Plugin(); $my_plugin->group_menu_pages( array ( "menu_name" => "My Plugin Options", "menu_slug" => "my_plugin_options", "icon" => plugins_url('/images/menu-icon.png', __FILE__), "position" => 100, "pages" => array ( array ( "page_title" => "First Page", "menu_title" => "First Page", "menu_slug" => "first_page", "page_content" => function () { echo "<h1>First Page</h1>"; } ), array ( "page_title" => "Second Page", "menu_title" => "Second Page", "menu_slug" => "second_page", "page_content" => function () { echo "<h1>Second Page</h1>"; } ) ) ); $my_plugin->init(); ?>
since

GWP_Plugin (0.1.2)

Arguments

$group_pages

array

Initializes plugin. Can be passed an optional callback.

init(object $callback = NULL) 
<?php $my_plugin = new GWP_Plugin(); $my_plugin->init(function () { // callback code }); ?>
since

GWP_Plugin (0.1)

Arguments

$callback

object

Properties

Logs class generated warnings to error log if true

debug : boolean
since

GWP_Plugin (0.1)

var

Type(s)

boolean

Path to plugin file

plugin_path : string
since

GWP_Plugin (0.1)

access

protected

var

Type(s)

string

Front end stylesheets action priority

front_end_styles_priority : int
since

GWP_Plugin (0.1)

var

Type(s)

int

Admin stylesheets action priority

admin_styles_priority : int
since

GWP_Plugin (0.1)

var

Type(s)

int

Front end scripts action priority

front_end_scripts_priority : int
since

GWP_Plugin (0.1)

var

Type(s)

int

Admin scripts action priority

admin_scripts_priority : int
since

GWP_Plugin (0.1)

var

Type(s)

int

User defined function containing code to be ran when the plugin is activated.

activate : object
<?php $my_plugin = new GWP_Plugin(); $my_plugin->activate = function () {     // do stuff when plugin is activated }; $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

var

Type(s)

object

User defined function containing code to be ran when the plugin is deactivated.

deactivate : object
<?php $my_plugin = new GWP_Plugin(); $my_plugin->deactivate = function () {     // do stuff when plugin is deactivated }; $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

var

Type(s)

object

User defined function containing code to be triggered within the <head></head> section of the active template

wp_head : object
<?php $my_plugin = new GWP_Plugin(); $my_plugin->wp_head = function () {     // do stuff within theme header }; $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

var

Type(s)

object

User defined function containing code to be triggered within the <head></head> section of the WordPress dashboard

admin_head : object
<?php $my_plugin = new GWP_Plugin(); $my_plugin->admin_head = function () {     // do stuff within admin header }; $my_plugin->init(); ?>
since

GWP_Plugin (0.1)

var

Type(s)

object