PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.1
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / actions / wpsc_check_cron_attachment.php

wpsc_check_cron_attachment.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/actions/wpsc_check_cron_attachment.php

67 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 $time = get_option('wpsc_garbage_collection_time' ,'');
7 $check_flag = false;
8
9 $now = time();
10 $ago = strtotime($time);
11 $diff = $now - $ago;
12 if($diff >= 86400){
13 $check_flag = true;
14 }
15
16 if(!$check_flag){
17 return;
18 }
19
20 $attachments = get_terms([
21 'taxonomy' => 'wpsc_attachment',
22 'hide_empty' => false,
23 'meta_query' => array(
24 'relation' => 'AND',
25 array(
26 'key' => 'active',
27 'value' => 0,
28 'compare' => '='
29 ),
30 ),
31 ]);
32
33 if($attachments){
34 foreach($attachments as $attachment){
35 $updated_time = get_term_meta($attachment->term_id,'time_uploaded',true);
36 $file_name = get_term_meta($attachment->term_id,'save_file_name',true);
37 $is_restructured= get_term_meta($attachment->term_id,'is_restructured',true);
38 $upload_dir = wp_upload_dir();
39 $wpsp_file = get_term_meta($attachment->term_id,'wpsp_file');
40
41 if ($wpsp_file) {
42 $filepath = $upload_dir['basedir'] . '/wpsp/'. $file_name;
43 }else {
44 if($is_restructured){
45 $updated_time = get_term_meta($attachment->term_id,'time_uploaded',true);
46 $time = strtotime($updated_time);
47 $month = date("m",$time);
48 $year = date("Y",$time);
49 $filepath = $upload_dir['basedir'] . '/wpsc/'.$year.'/'.$month.'/'. $file_name;
50 }else{
51 $filepath = $upload_dir['basedir'] . '/wpsc/'. $file_name;
52 }
53 }
54
55 $attachment_updated_time = strtotime($updated_time);
56 $now = time();
57 $diff = $now - $attachment_updated_time;
58 if($diff > 86400){
59 wp_delete_term($attachment->term_id,'wpsc_attachment');
60 if(file_exists($filepath)){
61 unlink($filepath);
62 }
63 }
64 }
65 }
66
67 update_option('wpsc_garbage_collection_time', date("Y-m-d H:i:s"));