$value) { // Call the Callback and Get the Result $result = call_user_func($callback, $value, $key, $input); // Key and Value Returned if (Arr::is($result)) { $k = $result[1]; $v = $result[0]; } // Only Value Returned else { $k = $key; $v = $result; } // Build Output $output[$k] = $v; } // Return Output return $output; } /** * Remove the array key prefixes * * @param mixed[] $input * @param string $toBeRemoved * @return mixed[] */ public static function unPrefix(array $input, string $toBeRemoved = 'daytidy_'): array { return Utils::map( $input, fn($value, $key) => [$value, str_replace($toBeRemoved, '', $key)] ); } /** * Remove useless information * * @param mixed[] $data * @return mixed[] */ public static function arrayTrim(array $data): array { // New Trimmed Array $trimmed = []; // Trim the Values foreach ($data as $key => $values) { // Remove Template Placeholders if (isset($values[':d:'])) unset($values[':d:']); // Add Trimmed Values $trimmed[$key] = is_array($values) ? self::arrayTrim($values) : $values; } return $trimmed; } /** * @param string $key * @param string|int $value * @return int */ public static function getIdByMeta(string $key, $value): int { // DB $db = new Db(); // Id return (int) $db->getVar($db->prepare( "SELECT `post_id` FROM `#__postmeta` WHERE `meta_key` = %s AND `meta_value` = %s ORDER BY `meta_id` ASC LIMIT 1", $key, (string) $value )); } /** * @param int $timestamp * @param int $time * @param string $interval * @param string $type * @return DateTime * @throws Exception */ public static function timeMachine(int $timestamp, int $time, string $interval, string $type = 'sub'): DateTime { // New DateTime $dt = (new DateTime())->setTimestamp($timestamp); // Travel Duration if ($interval === 'minutes') $duration = 'PT' . $time . 'M'; else if ($interval === 'hours') $duration = 'PT' . $time . 'H'; else $duration = 'P' . $time . 'D'; // Time Interval $i = new DateInterval($duration); // Travel if ($type === 'sub') $dt->sub($i); else $dt->add($i); // Return New DateTime return $dt; } public static function timeInPeriod(string $datetime, string $start = '', string $end = ''): bool { try { $dt = new DateTime($datetime); $st = new DateTime($start); $et = new DateTime($end); // Both Start & End if ($start && $end) return $dt->getTimestamp() >= $st->getTimestamp() && $dt->getTimestamp() <= $et->getTimestamp(); // Only Start else if ($start) return $dt->getTimestamp() >= $st->getTimestamp(); // Only End else if ($end) return $dt->getTimestamp() <= $et->getTimestamp(); // No Period else return true; } catch (Exception $e) { return false; } } public static function autoParagraph(string $text): string { // Auto Paragraph $text = wpautop(trim($text)); // Remove Empty Paragraph return preg_replace('#

#i', '', $text); } }