承接 alleyinteractive/expiring-posts 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alleyinteractive/expiring-posts

最新稳定版本:v0.3.0

Composer 安装命令:

composer require alleyinteractive/expiring-posts

包简介

Automatically Expire Posts

README 文档

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: bool Whether the post is expired.
  • $post: WP_Post Post to check.
  • $threshold: int Threshold to check against (unix timestamp).
  • $now: int Current 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: int Post ID
  • $post: WP_Post Post object.

expiring_posts_query_args

Filter applied to the query arguments used to find expired posts.

Props:

  • $args: array Query arguments.
  • $now: int Current timestamp.

Unregister a post type

expiring_posts_remove_post_type( $post_type );

Testing

composer test

License

Released under the GPL v2 license.

统计信息

  • 总下载量: 5.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 23
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-03-22