Привет, мой плагин WordPress не хочет запускаться до конца во второй раз.
Обратите внимание, что в первый раз все в порядке, мы выполняем сценарий и планируем его на следующий раз.
Но в следующий раз он останавливается на этой строке $ posts_array = get_posts ($ args);
Другие слова, которые я вижу в отладчике
'start plugin' 'end plugin'
' плагин запуска '
<?php
//Plugin Name: MY PLUGIN
register_activation_hook( __FILE__, 'myplugin_activate' );
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
function myplugin_activate() {
start();
}
add_action( 'startAction', 'start' );
function start() {
write_log ('start plugin');
//get fetch params
$args = array(
'orderby' => 'date',
'post_status' => 'publish',
'order' => 'DESC',
'numberposts' => -1
);
$posts_array = get_posts( $args );
workWithPosts($posts_array)
write_log('end of plugin');
}
function workWithPosts($array)
{
//shedule next call in 1 minute
if ( ! wp_next_scheduled( 'startAction' ) ) {
wp_schedule_single_event( time() + 60, 'startAction' );
}
}
function myplugin_deactivate() {
wp_clear_scheduled_hook( 'startAction' );
}
?>