WordPress.org

Ready to get started?Download WordPress

Forums

WP-Polls
Not Posting on Specific Day of the Week (8 posts)

  1. MuskKing
    Member
    Posted 9 months ago #

    We have problem where the Poll are not being posted if they are scheduled for Monday at 4:00 AM but any other day of the week works. I found it odd so i'm wondering if it is due to a settings in WP-Cron or the actual plugin.

    Thanks.

    http://wordpress.org/plugins/wp-polls/

  2. Lester Chan
    Member
    Plugin Author

    Posted 9 months ago #

    I am not too sure about this, but WP just uses WP Cron to schedule the poll to be open. Do you get any traffic on that day to trigger the cron since WP Cron is not a true cron?

  3. MuskKing
    Member
    Posted 8 months ago #

    The traffic is reduce to 56 visitors at that time it shouldn't be a problem for WP Cron to handle.

  4. Lester Chan
    Member
    Plugin Author

    Posted 8 months ago #

    Install WP-Crontrol to check if WP-Polls cron job is there, it will run twice daily to check on the status of the poll which basically means every 12 hours once.

  5. Luís Peralta
    Member
    Posted 8 months ago #

    i saw some other users refering to the fact of polls not being activated when they should, nor being closed at a given time.

    yesterday, while configuring the plugin on my site, i did aswell faced this issue while testing this functionality.

    the issue is in fact on the cron settings setup on the plugin at function cron_polls_place in wp-polls.php.

    It is scheduled to run the plugin stuff two times per day, as Lester Chan just said. This means, that a poll scheduled to a given time will only get activated when the cron runs after that time. might take 1 minute. might take half a day.

    Since wordpress only comes with the options hourly, twicedaily or daily, to use in the wp_schedule_event function, and since i need the plugin to run when i want, i solved my issue editing functions.php, and added the following:

    add_filter( 'cron_schedules', 'cron_add_2min' );
    function cron_add_2min( $schedules ) {
     	// Adds once weekly to the existing schedules.
     	$schedules['weekly'] = array(
     		'interval' => 120,
     		'display' => __( 'two_mins' )
     	);
     	return $schedules;
    }

    This code gives me the ability to, on wp-polls.php, change the function cron_polls_place() to start using the arg 'two_mins' instead of the default 'twicedaily':

    function cron_polls_place() {
    	wp_clear_scheduled_hook('polls_cron');
    	if (!wp_next_scheduled('polls_cron')) {
    		wp_schedule_event(time(), 'two_mins', 'polls_cron');
    	}
    }

    Now i got the plugin getting updated once every 2 minutes.

    Of course, for some the option hourly would do just fine, while others can grab my code and edit it to run on a different interval, like 'interval' => 300 for an update every 5 minutes.

    ++info

    @Lester Chan: It would be nice to have this cron option available on the plugin admin page. At least with the default wordpress intervals.

  6. Lester Chan
    Member
    Plugin Author

    Posted 8 months ago #

    Actually that is a good idea, having the cron schedule as an option. Or maybe I should change it to every hour.

  7. Luís Peralta
    Member
    Posted 8 months ago #

    Every hour, i believe will be fine for the majority of the users. But having an option to make it run every 5min, 30min, 1hour, 12h, 24h etc. would be better.

    It could be even better to allow a user to type the seconds interval and have the plugin creating the custom schedule interval to use on the cron set up.

    Btw, my code above was wrong. Here's the corrected one:

    functions.php:

    add_filter( 'cron_schedules', 'cron_add_2min' );
    function cron_add_2min( $schedules ) {
     	// Adds once weekly to the existing schedules.
     	$schedules['2min'] = array(
     		'interval' => 120,
     		'display' => __( 'Every two minutes' )
     	);
     	return $schedules;
    }

    wp-polls.php:

    function cron_polls_place() {
    	wp_clear_scheduled_hook('polls_cron');
    	if (!wp_next_scheduled('polls_cron')) {
    		wp_schedule_event(time(), '2min', 'polls_cron');
    	}
    }
  8. Lester Chan
    Member
    Plugin Author

    Posted 8 months ago #

    No worries on the code, I have the code on my end as I am using it for my WP-DBManager

Reply

You must log in to post.

About this Plugin

About this Topic