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 | |
copyright |
Copyright (c) 2014 George Holmes II |
license |
GPLv2 or later |
__construct(string $path)
since |
GWP_Plugin (0.1) |
---|---|
string
File path of plugin
is_mobile() : boolean
Returns true if user is on a mobile device and false if user is on a desktop device.
<?php
if (GWP_Plugin::is_mobile() == true)
{
// do stuff exclusive to mobile devices
}
?>
since |
GWP_Plugin (0.1) |
---|---|
static | |
boolean
add_styles(array $styles, string $location)
since |
GWP_Plugin (0.1) |
---|---|
array
string
add_front_end_styles(array $styles, int $priority = 10)
<?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) |
---|---|
array
int
add_admin_styles(array $styles, int $priority = 10)
<?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) |
---|---|
array
int
add_scripts(array $scripts, string $location)
since |
GWP_Plugin (0.1) |
---|---|
array
string
add_front_end_scripts(array $scripts, int $priority = 10)
<?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) |
---|---|
array
int
add_admin_scripts(array $scripts, int $priority = 10)
<?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) |
---|---|
array
int
image_sizes(array $sizes)
<?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) |
---|---|
array
init(object $callback = NULL)
<?php
$my_plugin = new GWP_Plugin();
$my_plugin->init(function () {
// callback code
});
?>
since |
GWP_Plugin (0.1) |
---|---|
object
debug : boolean
since |
GWP_Plugin (0.1) |
---|---|
var | |
boolean
plugin_path : string
since |
GWP_Plugin (0.1) |
---|---|
access |
protected |
var | |
string
front_end_styles_priority : int
since |
GWP_Plugin (0.1) |
---|---|
var | |
int
admin_styles_priority : int
since |
GWP_Plugin (0.1) |
---|---|
var | |
int
front_end_scripts_priority : int
since |
GWP_Plugin (0.1) |
---|---|
var | |
int
admin_scripts_priority : int
since |
GWP_Plugin (0.1) |
---|---|
var | |
int
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 | |
object
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 | |
object
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 | |
object
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 | |
object