alleyinteractive / expiring-posts
Automatically Expire Posts
Installs: 5 436
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 24
Forks: 1
Open Issues: 4
Type:wordpress-plugin
pkg:composer/alleyinteractive/expiring-posts
Requires (Dev)
This package is auto-updated.
Last update: 2025-10-04 13:54:17 UTC
README
Automatically expire posts after a certain period of time. Checks the post's published and modified date to see if the post is expired and will perform an action on the post (draft/trash/delete it).
Usage
Registering Post Types
Posts that are expired can be made into draft or trash posts or outright
deleted.
Register a post type to be drafted after a month
expiring_posts_add_post_type( $post_type, [ 'action' => 'draft', 'expire_after' => MONTH_IN_SECONDS, ], );
Register a post type to be trashed after a week
expiring_posts_add_post_type( $post_type, [ 'action' => 'trash', 'expire_after' => WEEK_IN_SECONDS, ], );
Register a post type to be deleted after a week
expiring_posts_add_post_type( $post_type, [ 'action' => 'delete', 'expire_after' => WEEK_IN_SECONDS, ], );
Register a post type to be updated after a week
expiring_posts_add_post_type( $post_type, [ 'action' => 'update', 'expire_after' => WEEK_IN_SECONDS, 'update_args' => [ 'meta_input' => [ 'key' => 'value', ], ], ], ); // Or use a callback to define the arguments. The callback // is passed an instance of WP_Post. expiring_posts_add_post_type( $post_type, [ 'action' => 'update', 'expire_after' => WEEK_IN_SECONDS, 'update_args' => fn ( WP_Post $post ) => [ 'post_title' => 'Expired: ' . $post->post_title, ], ], );
By default, the post type will be set to be drafted after a year.
Hooks
expiring_posts_is_post_expired
Filter applied to check if a post is expired.
Props:
$is_expired:boolWhether the post is expired.$post:WP_PostPost to check.$threshold:intThreshold to check against (unix timestamp).$now:intCurrent timestamp.
expiring_posts_cron_interval
Interval to run the expiration check. Defaults to every hour.
expiring_posts_expired
Action fired when a post was expired.
Props:
$post_id:intPost ID$post:WP_PostPost object.
expiring_posts_query_args
Filter applied to the query arguments used to find expired posts.
Props:
$args:arrayQuery arguments.$now:intCurrent timestamp.
Unregister a post type
expiring_posts_remove_post_type( $post_type );
Testing
composer test
License
Released under the GPL v2 license.