PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.1.1
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.1.1
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / includes / folders.class.php
folders / includes Last commit date
folders.class.php 7 years ago form.class.php 7 years ago plugin.updates.php 7 years ago tree.class.php 7 years ago
folders.class.php
1804 lines
1 <?php
2
3 defined('ABSPATH') or die('Nope, not accessing this');
4
5 class WCP_Folders
6 {
7
8 private static $instance;
9
10 public $license_key_data = null;
11
12 private static $folders;
13
14 public $total_folders = 0;
15
16 public function __construct()
17 {
18 spl_autoload_register(array($this, 'autoload'));
19 add_action('init', array($this, 'create_folder_terms'), 15);
20 add_action('admin_init', array($this, 'folders_register_settings'));
21 add_action('admin_menu', array($this, 'admin_menu'), 10000);
22 add_action('admin_enqueue_scripts', array($this, 'folders_admin_styles'));
23 add_action('admin_enqueue_scripts', array($this, 'folders_admin_scripts'));
24 add_filter('plugin_action_links_' . WCP_FOLDERS_PLUGIN_BASE, [$this, 'plugin_action_links']);
25 add_action('admin_footer', array($this, 'admin_footer'));
26 add_action('parse_tax_query', array($this, 'taxonomy_archive_exclude_children'));
27
28 /* Save Data */
29 add_action('wp_ajax_wcp_add_new_folder', array($this, 'wcp_add_new_folder'));
30
31 /* Update Data */
32 add_action('wp_ajax_wcp_update_folder', array($this, 'wcp_update_folder'));
33
34 /* Remove Data */
35 add_action('wp_ajax_wcp_remove_folder', array($this, 'wcp_remove_folder'));
36
37 /* Save State Data */
38 add_action('wp_ajax_save_wcp_folder_state', array($this, 'save_wcp_folder_state'));
39
40 /* Save State Data */
41 add_action('wp_ajax_wcp_save_parent_data', array($this, 'wcp_save_parent_data'));
42
43 /* Update Parent Data */
44 add_action('wp_ajax_wcp_update_parent_information', array($this, 'wcp_update_parent_information'));
45
46 /* Update Parent Data */
47 add_action('wp_ajax_wcp_save_folder_order', array($this, 'wcp_save_folder_order'));
48
49 /* Update Parent Data */
50 add_action('wp_ajax_wcp_mark_un_mark_folder', array($this, 'wcp_mark_un_mark_folder'));
51
52 /* Update Parent Data */
53 add_action('wp_ajax_wcp_change_post_folder', array($this, 'wcp_change_post_folder'));
54
55 /* Update Parent Data */
56 add_action('wp_ajax_wcp_change_multiple_post_folder', array($this, 'wcp_change_multiple_post_folder'));
57
58 /* Update width Data */
59 add_action('wp_ajax_wcp_change_post_width', array($this, 'wcp_change_post_width'));
60
61 /* Update width Data */
62 add_action('wp_ajax_wcp_change_all_status', array($this, 'wcp_change_all_status'));
63
64 self::$folders = 10;
65
66 /* Send message on plugin deactivate */
67 add_action( 'wp_ajax_folder_plugin_deactivate', array( $this, 'folder_plugin_deactivate' ) );
68
69 /* Send message on owner */
70 add_action( 'wp_ajax_wcp_folder_send_message_to_owner', array( $this, 'wcp_folder_send_message_to_owner' ) );
71
72 /* Get default list */
73 add_action( 'wp_ajax_wcp_get_default_list', array( $this, 'wcp_get_default_list' ) );
74
75 /* Auto select folder for new page, post */
76 add_action('new_to_auto-draft', array($this, 'new_to_auto_draft'), 10);
77
78 /* for media */
79 add_action('restrict_manage_posts', array($this, 'output_list_table_filters'), 10, 2);
80 add_filter('pre_get_posts', array($this, 'filter_attachments_list'));
81 add_action('wp_enqueue_media', array($this, 'output_backbone_view_filters'));
82 add_filter('ajax_query_attachments_args', array($this, 'filter_attachments_grid'));
83 add_filter('add_attachment', array($this, 'save_media_terms'));
84 }
85
86 public function wcp_get_default_list() {
87 $post_type = 'attachment';
88
89 $total_posts = wp_count_posts($post_type)->inherit;;
90
91 $post_type = self::get_custom_post_type($post_type);
92 $terms_data = WCP_Tree::get_full_tree_data($post_type);
93 $taxonomies = self::get_terms_hierarchical('media_folder');
94
95 $response = array(
96 'status' => 1,
97 'data' => $terms_data,
98 'total_items' => $total_posts,
99 'taxonomies' => $taxonomies
100 );
101 echo json_encode($response);
102 die;
103 }
104
105 function save_media_terms( $post_id ) {
106 if ( wp_is_post_revision( $post_id ) ) {
107 return;
108 }
109 $post = get_post($post_id);
110 if($post->post_type !== 'attachment') {
111 return;
112 }
113 $post_type = self::get_custom_post_type('attachment');
114 $selected_folder = get_option("selected_{$post_type}_folder");
115 if($selected_folder != null && !empty($selected_folder)) {
116 $terms = get_term($selected_folder);
117 if(!empty($terms) && isset($terms->term_id)) {
118 wp_set_post_terms($post_id, $terms->term_id, $post_type, false);
119 }
120 }
121 }
122
123 public function filter_attachments_grid( $args ) {
124 $taxonomy = 'media_folder';
125 if ( ! isset( $args[ $taxonomy ] ) ) {
126 return $args;
127 }
128 $term = sanitize_text_field( $args[ $taxonomy ] );
129 if ( $term != "-1" ) {
130 return $args;
131 }
132 unset( $args[ $taxonomy ] );
133 $args['tax_query'] = array(
134 array(
135 'taxonomy' => $taxonomy,
136 'operator' => 'NOT EXISTS',
137 ),
138 );
139 $args = apply_filters( 'media_library_organizer_media_filter_attachments_grid', $args );
140 return $args;
141 }
142
143 public function output_backbone_view_filters() {
144 wp_enqueue_script( 'folders-media', WCP_FOLDER_URL.'assets/js/media.js', array( 'media-editor', 'media-views' ), false, true );
145 wp_localize_script( 'folders-media', 'folders_media_options', array(
146 'terms' => self::get_terms_hierarchical('media_folder'),
147 'taxonomy' => get_taxonomy('media_folder')
148 ));
149 wp_enqueue_style( 'folders-media', WCP_FOLDER_URL . 'assets/css/media.css' );
150 }
151
152 public function get_terms_hierarchical( $taxonomy ) {
153 $terms = get_terms( array(
154 'taxonomy' => $taxonomy,
155 'hide_empty' => false,
156 'parent' => 0,
157 ) );
158
159 if ( empty( $terms ) ) {
160 return false;
161 }
162
163 $hierarchy = _get_term_hierarchy( $taxonomy );
164
165 $hierarchical_terms = array();
166 foreach ( $terms as $term ) {
167 $hierarchical_terms[] = $term;
168 $hierarchical_terms = self::add_child_terms_recursive( $taxonomy, $hierarchical_terms, $hierarchy, $term->term_id, 1 );
169 }
170
171 return $hierarchical_terms;
172 }
173
174 private function add_child_terms_recursive( $taxonomy, $hierarchical_terms, $hierarchy, $current_term_id, $current_depth ) {
175
176 if ( ! isset( $hierarchy[ $current_term_id ] ) ) {
177 return $hierarchical_terms;
178 }
179
180 foreach ( $hierarchy[ $current_term_id ] as $child_term_id ) {
181
182 $child_term = get_term( $child_term_id, $taxonomy );
183
184 $child_term->name = str_pad( '', $current_depth, '-', STR_PAD_LEFT ) . ' ' . $child_term->name;
185
186 $hierarchical_terms[] = $child_term;
187
188 $hierarchical_terms = self::add_child_terms_recursive( $taxonomy, $hierarchical_terms, $hierarchy, $child_term_id, ( $current_depth + 1 ) );
189 }
190
191 return $hierarchical_terms;
192 }
193
194 public function filter_attachments_list( $query ) {
195
196 if ( ! isset( $query->query['post_type'] ) ) {
197 return $query;
198 }
199
200 if ( is_array( $query->query['post_type'] ) && ! in_array( 'attachment', $query->query['post_type'] ) ) {
201 return $query;
202 }
203 if ( ! is_array( $query->query['post_type'] ) && strpos( $query->query['post_type'], 'attachment' ) === false ) {
204 return $query;
205 }
206
207 if ( ! isset( $_REQUEST['media_folder'] ) ) {
208 return $query;
209 }
210
211 $term = sanitize_text_field( $_REQUEST['media_folder'] );
212 if ( $term != "-1" ) {
213 return $query;
214 }
215
216 unset( $query->query_vars['media_folder'] );
217
218 $tax_query = array(
219 'taxonomy' => 'media_folder',
220 'operator' => 'NOT EXISTS',
221 );
222
223 $query->set( 'tax_query', array( $tax_query ) );
224 $query->tax_query = new WP_Tax_Query( array( $tax_query ) );
225
226 $query = apply_filters( 'media_library_organizer_media_filter_attachments', $query, $_REQUEST );
227
228 return $query;
229
230 }
231
232 public function output_list_table_filters( $post_type, $view_name )
233 {
234 if ($post_type != 'attachment') {
235 return;
236 }
237
238 if ($view_name != 'bar') {
239 return;
240 }
241
242 $current_term = false;
243 if ( isset( $_REQUEST['media_folder'] ) ) {
244 $current_term = sanitize_text_field($_REQUEST['media_folder']);
245 }
246
247 wp_dropdown_categories( array(
248 'show_option_all' => __( 'All Folders', WCP_FOLDER ),
249 'show_option_none' => __( '(Unassigned)', WCP_FOLDER ),
250 'option_none_value' => -1,
251 'orderby' => 'name',
252 'order' => 'ASC',
253 'show_count' => true,
254 'hide_empty' => false,
255 'echo' => true,
256 'selected' => $current_term,
257 'hierarchical' => true,
258 'name' => 'media_folder',
259 'id' => '',
260 'class' => '',
261 'taxonomy' => 'media_folder',
262 'value_field' => 'slug',
263 ) );
264
265 }
266
267
268 function new_to_auto_draft($post) {
269
270 $post_type = $post->post_type;
271
272 if(self::is_for_this_post_type($post_type)) {
273
274 $post_type = self::get_custom_post_type($post_type);
275 $selected_folder = get_option("selected_{$post_type}_folder");
276
277 if($selected_folder != null && !empty($selected_folder)) {
278 $terms = get_term($selected_folder);
279 if(!empty($terms) && isset($terms->slug)) {
280 wp_set_object_terms($post->ID, $terms->slug, $post_type );
281 }
282
283 }
284 }
285 }
286
287 public function wcp_folder_send_message_to_owner() {
288 $response = array();
289 $response['status'] = 0;
290 $response['error'] = 0;
291 $response['errors'] = array();
292 $response['message'] = "";
293 $errorArray = [];
294 $errorMessage = __("%s is required", WCP_FOLDER);
295 $postData = $_POST;
296 if(!isset($postData['textarea_text']) || trim($postData['textarea_text']) == "") {
297 $error = array(
298 "key" => "textarea_text",
299 "message" => __("Please enter your message",WCP_FOLDER)
300 );
301 $errorArray[] = $error;
302 }
303 if(!isset($postData['user_email']) || trim($postData['user_email']) == "") {
304 $error = array(
305 "key" => "user_email",
306 "message" => sprintf($errorMessage,__("Email",WCP_FOLDER))
307 );
308 $errorArray[] = $error;
309 } else if(!filter_var($postData['user_email'], FILTER_VALIDATE_EMAIL)) {
310 $error = array(
311 'key' => "user_email",
312 "message" => "Email is not valid"
313 );
314 $errorArray[] = $error;
315 }
316 if(empty($errorArray)) {
317 if(!isset($postData['folder_help_nonce']) || trim($postData['folder_help_nonce']) == "") {
318 $error = array(
319 "key" => "nonce",
320 "message" => __("Your request is not valid", WCP_FOLDER)
321 );
322 $errorArray[] = $error;
323 } else {
324 if(!wp_verify_nonce($postData['folder_help_nonce'], 'wcp_folder_help_nonce')) {
325 $error = array(
326 "key" => "nonce",
327 "message" => __("Your request is not valid", WCP_FOLDER)
328 );
329 $errorArray[] = $error;
330 }
331 }
332 }
333 if(empty($errorArray)) {
334 global $current_user;
335 $text_message = self::sanitize_options($postData['textarea_text']);
336 $email = self::sanitize_options($postData['user_email'],"email");
337 $domain = site_url();
338 $user_name = $current_user->first_name." ".$current_user->last_name;
339 $subject = "Folder request: ".$domain;
340 $headers = "MIME-Version: 1.0\r\n";
341 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
342 $headers .= 'From: '.$user_name.' <'.$email.'>'.PHP_EOL ;
343 $headers .= 'Reply-To: '.$user_name.' <'.$email.'>'.PHP_EOL ;
344 $headers .= 'X-Mailer: PHP/' . phpversion();
345 ob_start();
346 ?>
347 <table border="0" cellspacing="0" cellpadding="5">
348 <tr>
349 <th>Domain</th>
350 <td><?php echo $domain ?></td>
351 </tr>
352 <tr>
353 <th>Email</th>
354 <td><?php echo $email ?></td>
355 </tr>
356 <tr>
357 <th>Message</th>
358 <td><?php echo nl2br($text_message) ?></td>
359 </tr>
360 </table>
361 <?php
362 $message = ob_get_clean();
363 $to = "contact+fromwp@premio.io";
364 $status = wp_mail($to, $subject, $message, $headers);
365 if($status) {
366 $response['status'] = 1;
367 } else {
368 $response['status'] = 0;
369 $response['message'] = "Not able to send mail";
370 }
371 } else {
372 $response['error'] = 1;
373 $response['errors'] = $errorArray;
374 }
375 echo json_encode($response);
376 }
377
378 public function folder_plugin_deactivate() {
379 global $current_user;
380 $postData = $_POST;
381 $errorCounter = 0;
382 $response = array();
383 $response['status'] = 0;
384 $response['message'] = "";
385 $response['valid'] = 1;
386 if(!isset($postData['reason']) || empty($postData['reason'])) {
387 $errorCounter++;
388 $response['message'] = "Please provide reason";
389 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
390 $response['message'] = __("Your request is not valid", WCP_FOLDER);
391 $errorCounter++;
392 $response['valid'] = 0;
393 } else {
394 $nonce = self::sanitize_options($postData['nonce']);
395 if(!wp_verify_nonce($nonce, 'wcp_folder_deactivate_nonce')) {
396 $response['message'] = __("Your request is not valid", WCP_FOLDER);
397 $errorCounter++;
398 $response['valid'] = 0;
399 }
400 }
401 if($errorCounter == 0) {
402 $reason = $postData['reason'];
403 $email = get_option( 'admin_email' );
404 $domain = site_url();
405 $user_name = $current_user->first_name." ".$current_user->last_name;
406 $subject = "Folders was removed from {$domain}";
407 $headers = "MIME-Version: 1.0\r\n";
408 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
409 $headers .= 'From: '.$user_name.' <'.$email.'>'.PHP_EOL ;
410 $headers .= 'Reply-To: '.$user_name.' <'.$email.'>'.PHP_EOL ;
411 $headers .= 'X-Mailer: PHP/' . phpversion();
412 ob_start();
413 ?>
414 <table border="0" cellspacing="0" cellpadding="5">
415 <tr>
416 <th>Plugin</th>
417 <td>Folders</td>
418 </tr>
419 <tr>
420 <th>Plugin Version</th>
421 <td><?php echo WCP_FOLDER_VERSION ?></td>
422 </tr>
423 <tr>
424 <th>Domain</th>
425 <td><?php echo $domain ?></td>
426 </tr>
427 <tr>
428 <th>Email</th>
429 <td><?php echo $email ?></td>
430 </tr>
431 <tr>
432 <th>Comment</th>
433 <td><?php echo nl2br($reason) ?></td>
434 </tr>
435 <tr>
436 <th>WordPress Version</th>
437 <td><?php echo get_bloginfo('version') ?></td>
438 </tr>
439 <tr>
440 <th>PHP Version</th>
441 <td><?php echo PHP_VERSION ?></td>
442 </tr>
443 </table>
444 <?php
445 $content = ob_get_clean();
446 $to = "contact+removed@premio.io";
447 wp_mail($to, $subject, $content, $headers);
448 $response['status'] = 1;
449 }
450 echo json_encode($response);
451 die;
452 }
453
454 public function check_has_valid_key()
455 {
456 return 0;
457 }
458
459 public static function total_term_folders()
460 {
461 $post_types = get_option(WCP_FOLDER_VAR);
462 $post_types = is_array($post_types)?$post_types:array();
463 $total = 0;
464 foreach ($post_types as $post_type) {
465 $post_type = self::get_custom_post_type($post_type);
466 $total += wp_count_terms($post_type);
467 }
468 return $total;
469 }
470
471 public function get_license_key_information($licenseKey)
472 {
473 return array();
474 }
475
476 public function get_license_key_data($licenseKey = '')
477 {
478 return array();
479 }
480
481 public function check_for_license_key()
482 {
483 return false;
484 }
485
486 public function wcp_remove_post_item()
487 {
488 $response = array();
489 $response['status'] = 0;
490 $response['error'] = 0;
491 $response['data'] = array();
492 $response['message'] = "";
493 $postData = $_POST;
494 if (isset($postData['post_id']) && !empty($postData['post_id'])) {
495 wp_delete_post($postData['post_id']);
496 $response['status'] = 1;
497 }
498 echo json_encode($response);
499 die;
500 }
501
502 public function wcp_change_all_status()
503 {
504 $response = array();
505 $response['status'] = 0;
506 $response['error'] = 0;
507 $response['data'] = array();
508 $response['message'] = "";
509 $postData = $_POST;
510 $errorCounter = 0;
511 if (!isset($postData['type']) || empty($postData['type'])) {
512 $response['message'] = __("Your request is not valid", WCP_FOLDER);
513 $errorCounter++;
514 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
515 $response['message'] = __("Your request is not valid", WCP_FOLDER);
516 $errorCounter++;
517 } else if (!current_user_can("manage_categories") || ($postData['type'] == "page" && !current_user_can("edit_pages"))) {
518 $response['message'] = __("You have not permission to update width", WCP_FOLDER);
519 $errorCounter++;
520 } else if (!current_user_can("manage_categories") || ($postData['type'] != "page" && !current_user_can("edit_posts"))) {
521 $response['message'] = __("You have not permission to update width", WCP_FOLDER);
522 $errorCounter++;
523 } else {
524 $type = self::sanitize_options($postData['type']);
525 $nonce = self::sanitize_options($postData['nonce']);
526 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
527 $response['message'] = __("Your request is not valid", WCP_FOLDER);
528 $errorCounter++;
529 }
530 }
531 if ($errorCounter == 0) {
532 if (isset($postData['folders']) || !empty($postData['folders'])) {
533 $status = isset($postData['status']) ? $postData['status'] : 0;
534 $status = self::sanitize_options($status);
535 $folders = self::sanitize_options($postData['folders']);
536 $folders = trim($folders, ",");
537 $folders = explode(",", $folders);
538 foreach ($folders as $folder) {
539 update_term_meta($folder, "is_active", $status);
540 }
541 }
542 $response['status'] = 1;
543 }
544 echo json_encode($response);
545 die;
546 }
547
548 public function wcp_change_post_width()
549 {
550 $response = array();
551 $response['status'] = 0;
552 $response['error'] = 0;
553 $response['data'] = array();
554 $response['message'] = "";
555 $postData = $_POST;
556 $errorCounter = 0;
557 if (!isset($postData['width']) || empty($postData['width'])) {
558 $response['message'] = __("Your request is not valid", WCP_FOLDER);
559 $errorCounter++;
560 } else if (!isset($postData['type']) || empty($postData['type'])) {
561 $response['message'] = __("Your request is not valid", WCP_FOLDER);
562 $errorCounter++;
563 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
564 $response['message'] = __("Your request is not valid", WCP_FOLDER);
565 $errorCounter++;
566 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
567 $response['message'] = __("You have not permission to update width", WCP_FOLDER);
568 $errorCounter++;
569 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
570 $response['message'] = __("You have not permission to update width", WCP_FOLDER);
571 $errorCounter++;
572 } else {
573 $type = self::sanitize_options($postData['type']);
574 $nonce = self::sanitize_options($postData['nonce']);
575 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
576 $response['message'] = __("Your request is not valid", WCP_FOLDER);
577 $errorCounter++;
578 }
579 }
580 if ($errorCounter == 0) {
581 $type = self::sanitize_options($postData['type']);
582 $width = self::sanitize_options($postData['width'], "int");
583 $optionName = "wcp_dynamic_width_for_" . $type;
584 update_option($optionName, $width);
585 $response['status'] = 1;
586 }
587 echo json_encode($response);
588 die;
589 }
590
591 public function wcp_change_multiple_post_folder()
592 {
593 $response = array();
594 $response['status'] = 0;
595 $response['error'] = 0;
596 $response['data'] = array();
597 $response['message'] = "";
598 $postData = $_POST;
599 $errorCounter = 0;
600 if (!isset($postData['post_ids']) || empty($postData['post_ids'])) {
601 $response['message'] = __("Your request is not valid", WCP_FOLDER);
602 $errorCounter++;
603 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
604 $response['message'] = __("Your request is not valid", WCP_FOLDER);
605 $errorCounter++;
606 } else if (!isset($postData['type']) || empty($postData['type'])) {
607 $response['message'] = __("Your request is not valid", WCP_FOLDER);
608 $errorCounter++;
609 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
610 $response['message'] = __("Your request is not valid", WCP_FOLDER);
611 $errorCounter++;
612 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
613 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
614 $errorCounter++;
615 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
616 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
617 $errorCounter++;
618 } else {
619 $folder_id = self::sanitize_options($postData['folder_id']);
620 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$folder_id)) {
621 $response['message'] = __("Your request is not valid", WCP_FOLDER);
622 $errorCounter++;
623 }
624 }
625 if ($errorCounter == 0) {
626 $postID = self::sanitize_options($postData['post_ids']);
627 $postID = trim($postID, ",");
628 $folderID = self::sanitize_options($postData['folder_id']);
629 $type = self::sanitize_options($postData['type']);
630 $postArray = explode(",", $postID);
631 if (is_array($postArray)) {
632 foreach ($postArray as $post) {
633 $post_type = self::get_custom_post_type($type);
634 wp_set_post_terms($post, $folderID, $post_type, false);
635 }
636 }
637 $response['status'] = 1;
638 }
639 echo json_encode($response);
640 die;
641 }
642
643 public function wcp_change_post_folder()
644 {
645 $response = array();
646 $response['status'] = 0;
647 $response['error'] = 0;
648 $response['data'] = array();
649 $response['message'] = "";
650 $postData = $_POST;
651 $errorCounter = 0;
652 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
653 $errorCounter++;
654 $response['message'] = __("Your request is not valid", WCP_FOLDER);
655 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
656 $errorCounter++;
657 $response['message'] = __("Your request is not valid", WCP_FOLDER);
658 } else if (!isset($postData['type']) || empty($postData['type'])) {
659 $errorCounter++;
660 $response['message'] = __("Your request is not valid", WCP_FOLDER);
661 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
662 $response['message'] = __("Your request is not valid", WCP_FOLDER);
663 $errorCounter++;
664 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
665 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
666 $errorCounter++;
667 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
668 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
669 $errorCounter++;
670 } else {
671 $term_id = self::sanitize_options($postData['folder_id']);
672 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
673 $response['message'] = __("Your request is not valid", WCP_FOLDER);
674 $errorCounter++;
675 }
676 }
677 if ($errorCounter == 0) {
678 $postID = self::sanitize_options($postData['post_id']);
679 $folderID = self::sanitize_options($postData['folder_id']);
680 $type = self::sanitize_options($postData['type']);
681 $folder_post_type = self::get_custom_post_type($type);
682 $terms = get_the_terms($postID, $folder_post_type);
683 if (!empty($terms)) {
684 foreach ($terms as $term) {
685 wp_remove_object_terms($postID, $term->term_id, $folder_post_type);
686 }
687 }
688 wp_set_post_terms($postID, $folderID, $folder_post_type);
689 $response['status'] = 1;
690 }
691 echo json_encode($response);
692 die;
693 }
694
695 public function wcp_mark_un_mark_folder()
696 {
697 $response = array();
698 $response['status'] = 0;
699 $response['error'] = 0;
700 $response['data'] = array();
701 $response['message'] = "";
702 $postData = $_POST;
703 $errorCounter = 0;
704 if (!current_user_can("manage_categories")) {
705 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
706 $errorCounter++;
707 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
708 $errorCounter++;
709 $response['message'] = __("Your request is not valid", WCP_FOLDER);
710 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
711 $response['message'] = __("Your request is not valid", WCP_FOLDER);
712 $errorCounter++;
713 } else {
714 $term_id = self::sanitize_options($postData['term_id']);
715 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_highlight_term_'.$term_id)) {
716 $response['message'] = __("Your request is not valid", WCP_FOLDER);
717 $errorCounter++;
718 }
719 }
720 if ($errorCounter == 0) {
721 $term_id = self::sanitize_options($postData['term_id']);
722 $status = get_term_meta($term_id, "is_highlighted", true);
723 if ($status == 1) {
724 update_term_meta($term_id, "is_highlighted", 0);
725 $status = 0;
726 } else {
727 update_term_meta($term_id, "is_highlighted", 1);
728 $status = 1;
729 }
730 $response['marked'] = $status;
731 $response['id'] = $postData['term_id'];
732 $response['status'] = 1;
733 }
734 echo json_encode($response);
735 die;
736 }
737
738 public function wcp_save_folder_order()
739 {
740 $response = array();
741 $response['status'] = 0;
742 $response['error'] = 0;
743 $response['data'] = array();
744 $response['message'] = "";
745 $postData = $_POST;
746 $errorCounter = 0;
747 if (!current_user_can("manage_categories")) {
748 $response['message'] = __("You have not permission to update folder order", WCP_FOLDER);
749 $errorCounter++;
750 } else if (!isset($postData['term_ids']) || empty($postData['term_ids'])) {
751 $errorCounter++;
752 $response['message'] = __("Your request is not valid", WCP_FOLDER);
753 } else if (!isset($postData['type']) || empty($postData['type'])) {
754 $errorCounter++;
755 $response['message'] = __("Your request is not valid", WCP_FOLDER);
756 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
757 $response['message'] = __("Your request is not valid", WCP_FOLDER);
758 $errorCounter++;
759 } else {
760 $type = self::sanitize_options($postData['type']);
761 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
762 $response['message'] = __("Your request is not valid", WCP_FOLDER);
763 $errorCounter++;
764 }
765 }
766 if ($errorCounter == 0) {
767 $termIds = self::sanitize_options(($postData['term_ids']));
768 $type = self::sanitize_options($postData['type']);
769 $termIds = trim($termIds, ",");
770 $termArray = explode(",", $termIds);
771 $order = 1;
772 foreach ($termArray as $term) {
773 if (!empty($term)) {
774 update_term_meta($term, "wcp_custom_order", $order);
775 $order++;
776 }
777 }
778 $response['status'] = 1;
779 $folder_type = self::get_custom_post_type($type);
780 $response['options'] = WCP_Tree::get_option_data_for_select($folder_type);
781
782 }
783 echo json_encode($response);
784 die;
785 }
786
787 public function save_wcp_folder_state()
788 {
789 $response = array();
790 $response['status'] = 0;
791 $response['error'] = 0;
792 $response['data'] = array();
793 $response['message'] = "";
794 $postData = $_POST;
795 $errorCounter = 0;
796 if (!current_user_can("manage_categories")) {
797 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
798 $errorCounter++;
799 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
800 $response['message'] = __("Your request is not valid", WCP_FOLDER);
801 $errorCounter++;
802 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
803 $response['message'] = "Unable to create folder, Your request is not valid";
804 $errorCounter++;
805 } else {
806 $term_id = self::sanitize_options($postData['term_id']);
807 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
808 $response['message'] = __("Your request is not valid", WCP_FOLDER);
809 $errorCounter++;
810 }
811 }
812 if ($errorCounter == 0) {
813 $response['status'] = 1;
814 $term_id = self::sanitize_options($postData['term_id']);
815 $is_active = isset($postData['is_active'])?$postData['is_active']:0;
816 $is_active = self::sanitize_options($is_active);
817 if ($is_active == 1) {
818 update_term_meta($term_id, "is_active", 1);
819 } else {
820 update_term_meta($term_id, "is_active", 0);
821 }
822 }
823 echo json_encode($response);
824 die;
825 }
826
827 public function wcp_update_parent_information()
828 {
829 $response = array();
830 $response['status'] = 0;
831 $response['error'] = 0;
832 $response['data'] = array();
833 $response['message'] = "";
834 $postData = $_POST;
835 $errorCounter = 0;
836 if (!current_user_can("manage_categories")) {
837 $response['message'] = __("You have not permission to update folder", WCP_FOLDER);
838 $errorCounter++;
839 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
840 $response['message'] = __("Your request is not valid", WCP_FOLDER);
841 $errorCounter++;
842 } else if (!isset($postData['type']) || empty($postData['type'])) {
843 $response['message'] = __("Your request is not valid", WCP_FOLDER);
844 $errorCounter++;
845 } else if (!isset($postData['parent_id'])) {
846 $response['message'] = __("Your request is not valid", WCP_FOLDER);
847 $errorCounter++;
848 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
849 $response['message'] = __("Your request is not valid", WCP_FOLDER);
850 $errorCounter++;
851 } else {
852 $term_id = self::sanitize_options($postData['term_id']);
853 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
854 $response['message'] = __("Your request is not valid", WCP_FOLDER);
855 $errorCounter++;
856 }
857 }
858 if($errorCounter == 0) {
859 $term_id = self::sanitize_options($postData['term_id']);
860 $parent_id = self::sanitize_options($postData['parent_id']);
861 $type = self::sanitize_options($postData['type']);
862 $folder_type = self::get_custom_post_type($type);
863 wp_update_term($term_id, $folder_type, array(
864 'parent' => $parent_id
865 ));
866 update_term_meta($parent_id, "is_active", 1);
867 $response['status'] = 1;
868 }
869 echo json_encode($response);
870 die;
871 }
872
873 public function wcp_save_parent_data()
874 {
875 $response = array();
876 $response['status'] = 0;
877 $response['error'] = 0;
878 $response['data'] = array();
879 $response['message'] = "";
880 $postData = $_POST;
881 $errorCounter = 0;
882 if (!isset($postData['type']) || empty($postData['type'])) {
883 $response['message'] = __("Your request is not valid", WCP_FOLDER);
884 $errorCounter++;
885 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
886 $response['message'] = __("Your request is not valid", WCP_FOLDER);
887 $errorCounter++;
888 } else {
889 $type = self::sanitize_options($postData['type']);
890 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
891 $response['message'] = __("Your request is not valid", WCP_FOLDER);
892 $errorCounter++;
893 }
894 }
895 if ($errorCounter == 0) {
896 $type = self::sanitize_options($postData['type']);
897 $optionName = $type . "_parent_status";
898 $response['status'] = 1;
899 $is_active = isset($postData['is_active'])?$postData['is_active']:0;
900 $is_active = self::sanitize_options($is_active);
901 if ($is_active == 1) {
902 update_option($optionName, 1);
903 } else {
904 update_option($optionName, 0);
905 }
906 }
907 echo json_encode($response);
908 die;
909 }
910
911 public function wcp_remove_folder()
912 {
913 $response = array();
914 $response['status'] = 0;
915 $response['error'] = 0;
916 $response['data'] = array();
917 $response['message'] = "";
918 $postData = $_POST;
919 $errorCounter = 0;
920 if (!current_user_can("manage_categories")) {
921 $error = __("You have not permission to remove folder", WCP_FOLDER);
922 $errorCounter++;
923 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
924 $error = __("Your request is not valid", WCP_FOLDER);
925 $errorCounter++;
926 } else if (!isset($postData['type']) || empty($postData['type'])) {
927 $error = __("Your request is not valid", WCP_FOLDER);
928 $errorCounter++;
929 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
930 $error = "Unable to delete folder, Your request is not valid";
931 $errorCounter++;
932 } else {
933 $term_id = self::sanitize_options($postData['term_id']);
934 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_delete_term_'.$term_id)) {
935 $error = "Unable to delete folder, Your request is not valid";
936 $errorCounter++;
937 }
938 }
939 if ($errorCounter == 0) {
940 $term_id = self::sanitize_options($postData['term_id']);
941 $type = self::sanitize_options($postData['type']);
942 self::remove_folder_child_items($term_id, $type);
943 $response['status'] = 1;
944 $is_active = 1;
945 $folders = -1;
946 if (!self::check_has_valid_key()) {
947 $is_active = 0;
948 $folders = self::total_term_folders();
949 }
950 $response['folders'] = $folders;
951 $response['is_key_active'] = $is_active;
952 } else {
953 $response['error'] = 1;
954 $response['message'] = $error;
955 }
956 echo json_encode($response);
957 die;
958 }
959
960 public function remove_folder_child_items($term_id, $post_type)
961 {
962 $folder_type = self::get_custom_post_type($post_type);
963 $terms = get_terms($folder_type, array(
964 'hide_empty' => false,
965 'parent' => $term_id
966 ));
967
968 if (!empty($terms)) {
969 foreach ($terms as $term) {
970 self::remove_folder_child_items($term->term_id, $post_type);
971 }
972 wp_delete_term($term_id, $folder_type);
973 } else {
974 wp_delete_term($term_id, $folder_type);
975 }
976 }
977
978 public function wcp_update_folder()
979 {
980 $response = array();
981 $response['status'] = 0;
982 $response['error'] = 0;
983 $response['data'] = array();
984 $response['message'] = "";
985 $postData = $_REQUEST;
986 $errorCounter = 0;
987 if (!current_user_can("manage_categories")) {
988 $error = __("You have not permission to update folder", WCP_FOLDER);
989 $errorCounter++;
990 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
991 $error = __("Unable to rename folder, Your request is not valid", WCP_FOLDER);
992 $errorCounter++;
993 } else if (!isset($postData['name']) || empty($postData['name'])) {
994 $error = __("Folder name can no be empty", WCP_FOLDER);
995 $errorCounter++;
996 } else if (!isset($postData['type']) || empty($postData['type'])) {
997 $error = __("Your request is not valid", WCP_FOLDER);
998 $errorCounter++;
999 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1000 $error = __("Unable to rename folder, Your request is not valid", WCP_FOLDER);
1001 $errorCounter++;
1002 } else {
1003 $term_id = self::sanitize_options($postData['term_id']);
1004 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_rename_term_'.$term_id)) {
1005 $error = _("Unable to rename folder, Your request is not valid", WCP_FOLDER);
1006 $errorCounter++;
1007 }
1008 }
1009 if ($errorCounter == 0) {
1010 $type = self::sanitize_options($postData['type']);
1011 $folder_type = self::get_custom_post_type($type);
1012 $name = self::sanitize_options($postData['name']);
1013 $term_id = self::sanitize_options($postData['term_id']);
1014 $result = wp_update_term(
1015 $term_id,
1016 $folder_type,
1017 array(
1018 'name' => $name,
1019 )
1020 );
1021 if (!empty($result)) {
1022 $response['id'] = $result['term_id'];
1023 $response['status'] = 1;
1024 $response['term_title'] = $postData['name'];
1025 } else {
1026 $response['message'] = __("Unable to rename folder", WCP_FOLDER);
1027 }
1028 } else {
1029 $response['error'] = 1;
1030 $response['message'] = $error;
1031 }
1032 echo json_encode($response);
1033 die;
1034 }
1035
1036 public function create_slug_from_string($str)
1037 {
1038 $a = array('À', 'Á', 'Â', 'Ã', 'Ä', '�
1039 ', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
1040 $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
1041 return strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), str_replace($a, $b, $str)));
1042 }
1043
1044 public static function sanitize_options($value, $type = "") {
1045 $value = stripslashes($value);
1046 if($type == "int") {
1047 $value = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
1048 } else if($type == "email") {
1049 $value = sanitize_email($value);
1050 } else {
1051 $value = sanitize_text_field($value);
1052 }
1053 return $value;
1054 }
1055
1056 public function wcp_add_new_folder()
1057 {
1058 $response = array();
1059 $response['status'] = 0;
1060 $response['error'] = 0;
1061 $response['login'] = 1;
1062 $response['data'] = array();
1063 $response['message'] = "";
1064 $postData = $_REQUEST;
1065 $errorCounter = 0;
1066 if (!current_user_can("manage_categories")) {
1067 $error = __("You have not permission to add folder", WCP_FOLDER);
1068 $errorCounter++;
1069 } else if (!isset($postData['name']) || empty($postData['name'])) {
1070 $error = __("Folder name can no be empty", WCP_FOLDER);
1071 $errorCounter++;
1072 } else if (!isset($postData['type']) || empty($postData['type'])) {
1073 $error = __("Your request is not valid", WCP_FOLDER);
1074 $errorCounter++;
1075 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1076 $response['login'] = 0;
1077 $error = __("Unable to create folder, Your request is not valid", WCP_FOLDER);
1078 $errorCounter++;
1079 } else {
1080 $type = self::sanitize_options($postData['type']);
1081 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
1082 $response['login'] = 0;
1083 $error = __("Unable to create folder, Your request is not valid", WCP_FOLDER);
1084 $errorCounter++;
1085 }
1086 }
1087 if ($errorCounter == 0) {
1088 $parent = isset($postData['parent_id']) && !empty($postData['parent_id']) ? $postData['parent_id'] : 0;
1089 $parent = self::sanitize_options($parent);
1090 $type = self::sanitize_options($postData['type']);
1091 $folder_type = self::get_custom_post_type($type);
1092 $term_name = self::sanitize_options($postData['name']);
1093 $term = term_exists($term_name, $folder_type, $parent);
1094 if (!(0 !== $term && null !== $term)) {
1095 $slug = self::create_slug_from_string($postData['name']) . "-" . time();
1096 $result = wp_insert_term(
1097 $postData['name'], // the term
1098 $folder_type, // the taxonomy
1099 array(
1100 'parent' => $parent,
1101 'slug' => $slug
1102 )
1103 );
1104 if (!empty($result)) {
1105 $response['id'] = $result['term_id'];
1106 $response['status'] = 1;
1107 $order = isset($postData['order']) ? $postData['order'] : 0;
1108 $order = self::sanitize_options($order);
1109 update_term_meta($result['term_id'], "wcp_custom_order", $order);
1110 if ($parent != 0) {
1111 update_term_meta($parent, "is_active", 1);
1112 }
1113 $delete_nonce = wp_create_nonce('wcp_folder_delete_term_'.$result['term_id']);
1114 $rename_nonce = wp_create_nonce('wcp_folder_rename_term_'.$result['term_id']);
1115 $highlight_nonce = wp_create_nonce('wcp_folder_highlight_term_'.$result['term_id']);
1116 $term_nonce = wp_create_nonce('wcp_folder_term_'.$result['term_id']);
1117 $string = "<li data-nonce='{$term_nonce}' data-star='{$highlight_nonce}' data-rename='{$rename_nonce}' data-delete='{$delete_nonce}' data-slug='{$result['term_id']}' class='ui-state-default route' id='wcp_folder_{$result['term_id']}' data-folder-id='{$result['term_id']}'><h3 class='title' id='title_{$result['term_id']}'><span class='title-text'>{$postData['name']}</span> <span class='update-inline-record'></span><span class='star-icon'></span> </h3><span class='nav-icon'><i class='wcp-icon folder-icon-arrow_right'></i></span><span class='ui-icon'><i class='wcp-icon folder-icon-folder'></i></span> <ul class='space' id='space_{$result['term_id']}'>";
1118 $string .= "</ul></li>";
1119 $response['term_data'] = $string;
1120 $response['parent_id'] = $parent;
1121
1122 $is_active = 1;
1123 $folders = -1;
1124 if (!self::check_has_valid_key()) {
1125 $is_active = 0;
1126 $folders = self::total_term_folders();
1127 }
1128 $response['is_key_active'] = $is_active;
1129 $response['folders'] = $folders;
1130 } else {
1131 $response['message'] = __("Error during server request", WCP_FOLDER);
1132 }
1133 } else {
1134 $response['error'] = 1;
1135 $response['message'] = __("Folder name already exists", WCP_FOLDER);
1136 }
1137 } else {
1138 $response['error'] = 1;
1139 $response['message'] = $error;
1140 }
1141 echo json_encode($response);
1142 die;
1143 }
1144
1145 public function is_for_this_post_type($post_type)
1146 {
1147 $post_types = get_option(WCP_FOLDER_VAR);
1148 $post_types = is_array($post_types)?$post_types:array();
1149 return in_array($post_type, $post_types);
1150 }
1151
1152 public function is_active_for_screen()
1153 {
1154
1155 global $typenow, $current_screen;
1156
1157 if ((isset($_POST['action']) && $_POST['action'] == 'inline-save') && (isset($_POST['post_type']) && self::is_for_this_post_type($_POST['post_type']))) {
1158 return true;
1159 }
1160 global $current_screen;
1161
1162 if (self::is_for_this_post_type($typenow) && ('edit' == $current_screen->base || 'upload' == $current_screen->base)) {
1163 return true;
1164 }
1165
1166 $post_types = get_option(WCP_FOLDER_VAR);
1167 $post_types = is_array($post_types)?$post_types:array();
1168
1169 if(empty($typenow) && 'upload' == $current_screen->base ) {
1170 $typenow = "attachment";
1171 if (self::is_for_this_post_type($typenow)) {
1172 return true;
1173 }
1174 }
1175 return false;
1176 }
1177
1178 public function is_add_update_screen()
1179 {
1180 global $current_screen;
1181 $current_type = $current_screen->base;
1182 $action = $current_screen->action;
1183 $post_types = get_option(WCP_FOLDER_VAR);
1184 $post_types = is_array($post_types)?$post_types:array();
1185 global $typenow;
1186 if (in_array($current_type, $post_types) && in_array($action, array("add", ""))) {
1187 $license_data = self::get_license_key_data();
1188
1189 $is_active = 1;
1190 $folders = -1;
1191 if (!self::check_has_valid_key()) {
1192 $is_active = 0;
1193 $folders = self::total_term_folders();
1194 }
1195 $response['folders'] = $folders;
1196 $response['is_key_active'] = $is_active;
1197 }
1198 }
1199
1200 public static function get_custom_post_type($post_type)
1201 {
1202 if ($post_type == "post") {
1203 return "post_folder";
1204 } else if ($post_type == "page") {
1205 return "folder";
1206 } else if ($post_type == "attachment") {
1207 return "media_folder";
1208 }
1209 return $post_type . '_folder';
1210 }
1211
1212 public function admin_footer()
1213 {
1214
1215 if (self::is_active_for_screen()) {
1216 global $typenow;
1217
1218 $total_posts = self::get_total_posts($typenow);
1219
1220 $folder_type = self::get_custom_post_type($typenow);
1221 $terms_data = WCP_Tree::get_full_tree_data($folder_type);
1222 $terms_html = WCP_Tree::get_option_data_for_select($folder_type);
1223 $form_html = WCP_Forms::get_form_html($terms_html);
1224 include_once dirname(dirname(__FILE__)) . WCP_DS . "/templates" . WCP_DS . "admin" . WCP_DS . "admin-content.php";
1225 }
1226
1227 global $pagenow;
1228 if ( 'plugins.php' !== $pagenow ) {
1229
1230 } else {
1231 include_once dirname(dirname(__FILE__)) . WCP_DS . "/templates" . WCP_DS . "admin" . WCP_DS . "folder-deactivate-form.php";
1232 }
1233 }
1234
1235 public function get_total_posts($post_type = "")
1236 {
1237 global $typenow;
1238 if ($post_type == "") {
1239 $post_type = $typenow;
1240 }
1241 if ($typenow == "attachment") {
1242 return wp_count_posts($post_type)->inherit;
1243 } else {
1244 return wp_count_posts($post_type)->publish + wp_count_posts($post_type)->draft + wp_count_posts($post_type)->future + wp_count_posts($post_type)->private;
1245 }
1246 }
1247
1248 public function autoload()
1249 {
1250 $files = array(
1251 'WCP_Tree_View' => WCP_DS . "includes" . WCP_DS . "tree.class.php",
1252 'WCP_Form_View' => WCP_DS . "includes" . WCP_DS . "form.class.php",
1253 );
1254
1255 foreach ($files as $file) {
1256 if (file_exists(dirname(dirname(__FILE__)) . $file)) {
1257 include_once dirname(dirname(__FILE__)) . $file;
1258 }
1259 }
1260 }
1261
1262 public function create_folder_terms()
1263 {
1264 $options = get_option(WCP_FOLDER_VAR);
1265 $options = is_array($options)?$options:array();
1266 $old_plugin_status = 0;
1267 $posts = array();
1268 if (!empty($options)) {
1269 foreach ($options as $option) {
1270 if (!(strpos($option, 'folder4') === false) && $old_plugin_status == 0) {
1271 $old_plugin_status = 1;
1272 }
1273 if (in_array($option, array("page", "post", "attachment"))) {
1274 $posts[] = str_replace("folder4", "", $option);
1275 } else {
1276 $posts[] = $option;
1277 }
1278 }
1279 if(!empty($posts)) {
1280 update_option(WCP_FOLDER_VAR, $posts);
1281 }
1282 }
1283 if ($old_plugin_status == 1) {
1284 update_option("folders_show_in_menu", "on");
1285 $old_plugin_var = get_option("folder_old_plugin_status");
1286 if (empty($old_plugin_var) || $old_plugin_var == null) {
1287 update_option("folder_old_plugin_status", "1");
1288 }
1289 }
1290 $posts = get_option(WCP_FOLDER_VAR);
1291 if (!empty($posts)) {
1292 foreach ($posts as $post_type) {
1293 $labels = array(
1294 'name' => __('Folders', WCP_FOLDER),
1295 'singular_name' => __('Folder', WCP_FOLDER),
1296 'all_items' => __('All Folders', WCP_FOLDER),
1297 'edit_item' => __('Edit Folder', WCP_FOLDER),
1298 'update_item' => __('Update Folder', WCP_FOLDER),
1299 'add_new_item' => __('Add New Folder', WCP_FOLDER),
1300 'new_item_name' => __('Add Folder Name', WCP_FOLDER),
1301 'menu_name' => __('Folders', WCP_FOLDER),
1302 'search_items' => __('Search Folders', WCP_FOLDER),
1303 'parent_item' => __('Parent Folder', WCP_FOLDER),
1304 );
1305
1306 $args = array(
1307 'label' => __('Folder'),
1308 'labels' => $labels,
1309 'show_tagcloud' => false,
1310 'hierarchical' => true,
1311 'public' => false,
1312 'show_ui' => true,
1313 'show_in_menu' => false,
1314 'show_in_rest' => true,
1315 'show_admin_column' => true,
1316 'update_count_callback' => '_update_generic_term_count',
1317 'query_var' => true,
1318 'rewrite' => false,
1319 );
1320
1321 $folder_post_type = self::get_custom_post_type($post_type);
1322
1323 register_taxonomy(
1324 $folder_post_type,
1325 $post_type,
1326 $args
1327 );
1328 }
1329 }
1330
1331 if(current_user_can("manage_categories")) {
1332 if (isset($_POST['folders_show_in_menu']) && !empty($_POST['folders_show_in_menu'])) {
1333 $show_menu = "off";
1334 if ($_POST['folders_show_in_menu'] == "on") {
1335 $show_menu = "on";
1336 }
1337 update_option("folders_show_in_menu", $show_menu);
1338 }
1339
1340 if (isset($_POST['folders_settings1'])) {
1341 $posts = array();
1342 if (isset($_POST['folders_settings']) && is_array($_POST['folders_settings'])) {
1343 foreach ($_POST['folders_settings'] as $key => $val) {
1344 $posts[] = $val;
1345 }
1346 }
1347 update_option("folders_settings", $posts);
1348 }
1349 }
1350
1351 $old_version = get_option("folder_old_plugin_status");
1352 if($old_version !== false && $old_version == 1) {
1353 $total_folders = get_option("folder_old_plugin_folder_status");
1354 if($total_folders === false) {
1355 $total = self::total_term_folders();
1356 if($total <= 10) {
1357 $total = 10;
1358 };
1359 update_option("folder_old_plugin_folder_status", $total);
1360 self::$folders = $total;
1361 } else {
1362 self::$folders = $total_folders;
1363 }
1364 }
1365
1366 $total_folders = get_option("folder_old_plugin_folder_status");
1367 if($total_folders === false) {
1368 self::$folders = 10;
1369 } else {
1370 self::$folders = $total_folders;
1371 }
1372 }
1373
1374 function searchForId($id, $menu)
1375 {
1376 if ($menu) {
1377 foreach ($menu as $key => $val) {
1378 if (array_key_exists(2, $val)) {
1379 $stripVal = explode('=', $val[2]);
1380 }
1381 if (array_key_exists(1, $stripVal)) {
1382 $stripVal = $stripVal[1];
1383 }
1384 if ($stripVal === $id) {
1385 return $key;
1386 }
1387 }
1388 }
1389 }
1390
1391 function create_menu_for_folders()
1392 {
1393 global $menu;
1394 self::check_and_set_post_type();
1395
1396 $folder_types = get_option("folders_settings");
1397 if (empty($folder_types)) {
1398 return;
1399 }
1400
1401 foreach ($folder_types as $type) {
1402 $itemKey = self::searchForId($type, $menu);
1403 switch (true) {
1404 case ($type == 'attachment'):
1405 $itemKey = 10;
1406 $edit = 'upload.php';
1407 break;
1408 case ($type === 'post'):
1409 $edit = 'edit.php';
1410 $itemKey = 5;
1411 break;
1412 default:
1413 $edit = 'edit.php';
1414 break;
1415 }
1416
1417 $folder = $type == 'attachment' ? 'media' : $type;
1418 $upper = $type == 'attachment' ? 'Media' : ucwords(str_replace(array('-', '_'), ' ', $type));
1419 if ($type == 'page') {
1420 $tax_slug = 'folder';
1421 } else {
1422 $tax_slug = $folder . '_folder';
1423 }
1424
1425
1426 if ($type == 'attachment') {
1427 add_menu_page('Media Folders', 'Media Folders', 'publish_pages', "{$edit}?type=folder", false, 'dashicons-portfolio', "{$itemKey}.5");
1428 } else {
1429 add_menu_page($upper . ' Folders', "{$upper} Folders", 'publish_pages', "{$edit}?post_type={$type}&type=folder", false, 'dashicons-portfolio', "{$itemKey}.5");
1430 }
1431 $terms = get_terms($tax_slug, array(
1432 'hide_empty' => true,
1433 'parent' => 0,
1434 'orderby' => 'meta_value_num',
1435 'order' => 'ASC',
1436 'hierarchical' => false,
1437 'meta_query' => [[
1438 'key' => 'wcp_custom_order',
1439 'type' => 'NUMERIC',
1440 ]]
1441 )
1442 );
1443
1444 if ($terms) {
1445 foreach ($terms as $term) {
1446 if ($type == 'attachment') {
1447 add_submenu_page("{$edit}?type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type=attachment&media_folder={$term->slug}", false);
1448 } else {
1449 add_submenu_page("{$edit}?post_type={$type}&type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type={$type}&{$tax_slug}={$term->slug}", false);
1450 }
1451 }
1452 }
1453 }
1454 }
1455
1456 function folders_admin_styles()
1457 {
1458 if (self::is_active_for_screen()) {
1459 wp_register_style('wcp-folders-fa', plugin_dir_url(dirname(__FILE__)) . 'assets/css/folder-icon.css');
1460 wp_enqueue_style('wcp-folders-fa');
1461 wp_register_style('wcp-folders-admin', plugin_dir_url(dirname(__FILE__)) . 'assets/css/design.css');
1462 wp_enqueue_style('wcp-folders-admin');
1463 }
1464 wp_register_style('wcp-css-handle', false);
1465 wp_enqueue_style('wcp-css-handle');
1466 $css = "
1467 .wcp-folder-upgrade-button {color: #FF5983; font-weight: bold;}
1468 ";
1469 if (self::is_active_for_screen()) {
1470 global $typenow;
1471 $width = get_option("wcp_dynamic_width_for_" . $typenow);
1472 $width = esc_attr($width);
1473 if (!empty($width) && is_numeric($width)) {
1474 $css .= ".wcp-content{width:{$width}px}";
1475 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
1476 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-right:" . ($width + 20) . "px}";
1477 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-left:0px}";
1478 } else {
1479 $css .= "body.wp-admin #wpcontent {padding-left:" . ($width + 20) . "px}";
1480 }
1481
1482 }
1483 }
1484 wp_add_inline_style('wcp-css-handle', $css);
1485
1486 if (self::is_active_for_screen()) {
1487 global $typenow;
1488 add_filter('views_edit-' . $typenow, array($this, 'wcp_check_for_child_folders'));
1489 }
1490
1491 }
1492
1493 function wcp_check_for_child_folders($content)
1494 {
1495 $termId = 0;
1496 global $typenow;
1497 $post_type = self::get_custom_post_type($typenow);
1498 if (isset($_GET[$post_type]) && !empty($_GET[$post_type])) {
1499 $term = $_GET[$post_type];
1500 $term = get_term_by("slug", $term, $post_type);
1501 if (!empty($term)) {
1502 $termId = $term->term_id;
1503 }
1504 }
1505 $terms = get_terms($post_type, array(
1506 'hide_empty' => false,
1507 'parent' => $termId,
1508 'orderby' => 'meta_value_num',
1509 'order' => 'ASC',
1510 'hierarchical' => false,
1511 'update_count_callback' => '_update_generic_term_count',
1512 'meta_query' => [[
1513 'key' => 'wcp_custom_order',
1514 'type' => 'NUMERIC',
1515 ]]
1516 ));
1517 echo '<div class="tree-structure" id="list-folder-' . $termId . '" data-id="' . $termId . '">';
1518 echo '<ul>';
1519 foreach ($terms as $term) {
1520 $status = get_term_meta($term->term_id, "is_highlighted", true);
1521 ?>
1522 <li class="grid-view" data-id="<?php echo $term->term_id ?>" id="folder_<?php echo $term->term_id ?>">
1523 <div class="folder-item is-folder" data-id="<?php echo $term->term_id ?>">
1524 <a title='<?php echo $term->name ?>' id="folder_view_<?php echo $term->term_id ?>"
1525 class="folder-view <?php echo ($status == 1) ? "is-high" : "" ?>"
1526 data-id="<?php echo $term->term_id ?>">
1527 <span class="folder item-name"><span id="wcp_folder_text_<?php echo $term->term_id ?>"
1528 class="folder-title"><?php echo $term->name ?></span></span>
1529 <!--<span class="folder-option"></span>-->
1530 </a>
1531 </div>
1532 </li>
1533 <?php
1534 }
1535 echo '</ul>';
1536 echo '<div class="clear clearfix"></div>';
1537 echo '</div>';
1538 if(!empty($content) && is_array($content)) {
1539 echo '<ul class="subsubsub">';
1540 foreach($content as $k=>$v) {
1541 echo "<li class='{$k}'>{$v}</li>";
1542 }
1543 echo '</ul>';
1544 }
1545 }
1546
1547 function folders_admin_scripts()
1548 {
1549 if (self::is_active_for_screen()) {
1550 global $typenow;
1551 wp_register_script('wcp-folders-alert', plugin_dir_url(dirname(__FILE__)) . 'assets/js/sweetalert.all.min.js');
1552 wp_register_script('wcp-folders-custom', plugin_dir_url(dirname(__FILE__)) . 'assets/js/custom.js', array('jquery', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'backbone'));
1553
1554 if ($typenow == "attachment") {
1555 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
1556 } else {
1557 $admin_url = admin_url("edit.php?post_type=" . $typenow);
1558 if (isset($_GET['s']) && !empty($_GET['s'])) {
1559 $admin_url .= "&s=" . $_GET['s'];
1560 }
1561 $post_type = self::get_custom_post_type($typenow);
1562 $admin_url .= "&{$post_type}=";
1563 }
1564
1565 $is_active = 1;
1566 $folders = -1;
1567 if (!self::check_has_valid_key()) {
1568 $is_active = 0;
1569 $folders = self::total_term_folders();
1570 }
1571 $register_url = admin_url("admin.php?page=wcp_folders_upgrade");
1572
1573 $is_rtl = 0;
1574 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
1575 $is_rtl = 1;
1576 }
1577
1578 $can_manage_folder = current_user_can("manage_categories")?1:0;
1579 wp_localize_script('wcp-folders-custom', 'wcp_settings', array(
1580 'ajax_url' => admin_url('admin-ajax.php'),
1581 'post_type' => $typenow,
1582 'page_url' => $admin_url,
1583 'ajax_image' => plugin_dir_url(dirname(__FILE__)) . "assets/images/ajax-loader.gif",
1584 'is_key_active' => $is_active,
1585 'folders' => $folders,
1586 'register_url' => $register_url,
1587 'isRTL' => $is_rtl,
1588 'nonce' => wp_create_nonce('wcp_folder_nonce_'.$typenow),
1589 'can_manage_folder' => $can_manage_folder
1590 ));
1591
1592 wp_enqueue_script('wcp-folders-alert');
1593 wp_enqueue_script('wcp-folders-custom');
1594
1595 } else {
1596 self::is_add_update_screen();
1597 }
1598 }
1599
1600 public function plugin_action_links($links)
1601 {
1602 array_unshift($links, '<a href="' . admin_url("admin.php?page=wcp_folders_settings") . '" >' . __('Settings', WCP_FOLDER) . '</a>');
1603 $links['pro'] = '<a class="wcp-folder-upgrade-button" href="'.admin_url("admin.php?page=wcp_folders_upgrade").'" >'.__( 'Upgrade', WCP_FOLDER ).'</a>';
1604 return $links;
1605 }
1606
1607 public static function get_instance()
1608 {
1609 if (empty(self::$instance)) {
1610 self::$instance = new WCP_Folders();
1611 }
1612 return self::$instance;
1613 }
1614
1615 public function check_and_set_post_type() {
1616 $options = get_option(WCP_FOLDER_VAR);
1617 $options = is_array($options)?$options:array();
1618 $old_plugin_status = 0;
1619 $post_array = array();
1620 if (!empty($options)) {
1621 foreach ($options as $key=>$val) {
1622 if (!(strpos($key, 'folders4') === false) && $old_plugin_status == 0) {
1623 $old_plugin_status = 1;
1624 }
1625 if (in_array($key, array("folders4page", "folders4post", "folders4attachment"))) {
1626 $post_array[] = str_replace("folders4", "", $key);
1627 }
1628 }
1629 } else {
1630 $post_array = array("page", "post", "attachment");
1631 }
1632 if ($old_plugin_status == 1) {
1633 update_option("folders_show_in_menu", "on");
1634 $old_plugin_var = get_option("folder_old_plugin_status");
1635 if (empty($old_plugin_var) || $old_plugin_var == null) {
1636 update_option("folder_old_plugin_status", "1");
1637 }
1638 update_option(WCP_FOLDER_VAR, $post_array);
1639 self::set_default_values_if_not_exists();
1640 }
1641 if (!empty($post_array) && get_option(WCP_FOLDER_VAR) === false) {
1642 update_option(WCP_FOLDER_VAR, $post_array);
1643 update_option("folders_show_in_menu", "off");
1644 }
1645 }
1646
1647 public static function activate()
1648 {
1649 update_option("folders_show_in_menu", "off");
1650 update_option("folder_redirect_status", 1);
1651 }
1652
1653 public static function get_total_term_folders()
1654 {
1655 return self::total_term_folders();
1656 }
1657
1658 function folders_register_settings()
1659 {
1660 register_setting('folders_settings', 'folders_settings1', 'folders_settings_validate');
1661
1662 self::check_and_set_post_type();
1663
1664 $options = get_option("folders_settings");
1665
1666 if (in_array("post", $options)) {
1667 add_filter('manage_posts_columns', array($this, 'wcp_manage_columns_head'));
1668 add_action('manage_posts_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
1669 }
1670
1671 if (in_array("page", $options)) {
1672 add_filter('manage_page_posts_columns', array($this, 'wcp_manage_columns_head'));
1673 add_action('manage_page_posts_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
1674 }
1675
1676 if (in_array("attachment", $options)) {
1677 add_filter('manage_media_columns', array($this, 'wcp_manage_columns_head'));
1678 add_action('manage_media_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
1679 }
1680
1681 foreach ($options as $option) {
1682 if ($option != "post" && $option != "page" && $option != "attachment") {
1683 add_filter('manage_media_columns', array($this, 'wcp_manage_columns_head'));
1684 add_action('manage_media_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
1685 }
1686 }
1687
1688 $option = get_option("folder_redirect_status", true);
1689 if ($option == 1) {
1690 update_option("folder_redirect_status", 0);
1691 wp_redirect(admin_url("admin.php?page=wcp_folders_settings"));
1692 exit;
1693 }
1694 }
1695
1696 function wcp_manage_columns_head($defaults, $d = "")
1697 {
1698 global $typenow;
1699 $options = get_option("folders_settings");
1700 if (is_array($options) && in_array($typenow, $options)) {
1701 $columns = array(
1702 'wcp_move' => '<div class="wcp-move-multiple wcp-col" title="' . __('Move selected items', WCP_FOLDER) . '"><span class="dashicons dashicons-move"></span><div class="wcp-items"></div></div>',
1703 ) + $defaults;
1704 return $columns;
1705 }
1706 return $defaults;
1707 }
1708
1709 function wcp_manage_columns_content($column_name, $post_ID)
1710 {
1711 global $typenow;
1712 $options = get_option("folders_settings");
1713 if (is_array($options) && in_array($typenow, $options)) {
1714 if ($column_name == 'wcp_move') {
1715 $title = get_the_title();
1716 if (strlen($title) > 20) {
1717 $title = substr($title, 0, 20) . "...";
1718 }
1719 echo "<div class='wcp-move-file' data-id='{$post_ID}'><span class='wcp-move dashicons dashicons-move' data-id='{$post_ID}'></span><span class='wcp-item' data-object-id='{$post_ID}'>" . $title . "</span></div>";
1720 }
1721 }
1722 }
1723
1724 function taxonomy_archive_exclude_children($query)
1725 {
1726 $options = get_option("folders_settings");
1727 if (!empty($options)) {
1728 $taxonomy_slugs = array();
1729 foreach ($options as $option) {
1730 $taxonomy_slugs[] = self::get_custom_post_type($option);
1731 }
1732 if (!empty($taxonomy_slugs)) {
1733 $i = 0;
1734 foreach ($query->tax_query->queries as $tax_query_item) {
1735 if (empty($taxonomy_slugs) || (isset($tax_query_item['taxonomy']) && in_array($tax_query_item['taxonomy'], $taxonomy_slugs))) {
1736 $query->tax_query->queries[$i]['include_children'] = 0;
1737 }
1738 }
1739 }
1740 }
1741 }
1742
1743 public function admin_menu()
1744 {
1745 // Add menu item for settings page
1746 $page_title = __('Folders', WCP_FOLDER);
1747 $menu_title = __('Folders Settings', WCP_FOLDER);
1748 $capability = 'manage_options';
1749 $menu_slug = 'wcp_folders_settings';
1750 $callback = array($this, "wcp_folders_settings");
1751 $icon_url = 'dashicons-category';
1752 $position = 99;
1753
1754 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $position);
1755
1756 add_submenu_page(
1757 $menu_slug,
1758 __('Upgrade to Pro', WCP_FOLDER),
1759 __('Upgrade to Pro', WCP_FOLDER),
1760 'manage_options',
1761 'wcp_folders_upgrade',
1762 array($this, 'wcp_folders_upgrade')
1763 );
1764
1765 self::check_and_set_post_type();
1766
1767 $show_menu = get_option("folders_show_in_menu", true);
1768 if ($show_menu == "on") {
1769 self::create_menu_for_folders();
1770 }
1771 }
1772
1773 public function wcp_folders_upgrade()
1774 {
1775 self::set_default_values_if_not_exists();
1776 include_once dirname(dirname(__FILE__)) . "/templates/admin/upgrade-to-pro.php";
1777 }
1778
1779 public function wcp_folders_settings()
1780 {
1781 self::set_default_values_if_not_exists();
1782 include_once dirname(dirname(__FILE__)) . "/templates/admin/general-settings.php";
1783 }
1784
1785 public function set_default_values_if_not_exists()
1786 {
1787 $options = get_option(WCP_FOLDER_VAR);
1788 $options = is_array($options)?$options:array();
1789 foreach ($options as $option) {
1790 $post_type = self::get_custom_post_type($option);
1791 $terms = get_terms($post_type, array(
1792 'hide_empty' => false,
1793 )
1794 );
1795 foreach ($terms as $term) {
1796 $order = get_term_meta($term->term_id, "wcp_custom_order", true);
1797 if (empty($order) || $order == null) {
1798 update_term_meta($term->term_id, "wcp_custom_order", "1");
1799 }
1800
1801 }
1802 }
1803 }
1804 }