WordPress.org

Ready to get started?Download WordPress

Forums

BuddyPress Group Email Subscription
[resolved] Schedules hook bug (20 posts)

  1. Stefano Lissa
    Member
    Posted 3 years ago #

    Hi, the plugin uses the WordPress cron_schedules hook to add it's own Weekly schedule, but it does in the wrong way. Other plugin using the same hook but loaded before it have it's own schedules removed.

    The wrong code starts on line 356 of bp-activity-subscription-digest.php

    function ass_cron_add_weekly( $schedules ) {
        // note it looks like by returning just the value, we'd be replacing the filtered function, however the function does an array merge, so we return just what we want to add.
        return array(
            'weekly' => array( 'interval' => 604800, 'display' => __( 'Once Weekly', 'bp-ass' ) )
        );
    }

    and can be corrected this way:

    function ass_cron_add_weekly( $schedules ) {
    	// note it looks like by returning just the value, we'd be replacing the filtered function, however the function does an array merge, so we return just what we want to add.
    	$schedules['weekly'] = array( 'interval' => 604800, 'display' => __( 'Once Weekly', 'bp-ass' ) );
    return $schedules;
    }

    so the weekly schedule is added to other schedules that may have already added.

    Bye, Stefano.
    ps: I tried to find a way to write directly the authors, but there is not reference site for this plugin.

  2. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    we'll look into this. thanks for the post.

  3. gvvaughan
    Member
    Posted 3 years ago #

    After applying Stefano's fix to my copy of buddypress-group-email-subscription... WP Crontrol now shows half a dozen new cronjobs from other plugins which should have been there. I had been wondering why things had become flakey... but this seems to have fixed most of my ongoing problems with backups not working, emails not being sent etc.

    Please add this fix and make a new release of buddypress-group-email-subscription.

    Cheers,
    Gary

  4. gvvaughan
    Member
    Posted 3 years ago #

    double post... sorry

  5. gvvaughan
    Member
    Posted 3 years ago #

    I've just updated all my plugins, and it turns out that while this fix is in buddypress-group-email-subscription 2.7.3, neither it nor the patched 2.7.1 (according to the patch above) was ever fully working.

    This is a partial fix, as the first queued cron jobs from my other plugins appear to work, but none of the repeating jobs are ever requeued when I have buddypress-group-email-subscription activated. I only noticed this recently when my BeiFen backup emails, Broken Link checker emails, and others had not been working for a few weeks. Deactivating and reactivating the affected plugins with buddypress-group-email-subscription removed from the plugins directory appears to fix this issue, so I think there is still a bug in this plugin... if there's any more info I can give to help squash it, please feel free to ask.

  6. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    OK, i've made a change to the code so that I only add the weekly if it does not already exist.

    function ass_cron_add_weekly( $schedules ) {
    	if ( !isset( $schedules[ 'weekly' ] ) ) {
    		$schedules['weekly'] = array( 'interval' => 604800, 'display' => __( 'Once Weekly', 'bp-ass' ) );
    	}
    	return $schedules;
    }
    add_filter( 'cron_schedules', 'ass_cron_add_weekly' );

    try it and see if it works.

  7. gvvaughan
    Member
    Posted 3 years ago #

    Hi Dwenaus,

    Thanks for looking into this!

    Unfortunately that patch still doesn't seem to fix it. By running WP-Crontrol, I see the following schedules listed before I activate buddypress-group-email-subscription:

    Name         Interval                           Display Name
    mailer       300 (5 minutes)	                Mailer
    hourly       3600 (1 hour)                      Once Hourly
    twicedaily   43200 (12 hours)                   Twice Daily
    daily        86400 (1 day)                      Once Daily
    weekly       604800 (1 week)                    Once Weekly
    bimonthly    936000 (1 week 3 days)             Twice a Month

    And then when I check back after activating:

    Name         Interval                           Display Name
    hourly       3600 (1 hour)                      Once Hourly
    twicedaily   43200 (12 hours)                   Twice Daily
    daily        86400 (1 day)                      Once Daily
    weekly       604800 (1 week)                    Once Weekly

    If I deactivate bp-group-email-sub again, the missing bimonthly and mailer schedules reappear, but I need to deactivate and reactivate several other plugins to reinstate their jobs. I suppose (educated guess only tho!) that when those two schedules are lost for long enough that the currently active jobs come up for repeat, they are not requeued due to the missing schedules, which is why it seems that things continue to work for a while after activating bp-group-email-sub?

  8. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    i did't really follow your idea of why it didn't work. But perhaps I need to change the plugin so that the function only gets called when activating the plugin - like the other plugins do. Which plugin should I install to get the bi-monthly to work?
    (ps. I'm doing this for free, so any donation would be greatly appreciated (paypal deryk@bluemandala.com)

  9. gvvaughan
    Member
    Posted 3 years ago #

    Well, I'm just guessing as to the reasons why things are not working anyway... so there's a good chance that in addition to making no sense, I'm flat out wrong! :)

    The bimonthly schedule comes from broken link checker, and the mailer schedule comes from mailer. (I'm using the latest released versions of each of these).

    HTH. Thanks again for your help; I'll talk to my boss about organising a donation for your time.

  10. gvvaughan
    Member
    Posted 3 years ago #

    buddypress-group-email-subscription-2.7.5 still clobbers all other plugins' schedules when activated... if there's anything I can do to help you diagnose this please let me know.

    Reproducing it is very easy:

    1. Make a fresh and clean WordPress 3.0.1 and BuddyPress 1.2.6 installation;
    2. Copy this plugin to wp-content/plugins/bug.php and activate it in WordPress backend:
      <?php
      /*
         Plugin Name: Bug
      */
      function bug_cron ( $schedules ) {
          if( !isset( $schedules['bug'] ) ) {
              $schedules['bug'] = array( 'interval' => 4300, 'display' => 'Soon' );
          }
      }
      add_filter( 'cron_schedules', 'bug_cron' );
    3. install and activate any other plugin that installs its own cron schedule - broken link checker is a fine choice, but any other cron schedule using plugin reveals the bug too;
    4. Install and activate wp-crontrol plugin to observe the schedules;
    5. Go to Dashboard->Settings->Crontrol and note the presence of a bug schedule from the bug.php plugin above, and a bimonthly schedule from broken-link-checker. Neither of these plugins interferes with the other (or with various other cron using plugins I have), so I have no reason to suspect they are broken;
    6. Install and activate buddypress-group-email-subscription-plugin 2.7.5, then go back to Dashboard->Settings->Crontrol and notice that bug and bimonthly are both missing, leaving only the core schedules;
    7. Deactivate buddypress-group-email-subscription-plugin and notice that the missing schedules are available again.</i>

    Hope that helps you to squash this bug.

  11. gvvaughan
    Member
    Posted 3 years ago #

    Here is an implementation of ass_custom_digest_frequency from line 1224 of bp-activity-subscription-functions.php in buddypress-group-email-subscription version 2.7.5, which fixes the schedule clobbering bug:

    function ass_custom_digest_frequency( $schedules ) {
        if( ( $freq = get_option(  'ass_digest_frequency' ) ) ) {
            if( !isset( $schedules[$freq.'_hrs'] ) ) {
                $schedules[$freq.'_hrs'] = array( 'interval' => $freq * 3600, 'display' => "Every $freq hours" );
            }
        }
    
        return $schedules;
    }
  12. Stefano Lissa
    Member
    Posted 3 years ago #

    Hi everyone, I see we are still here discussing about schedules. Schedules other than the default ones must be added on plugin initialization not only on plugin activation.

    Schedules must added using the FILTER cron_schedules. It is a FILTER so the associated function RECEIVES some data, MODIFIES it and RETURNS it.

    The bug plugin example above does not return the new modified schedules so it creates the error. Other kind of error using filters is to return a completely new array without taking in consideration what we have in input.

    I hope this can be of any help.

    Bye, Stefano.

  13. gvvaughan
    Member
    Posted 3 years ago #

    Hi Stefano,

    Oops, you're right I made a cut-n-paste error when I copied the Bug plugin earlier, and somehow deleted the return $schedules line. Not that it matters now, since I found the other instance of broken cron schedule use in buddypress-group-email-subscription plugin, and applied the same fix that you posted at the start of this thread in my last message here.

    For the record, incase anyone wants to verify that buddypress-group-email-subscription 2.7.5 clobbers other schedules without the patch, here is the correct bug.php contents:

    <?php
    /*
       Plugin Name: Bug
    */
    function bug_cron ( $schedules ) {
        if( !isset( $schedules['bug'] ) ) {
            $schedules['bug'] = array( 'interval' => 4300, 'display' => 'Soon' );
        }
        return $schedules;
    }
    add_filter( 'cron_schedules', 'bug_cron' );

    I hope this makes it into the next release, and we finally have a version of the plugin that works properly with Mailer, Newsletter Pro, Broken Link Checker and others!

  14. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    @satollo or @gvvaughan would either of you be so kind as to suggest some code to solve this problem. I don't have the time to fix it now. I think satollo has the right solution in his last post.

  15. gvvaughan
    Member
    Posted 3 years ago #

    Hi Dwenaus,

    I posted the fix already, and it is working well for me on both my blogs.

    Cheers,
    Gary

  16. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    yes, but where is ass_digest_frequency set?

  17. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    aha! I was looking in the wrong file. that function should not even exist!!! I will either implement your solution in the next update or delete that function altogether. thanks.

  18. gvvaughan
    Member
    Posted 3 years ago #

    I have no idea... I'm far from familiar with the implementation of this plugin; maybe this function is even dead code at this point (except of course that even if it doesn't do anything useful anymore, it still breaks other cron using plugins in its current form)?

    The particular bug fixed by this revised function definition is simply to not clobber all the other schedules by throwing them away during the filtering process (compare to the implementation in 2.7.5 as shipped (copied below), which as you can see not only discards the contents of $schedules that wordpress passes in, but then returns either an empty array in the worst case, or an entirely new array with just its own schedule):

    function ass_custom_digest_frequency() {
        if ( !$freq = get_option( 'ass_digest_frequency' ) )
            return array();
    
        return array(
            $freq . '_hrs' => array('interval' => $freq * 3600, 'display' => "Every $freq hours" )
        );
    }                                                                                                                                 add_filter( 'cron_schedules', 'ass_custom_digest_frequency' );

    If ass_digest_frequency is no longer used, or even if this function now represents entirely dead code, then by all means remove it or fix any other bugs that it is also responsible for. I personally don't use the digest functionality, and am merely happy to make a minimally intrusive correction to the code so that activating buddypress-group-email-subscription doesn't break all my other wp-cron using plugins.

    Cheers,
    Gary

  19. gvvaughan
    Member
    Posted 3 years ago #

    Excellent. Thank you :)

  20. Dwenaus
    Member
    Plugin Author

    Posted 3 years ago #

    it was dead code. so i've left your solution in there for future reference if we ever need to do a flexible schedule, but i've commented it out. it is now up as versino 2.7.6.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic