';
+ $redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
+ $html .= sprintf( __( "Do you really want to log out?"), wp_logout_url( $redirect_to ) );
+ } else {
+ $html = __( 'Are you sure you want to do this?' );
+ if ( wp_get_referer() )
+ $html .= "
" . __( 'Please try again.' ) . "";
+ }
+
+ wp_die( $html, __( 'WordPress Failure Notice' ), 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 {@see WP_Error} object,
+ * 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 500.
+ * @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 {@see 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 ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
+ /**
+ * Filter 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 ) {
+ /**
+ * Filter 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 {
+ /**
+ * Filter 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 );
+}
+
+/**
+ * Kill 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 wp_die_handler filter in wp_die
+ *
+ * @since 3.0.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 _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 = "
";
+ }
+
+ 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';
+?>
+
+
+>
+
+
+
+
+
+
+
+
+
+
+
+ 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();
}
/**
- * Retrieve a modified URL query string.
+ * Kill WordPress ajax execution.
*
- * You can rebuild the URL and append a new query variable to the URL query by
- * using this function. You can also retrieve the full URL with query data.
+ * This is the handler for wp_die when processing Ajax requests.
*
- * Adding a single key & value or an associative array. Setting a key value to
- * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
- * value.
+ * @since 3.4.0
+ * @access private
*
- * @since 1.5.0
+ * @param string $message Optional. Response to print. Default empty.
+ */
+function _ajax_wp_die_handler( $message = '' ) {
+ if ( is_scalar( $message ) )
+ die( (string) $message );
+ die( '0' );
+}
+
+/**
+ * Kill WordPress execution.
*
- * @param mixed $param1 Either newkey or an associative_array
- * @param mixed $param2 Either newvalue or oldquery or uri
- * @param mixed $param3 Optional. Old query or uri
- * @return string New URL query string.
+ * 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 add_query_arg() {
- $ret = '';
- if ( is_array( func_get_arg(0) ) ) {
- if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
- $uri = $_SERVER['REQUEST_URI'];
- else
- $uri = @func_get_arg( 1 );
+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 {
- if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
- $uri = $_SERVER['REQUEST_URI'];
- else
- $uri = @func_get_arg( 2 );
+ $args = array( $data );
}
- if ( $frag = strstr( $uri, '#' ) )
- $uri = substr( $uri, 0, -strlen( $frag ) );
- else
- $frag = '';
+ // Prepare the data for JSON serialization.
+ $data = _wp_json_prepare_data( $data );
- if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
- $protocol = $matches[0];
- $uri = substr( $uri, strlen( $protocol ) );
- } else {
- $protocol = '';
+ $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;
}
- if ( strpos( $uri, '?' ) !== false ) {
- $parts = explode( '?', $uri, 2 );
- if ( 1 == count( $parts ) ) {
- $base = '?';
- $query = $parts[0];
- } else {
- $base = $parts[0] . '?';
- $query = $parts[1];
- }
- } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
- $base = $uri . '?';
- $query = '';
- } else {
- $base = '';
- $query = $uri;
+ try {
+ $args[0] = _wp_json_sanity_check( $data, $depth );
+ } catch ( Exception $e ) {
+ return false;
}
- wp_parse_str( $query, $qs );
- $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
- if ( is_array( func_get_arg( 0 ) ) ) {
- $kayvees = func_get_arg( 0 );
- $qs = array_merge( $qs, $kayvees );
- } else {
- $qs[func_get_arg( 0 )] = func_get_arg( 1 );
+ 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' );
}
- foreach ( (array) $qs as $k => $v ) {
- if ( $v === false )
- unset( $qs[$k] );
+ 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;
}
- $ret = build_query( $qs );
- $ret = trim( $ret, '?' );
- $ret = preg_replace( '#=(&|$)#', '$1', $ret );
- $ret = $protocol . $base . $ret . $frag;
- $ret = rtrim( $ret, '?' );
- return $ret;
+ return $output;
}
/**
- * Removes an item or list from the query string.
+ * Convert a string to UTF-8, so that it can be safely encoded to JSON.
*
- * @since 1.5.0
+ * @ignore
+ * @since 4.1.0
+ * @access private
*
- * @param string|array $key Query key or keys to remove.
- * @param bool $query When false uses the $_SERVER value.
- * @return string New URL query string.
+ * @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 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;
+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 );
}
- return add_query_arg( $key, false, $query );
}
/**
- * Walks the array while sanitizing the contents.
+ * Prepares response data to be serialized to JSON.
*
- * @uses $wpdb Used to sanitize values
- * @since 0.71
+ * This supports the JsonSerializable interface for PHP 5.2-5.3 as well.
*
- * @param array $array Array to used to walk while sanitizing contents.
- * @return array Sanitized $array.
+ * @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 add_magic_quotes( $array ) {
- global $wpdb;
+function _wp_json_prepare_data( $data ) {
+ if ( ! defined( 'WP_JSON_SERIALIZE_COMPATIBLE' ) || WP_JSON_SERIALIZE_COMPATIBLE === false ) {
+ return $data;
+ }
- foreach ( (array) $array as $k => $v ) {
- if ( is_array( $v ) ) {
- $array[$k] = add_magic_quotes( $v );
- } else {
- $array[$k] = $wpdb->escape( $v );
- }
+ 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;
}
- return $array;
}
/**
- * HTTP request for URI to retrieve content.
+ * Send a JSON response back to an Ajax request.
*
- * @since 1.5.1
- * @uses wp_remote_get()
+ * @since 3.5.0
*
- * @param string $uri URI/URL of web page to retrieve.
- * @return bool|string HTTP content. False on failure.
+ * @param mixed $response Variable (usually an array or object) to encode as JSON,
+ * then print and die.
*/
-function wp_remote_fopen( $uri ) {
- $parsed_url = @parse_url( $uri );
+function wp_send_json( $response ) {
+ @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
+ echo wp_json_encode( $response );
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
+ wp_die();
+ else
+ die;
+}
- if ( !$parsed_url || !is_array( $parsed_url ) )
- return false;
+/**
+ * Send a JSON response back to an Ajax request, indicating success.
+ *
+ * @since 3.5.0
+ *
+ * @param mixed $data Data to encode as JSON, then print and die.
+ */
+function wp_send_json_success( $data = null ) {
+ $response = array( 'success' => true );
- $options = array();
- $options['timeout'] = 10;
+ if ( isset( $data ) )
+ $response['data'] = $data;
- $response = wp_remote_get( $uri, $options );
+ wp_send_json( $response );
+}
- if ( is_wp_error( $response ) )
- return false;
+/**
+ * Send a JSON response back to an Ajax request, indicating failure.
+ *
+ * If the `$data` parameter is a {@see 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 {@see WP_Error}
+ * object is passed in.
+ *
+ * @param mixed $data Data to encode as JSON, then print and die.
+ */
+function wp_send_json_error( $data = 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;
+ }
+ }
- return $response['body'];
+ wp_send_json( $response );
}
/**
- * Setup the WordPress query.
+ * Retrieve the WordPress home page URL.
*
- * @since 2.0.0
+ * 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 $query_vars Default WP_Query arguments.
+ * @param string $url URL for the home location.
+ * @return string Homepage location.
*/
-function wp( $query_vars = '' ) {
- global $wp, $wp_query, $wp_the_query;
- $wp->main( $query_vars );
+function _config_wp_home( $url = '' ) {
+ if ( defined( 'WP_HOME' ) )
+ return untrailingslashit( WP_HOME );
+ return $url;
+}
- if( !isset($wp_the_query) )
- $wp_the_query = $wp_query;
+/**
+ * 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;
}
/**
- * Retrieve the description for the HTTP status.
+ * Set the localized direction for MCE plugin.
*
- * @since 2.3.0
+ * Will only set the direction to 'rtl', if the WordPress locale has
+ * the text direction set to 'rtl'.
*
- * @param int $code HTTP status code.
- * @return string Empty string if not found, or description if found.
+ * 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 $input (TinyMCE settings) array.
+ *
+ * @since 2.1.0
+ * @access private
+ *
+ * @param array $input MCE settings array.
+ * @return array Direction set for 'rtl', if needed by locale.
*/
-function get_status_header_desc( $code ) {
- global $wp_header_to_desc;
+function _mce_set_direction( $input ) {
+ if ( is_rtl() ) {
+ $input['directionality'] = 'rtl';
- $code = absint( $code );
+ if ( ! empty( $input['plugins'] ) && strpos( $input['plugins'], 'directionality' ) === false ) {
+ $input['plugins'] .= ',directionality';
+ }
- if ( !isset( $wp_header_to_desc ) ) {
- $wp_header_to_desc = array(
- 100 => 'Continue',
- 101 => 'Switching Protocols',
+ if ( ! empty( $input['toolbar1'] ) && ! preg_match( '/\bltr\b/', $input['toolbar1'] ) ) {
+ $input['toolbar1'] .= ',ltr';
+ }
+ }
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
+ return $input;
+}
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 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',
+/**
+ * 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;
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported'
+ // 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:' => 'simple-smile.png',
+ ':???:' => "\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:' => 'rolleyes.png',
+ ':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:' => 'frownie.png',
+ '8-)' => "\xf0\x9f\x98\x8e",
+ '8-O' => "\xf0\x9f\x98\xaf",
+ ':-(' => 'frownie.png',
+ ':-)' => 'simple-smile.png',
+ ':-?' => "\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",
+ ':(' => 'frownie.png',
+ ':)' => 'simple-smile.png',
+ ':?' => "\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",
);
}
- if ( isset( $wp_header_to_desc[$code] ) )
- return $wp_header_to_desc[$code];
- else
- return '';
+ 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';
+
}
/**
- * Set HTTP status header.
+ * Merge user defined arguments into defaults array.
*
- * @since 2.0.0
- * @uses apply_filters() Calls 'status_header' on status header string, HTTP
- * HTTP code, HTTP code description, and protocol string as separate
- * parameters.
+ * This function is used throughout WordPress to allow for both string or array
+ * to be merged into another array.
+ *
+ * @since 2.2.0
*
- * @param int $header HTTP status code
- * @return null Does not return anything.
+ * @param string|array $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 status_header( $header ) {
- $text = get_status_header_desc( $header );
-
- if ( empty( $text ) )
- return false;
-
- $protocol = $_SERVER["SERVER_PROTOCOL"];
- if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
- $protocol = 'HTTP/1.0';
- $status_header = "$protocol $header $text";
- if ( function_exists( 'apply_filters' ) )
- $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
-
- if ( version_compare( phpversion(), '4.3.0', '>=' ) )
- return @header( $status_header, true, $header );
+function wp_parse_args( $args, $defaults = '' ) {
+ if ( is_object( $args ) )
+ $r = get_object_vars( $args );
+ elseif ( is_array( $args ) )
+ $r =& $args;
else
- return @header( $status_header );
+ wp_parse_str( $args, $r );
+
+ if ( is_array( $defaults ) )
+ return array_merge( $defaults, $r );
+ return $r;
}
/**
- * Sets the headers to prevent caching for the different browsers.
+ * Clean up an array, comma- or space-separated list of IDs.
*
- * 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 3.0.0
*
- * @since 2.0.0
+ * @param array|string $list List of ids.
+ * @return array Sanitized array of IDs.
*/
-function nocache_headers() {
- // why are these @-silenced when other header calls aren't?
- @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
- @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
- @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
- @header( 'Pragma: no-cache' );
+function wp_parse_id_list( $list ) {
+ if ( !is_array($list) )
+ $list = preg_split('/[\s,]+/', $list);
+
+ return array_unique(array_map('absint', $list));
}
/**
- * Set the headers for caching for 10 days with JavaScript content type.
+ * Extract a slice of an array, given a list of keys.
*
- * @since 2.1.0
+ * @since 3.1.0
+ *
+ * @param array $array The original array.
+ * @param array $keys The list of keys.
+ * @return array The array slice.
*/
-function cache_javascript_headers() {
- $expiresOffset = 864000; // 10 days
- 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" );
+function wp_array_slice_assoc( $array, $keys ) {
+ $slice = array();
+ foreach ( $keys as $key )
+ if ( isset( $array[ $key ] ) )
+ $slice[ $key ] = $array[ $key ];
+
+ return $slice;
}
/**
- * Retrieve the number of database queries during the WordPress execution.
+ * Determines if the variable is a numeric-indexed array.
*
- * @since 2.0.0
+ * @since 4.4.0
*
- * @return int Number of database queries
+ * @param mixed $data Variable to check.
+ * @return bool Whether the variable is a list.
*/
-function get_num_queries() {
- global $wpdb;
- return $wpdb->num_queries;
+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;
}
/**
- * Whether input is yes or no. Must be 'y' to be true.
- *
- * @since 1.0.0
- *
- * @param string $yn Character string containing either 'y' or 'n'
- * @return bool True if yes, false on anything else
+ * Filters a list of objects, based on a set of key => value arguments.
+ *
+ * @since 3.0.0
+ *
+ * @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. 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 bool_from_yn( $yn ) {
- return ( strtolower( $yn ) == 'y' );
+function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
+ if ( ! is_array( $list ) )
+ return array();
+
+ $list = wp_list_filter( $list, $args, $operator );
+
+ if ( $field )
+ $list = wp_list_pluck( $list, $field );
+
+ return $list;
}
/**
- * Loads 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
- * @uses $wp_query Used to tell if the use a comment feed.
- * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed.
+ * Filters a list of objects, based on a set of key => value arguments.
+ *
+ * @since 3.1.0
+ *
+ * @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 do_feed() {
- global $wp_query;
+function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
+ if ( ! is_array( $list ) )
+ return array();
- $feed = get_query_var( 'feed' );
+ if ( empty( $args ) )
+ return $list;
- // Remove the pad, if present.
- $feed = preg_replace( '/^_+/', '', $feed );
+ $operator = strtoupper( $operator );
+ $count = count( $args );
+ $filtered = array();
- if ( $feed == '' || $feed == 'feed' )
- $feed = get_default_feed();
+ foreach ( $list as $key => $obj ) {
+ $to_match = (array) $obj;
- $hook = 'do_feed_' . $feed;
- if ( !has_action($hook) ) {
- $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), wp_specialchars($feed));
- wp_die($message);
+ $matched = 0;
+ foreach ( $args as $m_key => $m_value ) {
+ if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] )
+ $matched++;
+ }
+
+ if ( ( 'AND' == $operator && $matched == $count )
+ || ( 'OR' == $operator && $matched > 0 )
+ || ( 'NOT' == $operator && 0 == $matched ) ) {
+ $filtered[$key] = $obj;
+ }
}
- do_action( $hook, $wp_query->is_comment_feed );
+ return $filtered;
}
/**
- * Load the RDF RSS 0.91 Feed template.
+ * Pluck a certain field out of each object in a list.
*
- * @since 2.1.0
- */
-function do_feed_rdf() {
- load_template( ABSPATH . WPINC . '/feed-rdf.php' );
-}
-
-/**
- * Load the RSS 1.0 Feed Template
+ * This has the same functionality and prototype of
+ * array_column() (PHP 5.5) but also supports objects.
*
- * @since 2.1.0
+ * @since 3.1.0
+ * @since 4.0.0 $index_key parameter added.
+ *
+ * @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 do_feed_rss() {
- load_template( ABSPATH . WPINC . '/feed-rss.php' );
+function wp_list_pluck( $list, $field, $index_key = null ) {
+ if ( ! $index_key ) {
+ /*
+ * This is simple. Could at some point wrap array_column()
+ * if we knew we had an array of arrays.
+ */
+ foreach ( $list as $key => $value ) {
+ if ( is_object( $value ) ) {
+ $list[ $key ] = $value->$field;
+ } else {
+ $list[ $key ] = $value[ $field ];
+ }
+ }
+ return $list;
+ }
+
+ /*
+ * When index_key is not set for a particular item, push the value
+ * to the end of the stack. This is how array_column() behaves.
+ */
+ $newlist = array();
+ foreach ( $list as $value ) {
+ if ( is_object( $value ) ) {
+ if ( isset( $value->$index_key ) ) {
+ $newlist[ $value->$index_key ] = $value->$field;
+ } else {
+ $newlist[] = $value->$field;
+ }
+ } else {
+ if ( isset( $value[ $index_key ] ) ) {
+ $newlist[ $value[ $index_key ] ] = $value[ $field ];
+ } else {
+ $newlist[] = $value[ $field ];
+ }
+ }
+ }
+
+ return $newlist;
}
/**
- * Load either the RSS2 comment feed or the RSS2 posts feed.
+ * Determines if Widgets library should be loaded.
*
- * @since 2.1.0
+ * 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.
*
- * @param bool $for_comments True for the comment feed, false for normal feed.
+ * @since 2.2.0
*/
-function do_feed_rss2( $for_comments ) {
- if ( $for_comments )
- load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
- else
- load_template( ABSPATH . WPINC . '/feed-rss2.php' );
+function wp_maybe_load_widgets() {
+ /**
+ * Filter 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' );
}
/**
- * Load either Atom comment feed or Atom posts feed.
+ * Append the Widgets menu to the themes main menu.
*
- * @since 2.1.0
+ * @since 2.2.0
*
- * @param bool $for_comments True for the comment feed, false for normal feed.
+ * @global array $submenu
*/
-function do_feed_atom( $for_comments ) {
- if ($for_comments)
- load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
- else
- load_template( ABSPATH . WPINC . '/feed-atom.php' );
+function 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 );
}
/**
- * Display the robot.txt file content.
+ * Flush all output buffers for PHP 5.2.
*
- * The echo content should be with usage of the permalinks or for creating the
- * robot.txt file.
+ * Make sure all output buffers are flushed before our singletons are destroyed.
*
- * @since 2.1.0
- * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules.
+ * @since 2.2.0
*/
-function do_robots() {
- header( 'Content-Type: text/plain; charset=utf-8' );
-
- do_action( 'do_robotstxt' );
-
- if ( '0' == get_option( 'blog_public' ) ) {
- echo "User-agent: *\n";
- echo "Disallow: /\n";
- } else {
- echo "User-agent: *\n";
- echo "Disallow:\n";
- }
+function wp_ob_end_flush_all() {
+ $levels = ob_get_level();
+ for ($i=0; $i<$levels; $i++)
+ ob_end_flush();
}
/**
- * Test whether blog is already installed.
+ * 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 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.
+ * 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.
*
- * Checks for the option siteurl for whether WordPress is installed.
+ * This function was backported to WordPress 2.3.2, but originally was added
+ * in WordPress 2.5.0.
*
- * @since 2.1.0
- * @uses $wpdb
+ * @since 2.3.2
*
- * @return bool Whether blog is already installed.
+ * @global wpdb $wpdb WordPress database abstraction object.
*/
-function is_blog_installed() {
+function dead_db() {
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;
+ wp_load_translations_early();
- $suppress = $wpdb->suppress_errors();
- $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
- $wpdb->suppress_errors($suppress);
+ // 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();
+ }
- $installed = !empty( $installed ) ? true : false;
- wp_cache_set('is_blog_installed', $installed);
+ // 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' );
+?>
+
+>
+
+
+
- return $installed;
+
+
+
+
+
+';
- if ( $echo )
- echo $nonce_field;
-
- if ( $referer )
- wp_referer_field( $echo, 'previous' );
-
- return $nonce_field;
+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 );
+
+ /**
+ * Filter 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 ) )
+ trigger_error( sprintf( __('%1$s is deprecated since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
+ else
+ trigger_error( sprintf( __('%1$s is deprecated since version %2$s with no alternative available.'), $function, $version ) );
+ } else {
+ if ( ! is_null( $replacement ) )
+ trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
+ else
+ trigger_error( sprintf( '%1$s is deprecated since version %2$s with no alternative available.', $function, $version ) );
+ }
+ }
}
/**
- * Retrieve or display referer hidden field for forms.
+ * Marks a constructor as deprecated and informs when it has been used.
*
- * 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.
+ * Similar to _deprecated_function(), but with different strings. Used to
+ * remove PHP4 style constructors.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * 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
+ * @access private
*
- * @param bool $echo Whether to echo or return the referer field.
- * @return string Referer field.
+ * @param string $class The class containing the deprecated constructor.
+ * @param string $version The version of WordPress that deprecated the function.
*/
-function wp_referer_field( $echo = true) {
- $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
- $referer_field = '';
+function _deprecated_constructor( $class, $version ) {
+
+ /**
+ * Fires when a deprecated constructor is called.
+ *
+ * @since 4.3.0
+ *
+ * @param string $class The class containing the deprecated constructor.
+ * @param string $version The version of WordPress that deprecated the function.
+ */
+ do_action( 'deprecated_constructor_run', $class, $version );
+
+ /**
+ * Filter 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( '__' ) ) {
+ trigger_error( sprintf( __( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.' ), $class, $version, '
__construct()
' ) );
+ } else {
+ trigger_error( sprintf( 'The called constructor method for %1$s is deprecated since version %2$s! Use %3$s instead.', $class, $version, '
__construct()
' ) );
+ }
+ }
- if ( $echo )
- echo $referer_field;
- return $referer_field;
}
/**
- * Retrieve or display original referer hidden field for forms.
+ * Mark a file as deprecated and inform when it has been used.
*
- * The input name is '_wp_original_http_referer' and will be either the same
- * value of {@link wp_referer_field()}, if that was posted already or it will
- * be the current page, if it doesn't exist.
+ * There is a hook 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.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
*
- * @param bool $echo Whether to echo the original http referer
- * @param string $jump_back_to Optional, default is 'current'. Can be 'previous' or page you want to jump back to.
- * @return string Original referer field.
+ * 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 wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
- $jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
- $ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to;
- $orig_referer_field = '';
- if ( $echo )
- echo $orig_referer_field;
- return $orig_referer_field;
+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 );
+
+ /**
+ * Filter 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 ) )
+ trigger_error( sprintf( __('%1$s is deprecated since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
+ else
+ trigger_error( sprintf( __('%1$s is deprecated since version %2$s with no alternative available.'), $file, $version ) . $message );
+ } else {
+ if ( ! is_null( $replacement ) )
+ trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
+ else
+ trigger_error( sprintf( '%1$s is deprecated since version %2$s with no alternative available.', $file, $version ) . $message );
+ }
+ }
}
-
/**
- * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.
+ * Mark a function argument as deprecated and inform when it has been used.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * 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' );
+ * }
+ *
+ *
+ * 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
*
- * @return string|bool False on failure. Referer URL on success.
+ * @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 wp_get_referer() {
- $ref = '';
- if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
- $ref = $_REQUEST['_wp_http_referer'];
- else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
- $ref = $_SERVER['HTTP_REFERER'];
-
- if ( $ref !== $_SERVER['REQUEST_URI'] )
- return $ref;
- return false;
+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 );
+
+ /**
+ * Filter 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 ) )
+ trigger_error( sprintf( __('%1$s was called with an argument that is deprecated since version %2$s! %3$s'), $function, $version, $message ) );
+ else
+ trigger_error( sprintf( __('%1$s was called with an argument that is deprecated 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 deprecated since version %2$s! %3$s', $function, $version, $message ) );
+ else
+ trigger_error( sprintf( '%1$s was called with an argument that is deprecated since version %2$s with no alternative available.', $function, $version ) );
+ }
+ }
}
/**
- * Retrieve original referer that was posted, if it exists.
+ * Mark something as being incorrectly called.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * There is a hook 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.
*
- * @return string|bool False if no original referer or original referer if set.
+ * @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 wp_get_original_referer() {
- if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
- return $_REQUEST['_wp_original_http_referer'];
- return false;
+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 );
+
+ /**
+ * Filter 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( '__' ) ) {
+ $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
+ /* translators: %s: Codex URL */
+ $message .= ' ' . sprintf( __( 'Please see Debugging in WordPress for more information.' ),
+ __( 'https://codex.wordpress.org/Debugging_in_WordPress' )
+ );
+ trigger_error( sprintf( __( '%1$s was called incorrectly. %2$s %3$s' ), $function, $message, $version ) );
+ } else {
+ $version = is_null( $version ) ? '' : sprintf( '(This message was added in version %s.)', $version );
+ $message .= sprintf( ' Please see Debugging in WordPress for more information.',
+ 'https://codex.wordpress.org/Debugging_in_WordPress'
+ );
+ trigger_error( sprintf( '%1$s was called incorrectly. %2$s %3$s', $function, $message, $version ) );
+ }
+ }
}
/**
- * Recursive directory creation based on full path.
+ * Is the server running earlier than 1.5.0 version of lighttpd?
*
- * Will attempt to set permissions on folders.
- *
- * @since 2.0.1
+ * @since 2.5.0
*
- * @param string $target Full path to attempt to create.
- * @return bool Whether the path was created or not. True if path already exists.
+ * @return bool Whether the server is running lighttpd < 1.5.0.
*/
-function wp_mkdir_p( $target ) {
- // from php.net/mkdir user contributed notes
- $target = str_replace( '//', '/', $target );
- if ( file_exists( $target ) )
- return @is_dir( $target );
-
- // Attempting to create the directory may clutter up our display.
- if ( @mkdir( $target ) ) {
- $stat = @stat( dirname( $target ) );
- $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
- @chmod( $target, $dir_perms );
- return true;
- } elseif ( is_dir( dirname( $target ) ) ) {
- return false;
- }
-
- // If the above failed, attempt to create the parent node, then try again.
- if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) )
- return wp_mkdir_p( $target );
-
- return false;
+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' );
}
/**
- * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows').
+ * Does the specified module exist in the Apache config?
*
* @since 2.5.0
*
- * @param string $path File path
- * @return bool True if path is absolute, false is not absolute.
+ * @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 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;
+function apache_mod_loaded($mod, $default = false) {
+ global $is_apache;
- if ( strlen($path) == 0 || $path{0} == '.' )
+ if ( !$is_apache )
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 (bool) preg_match('#^[/\\\\]#', $path);
+ 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;
}
/**
- * Join two filesystem paths together (e.g. 'give me $path relative to $base').
+ * Check if IIS 7+ supports pretty permalinks.
*
- * If the $path is absolute, then it the full path is returned.
+ * @since 2.8.0
*
- * @since 2.5.0
+ * @global bool $is_iis7
*
- * @param string $base
- * @param string $path
- * @return string The path with the base or absolute path.
+ * @return bool Whether IIS7 supports permalinks.
*/
-function path_join( $base, $path ) {
- if ( path_is_absolute($path) )
- return $path;
+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' );
+ }
- return rtrim($base, '/') . '/' . ltrim($path, '/');
+ /**
+ * Filter 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 );
}
/**
- * 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.
+ * File validates against allowed set of defined rules.
*
- * 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' - set to false.
+ * A return value of '1' means that the $file contains either '..' or './'. A
+ * return value of '2' means that the $file contains ':' after the first
+ * character. A return value of '3' means that the file is not in the allowed
+ * files list.
*
- * @since 2.0.0
- * @uses apply_filters() Calls 'upload_dir' on returned array.
+ * @since 1.2.0
*
- * @param string $time Optional. Time formatted in 'yyyy/mm'.
- * @return array See above for description.
+ * @param string $file File path.
+ * @param array $allowed_files List of allowed files.
+ * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
*/
-function wp_upload_dir( $time = null ) {
- $siteurl = get_option( 'siteurl' );
- $upload_path = get_option( 'upload_path' );
- $upload_path = trim($upload_path);
- if ( empty($upload_path) )
- $dir = WP_CONTENT_DIR . '/uploads';
- else
- $dir = $upload_path;
+function validate_file( $file, $allowed_files = '' ) {
+ if ( false !== strpos( $file, '..' ) )
+ return 1;
- // $dir is absolute, $path is (maybe) relative to ABSPATH
- $dir = path_join( ABSPATH, $dir );
+ if ( false !== strpos( $file, './' ) )
+ return 1;
- if ( !$url = get_option( 'upload_url_path' ) ) {
- if ( empty($upload_path) or ( $upload_path == $dir ) )
- $url = WP_CONTENT_URL . '/uploads';
- else
- $url = trailingslashit( $siteurl ) . $upload_path;
- }
+ if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
+ return 3;
- if ( defined('UPLOADS') ) {
- $dir = ABSPATH . UPLOADS;
- $url = trailingslashit( $siteurl ) . UPLOADS;
- }
+ if (':' == substr( $file, 1, 1 ) )
+ return 2;
- $bdir = $dir;
- $burl = $url;
+ return 0;
+}
- $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";
+/**
+ * Determine if SSL is used.
+ *
+ * @since 2.6.0
+ *
+ * @return bool True if SSL, false if not used.
+ */
+function is_ssl() {
+ if ( isset($_SERVER['HTTPS']) ) {
+ if ( 'on' == strtolower($_SERVER['HTTPS']) )
+ return true;
+ if ( '1' == $_SERVER['HTTPS'] )
+ return true;
+ } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
+ return true;
}
+ return false;
+}
- $dir .= $subdir;
- $url .= $subdir;
+/**
+ * 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;
- // Make sure we have an uploads dir
- if ( ! wp_mkdir_p( $dir ) ) {
- $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir );
- return array( 'error' => $message );
+ if ( !is_null( $force ) ) {
+ $old_forced = $forced;
+ $forced = $force;
+ return $old_forced;
}
- $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false );
-
- return apply_filters( 'upload_dir', $uploads );
+ return $forced;
}
/**
- * 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.
+ * Guess the URL for the site.
*
- * The callback must accept two parameters, the first one is the directory and
- * the second is the filename. The callback must be a function.
+ * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
+ * directory.
*
- * @since 2.5
+ * @since 2.6.0
*
- * @param string $dir
- * @param string $filename
- * @param string $unique_filename_callback Function name, must be a function.
- * @return string New filename, if given wasn't unique.
+ * @return string The guessed URL.
*/
-function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
- $filename = strtolower( $filename );
- // separate the filename into a name and extension
- $info = pathinfo($filename);
- $ext = !empty($info['extension']) ? $info['extension'] : '';
- $name = basename($filename, ".{$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 $override['unique_filename_callback'] if supplied.
- if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
- $filename = $unique_filename_callback( $dir, $name );
+function wp_guess_url() {
+ if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
+ $url = WP_SITEURL;
} else {
- $number = '';
+ $abspath_fix = str_replace( '\\', '/', ABSPATH );
+ $script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
- if ( !empty( $ext ) )
- $ext = strtolower( ".$ext" );
+ // 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'] );
- $filename = str_replace( $ext, '', $filename );
- // Strip % so the server doesn't try to decode entities.
- $filename = str_replace('%', '', sanitize_title_with_dashes( $filename ) ) . $ext;
+ // 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'] );
- while ( file_exists( $dir . "/$filename" ) ) {
- if ( '' == "$number$ext" )
- $filename = $filename . ++$number . $ext;
- else
- $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
+ } 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 install
+ $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 $filename;
+ return rtrim($url, '/');
}
/**
- * Create a file in the upload folder with given content.
+ * Temporarily suspend cache additions.
*
- * 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.
+ * 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.
*
- * 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.
+ * Suspension lasts for a single page load at most. Remember to call this
+ * function again if you wish to re-enable cache adds earlier.
*
- * The permissions will be set on the new file automatically by this function.
+ * @since 3.3.0
*
- * @since 2.0.0
+ * @staticvar bool $_suspend
*
- * @param string $name
- * @param null $deprecated Not used. Set to null.
- * @param mixed $bits File content
- * @param string $time Optional. Time formatted in 'yyyy/mm'.
- * @return array
+ * @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
+ * @return bool The current suspend setting
*/
-function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
- if ( empty( $name ) )
- return array( 'error' => __( 'Empty filename' ) );
+function wp_suspend_cache_addition( $suspend = null ) {
+ static $_suspend = false;
- $wp_filetype = wp_check_filetype( $name );
- if ( !$wp_filetype['ext'] )
- return array( 'error' => __( 'Invalid file type' ) );
-
- $upload = wp_upload_dir( $time );
+ if ( is_bool( $suspend ) )
+ $_suspend = $suspend;
- if ( $upload['error'] !== false )
- return $upload;
+ return $_suspend;
+}
- $filename = wp_unique_filename( $upload['path'], $name );
+/**
+ * Suspend cache invalidation.
+ *
+ * Turns cache invalidation on and off. Useful during imports where you don't wont 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;
- $new_file = $upload['path'] . "/$filename";
- if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
- $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) );
- return array( 'error' => $message );
- }
+ $current_suspend = $_wp_suspend_cache_invalidation;
+ $_wp_suspend_cache_invalidation = $suspend;
+ return $current_suspend;
+}
- $ifp = @ fopen( $new_file, 'wb' );
- if ( ! $ifp )
- return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
+/**
+ * Determine whether a site is the main site of the current network.
+ *
+ * @since 3.0.0
+ *
+ * @global object $current_site
+ *
+ * @param int $site_id Optional. Site ID to test. Defaults to current site.
+ * Defaults to current site.
+ * @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 ) {
+ // This is the current network's information; 'site' is old terminology.
+ global $current_site;
- @fwrite( $ifp, $bits );
- fclose( $ifp );
- // Set correct file permissions
- $stat = @ stat( dirname( $new_file ) );
- $perms = $stat['mode'] & 0007777;
- $perms = $perms & 0000666;
- @ chmod( $new_file, $perms );
+ if ( ! is_multisite() )
+ return true;
- // Compute the URL
- $url = $upload['url'] . "/$filename";
+ if ( ! $site_id )
+ $site_id = get_current_blog_id();
- return array( 'file' => $new_file, 'url' => $url, 'error' => false );
+ return (int) $site_id === (int) $current_site->blog_id;
}
/**
- * Retrieve the file type based on the extension name.
+ * Determine whether a network is the main network of the Multisite install.
*
- * @package WordPress
- * @since 2.5.0
- * @uses apply_filters() Calls 'ext2type' hook on default supported types.
+ * @since 3.7.0
*
- * @param string $ext The extension to search.
- * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
+ * @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 wp_ext2type( $ext ) {
- $ext2type = apply_filters('ext2type', array(
- 'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'),
- 'video' => array('asf','avi','divx','dv','mov','mpg','mpeg','mp4','mpv','ogm','qt','rm','vob','wmv'),
- 'document' => array('doc','docx','pages','odt','rtf','pdf'),
- 'spreadsheet' => array('xls','xlsx','numbers','ods'),
- 'interactive' => array('ppt','pptx','key','odp','swf'),
- 'text' => array('txt'),
- 'archive' => array('tar','bz2','gz','cab','dmg','rar','sea','sit','sqx','zip'),
- 'code' => array('css','html','php','js'),
- ));
- foreach ( $ext2type as $type => $exts )
- if ( in_array($ext, $exts) )
- return $type;
+function is_main_network( $network_id = null ) {
+ if ( ! is_multisite() ) {
+ return true;
+ }
+
+ $current_network_id = (int) get_current_site()->id;
+
+ if ( null === $network_id ) {
+ $network_id = $current_network_id;
+ }
+
+ $network_id = (int) $network_id;
+
+ return ( $network_id === get_main_network_id() );
}
/**
- * Retrieve the file type from the file name.
+ * Get the main network ID.
*
- * You can optionally define the mime array, if needed.
+ * @since 4.3.0
*
- * @since 2.0.4
+ * @global wpdb $wpdb WordPress database abstraction object.
*
- * @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.
+ * @return int The ID of the main network.
*/
-function wp_check_filetype( $filename, $mimes = null ) {
- // Accepted MIME types are set here as PCRE unless provided.
- $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
- 'jpg|jpeg|jpe' => 'image/jpeg',
- 'gif' => 'image/gif',
- 'png' => 'image/png',
- 'bmp' => 'image/bmp',
- 'tif|tiff' => 'image/tiff',
- 'ico' => 'image/x-icon',
- 'asf|asx|wax|wmv|wmx' => 'video/asf',
- 'avi' => 'video/avi',
- 'divx' => 'video/divx',
- 'mov|qt' => 'video/quicktime',
- 'mpeg|mpg|mpe|mp4' => 'video/mpeg',
- 'txt|c|cc|h' => 'text/plain',
- 'rtx' => 'text/richtext',
- 'css' => 'text/css',
- 'htm|html' => 'text/html',
- 'mp3|m4a' => 'audio/mpeg',
- 'ra|ram' => 'audio/x-realaudio',
- 'wav' => 'audio/wav',
- 'ogg' => 'audio/ogg',
- 'mid|midi' => 'audio/midi',
- 'wma' => 'audio/wma',
- 'rtf' => 'application/rtf',
- 'js' => 'application/javascript',
- 'pdf' => 'application/pdf',
- 'doc|docx' => 'application/msword',
- 'pot|pps|ppt|pptx' => 'application/vnd.ms-powerpoint',
- 'wri' => 'application/vnd.ms-write',
- 'xla|xls|xlsx|xlt|xlw' => 'application/vnd.ms-excel',
- 'mdb' => 'application/vnd.ms-access',
- 'mpp' => 'application/vnd.ms-project',
- 'swf' => 'application/x-shockwave-flash',
- 'class' => 'application/java',
- 'tar' => 'application/x-tar',
- 'zip' => 'application/zip',
- 'gz|gzip' => 'application/x-gzip',
- 'exe' => 'application/x-msdownload',
- // 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',
- )
- );
+function get_main_network_id() {
+ global $wpdb;
- $type = false;
- $ext = false;
+ if ( ! is_multisite() ) {
+ return 1;
+ }
- 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;
+ if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
+ $main_network_id = PRIMARY_NETWORK_ID;
+ } elseif ( 1 === (int) get_current_site()->id ) {
+ // If the current network has an ID of 1, assume it is the main network.
+ $main_network_id = 1;
+ } else {
+ $main_network_id = wp_cache_get( 'primary_network_id', 'site-options' );
+
+ if ( false === $main_network_id ) {
+ $main_network_id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1" );
+ wp_cache_add( 'primary_network_id', $main_network_id, 'site-options' );
}
}
- return compact( 'ext', 'type' );
+ /**
+ * Filter 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 );
}
/**
- * Retrieve nonce action "Are you sure" message.
+ * Determine whether global terms are enabled.
*
- * The action is split by verb and noun. The action format is as follows:
- * verb-action_extra. The verb is before the first dash and has the format of
- * letters and no spaces and numbers. The noun is after the dash and before the
- * underscore, if an underscore exists. The noun is also only letters.
+ * @since 3.0.0
*
- * The filter will be called for any action, which is not defined by WordPress.
- * You may use the filter for your plugin to explain nonce actions to the user,
- * when they get the "Are you sure?" message. The filter is in the format of
- * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the
- * $noun replaced by the found noun. The two parameters that are given to the
- * hook are the localized "Are you sure you want to do this?" message with the
- * extra text (the text after the underscore).
- *
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @staticvar bool $global_terms
*
- * @param string $action Nonce action.
- * @return string Are you sure message.
- */
-function wp_explain_nonce( $action ) {
- if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
- $verb = $matches[1];
- $noun = $matches[2];
-
- $trans = array();
- $trans['update']['attachment'] = array( __( 'Your attempt to edit this attachment: "%s" has failed.' ), 'get_the_title' );
-
- $trans['add']['category'] = array( __( 'Your attempt to add this category has failed.' ), false );
- $trans['delete']['category'] = array( __( 'Your attempt to delete this category: "%s" has failed.' ), 'get_catname' );
- $trans['update']['category'] = array( __( 'Your attempt to edit this category: "%s" has failed.' ), 'get_catname' );
-
- $trans['delete']['comment'] = array( __( 'Your attempt to delete this comment: "%s" has failed.' ), 'use_id' );
- $trans['unapprove']['comment'] = array( __( 'Your attempt to unapprove this comment: "%s" has failed.' ), 'use_id' );
- $trans['approve']['comment'] = array( __( 'Your attempt to approve this comment: "%s" has failed.' ), 'use_id' );
- $trans['update']['comment'] = array( __( 'Your attempt to edit this comment: "%s" has failed.' ), 'use_id' );
- $trans['bulk']['comments'] = array( __( 'Your attempt to bulk modify comments has failed.' ), false );
- $trans['moderate']['comments'] = array( __( 'Your attempt to moderate comments has failed.' ), false );
-
- $trans['add']['bookmark'] = array( __( 'Your attempt to add this link has failed.' ), false );
- $trans['delete']['bookmark'] = array( __( 'Your attempt to delete this link: "%s" has failed.' ), 'use_id' );
- $trans['update']['bookmark'] = array( __( 'Your attempt to edit this link: "%s" has failed.' ), 'use_id' );
- $trans['bulk']['bookmarks'] = array( __( 'Your attempt to bulk modify links has failed.' ), false );
-
- $trans['add']['page'] = array( __( 'Your attempt to add this page has failed.' ), false );
- $trans['delete']['page'] = array( __( 'Your attempt to delete this page: "%s" has failed.' ), 'get_the_title' );
- $trans['update']['page'] = array( __( 'Your attempt to edit this page: "%s" has failed.' ), 'get_the_title' );
-
- $trans['edit']['plugin'] = array( __( 'Your attempt to edit this plugin file: "%s" has failed.' ), 'use_id' );
- $trans['activate']['plugin'] = array( __( 'Your attempt to activate this plugin: "%s" has failed.' ), 'use_id' );
- $trans['deactivate']['plugin'] = array( __( 'Your attempt to deactivate this plugin: "%s" has failed.' ), 'use_id' );
- $trans['upgrade']['plugin'] = array( __( 'Your attempt to upgrade this plugin: "%s" has failed.' ), 'use_id' );
-
- $trans['add']['post'] = array( __( 'Your attempt to add this post has failed.' ), false );
- $trans['delete']['post'] = array( __( 'Your attempt to delete this post: "%s" has failed.' ), 'get_the_title' );
- $trans['update']['post'] = array( __( 'Your attempt to edit this post: "%s" has failed.' ), 'get_the_title' );
-
- $trans['add']['user'] = array( __( 'Your attempt to add this user has failed.' ), false );
- $trans['delete']['users'] = array( __( 'Your attempt to delete users has failed.' ), false );
- $trans['bulk']['users'] = array( __( 'Your attempt to bulk modify users has failed.' ), false );
- $trans['update']['user'] = array( __( 'Your attempt to edit this user: "%s" has failed.' ), 'get_author_name' );
- $trans['update']['profile'] = array( __( 'Your attempt to modify the profile for: "%s" has failed.' ), 'get_author_name' );
-
- $trans['update']['options'] = array( __( 'Your attempt to edit your settings has failed.' ), false );
- $trans['update']['permalink'] = array( __( 'Your attempt to change your permalink structure to: %s has failed.' ), 'use_id' );
- $trans['edit']['file'] = array( __( 'Your attempt to edit this file: "%s" has failed.' ), 'use_id' );
- $trans['edit']['theme'] = array( __( 'Your attempt to edit this theme file: "%s" has failed.' ), 'use_id' );
- $trans['switch']['theme'] = array( __( 'Your attempt to switch to this theme: "%s" has failed.' ), 'use_id' );
-
- $trans['log']['out'] = array( sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'sitename' ) ), false );
-
- if ( isset( $trans[$verb][$noun] ) ) {
- if ( !empty( $trans[$verb][$noun][1] ) ) {
- $lookup = $trans[$verb][$noun][1];
- $object = $matches[4];
- if ( 'use_id' != $lookup )
- $object = call_user_func( $lookup, $object );
- return sprintf( $trans[$verb][$noun][0], wp_specialchars($object) );
- } else {
- return $trans[$verb][$noun][0];
- }
- }
- }
+ * @return bool True if multisite and global terms enabled.
+ */
+function global_terms_enabled() {
+ if ( ! is_multisite() )
+ return false;
- return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
+ static $global_terms = null;
+ if ( is_null( $global_terms ) ) {
+
+ /**
+ * Filter 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;
}
/**
- * Display "Are You Sure" message to confirm the action being taken.
+ * gmt_offset modification for smart timezone handling.
*
- * If the action has the nonce explain message, then it will be displayed along
- * with the "Are you sure?" message.
+ * Overrides the gmt_offset option if we have a timezone_string available.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @since 2.8.0
*
- * @param string $action The nonce action.
+ * @return float|false Timezone GMT offset, false otherwise.
*/
-function wp_nonce_ays( $action ) {
- $title = __( 'WordPress Failure Notice' );
- $html = wp_specialchars( wp_explain_nonce( $action ) );
- if ( wp_get_referer() )
- $html .= "
";
+
+ // 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' );
- if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL )
- $admin_dir = WP_SITEURL . '/wp-admin/';
- elseif ( function_exists( 'get_bloginfo' ) && '' != get_bloginfo( 'wpurl' ) )
- $admin_dir = get_bloginfo( 'wpurl' ) . '/wp-admin/';
- elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false )
- $admin_dir = '';
- else
- $admin_dir = 'wp-admin/';
+ $structure = array();
+
+ if ( empty( $selected_zone ) ) {
+ $structure[] = '';
+ }
+
+ 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[] = '';
+ }
}
- if ( empty($title) ) {
- if ( function_exists( '__' ) )
- $title = __( 'WordPress › Error' );
+ // Do UTC
+ $structure[] = '';
+
+ // Do manual UTC offsets
+ $structure[] = '';
-?>
-
->
-
-
-
-
-text_direction ) ) : ?>
-
-
-
-
-
-
-
-
-
-).*/", '', $str));
}
/**
- * Retrieve the WordPress site URL.
+ * 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.
*
- * 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.
+ * The default value of `EMPTY_TRASH_DAYS` is 30 (days).
*
- * @access private
- * @package WordPress
- * @since 2.2.0
+ * @since 2.9.0
*
- * @param string $url URL to set the WordPress site location.
- * @return string The WordPress Site URL
+ * @global wpdb $wpdb WordPress database abstraction object.
*/
-function _config_wp_siteurl( $url = '' ) {
- if ( defined( 'WP_SITEURL' ) )
- return WP_SITEURL;
- return $url;
+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 );
+ }
+ }
}
/**
- * Set the localized direction for MCE plugin.
+ * Retrieve metadata from a file.
*
- * Will only set the direction to 'rtl', if the WordPress locale has the text
- * direction set to 'rtl'.
+ * 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.
*
- * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array
- * keys. These keys are then returned in the $input array.
+ * 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.
*
- * @access private
- * @package WordPress
- * @subpackage MCE
- * @since 2.1.0
+ * @link https://codex.wordpress.org/File_Header
*
- * @param array $input MCE plugin array.
- * @return array Direction set for 'rtl', if needed by locale.
+ * @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 "extra_{$context}_headers".
+ * Default empty.
+ * @return array Array of file headers in `HeaderKey => Header Value` format.
*/
-function _mce_set_direction( $input ) {
- global $wp_locale;
+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 );
+
+ /**
+ * Filter 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;
+ }
- if ( 'rtl' == $wp_locale->text_direction ) {
- $input['directionality'] = 'rtl';
- $input['plugins'] .= ',directionality';
- $input['theme_advanced_buttons1'] .= ',ltr';
+ 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 $input;
+ return $all_headers;
}
/**
- * Convert smiley code to the icon graphic file equivalent.
+ * Returns true.
*
- * 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.
+ * Useful for returning true to filters easily.
*
- * 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.
+ * @since 3.0.0
*
- * The $wp_smiliessearch global is for the regular expression array and is
- * set each time the function is called. The $wp_smiliesreplace is the full
- * replacement. Supposely, the $wp_smiliessearch array is looped over using
- * preg_replace() or just setting the array of $wp_smiliessearch along with the
- * array of $wp_smiliesreplace in the search and replace parameters of
- * preg_replace(), which would be faster and less overhead. Either way, both are
- * used with preg_replace() and can be defined after the function is called.
+ * @see __return_false()
*
- * 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.
+ * @return true True.
+ */
+function __return_true() {
+ return true;
+}
+
+/**
+ * Returns false.
*
- * @global array $wpsmiliestrans
- * @global array $wp_smiliesreplace
- * @global array $wp_smiliessearch
- * @since 2.2.0
+ * Useful for returning false to filters easily.
+ *
+ * @since 3.0.0
+ *
+ * @see __return_true()
+ *
+ * @return false False.
*/
-function smilies_init() {
- global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
+function __return_false() {
+ return false;
+}
- // don't bother setting up smilies if they are disabled
- if ( !get_option( 'use_smilies' ) )
- return;
+/**
+ * Returns 0.
+ *
+ * Useful for returning 0 to filters easily.
+ *
+ * @since 3.0.0
+ *
+ * @return int 0.
+ */
+function __return_zero() {
+ return 0;
+}
- if ( !isset( $wpsmiliestrans ) ) {
- $wpsmiliestrans = array(
- ':mrgreen:' => 'icon_mrgreen.gif',
- ':neutral:' => 'icon_neutral.gif',
- ':twisted:' => 'icon_twisted.gif',
- ':arrow:' => 'icon_arrow.gif',
- ':shock:' => 'icon_eek.gif',
- ':smile:' => 'icon_smile.gif',
- ':???:' => 'icon_confused.gif',
- ':cool:' => 'icon_cool.gif',
- ':evil:' => 'icon_evil.gif',
- ':grin:' => 'icon_biggrin.gif',
- ':idea:' => 'icon_idea.gif',
- ':oops:' => 'icon_redface.gif',
- ':razz:' => 'icon_razz.gif',
- ':roll:' => 'icon_rolleyes.gif',
- ':wink:' => 'icon_wink.gif',
- ':cry:' => 'icon_cry.gif',
- ':eek:' => 'icon_surprised.gif',
- ':lol:' => 'icon_lol.gif',
- ':mad:' => 'icon_mad.gif',
- ':sad:' => 'icon_sad.gif',
- '8-)' => 'icon_cool.gif',
- '8-O' => 'icon_eek.gif',
- ':-(' => 'icon_sad.gif',
- ':-)' => 'icon_smile.gif',
- ':-?' => 'icon_confused.gif',
- ':-D' => 'icon_biggrin.gif',
- ':-P' => 'icon_razz.gif',
- ':-o' => 'icon_surprised.gif',
- ':-x' => 'icon_mad.gif',
- ':-|' => 'icon_neutral.gif',
- ';-)' => 'icon_wink.gif',
- '8)' => 'icon_cool.gif',
- '8O' => 'icon_eek.gif',
- ':(' => 'icon_sad.gif',
- ':)' => 'icon_smile.gif',
- ':?' => 'icon_confused.gif',
- ':D' => 'icon_biggrin.gif',
- ':P' => 'icon_razz.gif',
- ':o' => 'icon_surprised.gif',
- ':x' => 'icon_mad.gif',
- ':|' => 'icon_neutral.gif',
- ';)' => 'icon_wink.gif',
- ':!:' => 'icon_exclaim.gif',
- ':?:' => 'icon_question.gif',
- );
- }
+/**
+ * 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();
+}
- $siteurl = get_option( 'siteurl' );
- foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
- $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
- $smiley_masked = attribute_escape( trim( $smiley ) );
- $wp_smiliesreplace[] = " ";
- }
+/**
+ * Returns null.
+ *
+ * Useful for returning null to filters easily.
+ *
+ * @since 3.4.0
+ *
+ * @return null Null value.
+ */
+function __return_null() {
+ return null;
}
/**
- * Merge user defined arguments into defaults array.
+ * Returns an empty string.
*
- * This function is used throughout WordPress to allow for both string or array
- * to be merged into another array.
+ * Useful for returning an empty string to filters easily.
*
- * @since 2.2.0
+ * @since 3.7.0
*
- * @param string|array $args Value to merge with $defaults
- * @param array $defaults Array that serves as the defaults.
- * @return array Merged user defined values with defaults.
+ * @see __return_null()
+ *
+ * @return string Empty string.
*/
-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 );
+function __return_empty_string() {
+ return '';
+}
- if ( is_array( $defaults ) )
- return array_merge( $defaults, $r );
- return $r;
+/**
+ * Send a HTTP header to disable content type sniffing in browsers which support it.
+ *
+ * @since 3.0.0
+ *
+ * @see http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
+ * @see http://src.chromium.org/viewvc/chrome?view=rev&revision=6985
+ */
+function send_nosniff_header() {
+ @header( 'X-Content-Type-Options: nosniff' );
}
/**
- * Determines if Widgets library should be loaded.
+ * Return a MySQL expression for selecting the week number based on the start_of_week option.
*
- * 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.
+ * @ignore
+ * @since 3.0.0
*
- * @since 2.2.0
- * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
+ * @param string $column Database column.
+ * @return string SQL clause.
*/
-function wp_maybe_load_widgets() {
- if ( !function_exists( 'dynamic_sidebar' ) ) {
- require_once( ABSPATH . WPINC . '/widgets.php' );
- add_action( '_admin_menu', 'wp_widgets_add_menu' );
+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 )";
}
}
/**
- * Append the Widgets menu to the themes main menu.
+ * Find hierarchy loops using a callback function that maps object IDs to parent IDs.
*
- * @since 2.2.0
- * @uses $submenu The administration submenu list.
+ * @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_widgets_add_menu() {
- global $submenu;
- $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
- ksort( $submenu['themes.php'], SORT_NUMERIC );
+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 );
}
/**
- * Flush all output buffers for PHP 5.2.
+ * Use the "The Tortoise and the Hare" algorithm to detect loops.
*
- * Make sure all output buffers are flushed before our singletons our destroyed.
+ * 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 2.2.0
+ * @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_ob_end_flush_all() {
- while ( @ob_end_flush() );
+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;
}
/**
- * Load the correct database class file.
+ * Send a HTTP header to limit rendering of pages to same origin iframes.
*
- * This function is used to load the database class file either at runtime or by
- * wp-admin/setup-config.php We must globalise $wpdb to ensure that it is
- * defined globally by the inline code in wp-db.php.
+ * @since 3.1.3
*
- * @since 2.5.0
- * @global $wpdb WordPress Database Object
+ * @see https://developer.mozilla.org/en/the_x-frame-options_response_header
*/
-function require_wp_db() {
- global $wpdb;
- if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
- require_once( WP_CONTENT_DIR . '/db.php' );
- else
- require_once( ABSPATH . WPINC . '/wp-db.php' );
+function send_frame_options_header() {
+ @header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
- * Load custom DB error or display WordPress DB error.
+ * Retrieve a list of protocols to allow in HTML attributes.
*
- * 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.
+ * @since 3.3.0
+ * @since 4.3.0 Added 'webcal' to the protocols array.
*
- * 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.
+ * @see wp_kses()
+ * @see esc_url()
*
- * This function was backported to the the WordPress 2.3.2, but originally was
- * added in WordPress 2.5.0.
+ * @staticvar array $protocols
*
- * @since 2.3.2
- * @uses $wpdb
+ * @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', and 'webcal'.
*/
-function dead_db() {
- global $wpdb;
-
- // 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();
+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' );
+
+ /**
+ * Filter 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 = apply_filters( 'kses_allowed_protocols', $protocols );
}
- // If installing or in the admin, provide the verbose message.
- if ( defined('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' );
-?>
-
->
-
-
- Database Error
-
-
-
-
Error establishing a database connection
-
-
-=' ) )
+ $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;
}
/**
- * Determines if the blog can be accessed over SSL.
+ * Retrieve ids that are not already present in the cache.
*
- * Determines if blog can be accessed over SSL by using cURL to access the site
- * using the https in the siteurl. Requires cURL extension to work correctly.
+ * @since 3.4.0
+ * @access private
*
- * @since 2.5.0
+ * @param array $object_ids ID list.
+ * @param string $cache_key The cache bucket to check against.
*
- * @return bool Whether or not SSL access is available
+ * @return array List of ids not present in the cache.
*/
-function url_is_accessable_via_ssl($url)
-{
- if (in_array('curl', get_loaded_extensions())) {
- $ssl = preg_replace( '/^http:\/\//', 'https://', $url );
+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;
+ }
+ }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $ssl);
- curl_setopt($ch, CURLOPT_FAILONERROR, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ return $clean;
+}
- curl_exec($ch);
+/**
+ * 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;
- $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close ($ch);
+ $ua = $_SERVER['HTTP_USER_AGENT'];
- if ($status == 200 || $status == 401) {
- return true;
- }
+ 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 false;
+
+ return true;
}
/**
- * Secure URL, if available or the given URL.
- *
- * @since 2.5.0
+ * Test if a given path is a stream URL
*
- * @param string $url Complete URL path with transport.
- * @return string Secure or regular URL path.
+ * @param string $path The resource path or URL.
+ * @return bool True if the path is a stream URL.
*/
-function atom_service_url_filter($url)
-{
- if ( url_is_accessable_via_ssl($url) )
- return preg_replace( '/^http:\/\//', 'https://', $url );
- else
- return $url;
+function wp_is_stream( $path ) {
+ $wrappers = stream_get_wrappers();
+ $wrappers_re = '(' . join('|', $wrappers) . ')';
+
+ return preg_match( "!^$wrappers_re://!", $path ) === 1;
}
/**
- * Marks a function as deprecated and informs when it has been used.
+ * Test if the supplied date is valid for the Gregorian calendar.
*
- * There is a 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.
+ * @since 3.5.0
*
- * The current behavior is to trigger an user error if WP_DEBUG is defined and
- * is true.
+ * @see checkdate()
*
- * This function is to be used in every function in depreceated.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 ) {
+ /**
+ * Filter 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.
*
- * @package WordPress
- * @package Debug
- * @since 2.5.0
- * @access private
+ * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
- * @uses do_action() Calls 'deprecated_function_run' and passes the function name and what to use instead.
- * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
+ * This is disabled for certain screens where a login screen could cause an
+ * inconvenient interruption. A filter called wp_auth_check_load can be used
+ * for fine-grained control.
*
- * @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
+ * @since 3.6.0
*/
-function _deprecated_function($function, $version, $replacement=null) {
+function wp_auth_check_load() {
+ if ( ! is_admin() && ! is_user_logged_in() )
+ return;
- do_action('deprecated_function_run', $function, $replacement);
+ if ( defined( 'IFRAME_REQUEST' ) )
+ return;
- // Allow plugin to filter the output error trigger
- if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_function_trigger_error', true )) {
- if( !is_null($replacement) )
- trigger_error( sprintf( __('%1$s is deprecated since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
- else
- trigger_error( sprintf( __('%1$s is deprecated since version %2$s with no alternative available.'), $function, $version ) );
+ $screen = get_current_screen();
+ $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
+ $show = ! in_array( $screen->id, $hidden );
+
+ /**
+ * Filter 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 );
}
}
/**
- * Marks a file as deprecated and informs when it has been used.
- *
- * There is a hook 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.
+ * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
- * The current behavior is to trigger an user error if WP_DEBUG is defined and
- * is true.
+ * @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 );
+
+ /**
+ * Filter 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';
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ deprecated since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) );
- else
- trigger_error( sprintf( __('%1$s is deprecated since version %2$s with no alternative available.'), $file, $version ) );
- }
+function wp_auth_check( $response ) {
+ $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
+ return $response;
}
/**
- * Is the server running earlier than 1.5.0 version of lighttpd
+ * Return RegEx body to liberally match an opening HTML tag.
*
- * @since 2.5.0
+ * 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
*
- * @return bool Whether the server is running lighttpd < 1.5.0
+ * @since 3.6.0
+ *
+ * @param string $tag An HTML tag name. Example: 'video'.
+ * @return string Tag RegEx.
*/
-function is_lighttpd_before_150() {
- $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' );
- $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : '';
- return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
+function get_tag_regex( $tag ) {
+ if ( empty( $tag ) )
+ return;
+ return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
- * Does the specified module exist in the apache config?
+ * Retrieve a canonical form of the provided charset appropriate for passing to PHP
+ * functions such as htmlspecialchars() and charset html attributes.
*
- * @since 2.5.0
+ * @since 3.6.0
+ * @access private
*
- * @param string $mod e.g. mod_rewrite
- * @param bool $default The default return value if the module is not found
- * @return bool
+ * @see https://core.trac.wordpress.org/ticket/23688
+ *
+ * @param string $charset A charset name.
+ * @return string The canonical form of the charset.
*/
-function apache_mod_loaded($mod, $default = false) {
- global $is_apache;
+function _canonical_charset( $charset ) {
+ if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset ||
+ 'UTF8' === $charset )
+ return 'UTF-8';
- if ( !$is_apache )
- return false;
+ if ( 'ISO-8859-1' === $charset || 'iso-8859-1' === $charset ||
+ 'iso8859-1' === $charset || 'ISO8859-1' === $charset )
+ return 'ISO-8859-1';
- if ( function_exists('apache_get_modules') ) {
- $mods = apache_get_modules();
- if ( in_array($mod, $mods) )
- return true;
- } elseif ( function_exists('phpinfo') ) {
- ob_start();
- phpinfo(8);
- $phpinfo = ob_get_clean();
- if ( false !== strpos($phpinfo, $mod) )
- return true;
- }
- return $default;
+ return $charset;
}
/**
- * File validates against allowed set of defined rules.
+ * Set the mbstring internal encoding to a binary safe encoding when func_overload
+ * is enabled.
*
- * A return value of '1' means that the $file contains either '..' or './'. A
- * return value of '2' means that the $file contains ':' after the first
- * character. A return value of '3' means that the file is not in the allowed
- * files list.
+ * 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.
*
- * @since 1.2.0
+ * 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.
*
- * @param string $file File path.
- * @param array $allowed_files List of allowed files.
- * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
+ * 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 validate_file( $file, $allowed_files = '' ) {
- if ( false !== strpos( $file, '..' ))
- return 1;
+function mbstring_binary_safe_encoding( $reset = false ) {
+ static $encodings = array();
+ static $overloaded = null;
- if ( false !== strpos( $file, './' ))
- return 1;
+ if ( is_null( $overloaded ) )
+ $overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
- if (':' == substr( $file, 1, 1 ))
- return 2;
+ if ( false === $overloaded )
+ return;
- if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
- return 3;
+ if ( ! $reset ) {
+ $encoding = mb_internal_encoding();
+ array_push( $encodings, $encoding );
+ mb_internal_encoding( 'ISO-8859-1' );
+ }
- return 0;
+ if ( $reset && $encodings ) {
+ $encoding = array_pop( $encodings );
+ mb_internal_encoding( $encoding );
+ }
}
/**
- * Determine if SSL is used.
+ * Reset the mbstring internal encoding to a users previously set encoding.
*
- * @since 2.6.0
+ * @see mbstring_binary_safe_encoding()
*
- * @return bool True if SSL, false if not used.
+ * @since 3.7.0
*/
-function is_ssl() {
- if ( isset($_SERVER['HTTPS']) ) {
- if ( 'on' == strtolower($_SERVER['HTTPS']) )
- return true;
- if ( '1' == $_SERVER['HTTPS'] )
- return true;
- } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
- return true;
- }
- return false;
+function reset_mbstring_encoding() {
+ mbstring_binary_safe_encoding( true );
}
/**
- * Whether SSL login should be forced.
+ * Filter/validate a variable as a boolean.
*
- * @since 2.6.0
+ * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
*
- * @param string|bool $force Optional.
- * @return bool True if forced, false if not forced.
+ * @since 4.0.0
+ *
+ * @param mixed $var Boolean value to validate.
+ * @return bool Whether the value is validated.
*/
-function force_ssl_login($force = '') {
- static $forced;
+function wp_validate_boolean( $var ) {
+ if ( is_bool( $var ) ) {
+ return $var;
+ }
- if ( '' != $force ) {
- $old_forced = $forced;
- $forced = $force;
- return $old_forced;
+ if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
+ return false;
}
- return $forced;
+ return (bool) $var;
}
/**
- * Whether to force SSL used for the Administration Panels.
+ * Delete a file
*
- * @since 2.6.0
+ * @since 4.2.0
*
- * @param string|bool $force
- * @return bool True if forced, false if not forced.
+ * @param string $file The path to the file to delete.
*/
-function force_ssl_admin($force = '') {
- static $forced;
-
- if ( '' != $force ) {
- $old_forced = $forced;
- $forced = $force;
- return $old_forced;
+function wp_delete_file( $file ) {
+ /**
+ * Filter the path of the file to delete.
+ *
+ * @since 2.1.0
+ *
+ * @param string $medium Path to the file to delete.
+ */
+ $delete = apply_filters( 'wp_delete_file', $file );
+ if ( ! empty( $delete ) ) {
+ @unlink( $delete );
}
-
- return $forced;
}
/**
- * Guess the URL for the site.
- *
- * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
- * directory.
+ * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
*
- * @since 2.6.0
+ * This prevents reusing the same tab for a preview when the user has navigated away.
*
- * @return string
+ * @since 4.3.0
*/
-function wp_guess_url() {
- if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
- $url = WP_SITEURL;
- } else {
- $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
- $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+function wp_post_preview_js() {
+ global $post;
+
+ if ( ! is_preview() || empty( $post ) ) {
+ return;
}
- return $url;
-}
-/**
- * Suspend cache invalidation.
- *
- * Turns cache invalidation on and off. Useful during imports where you don't wont 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
- *
- * @param bool $suspend Whether to suspend or enable cache invalidation
- * @return bool The current suspend setting
- */
-function wp_suspend_cache_invalidation($suspend = true) {
- global $_wp_suspend_cache_invalidation;
+ // Has to match the window name used in post_submit_meta_box()
+ $name = 'wp-preview-' . (int) $post->ID;
- $current_suspend = $_wp_suspend_cache_invalidation;
- $_wp_suspend_cache_invalidation = $suspend;
- return $current_suspend;
+ ?>
+
+ =' );
- }
- return $can_clone ? clone( $object ) : $object;
-}
-
+function mysql_to_rfc3339( $date_string ) {
+ $formatted = mysql2date( 'c', $date_string, false );
-?>
+ // Strip timezone information
+ return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
+}