-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-library-init.php
More file actions
229 lines (198 loc) · 7.5 KB
/
wp-library-init.php
File metadata and controls
229 lines (198 loc) · 7.5 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/*
Plugin Name: WP-Library
Plugin URI: http://atlanticbt.com/
Description: Provides a foundation and extensions for/to common Wordpress functions or tasks, such as creating and installing plugins, making complex database queries, etc
Version: 0.3.2
Author: atlanticbt, zaus, tnblueswirl
Author URI: http://www.atlanticbt.com/
License: GPLv2 or later
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* Common shared functions and stuff -- could put it in theme/functions.php, but this way is "available to everything"
*
* @package AtlanticBT_Common
* @subpackage WP_Library
* @since MM-Solid Rock 1.0, MPS Society 1.0
*
* @version 0.3.1
*
* HISTORY:
* - 0.1 creation, shared stuff
* - 0.2 mvc stub
* - 0.2.1 form validation, lang
* - 0.3 turned into a plugin
* - 0.3.1 authors credits
*/
/*
* Use this section to include other library files that should be available globally.
* Basically just used so that you can include all the other files by including this one.
*/
#region ========================== FILE INCLUSIONS =============================
define( 'WP_LIBRARY_DIR', dirname(__FILE__)/*.'/includes'*/ );
define( 'WP_LIBRARY_URL', plugins_url('', __FILE__) );
if( ! function_exists('wp_library_path')):
/**
* Get the filepath to library file
* @param $file the file to include; provide with extension
*/
function wp_library_path($file){
return WP_LIBRARY_DIR.'/'.$file;
}//-- fn wp_library_path
endif; //func-exists
if( ! function_exists('wp_library_url')):
/**
* Get the filepath to library file
* @param $file the file to include; provide with extension
*/
function wp_library_url($file){
return WP_LIBRARY_URL.'/'.$file;
}//-- fn wp_library_url
endif; //func-exists
if( ! function_exists('wp_library_include') ):
/**
* Include given library file, optional subdirectory
* NOT PART OF WP CORE
*
* @param $shortpath the file to include; provide with extension, optional subdirectory (no beginning slash)
* @param $isRequired {false} include() or require(), as given
* @param $isOnce {true} *_once() if specified
*/
function wp_library_include($shortpath, $isRequired = false, $isOnce = true){
if( $isRequired ){
if( $isOnce ){
require_once(wp_library_path($shortpath));
}
else {
require(wp_library_path($shortpath));
}
}// isRequired
else {
if( $isOnce ){
include_once(wp_library_path($shortpath));
}
else {
include(wp_library_path($shortpath));
}
}// not required
}//-- fn wp_library_include
endif; //func-exists
if( ! function_exists('wp_is_library')):
/**
* Check if the given library (file) exists
* @param $shortpath the file to include; provide with extension, optional subdirectory (no beginning slash)
*/
function wp_is_library($shortpath){
return file_exists( wp_library_path($shortpath) );
}//-- fn wp_is_library
endif; //func-exists
// "mandatory" includes
wp_library_include('includes/common-functions.php'); //library file - Shared functions to be available to other files
wp_library_include('mvc/common_micromvc.php'); //more shared functions - mainly for micromvc/mvc files, but helpful in general: v() and kv()
wp_library_include('includes/wp_library_base.class.php'); //root class for library - inheritable common methods
#wp_library_include('wp_pagination.class.php' ); // pagination helper
#wp_library_include('wp_querybuilder.class.php' ); // complex-sql statement builder
#endregion ========================== FILE INCLUSIONS =============================
#region ========================== ADMIN PAGE =============================
/**
* Actual plugin class, to integrate with admin
* For now more of an example
*/
class WP_Library_Plugin extends WP_Library_Base {
/**
* Internal namespace
*/
private $N = 'wp_library_plugin';
/**
* Bucket for settings pages
*/
private $settings;
public function __construct(){
if( !class_exists('WP_Options_Page') ) {
wp_library_include('includes/wp_options_page.class.php'); //options page helper
}
//create settings pages
$this->settings = array();
$this->settings['main'] = new WP_Options_Page($this->N);
//need to check for any one of these, since registering one should happen when we're on that specific page
if( $this->settings['main']->register(
'WP Library'
, 'WP-Library'
, array(
'style'=>array('submenu', 'tools.php')
, 'capabilities'=>'manage_options'
)
) ) {
//add action to set up plugin settings
$this->add_hook('admin_init');
}// if settings registered
}//-- fn __construct
public function admin_init(){
$this->settings['main']
#->add_scripts( array('ABT_Ecom', 'admin_scripts' ))
->add_section('general', 'General', 'Global administration settings (this is just an example for now).')
->add_field('general', 'admin_percentage', 'Admin Percentage (default)', array(
'type' => 'text',
'description' => 'How much of each purchase should be "diverted" as an admin fee? <em>Note: this only applies for reporting</em>',
'std' => '5',
'suffix' => '%',
'sanitize' => array('numeric', array('min'=>0), array('max'=>100))
))
->add_field('general', 'some_text', 'Some Text', array(
'type' => 'p',
'text' => 'arbitrary paragraph'
))
->add_section('tax_shipping', 'Tax and Shipping', 'Apply tax and/or shipping to items.')
->add_field('tax_shipping', 'has_tax', 'Apply Tax', array(
'type' => 'select',
'description' => 'Can items be taxed?',
'std' => true,
'choices' => array(
true => 'Yes',
false => 'No'
),
'sanitize' => array('boolean')
))
->add_field('tax_shipping', 'tax_rate', 'Tax Rate', array(
'type' => 'text',
'description' => 'If items are taxed, what is their default tax rate (percent)?',
'std' => '7.75',
'suffix' => '%',
'sanitize' => array('numeric', array('min'=>0), array('max'=>100))
))
->add_field('tax_shipping', 'has_shipping', 'Apply Shipping', array(
'type' => 'select',
'description' => 'Can items be shipped? If so, they\'ll have a shipping cost and weight.',
'std' => true,
'choices' => array(
true => 'Yes',
false => 'No'
),
'sanitize' => array('boolean')
))
->add_field('tax_shipping', 'shipping_rate', 'Shipping Rate', array(
'type' => 'text',
'description' => 'If items are shipped, what is their default shipping cost (%)?',
'std' => '5.00',
'suffix' => '%',
'sanitize' => array('numeric', array('min'=>0), array('max'=>100))
))
;
}//-- fn admin_init
}///--- class WP_Library_Plugin
//call it
new WP_Library_Plugin();
#endregion ========================== ADMIN PAGE =============================