public static function scheduler($atts = null, $content = null) { $atts = shortcode_atts(array('time' => 'all', 'days_week' => 'all', 'days_month' => 'all', 'months' => 'all', 'years' => 'all', 'alt' => ''), $atts, 'scheduler'); // Check time if ($atts['time'] !== 'all') { // Get current time $now = current_time('timestamp', 0); // Sanitize $atts['time'] = preg_replace("/[^0-9-,:]/", '', $atts['time']); // Loop time ranges foreach (explode(',', $atts['time']) as $range) { // Check for range symbol if (strpos($range, '-') === false) { return Su_Tools::error(__FUNCTION__, sprintf(__('Incorrect time range (%s). Please use - (minus) symbol to specify time range. Example: 14:00 - 18:00', 'su'), $range)); } // Split begin/end time $time = explode('-', $range); // Add minutes if (strpos($time[0], ':') === false) { $time[0] .= ':00'; } if (strpos($time[1], ':') === false) { $time[1] .= ':00'; } // Parse begin/end time $time[0] = strtotime($time[0]); $time[1] = strtotime($time[1]); // Check time if ($now < $time[0] || $now > $time[1]) { return $atts['alt']; } } } // Check day of the week if ($atts['days_week'] !== 'all') { // Get current day of the week $today = date('w', current_time('timestamp', 0)); // Sanitize input $atts['days_week'] = preg_replace("/[^0-9-,]/", '', $atts['days_week']); // Parse days range $days = Su_Tools::range($atts['days_week']); // Check current day if (!in_array($today, $days)) { return $atts['alt']; } } // Check day of the month if ($atts['days_month'] !== 'all') { // Get current day of the month $today = date('j', current_time('timestamp', 0)); // Sanitize input $atts['days_month'] = preg_replace("/[^0-9-,]/", '', $atts['days_month']); // Parse days range $days = Su_Tools::range($atts['days_month']); // Check current day if (!in_array($today, $days)) { return $atts['alt']; } } // Check month if ($atts['months'] !== 'all') { // Get current month $now = date('n', current_time('timestamp', 0)); // Sanitize input $atts['months'] = preg_replace("/[^0-9-,]/", '', $atts['months']); // Parse months range $months = Su_Tools::range($atts['months']); // Check current month if (!in_array($now, $months)) { return $atts['alt']; } } // Check year if ($atts['years'] !== 'all') { // Get current year $now = date('Y', current_time('timestamp', 0)); // Sanitize input $atts['years'] = preg_replace("/[^0-9-,]/", '', $atts['years']); // Parse years range $years = Su_Tools::range($atts['years']); // Check current year if (!in_array($now, $years)) { return $atts['alt']; } } // Return result (all check passed) return do_shortcode($content); }