Code cleanup and standardization for functions.php
git-svn-id: http://svn.automattic.com/wordpress/trunk@6223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c23352bedf
commit
a30ed0ded5
|
@ -3,9 +3,8 @@
|
|||
function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
|
||||
global $wp_locale;
|
||||
$m = $mysqlstring;
|
||||
if ( empty($m) ) {
|
||||
if ( empty( $m ) )
|
||||
return false;
|
||||
}
|
||||
$i = mktime(
|
||||
(int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
|
||||
(int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
|
||||
|
@ -35,28 +34,28 @@ function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
|
|||
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
|
||||
}
|
||||
$j = @date( $dateformatstring, $i );
|
||||
if ( !$j ) {
|
||||
// for debug purposes
|
||||
// echo $i." ".$mysqlstring;
|
||||
}
|
||||
|
||||
/*
|
||||
if ( !$j ) // for debug purposes
|
||||
echo $i." ".$mysqlstring;
|
||||
*/
|
||||
|
||||
return $j;
|
||||
}
|
||||
|
||||
|
||||
function current_time( $type, $gmt = 0 ) {
|
||||
switch ( $type ) {
|
||||
case 'mysql':
|
||||
if ( $gmt ) $d = gmdate('Y-m-d H:i:s');
|
||||
else $d = gmdate('Y-m-d H:i:s', (time() + (get_option('gmt_offset') * 3600)));
|
||||
return $d;
|
||||
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
|
||||
break;
|
||||
case 'timestamp':
|
||||
if ( $gmt ) $d = time();
|
||||
else $d = time() + (get_option('gmt_offset') * 3600);
|
||||
return $d;
|
||||
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function date_i18n( $dateformatstring, $unixtimestamp ) {
|
||||
global $wp_locale;
|
||||
$i = $unixtimestamp;
|
||||
|
@ -81,23 +80,26 @@ function date_i18n($dateformatstring, $unixtimestamp) {
|
|||
return $j;
|
||||
}
|
||||
|
||||
|
||||
function number_format_i18n( $number, $decimals = null ) {
|
||||
global $wp_locale;
|
||||
// let the user override the precision only
|
||||
$decimals = is_null($decimals)? $wp_locale->number_format['decimals'] : intval($decimals);
|
||||
$decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
|
||||
|
||||
return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
|
||||
}
|
||||
|
||||
|
||||
function size_format( $bytes, $decimals = null ) {
|
||||
// technically the correct unit names for powers of 1024 are KiB, MiB etc
|
||||
// see http://en.wikipedia.org/wiki/Byte
|
||||
$quant = array(
|
||||
'TB' => pow(1024, 4),
|
||||
'GB' => pow(1024, 3),
|
||||
'MB' => pow(1024, 2),
|
||||
'kB' => pow(1024, 1),
|
||||
'B' => pow(1024, 0),
|
||||
// ========================= Origin ====
|
||||
'TB' => 1099511627776, // pow( 1024, 4)
|
||||
'GB' => 1073741824, // pow( 1024, 3)
|
||||
'MB' => 1048576, // pow( 1024, 2)
|
||||
'kB' => 1024, // pow( 1024, 1)
|
||||
'B ' => 1, // pow( 1024, 0)
|
||||
);
|
||||
|
||||
foreach ( $quant as $unit => $mag )
|
||||
|
@ -105,6 +107,7 @@ function size_format($bytes, $decimals = null) {
|
|||
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
|
||||
}
|
||||
|
||||
|
||||
function get_weekstartend( $mysqlstring, $start_of_week ) {
|
||||
$my = substr( $mysqlstring, 0, 4 );
|
||||
$mm = substr( $mysqlstring, 8, 2 );
|
||||
|
@ -125,11 +128,11 @@ function get_weekstartend($mysqlstring, $start_of_week) {
|
|||
$i = 0;
|
||||
}
|
||||
$week['start'] = $day + 86400 - $i;
|
||||
// $week['end'] = $day - $i + 691199;
|
||||
$week['end'] = $week['start'] + 604799;
|
||||
return $week;
|
||||
}
|
||||
|
||||
|
||||
function maybe_unserialize( $original ) {
|
||||
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
|
||||
if ( false !== $gm = @unserialize( $original ) )
|
||||
|
@ -137,6 +140,7 @@ function maybe_unserialize($original) {
|
|||
return $original;
|
||||
}
|
||||
|
||||
|
||||
function is_serialized( $data ) {
|
||||
// if it isn't a string, it isn't serialized
|
||||
if ( !is_string( $data ) )
|
||||
|
@ -146,7 +150,7 @@ function is_serialized($data) {
|
|||
return true;
|
||||
if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
|
||||
return false;
|
||||
switch ( $badions[1] ) :
|
||||
switch ( $badions[1] ) {
|
||||
case 'a' :
|
||||
case 'O' :
|
||||
case 's' :
|
||||
|
@ -159,10 +163,11 @@ function is_serialized($data) {
|
|||
if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
|
||||
return true;
|
||||
break;
|
||||
endswitch;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function is_serialized_string( $data ) {
|
||||
// if it isn't a string, it isn't a serialized string
|
||||
if ( !is_string( $data ) )
|
||||
|
@ -173,6 +178,7 @@ function is_serialized_string($data) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Options functions */
|
||||
|
||||
// expects $setting to already be SQL-escaped
|
||||
|
@ -225,6 +231,7 @@ function get_option($setting) {
|
|||
return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
|
||||
}
|
||||
|
||||
|
||||
function wp_protect_special_option( $option ) {
|
||||
$protected = array( 'alloptions', 'notoptions' );
|
||||
if ( in_array( $option, $protected ) )
|
||||
|
@ -238,26 +245,22 @@ function form_option($option) {
|
|||
function get_alloptions() {
|
||||
global $wpdb, $wp_queries;
|
||||
$wpdb->hide_errors();
|
||||
if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) {
|
||||
if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
|
||||
$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
|
||||
}
|
||||
$wpdb->show_errors();
|
||||
|
||||
foreach ( $options as $option ) {
|
||||
// "When trying to design a foolproof system,
|
||||
// never underestimate the ingenuity of the fools :)" -- Dougal
|
||||
if ( 'siteurl' == $option->option_name )
|
||||
$option->option_value = preg_replace('|/+$|', '', $option->option_value);
|
||||
if ( 'home' == $option->option_name )
|
||||
$option->option_value = preg_replace('|/+$|', '', $option->option_value);
|
||||
if ( 'category_base' == $option->option_name )
|
||||
$option->option_value = preg_replace('|/+$|', '', $option->option_value);
|
||||
if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base' ) ) )
|
||||
$option->option_value = untrailingslashit( $option->option_value );
|
||||
$value = maybe_unserialize( $option->option_value );
|
||||
$all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
|
||||
}
|
||||
return apply_filters( 'all_options', $all_options );
|
||||
}
|
||||
|
||||
|
||||
function wp_load_alloptions() {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -276,6 +279,7 @@ function wp_load_alloptions() {
|
|||
return $alloptions;
|
||||
}
|
||||
|
||||
|
||||
// expects $option_name to NOT be SQL-escaped
|
||||
function update_option( $option_name, $newvalue ) {
|
||||
global $wpdb;
|
||||
|
@ -285,14 +289,14 @@ function update_option($option_name, $newvalue) {
|
|||
$safe_option_name = $wpdb->escape( $option_name );
|
||||
$newvalue = sanitize_option( $option_name, $newvalue );
|
||||
|
||||
// Likely legacy -- can we drop this?
|
||||
if ( is_string( $newvalue ) )
|
||||
$newvalue = trim( $newvalue );
|
||||
|
||||
// If the new and old values are the same, no need to update.
|
||||
$oldvalue = get_option( $safe_option_name );
|
||||
if ( $newvalue === $oldvalue ) {
|
||||
if ( $newvalue === $oldvalue )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false === $oldvalue ) {
|
||||
add_option( $option_name, $newvalue );
|
||||
|
@ -324,6 +328,7 @@ function update_option($option_name, $newvalue) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// thx Alex Stapleton, http://alex.vort-x.net/blog/
|
||||
// expects $name to NOT be SQL-escaped
|
||||
function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
|
||||
|
@ -361,6 +366,7 @@ function add_option($name, $value = '', $deprecated = '', $autoload = 'yes') {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
function delete_option( $name ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -369,7 +375,8 @@ function delete_option($name) {
|
|||
// Get the ID, if no ID then return
|
||||
// expected_slashed ($name)
|
||||
$option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
|
||||
if ( !$option->option_id ) return false;
|
||||
if ( !$option->option_id )
|
||||
return false;
|
||||
// expected_slashed ($name)
|
||||
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
|
||||
if ( 'yes' == $option->autoload ) {
|
||||
|
@ -384,6 +391,7 @@ function delete_option($name) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
function maybe_serialize( $data ) {
|
||||
if ( is_string( $data ) )
|
||||
$data = trim( $data );
|
||||
|
@ -394,19 +402,13 @@ function maybe_serialize($data) {
|
|||
return $data;
|
||||
}
|
||||
|
||||
|
||||
function gzip_compression() {
|
||||
if ( !get_option( 'gzipcompression' ) ) {
|
||||
if ( !get_option( 'gzipcompression' ) || ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0 || ini_get( 'output_handler' ) == 'ob_gzhandler' || !extension_loaded( 'zlib' ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0 ) || ini_get( 'output_handler' ) == 'ob_gzhandler' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( extension_loaded( 'zlib' ) ) {
|
||||
ob_start( 'ob_gzhandler' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function make_url_footnote( $content ) {
|
||||
preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
|
||||
|
@ -440,6 +442,7 @@ function xmlrpc_getposttitle($content) {
|
|||
return $post_title;
|
||||
}
|
||||
|
||||
|
||||
function xmlrpc_getpostcategory( $content ) {
|
||||
global $post_default_category;
|
||||
if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
|
||||
|
@ -451,6 +454,7 @@ function xmlrpc_getpostcategory($content) {
|
|||
return $post_category;
|
||||
}
|
||||
|
||||
|
||||
function xmlrpc_removepostdata( $content ) {
|
||||
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
|
||||
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
|
||||
|
@ -458,9 +462,10 @@ function xmlrpc_removepostdata($content) {
|
|||
return $content;
|
||||
}
|
||||
|
||||
|
||||
function debug_fopen( $filename, $mode ) {
|
||||
global $debug;
|
||||
if ( $debug == 1 ) {
|
||||
if ( 1 == $debug ) {
|
||||
$fp = fopen( $filename, $mode );
|
||||
return $fp;
|
||||
} else {
|
||||
|
@ -468,19 +473,19 @@ function debug_fopen($filename, $mode) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function debug_fwrite( $fp, $string ) {
|
||||
global $debug;
|
||||
if ( $debug == 1 ) {
|
||||
if ( 1 == $debug )
|
||||
fwrite( $fp, $string );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function debug_fclose( $fp ) {
|
||||
global $debug;
|
||||
if ( $debug == 1 ) {
|
||||
if ( 1 == $debug )
|
||||
fclose( $fp );
|
||||
}
|
||||
}
|
||||
|
||||
function do_enclose( $content, $post_ID ) {
|
||||
global $wp_version, $wpdb;
|
||||
|
@ -502,17 +507,17 @@ function do_enclose( $content, $post_ID ) {
|
|||
debug_fwrite( $log, 'Post contents:' );
|
||||
debug_fwrite( $log, $content . "\n" );
|
||||
|
||||
foreach($post_links_temp[0] as $link_test) :
|
||||
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
|
||||
foreach ( $post_links_temp[0] as $link_test ) {
|
||||
if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
|
||||
$test = parse_url( $link_test );
|
||||
if ( isset( $test['query'] ) )
|
||||
$post_links[] = $link_test;
|
||||
elseif (($test['path'] != '/') && ($test['path'] != ''))
|
||||
elseif ( $test['path'] != '/' && $test['path'] != '' )
|
||||
$post_links[] = $link_test;
|
||||
endif;
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($post_links as $url) :
|
||||
foreach ( $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 ( $headers = wp_get_http_headers( $url) ) {
|
||||
$len = (int) $headers['content-length'];
|
||||
|
@ -525,8 +530,9 @@ function do_enclose( $content, $post_ID ) {
|
|||
}
|
||||
}
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function wp_get_http_headers( $url, $red = 1 ) {
|
||||
global $wp_version;
|
||||
|
@ -536,7 +542,7 @@ function wp_get_http_headers( $url, $red = 1 ) {
|
|||
return false;
|
||||
|
||||
$parts = parse_url( $url );
|
||||
$file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
|
||||
$file = $parts['path'] . ( ( $parts['query'] ) ? '?' . $parts['query'] : '' );
|
||||
$host = $parts['host'];
|
||||
if ( !isset( $parts['port'] ) )
|
||||
$parts['port'] = 80;
|
||||
|
@ -569,19 +575,21 @@ function wp_get_http_headers( $url, $red = 1 ) {
|
|||
return $headers;
|
||||
}
|
||||
|
||||
|
||||
function is_new_day() {
|
||||
global $day, $previousday;
|
||||
if ( $day != $previousday ) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ( $day != $previousday )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function build_query( $data ) {
|
||||
return _http_build_query( $data, NULL, '&', '', false );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
add_query_arg: Returns a modified querystring by adding
|
||||
a single key & value or an associative array.
|
||||
|
@ -657,6 +665,7 @@ function add_query_arg() {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
remove_query_arg: Returns a modified querystring by removing
|
||||
a single key or an array of keys.
|
||||
|
@ -676,6 +685,7 @@ function remove_query_arg($key, $query=FALSE) {
|
|||
return add_query_arg( $key, FALSE, $query );
|
||||
}
|
||||
|
||||
|
||||
function add_magic_quotes( $array ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -724,16 +734,17 @@ function wp_remote_fopen( $uri ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function wp( $query_vars = '' ) {
|
||||
global $wp;
|
||||
|
||||
$wp->main( $query_vars );
|
||||
}
|
||||
|
||||
|
||||
function get_status_header_desc( $code ) {
|
||||
global $wp_header_to_desc;
|
||||
|
||||
$code = (int) $code;
|
||||
$code = absint( $code );
|
||||
|
||||
if ( !isset( $wp_header_to_desc ) ) {
|
||||
$wp_header_to_desc = array(
|
||||
|
@ -783,12 +794,12 @@ function get_status_header_desc( $code ) {
|
|||
);
|
||||
}
|
||||
|
||||
if ( isset( $wp_header_to_desc[$code] ) ) {
|
||||
if ( isset( $wp_header_to_desc[$code] ) )
|
||||
return $wp_header_to_desc[$code];
|
||||
} else {
|
||||
else
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function status_header( $header ) {
|
||||
$text = get_status_header_desc( $header );
|
||||
|
@ -797,26 +808,28 @@ function status_header( $header ) {
|
|||
return false;
|
||||
|
||||
$protocol = $_SERVER["SERVER_PROTOCOL"];
|
||||
if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
|
||||
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
|
||||
$protocol = 'HTTP/1.0';
|
||||
$status_header = "$protocol $header $text";
|
||||
if ( function_exists( 'apply_filters' ) )
|
||||
$status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
|
||||
|
||||
if ( version_compare( phpversion(), '4.3.0', '>=' ) ) {
|
||||
if ( version_compare( phpversion(), '4.3.0', '>=' ) )
|
||||
return @header( $status_header, true, $header );
|
||||
} else {
|
||||
else
|
||||
return @header( $status_header );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function nocache_headers() {
|
||||
// why are these @-silenced when other header calls aren't?
|
||||
@header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
|
||||
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
|
||||
@header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
|
||||
@header( 'Pragma: no-cache' );
|
||||
}
|
||||
|
||||
|
||||
function cache_javascript_headers() {
|
||||
$expiresOffset = 864000; // 10 days
|
||||
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
|
||||
|
@ -824,15 +837,18 @@ function cache_javascript_headers() {
|
|||
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
|
||||
}
|
||||
|
||||
|
||||
function get_num_queries() {
|
||||
global $wpdb;
|
||||
return $wpdb->num_queries;
|
||||
}
|
||||
|
||||
|
||||
function bool_from_yn( $yn ) {
|
||||
return ( strtolower( $yn ) == 'y' );
|
||||
}
|
||||
|
||||
|
||||
function do_feed() {
|
||||
global $wp_query;
|
||||
|
||||
|
@ -848,29 +864,31 @@ function do_feed() {
|
|||
do_action( $hook, $wp_query->is_comment_feed );
|
||||
}
|
||||
|
||||
|
||||
function do_feed_rdf() {
|
||||
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
|
||||
}
|
||||
|
||||
|
||||
function do_feed_rss() {
|
||||
load_template( ABSPATH . WPINC . '/feed-rss.php' );
|
||||
}
|
||||
|
||||
|
||||
function do_feed_rss2( $for_comments ) {
|
||||
if ( $for_comments ) {
|
||||
if ( $for_comments )
|
||||
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
|
||||
} else {
|
||||
else
|
||||
load_template( ABSPATH . WPINC . '/feed-rss2.php' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function do_feed_atom( $for_comments ) {
|
||||
if ($for_comments) {
|
||||
if ($for_comments)
|
||||
load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
|
||||
} else {
|
||||
else
|
||||
load_template( ABSPATH . WPINC . '/feed-atom.php' );
|
||||
}
|
||||
}
|
||||
|
||||
function do_robots() {
|
||||
header( 'Content-Type: text/plain; charset=utf-8' );
|
||||
|
@ -886,21 +904,23 @@ function do_robots() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function is_blog_installed() {
|
||||
global $wpdb;
|
||||
$wpdb->hide_errors();
|
||||
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
|
||||
$wpdb->show_errors();
|
||||
|
||||
$install_status = !empty( $installed ) ? TRUE : FALSE;
|
||||
return $install_status;
|
||||
return !empty( $installed );
|
||||
}
|
||||
|
||||
|
||||
function wp_nonce_url( $actionurl, $action = -1 ) {
|
||||
$actionurl = str_replace( '&', '&', $actionurl );
|
||||
return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
|
||||
}
|
||||
|
||||
|
||||
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true ) {
|
||||
$name = attribute_escape( $name );
|
||||
echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
|
||||
|
@ -908,6 +928,7 @@ function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true) {
|
|||
wp_referer_field();
|
||||
}
|
||||
|
||||
|
||||
function wp_referer_field() {
|
||||
$ref = attribute_escape( $_SERVER['REQUEST_URI'] );
|
||||
echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
|
||||
|
@ -917,10 +938,12 @@ function wp_referer_field() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function wp_original_referer_field() {
|
||||
echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $_SERVER['REQUEST_URI'] ) ) . '" />';
|
||||
}
|
||||
|
||||
|
||||
function wp_get_referer() {
|
||||
foreach ( array( $_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER'] ) as $ref )
|
||||
if ( !empty( $ref ) )
|
||||
|
@ -928,20 +951,18 @@ function wp_get_referer() {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
function wp_get_original_referer() {
|
||||
if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
|
||||
return $_REQUEST['_wp_original_http_referer'];
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function wp_mkdir_p( $target ) {
|
||||
// from php.net/mkdir user contributed notes
|
||||
if (file_exists($target)) {
|
||||
if (! @ is_dir($target))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
if ( file_exists( $target ) )
|
||||
return @is_dir( $target );
|
||||
|
||||
// Attempting to create the directory may clutter up our display.
|
||||
if ( @mkdir( $target ) ) {
|
||||
|
@ -949,8 +970,7 @@ function wp_mkdir_p($target) {
|
|||
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
|
||||
@chmod( $target, $dir_perms );
|
||||
return true;
|
||||
} else {
|
||||
if ( is_dir(dirname($target)) )
|
||||
} elseif ( is_dir( dirname( $target ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -961,6 +981,7 @@ function wp_mkdir_p($target) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Returns an array containing the current upload directory's path and url, or an error message.
|
||||
function wp_upload_dir() {
|
||||
$siteurl = get_option( 'siteurl' );
|
||||
|
@ -969,9 +990,8 @@ function wp_upload_dir() {
|
|||
$dir = ABSPATH . $path;
|
||||
$url = trailingslashit( $siteurl ) . $path;
|
||||
|
||||
if ( $dir == ABSPATH ) { //the option was empty
|
||||
if ( $dir == ABSPATH ) // the option was empty
|
||||
$dir = ABSPATH . 'wp-content/uploads';
|
||||
}
|
||||
|
||||
if ( defined('UPLOADS') ) {
|
||||
$dir = ABSPATH . UPLOADS;
|
||||
|
@ -1049,9 +1069,10 @@ function wp_upload_bits($name, $type, $bits) {
|
|||
return array( 'file' => $new_file, 'url' => $url, 'error' => false );
|
||||
}
|
||||
|
||||
|
||||
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 (
|
||||
$mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
|
||||
'jpg|jpeg|jpe' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'png' => 'image/png',
|
||||
|
@ -1095,8 +1116,8 @@ function wp_check_filetype($filename, $mimes = null) {
|
|||
'odc' => 'application/vnd.oasis.opendocument.chart',
|
||||
'odb' => 'application/vnd.oasis.opendocument.database',
|
||||
'odf' => 'application/vnd.oasis.opendocument.formula',
|
||||
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
$type = false;
|
||||
$ext = false;
|
||||
|
@ -1177,6 +1198,7 @@ function wp_explain_nonce($action) {
|
|||
return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
|
||||
}
|
||||
|
||||
|
||||
function wp_nonce_ays( $action ) {
|
||||
global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
|
||||
|
||||
|
@ -1205,6 +1227,7 @@ function wp_nonce_ays($action) {
|
|||
wp_die( $html, $title );
|
||||
}
|
||||
|
||||
|
||||
function wp_die( $message, $title = '' ) {
|
||||
global $wp_locale;
|
||||
|
||||
|
@ -1276,18 +1299,21 @@ if ( ( $wp_locale ) && ('rtl' == $wp_locale->text_direction) ) : ?>
|
|||
die();
|
||||
}
|
||||
|
||||
|
||||
function _config_wp_home( $url = '' ) {
|
||||
if ( defined( 'WP_HOME' ) )
|
||||
return WP_HOME;
|
||||
else return $url;
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
function _config_wp_siteurl( $url = '' ) {
|
||||
if ( defined( 'WP_SITEURL' ) )
|
||||
return WP_SITEURL;
|
||||
else return $url;
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
function _mce_set_direction() {
|
||||
global $wp_locale;
|
||||
|
||||
|
@ -1297,6 +1323,7 @@ function _mce_set_direction() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function _mce_load_rtl_plugin( $input ) {
|
||||
global $wp_locale;
|
||||
|
||||
|
@ -1306,6 +1333,7 @@ function _mce_load_rtl_plugin($input) {
|
|||
return $input;
|
||||
}
|
||||
|
||||
|
||||
function _mce_add_direction_buttons( $input ) {
|
||||
global $wp_locale;
|
||||
|
||||
|
@ -1317,6 +1345,7 @@ function _mce_add_direction_buttons($input) {
|
|||
return $input;
|
||||
}
|
||||
|
||||
|
||||
function smilies_init() {
|
||||
global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
|
||||
|
||||
|
@ -1376,11 +1405,12 @@ function smilies_init() {
|
|||
$siteurl = get_option( 'siteurl' );
|
||||
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
|
||||
$wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
|
||||
$smiley_masked = htmlspecialchars(trim($smiley), ENT_QUOTES);
|
||||
$smiley_masked = attribute_escape( trim( $smiley ) );
|
||||
$wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function wp_parse_args( $args, $defaults = '' ) {
|
||||
if ( is_object( $args ) )
|
||||
$r = get_object_vars( $args );
|
||||
|
@ -1391,30 +1421,32 @@ function wp_parse_args( $args, $defaults = '' ) {
|
|||
|
||||
if ( is_array( $defaults ) )
|
||||
return array_merge( $defaults, $r );
|
||||
else
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
function wp_maybe_load_widgets() {
|
||||
if ( !function_exists( 'dynamic_sidebar' ) ) {
|
||||
require_once ABSPATH . WPINC . '/widgets.php';
|
||||
require_once( ABSPATH . WPINC . '/widgets.php' );
|
||||
add_action( '_admin_menu', 'wp_widgets_add_menu' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function wp_widgets_add_menu() {
|
||||
global $submenu;
|
||||
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
|
||||
ksort( $submenu['themes.php'], SORT_NUMERIC );
|
||||
}
|
||||
|
||||
|
||||
// For PHP 5.2, make sure all output buffers are flushed
|
||||
// before our singletons our destroyed.
|
||||
function wp_ob_end_flush_all()
|
||||
{
|
||||
function wp_ob_end_flush_all() {
|
||||
while ( @ob_end_flush() );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* require_wp_db() - require_once the correct database class file.
|
||||
*
|
||||
|
@ -1423,8 +1455,7 @@ function wp_ob_end_flush_all()
|
|||
*
|
||||
* @global $wpdb
|
||||
*/
|
||||
function require_wp_db()
|
||||
{
|
||||
function require_wp_db() {
|
||||
global $wpdb;
|
||||
if ( file_exists( ABSPATH . 'wp-content/db.php' ) )
|
||||
require_once( ABSPATH . 'wp-content/db.php' );
|
||||
|
@ -1432,6 +1463,7 @@ function require_wp_db()
|
|||
require_once( ABSPATH . WPINC . '/wp-db.php' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts input to an absolute integer
|
||||
* @param mixed $maybeint data you wish to have convered to an absolute integer
|
||||
|
|
Loading…
Reference in New Issue