-
Notifications
You must be signed in to change notification settings - Fork 3
/
OriggamiWpProgrammingUtils.php
101 lines (85 loc) · 2.55 KB
/
OriggamiWpProgrammingUtils.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Plugin Name: Origgami Wp Programming Utils
* Plugin URI: http://origgami.com.br
* Description: Programming Utilities for Wordpress
* Version: 1.0.0
* Author: Origgami
* Author URI: http://origgami.com.br
* Text Domain:
* Domain Path: /i18n
* Network:
* License: GPL2
* Bitbucket Plugin URI: https://bitbucket.org/origgamiwordpressplugins/origgami-wp-programming-utils
* Bitbucket Branch: master
*/
namespace OriggamiWpProgrammingUtils;
if (!class_exists('\OriggamiWpProgrammingUtils\OriggamiWpProgrammingUtils')) {
require_once dirname(__FILE__) . '/DesignPatterns/Singleton.php';
//require './oop_functions/OOPFunctions.php';
/**
* Description of WpProgrammingTools
*
* @author Pablo Pacheco <pablo.pacheco@origgami.com.br>
*/
class OriggamiWpProgrammingUtils extends DesignPatterns\Singleton {
private $autoload;
private $oopFunctions;
private $utils;
protected function __construct() {
parent::__construct();
add_action('activated_plugin', array($this, 'my_plugin_load_first'));
$this->loadUsefulFiles();
$this->handleAutoload();
}
function my_plugin_load_first() {
//$path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__);
$path = plugin_basename(dirname(__FILE__)) . '/' . basename(__FILE__);
$plugins = get_option('active_plugins');
if ($plugins) {
if ($key = array_search($path, $plugins)) {
array_splice($plugins, $key, 1);
array_unshift($plugins, $path);
update_option('active_plugins', $plugins);
}
}
}
private function loadUsefulFiles() {
require_once dirname(__FILE__) . '/Autoload/WpAutoload.php';
require_once dirname(__FILE__) . '/PhpFunctions/php_functions.php';
}
private function handleAutoload() {
if (!$this->getAutoload()) {
$autoload = new Autoload\WpAutoload(array(get_stylesheet_directory(), WP_PLUGIN_DIR));
$dir = basename(dirname(__FILE__));
$autoload->addNamespaceReplace(array('OriggamiWpProgrammingUtils' => $dir));
$autoload->handleAutoload();
$this->setAutoload($autoload);
}
}
/**
*
* @return Autoload\WpAutoload;
*/
function getAutoload() {
return $this->autoload;
}
function setAutoload(Autoload\WpAutoload $autoload) {
$this->autoload = $autoload;
}
/**
*
* @return Utils\Utils
*/
function getUtils() {
if (!$this->utils) {
$this->setUtils(new Utils\Utils());
}
return $this->utils;
}
function setUtils(Utils\Utils $utils) {
$this->utils = $utils;
}
}
$programmingTools = \OriggamiWpProgrammingUtils\OriggamiWpProgrammingUtils::getInstance();
}