if ( empty( $m ) )
return false;
- if ( 'G' == $dateformatstring ) {
+ if ( 'G' == $dateformatstring )
return strtotime( $m . ' +0000' );
- }
$i = strtotime( $m );
if ( 'U' == $dateformatstring )
return $i;
- if ( $translate)
- return date_i18n( $dateformatstring, $i );
+ if ( $translate )
+ return date_i18n( $dateformatstring, $i );
else
- return date( $dateformatstring, $i );
+ return date( $dateformatstring, $i );
}
/**
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
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
}
+ $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
+ $timezone_formats_re = implode( '|', $timezone_formats );
+ if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
+ $timezone_string = get_option( 'timezone_string' );
+ if ( $timezone_string ) {
+ $timezone_object = timezone_open( $timezone_string );
+ $date_object = date_create( null, $timezone_object );
+ foreach( $timezone_formats as $timezone_format ) {
+ if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
+ $formatted = date_format( $date_object, $timezone_format );
+ $dateformatstring = ' '.$dateformatstring;
+ $dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
+ $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
+ }
+ }
+ }
+ }
$j = @$datefunc( $dateformatstring, $i );
// allow plugins to redo this entirely for languages with untypical grammars
$j = apply_filters('date_i18n', $j, $req_format, $i, $gmt);
*/
function is_serialized( $data ) {
// if it isn't a string, it isn't serialized
- if ( !is_string( $data ) )
+ if ( ! is_string( $data ) )
return false;
$data = trim( $data );
- if ( 'N;' == $data )
+ if ( 'N;' == $data )
return true;
- if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
+ $length = strlen( $data );
+ if ( $length < 4 )
return false;
- switch ( $badions[1] ) {
+ if ( ':' !== $data[1] )
+ return false;
+ $lastc = $data[$length-1];
+ if ( ';' !== $lastc && '}' !== $lastc )
+ return false;
+ $token = $data[0];
+ switch ( $token ) {
+ case 's' :
+ if ( '"' !== $data[$length-2] )
+ return false;
case 'a' :
case 'O' :
- case 's' :
- if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
- return true;
- break;
+ return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b' :
case 'i' :
case 'd' :
- if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
- return true;
- break;
+ return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data );
}
return false;
}
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;
}
/**
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
$wpdb->suppress_errors($suppress);
$alloptions = array();
- foreach ( (array) $alloptions_db as $o )
+ foreach ( (array) $alloptions_db as $o ) {
$alloptions[$o->option_name] = $o->option_value;
- if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
- wp_cache_add( 'alloptions', $alloptions, 'options' );
+ }
+ if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
+ wp_cache_add( 'alloptions', $alloptions, 'options' );
}
return $alloptions;
if ( empty($site_id) )
$site_id = $wpdb->siteid;
- $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'dashboard_blog', 'can_compress_scripts', 'global_terms_enabled' );
+ $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled' );
$core_options_in = "'" . implode("', '", $core_options) . "'";
$options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) );
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 );
* @package WordPress
* @subpackage Option
* @since 1.0.0
- * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
*
* @uses do_action() Calls 'add_option' hook before adding the option.
* @uses do_action() Calls 'add_option_$option' and 'added_option' hooks on success.
wp_protect_special_option( $option );
if ( is_object($value) )
- $value = wp_clone($value);
+ $value = clone $value;
$value = sanitize_option( $option, $value );
function delete_transient( $transient ) {
global $_wp_using_ext_object_cache;
- do_action( 'delete_transient_' . $transient, $transient );
+ do_action( 'delete_transient_' . $transient, $transient );
if ( $_wp_using_ext_object_cache ) {
$result = wp_cache_delete( $transient, 'transient' );
function set_transient( $transient, $value, $expiration = 0 ) {
global $_wp_using_ext_object_cache;
- $value = apply_filters( 'pre_set_transient_' . $transient, $value );
+ $value = apply_filters( 'pre_set_transient_' . $transient, $value );
if ( $_wp_using_ext_object_cache ) {
$result = wp_cache_set( $transient, $value, 'transient', $expiration );
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
+
+ //TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . '/class-IXR.php' );
$log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
foreach ( $pung as $link_test ) {
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
- $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
+ $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
do_action( 'delete_postmeta', $mid );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
do_action( 'deleted_postmeta', $mid );
continue;
if ( isset( $test['query'] ) )
$post_links[] = $link_test;
- elseif ( $test['path'] != '/' && $test['path'] != '' )
+ elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) )
$post_links[] = $link_test;
}
}
foreach ( (array) $post_links as $url ) {
- if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
+ if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = (int) $headers['content-length'];
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'] ) ) {
if ( !$out_fp )
return $headers;
- fwrite( $out_fp, $response['body']);
+ fwrite( $out_fp, wp_remote_retrieve_body( $response ) );
fclose($out_fp);
clearstatcache();
* @return int 1 when new day, 0 if not a new day.
*/
function is_new_day() {
- global $day, $previousday;
- if ( $day != $previousday )
+ global $currentday, $previousday;
+ if ( $currentday != $previousday )
return 1;
else
return 0;
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.
*
if ( is_wp_error( $response ) )
return false;
- return $response['body'];
+ return wp_remote_retrieve_body( $response );
}
/**
* The several different headers cover the different ways cache prevention is handled
* by different browsers
*
- * @since 2.8
+ * @since 2.8.0
*
* @uses apply_filters()
* @return array The associative array of header names and field values.
);
if ( function_exists('apply_filters') ) {
- $headers = apply_filters('nocache_headers', $headers);
+ $headers = (array) apply_filters('nocache_headers', $headers);
}
return $headers;
}
*/
function nocache_headers() {
$headers = wp_get_nocache_headers();
- foreach( (array) $headers as $name => $field_value )
+ foreach( $headers as $name => $field_value )
@header("{$name}: {$field_value}");
}
* 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
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
$name = esc_attr( $name );
$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
- if ( $echo )
- echo $nonce_field;
if ( $referer )
- wp_referer_field( $echo );
+ $nonce_field .= wp_referer_field( false );
+
+ if ( $echo )
+ echo $nonce_field;
return $nonce_field;
}
if ( realpath($path) == $path )
return true;
- if ( strlen($path) == 0 || $path{0} == '.' )
+ if ( strlen($path) == 0 || $path[0] == '.' )
return false;
// windows allows absolute paths like this
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 <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/
+ *
+ * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> 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.
*
$siteurl = get_option( 'siteurl' );
$upload_path = get_option( 'upload_path' );
$upload_path = trim($upload_path);
- $main_override = defined( 'MULTISITE' ) && is_main_site();
+ $main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site();
if ( empty($upload_path) ) {
$dir = WP_CONTENT_DIR . '/uploads';
} else {
* before the extension, and will continue adding numbers until the filename is
* unique.
*
- * The callback must accept two parameters, the first one is the directory and
- * the second is the filename. The callback must be a function.
+ * The callback is passed three parameters, the first one is the directory, the
+ * second is the filename, and the third is the extension.
*
- * @since 2.5
+ * @since 2.5.0
*
* @param string $dir
* @param string $filename
- * @param string $unique_filename_callback Function name, must be a function.
+ * @param mixed $unique_filename_callback Callback.
* @return string New filename, if given wasn't unique.
*/
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
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.
+ // Increment the file number until we have a unique file to save in $dir. Use callback if supplied.
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
- $filename = $unique_filename_callback( $dir, $name );
+ $filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
'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',
$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['upgrade']['plugin'] = array( __( 'Your attempt to update 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' );
* @param string|array $args Optional arguements to control behaviour.
*/
function wp_die( $message, $title = '', $args = array() ) {
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
+ die('-1');
+
if ( function_exists( 'apply_filters' ) ) {
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler');
- }else {
+ } else {
$function = '_default_wp_die_handler';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->
-<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
+<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
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 arguements to control behaviour.
+ */
+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.
*
return array_unique(array_map('absint', $list));
}
+/**
+ * Extract a slice of an array, given a list of keys
+ *
+ * @since 3.1.0
+ *
+ * @param array $array The original array
+ * @param array $keys The list of keys
+ * @return array The array slice
+ */
+function wp_array_slice_assoc( $array, $keys ) {
+ $slice = array();
+ foreach ( $keys as $key )
+ if ( isset( $array[ $key ] ) )
+ $slice[ $key ] = $array[ $key ];
+
+ return $slice;
+}
+
/**
* Filters a list of objects, based on a set of key => value arguments
*
* @return array A list of objects or object fields
*/
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
- if ( !is_array($list) )
+ if ( ! is_array( $list ) )
return array();
- if ( empty($args) )
- $args = array();
+ $list = wp_list_filter( $list, $args, $operator );
+
+ if ( $field )
+ $list = wp_list_pluck( $list, $field );
+
+ return $list;
+}
- if ( empty($args) && !$field )
- return $list; // nothing to do
+/**
+ * Filters a list of objects, based on a set of key => value arguments
+ *
+ * @since 3.1.0
+ *
+ * @param array $list An array of objects to filter
+ * @param array $args 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_list_filter( $list, $args = array(), $operator = 'AND' ) {
+ if ( ! is_array( $list ) )
+ return array();
- $count = count($args);
+ if ( empty( $args ) )
+ return $list;
+ $operator = strtoupper( $operator );
+ $count = count( $args );
$filtered = array();
foreach ( $list as $key => $obj ) {
- $matched = count(array_intersect_assoc(get_object_vars($obj), $args));
- if ( ('and' == $operator && $matched == $count) || ('or' == $operator && $matched <= $count) ) {
- if ( $field )
- $filtered[] = $obj->$field;
- else
- $filtered[$key] = $obj;
+ $matched = count( array_intersect_assoc( (array) $obj, $args ) );
+ if ( ( 'AND' == $operator && $matched == $count )
+ || ( 'OR' == $operator && $matched <= $count )
+ || ( 'NOT' == $operator && 0 == $matched ) ) {
+ $filtered[$key] = $obj;
}
}
}
/**
- * Determines if default embed handlers should be loaded.
+ * Pluck a certain field out of each object in a list
*
- * 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 3.1.0
*
- * @since 2.9.0
+ * @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_maybe_load_embeds() {
- if ( ! apply_filters('load_default_embeds', true) )
- return;
- require_once( ABSPATH . WPINC . '/default-embeds.php' );
+function wp_list_pluck( $list, $field ) {
+ foreach ( $list as $key => $value ) {
+ $value = (array) $value;
+ $list[ $key ] = $value[ $field ];
+ }
+
+ return $list;
}
/**
ob_end_flush();
}
-/**
- * Load the correct database class file.
- *
- * 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.5.0
- * @global $wpdb WordPress Database Object
- */
-function require_wp_db() {
- global $wpdb;
- if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
- require_once( WP_CONTENT_DIR . '/db.php' );
- else
- require_once( ABSPATH . WPINC . '/wp-db.php' );
-}
-
/**
* Load custom DB error or display WordPress DB error.
*
return false;
}
-/**
- * Secure URL, if available or the given URL.
- *
- * @since 2.5.0
- *
- * @param string $url Complete URL path with transport.
- * @return string Secure or regular URL path.
- */
-function atom_service_url_filter($url)
-{
- if ( url_is_accessable_via_ssl($url) )
- return preg_replace( '/^http:\/\//', 'https://', $url );
- else
- return $url;
-}
-
/**
* Marks a function as deprecated and informs when it has been used.
*
* to get the backtrace up to what file and function called the deprecated
* function.
*
- * The current behavior is to trigger an user error if WP_DEBUG is true.
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
*
- * This function is to be used in every function in depreceated.php
+ * This function is to be used in every function that is deprecated.
*
* @package WordPress
* @subpackage Debug
* to get the backtrace up to what file and function included the deprecated
* file.
*
- * The current behavior is to trigger an user error if WP_DEBUG is true.
+ * 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 depreceated
+ * This function is to be used in every file that is deprecated.
*
* @package WordPress
* @subpackage Debug
* to get the backtrace up to what file and function used the deprecated
* argument.
*
- * The current behavior is to trigger an user error if WP_DEBUG is true.
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @package WordPress
* @subpackage Debug
}
}
+/**
+ * Marks something as being incorrectly called.
+ *
+ * There is a hook doing_it_wrong_run that will be called that can be used
+ * to get the backtrace up to what file and function called the deprecated
+ * function.
+ *
+ * The current behavior is to trigger a user error if WP_DEBUG is true.
+ *
+ * @package WordPress
+ * @subpackage Debug
+ * @since 3.1.0
+ * @access private
+ *
+ * @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 $function The function that was called.
+ * @param string $message A message explaining what has been done incorrectly.
+ * @param string $version The version of WordPress where the message was added.
+ */
+function _doing_it_wrong( $function, $message, $version ) {
+
+ do_action( 'doing_it_wrong_run', $function, $message, $version );
+
+ // Allow plugin to filter the output error trigger
+ if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
+ $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
+ trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
+ }
+}
+
/**
* Is the server running earlier than 1.5.0 version of lighttpd
*
return $default;
}
+/**
+ * Check if IIS 7 supports pretty permalinks
+ *
+ * @since 2.8.0
+ *
+ * @return bool
+ */
+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,
+ * 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
+ * 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'.
+ * 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);
+}
+
/**
* File validates against allowed set of defined rules.
*
}
/**
- * Whether to force SSL used for the Administration Panels.
+ * Whether to force SSL used for the Administration Screens.
*
* @since 2.6.0
*
$schema = is_ssl() ? 'https://' : 'http://';
$url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
- return $url;
+ return rtrim($url, '/');
}
/**
function set_site_transient( $transient, $value, $expiration = 0 ) {
global $_wp_using_ext_object_cache;
- $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
+ $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
if ( $_wp_using_ext_object_cache ) {
$result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
* @return float|bool
*/
function wp_timezone_override_offset() {
- if ( !wp_timezone_supported() ) {
- return false;
- }
if ( !$timezone_string = get_option( 'timezone_string' ) ) {
return false;
}
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}}
*
}
/**
- * Parse the file contents to retrieve its metadata.
- *
- * Searches for metadata for a file, such as a plugin or theme. Each piece of
- * metadata must be on its own line. For a field spanning multple lines, it
- * must not have any newlines or only parts of it will be displayed.
+ * Retrieve metadata from a file.
*
- * Some users have issues with opening large files and manipulating the contents
- * for want is usually the first 1kiB or 2kiB. This function stops pulling in
- * the file contents when it has all of the required data.
+ * 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
+ * lines, the value will get cut at the end of the first line.
*
- * The first 8kiB of the file will be pulled in and 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.
+ * 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.
*
- * The file is assumed to have permissions to allow for scripts to read
- * the file. This is not checked however and the file is only opened for
- * reading.
+ * @see http://codex.wordpress.org/File_Header
*
* @since 2.9.0
- *
* @param string $file Path to the file
- * @param bool $markup If the returned data should have HTML markup applied
- * @param string $context If specified adds filter hook "extra_<$context>_headers"
+ * @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 get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
fclose( $fp );
if ( $context != '' ) {
- $extra_headers = apply_filters( "extra_$context".'_headers', array() );
+ $extra_headers = apply_filters( "extra_{$context}_headers", array() );
$extra_headers = array_flip( $extra_headers );
foreach( $extra_headers as $key=>$value ) {
$extra_headers[$key] = $key;
}
- $all_headers = array_merge($extra_headers, $default_headers);
+ $all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
-
foreach ( $all_headers as $field => $regex ) {
- preg_match( '/' . 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
return $file_data;
}
-/*
+
+/**
* Used internally to tidy up the search terms
*
* @access private
}
}
+/**
+ * Finds hierarchy loops using a callback function that maps object IDs to parent IDs.
+ *
+ * @since 3.1.0
+ * @access private
+ *
+ * @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.
+ *
+ * For every step of the algorithm, the hare takes two steps and the tortoise one.
+ * If the hare ever laps the tortoise, there must be a loop.
+ *
+ * @since 3.1.0
+ * @access private
+ *
+ * @param callback $callback function that accupts ( 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 wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
+ $tortoise = $hare = $evanescent_hare = $start;
+ $return = array();
+
+ // Set evanescent_hare to one past hare
+ // Increment hare two steps
+ while (
+ $tortoise
+ &&
+ ( $evanescent_hare = isset( $override[$hare] ) ? $override[$hare] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
+ &&
+ ( $hare = isset( $override[$evanescent_hare] ) ? $override[$evanescent_hare] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
+ ) {
+ if ( $_return_loop )
+ $return[$tortoise] = $return[$evanescent_hare] = $return[$hare] = true;
+
+ // tortoise got lapped - must be a loop
+ if ( $tortoise == $evanescent_hare || $tortoise == $hare )
+ return $_return_loop ? $return : $tortoise;
+
+ // Increment tortoise by one step
+ $tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
+ }
+
+ return false;
+}
+
+/**
+ * Send a HTTP header to limit rendering of pages to same origin iframes.
+ *
+ * @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' );
+}
+
?>