Support » Plugin: BuddyPress Group Email Subscription » [Plugin: BuddyPress Group Email Subscription] Schedules hook bug

  • Resolved Stefano Lissa

    (@satollo)


    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.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Dwenaus

    (@dwenaus)

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

    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

    double post… sorry

    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.

    Plugin Author Dwenaus

    (@dwenaus)

    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.

    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?

    Plugin Author Dwenaus

    (@dwenaus)

    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)

    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.

    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.

    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;
    }

    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.

    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!

    Plugin Author Dwenaus

    (@dwenaus)

    @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.

    Hi Dwenaus,

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

    Cheers,
    Gary

    Plugin Author Dwenaus

    (@dwenaus)

    yes, but where is ass_digest_frequency set?

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: BuddyPress Group Email Subscription] Schedules hook bug’ is closed to new replies.