X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/fef8173b8c3bad08f495551e43cfdeac1cae6021..97318cb132b41ce8416eeb8bc0bf2b82cbcc2572:/wp-includes/functions.php diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 65ee33ea..6b5aa505 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -20,7 +20,7 @@ * @param string $dateformatstring Either 'G', 'U', or php date format. * @param string $mysqlstring Time from mysql DATETIME field. * @param bool $translate Optional. Default is true. Will switch format to locale. - * @return string Date formated by $dateformatstring or locale (if available). + * @return string Date formatted by $dateformatstring or locale (if available). */ function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { $m = $mysqlstring; @@ -84,8 +84,8 @@ function current_time( $type, $gmt = 0 ) { function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { global $wp_locale; $i = $unixtimestamp; - // Sanity check for PHP 5.1.0- - if ( false === $i || intval($i) < 0 ) { + + if ( false === $i ) { if ( ! $gmt ) $i = current_time( 'timestamp' ); else @@ -120,7 +120,7 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { } $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); $timezone_formats_re = implode( '|', $timezone_formats ); - if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) && wp_timezone_supported() ) { + if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { $timezone_string = get_option( 'timezone_string' ); if ( $timezone_string ) { $timezone_object = timezone_open( $timezone_string ); @@ -288,9 +288,19 @@ function is_serialized_string( $data ) { if ( !is_string( $data ) ) return false; $data = trim( $data ); - if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings + $length = strlen( $data ); + if ( $length < 4 ) + return false; + elseif ( ':' !== $data[1] ) + return false; + elseif ( ';' !== $data[$length-1] ) + return false; + elseif ( $data[0] !== 's' ) + return false; + elseif ( '"' !== $data[$length-2] ) + return false; + else return true; - return false; } /** @@ -314,6 +324,7 @@ function is_serialized_string( $data ) { * the option value. * * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. + * @param mixed $default Optional. Default value to return if the option does not exist. * @return mixed Value set for the option. */ function get_option( $option, $default = false ) { @@ -444,7 +455,7 @@ function wp_load_alloptions() { } /** - * Loads and caches certain often requested site options if is_multisite() and a peristent cache is not being used. + * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used. * * @since 3.0.0 * @package WordPress @@ -509,7 +520,7 @@ function update_option( $option, $newvalue ) { wp_protect_special_option( $option ); if ( is_object($newvalue) ) - $newvalue = wp_clone($newvalue); + $newvalue = clone $newvalue; $newvalue = sanitize_option( $option, $newvalue ); $oldvalue = get_option( $option ); @@ -559,11 +570,10 @@ function update_option( $option, $newvalue ) { * it will be serialized before it is inserted into the database. Remember, * resources can not be serialized or added as an option. * - * You can create options without values and then add values later. Does not - * check whether the option has already been added, but does check that you + * You can create options without values and then update the values later. + * Existing options will not be updated and checks are performed to ensure that you * aren't adding a protected WordPress option. Care should be taken to not name - * options the same as the ones which are protected and to not add options - * that were already added. + * options the same as the ones which are protected. * * @package WordPress * @subpackage Option @@ -576,7 +586,7 @@ function update_option( $option, $newvalue ) { * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. * @param mixed $deprecated Optional. Description. Not used anymore. * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up. - * @return null returns when finished. + * @return bool False if option was not added and true if option was added. */ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { global $wpdb; @@ -591,7 +601,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) wp_protect_special_option( $option ); if ( is_object($value) ) - $value = wp_clone($value); + $value = clone $value; $value = sanitize_option( $option, $value ); @@ -599,7 +609,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) if ( false !== get_option( $option ) ) - return; + return false; $_value = $value; $value = maybe_serialize( $value ); @@ -676,7 +686,7 @@ function delete_option( $option ) { } /** - * Delete a transient + * Delete a transient. * * @since 2.8.0 * @package WordPress @@ -709,7 +719,7 @@ function delete_transient( $transient ) { } /** - * Get the value of a transient + * Get the value of a transient. * * If the transient does not exist or does not have a value, then the return value * will be false. @@ -758,7 +768,7 @@ function get_transient( $transient ) { } /** - * Set/update the value of a transient + * Set/update the value of a transient. * * You do not need to serialize values. If the value needs to be serialized, then * it will be serialized before it is set. @@ -1027,6 +1037,8 @@ function maybe_serialize( $data ) { if ( is_array( $data ) || is_object( $data ) ) return serialize( $data ); + // Double serialization is required for backward compatibility. + // See http://core.trac.wordpress.org/ticket/12930 if ( is_serialized( $data ) ) return serialize( $data ); @@ -1291,7 +1303,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) { return false; $headers = wp_remote_retrieve_headers( $response ); - $headers['response'] = $response['response']['code']; + $headers['response'] = wp_remote_retrieve_response_code( $response ); // WP_HTTP no longer follows redirects for HEAD requests. if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) { @@ -1306,7 +1318,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) { if ( !$out_fp ) return $headers; - fwrite( $out_fp, $response['body']); + fwrite( $out_fp, wp_remote_retrieve_body( $response ) ); fclose($out_fp); clearstatcache(); @@ -1370,6 +1382,36 @@ function build_query( $data ) { return _http_build_query( $data, null, '&', '', false ); } +// from php.net (modified by Mark Jaquith to behave like the native PHP5 function) +function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { + $ret = array(); + + foreach ( (array) $data as $k => $v ) { + if ( $urlencode) + $k = urlencode($k); + if ( is_int($k) && $prefix != null ) + $k = $prefix.$k; + if ( !empty($key) ) + $k = $key . '%5B' . $k . '%5D'; + if ( $v === NULL ) + continue; + elseif ( $v === FALSE ) + $v = '0'; + + if ( is_array($v) || is_object($v) ) + array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); + elseif ( $urlencode ) + array_push($ret, $k.'='.urlencode($v)); + else + array_push($ret, $k.'='.$v); + } + + if ( NULL === $sep ) + $sep = ini_get('arg_separator.output'); + + return implode($sep, $ret); +} + /** * Retrieve a modified URL query string. * @@ -1377,8 +1419,9 @@ function build_query( $data ) { * using this function. You can also retrieve the full URL with query data. * * Adding a single key & value or an associative array. Setting a key value to - * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER - * value. + * an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER + * value. Additional values provided are expected to be encoded appropriately + * with urlencode() or rawurlencode(). * * @since 1.5.0 * @@ -1512,7 +1555,7 @@ function wp_remote_fopen( $uri ) { if ( is_wp_error( $response ) ) return false; - return $response['body']; + return wp_remote_retrieve_body( $response ); } /** @@ -1754,7 +1797,7 @@ function do_feed_rdf() { } /** - * Load the RSS 1.0 Feed Template + * Load the RSS 1.0 Feed Template. * * @since 2.1.0 */ @@ -1791,27 +1834,28 @@ function do_feed_atom( $for_comments ) { } /** - * Display the robot.txt file content. + * Display the robots.txt file content. * * The echo content should be with usage of the permalinks or for creating the - * robot.txt file. + * robots.txt file. * * @since 2.1.0 - * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules. + * @uses do_action() Calls 'do_robotstxt' hook for displaying robots.txt rules. */ function do_robots() { header( 'Content-Type: text/plain; charset=utf-8' ); do_action( 'do_robotstxt' ); - $output = ''; + $output = "User-agent: *\n"; $public = get_option( 'blog_public' ); - if ( '0' == $public ) { - $output .= "User-agent: *\n"; + if ( '0' == $public ) { $output .= "Disallow: /\n"; } else { - $output .= "User-agent: *\n"; - $output .= "Disallow:\n"; + $site_url = parse_url( site_url() ); + $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; + $output .= "Disallow: $path/wp-admin/\n"; + $output .= "Disallow: $path/wp-includes/\n"; } echo apply_filters('robots_txt', $output, $public); @@ -1855,32 +1899,35 @@ function is_blog_installed() { if ( $installed ) return true; + // If visiting repair.php, return true and let it take over. + if ( defined( 'WP_REPAIRING' ) ) + return true; + $suppress = $wpdb->suppress_errors(); - $tables = $wpdb->get_col('SHOW TABLES'); - $wpdb->suppress_errors( $suppress ); - $wp_tables = $wpdb->tables(); // Loop over the WP tables. If none exist, then scratch install is allowed. // If one or more exist, suggest table repair since we got here because the options // table could not be accessed. + $wp_tables = $wpdb->tables(); foreach ( $wp_tables as $table ) { - // If one of the WP tables exist, then we are in an insane state. - if ( in_array( $table, $tables ) ) { - // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. - if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) - continue; - if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) - continue; + // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. + if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) + continue; + if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) + continue; - // If visiting repair.php, return true and let it take over. - if ( defined('WP_REPAIRING') ) - return true; - // Die with a DB error. - $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' ); - dead_db(); - } + if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) + continue; + + // One or more tables exist. We are insane. + + // Die with a DB error. + $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' ); + dead_db(); } + $wpdb->suppress_errors( $suppress ); + wp_cache_set( 'is_blog_installed', false ); return false; @@ -1910,11 +1957,6 @@ function wp_nonce_url( $actionurl, $action = -1 ) { * 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 @@ -1938,11 +1980,12 @@ function wp_nonce_url( $actionurl, $action = -1 ) { function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) { $name = esc_attr( $name ); $nonce_field = ''; - if ( $echo ) - echo $nonce_field; if ( $referer ) - wp_referer_field( $echo ); + $nonce_field .= wp_referer_field( false ); + + if ( $echo ) + echo $nonce_field; return $nonce_field; } @@ -1994,7 +2037,8 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { } /** - * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively. + * Retrieve referer from '_wp_http_referer' or HTTP referer. If it's the same + * as the current request URL, will return false. * * @package WordPress * @subpackage Security @@ -2003,13 +2047,13 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { * @return string|bool False on failure. Referer URL on success. */ function wp_get_referer() { - $ref = ''; + $ref = false; if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) $ref = $_REQUEST['_wp_http_referer']; else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) $ref = $_SERVER['HTTP_REFERER']; - if ( $ref !== $_SERVER['REQUEST_URI'] ) + if ( $ref && $ref !== $_SERVER['REQUEST_URI'] ) return $ref; return false; } @@ -2089,7 +2133,7 @@ function path_is_absolute( $path ) { return true; // a path starting with / or \ is absolute; anything else is relative - return (bool) preg_match('#^[/\\\\]#', $path); + return ( $path[0] == '/' || $path[0] == '\\' ); } /** @@ -2110,6 +2154,42 @@ function path_join( $base, $path ) { return rtrim($base, '/') . '/' . ltrim($path, '/'); } +/** + * Determines a writable directory for temporary files. + * Function's preference is to WP_CONTENT_DIR followed by the return value of sys_get_temp_dir(), before finally defaulting to /tmp/ + * + * In the event that this function does not find a writable location, It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file. + * + * @since 2.5.0 + * + * @return string Writable temporary directory + */ +function get_temp_dir() { + static $temp; + if ( defined('WP_TEMP_DIR') ) + return trailingslashit(WP_TEMP_DIR); + + if ( $temp ) + return trailingslashit($temp); + + $temp = WP_CONTENT_DIR . '/'; + if ( is_dir($temp) && @is_writable($temp) ) + return $temp; + + if ( function_exists('sys_get_temp_dir') ) { + $temp = sys_get_temp_dir(); + if ( @is_writable($temp) ) + return trailingslashit($temp); + } + + $temp = ini_get('upload_tmp_dir'); + if ( is_dir($temp) && @is_writable($temp) ) + return trailingslashit($temp); + + $temp = '/tmp/'; + return $temp; +} + /** * Get an array containing the current upload directory's path and url. * @@ -2360,7 +2440,7 @@ function wp_ext2type( $ext ) { 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsb', 'xlsm' ), 'interactive' => array( 'key', 'ppt', 'pptx', 'pptm', 'odp', 'swf' ), 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), - 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip' ), + 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), )); foreach ( $ext2type as $type => $exts ) @@ -2493,6 +2573,7 @@ function get_allowed_mime_types() { 'txt|asc|c|cc|h' => 'text/plain', 'csv' => 'text/csv', 'tsv' => 'text/tab-separated-values', + 'ics' => 'text/calendar', 'rtx' => 'text/richtext', 'css' => 'text/css', 'htm|html' => 'text/html', @@ -2525,6 +2606,8 @@ function get_allowed_mime_types() { 'tar' => 'application/x-tar', 'zip' => 'application/zip', 'gz|gzip' => 'application/x-gzip', + 'rar' => 'application/rar', + '7z' => 'application/x-7z-compressed', 'exe' => 'application/x-msdownload', // openoffice formats 'odt' => 'application/vnd.oasis.opendocument.text', @@ -2671,13 +2754,13 @@ function wp_nonce_ays( $action ) { * HTML will be displayed to the user. It is recommended to use this function * only, when the execution should not continue any further. It is not * recommended to call this function very often and try to handle as many errors - * as possible siliently. + * as possible silently. * * @since 2.0.4 * * @param string $message Error message. * @param string $title Error title. - * @param string|array $args Optional arguements to control behaviour. + * @param string|array $args Optional arguments to control behavior. */ function wp_die( $message, $title = '', $args = array() ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) @@ -2703,7 +2786,7 @@ function wp_die( $message, $title = '', $args = array() ) { * * @param string $message Error message. * @param string $title Error title. - * @param string|array $args Optional arguements to control behaviour. + * @param string|array $args Optional arguments to control behavior. */ function _default_wp_die_handler( $message, $title = '', $args = array() ) { $defaults = array( 'response' => 500 ); @@ -2735,48 +2818,105 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) { if ( isset( $r['back_link'] ) && $r['back_link'] ) { $back_text = $have_gettext? __('« Back') : '« Back'; - $message .= "\n

$back_text

"; + $message .= "\n

$back_text

"; } - 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' ); - } + 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'; + 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'; + $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'; ?> - - + + > <?php echo $title ?> - - - - + - + @@ -2784,10 +2924,46 @@ if ( 'rtl' == $text_direction ) : ?> die(); } +/** + * Kill WordPress execution and display XML message with error message. + * + * This is the handler for wp_die when processing XMLRPC requests. + * + * @since 3.2.0 + * @access private + * + * @param string $message Error message. + * @param string $title Error title. + * @param string|array $args Optional arguments to control behavior. + */ +function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) { + global $wp_xmlrpc_server; + $defaults = array( 'response' => 500 ); + + $r = wp_parse_args($args, $defaults); + + if ( $wp_xmlrpc_server ) { + $error = new IXR_Error( $r['response'] , $message); + $wp_xmlrpc_server->output( $error->getXml() ); + } + die(); +} + +/** + * Filter to enable special wp_die handler for xmlrpc requests. + * + * @since 3.2.0 + * @access private + */ +function _xmlrpc_wp_die_filter() { + return '_xmlrpc_wp_die_handler'; +} + + /** * Retrieve the WordPress home page URL. * - * If the constant named 'WP_HOME' exists, then it willl be used and returned by + * 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. * @@ -2800,7 +2976,7 @@ if ( 'rtl' == $text_direction ) : ?> */ function _config_wp_home( $url = '' ) { if ( defined( 'WP_HOME' ) ) - return WP_HOME; + return untrailingslashit( WP_HOME ); return $url; } @@ -2820,7 +2996,7 @@ function _config_wp_home( $url = '' ) { */ function _config_wp_siteurl( $url = '' ) { if ( defined( 'WP_SITEURL' ) ) - return WP_SITEURL; + return untrailingslashit( WP_SITEURL ); return $url; } @@ -2989,7 +3165,7 @@ function wp_parse_args( $args, $defaults = '' ) { } /** - * Clean up an array, comma- or space-separated list of IDs + * Clean up an array, comma- or space-separated list of IDs. * * @since 3.0.0 * @@ -3004,7 +3180,7 @@ function wp_parse_id_list( $list ) { } /** - * Extract a slice of an array, given a list of keys + * Extract a slice of an array, given a list of keys. * * @since 3.1.0 * @@ -3022,7 +3198,7 @@ function wp_array_slice_assoc( $array, $keys ) { } /** - * Filters a list of objects, based on a set of key => value arguments + * Filters a list of objects, based on a set of key => value arguments. * * @since 3.0.0 * @@ -3046,7 +3222,7 @@ function wp_filter_object_list( $list, $args = array(), $operator = 'and', $fiel } /** - * Filters a list of objects, based on a set of key => value arguments + * Filters a list of objects, based on a set of key => value arguments. * * @since 3.1.0 * @@ -3071,9 +3247,16 @@ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { $filtered = array(); foreach ( $list as $key => $obj ) { - $matched = count( array_intersect_assoc( (array) $obj, $args ) ); + $to_match = (array) $obj; + + $matched = 0; + foreach ( $args as $m_key => $m_value ) { + if ( $m_value == $to_match[ $m_key ] ) + $matched++; + } + if ( ( 'AND' == $operator && $matched == $count ) - || ( 'OR' == $operator && $matched <= $count ) + || ( 'OR' == $operator && $matched > 0 ) || ( 'NOT' == $operator && 0 == $matched ) ) { $filtered[$key] = $obj; } @@ -3083,7 +3266,7 @@ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { } /** - * Pluck a certain field out of each object in a list + * Pluck a certain field out of each object in a list. * * @since 3.1.0 * @@ -3093,27 +3276,15 @@ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { */ function wp_list_pluck( $list, $field ) { foreach ( $list as $key => $value ) { - $value = (array) $value; - $list[ $key ] = $value[ $field ]; + if ( is_object( $value ) ) + $list[ $key ] = $value->$field; + else + $list[ $key ] = $value[ $field ]; } return $list; } -/** - * Determines if default embed handlers should be loaded. - * - * Checks to make sure that the embeds library hasn't already been loaded. If - * it hasn't, then it will load the embeds library. - * - * @since 2.9.0 - */ -function wp_maybe_load_embeds() { - if ( ! apply_filters('load_default_embeds', true) ) - return; - require_once( ABSPATH . WPINC . '/default-embeds.php' ); -} - /** * Determines if Widgets library should be loaded. * @@ -3190,15 +3361,15 @@ function dead_db() { nocache_headers(); header( 'Content-Type: text/html; charset=utf-8' ); ?> - + > - Database Error + <?php echo /*WP_I18N_DB_ERROR*/'Database Error'/*/WP_I18N_DB_ERROR*/; ?> -

Error establishing a database connection

+

Debugging in WordPress for more information.' ); trigger_error( sprintf( __( '%1$s was called incorrectly. %2$s %3$s' ), $function, $message, $version ) ); } } /** - * Is the server running earlier than 1.5.0 version of lighttpd + * Is the server running earlier than 1.5.0 version of lighttpd? * * @since 2.5.0 * @@ -3437,7 +3593,7 @@ function is_lighttpd_before_150() { } /** - * Does the specified module exist in the apache config? + * Does the specified module exist in the Apache config? * * @since 2.5.0 * @@ -3466,7 +3622,7 @@ function apache_mod_loaded($mod, $default = false) { } /** - * Check if IIS 7 supports pretty permalinks + * Check if IIS 7 supports pretty permalinks. * * @since 2.8.0 * @@ -3480,7 +3636,7 @@ function iis7_supports_permalinks() { /* First we check if the DOMDocument class exists. If it does not exist, * which is the case for PHP 4.X, then we cannot easily update the xml configuration file, * hence we just bail out and tell user that pretty permalinks cannot be used. - * This is not a big issue because PHP 4.X is going to be depricated and for IIS it + * This is not a big issue because PHP 4.X is going to be deprecated and for IIS it * is recommended to use PHP 5.X NTS. * 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'. @@ -3508,16 +3664,16 @@ function iis7_supports_permalinks() { * @return int 0 means nothing is wrong, greater than 0 means something was wrong. */ function validate_file( $file, $allowed_files = '' ) { - if ( false !== strpos( $file, '..' )) + if ( false !== strpos( $file, '..' ) ) return 1; - if ( false !== strpos( $file, './' )) + if ( false !== strpos( $file, './' ) ) return 1; - if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) + if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) return 3; - if (':' == substr( $file, 1, 1 )) + if (':' == substr( $file, 1, 1 ) ) return 2; return 0; @@ -3563,7 +3719,7 @@ function force_ssl_login( $force = null ) { } /** - * Whether to force SSL used for the Administration Panels. + * Whether to force SSL used for the Administration Screens. * * @since 2.6.0 * @@ -3602,6 +3758,30 @@ function wp_guess_url() { return rtrim($url, '/'); } +/** + * Temporarily suspend cache additions. + * + * Stops more data being added to the cache, but still allows cache retrieval. + * This is useful for actions, such as imports, when a lot of data would otherwise + * be almost uselessly added to the cache. + * + * Suspension lasts for a single page load at most. Remember to call this + * function again if you wish to re-enable cache adds earlier. + * + * @since 3.3.0 + * + * @param bool $suspend Optional. Suspends additions if true, re-enables them if false. + * @return bool The current suspend setting + */ +function wp_suspend_cache_addition( $suspend = null ) { + static $_suspend = false; + + if ( is_bool( $suspend ) ) + $_suspend = $suspend; + + return $_suspend; +} + /** * Suspend cache invalidation. * @@ -3660,14 +3840,13 @@ function get_site_option( $option, $default = false, $use_cache = true ) { $row = $wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); // Has to be get_row instead of get_var because of funkiness with 0, false, null values - if ( is_object( $row ) ) + if ( is_object( $row ) ) { $value = $row->meta_value; - else + $value = maybe_unserialize( $value ); + wp_cache_set( $cache_key, $value, 'site-options' ); + } else { $value = $default; - - $value = maybe_unserialize( $value ); - - wp_cache_set( $cache_key, $value, 'site-options' ); + } } } @@ -3677,6 +3856,8 @@ function get_site_option( $option, $default = false, $use_cache = true ) { /** * Add a new site option. * + * Existing options will not be updated. Note that prior to 3.3 this wasn't the case. + * * @see add_option() * @package WordPress * @subpackage Option @@ -3700,22 +3881,24 @@ function add_site_option( $option, $value ) { } else { $cache_key = "{$wpdb->siteid}:$option"; - if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) - return update_site_option( $option, $value ); + if ( false !== get_site_option( $option ) ) + return false; $value = sanitize_option( $option, $value ); wp_cache_set( $cache_key, $value, 'site-options' ); $_value = $value; - $value = maybe_serialize($value); + $value = maybe_serialize( $value ); $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) ); $value = $_value; } - do_action( "add_site_option_{$option}", $option, $value ); - do_action( "add_site_option", $option, $value ); - - return $result; + if ( $result ) { + do_action( "add_site_option_{$option}", $option, $value ); + do_action( "add_site_option", $option, $value ); + return true; + } + return false; } /** @@ -3785,14 +3968,14 @@ function update_site_option( $option, $value ) { if ( $value === $oldvalue ) return false; + if ( false === $oldvalue ) + return add_site_option( $option, $value ); + if ( !is_multisite() ) { $result = update_option( $option, $value ); } else { - $cache_key = "{$wpdb->siteid}:$option"; - - if ( $value && !$wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) - return add_site_option( $option, $value ); $value = sanitize_option( $option, $value ); + $cache_key = "{$wpdb->siteid}:$option"; wp_cache_set( $cache_key, $value, 'site-options' ); $_value = $value; @@ -3802,15 +3985,15 @@ function update_site_option( $option, $value ) { } if ( $result ) { - do_action( "update_site_option_{$option}", $option, $value ); - do_action( "update_site_option", $option, $value ); + do_action( "update_site_option_{$option}", $option, $value, $oldvalue ); + do_action( "update_site_option", $option, $value, $oldvalue ); return true; } return false; } /** - * Delete a site transient + * Delete a site transient. * * @since 2.9.0 * @package WordPress @@ -3841,7 +4024,7 @@ function delete_site_transient( $transient ) { } /** - * Get the value of a site transient + * Get the value of a site transient. * * If the transient does not exist or does not have a value, then the return value * will be false. @@ -3890,7 +4073,7 @@ function get_site_transient( $transient ) { } /** - * Set/update the value of a site transient + * Set/update the value of a site transient. * * You do not need to serialize values, if the value needs to be serialize, then * it will be serialized before it is set. @@ -3937,7 +4120,7 @@ function set_site_transient( $transient, $value, $expiration = 0 ) { } /** - * is main site + * Is main site? * * * @since 3.0.0 @@ -3983,18 +4166,15 @@ function global_terms_enabled() { } /** - * gmt_offset modification for smart timezone handling + * gmt_offset modification for smart timezone handling. * - * Overrides the gmt_offset option if we have a timezone_string available + * Overrides the gmt_offset option if we have a timezone_string available. * * @since 2.8.0 * * @return float|bool */ function wp_timezone_override_offset() { - if ( !wp_timezone_supported() ) { - return false; - } if ( !$timezone_string = get_option( 'timezone_string' ) ) { return false; } @@ -4007,27 +4187,6 @@ function wp_timezone_override_offset() { return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); } -/** - * Check for PHP timezone support - * - * @since 2.9.0 - * - * @return bool - */ -function wp_timezone_supported() { - $support = false; - if ( - function_exists( 'date_create' ) && - function_exists( 'date_default_timezone_set' ) && - function_exists( 'timezone_identifiers_list' ) && - function_exists( 'timezone_open' ) && - function_exists( 'timezone_offset_get' ) - ) { - $support = true; - } - return apply_filters( 'timezone_support', $support ); -} - /** * {@internal Missing Short Description}} * @@ -4076,7 +4235,7 @@ function _wp_timezone_choice_usort_callback( $a, $b ) { } /** - * Gives a nicely formatted list of timezone strings // temporary! Not in final + * Gives a nicely formatted list of timezone strings. // temporary! Not in final * * @since 2.9.0 * @@ -4205,7 +4364,7 @@ function wp_timezone_choice( $selected_zone ) { } /** - * Strip close comment and close php tags from file headers used by WP + * Strip close comment and close php tags from file headers used by WP. * See http://core.trac.wordpress.org/ticket/8497 * * @since 2.8.0 @@ -4266,7 +4425,7 @@ function wp_scheduled_delete() { * Retrieve metadata from a file. * * Searches for metadata in the first 8kiB of a file, such as a plugin or theme. - * Each piece of metadata must be on its own line. Fields can not span multple + * Each piece of metadata must be on its own line. Fields can not span multiple * lines, the value will get cut at the end of the first line. * * If the file data is not within that first 8kiB, then the author should correct @@ -4302,7 +4461,7 @@ function get_file_data( $file, $default_headers, $context = '' ) { } foreach ( $all_headers as $field => $regex ) { - preg_match( '/^[ \t\/*#]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field}); + preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field}); if ( !empty( ${$field} ) ) ${$field} = _cleanup_header_comment( ${$field}[1] ); else @@ -4315,7 +4474,7 @@ function get_file_data( $file, $default_headers, $context = '' ) { } /** - * Used internally to tidy up the search terms + * Used internally to tidy up the search terms. * * @access private * @since 2.9.0 @@ -4328,9 +4487,9 @@ function _search_terms_tidy($t) { } /** - * Returns true + * Returns true. * - * Useful for returning true to filters easily + * Useful for returning true to filters easily. * * @since 3.0.0 * @see __return_false() @@ -4341,9 +4500,9 @@ function __return_true() { } /** - * Returns false + * Returns false. * - * Useful for returning false to filters easily + * Useful for returning false to filters easily. * * @since 3.0.0 * @see __return_true() @@ -4354,9 +4513,9 @@ function __return_false() { } /** - * Returns 0 + * Returns 0. * - * Useful for returning 0 to filters easily + * Useful for returning 0 to filters easily. * * @since 3.0.0 * @see __return_zero() @@ -4367,9 +4526,9 @@ function __return_zero() { } /** - * Returns an empty array + * Returns an empty array. * - * Useful for returning an empty array to filters easily + * Useful for returning an empty array to filters easily. * * @since 3.0.0 * @see __return_zero() @@ -4446,7 +4605,7 @@ function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_arg * @since 3.1.0 * @access private * - * @param callback $callback function that accupts ( ID, callback_arg, ... ) and outputs parent_ID + * @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 @@ -4482,4 +4641,36 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar return false; } +/** + * Send a HTTP header to limit rendering of pages to same origin iframes. + * + * @link https://developer.mozilla.org/en/the_x-frame-options_response_header + * + * @since 3.1.3 + * @return none + */ +function send_frame_options_header() { + @header( 'X-Frame-Options: SAMEORIGIN' ); +} + +/** + * Retrieve a list of protocols to allow in HTML attributes. + * + * @since 3.3.0 + * @see wp_kses() + * @see esc_url() + * + * @return array Array of allowed protocols + */ +function wp_allowed_protocols() { + static $protocols; + + if ( empty( $protocols ) ) { + $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' ); + $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); + } + + return $protocols; +} + ?>