-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Description
I would like to see additional values passed through WordPress filters in the AI_Logger_Garbage_Collector class so that I can fine tune when our logs are garbage collected, and how logs are queried during the garbage collection process.
Specifically, I would like to see a filter around the $recurrence parameter of the wp_schedule_event function, like so:
apply_filters( 'ai_logger_garbage_collector_cron_interval', 'every_three_hours' )
I would also like to see the return of the filter for the $throttle variable within the run_cleanup method:
$throttle = boolval( apply_filters( 'ai_logger_garbage_collector_throttle', $throttle ) );
Finally, I would like to see the post args array that is passed to the get_posts function passed through a filter:
$post_args = apply_filters( 'ai_logger_garbage_collector_post_args', [ 'fields' => 'ids', 'ignore_sticky_posts' => true, 'post_type' => 'ai_log', 'posts_per_page' => $throttle ? 100 : 1000, 'suppress_filters' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'date_query' => [ [ 'before' => "-{$max_age} days", 'column' => 'post_date', ], ], ] );
...
$logs_to_delete = get_posts( // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_posts $post_args );
This last point is motivated by the fact that currently, all of our logs have a post_status value of draft. By default, if post_status is not included in the post args array, get_posts will only query for posts that have a post_status of publish. Therefore, none of our logs are being garbage collected.
Use Case
Users will have a greater degree of freedom in determining how frequently their logs are garbage collected and how the logs to be garbage collected are queried.