• Hi guys,
    I need to have an events import every 5 minutes.
    I tried adding this in my function.php

    function isa_add_every_five_minutes( $schedules ) {
    
        $schedules['every_five_minutes'] = array(
                'interval'  => 300,
                'display'   => __( 'Every 5 Minutes')
        );
        return $schedules;
    }
    add_filter( 'cron_schedules', 'isa_add_every_five_minutes' );

    and changed this in fb-sch.php:

    <?php
    add_action( 'wp', 'fbe_cron_setup_schedule' );
    
    function fbe_cron_setup_schedule() {
    	if ( !wp_next_scheduled( 'fbe_cron_hourly_event' ) ) {
    		wp_schedule_event( time(), 'every_five_minutes', 'fbe_cron_hourly_event');
    		//wp_schedule_event( time(), 'hourly', 'fbe_cron_hourly_event');
    	}
    }
    
    add_action( 'fbe_cron_hourly_event', 'fbe_cron_do_this_hourly' );
    
    function fbe_cron_do_this_hourly() {
    	// Check for new events every hour
    	$pages = get_option("facebook_pages");
    	$location = array_filter(explode(",",$pages));
    
    	foreach ($location as $loc){
    		fbe_facebook_sdk($loc,get_option("app_id"),get_option("app_secret"));
    	}
    	update_option('fbe_cron_date', time());
    }
    ?>

    But it doesn’t work 🙁

    https://wordpress.org/plugins/facebook-events-importer/

Viewing 1 replies (of 1 total)
  • Plugin Author WPTrashPanda

    (@jprescher)

    In this format the only options are:

    • hourly
    • twicedaily
    • daily

    This is untested code but you could try:

    // Scheduled Action Hook
    function CustomWPFBCronHook( ) {
    	$pages = get_option("facebook_pages");
    		$location = array_filter(explode(",",$pages));
    
    		foreach ($location as $loc){
    			fbe_facebook_sdk($loc,get_option("app_id"),get_option("app_secret"));
    		}
    		update_option('fbe_cron_date', time());
    }
    
    // Custom Cron Recurrences
    function custom_wpfb_cron_job_recurrence( $schedules ) {
    	$schedules['5min'] = array(
    		'display' => __( '5', 'textdomain' ),
    		'interval' => 300,
    	);
    	return $schedules;
    }
    add_filter( 'cron_schedules', 'custom_wpfb_cron_job_custom_recurrence' );
    
    // Schedule Cron Job Event
    function custom_wpfb_cron_job() {
    	if ( ! wp_next_scheduled( 'CustomWPFBCronHook' ) ) {
    		wp_schedule_event( current_time( 'timestamp' ), '5min', 'CustomWPFBCronHook' );
    	}
    }
    add_action( 'wp', 'custom_wpfb_cron_job' );)

    GenerateWP

Viewing 1 replies (of 1 total)

The topic ‘Change scheduling frequence’ is closed to new replies.