Hi my wordpress plugin doesn't want run to the end second time.

Please note, the first time everything is ok, we perform script and schedule it for the next time.

But next time it stops on this line $posts_array = get_posts( $args );

Another words I see in the debugger

'start plugin' 'end plugin'

'start 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' );
    }
 

?> 







 

0 Answers