Support » Plugin: Widget Visibility Time Scheduler » Using cronjobs possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Martin Stehle

    (@hinjiriyo)

    Sorry for my late answer. Good point by you! I will think about that.

    Thread Starter Wielands

    (@wielands)

    I have made this function, maybe it helps 🙂

    add_filter( 'widget_update_callback', 'wp_add_cronjob_widget_schedule', 90, 3 );
    // Hook in the widget-visibility-time-scheduler plugin and set cronjob
       function wp_add_cronjob_widget_schedule( $widget_settings, $new_widget_settings, $old_widget_settings ) {
    
            $schedule_hook = 'wp_rocket_purge_widget';
            $schedule_args = array(
                'widget_id' =>      $_POST['id_base'],
                'sidebar' =>        $_POST['sidebar'],
                'widget_number' =>  $_POST['widget_number']
            );
    
            wp_clear_scheduled_hook( $schedule_hook, $schedule_args);
    
            if ( !empty( $_POST['hinjiwvts'][ 'mode' ] ) )
            {
                $offset = get_option('gmt_offset') * 3600; // WP schedule use UTC +0 time
                $trigger_event_start = $widget_settings['hinjiwvts'][ 'timestamps' ][ 'start' ] - $offset;
                $trigger_event_end = $widget_settings['hinjiwvts'][ 'timestamps' ][ 'end' ] - $offset;
                wp_schedule_single_event( $trigger_event_start, $schedule_hook, $schedule_args );
                wp_schedule_single_event( $trigger_event_end, $schedule_hook, $schedule_args );
            }
    
            return $widget_settings;
        }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using cronjobs possible?’ is closed to new replies.