• Resolved Philipp

    (@philippmuenchen)


    Dear imath,

    as always this is a excellent PlugIn. Thank you very much! ??
    I got just a quick question: Is it easily possible to add a feature, which gives single files a durability? Let’s say I’m uploading a file from which I know that it will be outdated next month. So I’m able to to choose a durability of one month for that file at the upload process. After the month the file get’s deleted automatically.

    Haha, that would be such a great feature. Maybe you’re able to give me a hint how to reach that. ??

    Thanks and take care!

    Philipp

    https://www.ads-software.com/plugins/buddydrive/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Mathieu Viet

    (@imath)

    Thanks for your feedback ??

    I think, i would use WordPress Cron API for this need see https://codex.www.ads-software.com/Function_Reference/wp_schedule_event

    You should be able to add a daily event that would loop in BuddyDrive file post types to get the needed IDs using WP_Query see https://codex.www.ads-software.com/wp_query#Date_Parameters

    To get the BuddyDrive post type “id”, you can alternatively use buddydrive_get_file_post_type() or directly ‘buddydrive-file’

    So i guess the query could look like this :

    $args = array(
    	'post_type' => buddydrive_get_file_post_type(),
    	'date_query' => array(
    		array(
    			'after'     => 'January 1st, 2013',
    			'before'    => array(
    				'year'  => 2013,
    				'month' => 2,
    				'day'   => 28,
    			),
    			'inclusive' => true,
    		),
    	),
    	'posts_per_page' => -1,
    );
    $query = new WP_Query( $args );

    Then after i guess you can loop throught results to get the IDs and user_ids and do something like for each item :
    buddydrive_delete_item( $result->ID, $result->user_id ).

    Thread Starter Philipp

    (@philippmuenchen)

    Thank you! That’s the perfect hint for a good start. I’ll share my function here asa I got it working. If you don’t mind I got another question to extend that function:

    Is it possible to add two more fields to the upload process? One should ask for tags for the file so that I’m able to include them to the search results in WordPress (as long as they are shared). Let’s say I’m uploading a file with the tags “fun, video, cat”.
    The other field should contain the choice to set a durability of the file. So within the upload process I’m able to set “x Months” or “x years”. It should be possible to use the function you advised before to select all files with outdated chosen durability to delete them automatically. ?? That would be awesome.

    Again, thank you for your help and the great Plugin!

    Cheers,

    Philipp

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘durability of files’ is closed to new replies.