wp_schedule_event-Hook geplant, funktioniert aber nicht

Lesezeit: 1 Minute

Benutzer-Avatar
Nick

Ich versuche, einen Cron-Job vom WordPress-Plugin auszulösen, das ich schreibe (es wird alle neuen Produkte nehmen und sie jeden Tag in CSV exportieren), also ist das Problem, dass, wenn ich diesen Code in functions.php einfüge, alles großartig funktioniert und der Code ist gültig, aber aus dem Plug-in-Ordner ist er geplant und ich kann ihn sehen (mit Cron View Plug-in), aber nicht ausgeführt oder etwas blockiert es.. schau dir meinen code an..

function csv_init(){
add_action('my_hourly_event', 'Download_CSV_with_args');
}

function starthere(){
// some code here
    $file = $_SERVER['DOCUMENT_ROOT'].'/wp-content/csv_settings.php';
                            $content = serialize($args);
                            file_put_contents($file, $content);

                        wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');

                            $schedule = wp_get_schedule( 'my_hourly_event' );
                            echo  wp_next_scheduled( 'my_hourly_event' ).'<br>';
                        if ($schedule){
                            echo '<h3>The "'.$schedule.'" Cron Job is running..</h3>';
                         }else {
                            echo '<h3>There are no Cron Jobs that running..</h3>';
                         }

}

function Download_CSV_with_args() {
        //execution of my code
}

Benutzer-Avatar
Wladimir Atamanenko

Versuchen Sie sich zu bewegen add_action außerhalb einer Funktion:

function starthere(){
  if (!wp_next_scheduled('my_hourly_event')) {
    wp_schedule_event( time(), 'hourly', 'my_hourly_event' );
  }
}

add_action( 'my_hourly_event', 'Download_CSV_with_args' );

function Download_CSV_with_args() {
  wp_mail('[email protected]', 'Automatic email', 'Cron works!');
}

  • Vergessen Sie nicht, die Antwort als beste zu markieren, wenn sie Ihnen geholfen hat. 🙂

    – Wladimir Atamanenko

    15. Juni 2015 um 16:53 Uhr

1352880cookie-checkwp_schedule_event-Hook geplant, funktioniert aber nicht

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy