WordPress 采集文章后,定时发布

WordPress 定时发布

seo的经常进行数据采集工作,但是大规模的数据采集后进行发布,往往会导致百度K站,所以实现了定时自动发布文章的功能

Python
/** * 定时发布 插件 */ if(!function_exists('add_action')){ header('Status 403 Forbidden'); header('HTTP/1.0 403 Forbidden'); header('HTTP/1.1 403 Forbidden'); exit();} /** * 定义发布时间间隔 单位分钟 * WPMS_DELAY */ define('WPMS_DELAY',1); define('WPMS_OPTION','wp_missed_schedule'); function wpms_replace(){ delete_option(WPMS_OPTION); } register_deactivation_hook(__FILE__,'wpms_replace'); function wpms_init(){ remove_action('publish_future_post','check_and_publish_future_post'); $last=get_option(WPMS_OPTION,false); if(($last!==false)&&($last>(time()-(WPMS_DELAY*60))))return; update_option(WPMS_OPTION,time()); global$wpdb; /** * 获取需要发布的文章,从draft到publish状态 */ $scheduledIDs=$wpdb->get_col("SELECT`ID`FROM`{$wpdb->posts}`"."WHERE("."((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP()))OR"."((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP()))".")AND`post_status`='draft'LIMIT 0,1"); if(!count($scheduledIDs))return; foreach($scheduledIDs as$scheduledID){if(!$scheduledID)continue; wp_publish_post($scheduledID);} } add_action('init','wpms_init',0);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/ * *
* 定时发布 插件
* /
 
if ( ! function_exists ( 'add_action' ) ) {
     header ( 'Status 403 Forbidden' ) ;
     header ( 'HTTP/1.0 403 Forbidden' ) ;
     header ( 'HTTP/1.1 403 Forbidden' ) ;
     exit ( ) ; }
/ * *
* 定义发布时间间隔 单位分钟
* WPMS_DELAY
* /
define ( 'WPMS_DELAY' , 1 ) ;
 
define ( 'WPMS_OPTION' , 'wp_missed_schedule' ) ;
 
function wpms_replace ( ) {
     delete_option ( WPMS_OPTION ) ;
}
register_deactivation_hook ( __FILE__ , 'wpms_replace' ) ;
function wpms_init ( ) {
     remove_action ( 'publish_future_post' , 'check_and_publish_future_post' ) ;
     $ last = get_option ( WPMS_OPTION , false ) ;
     if ( ( $ last !== false ) && ( $ last > ( time ( ) - ( WPMS_DELAY * 60 ) ) ) ) return ;
     update_option ( WPMS_OPTION , time ( ) ) ;
     global $ wpdb ;
     / * *
     * 获取需要发布的文章 ,从 draft到 publish状态
     * /
 
     $ scheduledIDs = $ wpdb -> get_col ( "SELECT`ID`FROM`{$wpdb->posts}`" . "WHERE(" . "((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP()))OR" . "((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP()))" . ")AND`post_status`='draft'LIMIT 0,1" ) ;
 
     if ( ! count ( $ scheduledIDs ) ) return ;
     foreach ( $ scheduledIDs as $ scheduledID ) { if ( ! $ scheduledID ) continue ;
         wp_publish_post ( $ scheduledID ) ; }
}
add_action ( 'init' , 'wpms_init' , 0 ) ;
 

亲测 效果还是可以的!!!,采集有风险需谨慎啊。




  • zeropython 微信公众号 5868037 QQ号 5868037@qq.com QQ邮箱
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值