forked from mpeshev/DX-Plugin-Base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdx-plugin-base.php
290 lines (254 loc) · 7.74 KB
/
dx-plugin-base.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* Plugin Name: Your Sample Plugin
* Plugin URI: http://example.org/
* Description: Your sample plugin description
* Author: nofearinc
* Author URI: http://devwp.eu/
* Version: 0.1a
* Text Domain: dx-sample-plugin
* License: GPL2
Copyright 2011 mpeshev (email : mpeshev AT devrix DOT com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
*
* The plugin base class - the root of all WP goods!
*
* @author nofearinc
*
*/
class DX_Plugin_Base {
/**
*
* Assign everything as a call from within the constructor
*/
function __construct() {
// add script and style calls the WP way
$this->dx_add_JS();
$this->dx_add_CSS();
// register admin pages for the plugin
$this->dx_admin_pages();
// register meta boxes for Pages (could be replicated for posts and custom post types)
$this->dx_meta_boxes();
// Register custom post types and taxonomies
$this->dx_custom_post_types();
$this->dx_custom_taxonomies();
// Register activation and deactivation hooks
$this->dx_on_activate();
$this->dx_on_dectivate();
/*
$this->dx_add_widgets();
$this->dx_add_shortcodes();
$this->dx_register_settings();
*/
// TODO: add some filters so that this may not be edited at all but hooked instead
}
/**
*
* Adding JavaScript scripts
*
* Loading existing scripts from wp-includes or adding custom ones
*
*/
function dx_add_JS() {
wp_enqueue_script('jquery');
// load custom JSes and put them in footer
wp_register_script('samplescript', plugins_url( 'samplescript.js' , __FILE__ ), array('jquery'), '1.0', true);
wp_enqueue_script('samplescript');
}
/**
*
* Add CSS styles
*
*/
function dx_add_CSS() {
wp_register_style('samplestyle', plugins_url('samplestyle.css', __FILE__), array(), '1.0', 'screen');
wp_enqueue_style('samplestyle');
}
/**
*
* Add admin pages via callback
*
*/
function dx_admin_pages() {
add_action( 'admin_menu', array(&$this, 'dx_admin_pages_callback') );
}
/**
*
* Callback for registering pages
*
* This demo registers a custom page for the plugin and a subpage
*
*/
function dx_admin_pages_callback() {
add_menu_page('Plugin Base Admin', 'Plugin Base Admin', 'edit_themes', 'dx-plugin-base', array(&$this, 'dx_plugin_base'));
add_submenu_page( 'dx-plugin-base', 'Base Subpage', 'Base Subpage', 'edit_themes', 'dx-base-subpage', array(&$this, 'dx_plugin_subpage'));
}
/**
*
* The content of the base page
*
*/
function dx_plugin_base() {
}
/**
*
* The content of the subpage
*
*/
function dx_plugin_subpage() {
}
/**
*
* Registering meta boxes
*
*/
function dx_meta_boxes() {
add_action( 'add_meta_boxes', array(&$this, 'dx_meta_boxes_callback') );
}
/**
*
* Adding right and bottom meta boxes to Pages
*
*/
function dx_meta_boxes_callback() {
// register side box
add_meta_box(
'dx_side_meta_box',
__( 'DX Side Box', 'dxbase' ),
array(&$this, 'dx_side_meta_box'),
'page',
'side',
'high'
);
// register bottom box
add_meta_box(
'dx_bottom_meta_box',
__( 'DX Bottom Box', 'dxbase' ),
array(&$this, 'dx_bottom_meta_box'),
'page'
);
}
/**
*
* Init right side meta box here
* @param post $post the post object of the given page
* @param metabox $metabox metabox data
*/
function dx_side_meta_box($post, $metabox) {
_e('<p>Side meta content here</p>', 'dxbase');
}
/**
*
* Init bottom meta box here
* @param post $post the post object of the given page
* @param metabox $metabox metabox data
*/
function dx_bottom_meta_box($post, $metabox) {
_e('<p>Bottom meta content here</p>', 'dxbase');
}
/**
* Register custom post types
*
*/
function dx_custom_post_types() {
add_action('init', array( &$this, 'dx_custom_post_types_callback' ));
}
function dx_custom_post_types_callback() {
register_post_type('pluginbase', array(
'labels' => array(
'name' => __('Base Items', 'dxbase'),
'singular_name' => __('Base Item', 'dxbase'),
'add_new' => _x('Add New', 'pluginbase', 'dxbase' ),
'add_new_item' => __('Add New Base Item', 'dxbase' ),
'edit_item' => __('Edit Base Item', 'dxbase' ),
'new_item' => __('New Base Item', 'dxbase' ),
'view_item' => __('View Base Item', 'dxbase' ),
'search_items' => __('Search Base Items', 'dxbase' ),
'not_found' => __('No base items found', 'dxbase' ),
'not_found_in_trash' => __('No base items found in Trash', 'dxbase' ),
),
'description' => __('Base Items for the demo', 'dxbase'),
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'exclude_from_search' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 40, // probably have to change, many plugins use this
'supports' => array(
'title',
'editor',
'thumbnail',
'custom-fields',
'page-attributes',
),
'taxonomies' => array('post_tag')
));
}
/**
* Register custom taxonomies
*
*/
function dx_custom_taxonomies() {
add_action('init', array(&$this, 'dx_custom_taxonomies_callback' ));
}
function dx_custom_taxonomies_callback() {
register_taxonomy('pluginbase_taxonomy','pluginbase',array(
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Base Item Taxonomies', 'taxonomy general name', 'dxbase' ),
'singular_name' => _x( 'Base Item Taxonomy', 'taxonomy singular name', 'dxbase' ),
'search_items' => __( 'Search Taxonomies', 'dxbase' ),
'popular_items' => __( 'Popular Taxonomies', 'dxbase' ),
'all_items' => __( 'All Taxonomies', 'dxbase' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Base Item Taxonomy', 'dxbase' ),
'update_item' => __( 'Update Base Item Taxonomy', 'dxbase' ),
'add_new_item' => __( 'Add New Base Item Taxonomy', 'dxbase' ),
'new_item_name' => __( 'New Base Item Taxonomy Name', 'dxbase' ),
'separate_items_with_commas' => __( 'Separate Base Item taxonomies with commas', 'dxbase' ),
'add_or_remove_items' => __( 'Add or remove Base Item taxonomy', 'dxbase' ),
'choose_from_most_used' => __( 'Choose from the most used Base Item taxonomies', 'dxbase' )
),
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
));
register_taxonomy_for_object_type('pluginbase_taxonomy', 'pluginbase');
}
/**
* Register activation hook
*
*/
function dx_on_activate() {
register_activation_hook( __FILE__, 'dx_on_activate_callback' );
}
function dx_on_activate_callback() {
// do something on activation
}
/**
* Register deactivation hook
*
*/
function dx_on_deactivate() {
register_activation_hook( __FILE__, 'dx_on_deactivate_callback' );
}
function dx_on_deactivate_callback() {
// do something when deactivated
}
}
// Initialize everything
$dx_plugin_base = new DX_Plugin_Base();