tz-tools.php
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
Plugin Name: Tenzing Tools
Version: 0.1
Description: Various classes to help out with stuff
Author: Tenzing
*/
if (version_compare(PHP_VERSION, '5.2.2') !== 1) {
die('PHP version 5.2.2 or greater is required');
}
TzTools::load();
class TzTools {
public static function load() {
// set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__));
spl_autoload_register(Array(__CLASS__, 'autoloader'));
require_once(dirname(__FILE__) . '/wp_functions.php');
_register_script('addEvent', plugins_url('addEvent.js', __FILE__));
_register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__));
_register_script('fireEvent', plugins_url('fireEvent.js', __FILE__));
add_action('widgets_init', Array('MenuWidget', 'init'));
}
public static function autoloader($class) {
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php';
if (is_file($file)) {
include($file);
}
}
}
function add_actions($class) {
if (!class_exists($class)) {
throw new Exception("$class does not exist");
}
$ref = new ReflectionClass($class);
$actions = $ref->getMethods(ReflectionMethod::IS_STATIC);
foreach ($actions as $action) {
add_action($action->name, Array($class, $action->name));
}
}
function add_shortcodes($class) {
if (!class_exists($class)) {
throw new Exception("$class does not exist");
}
$ref = new ReflectionClass($class);
$methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
foreach ($methods as $method) {
add_shortcode($method->name, Array($class, $method->name));
}
}
function add_filters($class) {
if (!class_exists($class)) {
throw new Exception("$class does not exist");
}
$ref = new ReflectionClass($class);
$methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
foreach ($methods as $method) {
add_filter($method->name, Array($class, $method->name));
}
}
?>