1000000) { return floor($x / 1000000) . 'M'; } if ($x > 10000) { return floor($x / 1000) . 'k'; } return $x; } public static function get_site_domain() { return str_ireplace('www.', '', (string) wp_parse_url(home_url() ?? '', PHP_URL_HOST)); } public static function human_readable_num($size) { $l = substr($size, -1); $ret = substr($size, 0, -1); switch (strtoupper($l)) { case 'P': $ret *= 1024; case 'T': $ret *= 1024; case 'G': $ret *= 1024; case 'M': $ret *= 1024; case 'K': $ret *= 1024; } return $ret; } public static function array_flatten($array) { if (!is_array($array)) { return false; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = $value[0]; } else { $result[$key] = $value; } } return $result; } public static function hex2rgb_array($hex) { $hex = str_replace('#', '', $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1)); $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } $rgb = array($r, $g, $b); return $rgb; } public static function hex2Rgb($hex, $alpha = false) { $hex = str_replace('#', '', $hex); $length = strlen($hex); $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0)); $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0)); $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0)); if ($alpha) { $rgb['a'] = $alpha; } return $rgb; } public static function image_filter_gallery_categories($gallery_items) { if (!is_array($gallery_items)) { return false; } $gallery_category_names = array(); $gallery_category_names_final = array(); foreach ($gallery_items as $gallery_item) { $gallery_category_names[] = $gallery_item['gallery_category_name']; } if (is_array($gallery_category_names) && !empty($gallery_category_names)) { foreach ($gallery_category_names as $gallery_category_name) { $gallery_category_names_final[] = explode(',', $gallery_category_name); } } if (is_array($gallery_category_names_final) && !empty($gallery_category_names_final)) { $gallery_category_names_final = self::image_filter_gallery_array_flatten($gallery_category_names_final); return array_unique(array_filter($gallery_category_names_final)); } } public static function image_filter_gallery_category_classes($gallery_classes, $id) { if (!($gallery_classes)) { return false; } $gallery_cat_classes = array(); $gallery_classes = explode(',', $gallery_classes); if (is_array($gallery_classes) && !empty($gallery_classes)) { foreach ($gallery_classes as $gallery_class) { $gallery_cat_classes[] = sanitize_title($gallery_class) . '-' . $id; } } return implode(' ', $gallery_cat_classes); } public static function image_filter_gallery_categories_parts($gallery_classes) { if (!($gallery_classes)) { return false; } $gallery_cat_classes = array(); $gallery_classes = explode(',', $gallery_classes); if (is_array($gallery_classes) && !empty($gallery_classes)) { foreach ($gallery_classes as $gallery_class) { $gallery_cat_classes[] = '