-
Notifications
You must be signed in to change notification settings - Fork 11
/
pods-extend.php
382 lines (315 loc) · 9.49 KB
/
pods-extend.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/*
Plugin Name: Pods Starter Plugin
Plugin URI: http://example.com/
Description: Description
Version: 0.0.1
Author: Your Name
Author URI: http://example.com/
Text Domain: pods-extend
License: GPL v2 or later
*/
/**
* Copyright (c) YEAR Your Name (email: Email). All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
* **********************************************************************
*/
// don't call the file directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Define constants
*
* @since 0.0.2
*/
define( 'PODS_EXTEND_SLUG', plugin_basename( __FILE__ ) );
define( 'PODS_EXTEND_URL', plugin_dir_url( __FILE__ ) );
define( 'PODS_EXTEND_DIR', plugin_dir_path( __FILE__ ) );
/**
* Pods_Extend class
*
* @class Pods_Extend The class that holds the entire Pods_Extend plugin
*
* @since 0.0.1
*/
class Pods_Extend {
/**
* Constructor for the Pods_Extend class
*
* Sets up all the appropriate hooks and actions
* within the plugin.
*
* @since 0.0.1
*/
public function __construct() {
/**
* Plugin Setup
*/
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
// Localize our plugin
add_action( 'init', array( $this, 'localization_setup' ) );
/**
* Scripts/ Styles
*/
// Loads frontend scripts and styles
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// Loads admin scripts and styles
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
/**
* Hooks that extend Pods
*
* NOTE: These are some example hooks that are useful for extending Pods, uncomment as needed.
*/
//Example: Add a tab to the pods editor for a CPT Pod called 'jedi
//add_filter( 'pods_admin_setup_edit_tabs_post_type_jedi', array( $this, 'jedi_tabs' ), 11, 3 );
//Example: Add fields to the Pods editor for all Advanced Content Types
//add_filter( 'pods_admin_setup_edit_options_advanced', array( $this, 'act_options' ), 11, 2 );
//Example: Add a submenu item to Pods Admin Menu
//add_filter( 'pods_admin_menu', array( $this, 'add_menu' ) );
/**
//Complete Example: Add a tab for all post types and some options inside of it.
//See example callbacks below
add_filter( 'pods_admin_setup_edit_tabs_post_type', array( $this, 'pt_tab' ), 11, 3 );
add_filter( 'pods_admin_setup_edit_options_post_type', array( $this, 'pt_options' ), 12, 2 );
*/
}
/**
* Initializes the Pods_Extend() class
*
* Checks for an existing Pods_Extend() instance
* and if it doesn't find one, creates it.
*
* @since 0.0.1
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new Pods_Extend();
}
return $instance;
}
/**
* Placeholder for activation function
*
* @since 0.0.1
*/
public function activate() {
}
/**
* Placeholder for deactivation function
*
* @since 0.0.1
*/
public function deactivate() {
}
/**
* Initialize plugin for localization
*
* @since 0.0.1
*/
public function localization_setup() {
load_plugin_textdomain( 'pods-extend', false, trailingslashit( PODS_EXTEND_URL ) . '/languages/' );
}
/**
* Enqueue front-end scripts
*
* Allows plugin assets to be loaded.
*
* @since 0.0.1
*/
public function enqueue_scripts() {
/**
* All styles goes here
*/
wp_enqueue_style( 'pods-extend-styles', trailingslashit( PODS_EXTEND_URL ) . 'css/front-end.css' );
/**
* All scripts goes here
*/
wp_enqueue_script( 'pods-extend-scripts', trailingslashit( PODS_EXTEND_URL ) . 'js/front-end.js', array( ), false, true );
/**
* Example for setting up text strings from Javascript files for localization
*
* Uncomment line below and replace with proper localization variables.
*/
// $translation_array = array( 'some_string' => __( 'Some string to translate', 'pods-extend' ), 'a_value' => '10' );
// wp_localize_script( 'pods-extend-scripts', 'podsExtend', $translation_array ) );
}
/**
* Enqueue admin scripts
*
* Allows plugin assets to be loaded.
*
* @since 0.0.1
*/
public function admin_enqueue_scripts() {
/**
* All admin styles goes here
*/
wp_enqueue_style( 'pods-extend-admin-styles', plugins_url( 'css/admin.css', __FILE__ ) );
/**
* All admin scripts goes here
*/
wp_enqueue_script( 'pods-extend-admin-scripts', plugins_url( 'js/admin.js', __FILE__ ), array( ), false, true );
}
/**
* Adds an admin tab to Pods editor for all post types
*
* @param array $tabs The admin tabs
* @param object $pod Current Pods Object
* @param $addtl_args
*
* @return array
*
* @since 0.0.1
*/
function pt_tab( $tabs, $pod, $addtl_args ) {
$tabs[ 'pods-extend' ] = __( 'Pods Extend Options', 'pods-extend' );
return $tabs;
}
/**
* Adds options to Pods editor for post types
*
* @param array $options All the options
* @param object $pod Current Pods object.
*
* @return array
*
* @since 0.0.1
*/
function pt_options( $options, $pod ) {
$options[ 'pods-extend' ] = array(
'example_boolean' => array(
'label' => __( 'Enable something?', 'pods-extend' ),
'help' => __( 'Helpful info about this option that will appear in its help bubble', 'pods-extend' ),
'type' => 'boolean',
'default' => true,
'boolean_yes_label' => 'Yes'
),
'example_text' => array(
'label' => __( 'Enter some text', 'pods-extend' ),
'help' => __( 'Helpful info about this option that will appear in its help bubble', 'pods-extend' ),
'type' => 'text',
'default' => 'Default text',
),
'dependency_example' => array(
'label' => __( 'Dependency Example', 'pods-extend' ),
'help' => __( 'When set to true, this field reveals the field "dependent_example".', 'pods' ),
'type' => 'boolean',
'default' => false,
'dependency' => true,
'boolean_yes_label' => ''
),
'dependent_example' => array(
'label' => __( 'Dependent Option', 'pods-extend' ),
'help' => __( 'This field is hidden unless the field "dependency_example" is set to true.', 'pods' ),
'type' => 'text',
'depends-on' => array( 'dependency_example' => true )
)
);
return $options;
}
/**
* Adds a sub menu page to the Pods admin
*
* @param array $admin_menus The submenu items in Pods Admin menu.
*
* @return mixed
*
* @since 0.0.1
*/
function add_menu( $admin_menus ) {
$admin_menus[ 'pods_extend'] = array(
'label' => __( 'Pods Extend', 'pods-extend' ),
'function' => array( $this, 'menu_page' ),
'access' => 'manage_options'
);
return $admin_menus;
}
/**
* This is the callback for the menu page. Be sure to create some actual functionality!
*
* @since 0.0.1
*/
function menu_page() {
echo '<h3>Pods Extend</h3>';
}
} // Pods_Extend
/**
* Initialize class, if Pods is active.
*
* @since 0.0.1
*/
add_action( 'plugins_loaded', 'pods_extend_safe_activate');
function pods_extend_safe_activate() {
if ( defined( 'PODS_VERSION' ) ) {
$GLOBALS[ 'Pods_Extend' ] = Pods_Extend::init();
}
}
/**
* Throw admin nag if Pods isn't activated.
*
* Will only show on the plugins page.
*
* @since 0.0.1
*/
add_action( 'admin_notices', 'pods_extend_admin_notice_pods_not_active' );
function pods_extend_admin_notice_pods_not_active() {
if ( ! defined( 'PODS_VERSION' ) ) {
//use the global pagenow so we can tell if we are on plugins admin page
global $pagenow;
if ( $pagenow == 'plugins.php' ) {
?>
<div class="updated">
<p><?php _e( 'You have activated Pods Extend, but not the core Pods plugin.', 'pods_extend' ); ?></p>
</div>
<?php
} //endif on the right page
} //endif Pods is not active
}
/**
* Throw admin nag if Pods minimum version is not met
*
* Will only show on the Pods admin page
*
* @since 0.0.1
*/
add_action( 'admin_notices', 'pods_extend_admin_notice_pods_min_version_fail' );
function pods_extend_admin_notice_pods_min_version_fail() {
if ( defined( 'PODS_VERSION' ) ) {
//set minimum supported version of Pods.
$minimum_version = '2.3.18';
//check if Pods version is greater than or equal to minimum supported version for this plugin
if ( version_compare( $minimum_version, PODS_VERSION ) >= 0) {
//create $page variable to check if we are on pods admin page
$page = pods_v('page','get', false, true );
//check if we are on Pods Admin page
if ( $page === 'pods' ) {
?>
<div class="updated">
<p><?php _e( 'Pods Extend, requires Pods version '.$minimum_version.' or later. Current version of Pods is '.PODS_VERSION, 'pods_extend' ); ?></p>
</div>
<?php
} //endif on the right page
} //endif version compare
} //endif Pods is not active
}