Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress中创建cron_Php_Wordpress_Cron_Sticky_Posts - Fatal编程技术网

Php 在wordpress中创建cron

Php 在wordpress中创建cron,php,wordpress,cron,sticky,posts,Php,Wordpress,Cron,Sticky,Posts,我正在努力在wordpress中制作一个cron,它将从具有过期自定义过期日期的粘贴帖子中删除粘性选项。除了我不能让Wordpress认出我的老太婆外,我什么都做得很好。这是我插件中cron的代码 // Custom Cron Recurrences function expire_posts_cron_recurrence( $schedules ) { $schedules['every_three_minutes'] = array( 'display' =>

我正在努力在wordpress中制作一个cron,它将从具有过期自定义过期日期的粘贴帖子中删除粘性选项。除了我不能让Wordpress认出我的老太婆外,我什么都做得很好。这是我插件中cron的代码

// Custom Cron Recurrences
function expire_posts_cron_recurrence( $schedules ) {
    $schedules['every_three_minutes'] = array(
        'display' => __( 'every three minutes', 'textdomain' ),
        'interval' => 180,
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'expire_posts_cron_recurrence' );

// Schedule Cron Job Event
function expire_posts_cron() {
    if ( ! wp_next_scheduled( 'expire_action_func' ) ) {
        wp_schedule_event( time(), 'every_three_minutes', 'expire_action_func' );
    }
}

register_activation_hook(__FILE__, 'expire_posts_cron');

// Scheduled Action Hook
function expire_action( ) {
    // get sticky posts from DB
    $sticky = get_option('sticky_posts');
    // check if there are any
    if (!empty($sticky)) {


        $args = array(
            'post__in' => $sticky
        );

        query_posts($args);

        if ( have_posts() ) {
            while ( have_posts() ) {
                the_post(); 
                $post_ID = get_the_ID();

                $expire_date = get_post_meta( $post_ID, 'expires_date', true );
                $expire_time = get_post_meta( $post_ID, 'expires_time', true );

                if(!empty($expire_date) && $expire_date != '' && !empty($expire_time) && $expire_time != ''){
                    $full_datetime = $expire_date.$expire_time." GMT-4:00 DST";
                    $epoch_full_datetime = strtotime($full_datetime);
                    $current_epoch_time = time();
                    if($epoch_full_datetime <= $current_epoch_time){
                        unstick_post( $post_id );
                    }
                }

            } // end while
        } // end if

    }
}

add_action( 'expire_action_func', 'expire_action' );
//自定义Cron重复出现
函数过期\u发布\u cron\u重复($schedules){
$schedules['每三分钟]]=数组(
'display'=>\('every three minutes','textdomain'),
“间隔”=>180,
);
返回$时间表;
}
添加过滤器('cron_schedules'、'expire_posts\u cron_recurrence');
//计划Cron作业事件
函数expire\u posts\u cron(){
如果(!wp_next_scheduled('expire_action_func')){
wp_schedule_event(时间(),“每三分钟一次”,“过期行动函数”);
}
}
注册\激活\挂钩(\文件\过期\发布\ cron');
//计划动作挂钩
函数expire\u操作(){
//从DB获取粘性帖子
$sticky=get_选项(“sticky_帖子”);
//检查是否有
如果(!空($sticky)){
$args=数组(
'post_uuin'=>$sticky
);
查询职位($args);
if(have_posts()){
while(have_posts()){
_post();
$post_ID=获取_ID();
$expire\u date=get\u post\u meta($post\u ID,'expires\u date',true);
$expire\u time=get\u post\u meta($post\u ID,'expires\u time',true);
如果(!empty($expire\u date)&&$expire\u date!=''&&&!empty($expire\u time)&&$expire\u time!=''){
$full_datetime=$expire_date.$expire_time.“GMT-4:00 DST”;
$epoch\u full\u datetime=strottime($full\u datetime);
$current_epoch_time=time();
如果($epoch\u full\u datetime
<?php echo '<pre>'; print_r( _get_cron_array() ); echo '</pre>'; ?>