Closed knutsp closed 8 months ago
The biggest issue with this plugin is probably the lack of trashing, either after time or by maximum number reached.
Like this, in a cron every night:
$days_to_keep = apply _filters( 'wp_user_activity_trash_days_to_keep', 14 ); $max_trash_each_time = apply _filters( 'wp_user_activity_trash_each', 100 ); $activities = get_posts( [ 'post_type' => 'activity', 'date_query' => [ 'before' => date( 'Y-m-d H:i:s', strtotime( -$days_to_keep . ' days' ) ) ], 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => $max_trash_each_time, ] ); if ( is_array( $activities ) ) { foreach( $activities as $activity ) { wp_trash_post( $activity->ID ); } }
Direct WP_Query may be better than get_posts, since one may further filter the trashing query by meta.
get_posts
The biggest issue with this plugin is probably the lack of trashing, either after time or by maximum number reached.
Like this, in a cron every night:
Direct WP_Query may be better than
get_posts
, since one may further filter the trashing query by meta.