";
+ }
+
+ 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 );
- if ( empty( $text ) )
- return false;
+ $r = wp_parse_args($args, $defaults);
- $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 ( $wp_xmlrpc_server ) {
+ $error = new IXR_Error( $r['response'] , $message);
+ $wp_xmlrpc_server->output( $error->getXml() );
+ }
+ die();
+}
- return @header( $status_header, true, $header );
+/**
+ * Kill WordPress ajax execution.
+ *
+ * This is the handler for wp_die when processing Ajax requests.
+ *
+ * @since 3.4.0
+ * @access private
+ *
+ * @param string $message Optional. Response to print.
+ */
+function _ajax_wp_die_handler( $message = '' ) {
+ if ( is_scalar( $message ) )
+ die( (string) $message );
+ die( '0' );
}
/**
- * Gets the header information to prevent caching.
+ * Kill WordPress execution.
*
- * The several different headers cover the different ways cache prevention is handled
- * by different browsers
+ * This is the handler for wp_die when processing APP requests.
*
- * @since 2.8
+ * @since 3.4.0
+ * @access private
*
- * @uses apply_filters()
- * @return array The associative array of header names and field values.
+ * @param string $message Optional. Response to print.
*/
-function wp_get_nocache_headers() {
- $headers = array(
- 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
- 'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT',
- 'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
- 'Pragma' => 'no-cache',
- );
+function _scalar_wp_die_handler( $message = '' ) {
+ if ( is_scalar( $message ) )
+ die( (string) $message );
+ die();
+}
- if ( function_exists('apply_filters') ) {
- $headers = apply_filters('nocache_headers', $headers);
- }
- return $headers;
+/**
+ * Send a JSON response back to an Ajax request.
+ *
+ * @since 3.5.0
+ *
+ * @param mixed $response Variable (usually an array or object) to encode as JSON, then print and die.
+ */
+function wp_send_json( $response ) {
+ @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
+ echo json_encode( $response );
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
+ wp_die();
+ else
+ die;
}
/**
- * Sets the headers to prevent caching for the different browsers.
+ * Send a JSON response back to an Ajax request, indicating success.
*
- * 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.5.0
*
- * @since 2.0.0
- * @uses wp_get_nocache_headers()
+ * @param mixed $data Data to encode as JSON, then print and die.
*/
-function nocache_headers() {
- $headers = wp_get_nocache_headers();
- foreach( (array) $headers as $name => $field_value )
- @header("{$name}: {$field_value}");
+function wp_send_json_success( $data = null ) {
+ $response = array( 'success' => true );
+
+ if ( isset( $data ) )
+ $response['data'] = $data;
+
+ wp_send_json( $response );
}
/**
- * Set the headers for caching for 10 days with JavaScript content type.
+ * Send a JSON response back to an Ajax request, indicating failure.
*
- * @since 2.1.0
+ * @since 3.5.0
+ *
+ * @param mixed $data Data to encode as JSON, then print and die.
*/
-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_send_json_error( $data = null ) {
+ $response = array( 'success' => false );
+
+ if ( isset( $data ) )
+ $response['data'] = $data;
+
+ wp_send_json( $response );
}
/**
- * Retrieve the number of database queries during the WordPress execution.
+ * 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.
*
- * @return int Number of database queries
+ * @access private
+ * @package WordPress
+ * @since 2.2.0
+ *
+ * @param string $url URL for the home location
+ * @return string Homepage location.
*/
-function get_num_queries() {
- global $wpdb;
- return $wpdb->num_queries;
+function _config_wp_home( $url = '' ) {
+ if ( defined( 'WP_HOME' ) )
+ return untrailingslashit( WP_HOME );
+ return $url;
}
/**
- * Whether input is yes or no. Must be 'y' to be true.
+ * Retrieve the WordPress site URL.
*
- * @since 1.0.0
+ * 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.
*
- * @param string $yn Character string containing either 'y' or 'n'
- * @return bool True if yes, false on anything else
+ * @access private
+ * @package WordPress
+ * @since 2.2.0
+ *
+ * @param string $url URL to set the WordPress site location.
+ * @return string The WordPress Site URL
*/
-function bool_from_yn( $yn ) {
- return ( strtolower( $yn ) == 'y' );
+function _config_wp_siteurl( $url = '' ) {
+ if ( defined( 'WP_SITEURL' ) )
+ return untrailingslashit( WP_SITEURL );
+ return $url;
}
/**
- * Loads the feed template from the use of an action hook.
+ * Set the localized direction for MCE plugin.
*
- * 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.
+ * Will only set the direction to 'rtl', if the WordPress locale has the text
+ * direction set to 'rtl'.
*
- * It is better to only have one hook for each feed.
+ * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array
+ * keys. These keys are then returned in the $input array.
*
+ * @access private
+ * @package WordPress
+ * @subpackage MCE
* @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.
+ *
+ * @param array $input MCE plugin array.
+ * @return array Direction set for 'rtl', if needed by locale.
*/
-function do_feed() {
- global $wp_query;
+function _mce_set_direction( $input ) {
+ if ( is_rtl() ) {
+ $input['directionality'] = 'rtl';
+ $input['plugins'] .= ',directionality';
+ $input['theme_advanced_buttons1'] .= ',ltr';
+ }
- $feed = get_query_var( 'feed' );
+ return $input;
+}
- // Remove the pad, if present.
- $feed = preg_replace( '/^_+/', '', $feed );
- if ( $feed == '' || $feed == 'feed' )
- $feed = get_default_feed();
+/**
+ * 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;
- $hook = 'do_feed_' . $feed;
- if ( !has_action($hook) ) {
- $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), esc_html($feed));
- wp_die($message);
+ // don't bother setting up smilies if they are disabled
+ if ( !get_option( 'use_smilies' ) )
+ return;
+
+ 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',
+ // This one transformation breaks regular text with frequency.
+ // '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',
+ );
+ }
+
+ 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);
+
+ $wp_smiliessearch = '/((?:\s|^)';
+
+ $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 .= ')(?=\s|$))|((?:\s|^)'; ;
+ }
+ $subchar = $firstchar;
+ $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
+ } else {
+ $wp_smiliessearch .= '|';
+ }
+ $wp_smiliessearch .= preg_quote($rest, '/');
}
- do_action( $hook, $wp_query->is_comment_feed );
-}
+ $wp_smiliessearch .= ')(?=\s|$))/m';
-/**
- * Load the RDF RSS 0.91 Feed template.
- *
- * @since 2.1.0
- */
-function do_feed_rdf() {
- load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}
/**
- * Load the RSS 1.0 Feed Template
+ * Merge user defined arguments into defaults array.
*
- * @since 2.1.0
- */
-function do_feed_rss() {
- load_template( ABSPATH . WPINC . '/feed-rss.php' );
-}
-
-/**
- * Load either the RSS2 comment feed or the RSS2 posts feed.
+ * This function is used throughout WordPress to allow for both string or array
+ * to be merged into another array.
*
- * @since 2.1.0
+ * @since 2.2.0
*
- * @param bool $for_comments True for the comment feed, false for normal feed.
+ * @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.
*/
-function do_feed_rss2( $for_comments ) {
- if ( $for_comments )
- load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
+function wp_parse_args( $args, $defaults = '' ) {
+ if ( is_object( $args ) )
+ $r = get_object_vars( $args );
+ elseif ( is_array( $args ) )
+ $r =& $args;
else
- load_template( ABSPATH . WPINC . '/feed-rss2.php' );
+ wp_parse_str( $args, $r );
+
+ if ( is_array( $defaults ) )
+ return array_merge( $defaults, $r );
+ return $r;
}
/**
- * Load either Atom comment feed or Atom posts feed.
+ * Clean up an array, comma- or space-separated list of IDs.
*
- * @since 2.1.0
+ * @since 3.0.0
*
- * @param bool $for_comments True for the comment feed, false for normal feed.
+ * @param array|string $list
+ * @return array Sanitized array of IDs
*/
-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_parse_id_list( $list ) {
+ if ( !is_array($list) )
+ $list = preg_split('/[\s,]+/', $list);
+
+ return array_unique(array_map('absint', $list));
}
/**
- * Display the robot.txt file content.
+ * Extract a slice of an array, given a list of keys.
*
- * The echo content should be with usage of the permalinks or for creating the
- * robot.txt file.
+ * @since 3.1.0
*
- * @since 2.1.0
- * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules.
+ * @param array $array The original array
+ * @param array $keys The list of keys
+ * @return array The array slice
*/
-function do_robots() {
- header( 'Content-Type: text/plain; charset=utf-8' );
+function wp_array_slice_assoc( $array, $keys ) {
+ $slice = array();
+ foreach ( $keys as $key )
+ if ( isset( $array[ $key ] ) )
+ $slice[ $key ] = $array[ $key ];
- 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";
- }
+ return $slice;
}
/**
- * Test whether blog is already installed.
- *
- * The cache will be checked first. If you have a cache plugin, which saves the
- * cache values, then this will work. If you use the default WordPress cache,
- * and the database goes away, then you might have problems.
- *
- * Checks for the option siteurl for whether WordPress is installed.
+ * Filters a list of objects, based on a set of key => value arguments.
*
- * @since 2.1.0
- * @uses $wpdb
+ * @since 3.0.0
*
- * @return bool Whether blog is already installed.
+ * @param array $list An array of objects to filter
+ * @param array $args An array of key => value arguments to match against each object
+ * @param string $operator The logical operation to perform. 'or' means only one element
+ * from the array needs to match; 'and' means all elements must match. The default is 'and'.
+ * @param bool|string $field A field from the object to place instead of the entire object
+ * @return array A list of objects or object fields
*/
-function is_blog_installed() {
- global $wpdb;
-
- // Check cache first. If options table goes away and we have true cached, oh well.
- if ( wp_cache_get( 'is_blog_installed' ) )
- return true;
+function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
+ if ( ! is_array( $list ) )
+ return array();
- $suppress = $wpdb->suppress_errors();
- $alloptions = wp_load_alloptions();
- // If siteurl is not set to autoload, check it specifically
- if ( !isset( $alloptions['siteurl'] ) )
- $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
- else
- $installed = $alloptions['siteurl'];
- $wpdb->suppress_errors( $suppress );
+ $list = wp_list_filter( $list, $args, $operator );
- $installed = !empty( $installed );
- wp_cache_set( 'is_blog_installed', $installed );
+ if ( $field )
+ $list = wp_list_pluck( $list, $field );
- return $installed;
+ return $list;
}
/**
- * Retrieve URL with nonce added to URL query.
+ * Filters a list of objects, based on a set of key => value arguments.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @since 3.1.0
*
- * @param string $actionurl URL to add nonce action
- * @param string $action Optional. Nonce action name
- * @return string URL with nonce action added.
+ * @param array $list An array of objects to filter
+ * @param array $args An array of key => value arguments to match against each object
+ * @param string $operator 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.
+ * The default is 'AND'.
+ * @return array
*/
-function wp_nonce_url( $actionurl, $action = -1 ) {
- $actionurl = str_replace( '&', '&', $actionurl );
- return esc_html( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
-}
+function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
+ if ( ! is_array( $list ) )
+ return array();
-/**
- * Retrieve or display nonce hidden field for forms.
- *
- * The nonce field is used to validate that the contents of the form came from
- * the location on the current site and not somewhere else. The nonce does not
- * offer absolute protection, but should protect against most cases. It is very
- * important to use nonce field in forms.
- *
- * If you set $echo to true and set $referer to true, then you will need to
- * retrieve the {@link wp_referer_field() wp referer field}. If you have the
- * $referer set to true and are echoing the nonce field, it will also echo the
- * referer field.
- *
- * The $action and $name are optional, but if you want to have better security,
- * it is strongly suggested to set those two parameters. It is easier to just
- * call the function without any parameters, because validation of the nonce
- * doesn't require any parameters, but since crackers know what the default is
- * it won't be difficult for them to find a way around your nonce and cause
- * damage.
- *
- * The input name will be whatever $name value you gave. The input value will be
- * the nonce creation value.
- *
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
- *
- * @param string $action Optional. Action name.
- * @param string $name Optional. Nonce name.
- * @param bool $referer Optional, default true. Whether to set the referer field for validation.
- * @param bool $echo Optional, default true. Whether to display or return hidden form field.
- * @return string Nonce field.
- */
-function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
- $name = esc_attr( $name );
- $nonce_field = '';
- if ( $echo )
- echo $nonce_field;
+ if ( empty( $args ) )
+ return $list;
- if ( $referer )
- wp_referer_field( $echo, 'previous' );
+ $operator = strtoupper( $operator );
+ $count = count( $args );
+ $filtered = array();
- return $nonce_field;
+ foreach ( $list as $key => $obj ) {
+ $to_match = (array) $obj;
+
+ $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;
+ }
+ }
+
+ return $filtered;
}
/**
- * Retrieve or display referer hidden field for forms.
- *
- * The referer link is the current Request URI from the server super global. The
- * input name is '_wp_http_referer', in case you wanted to check manually.
+ * Pluck a certain field out of each object in a list.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @since 3.1.0
*
- * @param bool $echo Whether to echo or return the referer field.
- * @return string Referer field.
+ * @param array $list A list of objects or arrays
+ * @param int|string $field A field from the object to place instead of the entire object
+ * @return array
*/
-function wp_referer_field( $echo = true) {
- $ref = esc_attr( $_SERVER['REQUEST_URI'] );
- $referer_field = '';
+function wp_list_pluck( $list, $field ) {
+ foreach ( $list as $key => $value ) {
+ if ( is_object( $value ) )
+ $list[ $key ] = $value->$field;
+ else
+ $list[ $key ] = $value[ $field ];
+ }
- if ( $echo )
- echo $referer_field;
- return $referer_field;
+ return $list;
}
/**
- * Retrieve or display original referer hidden field for forms.
- *
- * The input name is '_wp_original_http_referer' and will be either the same
- * value of {@link wp_referer_field()}, if that was posted already or it will
- * be the current page, if it doesn't exist.
+ * Determines if Widgets library should be loaded.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * 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 $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.
+ * @since 2.2.0
+ * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
*/
-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 wp_maybe_load_widgets() {
+ if ( ! apply_filters('load_default_widgets', true) )
+ return;
+ require_once( ABSPATH . WPINC . '/default-widgets.php' );
+ add_action( '_admin_menu', 'wp_widgets_add_menu' );
}
/**
- * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.
- *
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * Append the Widgets menu to the themes main menu.
*
- * @return string|bool False on failure. Referer URL on success.
+ * @since 2.2.0
+ * @uses $submenu The administration submenu list.
*/
-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'];
+function wp_widgets_add_menu() {
+ global $submenu;
- if ( $ref !== $_SERVER['REQUEST_URI'] )
- return $ref;
- return false;
+ if ( ! current_theme_supports( 'widgets' ) )
+ return;
+
+ $submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
+ ksort( $submenu['themes.php'], SORT_NUMERIC );
}
/**
- * Retrieve original referer that was posted, if it exists.
+ * Flush all output buffers for PHP 5.2.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * Make sure all output buffers are flushed before our singletons our destroyed.
*
- * @return string|bool False if no original referer or original referer if set.
+ * @since 2.2.0
*/
-function wp_get_original_referer() {
- if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
- return $_REQUEST['_wp_original_http_referer'];
- return false;
+function wp_ob_end_flush_all() {
+ $levels = ob_get_level();
+ for ($i=0; $i<$levels; $i++)
+ ob_end_flush();
}
/**
- * Recursive directory creation based on full path.
+ * Load custom DB error or display WordPress DB error.
*
- * Will attempt to set permissions on folders.
+ * 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 2.0.1
+ * 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.
*
- * @param string $target Full path to attempt to create.
- * @return bool Whether the path was created or not. True if path already exists.
+ * This function was backported to WordPress 2.3.2, but originally was added
+ * in WordPress 2.5.0.
+ *
+ * @since 2.3.2
+ * @uses $wpdb
*/
-function wp_mkdir_p( $target ) {
- // from php.net/mkdir user contributed notes
- $target = str_replace( '//', '/', $target );
- if ( file_exists( $target ) )
- return @is_dir( $target );
+function dead_db() {
+ global $wpdb;
- // 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;
+ // Load custom DB error template, if present.
+ if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
+ require_once( WP_CONTENT_DIR . '/db-error.php' );
+ die();
}
- // If the above failed, attempt to create the parent node, then try again.
- if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) )
- return wp_mkdir_p( $target );
+ // 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' );
- return false;
+ wp_load_translations_early();
+?>
+
+>
+
+
+
+
+
+
+
+
+
+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 ) );
+ }
}
+}
- $dir .= $subdir;
- $url .= $subdir;
+/**
+ * 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.
+ *
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
+ *
+ * This function is to be used in every file that is deprecated.
+ *
+ * @package WordPress
+ * @subpackage Debug
+ * @since 2.5.0
+ * @access private
+ *
+ * @uses do_action() Calls 'deprecated_file_included' and passes the file name, what to use instead,
+ * the version in which the file was deprecated, and any message regarding the change.
+ * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do
+ * trigger or false to not trigger error.
+ *
+ * @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
+ * @param string $message Optional. A message regarding the change
+ */
+function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
- $uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) );
+ do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
- // Make sure we have an uploads dir
- if ( ! wp_mkdir_p( $uploads['path'] ) ) {
- $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $uploads['path'] );
- return array( 'error' => $message );
+ // Allow plugin to filter the output error trigger
+ 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 );
+ }
}
-
- return $uploads;
}
-
/**
- * Get a filename that is sanitized and unique for the given directory.
+ * Marks a function argument as deprecated and informs when it has been used.
*
- * 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.
+ * 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' );
+ *
*
- * The callback must accept two parameters, the first one is the directory and
- * the second is the filename. The callback must be a function.
+ * 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.
*
- * @since 2.5
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
*
- * @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.
+ * @package WordPress
+ * @subpackage Debug
+ * @since 3.0.0
+ * @access private
+ *
+ * @uses do_action() Calls 'deprecated_argument_run' and passes the function name, a message on the change,
+ * and the version in which the argument was deprecated.
+ * @uses apply_filters() Calls 'deprecated_argument_trigger_error' and expects boolean value of true to do
+ * trigger or false to not trigger error.
+ *
+ * @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.
*/
-function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
- // sanitize the file name before we begin processing
- $filename = sanitize_file_name($filename);
-
- // separate the filename into a name and extension
- $info = pathinfo($filename);
- $ext = !empty($info['extension']) ? $info['extension'] : '';
- $name = basename($filename, ".{$ext}");
+function _deprecated_argument( $function, $version, $message = null ) {
- // 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 );
- } else {
- $number = '';
-
- if ( !empty( $ext ) )
- $ext = ".$ext";
+ do_action( 'deprecated_argument_run', $function, $message, $version );
- while ( file_exists( $dir . "/$filename" ) ) {
- if ( '' == "$number$ext" )
- $filename = $filename . ++$number . $ext;
+ // Allow plugin to filter the output error trigger
+ 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
- $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
+ 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 ) );
}
}
-
- return $filename;
}
/**
- * Create a file in the upload folder with given content.
+ * Marks something as being incorrectly called.
*
- * 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.
+ * 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.
*
- * This function will not move an uploaded file to the upload folder. It will
- * create a new file with the content in $bits parameter. If you move the upload
- * file, read the content of the uploaded file, and then you can give the
- * filename and content to this function, which will add it to the upload
- * folder.
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
*
- * The permissions will be set on the new file automatically by this function.
+ * @package WordPress
+ * @subpackage Debug
+ * @since 3.1.0
+ * @access private
*
- * @since 2.0.0
+ * @uses do_action() Calls 'doing_it_wrong_run' and passes the function arguments.
+ * @uses apply_filters() Calls 'doing_it_wrong_trigger_error' and expects boolean value of true to do
+ * trigger or false to not trigger error.
*
- * @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 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_upload_bits( $name, $deprecated, $bits, $time = null ) {
- if ( empty( $name ) )
- return array( 'error' => __( 'Empty filename' ) );
-
- $wp_filetype = wp_check_filetype( $name );
- if ( !$wp_filetype['ext'] )
- return array( 'error' => __( 'Invalid file type' ) );
-
- $upload = wp_upload_dir( $time );
-
- if ( $upload['error'] !== false )
- return $upload;
+function _doing_it_wrong( $function, $message, $version ) {
- $filename = wp_unique_filename( $upload['path'], $name );
+ do_action( 'doing_it_wrong_run', $function, $message, $version );
- $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 );
+ // Allow plugin to filter the output error trigger
+ 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 );
+ $message .= ' ' . __( 'Please see Debugging in WordPress for more information.' );
+ 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 .= ' Please see Debugging in WordPress for more information.';
+ trigger_error( sprintf( '%1$s was called incorrectly. %2$s %3$s', $function, $message, $version ) );
+ }
}
+}
- $ifp = @ fopen( $new_file, 'wb' );
- if ( ! $ifp )
- return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
-
- @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 );
+/**
+ * Is the server running earlier than 1.5.0 version of lighttpd?
+ *
+ * @since 2.5.0
+ *
+ * @return bool Whether the server is running lighttpd < 1.5.0
+ */
+function is_lighttpd_before_150() {
+ $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' );
+ $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : '';
+ return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
+}
- // Compute the URL
- $url = $upload['url'] . "/$filename";
+/**
+ * Does the specified module exist in the Apache config?
+ *
+ * @since 2.5.0
+ *
+ * @param string $mod e.g. mod_rewrite
+ * @param bool $default The default return value if the module is not found
+ * @return bool
+ */
+function apache_mod_loaded($mod, $default = false) {
+ global $is_apache;
- return array( 'file' => $new_file, 'url' => $url, 'error' => false );
+ if ( !$is_apache )
+ return false;
+
+ if ( function_exists('apache_get_modules') ) {
+ $mods = apache_get_modules();
+ if ( in_array($mod, $mods) )
+ return true;
+ } elseif ( function_exists('phpinfo') ) {
+ ob_start();
+ phpinfo(8);
+ $phpinfo = ob_get_clean();
+ if ( false !== strpos($phpinfo, $mod) )
+ return true;
+ }
+ return $default;
}
/**
- * Retrieve the file type based on the extension name.
+ * Check if IIS 7+ supports pretty permalinks.
*
- * @package WordPress
- * @since 2.5.0
- * @uses apply_filters() Calls 'ext2type' hook on default supported types.
+ * @since 2.8.0
*
- * @param string $ext The extension to search.
- * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
+ * @return bool
*/
-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', 'm4v'),
- '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 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') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' );
+ }
+
+ return apply_filters('iis7_supports_permalinks', $supports_permalinks);
}
/**
- * Retrieve the file type from the file name.
+ * File validates against allowed set of defined rules.
*
- * You can optionally define the mime array, if needed.
+ * 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.4
+ * @since 1.2.0
*
- * @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.
+ * @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_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' => 'video/mpeg',
- 'txt|c|cc|h' => 'text/plain',
- 'rtx' => 'text/richtext',
- 'css' => 'text/css',
- 'htm|html' => 'text/html',
- 'mp3|m4a' => 'audio/mpeg',
- 'mp4|m4v' => 'video/mp4',
- '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 validate_file( $file, $allowed_files = '' ) {
+ if ( false !== strpos( $file, '..' ) )
+ return 1;
- $type = false;
- $ext = false;
+ if ( false !== strpos( $file, './' ) )
+ 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 ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
+ return 3;
- return compact( 'ext', 'type' );
+ if (':' == substr( $file, 1, 1 ) )
+ return 2;
+
+ return 0;
}
/**
- * Retrieve nonce action "Are you sure" message.
+ * Determine if SSL is used.
*
- * 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 2.6.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).
+ * @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;
+}
+
+/**
+ * Whether SSL login should be forced.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @since 2.6.0
*
- * @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_cat_name' );
- $trans['update']['category'] = array( __( 'Your attempt to edit this category: “%s” has failed.' ), 'get_cat_name' );
-
- $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_the_author_meta', 'display_name' );
- $trans['update']['profile'] = array( __( 'Your attempt to modify the profile for: “%s” has failed.' ), 'get_the_author_meta', 'display_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];
- if ( isset($trans[$verb][$noun][2]) )
- $lookup_value = $trans[$verb][$noun][2];
- $object = $matches[4];
- if ( 'use_id' != $lookup ) {
- if ( isset( $lookup_value ) )
- $object = call_user_func( $lookup, $lookup_value, $object );
- else
- $object = call_user_func( $lookup, $object );
- }
- return sprintf( $trans[$verb][$noun][0], esc_html($object) );
- } else {
- return $trans[$verb][$noun][0];
- }
- }
+ * @param string|bool $force Optional.
+ * @return bool True if forced, false if not forced.
+ */
+function force_ssl_login( $force = null ) {
+ static $forced = false;
- return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
- } else {
- return apply_filters( 'explain_nonce_' . $action, __( 'Are you sure you want to do this?' ) );
+ if ( !is_null( $force ) ) {
+ $old_forced = $forced;
+ $forced = $force;
+ return $old_forced;
}
+
+ return $forced;
}
/**
- * Display "Are You Sure" message to confirm the action being taken.
- *
- * If the action has the nonce explain message, then it will be displayed along
- * with the "Are you sure?" message.
+ * Whether to force SSL used for the Administration Screens.
*
- * @package WordPress
- * @subpackage Security
- * @since 2.0.4
+ * @since 2.6.0
*
- * @param string $action The nonce action.
+ * @param string|bool $force
+ * @return bool True if forced, false if not forced.
*/
-function wp_nonce_ays( $action ) {
- $title = __( 'WordPress Failure Notice' );
- $html = esc_html( wp_explain_nonce( $action ) );
- if ( wp_get_referer() )
- $html .= "
";
- }
-
- 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/';
- if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) :
- if( !headers_sent() ){
- status_header( $r['response'] );
- nocache_headers();
- header( 'Content-Type: text/html; charset=utf-8' );
+ $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
+ $url = $schema . $_SERVER['HTTP_HOST'] . $path;
}
- if ( empty($title) ) {
- $title = $have_gettext? __('WordPress › Error') : 'WordPress › Error';
- }
-
- $text_direction = 'ltr';
- if ( isset($r['text_direction']) && $r['text_direction'] == 'rtl' ) $text_direction = 'rtl';
- if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) $text_direction = 'rtl';
-?>
-
->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-text_direction ) {
- $input['directionality'] = 'rtl';
- $input['plugins'] .= ',directionality';
- $input['theme_advanced_buttons1'] .= ',ltr';
- }
+function wp_suspend_cache_invalidation($suspend = true) {
+ global $_wp_suspend_cache_invalidation;
- return $input;
+ $current_suspend = $_wp_suspend_cache_invalidation;
+ $_wp_suspend_cache_invalidation = $suspend;
+ return $current_suspend;
}
-
/**
- * 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.
+ * Whether a site is the main site of the current network.
*
- * 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 and is set each
- * time the function is called.
+ * @param int $site_id Optional. Site ID to test. 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;
+
+ if ( ! is_multisite() )
+ return true;
+
+ if ( ! $site_id )
+ $site_id = get_current_blog_id();
+
+ return (int) $site_id === (int) $current_site->blog_id;
+}
+
+/**
+ * Whether a network is the main network of the multisite install.
*
- * 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.
+ * @since 3.7.0
*
- * @global array $wpsmiliestrans
- * @global array $wp_smiliessearch
- * @since 2.2.0
+ * @param int $network_id Optional. Network ID to test. Defaults to current network.
+ * @return bool True if $network_id is the main network, or if not running multisite.
*/
-function smilies_init() {
- global $wpsmiliestrans, $wp_smiliessearch;
+function is_main_network( $network_id = null ) {
+ global $wpdb;
- // don't bother setting up smilies if they are disabled
- if ( !get_option( 'use_smilies' ) )
- return;
+ if ( ! is_multisite() )
+ return true;
- 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',
- );
- }
+ $current_network_id = (int) get_current_site()->id;
- if (count($wpsmiliestrans) == 0) {
- return;
- }
+ if ( ! $network_id )
+ $network_id = $current_network_id;
+ $network_id = (int) $network_id;
- /*
- * 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);
+ if ( defined( 'PRIMARY_NETWORK_ID' ) )
+ return $network_id === (int) PRIMARY_NETWORK_ID;
- $wp_smiliessearch = '/(?:\s|^)';
+ if ( 1 === $current_network_id )
+ return $network_id === $current_network_id;
- $subchar = '';
- foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
- $firstchar = substr($smiley, 0, 1);
- $rest = substr($smiley, 1);
+ $primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' );
- // new subpattern?
- if ($firstchar != $subchar) {
- if ($subchar != '') {
- $wp_smiliessearch .= ')|(?:\s|^)';
- }
- $subchar = $firstchar;
- $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
- } else {
- $wp_smiliessearch .= '|';
- }
- $wp_smiliessearch .= preg_quote($rest);
- }
+ if ( $primary_network_id )
+ return $network_id === $primary_network_id;
+
+ $primary_network_id = (int) $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" );
+ wp_cache_add( 'primary_network_id', $primary_network_id, 'site-options' );
- $wp_smiliessearch .= ')(?:\s|$)/m';
+ return $network_id === $primary_network_id;
}
/**
- * Merge user defined arguments into defaults array.
+ * Whether global terms are enabled.
*
- * This function is used throughout WordPress to allow for both string or array
- * to be merged into another array.
*
- * @since 2.2.0
+ * @since 3.0.0
+ * @package WordPress
*
- * @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.
+ * @return bool True if multisite and global terms enabled
*/
-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 global_terms_enabled() {
+ if ( ! is_multisite() )
+ return false;
- if ( is_array( $defaults ) )
- return array_merge( $defaults, $r );
- return $r;
+ static $global_terms = null;
+ if ( is_null( $global_terms ) ) {
+ $filter = apply_filters( 'global_terms_enabled', null );
+ if ( ! is_null( $filter ) )
+ $global_terms = (bool) $filter;
+ else
+ $global_terms = (bool) get_site_option( 'global_terms_enabled', false );
+ }
+ return $global_terms;
}
/**
- * Determines if Widgets library should be loaded.
+ * gmt_offset modification for smart timezone handling.
*
- * 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.
+ * Overrides the gmt_offset option if we have a timezone_string available.
*
- * @since 2.2.0
- * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
+ * @since 2.8.0
+ *
+ * @return float|bool
*/
-function wp_maybe_load_widgets() {
- if ( ! apply_filters('load_default_widgets', true) )
- return;
- require_once( ABSPATH . WPINC . '/default-widgets.php' );
- add_action( '_admin_menu', 'wp_widgets_add_menu' );
+function wp_timezone_override_offset() {
+ if ( !$timezone_string = get_option( 'timezone_string' ) ) {
+ return false;
+ }
+
+ $timezone_object = timezone_open( $timezone_string );
+ $datetime_object = date_create();
+ if ( false === $timezone_object || false === $datetime_object ) {
+ return false;
+ }
+ return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
}
/**
- * Append the Widgets menu to the themes main menu.
+ * Sort-helper for timezones.
*
- * @since 2.2.0
- * @uses $submenu The administration submenu list.
+ * @since 2.9.0
+ *
+ * @param array $a
+ * @param array $b
+ * @return int
*/
-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_timezone_choice_usort_callback( $a, $b ) {
+ // Don't use translated versions of Etc
+ if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
+ // Make the order of these more like the old dropdown
+ if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
+ return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
+ }
+ if ( 'UTC' === $a['city'] ) {
+ if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
+ return 1;
+ }
+ return -1;
+ }
+ if ( 'UTC' === $b['city'] ) {
+ if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
+ return -1;
+ }
+ return 1;
+ }
+ return strnatcasecmp( $a['city'], $b['city'] );
+ }
+ if ( $a['t_continent'] == $b['t_continent'] ) {
+ if ( $a['t_city'] == $b['t_city'] ) {
+ return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
+ }
+ return strnatcasecmp( $a['t_city'], $b['t_city'] );
+ } else {
+ // Force Etc to the bottom of the list
+ if ( 'Etc' === $a['continent'] ) {
+ return 1;
+ }
+ if ( 'Etc' === $b['continent'] ) {
+ return -1;
+ }
+ return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
+ }
}
/**
- * Flush all output buffers for PHP 5.2.
+ * Gives a nicely formatted list of timezone strings.
*
- * Make sure all output buffers are flushed before our singletons our destroyed.
+ * @since 2.9.0
*
- * @since 2.2.0
+ * @param string $selected_zone Selected Zone
+ * @return string
*/
-function wp_ob_end_flush_all() {
- $levels = ob_get_level();
- for ($i=0; $i<$levels; $i++)
- ob_end_flush();
+function wp_timezone_choice( $selected_zone ) {
+ static $mo_loaded = false;
+
+ $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
+
+ // Load translations for continents and cities
+ if ( !$mo_loaded ) {
+ $locale = get_locale();
+ $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
+ load_textdomain( 'continents-cities', $mofile );
+ $mo_loaded = true;
+ }
+
+ $zonen = array();
+ foreach ( timezone_identifiers_list() as $zone ) {
+ $zone = explode( '/', $zone );
+ if ( !in_array( $zone[0], $continents ) ) {
+ continue;
+ }
+
+ // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
+ $exists = array(
+ 0 => ( isset( $zone[0] ) && $zone[0] ),
+ 1 => ( isset( $zone[1] ) && $zone[1] ),
+ 2 => ( isset( $zone[2] ) && $zone[2] ),
+ );
+ $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
+ $exists[4] = ( $exists[1] && $exists[3] );
+ $exists[5] = ( $exists[2] && $exists[3] );
+
+ $zonen[] = array(
+ 'continent' => ( $exists[0] ? $zone[0] : '' ),
+ 'city' => ( $exists[1] ? $zone[1] : '' ),
+ 'subcity' => ( $exists[2] ? $zone[2] : '' ),
+ 't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),
+ 't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),
+ 't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' )
+ );
+ }
+ usort( $zonen, '_wp_timezone_choice_usort_callback' );
+
+ $structure = array();
+
+ if ( empty( $selected_zone ) ) {
+ $structure[] = '';
+ }
+
+ 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[] = '';
+ }
+ }
+
+ // Do UTC
+ $structure[] = '';
+
+ // Do manual UTC offsets
+ $structure[] = '';
+
+ return join( "\n", $structure );
}
/**
- * Load the correct database class file.
+ * Strip close comment and close php tags from file headers used by WP.
+ * See http://core.trac.wordpress.org/ticket/8497
*
- * 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 2.8.0
*
- * @since 2.5.0
- * @global $wpdb WordPress Database Object
+ * @param string $str
+ * @return string
+ */
+function _cleanup_header_comment($str) {
+ return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
+}
+
+/**
+ * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.
+ *
+ * @since 2.9.0
*/
-function require_wp_db() {
+function wp_scheduled_delete() {
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' );
+
+ $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($comment_id);
+ }
+ }
}
/**
- * Load custom DB error or display WordPress DB error.
+ * Retrieve metadata from a file.
*
- * 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.
+ * 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.
*
- * 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.
+ * 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.
*
- * This function was backported to the the WordPress 2.3.2, but originally was
- * added in WordPress 2.5.0.
+ * @see http://codex.wordpress.org/File_Header
*
- * @since 2.3.2
- * @uses $wpdb
+ * @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 If specified adds filter hook "extra_{$context}_headers"
*/
-function dead_db() {
- global $wpdb;
+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' );
- // 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();
- }
+ // Pull only the first 8kiB of the file in.
+ $file_data = fread( $fp, 8192 );
- // If installing or in the admin, provide the verbose message.
- if ( defined('WP_INSTALLING') || defined('WP_ADMIN') )
- wp_die($wpdb->error);
+ // PHP will close file handle, but we are good citizens.
+ fclose( $fp );
- // Otherwise, be terse.
- status_header( 500 );
- nocache_headers();
- header( 'Content-Type: text/html; charset=utf-8' );
-?>
-
->
-
-
- Database Error
+ // Make sure we catch CR-only line endings.
+ $file_data = str_replace( "\r", "\n", $file_data );
-
-
-
Error establishing a database connection
-
-
- $regex ) {
+ if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] )
+ $all_headers[ $field ] = _cleanup_header_comment( $match[1] );
+ else
+ $all_headers[ $field ] = '';
+ }
+
+ return $all_headers;
}
/**
- * Converts value to nonnegative integer.
+ * Returns true.
*
- * @since 2.5.0
+ * Useful for returning true to filters easily.
*
- * @param mixed $maybeint Data you wish to have convered to an nonnegative integer
- * @return int An nonnegative integer
+ * @since 3.0.0
+ * @see __return_false()
+ * @return bool true
*/
-function absint( $maybeint ) {
- return abs( intval( $maybeint ) );
+function __return_true() {
+ return true;
}
/**
- * Determines if the blog can be accessed over SSL.
- *
- * 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.
+ * Returns false.
*
- * @since 2.5.0
+ * Useful for returning false to filters easily.
*
- * @return bool Whether or not SSL access is available
+ * @since 3.0.0
+ * @see __return_true()
+ * @return bool false
*/
-function url_is_accessable_via_ssl($url)
-{
- if (in_array('curl', get_loaded_extensions())) {
- $ssl = preg_replace( '/^http:\/\//', 'https://', $url );
-
- $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);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
-
- curl_exec($ch);
-
- $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close ($ch);
-
- if ($status == 200 || $status == 401) {
- return true;
- }
- }
+function __return_false() {
return false;
}
/**
- * Secure URL, if available or the given URL.
+ * Returns 0.
*
- * @since 2.5.0
+ * Useful for returning 0 to filters easily.
*
- * @param string $url Complete URL path with transport.
- * @return string Secure or regular URL path.
+ * @since 3.0.0
+ * @return int 0
*/
-function atom_service_url_filter($url)
-{
- if ( url_is_accessable_via_ssl($url) )
- return preg_replace( '/^http:\/\//', 'https://', $url );
- else
- return $url;
+function __return_zero() {
+ return 0;
}
/**
- * Marks a function as deprecated and informs when it has been used.
+ * Returns an empty array.
*
- * 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.
+ * Useful for returning an empty array to filters easily.
*
- * The current behavior is to trigger an user error if WP_DEBUG is defined and
- * is true.
+ * @since 3.0.0
+ * @return array Empty array
+ */
+function __return_empty_array() {
+ return array();
+}
+
+/**
+ * Returns null.
*
- * This function is to be used in every function in depreceated.php
+ * Useful for returning null to filters easily.
*
- * @package WordPress
- * @package Debug
- * @since 2.5.0
- * @access private
+ * @since 3.4.0
+ * @return null
+ */
+function __return_null() {
+ return null;
+}
+
+/**
+ * Returns an empty string.
*
- * @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.
+ * Useful for returning an empty string to filters easily.
*
- * @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.7.0
+ * @see __return_null()
+ * @return string Empty string
*/
-function _deprecated_function($function, $version, $replacement=null) {
+function __return_empty_string() {
+ return '';
+}
- do_action('deprecated_function_run', $function, $replacement);
+/**
+ * Send a HTTP header to disable content type sniffing in browsers which support it.
+ *
+ * @link http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
+ * @link http://src.chromium.org/viewvc/chrome?view=rev&revision=6985
+ *
+ * @since 3.0.0
+ * @return none
+ */
+function send_nosniff_header() {
+ @header( 'X-Content-Type-Options: nosniff' );
+}
- // 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 ) );
+/**
+ * Returns a MySQL expression for selecting the week number based on the start_of_week option.
+ *
+ * @internal
+ * @since 3.0.0
+ * @param string $column
+ * @return string
+ */
+function _wp_mysql_week( $column ) {
+ switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) {
+ default :
+ case 0 :
+ return "WEEK( $column, 0 )";
+ 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 )";
}
}
/**
- * Marks a file as deprecated and informs when it has been used.
+ * Finds hierarchy loops using a callback function that maps object IDs to parent IDs.
*
- * 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.
+ * @since 3.1.0
+ * @access private
*
- * The current behavior is to trigger an user error if WP_DEBUG is defined and
- * is true.
+ * @param callback $callback function that accepts ( ID, $callback_args ) and outputs parent_ID
+ * @param int $start The ID to start the loop check at
+ * @param int $start_parent the parent_ID of $start to use instead of calling $callback( $start ). Use null to always use $callback
+ * @param array $callback_args optional additional arguments to send to $callback
+ * @return array IDs of all members of loop
+ */
+function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
+ $override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
+
+ if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) )
+ return array();
+
+ return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
+}
+
+/**
+ * Uses the "The Tortoise and the Hare" algorithm to detect loops.
*
- * This function is to be used in every file that is depreceated
+ * 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.
*
- * @package WordPress
- * @package Debug
- * @since 2.5.0
+ * @since 3.1.0
* @access private
*
- * @uses do_action() Calls 'deprecated_file_included' and passes the file name and what to use instead.
- * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
- *
- * @param string $file The file that was included
- * @param string $version The version of WordPress that deprecated the function
- * @param string $replacement Optional. The function that should have been called
+ * @param callback $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 an array of ( ID => parent_ID, ... ) to use instead of $callback
+ * @param array $callback_args optional additional arguments to send to $callback
+ * @param bool $_return_loop 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)
+ * @return mixed scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop
*/
-function _deprecated_file($file, $version, $replacement=null) {
-
- do_action('deprecated_file_included', $file, $replacement);
-
- // Allow plugin to filter the output error trigger
- if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_file_trigger_error', true )) {
- if( !is_null($replacement) )
- trigger_error( sprintf( __('%1$s is 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_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;
}
/**
- * Is the server running earlier than 1.5.0 version of lighttpd
+ * Send a HTTP header to limit rendering of pages to same origin iframes.
*
- * @since 2.5.0
+ * @link https://developer.mozilla.org/en/the_x-frame-options_response_header
*
- * @return bool Whether the server is running lighttpd < 1.5.0
+ * @since 3.1.3
+ * @return none
*/
-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 send_frame_options_header() {
+ @header( 'X-Frame-Options: SAMEORIGIN' );
}
/**
- * Does the specified module exist in the apache config?
+ * Retrieve a list of protocols to allow in HTML attributes.
*
- * @since 2.5.0
+ * @since 3.3.0
+ * @see wp_kses()
+ * @see esc_url()
*
- * @param string $mod e.g. mod_rewrite
- * @param bool $default The default return value if the module is not found
- * @return bool
+ * @return array Array of allowed protocols
*/
-function apache_mod_loaded($mod, $default = false) {
- global $is_apache;
-
- if ( !$is_apache )
- return false;
+function wp_allowed_protocols() {
+ static $protocols;
- 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;
+ if ( empty( $protocols ) ) {
+ $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' );
+ $protocols = apply_filters( 'kses_allowed_protocols', $protocols );
}
- return $default;
+
+ return $protocols;
}
/**
- * File validates against allowed set of defined rules.
- *
- * 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.
+ * Return a comma separated string of functions that have been called to get to the current point in code.
*
- * @since 1.2.0
+ * @link http://core.trac.wordpress.org/ticket/19589
+ * @since 3.4.0
*
- * @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.
+ * @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the callee
+ * @param int $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue
+ * @param bool $pretty Whether or not you want a comma separated string or raw array returned
+ * @return string|array Either a string containing a reversed comma separated trace or an array of individual calls.
*/
-function validate_file( $file, $allowed_files = '' ) {
- if ( false !== strpos( $file, '..' ))
- return 1;
-
- if ( false !== strpos( $file, './' ))
- return 1;
+function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
+ if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
+ $trace = debug_backtrace( false );
+ else
+ $trace = debug_backtrace();
- if (':' == substr( $file, 1, 1 ))
- return 2;
+ $caller = array();
+ $check_class = ! is_null( $ignore_class );
+ $skip_frames++; // skip this function
- if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
- return 3;
+ 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
- return 0;
+ $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;
}
/**
- * Determine if SSL is used.
+ * Retrieve ids that are not already present in the cache
*
- * @since 2.6.0
+ * @since 3.4.0
*
- * @return bool True if SSL, false if not used.
+ * @param array $object_ids ID list
+ * @param string $cache_key The cache bucket to check against
+ *
+ * @return array
*/
-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;
+function _get_non_cached_ids( $object_ids, $cache_key ) {
+ $clean = array();
+ foreach ( $object_ids as $id ) {
+ $id = (int) $id;
+ if ( !wp_cache_get( $id, $cache_key ) ) {
+ $clean[] = $id;
+ }
}
- return false;
+
+ return $clean;
}
/**
- * Whether SSL login should be forced.
+ * Test if the current device has the capability to upload files.
*
- * @since 2.6.0
+ * @since 3.4.0
+ * @access private
*
- * @param string|bool $force Optional.
- * @return bool True if forced, false if not forced.
+ * @return bool true|false
*/
-function force_ssl_login($force = '') {
- static $forced;
+function _device_can_upload() {
+ if ( ! wp_is_mobile() )
+ return true;
- if ( '' != $force ) {
- $old_forced = $forced;
- $forced = $force;
- return $old_forced;
+ $ua = $_SERVER['HTTP_USER_AGENT'];
+
+ if ( strpos($ua, 'iPhone') !== false
+ || strpos($ua, 'iPad') !== false
+ || strpos($ua, 'iPod') !== false ) {
+ return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
}
- return $forced;
+ return true;
}
/**
- * Whether to force SSL used for the Administration Panels.
- *
- * @since 2.6.0
+ * Test if a given path is a stream URL
*
- * @param string|bool $force
- * @return bool True if forced, false if not forced.
+ * @param string $path The resource path or URL
+ * @return bool True if the path is a stream URL
*/
-function force_ssl_admin($force = '') {
- static $forced;
-
- if ( '' != $force ) {
- $old_forced = $forced;
- $forced = $force;
- return $old_forced;
- }
+function wp_is_stream( $path ) {
+ $wrappers = stream_get_wrappers();
+ $wrappers_re = '(' . join('|', $wrappers) . ')';
- return $forced;
+ return preg_match( "!^$wrappers_re://!", $path ) === 1;
}
/**
- * Guess the URL for the site.
- *
- * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
- * directory.
+ * Test if the supplied date is valid for the Gregorian calendar
*
- * @since 2.6.0
+ * @since 3.5.0
*
- * @return string
+ * @return bool true|false
*/
-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']);
- }
- return $url;
+function wp_checkdate( $month, $day, $year, $source_date ) {
+ return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
}
/**
- * Suspend cache invalidation.
+ * Load the auth check for monitoring whether the user is still logged in.
*
- * 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.
+ * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
- * @since 2.7.0
+ * 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 bool $suspend Whether to suspend or enable cache invalidation
- * @return bool The current suspend setting
+ * @since 3.6.0
*/
-function wp_suspend_cache_invalidation($suspend = true) {
- global $_wp_suspend_cache_invalidation;
+function wp_auth_check_load() {
+ if ( ! is_admin() && ! is_user_logged_in() )
+ return;
- $current_suspend = $_wp_suspend_cache_invalidation;
- $_wp_suspend_cache_invalidation = $suspend;
- return $current_suspend;
-}
+ if ( defined( 'IFRAME_REQUEST' ) )
+ return;
-function get_site_option( $key, $default = false, $use_cache = true ) {
- return get_option($key, $default);
-}
+ $screen = get_current_screen();
+ $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
+ $show = ! in_array( $screen->id, $hidden );
-// expects $key, $value not to be SQL escaped
-function add_site_option( $key, $value ) {
- return add_option($key, $value);
-}
+ if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
+ wp_enqueue_style( 'wp-auth-check' );
+ wp_enqueue_script( 'wp-auth-check' );
-// expects $key, $value not to be SQL escaped
-function update_site_option( $key, $value ) {
- return update_option($key, $value);
+ add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
+ add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
+ }
}
/**
- * gmt_offset modification for smart timezone handling
+ * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
- * Overrides the gmt_offset option if we have a timezone_string available
+ * @since 3.6.0
*/
-function wp_timezone_override_offset() {
- if (!wp_timezone_supported()) return false;
-
- $tz = get_option('timezone_string');
- if (empty($tz)) return false;
-
- @date_default_timezone_set($tz);
-
- $dateTimeZoneSelected = timezone_open($tz);
- $dateTimeServer = date_create();
- if ($dateTimeZoneSelected === false || $dateTimeServer === false) return false;
-
- $timeOffset = timezone_offset_get($dateTimeZoneSelected, $dateTimeServer);
- $timeOffset = $timeOffset / 3600;
+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 );
+
+ if ( $same_domain && force_ssl_login() && ! force_ssl_admin() )
+ $same_domain = false;
+
+ // Let plugins change this if they know better.
+ $same_domain = apply_filters( 'wp_auth_check_same_domain', $same_domain );
+ $wrap_class = $same_domain ? 'hidden' : 'hidden fallback';
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}
/**
- * Gives a nicely formatted list of timezone strings // temporary! Not in final
+ * Return a canonical form of the provided charset appropriate for passing to PHP
+ * functions such as htmlspecialchars() and charset html attributes.
*
- * @param string $selectedzone - which zone should be the selected one
+ * @link http://core.trac.wordpress.org/ticket/23688
+ * @since 3.6.0
*
+ * @param string A charset name
+ * @return string The canonical form of the charset
*/
-function wp_timezone_choice($selectedzone) {
- static $mo_loaded = false;
+function _canonical_charset( $charset ) {
+ if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset ||
+ 'UTF8' === $charset )
+ return 'UTF-8';
- $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc');
+ if ( 'ISO-8859-1' === $charset || 'iso-8859-1' === $charset ||
+ 'iso8859-1' === $charset || 'ISO8859-1' === $charset )
+ return 'ISO-8859-1';
- // Load translations for continents and cities
- if ( ! $mo_loaded ) {
- $locale = get_locale();
- $mofile = WP_LANG_DIR . "/continents-cities-$locale.mo";
- load_textdomain('continents-cities', $mofile);
- $mo_loaded = true;
- }
+ return $charset;
+}
- $all = timezone_identifiers_list();
+/**
+ * Sets the mbstring internal encoding to a binary safe encoding whne func_overload is enabled.
+ *
+ * When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and
+ * similar functions respect the utf8 characters, causing binary data to return incorrect lengths.
+ *
+ * This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the
+ * users expected encoding afterwards through the `reset_mbstring_encoding` function.
+ *
+ * It is safe to recursively call this function, however each `mbstring_binary_safe_encoding()`
+ * call must be followed up with an equal number of `reset_mbstring_encoding()` calls.
+ *
+ * @see reset_mbstring_encoding()
+ *
+ * @since 3.7.0
+ *
+ * @param bool $reset Whether to reset the encoding back to a previously-set encoding.
+ */
+function mbstring_binary_safe_encoding( $reset = false ) {
+ static $encodings = array();
+ static $overloaded = null;
- $i = 0;
- foreach ( $all as $zone ) {
- $zone = explode('/',$zone);
- if ( ! in_array($zone[0], $continents) )
- continue;
- if ( $zone[0] == 'Etc' && in_array($zone[1], array('UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu')) )
- continue;
- $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
- $zonen[$i]['city'] = isset($zone[1]) ? $zone[1] : '';
- $zonen[$i]['subcity'] = isset($zone[2]) ? $zone[2] : '';
- $i++;
- }
-
- usort($zonen, create_function(
- '$a, $b', '
- $t = create_function(\'$s\', \'return translate(str_replace("_", " ", $s), "continents-cities");\');
- $a_continent = $t($a["continent"]);
- $b_continent = $t($b["continent"]);
- $a_city = $t($a["city"]);
- $b_city = $t($b["city"]);
- $a_subcity = $t($a["subcity"]);
- $b_subcity = $t($b["subcity"]);
- if ( $a_continent == $b_continent && $a_city == $b_city )
- return strnatcasecmp($a_subcity, $b_subcity);
- elseif ( $a_continent == $b_continent )
- return strnatcasecmp($a_city, $b_city);
- else
- return strnatcasecmp($a_continent, $b_continent);
- '));
-
- $structure = '';
- $pad = ' ';
-
- if ( empty($selectedzone) )
- $structure .= '\n";
- foreach ( $zonen as $zone ) {
- extract($zone);
- if ( empty($selectcontinent) && !empty($city) ) {
- $selectcontinent = $continent;
- $structure .= '\n";
- $selectcontinent = '';
- if ( !empty($city) ) {
- $selectcontinent = $continent;
- $structure .= '\n";
- return $structure;
+ if ( $reset && $encodings ) {
+ $encoding = array_pop( $encodings );
+ mb_internal_encoding( $encoding );
+ }
}
-
-
/**
- * Strip close comment and close php tags from file headers used by WP
- * See http://core.trac.wordpress.org/ticket/8497
+ * Resets the mbstring internal encoding to a users previously set encoding.
*
- * @since 2.8
-**/
-function _cleanup_header_comment($str) {
- return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
+ * @see mbstring_binary_safe_encoding()
+ *
+ * @since 3.7.0
+ */
+function reset_mbstring_encoding() {
+ mbstring_binary_safe_encoding( true );
}
-?>