Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
TaskManagerSchedules
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 init
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 add_schedules
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace NewfoldLabs\WP\Module\Installer\TaskManagers;
4
5/**
6 * Class TaskManagerSchedules
7 */
8abstract class TaskManagerSchedules {
9
10    /**
11     * Init the Task Manager Schedules class
12     */
13    public static function init() {
14        static $initialized = false;
15
16        if ( ! $initialized ) {
17            add_filter( 'cron_schedules', array( __CLASS__, 'add_schedules' ) );
18        }
19    }
20
21    /**
22     * Adds a task manager cron schedule.
23     *
24     * @param array $schedules The existing cron schedule.
25     * @return array
26     */
27    public static function add_schedules( $schedules ) {
28        $schedules_to_add = array(
29            'thirty_seconds' => array(
30                'interval' => 30,
31                'display'  => __( 'Once Every Thirty Seconds', 'wp-module-installer' ),
32            ),
33            'ten_seconds'    => array(
34                'interval' => 10,
35                'display'  => __( 'Once Every Ten Seconds', 'wp-module-installer' ),
36            ),
37        );
38
39        foreach ( $schedules_to_add as $schedule_slug => $schedule_data ) {
40            if ( ! array_key_exists( $schedule_slug, $schedules ) || $schedule_data['interval'] !== $schedules[ $schedule_slug ]['interval'] ) {
41                $schedules[ $schedule_slug ] = $schedule_data;
42            }
43        }
44
45        return $schedules;
46    }
47}