• Resolved Jehu

    (@jehu)


    The method used to define the cron_schedules appears to break other plugins that also define their own cron_schedules eg BackupWordPress, by not accepting the currently defined schedules as a parameter and adding to them.

    http://ww.wp.xz.cn/plugins/top-10/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ajay

    (@ajay)

    I’m not sure how exactly this overwriting takes place. The plugin defines a generic set of weekly, forthnightly and monthly.

    return array(
    		'weekly' => array('interval' => 604800, 'display' => __( 'Once Weekly', TPTN_LOCAL_NAME )),
    		'fortnightly' => array('interval' => 1209600, 'display' => __( 'Once Fortnightly', TPTN_LOCAL_NAME )),
    		'monthly' => array('interval' => 2419200, 'display' => __( 'Once Monthly', TPTN_LOCAL_NAME )),
    	);

    Can you provide me a link to BackupWordPress plugin you are referring to so I can see how they do it?

    Thread Starter Jehu

    (@jehu)

    In 3.5.2, the filters work by calling each of the defined functions in turn, passing the current result each time wp-includes\plugin.php

    do {
    		foreach( (array) current($wp_filter[$tag]) as $the_ )
    			if ( !is_null($the_['function']) ){
    				$args[1] = $value;
    				$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
    			}
    
    	} while ( next($wp_filter[$tag]) !== false );

    By appending to the current result you’ll not overwrite existing values

    function ald_more_reccurences( $schedules ) {
    /*	return array(
    		'weekly' => array('interval' => 604800, 'display' => __( 'Once Weekly', TPTN_LOCAL_NAME )),
    		'fortnightly' => array('interval' => 1209600, 'display' => __( 'Once Fortnightly', TPTN_LOCAL_NAME )),
    		'monthly' => array('interval' => 2419200, 'display' => __( 'Once Monthly', TPTN_LOCAL_NAME )),
    );
    */
    	$schedules['weekly'] = array('interval' => 604800, 'display' => __( 'Once Weekly', TPTN_LOCAL_NAME ));
    	$schedules['fortnightly'] = array('interval' => 1209600, 'display' => __( 'Once Fortnightly', TPTN_LOCAL_NAME ));
    	$schedules['monthly'] = array('interval' => 2419200, 'display' => __( 'Once Monthly', TPTN_LOCAL_NAME ));
    
    	return $schedules;
    
    }

    The plugin prefixes the key of the schedules it adds with hmbkp_ so that when it retrieves the schedules it can filter to the ones it uses.

    /**
    	 * Return an array of BackUpWordPress cron schedules
    	 *
    	 * @return array
    	 */
    	public function get_cron_schedules(){
    
    		$schedules = wp_get_schedules();
    
    		// remove any schedule whose key is not prefixed with 'hmbkp_'
    		foreach ( $schedules as $key => $arr ) {
    			if( ! preg_match("/^hmbkp_/", $key ) )
    				unset( $schedules[$key] );
    		}
    
    		return $schedules;
    	}
    Plugin Author Ajay

    (@ajay)

    Jehu,

    Understood now. I’ll modify the code to append the values and not overwrite it.

    Plugin Author Ajay

    (@ajay)

    I’ve released v1.9.9 which should fix this issue

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Plugin overwrites other plugin's cron_schedules’ is closed to new replies.