GIF89a;
Priv8 Uploader By InMyMine7
Linux server.abcbiz.in 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
<?php
if (!defined('ABSPATH')) {
die('-1');
}
require ABSPATH . WPINC . '/option.php';
function mysql2date($format, $date, $translate = true)
{
if (empty($date)) {
return false;
}
$timezone = wp_timezone();
$datetime = date_create($date, $timezone);
if (false === $datetime) {
return false;
}
if ('G' === $format || 'U' === $format) {
return $datetime->getTimestamp() + $datetime->getOffset();
}
if ($translate) {
return wp_date($format, $datetime->getTimestamp(), $timezone);
}
return $datetime->format($format);
}
function current_time($type, $gmt = 0)
{
if ('timestamp' === $type || 'U' === $type) {
return $gmt ? time() : time() + (int) ((float) get_option('gmt_offset') * HOUR_IN_SECONDS);
}
if ('mysql' === $type) {
$type = 'Y-m-d H:i:s';
}
$timezone = $gmt ? new DateTimeZone('UTC') : wp_timezone();
$datetime = new DateTime('now', $timezone);
return $datetime->format($type);
}
function current_datetime()
{
return new DateTimeImmutable('now', wp_timezone());
}
function wp_timezone_string()
{
$timezone_string = get_option('timezone_string');
if ($timezone_string) {
return $timezone_string;
}
$offset = (float) get_option('gmt_offset');
$hours = (int) $offset;
$minutes = $offset - $hours;
$sign = $offset < 0 ? '-' : '+';
$abs_hour = abs($hours);
$abs_mins = abs($minutes * 60);
$tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins);
return $tz_offset;
}
function wp_timezone()
{
return new DateTimeZone(wp_timezone_string());
}
function date_i18n($format, $timestamp_with_offset = false, $gmt = false)
{
$timestamp = $timestamp_with_offset;
if (!is_numeric($timestamp)) {
$timestamp = current_time('timestamp', $gmt);
}
if ('U' === $format) {
$date = $timestamp;
} elseif ($gmt && false === $timestamp_with_offset) {
$date = wp_date($format, null, new DateTimeZone('UTC'));
} elseif (false === $timestamp_with_offset) {
$date = wp_date($format);
} else {
$local_time = gmdate('Y-m-d H:i:s', $timestamp);
$timezone = wp_timezone();
$datetime = date_create($local_time, $timezone);
$date = wp_date($format, $datetime->getTimestamp(), $timezone);
}
$date = apply_filters('date_i18n', $date, $format, $timestamp, $gmt);
return $date;
}
function wp_date($format, $timestamp = null, $timezone = null)
{
global $wp_locale;
if (null === $timestamp) {
$timestamp = time();
} elseif (!is_numeric($timestamp)) {
return false;
}
if (!$timezone) {
$timezone = wp_timezone();
}
$datetime = date_create('@' . $timestamp);
$datetime->setTimezone($timezone);
if (empty($wp_locale->month) || empty($wp_locale->weekday)) {
$date = $datetime->format($format);
} else {
$format = preg_replace('/(?<!\\\\)r/', DATE_RFC2822, $format);
$new_format = '';
$format_length = strlen($format);
$month = $wp_locale->get_month($datetime->format('m'));
$weekday = $wp_locale->get_weekday($datetime->format('w'));
for ($i = 0; $i < $format_length; $i++) {
switch ($format[$i]) {
case 'D':
$new_format .= addcslashes($wp_locale->get_weekday_abbrev($weekday), '\\A..Za..z');
break;
case 'F':
$new_format .= addcslashes($month, '\\A..Za..z');
break;
case 'l':
$new_format .= addcslashes($weekday, '\\A..Za..z');
break;
case 'M':
$new_format .= addcslashes($wp_locale->get_month_abbrev($month), '\\A..Za..z');
break;
case 'a':
$new_format .= addcslashes($wp_locale->get_meridiem($datetime->format('a')), '\\A..Za..z');
break;
case 'A':
$new_format .= addcslashes($wp_locale->get_meridiem($datetime->format('A')), '\\A..Za..z');
break;
case '\\':
$new_format .= $format[$i];
if ($i < $format_length) {
$new_format .= $format[++$i];
}
break;
default:
$new_format .= $format[$i];
break;
}
}
$date = $datetime->format($new_format);
$date = wp_maybe_decline_date($date, $format);
}
$date = apply_filters('wp_date', $date, $format, $timestamp, $timezone);
return $date;
}
function wp_maybe_decline_date($date, $format = '')
{
global $wp_locale;
if (!function_exists('_x')) {
return $date;
}
if ('on' === _x('off', 'decline months names: on or off')) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
if ($format) {
$decline = preg_match('#[dj]\\.? F#', $format);
} else {
$decline = preg_match('#\\b\\d{1,2}\\.? [^\\d ]+\\b#u', $date);
}
if ($decline) {
foreach ($months as $key => $month) {
$months[$key] = '# ' . preg_quote($month, '#') . '\\b#u';
}
foreach ($months_genitive as $key => $month) {
$months_genitive[$key] = ' ' . $month;
}
$date = preg_replace($months, $months_genitive, $date);
}
if ($format) {
$decline = preg_match('#F [dj]#', $format);
} else {
$decline = preg_match('#\\b[^\\d ]+ \\d{1,2}(st|nd|rd|th)?\\b#u', trim($date));
}
if ($decline) {
foreach ($months as $key => $month) {
$months[$key] = '#\\b' . preg_quote($month, '#') . ' (\\d{1,2})(st|nd|rd|th)?([-–]\\d{1,2})?(st|nd|rd|th)?\\b#u';
}
foreach ($months_genitive as $key => $month) {
$months_genitive[$key] = '$1$3 ' . $month;
}
$date = preg_replace($months, $months_genitive, $date);
}
}
$locale = get_locale();
if ('ca' === $locale) {
$date = preg_replace('# de ([ao])#i', " d'\\1", $date);
}
return $date;
}
function number_format_i18n($number, $decimals = 0)
{
global $wp_locale;
if (isset($wp_locale)) {
$formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
} else {
$formatted = number_format($number, absint($decimals));
}
return apply_filters('number_format_i18n', $formatted, $number, $decimals);
}
function size_format($bytes, $decimals = 0)
{
$quant = array(_x('YB', 'unit symbol') => YB_IN_BYTES, _x('ZB', 'unit symbol') => ZB_IN_BYTES, _x('EB', 'unit symbol') => EB_IN_BYTES, _x('PB', 'unit symbol') => PB_IN_BYTES, _x('TB', 'unit symbol') => TB_IN_BYTES, _x('GB', 'unit symbol') => GB_IN_BYTES, _x('MB', 'unit symbol') => MB_IN_BYTES, _x('KB', 'unit symbol') => KB_IN_BYTES, _x('B', 'unit symbol') => 1);
if (0 === $bytes) {
return number_format_i18n(0, $decimals) . ' ' . _x('B', 'unit symbol');
}
foreach ($quant as $unit => $mag) {
if ((float) $bytes >= $mag) {
return number_format_i18n($bytes / $mag, $decimals) . ' ' . $unit;
}
}
return false;
}
function human_readable_duration($duration = '')
{
if (empty($duration) || !is_string($duration)) {
return false;
}
$duration = trim($duration);
if (str_starts_with($duration, '-')) {
$duration = substr($duration, 1);
}
$duration_parts = array_reverse(explode(':', $duration));
$duration_count = count($duration_parts);
$hour = null;
$minute = null;
$second = null;
if (3 === $duration_count) {
if (!(bool) preg_match('/^([0-9]+):([0-5]?[0-9]):([0-5]?[0-9])$/', $duration)) {
return false;
}
list($second, $minute, $hour) = $duration_parts;
} elseif (2 === $duration_count) {
if (!(bool) preg_match('/^([0-5]?[0-9]):([0-5]?[0-9])$/', $duration)) {
return false;
}
list($second, $minute) = $duration_parts;
} else {
return false;
}
$human_readable_duration = array();
if (is_numeric($hour)) {
$human_readable_duration[] = sprintf(_n('%s hour', '%s hours', $hour), (int) $hour);
}
if (is_numeric($minute)) {
$human_readable_duration[] = sprintf(_n('%s minute', '%s minutes', $minute), (int) $minute);
}
if (is_numeric($second)) {
$human_readable_duration[] = sprintf(_n('%s second', '%s seconds', $second), (int) $second);
}
return implode(', ', $human_readable_duration);
}
function get_weekstartend($mysqlstring, $start_of_week = '')
{
$my = substr($mysqlstring, 0, 4);
$mm = substr($mysqlstring, 8, 2);
$md = substr($mysqlstring, 5, 2);
$day = mktime(0, 0, 0, $md, $mm, $my);
$weekday = (int) gmdate('w', $day);
if (!is_numeric($start_of_week)) {
$start_of_week = (int) get_option('start_of_week');
}
if ($weekday < $start_of_week) {
$weekday += 7;
}
$start = $day - DAY_IN_SECONDS * ($weekday - $start_of_week);
$end = $start + WEEK_IN_SECONDS - 1;
return compact('start', 'end');
}
function maybe_serialize($data)
{
if (is_array($data) || is_object($data)) {
return serialize($data);
}
if (is_serialized($data, false)) {
return serialize($data);
}
return $data;
}
function maybe_unserialize($data)
{
if (is_serialized($data)) {
return @unserialize(trim($data));
}
return $data;
}
function is_serialized($data, $strict = true)
{
if (!is_string($data)) {
return false;
}
$data = trim($data);
if ('N;' === $data) {
return true;
}
if (strlen($data) < 4) {
return false;
}
if (':' !== $data[1]) {
return false;
}
if ($strict) {
$lastc = substr($data, -1);
if (';' !== $lastc && '}' !== $lastc) {
return false;
}
} else {
$semicolon = strpos($data, ';');
$brace = strpos($data, '}');
if (false === $semicolon && false === $brace) {
return false;
}
if (false !== $semicolon && $semicolon < 3) {
return false;
}
if (false !== $brace && $brace < 4) {
return false;
}
}
$token = $data[0];
switch ($token) {
case 's':
if ($strict) {
if ('"' !== substr($data, -2, 1)) {
return false;
}
} elseif (!str_contains($data, '"')) {
return false;
}
case 'a':
case 'O':
case 'E':
return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
case 'b':
case 'i':
case 'd':
$end = $strict ? '$' : '';
return (bool) preg_match("/^{$token}:[0-9.E+-]+;{$end}/", $data);
}
return false;
}
function is_serialized_string($data)
{
if (!is_string($data)) {
return false;
}
$data = trim($data);
if (strlen($data) < 4) {
return false;
} elseif (':' !== $data[1]) {
return false;
} elseif (!str_ends_with($data, ';')) {
return false;
} elseif ('s' !== $data[0]) {
return false;
} elseif ('"' !== substr($data, -2, 1)) {
return false;
} else {
return true;
}
}
function xmlrpc_getposttitle($content)
{
global $post_default_title;
if (preg_match('/<title>(.+?)<\\/title>/is', $content, $matchtitle)) {
$post_title = $matchtitle[1];
} else {
$post_title = $post_default_title;
}
return $post_title;
}
function xmlrpc_getpostcategory($content)
{
global $post_default_category;
if (preg_match('/<category>(.+?)<\\/category>/is', $content, $matchcat)) {
$post_category = trim($matchcat[1], ',');
$post_category = explode(',', $post_category);
} else {
$post_category = $post_default_category;
}
return $post_category;
}
function xmlrpc_removepostdata($content)
{
$content = preg_replace('/<title>(.+?)<\\/title>/si', '', $content);
$content = preg_replace('/<category>(.+?)<\\/category>/si', '', $content);
$content = trim($content);
return $content;
}
function wp_extract_urls($content)
{
preg_match_all("#([\"']?)(" . '(?:([\\w-]+:)?//?)' . '[^\\s()<>]+' . '[.]' . '(?:' . '\\([\\w\\d]+\\)|' . '(?:' . "[^`!()\\[\\]{}:'\".,<>«»“”‘’\\s]|" . '(?:[:]\\d+)?/?' . ')+' . ')' . ")\\1#", $content, $post_links);
$post_links = array_unique(array_map(static function ($link) {
$link = html_entity_decode($link);
return str_replace(';', '', $link);
}, $post_links[2]));
return array_values($post_links);
}
function do_enclose($content, $post)
{
global $wpdb;
require_once ABSPATH . WPINC . '/class-IXR.php';
$post = get_post($post);
if (!$post) {
return false;
}
if (null === $content) {
$content = $post->post_content;
}
$post_links = array();
$pung = get_enclosed($post->ID);
$post_links_temp = wp_extract_urls($content);
foreach ($pung as $link_test) {
if (!in_array($link_test, $post_links_temp, true)) {
$mids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like($link_test) . '%'));
foreach ($mids as $mid) {
delete_metadata_by_mid('post', $mid);
}
}
}
foreach ((array) $post_links_temp as $link_test) {
if (!in_array($link_test, $pung, true)) {
$test = parse_url($link_test);
if (false === $test) {
continue;
}
if (isset($test['query'])) {
$post_links[] = $link_test;
} elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
$post_links[] = $link_test;
}
}
}
$post_links = apply_filters('enclosure_links', $post_links, $post->ID);
foreach ((array) $post_links as $url) {
$url = strip_fragment_from_url($url);
if ('' !== $url && !$wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like($url) . '%'))) {
$headers = wp_get_http_headers($url);
if ($headers) {
$len = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0;
$type = isset($headers['Content-Type']) ? $headers['Content-Type'] : '';
$allowed_types = array('video', 'audio');
$url_parts = parse_url($url);
if (false !== $url_parts && !empty($url_parts['path'])) {
$extension = pathinfo($url_parts['path'], PATHINFO_EXTENSION);
if (!empty($extension)) {
foreach (wp_get_mime_types() as $exts => $mime) {
if (preg_match('!^(' . $exts . ')$!i', $extension)) {
$type = $mime;
break;
}
}
}
}
if (in_array(substr($type, 0, strpos($type, '/')), $allowed_types, true)) {
add_post_meta($post->ID, 'enclosure', "{$url}\n{$len}\n{$mime}\n");
}
}
}
}
}
function wp_get_http_headers($url, $deprecated = false)
{
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '2.7.0');
}
$response = wp_safe_remote_head($url);
if (is_wp_error($response)) {
return false;
}
return wp_remote_retrieve_headers($response);
}
function is_new_day()
{
global $currentday, $previousday;
if ($currentday !== $previousday) {
return 1;
} else {
return 0;
}
}
function build_query($data)
{
return _http_build_query($data, null, '&', '', false);
}
function _http_build_query($data, $prefix = null, $sep = null, $key = '', $urlencode = true)
{
$ret = array();
foreach ((array) $data as $k => $v) {
if ($urlencode) {
$k = urlencode($k);
}
if (is_int($k) && null !== $prefix) {
$k = $prefix . $k;
}
if (!empty($key)) {
$k = $key . '%5B' . $k . '%5D';
}
if (null === $v) {
continue;
} elseif (false === $v) {
$v = '0';
}
if (is_array($v) || is_object($v)) {
array_push($ret, _http_build_query($v, '', $sep, $k, $urlencode));
} elseif ($urlencode) {
array_push($ret, $k . '=' . urlencode($v));
} else {
array_push($ret, $k . '=' . $v);
}
}
if (null === $sep) {
$sep = ini_get('arg_separator.output');
}
return implode($sep, $ret);
}
function add_query_arg(...$args)
{
if (is_array($args[0])) {
if (count($args) < 2 || false === $args[1]) {
$uri = $_SERVER['REQUEST_URI'];
} else {
$uri = $args[1];
}
} else {
if (count($args) < 3 || false === $args[2]) {
$uri = $_SERVER['REQUEST_URI'];
} else {
$uri = $args[2];
}
}
$frag = strstr($uri, '#');
if ($frag) {
$uri = substr($uri, 0, -strlen($frag));
} else {
$frag = '';
}
if (0 === stripos($uri, 'http://')) {
$protocol = 'http://';
$uri = substr($uri, 7);
} elseif (0 === stripos($uri, 'https://')) {
$protocol = 'https://';
$uri = substr($uri, 8);
} else {
$protocol = '';
}
if (str_contains($uri, '?')) {
list($base, $query) = explode('?', $uri, 2);
$base .= '?';
} elseif ($protocol || !str_contains($uri, '=')) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str($query, $qs);
$qs = urlencode_deep($qs);
if (is_array($args[0])) {
foreach ($args[0] as $k => $v) {
$qs[$k] = $v;
}
} else {
$qs[$args[0]] = $args[1];
}
foreach ($qs as $k => $v) {
if (false === $v) {
unset($qs[$k]);
}
}
$ret = build_query($qs);
$ret = trim($ret, '?');
$ret = preg_replace('#=(&|$)#', '$1', $ret);
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim($ret, '?');
$ret = str_replace('?#', '#', $ret);
return $ret;
}
function remove_query_arg($key, $query = false)
{
if (is_array($key)) {
foreach ($key as $k) {
$query = add_query_arg($k, false, $query);
}
return $query;
}
return add_query_arg($key, false, $query);
}
function wp_removable_query_args()
{
$removable_query_args = array('activate', 'activated', 'admin_email_remind_later', 'approved', 'core-major-auto-updates-saved', 'deactivate', 'delete_count', 'deleted', 'disabled', 'doing_wp_cron', 'enabled', 'error', 'hotkeys_highlight_first', 'hotkeys_highlight_last', 'ids', 'locked', 'message', 'same', 'saved', 'settings-updated', 'skipped', 'spammed', 'trashed', 'unspammed', 'untrashed', 'update', 'updated', 'wp-post-new-reload');
return apply_filters('removable_query_args', $removable_query_args);
}
function add_magic_quotes($input_array)
{
foreach ((array) $input_array as $k => $v) {
if (is_array($v)) {
$input_array[$k] = add_magic_quotes($v);
} elseif (is_string($v)) {
$input_array[$k] = addslashes($v);
}
}
return $input_array;
}
function wp_remote_fopen($uri)
{
$parsed_url = parse_url($uri);
if (!$parsed_url || !is_array($parsed_url)) {
return false;
}
$options = array();
$options['timeout'] = 10;
$response = wp_safe_remote_get($uri, $options);
if (is_wp_error($response)) {
return false;
}
return wp_remote_retrieve_body($response);
}
function wp($query_vars = '')
{
global $wp, $wp_query, $wp_the_query;
$wp->main($query_vars);
if (!isset($wp_the_query)) {
$wp_the_query = $wp_query;
}
}
function get_status_header_desc($code)
{
global $wp_header_to_desc;
$code = absint($code);
if (!isset($wp_header_to_desc)) {
$wp_header_to_desc = array(100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 103 => 'Early Hints', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 226 => 'IM Used', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 421 => 'Misdirected Request', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Too Early', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 510 => 'Not Extended', 511 => 'Network Authentication Required');
}
if (isset($wp_header_to_desc[$code])) {
return $wp_header_to_desc[$code];
} else {
return '';
}
}
function status_header($code, $description = '')
{
if (!$description) {
$description = get_status_header_desc($code);
}
if (empty($description)) {
return;
}
$protocol = wp_get_server_protocol();
$status_header = "{$protocol} {$code} {$description}";
if (function_exists('apply_filters')) {
$status_header = apply_filters('status_header', $status_header, $code, $description, $protocol);
}
if (!headers_sent()) {
header($status_header, true, $code);
}
}
function wp_get_nocache_headers()
{
$cache_control = 'no-cache, must-revalidate, max-age=0, no-store, private';
$headers = array('Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', 'Cache-Control' => $cache_control);
if (function_exists('apply_filters')) {
$headers = (array) apply_filters('nocache_headers', $headers);
}
$headers['Last-Modified'] = false;
return $headers;
}
function nocache_headers()
{
if (headers_sent()) {
return;
}
$headers = wp_get_nocache_headers();
unset($headers['Last-Modified']);
header_remove('Last-Modified');
foreach ($headers as $name => $field_value) {
header("{$name}: {$field_value}");
}
}
function cache_javascript_headers()
{
$expires_offset = 10 * DAY_IN_SECONDS;
header('Content-Type: text/javascript; charset=' . get_bloginfo('charset'));
header('Vary: Accept-Encoding');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires_offset) . ' GMT');
}
function get_num_queries()
{
global $wpdb;
return $wpdb->num_queries;
}
function bool_from_yn($yn)
{
return 'y' === strtolower($yn);
}
function do_feed()
{
global $wp_query;
$feed = get_query_var('feed');
$feed = preg_replace('/^_+/', '', $feed);
if ('' === $feed || 'feed' === $feed) {
$feed = get_default_feed();
}
if (!has_action("do_feed_{$feed}")) {
wp_die(__('<strong>Error:</strong> This is not a valid feed template.'), '', array('response' => 404));
}
do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}
function do_feed_rdf()
{
load_template(ABSPATH . WPINC . '/feed-rdf.php');
}
function do_feed_rss()
{
load_template(ABSPATH . WPINC . '/feed-rss.php');
}
function do_feed_rss2($for_comments)
{
if ($for_comments) {
load_template(ABSPATH . WPINC . '/feed-rss2-comments.php');
} else {
load_template(ABSPATH . WPINC . '/feed-rss2.php');
}
}
function do_feed_atom($for_comments)
{
if ($for_comments) {
load_template(ABSPATH . WPINC . '/feed-atom-comments.php');
} else {
load_template(ABSPATH . WPINC . '/feed-atom.php');
}
}
function do_robots()
{
header('Content-Type: text/plain; charset=utf-8');
do_action('do_robotstxt');
$output = "User-agent: *\n";
$public = (bool) get_option('blog_public');
$site_url = parse_url(site_url());
$path = !empty($site_url['path']) ? $site_url['path'] : '';
$output .= "Disallow: {$path}/wp-admin/\n";
$output .= "Allow: {$path}/wp-admin/admin-ajax.php\n";
echo apply_filters('robots_txt', $output, $public);
}
function do_favicon()
{
do_action('do_faviconico');
wp_redirect(get_site_icon_url(32, includes_url('images/w-logo-blue-white-bg.png')));
exit;
}
function is_blog_installed()
{
global $wpdb;
if (wp_cache_get('is_blog_installed')) {
return true;
}
$suppress = $wpdb->suppress_errors();
if (!wp_installing()) {
$alloptions = wp_load_alloptions();
}
if (!isset($alloptions['siteurl'])) {
$installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'");
} else {
$installed = $alloptions['siteurl'];
}
$wpdb->suppress_errors($suppress);
$installed = !empty($installed);
wp_cache_set('is_blog_installed', $installed);
if ($installed) {
return true;
}
if (defined('WP_REPAIRING')) {
return true;
}
$suppress = $wpdb->suppress_errors();
$wp_tables = $wpdb->tables();
foreach ($wp_tables as $table) {
if (defined('CUSTOM_USER_TABLE') && CUSTOM_USER_TABLE === $table) {
continue;
}
if (defined('CUSTOM_USER_META_TABLE') && CUSTOM_USER_META_TABLE === $table) {
continue;
}
$described_table = $wpdb->get_results("DESCRIBE {$table};");
if (!$described_table && empty($wpdb->last_error) || is_array($described_table) && 0 === count($described_table)) {
continue;
}
wp_load_translations_early();
$wpdb->error = sprintf(__('One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.'), 'maint/repair.php?referrer=is_blog_installed');
dead_db();
}
$wpdb->suppress_errors($suppress);
wp_cache_set('is_blog_installed', false);
return false;
}
function wp_nonce_url($actionurl, $action = -1, $name = '_wpnonce')
{
$actionurl = str_replace('&', '&', $actionurl);
return esc_html(add_query_arg($name, wp_create_nonce($action), $actionurl));
}
function wp_nonce_field($action = -1, $name = '_wpnonce', $referer = true, $display = true)
{
$name = esc_attr($name);
$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce($action) . '" />';
if ($referer) {
$nonce_field .= wp_referer_field(false);
}
if ($display) {
echo $nonce_field;
}
return $nonce_field;
}
function wp_referer_field($display = true)
{
$request_url = remove_query_arg('_wp_http_referer');
$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_url($request_url) . '" />';
if ($display) {
echo $referer_field;
}
return $referer_field;
}
function wp_original_referer_field($display = true, $jump_back_to = 'current')
{
$ref = wp_get_original_referer();
if (!$ref) {
$ref = 'previous' === $jump_back_to ? wp_get_referer() : wp_unslash($_SERVER['REQUEST_URI']);
}
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr($ref) . '" />';
if ($display) {
echo $orig_referer_field;
}
return $orig_referer_field;
}
function wp_get_referer()
{
if (!function_exists('wp_validate_redirect')) {
return false;
}
$ref = wp_get_raw_referer();
if ($ref && wp_unslash($_SERVER['REQUEST_URI']) !== $ref && home_url() . wp_unslash($_SERVER['REQUEST_URI']) !== $ref) {
return wp_validate_redirect($ref, false);
}
return false;
}
function wp_get_raw_referer()
{
if (!empty($_REQUEST['_wp_http_referer']) && is_string($_REQUEST['_wp_http_referer'])) {
return wp_unslash($_REQUEST['_wp_http_referer']);
} elseif (!empty($_SERVER['HTTP_REFERER'])) {
return wp_unslash($_SERVER['HTTP_REFERER']);
}
return false;
}
function wp_get_original_referer()
{
if (!function_exists('wp_validate_redirect')) {
return false;
}
if (!empty($_REQUEST['_wp_original_http_referer'])) {
return wp_validate_redirect(wp_unslash($_REQUEST['_wp_original_http_referer']), false);
}
return false;
}
function wp_mkdir_p($target)
{
$wrapper = null;
if (wp_is_stream($target)) {
list($wrapper, $target) = explode('://', $target, 2);
}
$target = str_replace('//', '/', $target);
if (null !== $wrapper) {
$target = $wrapper . '://' . $target;
}
$target = rtrim($target, '/');
if (empty($target)) {
$target = '/';
}
if (file_exists($target)) {
return @is_dir($target);
}
if (str_contains($target, '../') || str_contains($target, '..' . DIRECTORY_SEPARATOR)) {
return false;
}
$target_parent = dirname($target);
while ('.' !== $target_parent && !is_dir($target_parent) && dirname($target_parent) !== $target_parent) {
$target_parent = dirname($target_parent);
}
$stat = @stat($target_parent);
if ($stat) {
$dir_perms = $stat['mode'] & 07777;
} else {
$dir_perms = 0777;
}
if (@mkdir($target, $dir_perms, true)) {
if (($dir_perms & ~umask()) !== $dir_perms) {
$folder_parts = explode('/', substr($target, strlen($target_parent) + 1));
for ($i = 1, $c = count($folder_parts); $i <= $c; $i++) {
chmod($target_parent . '/' . implode('/', array_slice($folder_parts, 0, $i)), $dir_perms);
}
}
return true;
}
return false;
}
function path_is_absolute($path)
{
if (wp_is_stream($path) && (is_dir($path) || is_file($path))) {
return true;
}
if (realpath($path) === $path) {
return true;
}
if (strlen($path) === 0 || '.' === $path[0]) {
return false;
}
if (preg_match('#^[a-zA-Z]:\\\\#', $path)) {
return true;
}
return '/' === $path[0] || '\\' === $path[0];
}
function path_join($base, $path)
{
if (path_is_absolute($path)) {
return $path;
}
return rtrim($base, '/') . '/' . $path;
}
function wp_normalize_path($path)
{
$wrapper = '';
if (wp_is_stream($path)) {
list($wrapper, $path) = explode('://', $path, 2);
$wrapper .= '://';
}
$path = str_replace('\\', '/', $path);
$path = preg_replace('|(?<=.)/+|', '/', $path);
if (':' === substr($path, 1, 1)) {
$path = ucfirst($path);
}
return $wrapper . $path;
}
function get_temp_dir()
{
static $temp = '';
if (defined('WP_TEMP_DIR')) {
return trailingslashit(WP_TEMP_DIR);
}
if ($temp) {
return trailingslashit($temp);
}
if (function_exists('sys_get_temp_dir')) {
$temp = sys_get_temp_dir();
if (@is_dir($temp) && wp_is_writable($temp)) {
return trailingslashit($temp);
}
}
$temp = ini_get('upload_tmp_dir');
if (@is_dir($temp) && wp_is_writable($temp)) {
return trailingslashit($temp);
}
$temp = WP_CONTENT_DIR . '/';
if (is_dir($temp) && wp_is_writable($temp)) {
return $temp;
}
return '/tmp/';
}
function wp_is_writable($path)
{
if ('Windows' === PHP_OS_FAMILY) {
return win_is_writable($path);
}
return @is_writable($path);
}
function win_is_writable($path)
{
if ('/' === $path[strlen($path) - 1]) {
return win_is_writable($path . uniqid(mt_rand()) . '.tmp');
} elseif (is_dir($path)) {
return win_is_writable($path . '/' . uniqid(mt_rand()) . '.tmp');
}
$should_delete_tmp_file = !file_exists($path);
$f = @fopen($path, 'a');
if (false === $f) {
return false;
}
fclose($f);
if ($should_delete_tmp_file) {
unlink($path);
}
return true;
}
function wp_get_upload_dir()
{
return wp_upload_dir(null, false);
}
function wp_upload_dir($time = null, $create_dir = true, $refresh_cache = false)
{
static $cache = array(), $tested_paths = array();
$key = sprintf('%d-%s', get_current_blog_id(), (string) $time);
if ($refresh_cache || empty($cache[$key])) {
$cache[$key] = _wp_upload_dir($time);
}
$uploads = apply_filters('upload_dir', $cache[$key]);
if ($create_dir) {
$path = $uploads['path'];
if (array_key_exists($path, $tested_paths)) {
$uploads['error'] = $tested_paths[$path];
} else {
if (!wp_mkdir_p($path)) {
if (str_starts_with($uploads['basedir'], ABSPATH)) {
$error_path = str_replace(ABSPATH, '', $uploads['basedir']) . $uploads['subdir'];
} else {
$error_path = wp_basename($uploads['basedir']) . $uploads['subdir'];
}
$uploads['error'] = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), esc_html($error_path));
}
$tested_paths[$path] = $uploads['error'];
}
}
return $uploads;
}
function _wp_upload_dir($time = null)
{
$siteurl = get_option('siteurl');
$upload_path = trim(get_option('upload_path'));
if (empty($upload_path) || 'wp-content/uploads' === $upload_path) {
$dir = WP_CONTENT_DIR . '/uploads';
} elseif (!str_starts_with($upload_path, ABSPATH)) {
$dir = path_join(ABSPATH, $upload_path);
} else {
$dir = $upload_path;
}
$url = get_option('upload_url_path');
if (!$url) {
if (empty($upload_path) || 'wp-content/uploads' === $upload_path || $upload_path === $dir) {
$url = WP_CONTENT_URL . '/uploads';
} else {
$url = trailingslashit($siteurl) . $upload_path;
}
}
if (defined('UPLOADS') && !(is_multisite() && get_site_option('ms_files_rewriting'))) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit($siteurl) . UPLOADS;
}
if (is_multisite() && !(is_main_network() && is_main_site() && defined('MULTISITE'))) {
if (!get_site_option('ms_files_rewriting')) {
if (defined('MULTISITE')) {
$ms_dir = '/sites/' . get_current_blog_id();
} else {
$ms_dir = '/' . get_current_blog_id();
}
$dir .= $ms_dir;
$url .= $ms_dir;
} elseif (defined('UPLOADS') && !ms_is_switched()) {
if (defined('BLOGUPLOADDIR')) {
$dir = untrailingslashit(BLOGUPLOADDIR);
} else {
$dir = ABSPATH . UPLOADS;
}
$url = trailingslashit($siteurl) . 'files';
}
}
$basedir = $dir;
$baseurl = $url;
$subdir = '';
if (get_option('uploads_use_yearmonth_folders')) {
if (!$time) {
$time = current_time('mysql');
}
$y = substr($time, 0, 4);
$m = substr($time, 5, 2);
$subdir = "/{$y}/{$m}";
}
$dir .= $subdir;
$url .= $subdir;
return array('path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $basedir, 'baseurl' => $baseurl, 'error' => false);
}
function wp_unique_filename($dir, $filename, $unique_filename_callback = null)
{
$filename = sanitize_file_name($filename);
$ext2 = null;
$number = '';
$alt_filenames = array();
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$name = pathinfo($filename, PATHINFO_BASENAME);
if ($ext) {
$ext = '.' . $ext;
}
if ($name === $ext) {
$name = '';
}
if ($unique_filename_callback && is_callable($unique_filename_callback)) {
$filename = call_user_func($unique_filename_callback, $dir, $name, $ext);
} else {
$fname = pathinfo($filename, PATHINFO_FILENAME);
if ($fname && preg_match('/-(?:\\d+x\\d+|scaled|rotated)$/', $fname)) {
$number = 1;
$filename = str_replace("{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename);
}
$file_type = wp_check_filetype($filename);
$mime_type = $file_type['type'];
$is_image = !empty($mime_type) && str_starts_with($mime_type, 'image/');
$upload_dir = wp_get_upload_dir();
$lc_filename = null;
$lc_ext = strtolower($ext);
$_dir = trailingslashit($dir);
if ($ext && $lc_ext !== $ext) {
$lc_filename = preg_replace('|' . preg_quote($ext) . '$|', $lc_ext, $filename);
}
while (file_exists($_dir . $filename) || $lc_filename && file_exists($_dir . $lc_filename)) {
$new_number = (int) $number + 1;
if ($lc_filename) {
$lc_filename = str_replace(array("-{$number}{$lc_ext}", "{$number}{$lc_ext}"), "-{$new_number}{$lc_ext}", $lc_filename);
}
if ('' === "{$number}{$ext}") {
$filename = "{$filename}-{$new_number}";
} else {
$filename = str_replace(array("-{$number}{$ext}", "{$number}{$ext}"), "-{$new_number}{$ext}", $filename);
}
$number = $new_number;
}
if ($lc_filename) {
$filename = $lc_filename;
}
$files = array();
$count = 10000;
if ($name && $ext && @is_dir($dir) && str_contains($dir, $upload_dir['basedir'])) {
$files = apply_filters('pre_wp_unique_filename_file_list', null, $dir, $filename);
if (null === $files) {
$files = @scandir($dir);
}
if (!empty($files)) {
$files = array_diff($files, array('.', '..'));
}
if (!empty($files)) {
$count = count($files);
$i = 0;
while ($i <= $count && _wp_check_existing_file_names($filename, $files)) {
$new_number = (int) $number + 1;
$filename = str_replace(array("-{$number}{$lc_ext}", "{$number}{$lc_ext}"), "-{$new_number}{$lc_ext}", $filename);
$number = $new_number;
++$i;
}
}
}
if ($is_image) {
$output_formats = wp_get_image_editor_output_format($_dir . $filename, $mime_type);
$alt_types = array();
if (!empty($output_formats[$mime_type])) {
$alt_mime_type = $output_formats[$mime_type];
$alt_types = array_keys(array_intersect($output_formats, array($mime_type, $alt_mime_type)));
$alt_types[] = $alt_mime_type;
} elseif (!empty($output_formats)) {
$alt_types = array_keys(array_intersect($output_formats, array($mime_type)));
}
$alt_types = array_unique(array_diff($alt_types, array($mime_type)));
foreach ($alt_types as $alt_type) {
$alt_ext = wp_get_default_extension_for_mime_type($alt_type);
if (!$alt_ext) {
continue;
}
$alt_ext = ".{$alt_ext}";
$alt_filename = preg_replace('|' . preg_quote($lc_ext) . '$|', $alt_ext, $filename);
$alt_filenames[$alt_ext] = $alt_filename;
}
if (!empty($alt_filenames)) {
$alt_filenames[$lc_ext] = $filename;
$i = 0;
while ($i <= $count && _wp_check_alternate_file_names($alt_filenames, $_dir, $files)) {
$new_number = (int) $number + 1;
foreach ($alt_filenames as $alt_ext => $alt_filename) {
$alt_filenames[$alt_ext] = str_replace(array("-{$number}{$alt_ext}", "{$number}{$alt_ext}"), "-{$new_number}{$alt_ext}", $alt_filename);
}
$filename = str_replace(array("-{$number}{$lc_ext}", "{$number}{$lc_ext}"), "-{$new_number}{$lc_ext}", $filename);
$number = $new_number;
++$i;
}
}
}
}
return apply_filters('wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number);
}
function _wp_check_alternate_file_names($filenames, $dir, $files)
{
foreach ($filenames as $filename) {
if (file_exists($dir . $filename)) {
return true;
}
if (!empty($files) && _wp_check_existing_file_names($filename, $files)) {
return true;
}
}
return false;
}
function _wp_check_existing_file_names($filename, $files)
{
$fname = pathinfo($filename, PATHINFO_FILENAME);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if (empty($fname)) {
return false;
}
if ($ext) {
$ext = ".{$ext}";
}
$regex = '/^' . preg_quote($fname) . '-(?:\\d+x\\d+|scaled|rotated)' . preg_quote($ext) . '$/i';
foreach ($files as $file) {
if (preg_match($regex, $file)) {
return true;
}
}
return false;
}
function wp_upload_bits($name, $deprecated, $bits, $time = null)
{
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '2.0.0');
}
if (empty($name)) {
return array('error' => __('Empty filename'));
}
$wp_filetype = wp_check_filetype($name);
if (!$wp_filetype['ext'] && !current_user_can('unfiltered_upload')) {
return array('error' => __('Sorry, you are not allowed to upload this file type.'));
}
$upload = wp_upload_dir($time);
if (false !== $upload['error']) {
return $upload;
}
$upload_bits_error = apply_filters('wp_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
if (!is_array($upload_bits_error)) {
$upload['error'] = $upload_bits_error;
return $upload;
}
$filename = wp_unique_filename($upload['path'], $name);
$new_file = $upload['path'] . "/{$filename}";
if (!wp_mkdir_p(dirname($new_file))) {
if (str_starts_with($upload['basedir'], ABSPATH)) {
$error_path = str_replace(ABSPATH, '', $upload['basedir']) . $upload['subdir'];
} else {
$error_path = wp_basename($upload['basedir']) . $upload['subdir'];
}
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
return array('error' => $message);
}
$ifp = @fopen($new_file, 'wb');
if (!$ifp) {
return array('error' => sprintf(__('Could not write file %s'), $new_file));
}
fwrite($ifp, $bits);
fclose($ifp);
clearstatcache();
$stat = @stat(dirname($new_file));
$perms = $stat['mode'] & 07777;
$perms = $perms & 0666;
chmod($new_file, $perms);
clearstatcache();
$url = $upload['url'] . "/{$filename}";
if (is_multisite()) {
clean_dirsize_cache($new_file);
}
return apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false), 'sideload');
}
function wp_ext2type($ext)
{
$ext = strtolower($ext);
$ext2type = wp_get_ext_types();
foreach ($ext2type as $type => $exts) {
if (in_array($ext, $exts, true)) {
return $type;
}
}
}
function wp_get_default_extension_for_mime_type($mime_type)
{
$extensions = explode('|', array_search($mime_type, wp_get_mime_types(), true));
if (empty($extensions[0])) {
return false;
}
return $extensions[0];
}
function wp_check_filetype($filename, $mimes = null)
{
if (empty($mimes)) {
$mimes = get_allowed_mime_types();
}
$type = false;
$ext = false;
foreach ($mimes as $ext_preg => $mime_match) {
$ext_preg = '!\\.(' . $ext_preg . ')$!i';
if (preg_match($ext_preg, $filename, $ext_matches)) {
$type = $mime_match;
$ext = $ext_matches[1];
break;
}
}
return compact('ext', 'type');
}
function wp_check_filetype_and_ext($file, $filename, $mimes = null)
{
$proper_filename = false;
$wp_filetype = wp_check_filetype($filename, $mimes);
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
if (!file_exists($file)) {
return compact('ext', 'type', 'proper_filename');
}
$real_mime = false;
if ($type && str_starts_with($type, 'image/')) {
$real_mime = wp_get_image_mime($file);
$heic_images_extensions = array('heif', 'heics', 'heifs');
if ($real_mime && ($real_mime !== $type || in_array($ext, $heic_images_extensions, true))) {
$mime_to_ext = apply_filters('getimagesize_mimes_to_exts', array('image/jpeg' => 'jpg', 'image/png' => 'png', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/tiff' => 'tif', 'image/webp' => 'webp', 'image/avif' => 'avif', 'image/heic' => 'heic', 'image/heif' => 'heic', 'image/heic-sequence' => 'heic', 'image/heif-sequence' => 'heic'));
if (!empty($mime_to_ext[$real_mime])) {
$filename_parts = explode('.', $filename);
array_pop($filename_parts);
$filename_parts[] = $mime_to_ext[$real_mime];
$new_filename = implode('.', $filename_parts);
if ($new_filename !== $filename) {
$proper_filename = $new_filename;
}
$wp_filetype = wp_check_filetype($new_filename, $mimes);
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
} else {
$real_mime = false;
}
}
}
if ($type && !$real_mime && extension_loaded('fileinfo')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$real_mime = finfo_file($finfo, $file);
finfo_close($finfo);
$google_docs_types = array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
foreach ($google_docs_types as $google_docs_type) {
if (2 === substr_count($real_mime, $google_docs_type)) {
$real_mime = $google_docs_type;
}
}
$nonspecific_types = array('application/octet-stream', 'application/encrypted', 'application/CDFV2-encrypted', 'application/zip');
if (in_array($real_mime, $nonspecific_types, true)) {
if (!in_array(substr($type, 0, strcspn($type, '/')), array('application', 'video', 'audio'), true)) {
$type = false;
$ext = false;
}
} elseif (str_starts_with($real_mime, 'video/') || str_starts_with($real_mime, 'audio/')) {
if (substr($real_mime, 0, strcspn($real_mime, '/')) !== substr($type, 0, strcspn($type, '/'))) {
$type = false;
$ext = false;
}
} elseif ('text/plain' === $real_mime) {
if (!in_array($type, array('text/plain', 'text/csv', 'application/csv', 'text/richtext', 'text/tsv', 'text/vtt'), true)) {
$type = false;
$ext = false;
}
} elseif ('application/csv' === $real_mime) {
if (!in_array($type, array('text/csv', 'text/plain', 'application/csv'), true)) {
$type = false;
$ext = false;
}
} elseif ('text/rtf' === $real_mime) {
if (!in_array($type, array('text/rtf', 'text/plain', 'application/rtf'), true)) {
$type = false;
$ext = false;
}
} else {
if ($type !== $real_mime) {
$type = false;
$ext = false;
}
}
}
if ($type) {
$allowed = get_allowed_mime_types();
if (!in_array($type, $allowed, true)) {
$type = false;
$ext = false;
}
}
return apply_filters('wp_check_filetype_and_ext', compact('ext', 'type', 'proper_filename'), $file, $filename, $mimes, $real_mime);
}
function wp_get_image_mime($file)
{
try {
if (is_callable('exif_imagetype')) {
$imagetype = exif_imagetype($file);
$mime = $imagetype ? image_type_to_mime_type($imagetype) : false;
} elseif (function_exists('getimagesize')) {
if (defined('WP_DEBUG') && WP_DEBUG && !defined('WP_RUN_CORE_TESTS')) {
$imagesize = getimagesize($file);
} else {
$imagesize = @getimagesize($file);
}
$mime = isset($imagesize['mime']) ? $imagesize['mime'] : false;
} else {
$mime = false;
}
if (false !== $mime) {
return $mime;
}
$magic = file_get_contents($file, false, null, 0, 12);
if (false === $magic) {
return false;
}
$magic = bin2hex($magic);
if (str_starts_with($magic, '52494646') && 16 === strpos($magic, '57454250')) {
$mime = 'image/webp';
}
$magic = str_split($magic, 8);
if (isset($magic[1]) && isset($magic[2]) && 'ftyp' === hex2bin($magic[1])) {
if ('avif' === hex2bin($magic[2]) || 'avis' === hex2bin($magic[2])) {
$mime = 'image/avif';
} elseif ('heic' === hex2bin($magic[2])) {
$mime = 'image/heic';
} elseif ('heif' === hex2bin($magic[2])) {
$mime = 'image/heif';
} else {
if (extension_loaded('fileinfo')) {
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($fileinfo, $file);
finfo_close($fileinfo);
if (wp_is_heic_image_mime_type($mime_type)) {
$mime = $mime_type;
}
}
}
}
} catch (Exception $e) {
$mime = false;
}
return $mime;
}
function wp_get_mime_types()
{
return apply_filters('mime_types', array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tiff|tif' => 'image/tiff', 'webp' => 'image/webp', 'avif' => 'image/avif', 'ico' => 'image/x-icon', 'heic' => 'image/heic', 'heif' => 'image/heif', 'heics' => 'image/heic-sequence', 'heifs' => 'image/heif-sequence', 'asf|asx' => 'video/x-ms-asf', 'wmv' => 'video/x-ms-wmv', 'wmx' => 'video/x-ms-wmx', 'wm' => 'video/x-ms-wm', 'avi' => 'video/avi', 'divx' => 'video/divx', 'flv' => 'video/x-flv', 'mov|qt' => 'video/quicktime', 'mpeg|mpg|mpe' => 'video/mpeg', 'mp4|m4v' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'mkv' => 'video/x-matroska', '3gp|3gpp' => 'video/3gpp', '3g2|3gp2' => 'video/3gpp2', 'txt|asc|c|cc|h|srt' => 'text/plain', 'csv' => 'text/csv', 'tsv' => 'text/tab-separated-values', 'ics' => 'text/calendar', 'rtx' => 'text/richtext', 'css' => 'text/css', 'htm|html' => 'text/html', 'vtt' => 'text/vtt', 'dfxp' => 'application/ttaf+xml', 'mp3|m4a|m4b' => 'audio/mpeg', 'aac' => 'audio/aac', 'ra|ram' => 'audio/x-realaudio', 'wav|x-wav' => 'audio/wav', 'ogg|oga' => 'audio/ogg', 'flac' => 'audio/flac', 'mid|midi' => 'audio/midi', 'wma' => 'audio/x-ms-wma', 'wax' => 'audio/x-ms-wax', 'mka' => 'audio/x-matroska', 'rtf' => 'application/rtf', 'js' => 'application/javascript', 'pdf' => 'application/pdf', 'swf' => 'application/x-shockwave-flash', 'class' => 'application/java', 'tar' => 'application/x-tar', 'zip' => 'application/zip', 'gz|gzip' => 'application/x-gzip', 'rar' => 'application/rar', '7z' => 'application/x-7z-compressed', 'exe' => 'application/x-msdownload', 'psd' => 'application/octet-stream', 'xcf' => 'application/octet-stream', 'doc' => 'application/msword', 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', 'wri' => 'application/vnd.ms-write', 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', 'mdb' => 'application/vnd.ms-access', 'mpp' => 'application/vnd.ms-project', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', 'oxps' => 'application/oxps', 'xps' => 'application/vnd.ms-xpsdocument', 'odt' => 'application/vnd.oasis.opendocument.text', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odg' => 'application/vnd.oasis.opendocument.graphics', 'odc' => 'application/vnd.oasis.opendocument.chart', 'odb' => 'application/vnd.oasis.opendocument.database', 'odf' => 'application/vnd.oasis.opendocument.formula', 'wp|wpd' => 'application/wordperfect', 'key' => 'application/vnd.apple.keynote', 'numbers' => 'application/vnd.apple.numbers', 'pages' => 'application/vnd.apple.pages'));
}
function wp_get_ext_types()
{
return apply_filters('ext2type', array('image' => array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'heif', 'webp', 'avif'), 'audio' => array('aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma'), 'video' => array('3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv'), 'document' => array('doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf'), 'spreadsheet' => array('numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb'), 'interactive' => array('swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp'), 'text' => array('asc', 'csv', 'tsv', 'txt'), 'archive' => array('bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z'), 'code' => array('css', 'htm', 'html', 'php', 'js')));
}
function wp_filesize($path)
{
$size = apply_filters('pre_wp_filesize', null, $path);
if (is_int($size)) {
return $size;
}
$size = file_exists($path) ? (int) filesize($path) : 0;
return (int) apply_filters('wp_filesize', $size, $path);
}
function get_allowed_mime_types($user = null)
{
$t = wp_get_mime_types();
unset($t['swf'], $t['exe']);
if (function_exists('current_user_can')) {
$unfiltered = $user ? user_can($user, 'unfiltered_html') : current_user_can('unfiltered_html');
}
if (empty($unfiltered)) {
unset($t['htm|html'], $t['js']);
}
return apply_filters('upload_mimes', $t, $user);
}
function wp_nonce_ays($action)
{
$title = __('An error occurred.');
$response_code = 403;
if ('log-out' === $action) {
$title = sprintf(__('You are attempting to log out of %s'), get_bloginfo('name'));
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
$html = $title;
$html .= '</p><p>';
$html .= sprintf(__('Do you really want to <a href="%s">log out</a>?'), wp_logout_url($redirect_to));
} else {
$html = __('The link you followed has expired.');
if (wp_get_referer()) {
$wp_http_referer = remove_query_arg('updated', wp_get_referer());
$wp_http_referer = wp_validate_redirect(sanitize_url($wp_http_referer));
$html .= '</p><p>';
$html .= sprintf('<a href="%s">%s</a>', esc_url($wp_http_referer), __('Please try again.'));
}
}
wp_die($html, $title, $response_code);
}
function wp_die($message = '', $title = '', $args = array())
{
global $wp_query;
if (is_int($args)) {
$args = array('response' => $args);
} elseif (is_int($title)) {
$args = array('response' => $title);
$title = '';
}
if (wp_doing_ajax()) {
$callback = apply_filters('wp_die_ajax_handler', '_ajax_wp_die_handler');
} elseif (wp_is_json_request()) {
$callback = apply_filters('wp_die_json_handler', '_json_wp_die_handler');
} elseif (wp_is_serving_rest_request() && wp_is_jsonp_request()) {
$callback = apply_filters('wp_die_jsonp_handler', '_jsonp_wp_die_handler');
} elseif (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
$callback = apply_filters('wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler');
} elseif (wp_is_xml_request() || isset($wp_query) && (function_exists('is_feed') && is_feed() || function_exists('is_comment_feed') && is_comment_feed() || function_exists('is_trackback') && is_trackback())) {
$callback = apply_filters('wp_die_xml_handler', '_xml_wp_die_handler');
} else {
$callback = apply_filters('wp_die_handler', '_default_wp_die_handler');
}
call_user_func($callback, $message, $title, $args);
}
function _default_wp_die_handler($message, $title = '', $args = array())
{
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
if (is_string($message)) {
if (!empty($parsed_args['additional_errors'])) {
$message = array_merge(array($message), wp_list_pluck($parsed_args['additional_errors'], 'message'));
$message = "<ul>\n\t\t<li>" . implode("</li>\n\t\t<li>", $message) . "</li>\n\t</ul>";
}
$message = sprintf('<div class="wp-die-message">%s</div>', $message);
}
$have_gettext = function_exists('__');
if (!empty($parsed_args['link_url']) && !empty($parsed_args['link_text'])) {
$link_url = $parsed_args['link_url'];
if (function_exists('esc_url')) {
$link_url = esc_url($link_url);
}
$link_text = $parsed_args['link_text'];
$message .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
}
if (isset($parsed_args['back_link']) && $parsed_args['back_link']) {
$back_text = $have_gettext ? __('« Back') : '« Back';
$message .= "\n<p><a href='javascript:history.back()'>{$back_text}</a></p>";
}
if (!did_action('admin_head')) {
if (!headers_sent()) {
header("Content-Type: text/html; charset={$parsed_args['charset']}");
status_header($parsed_args['response']);
nocache_headers();
}
$text_direction = $parsed_args['text_direction'];
$dir_attr = "dir='{$text_direction}'";
if (empty($args['text_direction']) && function_exists('language_attributes') && function_exists('is_rtl')) {
$dir_attr = get_language_attributes();
}
?>
<!DOCTYPE html>
<html <?php
echo $dir_attr;
?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php
echo $parsed_args['charset'];
?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
if (function_exists('wp_robots') && function_exists('wp_robots_no_robots') && function_exists('add_filter')) {
add_filter('wp_robots', 'wp_robots_no_robots');
remove_filter('wp_robots', 'wp_robots_noindex_embeds');
remove_filter('wp_robots', 'wp_robots_noindex_search');
wp_robots();
}
?>
<title><?php
echo $title;
?></title>
<style type="text/css">
html {
background: #f1f1f1;
}
body {
background: #fff;
border: 1px solid #ccd0d4;
color: #444;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
margin: 2em auto;
padding: 1em 2em;
max-width: 700px;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
}
h1 {
border-bottom: 1px solid #dadada;
clear: both;
color: #666;
font-size: 24px;
margin: 30px 0 0 0;
padding: 0;
padding-bottom: 7px;
}
#error-page {
margin-top: 50px;
}
#error-page p,
#error-page .wp-die-message {
font-size: 14px;
line-height: 1.5;
margin: 25px 0 20px;
}
#error-page code {
font-family: Consolas, Monaco, monospace;
}
ul li {
margin-bottom: 10px;
font-size: 14px ;
}
a {
color: #2271b1;
}
a:hover,
a:active {
color: #135e96;
}
a:focus {
color: #043959;
box-shadow: 0 0 0 2px #2271b1;
outline: 2px solid transparent;
}
.button {
background: #f3f5f6;
border: 1px solid #016087;
color: #016087;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 2;
height: 28px;
margin: 0;
padding: 0 10px 1px;
cursor: pointer;
-webkit-border-radius: 3px;
-webkit-appearance: none;
border-radius: 3px;
white-space: nowrap;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
vertical-align: top;
}
.button.button-large {
line-height: 2.30769231;
min-height: 32px;
padding: 0 12px;
}
.button:hover,
.button:focus {
background: #f1f1f1;
}
.button:focus {
background: #f3f5f6;
border-color: #007cba;
-webkit-box-shadow: 0 0 0 1px #007cba;
box-shadow: 0 0 0 1px #007cba;
color: #016087;
outline: 2px solid transparent;
outline-offset: 0;
}
.button:active {
background: #f3f5f6;
border-color: #7e8993;
-webkit-box-shadow: none;
box-shadow: none;
}
<?php
if ('rtl' === $text_direction) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
</style>
</head>
<body id="error-page">
<?php
}
?>
<?php
echo $message;
?>
</body>
</html>
<?php
if ($parsed_args['exit']) {
die;
}
}
function _ajax_wp_die_handler($message, $title = '', $args = array())
{
$args = wp_parse_args($args, array('response' => 200));
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
if (!headers_sent()) {
if (null !== $args['response']) {
status_header($parsed_args['response']);
}
nocache_headers();
}
if (is_scalar($message)) {
$message = (string) $message;
} else {
$message = '0';
}
if ($parsed_args['exit']) {
die($message);
}
echo $message;
}
function _json_wp_die_handler($message, $title = '', $args = array())
{
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
$data = array('code' => $parsed_args['code'], 'message' => $message, 'data' => array('status' => $parsed_args['response']), 'additional_errors' => $parsed_args['additional_errors']);
if (isset($parsed_args['error_data'])) {
$data['data']['error'] = $parsed_args['error_data'];
}
if (!headers_sent()) {
header("Content-Type: application/json; charset={$parsed_args['charset']}");
if (null !== $parsed_args['response']) {
status_header($parsed_args['response']);
}
nocache_headers();
}
echo wp_json_encode($data);
if ($parsed_args['exit']) {
die;
}
}
function _jsonp_wp_die_handler($message, $title = '', $args = array())
{
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
$data = array('code' => $parsed_args['code'], 'message' => $message, 'data' => array('status' => $parsed_args['response']), 'additional_errors' => $parsed_args['additional_errors']);
if (isset($parsed_args['error_data'])) {
$data['data']['error'] = $parsed_args['error_data'];
}
if (!headers_sent()) {
header("Content-Type: application/javascript; charset={$parsed_args['charset']}");
header('X-Content-Type-Options: nosniff');
header('X-Robots-Tag: noindex');
if (null !== $parsed_args['response']) {
status_header($parsed_args['response']);
}
nocache_headers();
}
$result = wp_json_encode($data);
$jsonp_callback = $_GET['_jsonp'];
echo '/**/' . $jsonp_callback . '(' . $result . ')';
if ($parsed_args['exit']) {
die;
}
}
function _xmlrpc_wp_die_handler($message, $title = '', $args = array())
{
global $wp_xmlrpc_server;
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
if (!headers_sent()) {
nocache_headers();
}
if ($wp_xmlrpc_server) {
$error = new IXR_Error($parsed_args['response'], $message);
$wp_xmlrpc_server->output($error->getXml());
}
if ($parsed_args['exit']) {
die;
}
}
function _xml_wp_die_handler($message, $title = '', $args = array())
{
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
$message = htmlspecialchars($message);
$title = htmlspecialchars($title);
$xml = <<<EOD
<error>
<code>{$parsed_args['code']}</code>
<title><![CDATA[{$title}]]></title>
<message><![CDATA[{$message}]]></message>
<data>
<status>{$parsed_args['response']}</status>
</data>
</error>
EOD;
if (!headers_sent()) {
header("Content-Type: text/xml; charset={$parsed_args['charset']}");
if (null !== $parsed_args['response']) {
status_header($parsed_args['response']);
}
nocache_headers();
}
echo $xml;
if ($parsed_args['exit']) {
die;
}
}
function _scalar_wp_die_handler($message = '', $title = '', $args = array())
{
list($message, $title, $parsed_args) = _wp_die_process_input($message, $title, $args);
if ($parsed_args['exit']) {
if (is_scalar($message)) {
die((string) $message);
}
die;
}
if (is_scalar($message)) {
echo (string) $message;
}
}
function _wp_die_process_input($message, $title = '', $args = array())
{
$defaults = array('response' => 0, 'code' => '', 'exit' => true, 'back_link' => false, 'link_url' => '', 'link_text' => '', 'text_direction' => '', 'charset' => 'utf-8', 'additional_errors' => array());
$args = wp_parse_args($args, $defaults);
if (function_exists('is_wp_error') && is_wp_error($message)) {
if (!empty($message->errors)) {
$errors = array();
foreach ((array) $message->errors as $error_code => $error_messages) {
foreach ((array) $error_messages as $error_message) {
$errors[] = array('code' => $error_code, 'message' => $error_message, 'data' => $message->get_error_data($error_code));
}
}
$message = $errors[0]['message'];
if (empty($args['code'])) {
$args['code'] = $errors[0]['code'];
}
if (empty($args['response']) && is_array($errors[0]['data']) && !empty($errors[0]['data']['status'])) {
$args['response'] = $errors[0]['data']['status'];
}
if (empty($title) && is_array($errors[0]['data']) && !empty($errors[0]['data']['title'])) {
$title = $errors[0]['data']['title'];
}
if (WP_DEBUG_DISPLAY && is_array($errors[0]['data']) && !empty($errors[0]['data']['error'])) {
$args['error_data'] = $errors[0]['data']['error'];
}
unset($errors[0]);
$args['additional_errors'] = array_values($errors);
} else {
$message = '';
}
}
$have_gettext = function_exists('__');
if (empty($args['code'])) {
$args['code'] = 'wp_die';
}
if (empty($args['response'])) {
$args['response'] = 500;
}
if (empty($title)) {
$title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error';
}
if (empty($args['text_direction']) || !in_array($args['text_direction'], array('ltr', 'rtl'), true)) {
$args['text_direction'] = 'ltr';
if (function_exists('is_rtl') && is_rtl()) {
$args['text_direction'] = 'rtl';
}
}
if (!empty($args['charset'])) {
$args['charset'] = _canonical_charset($args['charset']);
}
return array($message, $title, $args);
}
function wp_json_encode($value, $flags = 0, $depth = 512)
{
$json = json_encode($value, $flags, $depth);
if (false !== $json) {
return $json;
}
try {
$value = _wp_json_sanity_check($value, $depth);
} catch (Exception $e) {
return false;
}
return json_encode($value, $flags, $depth);
}
function _wp_json_sanity_check($value, $depth)
{
if ($depth < 0) {
throw new Exception('Reached depth limit');
}
if (is_array($value)) {
$output = array();
foreach ($value as $id => $el) {
if (is_string($id)) {
$clean_id = _wp_json_convert_string($id);
} else {
$clean_id = $id;
}
if (is_array($el) || is_object($el)) {
$output[$clean_id] = _wp_json_sanity_check($el, $depth - 1);
} elseif (is_string($el)) {
$output[$clean_id] = _wp_json_convert_string($el);
} else {
$output[$clean_id] = $el;
}
}
} elseif (is_object($value)) {
$output = new stdClass();
foreach ($value as $id => $el) {
if (is_string($id)) {
$clean_id = _wp_json_convert_string($id);
} else {
$clean_id = $id;
}
if (is_array($el) || is_object($el)) {
$output->{$clean_id} = _wp_json_sanity_check($el, $depth - 1);
} elseif (is_string($el)) {
$output->{$clean_id} = _wp_json_convert_string($el);
} else {
$output->{$clean_id} = $el;
}
}
} elseif (is_string($value)) {
return _wp_json_convert_string($value);
} else {
return $value;
}
return $output;
}
function _wp_json_convert_string($input_string)
{
static $use_mb = null;
if (is_null($use_mb)) {
$use_mb = function_exists('mb_convert_encoding');
}
if ($use_mb) {
$encoding = mb_detect_encoding($input_string, mb_detect_order(), true);
if ($encoding) {
return mb_convert_encoding($input_string, 'UTF-8', $encoding);
} else {
return mb_convert_encoding($input_string, 'UTF-8', 'UTF-8');
}
} else {
return wp_check_invalid_utf8($input_string, true);
}
}
function _wp_json_prepare_data($value)
{
_deprecated_function(__FUNCTION__, '5.3.0');
return $value;
}
function wp_send_json($response, $status_code = null, $flags = 0)
{
if (wp_is_serving_rest_request()) {
_doing_it_wrong(__FUNCTION__, sprintf(__('Return a %1$s or %2$s object from your callback when using the REST API.'), 'WP_REST_Response', 'WP_Error'), '5.5.0');
}
if (!headers_sent()) {
header('Content-Type: application/json; charset=' . get_option('blog_charset'));
if (null !== $status_code) {
status_header($status_code);
}
}
echo wp_json_encode($response, $flags);
if (wp_doing_ajax()) {
wp_die('', '', array('response' => null));
} else {
die;
}
}
function wp_send_json_success($value = null, $status_code = null, $flags = 0)
{
$response = array('success' => true);
if (isset($value)) {
$response['data'] = $value;
}
wp_send_json($response, $status_code, $flags);
}
function wp_send_json_error($value = null, $status_code = null, $flags = 0)
{
$response = array('success' => false);
if (isset($value)) {
if (is_wp_error($value)) {
$result = array();
foreach ($value->errors as $code => $messages) {
foreach ($messages as $message) {
$result[] = array('code' => $code, 'message' => $message);
}
}
$response['data'] = $result;
} else {
$response['data'] = $value;
}
}
wp_send_json($response, $status_code, $flags);
}
function wp_check_jsonp_callback($callback)
{
if (!is_string($callback)) {
return false;
}
preg_replace('/[^\\w\\.]/', '', $callback, -1, $illegal_char_count);
return 0 === $illegal_char_count;
}
function wp_json_file_decode($filename, $options = array())
{
$result = null;
$filename = wp_normalize_path(realpath($filename));
if (!$filename) {
wp_trigger_error(__FUNCTION__, sprintf(__("File %s doesn't exist!"), $filename));
return $result;
}
$options = wp_parse_args($options, array('associative' => false));
$decoded_file = json_decode(file_get_contents($filename), $options['associative']);
if (JSON_ERROR_NONE !== json_last_error()) {
wp_trigger_error(__FUNCTION__, sprintf(__('Error when decoding a JSON file at path %1$s: %2$s'), $filename, json_last_error_msg()));
return $result;
}
return $decoded_file;
}
function _config_wp_home($url = '')
{
if (defined('WP_HOME')) {
return untrailingslashit(WP_HOME);
}
return $url;
}
function _config_wp_siteurl($url = '')
{
if (defined('WP_SITEURL')) {
return untrailingslashit(WP_SITEURL);
}
return $url;
}
function _delete_option_fresh_site()
{
update_option('fresh_site', '0', false);
}
function _mce_set_direction($mce_init)
{
if (is_rtl()) {
$mce_init['directionality'] = 'rtl';
$mce_init['rtl_ui'] = true;
if (!empty($mce_init['plugins']) && !str_contains($mce_init['plugins'], 'directionality')) {
$mce_init['plugins'] .= ',directionality';
}
if (!empty($mce_init['toolbar1']) && !preg_match('/\\bltr\\b/', $mce_init['toolbar1'])) {
$mce_init['toolbar1'] .= ',ltr';
}
}
return $mce_init;
}
function wp_is_serving_rest_request()
{
return defined('REST_REQUEST') && REST_REQUEST;
}
function smilies_init()
{
global $wpsmiliestrans, $wp_smiliessearch;
if (!get_option('use_smilies')) {
return;
}
if (!isset($wpsmiliestrans)) {
$wpsmiliestrans = array(':mrgreen:' => 'mrgreen.png', ':neutral:' => "😐", ':twisted:' => "😈", ':arrow:' => "➡", ':shock:' => "😯", ':smile:' => "🙂", ':???:' => "😕", ':cool:' => "😎", ':evil:' => "👿", ':grin:' => "😀", ':idea:' => "💡", ':oops:' => "😳", ':razz:' => "😛", ':roll:' => "🙄", ':wink:' => "😉", ':cry:' => "😥", ':eek:' => "😮", ':lol:' => "😆", ':mad:' => "😡", ':sad:' => "🙁", '8-)' => "😎", '8-O' => "😯", ':-(' => "🙁", ':-)' => "🙂", ':-?' => "😕", ':-D' => "😀", ':-P' => "😛", ':-o' => "😮", ':-x' => "😡", ':-|' => "😐", ';-)' => "😉", '8O' => "😯", ':(' => "🙁", ':)' => "🙂", ':?' => "😕", ':D' => "😀", ':P' => "😛", ':o' => "😮", ':x' => "😡", ':|' => "😐", ';)' => "😉", ':!:' => "❗", ':?:' => "❓");
}
$wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
if (count($wpsmiliestrans) === 0) {
return;
}
krsort($wpsmiliestrans);
$spaces = wp_spaces_regexp();
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ((array) $wpsmiliestrans as $smiley => $img) {
$firstchar = substr($smiley, 0, 1);
$rest = substr($smiley, 1);
if ($firstchar !== $subchar) {
if ('' !== $subchar) {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)';
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)';
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote($rest, '/');
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
function wp_parse_args($args, $defaults = array())
{
if (is_object($args)) {
$parsed_args = get_object_vars($args);
} elseif (is_array($args)) {
$parsed_args =& $args;
} else {
wp_parse_str($args, $parsed_args);
}
if (is_array($defaults) && $defaults) {
return array_merge($defaults, $parsed_args);
}
return $parsed_args;
}
function wp_parse_list($input_list)
{
if (!is_array($input_list)) {
return preg_split('/[\\s,]+/', $input_list, -1, PREG_SPLIT_NO_EMPTY);
}
$input_list = array_filter($input_list, 'is_scalar');
return $input_list;
}
function wp_parse_id_list($input_list)
{
$input_list = wp_parse_list($input_list);
return array_unique(array_map('absint', $input_list));
}
function wp_parse_slug_list($input_list)
{
$input_list = wp_parse_list($input_list);
return array_unique(array_map('sanitize_title', $input_list));
}
function wp_array_slice_assoc($input_array, $keys)
{
$slice = array();
foreach ($keys as $key) {
if (isset($input_array[$key])) {
$slice[$key] = $input_array[$key];
}
}
return $slice;
}
function wp_recursive_ksort(&$input_array)
{
foreach ($input_array as &$value) {
if (is_array($value)) {
wp_recursive_ksort($value);
}
}
ksort($input_array);
}
function _wp_array_get($input_array, $path, $default_value = null)
{
if (!is_array($path) || 0 === count($path)) {
return $default_value;
}
foreach ($path as $path_element) {
if (!is_array($input_array)) {
return $default_value;
}
if (is_string($path_element) || is_integer($path_element) || null === $path_element) {
if (isset($input_array[$path_element])) {
$input_array = $input_array[$path_element];
continue;
}
if (array_key_exists($path_element, $input_array)) {
$input_array = $input_array[$path_element];
continue;
}
}
return $default_value;
}
return $input_array;
}
function _wp_array_set(&$input_array, $path, $value = null)
{
if (!is_array($input_array)) {
return;
}
if (!is_array($path)) {
return;
}
$path_length = count($path);
if (0 === $path_length) {
return;
}
foreach ($path as $path_element) {
if (!is_string($path_element) && !is_integer($path_element) && !is_null($path_element)) {
return;
}
}
for ($i = 0; $i < $path_length - 1; ++$i) {
$path_element = $path[$i];
if (!array_key_exists($path_element, $input_array) || !is_array($input_array[$path_element])) {
$input_array[$path_element] = array();
}
$input_array =& $input_array[$path_element];
}
$input_array[$path[$i]] = $value;
}
function _wp_to_kebab_case($input_string)
{
$rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
$rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
$rsPunctuationRange = '\\x{2000}-\\x{206f}';
$rsSpaceRange = ' \\t\\x0b\\f\\xa0\\x{feff}\\n\\r\\x{2028}\\x{2029}\\x{1680}\\x{180e}\\x{2000}\\x{2001}\\x{2002}\\x{2003}\\x{2004}\\x{2005}\\x{2006}\\x{2007}\\x{2008}\\x{2009}\\x{200a}\\x{202f}\\x{205f}\\x{3000}';
$rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
$rsBreakRange = $rsNonCharRange . $rsPunctuationRange . $rsSpaceRange;
$rsBreak = '[' . $rsBreakRange . ']';
$rsDigits = '\\d+';
$rsLower = '[' . $rsLowerRange . ']';
$rsMisc = '[^' . $rsBreakRange . $rsDigits . $rsLowerRange . $rsUpperRange . ']';
$rsUpper = '[' . $rsUpperRange . ']';
$rsMiscLower = '(?:' . $rsLower . '|' . $rsMisc . ')';
$rsMiscUpper = '(?:' . $rsUpper . '|' . $rsMisc . ')';
$rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
$rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
$regexp = '/' . implode('|', array($rsUpper . '?' . $rsLower . '+' . '(?=' . implode('|', array($rsBreak, $rsUpper, '$')) . ')', $rsMiscUpper . '+' . '(?=' . implode('|', array($rsBreak, $rsUpper . $rsMiscLower, '$')) . ')', $rsUpper . '?' . $rsMiscLower . '+', $rsUpper . '+', $rsOrdUpper, $rsOrdLower, $rsDigits)) . '/u';
preg_match_all($regexp, str_replace("'", '', $input_string), $matches);
return strtolower(implode('-', $matches[0]));
}
function wp_is_numeric_array($data)
{
if (!is_array($data)) {
return false;
}
$keys = array_keys($data);
$string_keys = array_filter($keys, 'is_string');
return count($string_keys) === 0;
}
function wp_filter_object_list($input_list, $args = array(), $operator = 'and', $field = false)
{
if (!is_array($input_list)) {
return array();
}
$util = new WP_List_Util($input_list);
$util->filter($args, $operator);
if ($field) {
$util->pluck($field);
}
return $util->get_output();
}
function wp_list_filter($input_list, $args = array(), $operator = 'AND')
{
return wp_filter_object_list($input_list, $args, $operator);
}
function wp_list_pluck($input_list, $field, $index_key = null)
{
if (!is_array($input_list)) {
return array();
}
$util = new WP_List_Util($input_list);
return $util->pluck($field, $index_key);
}
function wp_list_sort($input_list, $orderby = array(), $order = 'ASC', $preserve_keys = false)
{
if (!is_array($input_list)) {
return array();
}
$util = new WP_List_Util($input_list);
return $util->sort($orderby, $order, $preserve_keys);
}
function wp_maybe_load_widgets()
{
if (!apply_filters('load_default_widgets', true)) {
return;
}
require_once ABSPATH . WPINC . '/default-widgets.php';
add_action('_admin_menu', 'wp_widgets_add_menu');
}
function wp_widgets_add_menu()
{
global $submenu;
if (!current_theme_supports('widgets')) {
return;
}
$menu_name = __('Widgets');
if (wp_is_block_theme()) {
$submenu['themes.php'][] = array($menu_name, 'edit_theme_options', 'widgets.php');
} else {
$submenu['themes.php'][8] = array($menu_name, 'edit_theme_options', 'widgets.php');
}
ksort($submenu['themes.php'], SORT_NUMERIC);
}
function wp_ob_end_flush_all()
{
$levels = ob_get_level();
for ($i = 0; $i < $levels; $i++) {
ob_end_flush();
}
}
function dead_db()
{
global $wpdb;
wp_load_translations_early();
if (file_exists(WP_CONTENT_DIR . '/db-error.php')) {
require_once WP_CONTENT_DIR . '/db-error.php';
die;
}
if (wp_installing() || defined('WP_ADMIN')) {
wp_die($wpdb->error);
}
wp_die('<h1>' . __('Error establishing a database connection') . '</h1>', __('Database Error'));
}
function _deprecated_function($function_name, $version, $replacement = '')
{
do_action('deprecated_function_run', $function_name, $replacement, $version);
if (WP_DEBUG && apply_filters('deprecated_function_trigger_error', true)) {
if (function_exists('__')) {
if ($replacement) {
$message = sprintf(__('Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function_name, $version, $replacement);
} else {
$message = sprintf(__('Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function_name, $version);
}
} else {
if ($replacement) {
$message = sprintf('Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function_name, $version, $replacement);
} else {
$message = sprintf('Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function_name, $version);
}
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _deprecated_constructor($class_name, $version, $parent_class = '')
{
do_action('deprecated_constructor_run', $class_name, $version, $parent_class);
if (WP_DEBUG && apply_filters('deprecated_constructor_trigger_error', true)) {
if (function_exists('__')) {
if ($parent_class) {
$message = sprintf(__('The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.'), $class_name, $parent_class, $version, '<code>__construct()</code>');
} else {
$message = sprintf(__('The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $class_name, $version, '<code>__construct()</code>');
}
} else {
if ($parent_class) {
$message = sprintf('The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', $class_name, $parent_class, $version, '<code>__construct()</code>');
} else {
$message = sprintf('The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class_name, $version, '<code>__construct()</code>');
}
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _deprecated_class($class_name, $version, $replacement = '')
{
do_action('deprecated_class_run', $class_name, $replacement, $version);
if (WP_DEBUG && apply_filters('deprecated_class_trigger_error', true)) {
if (function_exists('__')) {
if ($replacement) {
$message = sprintf(__('Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $class_name, $version, $replacement);
} else {
$message = sprintf(__('Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $class_name, $version);
}
} else {
if ($replacement) {
$message = sprintf('Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class_name, $version, $replacement);
} else {
$message = sprintf('Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $class_name, $version);
}
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _deprecated_file($file, $version, $replacement = '', $message = '')
{
do_action('deprecated_file_included', $file, $replacement, $version, $message);
if (WP_DEBUG && apply_filters('deprecated_file_trigger_error', true)) {
$message = empty($message) ? '' : ' ' . $message;
if (function_exists('__')) {
if ($replacement) {
$message = sprintf(__('File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement) . $message;
} else {
$message = sprintf(__('File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version) . $message;
}
} else {
if ($replacement) {
$message = sprintf('File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement);
} else {
$message = sprintf('File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version) . $message;
}
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _deprecated_argument($function_name, $version, $message = '')
{
do_action('deprecated_argument_run', $function_name, $message, $version);
if (WP_DEBUG && apply_filters('deprecated_argument_trigger_error', true)) {
if (function_exists('__')) {
if ($message) {
$message = sprintf(__('Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function_name, $version, $message);
} else {
$message = sprintf(__('Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function_name, $version);
}
} else {
if ($message) {
$message = sprintf('Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function_name, $version, $message);
} else {
$message = sprintf('Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function_name, $version);
}
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _deprecated_hook($hook, $version, $replacement = '', $message = '')
{
do_action('deprecated_hook_run', $hook, $replacement, $version, $message);
if (WP_DEBUG && apply_filters('deprecated_hook_trigger_error', true)) {
$message = empty($message) ? '' : ' ' . $message;
if ($replacement) {
$message = sprintf(__('Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $hook, $version, $replacement) . $message;
} else {
$message = sprintf(__('Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $hook, $version) . $message;
}
wp_trigger_error('', $message, E_USER_DEPRECATED);
}
}
function _doing_it_wrong($function_name, $message, $version)
{
do_action('doing_it_wrong_run', $function_name, $message, $version);
if (WP_DEBUG && apply_filters('doing_it_wrong_trigger_error', true, $function_name, $message, $version)) {
if (function_exists('__')) {
if ($version) {
$version = sprintf(__('(This message was added in version %s.)'), $version);
}
$message .= ' ' . sprintf(__('Please see <a href="%s">Debugging in WordPress</a> for more information.'), __('https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/'));
$message = sprintf(__('Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s'), $function_name, $message, $version);
} else {
if ($version) {
$version = sprintf('(This message was added in version %s.)', $version);
}
$message .= sprintf(' Please see <a href="%s">Debugging in WordPress</a> for more information.', 'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/');
$message = sprintf('Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function_name, $message, $version);
}
wp_trigger_error('', $message);
}
}
function wp_trigger_error($function_name, $message, $error_level = E_USER_NOTICE)
{
if (!WP_DEBUG) {
return;
}
do_action('wp_trigger_error_run', $function_name, $message, $error_level);
if (!empty($function_name)) {
$message = sprintf('%s(): %s', $function_name, $message);
}
$message = wp_kses($message, array('a' => array('href' => true), 'br' => array(), 'code' => array(), 'em' => array(), 'strong' => array()), array('http', 'https'));
if (E_USER_ERROR === $error_level) {
throw new WP_Exception($message);
}
trigger_error($message, $error_level);
}
function is_lighttpd_before_150()
{
$server_parts = explode('/', isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '');
$server_parts[1] = isset($server_parts[1]) ? $server_parts[1] : '';
return 'lighttpd' === $server_parts[0] && -1 === version_compare($server_parts[1], '1.5.0');
}
function apache_mod_loaded($mod, $default_value = false)
{
global $is_apache;
if (!$is_apache) {
return false;
}
$loaded_mods = array();
if (function_exists('apache_get_modules')) {
$loaded_mods = apache_get_modules();
if (in_array($mod, $loaded_mods, true)) {
return true;
}
}
if (empty($loaded_mods) && function_exists('phpinfo') && !str_contains(ini_get('disable_functions'), 'phpinfo')) {
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_clean();
if (str_contains($phpinfo, $mod)) {
return true;
}
}
return $default_value;
}
function iis7_supports_permalinks()
{
global $is_iis7;
$supports_permalinks = false;
if ($is_iis7) {
$supports_permalinks = class_exists('DOMDocument', false) && isset($_SERVER['IIS_UrlRewriteModule']) && 'cgi-fcgi' === PHP_SAPI;
}
return apply_filters('iis7_supports_permalinks', $supports_permalinks);
}
function validate_file($file, $allowed_files = array())
{
if (!is_scalar($file) || '' === $file) {
return 0;
}
$file = wp_normalize_path($file);
$allowed_files = array_map('wp_normalize_path', $allowed_files);
if ('../' === $file) {
return 1;
}
if (preg_match_all('#\\.\\./#', $file, $matches, PREG_SET_ORDER) && count($matches) > 1) {
return 1;
}
if (str_contains($file, '../') && '../' !== mb_substr($file, -3, 3)) {
return 1;
}
if (!empty($allowed_files) && !in_array($file, $allowed_files, true)) {
return 3;
}
if (':' === substr($file, 1, 1)) {
return 2;
}
return 0;
}
function force_ssl_admin($force = null)
{
static $forced = false;
if (!is_null($force)) {
$old_forced = $forced;
$forced = (bool) $force;
return $old_forced;
}
return $forced;
}
function wp_guess_url()
{
if (defined('WP_SITEURL') && '' !== WP_SITEURL) {
$url = WP_SITEURL;
} else {
$abspath_fix = str_replace('\\', '/', ABSPATH);
$script_filename_dir = dirname($_SERVER['SCRIPT_FILENAME']);
if (str_contains($_SERVER['REQUEST_URI'], 'wp-admin') || str_contains($_SERVER['REQUEST_URI'], 'wp-login.php')) {
$path = preg_replace('#/(wp-admin/?.*|wp-login\\.php.*)#i', '', $_SERVER['REQUEST_URI']);
} elseif ($script_filename_dir . '/' === $abspath_fix) {
$path = preg_replace('#/[^/]*$#i', '', $_SERVER['PHP_SELF']);
} else {
if (str_contains($_SERVER['SCRIPT_FILENAME'], $abspath_fix)) {
$directory = str_replace(ABSPATH, '', $script_filename_dir);
$path = preg_replace('#/' . preg_quote($directory, '#') . '/[^/]*$#i', '', $_SERVER['REQUEST_URI']);
} elseif (str_contains($abspath_fix, $script_filename_dir)) {
$subdirectory = substr($abspath_fix, strpos($abspath_fix, $script_filename_dir) + strlen($script_filename_dir));
$path = preg_replace('#/[^/]*$#i', '', $_SERVER['REQUEST_URI']) . $subdirectory;
} else {
$path = $_SERVER['REQUEST_URI'];
}
}
$schema = is_ssl() ? 'https://' : 'http://';
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
return rtrim($url, '/');
}
function wp_suspend_cache_addition($suspend = null)
{
static $_suspend = false;
if (is_bool($suspend)) {
$_suspend = $suspend;
}
return $_suspend;
}
function wp_suspend_cache_invalidation($suspend = true)
{
global $_wp_suspend_cache_invalidation;
$current_suspend = $_wp_suspend_cache_invalidation;
$_wp_suspend_cache_invalidation = $suspend;
return $current_suspend;
}
function is_main_site($site_id = null, $network_id = null)
{
if (!is_multisite()) {
return true;
}
if (!$site_id) {
$site_id = get_current_blog_id();
}
$site_id = (int) $site_id;
return get_main_site_id($network_id) === $site_id;
}
function get_main_site_id($network_id = null)
{
if (!is_multisite()) {
return get_current_blog_id();
}
$network = get_network($network_id);
if (!$network) {
return 0;
}
return $network->site_id;
}
function is_main_network($network_id = null)
{
if (!is_multisite()) {
return true;
}
if (null === $network_id) {
$network_id = get_current_network_id();
}
$network_id = (int) $network_id;
return get_main_network_id() === $network_id;
}
function get_main_network_id()
{
if (!is_multisite()) {
return 1;
}
$current_network = get_network();
if (defined('PRIMARY_NETWORK_ID')) {
$main_network_id = PRIMARY_NETWORK_ID;
} elseif (isset($current_network->id) && 1 === (int) $current_network->id) {
$main_network_id = 1;
} else {
$_networks = get_networks(array('fields' => 'ids', 'number' => 1));
$main_network_id = array_shift($_networks);
}
return (int) apply_filters('get_main_network_id', $main_network_id);
}
function is_site_meta_supported()
{
global $wpdb;
if (!is_multisite()) {
return false;
}
$network_id = get_main_network_id();
$supported = get_network_option($network_id, 'site_meta_supported', false);
if (false === $supported) {
$supported = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->blogmeta}'") ? 1 : 0;
update_network_option($network_id, 'site_meta_supported', $supported);
}
return (bool) $supported;
}
function wp_timezone_override_offset()
{
$timezone_string = get_option('timezone_string');
if (!$timezone_string) {
return false;
}
$timezone_object = timezone_open($timezone_string);
$datetime_object = date_create();
if (false === $timezone_object || false === $datetime_object) {
return false;
}
return round(timezone_offset_get($timezone_object, $datetime_object) / HOUR_IN_SECONDS, 2);
}
function _wp_timezone_choice_usort_callback($a, $b)
{
if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
if (str_starts_with($a['city'], 'GMT+') && str_starts_with($b['city'], 'GMT+')) {
return -1 * strnatcasecmp($a['city'], $b['city']);
}
if ('UTC' === $a['city']) {
if (str_starts_with($b['city'], 'GMT+')) {
return 1;
}
return -1;
}
if ('UTC' === $b['city']) {
if (str_starts_with($a['city'], 'GMT+')) {
return -1;
}
return 1;
}
return strnatcasecmp($a['city'], $b['city']);
}
if ($a['t_continent'] === $b['t_continent']) {
if ($a['t_city'] === $b['t_city']) {
return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
}
return strnatcasecmp($a['t_city'], $b['t_city']);
} else {
if ('Etc' === $a['continent']) {
return 1;
}
if ('Etc' === $b['continent']) {
return -1;
}
return strnatcasecmp($a['t_continent'], $b['t_continent']);
}
}
function wp_timezone_choice($selected_zone, $locale = null)
{
static $mo_loaded = false, $locale_loaded = null;
$continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
if (!$mo_loaded || $locale !== $locale_loaded) {
$locale_loaded = $locale ? $locale : get_locale();
$mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
unload_textdomain('continents-cities', true);
load_textdomain('continents-cities', $mofile, $locale_loaded);
$mo_loaded = true;
}
$tz_identifiers = timezone_identifiers_list();
$zonen = array();
foreach ($tz_identifiers as $zone) {
$zone = explode('/', $zone);
if (!in_array($zone[0], $continents, true)) {
continue;
}
$exists = array(0 => isset($zone[0]) && $zone[0], 1 => isset($zone[1]) && $zone[1], 2 => isset($zone[2]) && $zone[2]);
$exists[3] = $exists[0] && 'Etc' !== $zone[0];
$exists[4] = $exists[1] && $exists[3];
$exists[5] = $exists[2] && $exists[3];
$zonen[] = array('continent' => $exists[0] ? $zone[0] : '', 'city' => $exists[1] ? $zone[1] : '', 'subcity' => $exists[2] ? $zone[2] : '', 't_continent' => $exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : '', 't_city' => $exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : '', 't_subcity' => $exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : '');
}
usort($zonen, '_wp_timezone_choice_usort_callback');
$structure = array();
if (empty($selected_zone)) {
$structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
}
if (in_array($selected_zone, $tz_identifiers, true) === false && in_array($selected_zone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC), true)) {
$structure[] = '<option selected="selected" value="' . esc_attr($selected_zone) . '">' . esc_html($selected_zone) . '</option>';
}
foreach ($zonen as $key => $zone) {
$value = array($zone['continent']);
if (empty($zone['city'])) {
$display = $zone['t_continent'];
} else {
if (!isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="' . esc_attr($label) . '">';
}
$value[] = $zone['city'];
$display = $zone['t_city'];
if (!empty($zone['subcity'])) {
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
}
}
$value = implode('/', $value);
$selected = '';
if ($value === $selected_zone) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . '</option>';
if (!empty($zone['city']) && (!isset($zonen[$key + 1]) || isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent'])) {
$structure[] = '</optgroup>';
}
}
$structure[] = '<optgroup label="' . esc_attr__('UTC') . '">';
$selected = '';
if ('UTC' === $selected_zone) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr('UTC') . '">' . __('UTC') . '</option>';
$structure[] = '</optgroup>';
$structure[] = '<optgroup label="' . esc_attr__('Manual Offsets') . '">';
$offset_range = array(-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
foreach ($offset_range as $offset) {
if (0 <= $offset) {
$offset_name = '+' . $offset;
} else {
$offset_name = (string) $offset;
}
$offset_value = $offset_name;
$offset_name = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $offset_name);
$offset_name = 'UTC' . $offset_name;
$offset_value = 'UTC' . $offset_value;
$selected = '';
if ($offset_value === $selected_zone) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr($offset_value) . '">' . esc_html($offset_name) . '</option>';
}
$structure[] = '</optgroup>';
return implode("\n", $structure);
}
function _cleanup_header_comment($str)
{
return trim(preg_replace('/\\s*(?:\\*\\/|\\?>).*/', '', $str));
}
function wp_scheduled_delete()
{
global $wpdb;
$delete_timestamp = time() - DAY_IN_SECONDS * EMPTY_TRASH_DAYS;
$posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp), ARRAY_A);
foreach ((array) $posts_to_delete as $post) {
$post_id = (int) $post['post_id'];
if (!$post_id) {
continue;
}
$del_post = get_post($post_id);
if (!$del_post || 'trash' !== $del_post->post_status) {
delete_post_meta($post_id, '_wp_trash_meta_status');
delete_post_meta($post_id, '_wp_trash_meta_time');
} else {
wp_delete_post($post_id);
}
}
$comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp), ARRAY_A);
foreach ((array) $comments_to_delete as $comment) {
$comment_id = (int) $comment['comment_id'];
if (!$comment_id) {
continue;
}
$del_comment = get_comment($comment_id);
if (!$del_comment || 'trash' !== $del_comment->comment_approved) {
delete_comment_meta($comment_id, '_wp_trash_meta_time');
delete_comment_meta($comment_id, '_wp_trash_meta_status');
} else {
wp_delete_comment($del_comment);
}
}
}
function get_file_data($file, $default_headers, $context = '')
{
$file_data = file_get_contents($file, false, null, 0, 8 * KB_IN_BYTES);
if (false === $file_data) {
$file_data = '';
}
$file_data = str_replace("\r", "\n", $file_data);
$extra_headers = $context ? apply_filters("extra_{$context}_headers", array()) : array();
if ($extra_headers) {
$extra_headers = array_combine($extra_headers, $extra_headers);
$all_headers = array_merge($extra_headers, (array) $default_headers);
} else {
$all_headers = $default_headers;
}
foreach ($all_headers as $field => $regex) {
if (preg_match('/^(?:[ \\t]*<\\?php)?[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
$all_headers[$field] = _cleanup_header_comment($match[1]);
} else {
$all_headers[$field] = '';
}
}
return $all_headers;
}
function __return_true()
{
return true;
}
function __return_false()
{
return false;
}
function __return_zero()
{
return 0;
}
function __return_empty_array()
{
return array();
}
function __return_null()
{
return null;
}
function __return_empty_string()
{
return '';
}
function send_nosniff_header()
{
header('X-Content-Type-Options: nosniff');
}
function _wp_mysql_week($column)
{
$start_of_week = (int) get_option('start_of_week');
switch ($start_of_week) {
case 1:
return "WEEK( {$column}, 1 )";
case 2:
case 3:
case 4:
case 5:
case 6:
return "WEEK( DATE_SUB( {$column}, INTERVAL {$start_of_week} DAY ), 0 )";
case 0:
default:
return "WEEK( {$column}, 0 )";
}
}
function wp_find_hierarchy_loop($callback, $start, $start_parent, $callback_args = array())
{
$override = is_null($start_parent) ? array() : array($start => $start_parent);
$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare($callback, $start, $override, $callback_args);
if (!$arbitrary_loop_member) {
return array();
}
return wp_find_hierarchy_loop_tortoise_hare($callback, $arbitrary_loop_member, $override, $callback_args, true);
}
function wp_find_hierarchy_loop_tortoise_hare($callback, $start, $override = array(), $callback_args = array(), $_return_loop = false)
{
$tortoise = $start;
$hare = $start;
$evanescent_hare = $start;
$return = array();
while ($tortoise && ($evanescent_hare = isset($override[$hare]) ? $override[$hare] : call_user_func_array($callback, array_merge(array($hare), $callback_args))) && ($hare = isset($override[$evanescent_hare]) ? $override[$evanescent_hare] : call_user_func_array($callback, array_merge(array($evanescent_hare), $callback_args)))) {
if ($_return_loop) {
$return[$tortoise] = true;
$return[$evanescent_hare] = true;
$return[$hare] = true;
}
if ($tortoise === $evanescent_hare || $tortoise === $hare) {
return $_return_loop ? $return : $tortoise;
}
$tortoise = isset($override[$tortoise]) ? $override[$tortoise] : call_user_func_array($callback, array_merge(array($tortoise), $callback_args));
}
return false;
}
function send_frame_options_header()
{
header('X-Frame-Options: SAMEORIGIN');
}
function wp_admin_headers()
{
$policy = 'strict-origin-when-cross-origin';
$policy = apply_filters('admin_referrer_policy', $policy);
header(sprintf('Referrer-Policy: %s', $policy));
}
function wp_allowed_protocols()
{
static $protocols = array();
if (empty($protocols)) {
$protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'irc6', 'ircs', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn');
}
if (!did_action('wp_loaded')) {
$protocols = array_unique((array) apply_filters('kses_allowed_protocols', $protocols));
}
return $protocols;
}
function wp_debug_backtrace_summary($ignore_class = null, $skip_frames = 0, $pretty = true)
{
static $truncate_paths;
$trace = debug_backtrace(false);
$caller = array();
$check_class = !is_null($ignore_class);
++$skip_frames;
if (!isset($truncate_paths)) {
$truncate_paths = array(wp_normalize_path(WP_CONTENT_DIR), wp_normalize_path(ABSPATH));
}
foreach ($trace as $call) {
if ($skip_frames > 0) {
--$skip_frames;
} elseif (isset($call['class'])) {
if ($check_class && $ignore_class === $call['class']) {
continue;
}
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
} else {
if (in_array($call['function'], array('do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array'), true)) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif (in_array($call['function'], array('include', 'include_once', 'require', 'require_once'), true)) {
$filename = isset($call['args'][0]) ? $call['args'][0] : '';
$caller[] = $call['function'] . "('" . str_replace($truncate_paths, '', wp_normalize_path($filename)) . "')";
} else {
$caller[] = $call['function'];
}
}
}
if ($pretty) {
return implode(', ', array_reverse($caller));
} else {
return $caller;
}
}
function _get_non_cached_ids($object_ids, $cache_group)
{
$object_ids = array_filter($object_ids, '_validate_cache_id');
$object_ids = array_unique(array_map('intval', $object_ids), SORT_NUMERIC);
if (empty($object_ids)) {
return array();
}
$non_cached_ids = array();
$cache_values = wp_cache_get_multiple($object_ids, $cache_group);
foreach ($cache_values as $id => $value) {
if (false === $value) {
$non_cached_ids[] = (int) $id;
}
}
return $non_cached_ids;
}
function _validate_cache_id($object_id)
{
if (is_int($object_id) || is_string($object_id) && (string) (int) $object_id === $object_id) {
return true;
}
$message = sprintf(__('Object ID must be an integer, %s given.'), gettype($object_id));
_doing_it_wrong('_get_non_cached_ids', $message, '6.3.0');
return false;
}
function _device_can_upload()
{
if (!wp_is_mobile()) {
return true;
}
$ua = $_SERVER['HTTP_USER_AGENT'];
if (str_contains($ua, 'iPhone') || str_contains($ua, 'iPad') || str_contains($ua, 'iPod')) {
return preg_match('#OS ([\\d_]+) like Mac OS X#', $ua, $version) && version_compare($version[1], '6', '>=');
}
return true;
}
function wp_is_stream($path)
{
$scheme_separator = strpos($path, '://');
if (false === $scheme_separator) {
return false;
}
$stream = substr($path, 0, $scheme_separator);
return in_array($stream, stream_get_wrappers(), true);
}
function wp_checkdate($month, $day, $year, $source_date)
{
return apply_filters('wp_checkdate', checkdate($month, $day, $year), $source_date);
}
function wp_auth_check_load()
{
if (!is_admin() && !is_user_logged_in()) {
return;
}
if (defined('IFRAME_REQUEST')) {
return;
}
$screen = get_current_screen();
$hidden = array('update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network');
$show = !in_array($screen->id, $hidden, true);
if (apply_filters('wp_auth_check_load', $show, $screen)) {
wp_enqueue_style('wp-auth-check');
wp_enqueue_script('wp-auth-check');
add_action('admin_print_footer_scripts', 'wp_auth_check_html', 5);
add_action('wp_print_footer_scripts', 'wp_auth_check_html', 5);
}
}
function wp_auth_check_html()
{
$login_url = wp_login_url();
$current_domain = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
$same_domain = str_starts_with($login_url, $current_domain);
$same_domain = apply_filters('wp_auth_check_same_domain', $same_domain);
$wrap_class = $same_domain ? 'hidden' : 'hidden fallback';
?>
<div id="wp-auth-check-wrap" class="<?php
echo $wrap_class;
?>">
<div id="wp-auth-check-bg"></div>
<div id="wp-auth-check">
<button type="button" class="wp-auth-check-close button-link"><span class="screen-reader-text">
<?php
_e('Close dialog');
?>
</span></button>
<?php
if ($same_domain) {
$login_src = add_query_arg(array('interim-login' => '1', 'wp_lang' => get_user_locale()), $login_url);
?>
<div id="wp-auth-check-form" class="loading" data-src="<?php
echo esc_url($login_src);
?>"></div>
<?php
}
?>
<div class="wp-auth-fallback">
<p><b class="wp-auth-fallback-expired" tabindex="0"><?php
_e('Session expired');
?></b></p>
<p><a href="<?php
echo esc_url($login_url);
?>" target="_blank"><?php
_e('Please log in again.');
?></a>
<?php
_e('The login page will open in a new tab. After logging in you can close it and return to this page.');
?></p>
</div>
</div>
</div>
<?php
}
function wp_auth_check($response)
{
$response['wp-auth-check'] = is_user_logged_in() && empty($GLOBALS['login_grace_period']);
return $response;
}
function get_tag_regex($tag)
{
if (empty($tag)) {
return '';
}
return sprintf('<%1$s[^<]*(?:>[\\s\\S]*<\\/%1$s>|\\s*\\/>)', tag_escape($tag));
}
function is_utf8_charset($blog_charset = null)
{
return _is_utf8_charset($blog_charset ?? get_option('blog_charset'));
}
function _canonical_charset($charset)
{
if (is_utf8_charset($charset)) {
return 'UTF-8';
}
if (0 === strcasecmp('iso-8859-1', $charset) || 0 === strcasecmp('iso8859-1', $charset)) {
return 'ISO-8859-1';
}
return $charset;
}
function mbstring_binary_safe_encoding($reset = false)
{
static $encodings = array();
static $overloaded = null;
if (is_null($overloaded)) {
if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
$overloaded = true;
} else {
$overloaded = false;
}
}
if (false === $overloaded) {
return;
}
if (!$reset) {
$encoding = mb_internal_encoding();
array_push($encodings, $encoding);
mb_internal_encoding('ISO-8859-1');
}
if ($reset && $encodings) {
$encoding = array_pop($encodings);
mb_internal_encoding($encoding);
}
}
function reset_mbstring_encoding()
{
mbstring_binary_safe_encoding(true);
}
function wp_validate_boolean($value)
{
if (is_bool($value)) {
return $value;
}
if (is_string($value) && 'false' === strtolower($value)) {
return false;
}
return (bool) $value;
}
function wp_delete_file($file)
{
$delete = apply_filters('wp_delete_file', $file);
if (!empty($delete)) {
return @unlink($delete);
}
return false;
}
function wp_delete_file_from_directory($file, $directory)
{
if (wp_is_stream($file)) {
$real_file = $file;
$real_directory = $directory;
} else {
$real_file = realpath(wp_normalize_path($file));
$real_directory = realpath(wp_normalize_path($directory));
}
if (false !== $real_file) {
$real_file = wp_normalize_path($real_file);
}
if (false !== $real_directory) {
$real_directory = wp_normalize_path($real_directory);
}
if (false === $real_file || false === $real_directory || !str_starts_with($real_file, trailingslashit($real_directory))) {
return false;
}
return wp_delete_file($file);
}
function wp_post_preview_js()
{
global $post;
if (!is_preview() || empty($post)) {
return;
}
$name = 'wp-preview-' . (int) $post->ID;
ob_start();
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php
echo $name;
?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'pagehide', function() { window.name = ''; } );
}
}());
</script>
<?php
wp_print_inline_script_tag(wp_remove_surrounding_empty_script_tags(ob_get_clean()));
}
function mysql_to_rfc3339($date_string)
{
return mysql2date('Y-m-d\\TH:i:s', $date_string, false);
}
function wp_raise_memory_limit($context = 'admin')
{
if (false === wp_is_ini_value_changeable('memory_limit')) {
return false;
}
$current_limit = ini_get('memory_limit');
$current_limit_int = wp_convert_hr_to_bytes($current_limit);
if (-1 === $current_limit_int) {
return false;
}
$wp_max_limit = WP_MAX_MEMORY_LIMIT;
$wp_max_limit_int = wp_convert_hr_to_bytes($wp_max_limit);
$filtered_limit = $wp_max_limit;
switch ($context) {
case 'admin':
$filtered_limit = apply_filters('admin_memory_limit', $filtered_limit);
break;
case 'image':
$filtered_limit = apply_filters('image_memory_limit', $filtered_limit);
break;
case 'cron':
$filtered_limit = apply_filters('cron_memory_limit', $filtered_limit);
break;
default:
$filtered_limit = apply_filters("{$context}_memory_limit", $filtered_limit);
break;
}
$filtered_limit_int = wp_convert_hr_to_bytes($filtered_limit);
if (-1 === $filtered_limit_int || $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int) {
if (false !== ini_set('memory_limit', $filtered_limit)) {
return $filtered_limit;
} else {
return false;
}
} elseif (-1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int) {
if (false !== ini_set('memory_limit', $wp_max_limit)) {
return $wp_max_limit;
} else {
return false;
}
}
return false;
}
function wp_generate_uuid4()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
}
function wp_is_uuid($uuid, $version = null)
{
if (!is_string($uuid)) {
return false;
}
if (is_numeric($version)) {
if (4 !== (int) $version) {
_doing_it_wrong(__FUNCTION__, __('Only UUID V4 is supported at this time.'), '4.9.0');
return false;
}
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
} else {
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
}
return (bool) preg_match($regex, $uuid);
}
function wp_unique_id($prefix = '')
{
static $id_counter = 0;
return $prefix . (string) ++$id_counter;
}
function wp_unique_prefixed_id($prefix = '')
{
static $id_counters = array();
if (!is_string($prefix)) {
wp_trigger_error(__FUNCTION__, sprintf('The prefix must be a string. "%s" data type given.', gettype($prefix)));
$prefix = '';
}
if (!isset($id_counters[$prefix])) {
$id_counters[$prefix] = 0;
}
$id = ++$id_counters[$prefix];
return $prefix . (string) $id;
}
function wp_cache_get_last_changed($group)
{
$last_changed = wp_cache_get('last_changed', $group);
if ($last_changed) {
return $last_changed;
}
return wp_cache_set_last_changed($group);
}
function wp_cache_set_last_changed($group)
{
$previous_time = wp_cache_get('last_changed', $group);
$time = microtime();
wp_cache_set('last_changed', $time, $group);
do_action('wp_cache_set_last_changed', $group, $time, $previous_time);
return $time;
}
function wp_site_admin_email_change_notification($old_email, $new_email, $option_name)
{
$send = true;
if ('you@example.com' === $old_email) {
$send = false;
}
$send = apply_filters('send_site_admin_email_change_email', $send, $old_email, $new_email);
if (!$send) {
return;
}
$email_change_text = __('Hi,
This notice confirms that the admin email address was changed on ###SITENAME###.
The new admin email address is ###NEW_EMAIL###.
This email has been sent to ###OLD_EMAIL###
Regards,
All at ###SITENAME###
###SITEURL###');
$email_change_email = array('to' => $old_email, 'subject' => __('[%s] Admin Email Changed'), 'message' => $email_change_text, 'headers' => '');
$site_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$email_change_email = apply_filters('site_admin_email_change_email', $email_change_email, $old_email, $new_email);
$email_change_email['message'] = str_replace('###OLD_EMAIL###', $old_email, $email_change_email['message']);
$email_change_email['message'] = str_replace('###NEW_EMAIL###', $new_email, $email_change_email['message']);
$email_change_email['message'] = str_replace('###SITENAME###', $site_name, $email_change_email['message']);
$email_change_email['message'] = str_replace('###SITEURL###', home_url(), $email_change_email['message']);
wp_mail($email_change_email['to'], sprintf($email_change_email['subject'], $site_name), $email_change_email['message'], $email_change_email['headers']);
}
function wp_privacy_anonymize_ip($ip_addr, $ipv6_fallback = false)
{
if (empty($ip_addr)) {
return '0.0.0.0';
}
$ip_prefix = '';
$is_ipv6 = substr_count($ip_addr, ':') > 1;
$is_ipv4 = 3 === substr_count($ip_addr, '.');
if ($is_ipv6 && $is_ipv4) {
$ip_prefix = '::ffff:';
$ip_addr = preg_replace('/^\\[?[0-9a-f:]*:/i', '', $ip_addr);
$ip_addr = str_replace(']', '', $ip_addr);
$is_ipv6 = false;
}
if ($is_ipv6) {
$left_bracket = strpos($ip_addr, '[');
$right_bracket = strpos($ip_addr, ']');
$percent = strpos($ip_addr, '%');
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
if (false !== $left_bracket && false !== $right_bracket) {
$ip_addr = substr($ip_addr, $left_bracket + 1, $right_bracket - $left_bracket - 1);
} elseif (false !== $left_bracket || false !== $right_bracket) {
return '::';
}
if (false !== $percent) {
$ip_addr = substr($ip_addr, 0, $percent);
}
if (preg_match('/[^0-9a-f:]/i', $ip_addr)) {
return '::';
}
if (function_exists('inet_pton') && function_exists('inet_ntop')) {
$ip_addr = inet_ntop(inet_pton($ip_addr) & inet_pton($netmask));
if (false === $ip_addr) {
return '::';
}
} elseif (!$ipv6_fallback) {
return '::';
}
} elseif ($is_ipv4) {
$last_octet_position = strrpos($ip_addr, '.');
$ip_addr = substr($ip_addr, 0, $last_octet_position) . '.0';
} else {
return '0.0.0.0';
}
return $ip_prefix . $ip_addr;
}
function wp_privacy_anonymize_data($type, $data = '')
{
switch ($type) {
case 'email':
$anonymous = 'deleted@site.invalid';
break;
case 'url':
$anonymous = 'https://site.invalid';
break;
case 'ip':
$anonymous = wp_privacy_anonymize_ip($data);
break;
case 'date':
$anonymous = '0000-00-00 00:00:00';
break;
case 'text':
$anonymous = __('[deleted]');
break;
case 'longtext':
$anonymous = __('This content was deleted by the author.');
break;
default:
$anonymous = '';
break;
}
return apply_filters('wp_privacy_anonymize_data', $anonymous, $type, $data);
}
function wp_privacy_exports_dir()
{
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit($upload_dir['basedir']) . 'wp-personal-data-exports/';
return apply_filters('wp_privacy_exports_dir', $exports_dir);
}
function wp_privacy_exports_url()
{
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit($upload_dir['baseurl']) . 'wp-personal-data-exports/';
return apply_filters('wp_privacy_exports_url', $exports_url);
}
function wp_schedule_delete_old_privacy_export_files()
{
if (wp_installing()) {
return;
}
if (!wp_next_scheduled('wp_privacy_delete_old_export_files')) {
wp_schedule_event(time(), 'hourly', 'wp_privacy_delete_old_export_files');
}
}
function wp_privacy_delete_old_export_files()
{
$exports_dir = wp_privacy_exports_dir();
if (!is_dir($exports_dir)) {
return;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
$export_files = list_files($exports_dir, 100, array('index.php'));
$expiration = apply_filters('wp_privacy_export_expiration', 3 * DAY_IN_SECONDS);
foreach ((array) $export_files as $export_file) {
$file_age_in_seconds = time() - filemtime($export_file);
if ($expiration < $file_age_in_seconds) {
unlink($export_file);
}
}
}
function wp_get_update_php_url()
{
$default_url = wp_get_default_update_php_url();
$update_url = $default_url;
if (false !== getenv('WP_UPDATE_PHP_URL')) {
$update_url = getenv('WP_UPDATE_PHP_URL');
}
$update_url = apply_filters('wp_update_php_url', $update_url);
if (empty($update_url)) {
$update_url = $default_url;
}
return $update_url;
}
function wp_get_default_update_php_url()
{
return _x('https://wordpress.org/support/update-php/', 'localized PHP upgrade information page');
}
function wp_update_php_annotation($before = '<p class="description">', $after = '</p>', $display = true)
{
$annotation = wp_get_update_php_annotation();
if ($annotation) {
if ($display) {
echo $before . $annotation . $after;
} else {
return $before . $annotation . $after;
}
}
}
function wp_get_update_php_annotation()
{
$update_url = wp_get_update_php_url();
$default_url = wp_get_default_update_php_url();
if ($update_url === $default_url) {
return '';
}
$annotation = sprintf(__('This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.'), esc_url($default_url));
return $annotation;
}
function wp_get_direct_php_update_url()
{
$direct_update_url = '';
if (false !== getenv('WP_DIRECT_UPDATE_PHP_URL')) {
$direct_update_url = getenv('WP_DIRECT_UPDATE_PHP_URL');
}
$direct_update_url = apply_filters('wp_direct_php_update_url', $direct_update_url);
return $direct_update_url;
}
function wp_direct_php_update_button()
{
$direct_update_url = wp_get_direct_php_update_url();
if (empty($direct_update_url)) {
return;
}
echo '<p class="button-container">';
printf('<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', esc_url($direct_update_url), __('Update PHP'), __('(opens in a new tab)'));
echo '</p>';
}
function wp_get_update_https_url()
{
$default_url = wp_get_default_update_https_url();
$update_url = $default_url;
if (false !== getenv('WP_UPDATE_HTTPS_URL')) {
$update_url = getenv('WP_UPDATE_HTTPS_URL');
}
$update_url = apply_filters('wp_update_https_url', $update_url);
if (empty($update_url)) {
$update_url = $default_url;
}
return $update_url;
}
function wp_get_default_update_https_url()
{
return __('https://developer.wordpress.org/advanced-administration/security/https/');
}
function wp_get_direct_update_https_url()
{
$direct_update_url = '';
if (false !== getenv('WP_DIRECT_UPDATE_HTTPS_URL')) {
$direct_update_url = getenv('WP_DIRECT_UPDATE_HTTPS_URL');
}
$direct_update_url = apply_filters('wp_direct_update_https_url', $direct_update_url);
return $direct_update_url;
}
function get_dirsize($directory, $max_execution_time = null)
{
if (is_multisite() && is_main_site()) {
$size = recurse_dirsize($directory, $directory . '/sites', $max_execution_time);
} else {
$size = recurse_dirsize($directory, null, $max_execution_time);
}
return $size;
}
function recurse_dirsize($directory, $exclude = null, $max_execution_time = null, &$directory_cache = null)
{
$directory = untrailingslashit($directory);
$save_cache = false;
if (!isset($directory_cache)) {
$directory_cache = get_transient('dirsize_cache');
$save_cache = true;
}
if (isset($directory_cache[$directory]) && is_int($directory_cache[$directory])) {
return $directory_cache[$directory];
}
if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
return false;
}
if (is_string($exclude) && $directory === $exclude || is_array($exclude) && in_array($directory, $exclude, true)) {
return false;
}
if (null === $max_execution_time) {
if (function_exists('ini_get')) {
$max_execution_time = ini_get('max_execution_time');
} else {
$max_execution_time = 0;
}
if ($max_execution_time > 10) {
$max_execution_time -= 1;
}
}
$size = apply_filters('pre_recurse_dirsize', false, $directory, $exclude, $max_execution_time, $directory_cache);
if (false === $size) {
$size = 0;
$handle = opendir($directory);
if ($handle) {
while (($file = readdir($handle)) !== false) {
$path = $directory . '/' . $file;
if ('.' !== $file && '..' !== $file) {
if (is_file($path)) {
$size += filesize($path);
} elseif (is_dir($path)) {
$handlesize = recurse_dirsize($path, $exclude, $max_execution_time, $directory_cache);
if ($handlesize > 0) {
$size += $handlesize;
}
}
if ($max_execution_time > 0 && microtime(true) - WP_START_TIMESTAMP > $max_execution_time) {
$size = null;
break;
}
}
}
closedir($handle);
}
}
if (!is_array($directory_cache)) {
$directory_cache = array();
}
$directory_cache[$directory] = $size;
if ($save_cache) {
$expiration = wp_using_ext_object_cache() ? 0 : 10 * YEAR_IN_SECONDS;
set_transient('dirsize_cache', $directory_cache, $expiration);
}
return $size;
}
function clean_dirsize_cache($path)
{
if (!is_string($path) || empty($path)) {
wp_trigger_error('', sprintf(__('%1$s only accepts a non-empty path string, received %2$s.'), '<code>clean_dirsize_cache()</code>', '<code>' . gettype($path) . '</code>'));
return;
}
$directory_cache = get_transient('dirsize_cache');
if (empty($directory_cache)) {
return;
}
$expiration = wp_using_ext_object_cache() ? 0 : 10 * YEAR_IN_SECONDS;
if (!str_contains($path, '/') && !str_contains($path, '\\')) {
unset($directory_cache[$path]);
set_transient('dirsize_cache', $directory_cache, $expiration);
return;
}
$last_path = null;
$path = untrailingslashit($path);
unset($directory_cache[$path]);
while ($last_path !== $path && DIRECTORY_SEPARATOR !== $path && '.' !== $path && '..' !== $path) {
$last_path = $path;
$path = dirname($path);
unset($directory_cache[$path]);
}
set_transient('dirsize_cache', $directory_cache, $expiration);
}
function wp_get_wp_version()
{
static $wp_version;
if (!isset($wp_version)) {
require ABSPATH . WPINC . '/version.php';
}
return $wp_version;
}
function is_wp_version_compatible($required)
{
if (defined('WP_RUN_CORE_TESTS') && WP_RUN_CORE_TESTS && isset($GLOBALS['_wp_tests_wp_version'])) {
$wp_version = $GLOBALS['_wp_tests_wp_version'];
} else {
$wp_version = wp_get_wp_version();
}
list($version) = explode('-', $wp_version);
if (is_string($required)) {
$trimmed = trim($required);
if (substr_count($trimmed, '.') > 1 && str_ends_with($trimmed, '.0')) {
$required = substr($trimmed, 0, -2);
}
}
return empty($required) || version_compare($version, $required, '>=');
}
function is_php_version_compatible($required)
{
return empty($required) || version_compare(PHP_VERSION, $required, '>=');
}
function wp_fuzzy_number_match($expected, $actual, $precision = 1)
{
return abs((float) $expected - (float) $actual) <= $precision;
}
function wp_get_admin_notice($message, $args = array())
{
$defaults = array('type' => '', 'dismissible' => false, 'id' => '', 'additional_classes' => array(), 'attributes' => array(), 'paragraph_wrap' => true);
$args = wp_parse_args($args, $defaults);
$args = apply_filters('wp_admin_notice_args', $args, $message);
$id = '';
$classes = 'notice';
$attributes = '';
if (is_string($args['id'])) {
$trimmed_id = trim($args['id']);
if ('' !== $trimmed_id) {
$id = 'id="' . $trimmed_id . '" ';
}
}
if (is_string($args['type'])) {
$type = trim($args['type']);
if (str_contains($type, ' ')) {
_doing_it_wrong(__FUNCTION__, sprintf(__('The %s key must be a string without spaces.'), '<code>type</code>'), '6.4.0');
}
if ('' !== $type) {
$classes .= ' notice-' . $type;
}
}
if (true === $args['dismissible']) {
$classes .= ' is-dismissible';
}
if (is_array($args['additional_classes']) && !empty($args['additional_classes'])) {
$classes .= ' ' . implode(' ', $args['additional_classes']);
}
if (is_array($args['attributes']) && !empty($args['attributes'])) {
$attributes = '';
foreach ($args['attributes'] as $attr => $val) {
if (is_bool($val)) {
$attributes .= $val ? ' ' . $attr : '';
} elseif (is_int($attr)) {
$attributes .= ' ' . esc_attr(trim($val));
} elseif ($val) {
$attributes .= ' ' . $attr . '="' . esc_attr(trim($val)) . '"';
}
}
}
if (false !== $args['paragraph_wrap']) {
$message = "<p>{$message}</p>";
}
$markup = sprintf('<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message);
return apply_filters('wp_admin_notice_markup', $markup, $message, $args);
}
function wp_admin_notice($message, $args = array())
{
do_action('wp_admin_notice', $message, $args);
echo wp_kses_post(wp_get_admin_notice($message, $args));
}
function wp_is_heic_image_mime_type($mime_type)
{
$heic_mime_types = array('image/heic', 'image/heif', 'image/heic-sequence', 'image/heif-sequence');
return in_array($mime_type, $heic_mime_types, true);
}
function wp_fast_hash(string $message) : string
{
$hashed = sodium_crypto_generichash($message, 'wp_fast_hash_6.8+', 30);
return '$generic$' . sodium_bin2base64($hashed, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING);
}
function wp_verify_fast_hash(string $message, string $hash) : bool
{
if (!str_starts_with($hash, '$generic$')) {
require_once ABSPATH . WPINC . '/class-phpass.php';
return (new PasswordHash(8, true))->CheckPassword($message, $hash);
}
return hash_equals($hash, wp_fast_hash($message));
}
function wp_unique_id_from_values(array $data, string $prefix = '') : string
{
if (empty($data)) {
_doing_it_wrong(__FUNCTION__, sprintf(__('The %s argument must not be empty.'), '$data'), '6.8.0');
}
$serialized = wp_json_encode($data);
$hash = substr(md5($serialized), 0, 8);
return $prefix . $hash;
}