PluginProbe ʕ •ᴥ•ʔ
Panda Pods Repeater Field / 1.5.9
Panda Pods Repeater Field v1.5.9
1.5.14 trunk 1.0 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.4.10 1.4.11 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9
panda-pods-repeater-field / class-panda-pods-repeater-field.php
panda-pods-repeater-field Last commit date
classes 3 years ago css 4 years ago fields 3 years ago images 9 years ago js 3 years ago languages 7 years ago README.txt 3 years ago class-panda-pods-repeater-field.php 3 years ago panda-pods-repeater-field.php 3 years ago
class-panda-pods-repeater-field.php
435 lines
1 <?php
2 /**
3 * The main class file
4 *
5 * @package Panda Pods Repeater Field.
6 * @author Dongjie Xu
7 */
8
9 /**
10 * The class that holds the entire Panda_Pods_Repeater_Field plugin
11 *
12 * @package Panda Pods Repeater Field.
13 */
14 class Panda_Pods_Repeater_Field {
15 /**
16 * The allowed html tags for html outputs
17 *
18 * @var array
19 * @since 1.5.6
20 */
21 public $allowed_html_tags = array(
22 'strong' => array(),
23 'span' => array(
24 'class' => true,
25 'title' => true,
26 ),
27 'div' => array(
28 'class' => true,
29 'title' => true,
30 'id' => true,
31 'data-*' => true,
32 'style' => true,
33 ),
34 'iframe' => array(
35 'src' => true,
36 'height' => true,
37 'width' => true,
38 'frameborder' => true,
39 'allowfullscreen' => true,
40 'name' => true,
41 'id' => true,
42 'style' => true,
43 'class' => true,
44 ),
45 'img' => array(
46 'class' => true,
47 'title' => true,
48 'id' => true,
49 'src' => true,
50 'alt' => true,
51 'style' => true,
52 ),
53 'label' => array(
54 'class' => true,
55 'id' => true,
56 'style' => true,
57 ),
58 'select' => array(
59 'class' => true,
60 'id' => true,
61 'style' => true,
62 'name' => true,
63 'disabled' => true,
64 ),
65 'option' => array(
66 'class' => true,
67 'value' => true,
68 'style' => true,
69 'selected' => true,
70 'disabled' => true,
71 ),
72 'button' => array(
73 'class' => true,
74 'id' => true,
75 'style' => true,
76 'name' => true,
77 'disabled' => true,
78 'data-*' => true,
79 ),
80 );
81 /**
82 * Title to use in the menu.
83 *
84 * @var string $menu_title
85 */
86 public $menu_title = 'Panda Pods Repeater Field';
87 /**
88 * The name of the field.
89 *
90 * @var string TYPE_NAME
91 */
92 const TYPE_NAME = 'pandarepeaterfield';
93 /**
94 * Constructor for the Panda_Pods_Repeater_Field class
95 *
96 * Sets up all the appropriate hooks and actions
97 * within the plugin.
98 *
99 * @since 1.0.0
100 */
101 public function __construct() {
102 // Return false if Pods Framework is not available.
103 if ( ! class_exists( 'PodsField' ) ) {
104 return false;
105 }
106 $files = array(
107 'class-panda-pods-repeater-field-db',
108 'class-podsfield-pandarepeaterfield',
109 'class-panda-pods-repeater-field-ajax',
110 );
111
112 $active_plugins = get_option( 'active_plugins' );
113 $has_classes = true;
114 $files_count = count( $files );
115
116 for ( $i = 0; $i < $files_count; $i ++ ) {
117 $file = dirname( __FILE__ ) . '/classes/' . $files[ $i ] . '.php';
118
119 if ( file_exists( $file ) ) {
120 $class_name = str_replace( '-', '_', $files[ $i ] );
121 $class_name = substr( $class_name, 6 );
122
123 include_once $file;
124
125 if ( ! class_exists( $class_name ) ) {
126
127 $has_classes = false;
128 }
129 } else {
130 $has_classes = false;
131 }
132 }
133
134 if ( true === $has_classes ) {
135 // Create an instance to store pods adavance custom tables.
136 $panda_repeater_field = new podsfield_pandarepeaterfield();
137 // Ajax.
138 $repeater_field_ajax = new Panda_Pods_Repeater_Field_Ajax();
139
140 foreach ( PodsField_Pandarepeaterfield::$act_tables as $pod_table_id => $pod_table_name ) {
141 // After pod saved.
142 add_action( 'pods_api_post_save_pod_item_' . $pod_table_name, array( $panda_repeater_field, 'pods_post_save' ), 10, 3 );
143 add_action( 'pods_api_post_delete_pod_item_' . $pod_table_name, array( $panda_repeater_field, 'pods_post_delete' ), 10, 3 );
144 }
145 add_action( 'pods_admin_ui_setup_edit_fields', array( $panda_repeater_field, 'field_table_fields' ), 10, 2 );
146
147 }
148
149 /**
150 * Plugin Setup
151 */
152 register_activation_hook( __FILE__, array( $this, 'activate' ) );
153 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
154
155 /**
156 * Scripts/ Styles
157 */
158 // Loads admin scripts and styles.
159 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
160
161 // Example: Add a submenu item to Pods Admin Menu.
162 add_filter( 'pods_admin_menu', array( $this, 'add_menu' ) );
163
164 }
165
166 /**
167 * Initializes the Panda_Pods_Repeater_Field() class
168 *
169 * Checks for an existing Panda_Pods_Repeater_Field() instance
170 * and if it doesn't find one, creates it.
171 *
172 * @since 1.0.0
173 */
174 public static function init() {
175 static $prf_cla = false;
176
177 if ( ! $prf_cla ) {
178 $prf_cla = new Panda_Pods_Repeater_Field();
179 }
180
181 return $prf_cla;
182
183 }
184
185 /**
186 * Placeholder for activation function
187 *
188 * @since 1.0.0
189 */
190 public function activate() {
191
192 }
193
194 /**
195 * Placeholder for deactivation function
196 *
197 * @since 1.0.0
198 */
199 public function deactivate() {
200
201 }
202
203 /**
204 * Initialize plugin for localization
205 *
206 * @since 1.0.0
207 */
208 public function localization_setup() {
209
210 }
211
212
213
214 /**
215 * Enqueue admin scripts
216 *
217 * Allows plugin assets to be loaded.
218 *
219 * @since 1.0.0
220 */
221 public function admin_enqueue_scripts() {
222 global $pprf_l10n, $wp_version;
223 /**
224 * All admin styles goes here.
225 */
226 wp_register_style( 'panda-pods-repeater-general-styles', plugins_url( 'css/general.min.css', __FILE__ ), array(), '1.0.0' );
227 wp_enqueue_style( 'panda-pods-repeater-general-styles' );
228 wp_register_style( 'panda-pods-repeater-admin-styles', plugins_url( 'css/admin.min.css', __FILE__ ), array( 'panda-pods-repeater-general-styles' ), '1.0.0' );
229 wp_enqueue_style( 'panda-pods-repeater-admin-styles' );
230
231 /**
232 * All admin scripts goes here
233 */
234 if ( isset( $_SERVER['REQUEST_URI'] ) && isset( $_GET ) && isset( $_GET['page'] ) && isset( $_GET['pprf_nonce'] ) ) {
235 $request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );
236 $page = sanitize_title( wp_unslash( $_GET['page'] ) );
237 $pprf_nonce = sanitize_text_field( wp_unslash( $_GET['pprf_nonce'] ) );
238 if ( wp_verify_nonce( $pprf_nonce, 'load-pprf-page' ) ) {
239 if ( false !== strpos( $request_uri, 'wp-admin' ) && 'panda-pods-repeater-field' === $page ) {
240 wp_register_style( 'pprf_fields', plugins_url( 'fields/css/pprf.min.css', __FILE__ ), array( 'panda-pods-repeater-general-styles', 'panda-pods-repeater-admin-styles' ), '1.0.0' );
241 wp_enqueue_style( 'pprf_fields' );
242 }
243 }
244 }
245
246 if ( version_compare( $wp_version, '5.9', '=' ) ) {
247
248 wp_register_script( 'panda-pods-repeater-admin-scripts', plugins_url( 'js/admin.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'panda-pods-repeater-jquery-ui' ), '1.0.1', true );
249 } else {
250 wp_register_script( 'panda-pods-repeater-admin-scripts', plugins_url( 'js/admin.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable' ), '1.0.0', true );
251
252 }
253
254 wp_enqueue_script( 'panda-pods-repeater-admin-scripts' );
255 // prepare ajax.
256 wp_localize_script(
257 'panda-pods-repeater-admin-scripts',
258 'ajax_script',
259 array(
260 'ajaxurl' => admin_url( 'admin-ajax.php' ),
261 'nonce' => wp_create_nonce( 'panda-pods-repeater-field-nonce' ),
262 )
263 );
264
265 wp_localize_script(
266 'panda-pods-repeater-admin-scripts',
267 'strs_obj',
268 $pprf_l10n
269 );
270 $admin_url = substr( admin_url(), 0, strrpos( admin_url(), '/wp-admin/' ) + 10 );
271 wp_localize_script(
272 'panda-pods-repeater-admin-scripts',
273 'PANDA_PODS_REPEATER_PAGE_URL',
274 array( $admin_url . '?page=panda-pods-repeater-field&' )
275 );
276 wp_localize_script(
277 'panda-pods-repeater-admin-scripts',
278 'PANDA_PODS_REPEATER_CONSTANTS',
279 array(
280 'url' => PANDA_PODS_REPEATER_URL,
281 'nonce' => PANDA_PODS_REPEATER_NONCE,
282 )
283 );
284
285 }
286
287 /**
288 * Adds an admin tab to Pods editor for all post types.
289 *
290 * @param array $tabs The admin tabs.
291 * @param object $pod Current Pods Object.
292 * @param array $additional_args additional arguments.
293 *
294 * @return array
295 *
296 * @since 1.0.0
297 */
298 public function pt_tab( $tabs, $pod, $additional_args ) {
299 $tabs['panda-pods-repeater'] = __( 'Panda Repeater Options', 'panda-pods-repeater-field' );
300
301 return $tabs;
302
303 }
304
305 /**
306 * Adds options to Pods editor for post types.
307 *
308 * @param array $options All the options.
309 * @param object $pod Current Pods object.
310 *
311 * @return array
312 *
313 * @since 1.0.0
314 */
315 public function pt_options( $options, $pod ) {
316
317 $options['panda-pods-repeater'] = array(
318 'example_boolean' => array(
319 'label' => __( 'Enable something?', 'panda-pods-repeater-field' ),
320 'help' => __( 'Helpful info about this option that will appear in its help bubble', 'panda-pods-repeater-field' ),
321 'type' => 'boolean',
322 'default' => true,
323 'boolean_yes_label' => 'Yes',
324 ),
325 'example_text' => array(
326 'label' => __( 'Enter some text', 'panda-pods-repeater-field' ),
327 'help' => __( 'Helpful info about this option that will appear in its help bubble', 'panda-pods-repeater-field' ),
328 'type' => 'text',
329 'default' => 'Default text',
330 ),
331 'dependency_example' => array(
332 'label' => __( 'Dependency Example', 'panda-pods-repeater-field' ),
333 'help' => __( 'When set to true, this field reveals the field "dependent_example".', 'pods' ),
334 'type' => 'boolean',
335 'default' => false,
336 'dependency' => true,
337 'boolean_yes_label' => '',
338 ),
339 'dependent_example' => array(
340 'label' => __( 'Dependent Option', 'panda-pods-repeater-field' ),
341 'help' => __( 'This field is hidden unless the field "dependency_example" is set to true.', 'pods' ),
342 'type' => 'text',
343 'depends-on' => array( 'dependency_example' => true ),
344 ),
345
346 );
347
348 return $options;
349
350 }
351
352 /**
353 * Adds a sub menu page to the Pods admin
354 *
355 * @param array $admin_menus The submenu items in Pods Admin menu.
356 *
357 * @return mixed
358 *
359 * @since 1.0.0
360 */
361 public function add_menu( $admin_menus ) {
362 $admin_menus['panda_repeater'] = array(
363 'label' => __( 'Panda Repeater', 'panda-pods-repeater-field' ),
364 'function' => array( $this, 'menu_page' ),
365 'access' => 'manage_options',
366
367 );
368
369 return $admin_menus;
370
371 }
372
373 /**
374 * This is the callback for the menu page. Be sure to create some actual functionality!
375 *
376 * @since 1.0.0
377 */
378 public function menu_page() {
379 echo '<h3>' . esc_html__( 'Panda Repeater Field', 'panda-pods-repeater-field' ) . '</h3>';
380
381 }
382 /**
383 * Not needed, now use pods_register_field_type
384 *
385 * @param array $field_types field types.
386 *
387 * @return array $field_types an array of the field types
388 *
389 * @deprecated
390 */
391 public function filter_pods_api_field_types( $field_types ) {
392
393 if ( ! in_array( 'pandarepeaterfield', $field_types, true ) ) {
394 array_push( $field_types, 'pandarepeaterfield' );
395 }
396 return $field_types;
397 }
398 /**
399 * Not needed, now use pods_register_field_type
400 *
401 * @param string $pods_dir the path to the pod field.
402 * @param string $field_type the type of the pod field.
403 *
404 * @return string $pods_dir the path to the pod field.
405 *
406 * @deprecated
407 */
408 public function filter_pods_form_field_include( $pods_dir, $field_type ) {
409
410 if ( 'pandarepeaterfield' === $field_type ) {
411 $pods_dir = dirname( __FILE__ ) . '/classes/class-podsfield-pandarepeaterfield.php';
412 }
413
414 return $pods_dir;
415 }
416 /**
417 * To filter the field output
418 *
419 * @param string $output the output of the field.
420 * @param string $name the name of the field.
421 * @param string $value the value of the field.
422 * @param string $options the options of the field.
423 * @param string $pod the pod of the field.
424 * @param string $id the id of the field.
425 *
426 * @return string $output the output of the field.
427 *
428 * @deprecated
429 */
430 public function filter_pods_form_ui_field_panda_repeater( $output, $name, $value, $options, $pod, $id ) {
431 return $output;
432 }
433
434 }
435