# taskbuilder/6.0.6/includes/actions/wppm_check_cron_attachment.php

Taskbuilder – Project Management &amp; Task Management Tool With Kanban Board, version 6.0.6. 49 lines.

- Page: https://pluginprobe.com/plugins/taskbuilder/6.0.6/code/includes/actions/wppm_check_cron_attachment.php
- Raw: https://pluginprobe.com/plugins/taskbuilder/6.0.6/raw/includes/actions/wppm_check_cron_attachment.php
- Modified: 2026-08-26T12:08:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/taskbuilder/6.0.6/code/includes/actions/wppm_check_cron_attachment.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
global $wpdb;
$garbage_collection_time = get_option('wppm_garbage_collection_time' ,'');
if ( empty( $garbage_collection_time ) ) {
    update_option( 'wppm_garbage_collection_time', current_time( 'mysql' ) );
    return;
}
$check_flag = false;
$now = current_time( 'timestamp' );
$ago = strtotime($garbage_collection_time);
$diff = $now - $ago;
if($diff >= DAY_IN_SECONDS){
  $check_flag = true;
}
if(!$check_flag){
  return;
}
$attachments=$wpdb->get_results(("select id,name,date_created from {$wpdb->prefix}wppm_attachments where is_active=0"));
if($attachments){
  foreach($attachments as $attachment){
    $created_time   = $attachment->date_created;
    $upload_dir  = wp_upload_dir();
    $time  = strtotime($created_time);
    $month = wp_date("m",$time);
    $year  = wp_date("Y",$time);
    $filename = sanitize_file_name( $attachment->name );
    $filepath = $upload_dir['basedir'] . '/wppm/'.'/'.$year.'/'.$month.'/'. $filename;
    $attachment_updated_time = strtotime($created_time);
    $diff = $now - $attachment_updated_time;
    if($diff > DAY_IN_SECONDS){
        $attachment_id = absint( $attachment->id );
        $wpdb->delete(
            $wpdb->prefix . 'wppm_attachments',
            array( 'id' => $attachment_id ),
            array( '%d' )
        );
        if(file_exists($filepath)){
            //unlink($filepath);
            wp_delete_file($filepath);
        }
    }
  }
}
update_option('wppm_garbage_collection_time', current_time( 'mysql' ) );
    

```
