9 * Converts MySQL DATETIME field to user specified date format.
11 * If $dateformatstring has 'G' value, then gmmktime() function will be used to
12 * make the time. If $dateformatstring is set to 'U', then mktime() function
13 * will be used to make the time.
15 * The $translate will only be used, if it is set to true and it is by default
16 * and if the $wp_locale object has the month and weekday set.
20 * @param string $dateformatstring Either 'G', 'U', or php date format.
21 * @param string $mysqlstring Time from mysql DATETIME field.
22 * @param bool $translate Optional. Default is true. Will switch format to locale.
23 * @return string Date formated by $dateformatstring or locale (if available).
25 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
31 if( 'G' == $dateformatstring ) {
33 (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
34 (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
39 (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
40 (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
43 if( 'U' == $dateformatstring )
46 if ( -1 == $i || false == $i )
49 if ( !empty( $wp_locale->month ) && !empty( $wp_locale->weekday ) && $translate ) {
50 $datemonth = $wp_locale->get_month( date( 'm', $i ) );
51 $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
52 $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
53 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
54 $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
55 $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
56 $dateformatstring = ' ' . $dateformatstring;
57 $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
58 $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
59 $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
60 $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
61 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
62 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
64 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
66 $j = @date( $dateformatstring, $i );
69 if ( !$j ) // for debug purposes
70 echo $i." ".$mysqlstring;
77 * Retrieve the current time based on specified type.
79 * The 'mysql' type will return the time in the format for MySQL DATETIME field.
80 * The 'timestamp' type will return the current timestamp.
82 * If the $gmt is set to either '1' or 'true', then both types will use the
83 * GMT offset in the WordPress option to add the GMT offset to the time.
87 * @param string $type Either 'mysql' or 'timestamp'.
88 * @param int|bool $gmt Optional. Whether to use $gmt offset. Default is false.
91 function current_time( $type, $gmt = 0 ) {
94 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
97 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
103 * Retrieve the date in localized format, based on timestamp.
105 * If the locale specifies the locale month and weekday, then the locale will
106 * take over the format for the date. If it isn't, then the date format string
107 * will be used instead.
111 * @param string $dateformatstring Format to display the date
112 * @param int $unixtimestamp Unix timestamp
113 * @return string The date, translated if locale specifies it.
115 function date_i18n( $dateformatstring, $unixtimestamp ) {
118 // Sanity check for PHP 5.1.0-
122 if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
123 $datemonth = $wp_locale->get_month( date( 'm', $i ) );
124 $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
125 $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
126 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
127 $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
128 $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
129 $dateformatstring = ' '.$dateformatstring;
130 $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
131 $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
132 $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
133 $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
134 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
135 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
137 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
139 $j = @date( $dateformatstring, $i );
144 * Convert number to format based on the locale.
148 * @param mixed $number The number to convert based on locale.
149 * @param int $decimals Precision of the number of decimal places.
150 * @return string Converted number in string format.
152 function number_format_i18n( $number, $decimals = null ) {
154 // let the user override the precision only
155 $decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
157 return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
161 * Convert number of bytes largest unit bytes will fit into.
163 * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts
164 * number of bytes to human readable number by taking the number of that unit
165 * that the bytes will go into it. Supports TB value.
167 * Please note that integers in PHP are limited to 32 bits, unless they are on
168 * 64 bit architecture, then they have 64 bit size. If you need to place the
169 * larger size then what PHP integer type will hold, then use a string. It will
170 * be converted to a double, which should always have 64 bit length.
172 * Technically the correct unit names for powers of 1024 are KiB, MiB etc.
173 * @link http://en.wikipedia.org/wiki/Byte
177 * @param int|string $bytes Number of bytes. Note max integer size for integers.
178 * @param int $decimals Precision of number of decimal places.
181 function size_format( $bytes, $decimals = null ) {
183 // ========================= Origin ====
184 'TB' => 1099511627776, // pow( 1024, 4)
185 'GB' => 1073741824, // pow( 1024, 3)
186 'MB' => 1048576, // pow( 1024, 2)
187 'kB' => 1024, // pow( 1024, 1)
188 'B ' => 1, // pow( 1024, 0)
191 foreach ( $quant as $unit => $mag )
192 if ( doubleval($bytes) >= $mag )
193 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
199 function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
200 $my = substr( $mysqlstring, 0, 4 );
201 $mm = substr( $mysqlstring, 8, 2 );
202 $md = substr( $mysqlstring, 5, 2 );
203 $day = mktime( 0, 0, 0, $md, $mm, $my );
204 $weekday = date( 'w', $day );
206 if( !is_numeric($start_of_week) )
207 $start_of_week = get_option( 'start_of_week' );
209 if ( $weekday < $start_of_week )
210 $weekday = 7 - $start_of_week - $weekday;
212 while ( $weekday > $start_of_week ) {
213 $weekday = date( 'w', $day );
214 if ( $weekday < $start_of_week )
215 $weekday = 7 - $start_of_week - $weekday;
220 $week['start'] = $day + 86400 - $i;
221 $week['end'] = $week['start'] + 604799;
226 * Unserialize value only if it was serialized.
230 * @param string $original Maybe unserialized original, if is needed.
231 * @return mixed Unserialized data can be any type.
233 function maybe_unserialize( $original ) {
234 if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
235 if ( false !== $gm = @unserialize( $original ) )
241 * Check value to find if it was serialized.
243 * If $data is not an string, then returned value will always be false.
244 * Serialized data is always a string.
248 * @param mixed $data Value to check to see if was serialized.
249 * @return bool False if not serialized and true if it was.
251 function is_serialized( $data ) {
252 // if it isn't a string, it isn't serialized
253 if ( !is_string( $data ) )
255 $data = trim( $data );
258 if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
260 switch ( $badions[1] ) {
264 if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
270 if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
278 * Check whether serialized data is of string type.
282 * @param mixed $data Serialized data
283 * @return bool False if not a serialized string, true if it is.
285 function is_serialized_string( $data ) {
286 // if it isn't a string, it isn't a serialized string
287 if ( !is_string( $data ) )
289 $data = trim( $data );
290 if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
296 * Retrieve option value based on setting name.
298 * If the option does not exist or does not have a value, then the return value
299 * will be false. This is useful to check whether you need to install an option
300 * and is commonly used during installation of plugin options and to test
301 * whether upgrading is required.
303 * You can "short-circuit" the retrieval of the option from the database for
304 * your plugin or core options that aren't protected. You can do so by hooking
305 * into the 'pre_option_$option' with the $option being replaced by the option
306 * name. You should not try to override special options, but you will not be
307 * prevented from doing so.
309 * There is a second filter called 'option_$option' with the $option being
310 * replaced with the option name. This gives the value as the only parameter.
315 * @uses apply_filters() Calls 'pre_option_$optionname' false to allow
316 * overwriting the option value in a plugin.
317 * @uses apply_filters() Calls 'option_$optionname' with the option name value.
319 * @param string $setting Name of option to retrieve. Should already be SQL-escaped
320 * @return mixed Value set for the option.
322 function get_option( $setting ) {
325 // Allow plugins to short-circuit options.
326 $pre = apply_filters( 'pre_option_' . $setting, false );
327 if ( false !== $pre )
330 // prevent non-existent options from triggering multiple queries
331 $notoptions = wp_cache_get( 'notoptions', 'options' );
332 if ( isset( $notoptions[$setting] ) )
335 $alloptions = wp_load_alloptions();
337 if ( isset( $alloptions[$setting] ) ) {
338 $value = $alloptions[$setting];
340 $value = wp_cache_get( $setting, 'options' );
342 if ( false === $value ) {
343 if ( defined( 'WP_INSTALLING' ) )
344 $suppress = $wpdb->suppress_errors();
345 // expected_slashed ($setting)
346 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
347 if ( defined( 'WP_INSTALLING' ) )
348 $wpdb->suppress_errors($suppress);
350 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
351 $value = $row->option_value;
352 wp_cache_add( $setting, $value, 'options' );
353 } else { // option does not exist, so we must cache its non-existence
354 $notoptions[$setting] = true;
355 wp_cache_set( 'notoptions', $notoptions, 'options' );
361 // If home is not set use siteurl.
362 if ( 'home' == $setting && '' == $value )
363 return get_option( 'siteurl' );
365 if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
366 $value = untrailingslashit( $value );
368 return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
372 * Protect WordPress special option from being modified.
374 * Will die if $option is in protected list.
380 * @param string $option Option name.
382 function wp_protect_special_option( $option ) {
383 $protected = array( 'alloptions', 'notoptions' );
384 if ( in_array( $option, $protected ) )
385 die( sprintf( __( '%s is a protected WP option and may not be modified' ), wp_specialchars( $option ) ) );
389 * Print option value after sanitizing for forms.
391 * @uses attribute_escape Sanitizes value.
396 * @param string $option Option name.
398 function form_option( $option ) {
399 echo attribute_escape (get_option( $option ) );
403 * Retrieve all autoload options or all options, if no autoloaded ones exist.
405 * This is different from wp_load_alloptions(), in this that function does not
406 * cache all options and will retrieve all options from the database every time
412 * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter.
413 * @uses apply_filters() Calls 'all_options' on options list.
415 * @return array List of all options.
417 function get_alloptions() {
418 global $wpdb, $wp_queries;
419 $show = $wpdb->hide_errors();
420 if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
421 $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
422 $wpdb->show_errors($show);
424 foreach ( $options as $option ) {
425 // "When trying to design a foolproof system,
426 // never underestimate the ingenuity of the fools :)" -- Dougal
427 if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
428 $option->option_value = untrailingslashit( $option->option_value );
429 $value = maybe_unserialize( $option->option_value );
430 $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
432 return apply_filters( 'all_options', $all_options );
436 * Loads and caches all autoloaded options, if available or all options.
438 * This is different from get_alloptions(), in that this function will cache the
439 * options and will return the cached options when called again.
445 * @return array List all options.
447 function wp_load_alloptions() {
450 $alloptions = wp_cache_get( 'alloptions', 'options' );
452 if ( !$alloptions ) {
453 $suppress = $wpdb->suppress_errors();
454 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
455 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
456 $wpdb->suppress_errors($suppress);
457 $alloptions = array();
458 foreach ( (array) $alloptions_db as $o )
459 $alloptions[$o->option_name] = $o->option_value;
460 wp_cache_add( 'alloptions', $alloptions, 'options' );
466 * Update the value of an option that was already added.
468 * If the option does not exist, then the option will be added with the option
469 * value, but you will not be able to set whether it is autoloaded. If you want
470 * to set whether an option autoloaded, then you need to use the add_option().
472 * When the option is updated, then the filter named
473 * 'update_option_$option_name', with the $option_name as the $option_name
474 * parameter value, will be called. The hook should accept two parameters, the
475 * first is the old parameter and the second is the new parameter.
481 * @param string $option_name Option name. Expected to not be SQL-escaped
482 * @param mixed $newvalue Option value.
483 * @return bool False if value was not updated and true if value was updated.
485 function update_option( $option_name, $newvalue ) {
488 wp_protect_special_option( $option_name );
490 $safe_option_name = $wpdb->escape( $option_name );
491 $newvalue = sanitize_option( $option_name, $newvalue );
493 $oldvalue = get_option( $safe_option_name );
495 $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
497 // If the new and old values are the same, no need to update.
498 if ( $newvalue === $oldvalue )
501 if ( false === $oldvalue ) {
502 add_option( $option_name, $newvalue );
506 $notoptions = wp_cache_get( 'notoptions', 'options' );
507 if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
508 unset( $notoptions[$option_name] );
509 wp_cache_set( 'notoptions', $notoptions, 'options' );
512 $_newvalue = $newvalue;
513 $newvalue = maybe_serialize( $newvalue );
515 $alloptions = wp_load_alloptions();
516 if ( isset( $alloptions[$option_name] ) ) {
517 $alloptions[$option_name] = $newvalue;
518 wp_cache_set( 'alloptions', $alloptions, 'options' );
520 wp_cache_set( $option_name, $newvalue, 'options' );
523 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name ) );
524 if ( $wpdb->rows_affected == 1 ) {
525 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
534 * You can create options without values and then add values later. Does not
535 * check whether the option has already been added, but does check that you
536 * aren't adding a protected WordPress option. Care should be taken to not name
537 * options, the same as the ones which are protected and to not add options
538 * that were already added.
540 * The filter named 'add_option_$optionname', with the $optionname being
541 * replaced with the option's name, will be called. The hook should accept two
542 * parameters, the first is the option name, and the second is the value.
547 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
549 * @param string $name Option name to add. Expects to NOT be SQL escaped.
550 * @param mixed $value Optional. Option value, can be anything.
551 * @param mixed $deprecated Optional. Description. Not used anymore.
552 * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
553 * @return null returns when finished.
555 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
558 wp_protect_special_option( $name );
559 $safe_name = $wpdb->escape( $name );
560 $value = sanitize_option( $name, $value );
562 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
563 $notoptions = wp_cache_get( 'notoptions', 'options' );
564 if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
565 if ( false !== get_option( $safe_name ) )
568 $value = maybe_serialize( $value );
569 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
571 if ( 'yes' == $autoload ) {
572 $alloptions = wp_load_alloptions();
573 $alloptions[$name] = $value;
574 wp_cache_set( 'alloptions', $alloptions, 'options' );
576 wp_cache_set( $name, $value, 'options' );
579 // This option exists now
580 $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
581 if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
582 unset( $notoptions[$name] );
583 wp_cache_set( 'notoptions', $notoptions, 'options' );
586 $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
588 do_action( "add_option_{$name}", $name, $value );
593 * Removes option by name and prevents removal of protected WordPress options.
599 * @param string $name Option name to remove.
600 * @return bool True, if succeed. False, if failure.
602 function delete_option( $name ) {
605 wp_protect_special_option( $name );
607 // Get the ID, if no ID then return
608 // expected_slashed ($name)
609 $option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
610 if ( is_null($option) || !$option->option_id )
612 // expected_slashed ($name)
613 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
614 if ( 'yes' == $option->autoload ) {
615 $alloptions = wp_load_alloptions();
616 if ( isset( $alloptions[$name] ) ) {
617 unset( $alloptions[$name] );
618 wp_cache_set( 'alloptions', $alloptions, 'options' );
621 wp_cache_delete( $name, 'options' );
627 * Serialize data, if needed.
629 * @param mixed $data Data that might be serialized.
630 * @return mixed A scalar data
632 function maybe_serialize( $data ) {
633 if ( is_array( $data ) || is_object( $data ) )
634 return serialize( $data );
636 if ( is_serialized( $data ) )
637 return serialize( $data );
643 function make_url_footnote( $content ) {
644 preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
646 for ( $i=0; $i<count($matches[0]); $i++ ) {
647 $links_summary = ( !$j ) ? "\n" : $links_summary;
649 $link_match = $matches[0][$i];
650 $link_number = '['.($i+1).']';
651 $link_url = $matches[2][$i];
652 $link_text = $matches[4][$i];
653 $content = str_replace( $link_match, $link_text . ' ' . $link_number, $content );
654 $link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) != 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) != 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url;
655 $links_summary .= "\n" . $link_number . ' ' . $link_url;
657 $content = strip_tags( $content );
658 $content .= $links_summary;
663 function xmlrpc_getposttitle( $content ) {
664 global $post_default_title;
665 if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
666 $post_title = $matchtitle[0];
667 $post_title = preg_replace( '/<title>/si', '', $post_title );
668 $post_title = preg_replace( '/<\/title>/si', '', $post_title );
670 $post_title = $post_default_title;
676 function xmlrpc_getpostcategory( $content ) {
677 global $post_default_category;
678 if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
679 $post_category = trim( $matchcat[1], ',' );
680 $post_category = explode( ',', $post_category );
682 $post_category = $post_default_category;
684 return $post_category;
688 function xmlrpc_removepostdata( $content ) {
689 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
690 $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
691 $content = trim( $content );
696 * Open the file handle for debugging.
698 * This function is used for XMLRPC feature, but it is general purpose enough
699 * to be used in anywhere.
701 * @see fopen() for mode options.
705 * @uses $debug Used for whether debugging is enabled.
707 * @param string $filename File path to debug file.
708 * @param string $mode Same as fopen() mode parameter.
709 * @return bool|resource File handle. False on failure.
711 function debug_fopen( $filename, $mode ) {
714 $fp = fopen( $filename, $mode );
722 * Write contents to the file used for debugging.
724 * Technically, this can be used to write to any file handle when the global
725 * $debug is set to 1 or true.
730 * @uses $debug Used for whether debugging is enabled.
732 * @param resource $fp File handle for debugging file.
733 * @param string $string Content to write to debug file.
735 function debug_fwrite( $fp, $string ) {
738 fwrite( $fp, $string );
742 * Close the debugging file handle.
744 * Technically, this can be used to close any file handle when the global $debug
745 * is set to 1 or true.
750 * @uses $debug Used for whether debugging is enabled.
752 * @param resource $fp Debug File handle.
754 function debug_fclose( $fp ) {
760 function do_enclose( $content, $post_ID ) {
762 include_once( ABSPATH . WPINC . '/class-IXR.php' );
764 $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
765 $post_links = array();
766 debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" );
768 $pung = get_enclosed( $post_ID );
771 $gunk = '/#~:.?+=&%@!\-';
773 $any = $ltrs . $gunk . $punc;
775 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
777 debug_fwrite( $log, 'Post contents:' );
778 debug_fwrite( $log, $content . "\n" );
780 foreach ( $post_links_temp[0] as $link_test ) {
781 if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
782 $test = parse_url( $link_test );
783 if ( isset( $test['query'] ) )
784 $post_links[] = $link_test;
785 elseif ( $test['path'] != '/' && $test['path'] != '' )
786 $post_links[] = $link_test;
790 foreach ( $post_links as $url ) {
791 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 . '%' ) ) ) {
792 if ( $headers = wp_get_http_headers( $url) ) {
793 $len = (int) $headers['content-length'];
794 $type = $wpdb->escape( $headers['content-type'] );
795 $allowed_types = array( 'video', 'audio' );
796 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
797 $meta_value = "$url\n$len\n$type\n";
798 $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
799 VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value ) );
807 * Perform a HTTP HEAD or GET request.
809 * If $file_path is a writable filename, this will do a GET request and write
810 * the file to that path.
815 * @param string|bool $file_path Optional. File path to write request to.
816 * @param int $red Optional. Number of Redirects. Stops at 5 redirects.
817 * @return bool|string False on failure and string of headers if HEAD request.
819 function wp_get_http( $url, $file_path = false, $red = 1 ) {
821 @set_time_limit( 60 );
826 $parts = parse_url( $url );
827 $file = $parts['path'] . ( ( $parts['query'] ) ? '?' . $parts['query'] : '' );
828 $host = $parts['host'];
829 if ( !isset( $parts['port'] ) )
833 $request_type = 'GET';
835 $request_type = 'HEAD';
837 $head = "$request_type $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
839 $fp = @fsockopen( $host, $parts['port'], $err_num, $err_msg, 3 );
845 while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
846 $response .= fgets( $fp, 2048 );
847 preg_match_all( '/(.*?): (.*)\r/', $response, $matches );
848 $count = count( $matches[1] );
849 for ( $i = 0; $i < $count; $i++ ) {
850 $key = strtolower( $matches[1][$i] );
851 $headers["$key"] = $matches[2][$i];
854 preg_match( '/.*([0-9]{3}).*/', $response, $return );
855 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
857 $code = $headers['response'];
858 if ( ( '302' == $code || '301' == $code ) && isset( $headers['location'] ) ) {
860 return wp_get_http( $headers['location'], $file_path, ++$red );
863 // make a note of the final location, so the caller can tell if we were redirected or not
864 $headers['x-final-location'] = $url;
872 // GET request - fetch and write it to the supplied filename
873 $content_length = $headers['content-length'];
875 $out_fp = fopen($file_path, 'w');
876 while ( !feof($fp) ) {
877 $buf = fread( $fp, 4096 );
878 fwrite( $out_fp, $buf );
879 $got_bytes += strlen($buf);
880 // don't read past the content-length
881 if ($content_length and $got_bytes >= $content_length)
891 * Retrieve HTTP Headers from URL.
896 * @param int $red Optional. Number of redirects.
897 * @return bool|string False on failure, headers on success.
899 function wp_get_http_headers( $url, $red = 1 ) {
900 return wp_get_http( $url, false, $red );
904 * Whether today is a new day.
906 * {@internal Need to find out how this function is used.}}
910 * @uses $previousday Previous day
912 * @return int 1 when new day, 0 if not a new day.
914 function is_new_day() {
915 global $day, $previousday;
916 if ( $day != $previousday )
923 * Build URL query based on an associative and, or indexed array.
925 * This is a convenient function for easily building url queries. It sets the
926 * separator to '&' and uses _http_build_query() function.
928 * @see _http_build_query() Used to build the query
929 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what
930 * http_build_query() does.
934 * @param array $data URL-encode key/value pairs.
935 * @return string URL encoded string
937 function build_query( $data ) {
938 return _http_build_query( $data, NULL, '&', '', false );
942 * Retrieve a modified URL query string.
944 * You can rebuild the URL and append a new query variable to the URL query by
945 * using this function. You can also retrieve the full URL with query data.
947 * Adding a single key & value or an associative array. Setting a key value to
948 * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
953 * @param mixed $param1 Either newkey or an associative_array
954 * @param mixed $param2 Either newvalue or oldquery or uri
955 * @param mixed $param3 Optional. Old query or uri
958 function add_query_arg() {
960 if ( is_array( func_get_arg(0) ) ) {
961 if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
962 $uri = $_SERVER['REQUEST_URI'];
964 $uri = @func_get_arg( 1 );
966 if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
967 $uri = $_SERVER['REQUEST_URI'];
969 $uri = @func_get_arg( 2 );
972 if ( $frag = strstr( $uri, '#' ) )
973 $uri = substr( $uri, 0, -strlen( $frag ) );
977 if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
978 $protocol = $matches[0];
979 $uri = substr( $uri, strlen( $protocol ) );
984 if ( strpos( $uri, '?' ) !== false ) {
985 $parts = explode( '?', $uri, 2 );
986 if ( 1 == count( $parts ) ) {
990 $base = $parts[0] . '?';
993 } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
1001 wp_parse_str( $query, $qs );
1002 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
1003 if ( is_array( func_get_arg( 0 ) ) ) {
1004 $kayvees = func_get_arg( 0 );
1005 $qs = array_merge( $qs, $kayvees );
1007 $qs[func_get_arg( 0 )] = func_get_arg( 1 );
1010 foreach ( $qs as $k => $v ) {
1015 $ret = build_query( $qs );
1016 $ret = trim( $ret, '?' );
1017 $ret = preg_replace( '#=(&|$)#', '$1', $ret );
1018 $ret = $protocol . $base . $ret . $frag;
1019 $ret = rtrim( $ret, '?' );
1024 * Removes an item or list from the query string.
1028 * @param string|array $key Query key or keys to remove.
1029 * @param bool $query When false uses the $_SERVER value.
1032 function remove_query_arg( $key, $query=false ) {
1033 if ( is_array( $key ) ) { // removing multiple keys
1034 foreach ( (array) $key as $k )
1035 $query = add_query_arg( $k, false, $query );
1038 return add_query_arg( $key, false, $query );
1042 * Walks the array while sanitizing the contents.
1044 * @uses $wpdb Used to sanitize values
1046 * @param array $array Array to used to walk while sanitizing contents.
1047 * @return array Sanitized $array.
1049 function add_magic_quotes( $array ) {
1052 foreach ( $array as $k => $v ) {
1053 if ( is_array( $v ) ) {
1054 $array[$k] = add_magic_quotes( $v );
1056 $array[$k] = $wpdb->escape( $v );
1063 * HTTP request for URI to retrieve content.
1065 * Tries to retrieve the HTTP content with fopen first and then using cURL, if
1066 * fopen can't be used.
1070 * @param string $uri URI/URL of web page to retrieve.
1071 * @return string HTTP content.
1073 function wp_remote_fopen( $uri ) {
1075 $parsed_url = @parse_url( $uri );
1077 if ( !$parsed_url || !is_array( $parsed_url ) )
1080 if ( !isset( $parsed_url['scheme'] ) || !in_array( $parsed_url['scheme'], array( 'http','https' ) ) )
1081 $uri = 'http://' . $uri;
1083 if ( ini_get( 'allow_url_fopen' ) ) {
1084 $fp = @fopen( $uri, 'r' );
1088 //stream_set_timeout($fp, $timeout); // Requires php 4.3
1090 while ( $remote_read = fread( $fp, 4096 ) )
1091 $linea .= $remote_read;
1094 } elseif ( function_exists( 'curl_init' ) ) {
1095 $handle = curl_init();
1096 curl_setopt( $handle, CURLOPT_URL, $uri);
1097 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 1 );
1098 curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 1 );
1099 curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
1100 $buffer = curl_exec( $handle );
1101 curl_close( $handle );
1109 function wp( $query_vars = '' ) {
1110 global $wp, $wp_query, $wp_the_query;
1111 $wp->main( $query_vars );
1113 if( !isset($wp_the_query) )
1114 $wp_the_query = $wp_query;
1118 * Retrieve the description for the HTTP status.
1122 * @param int $code HTTP status code.
1123 * @return string Empty string if not found, or description if found.
1125 function get_status_header_desc( $code ) {
1126 global $wp_header_to_desc;
1128 $code = absint( $code );
1130 if ( !isset( $wp_header_to_desc ) ) {
1131 $wp_header_to_desc = array(
1133 101 => 'Switching Protocols',
1138 203 => 'Non-Authoritative Information',
1139 204 => 'No Content',
1140 205 => 'Reset Content',
1141 206 => 'Partial Content',
1143 300 => 'Multiple Choices',
1144 301 => 'Moved Permanently',
1147 304 => 'Not Modified',
1149 307 => 'Temporary Redirect',
1151 400 => 'Bad Request',
1152 401 => 'Unauthorized',
1155 405 => 'Method Not Allowed',
1156 406 => 'Not Acceptable',
1157 407 => 'Proxy Authentication Required',
1158 408 => 'Request Timeout',
1161 411 => 'Length Required',
1162 412 => 'Precondition Failed',
1163 413 => 'Request Entity Too Large',
1164 414 => 'Request-URI Too Long',
1165 415 => 'Unsupported Media Type',
1166 416 => 'Requested Range Not Satisfiable',
1167 417 => 'Expectation Failed',
1169 500 => 'Internal Server Error',
1170 501 => 'Not Implemented',
1171 502 => 'Bad Gateway',
1172 503 => 'Service Unavailable',
1173 504 => 'Gateway Timeout',
1174 505 => 'HTTP Version Not Supported'
1178 if ( isset( $wp_header_to_desc[$code] ) )
1179 return $wp_header_to_desc[$code];
1185 * Set HTTP status header.
1188 * @uses apply_filters() Calls 'status_header' on status header string, HTTP
1189 * HTTP code, HTTP code description, and protocol string as separate
1192 * @param int $header HTTP status code
1193 * @return null Does not return anything.
1195 function status_header( $header ) {
1196 $text = get_status_header_desc( $header );
1198 if ( empty( $text ) )
1201 $protocol = $_SERVER["SERVER_PROTOCOL"];
1202 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
1203 $protocol = 'HTTP/1.0';
1204 $status_header = "$protocol $header $text";
1205 if ( function_exists( 'apply_filters' ) )
1206 $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
1208 if ( version_compare( phpversion(), '4.3.0', '>=' ) )
1209 return @header( $status_header, true, $header );
1211 return @header( $status_header );
1215 * Sets the headers to prevent caching for the different browsers.
1217 * Different browsers support different nocache headers, so several headers must
1218 * be sent so that all of them get the point that no caching should occur.
1222 function nocache_headers() {
1223 // why are these @-silenced when other header calls aren't?
1224 @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
1225 @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
1226 @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
1227 @header( 'Pragma: no-cache' );
1231 * Set the headers for caching for 10 days with JavaScript content type.
1235 function cache_javascript_headers() {
1236 $expiresOffset = 864000; // 10 days
1237 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
1238 header( "Vary: Accept-Encoding" ); // Handle proxies
1239 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
1243 * Retrieve the number of database queries during the WordPress execution.
1247 * @return int Number of database queries
1249 function get_num_queries() {
1251 return $wpdb->num_queries;
1255 * Whether input is yes or no. Must be 'y' to be true.
1259 * @param string $yn Character string containing either 'y' or 'n'
1260 * @return bool True if yes, false on anything else
1262 function bool_from_yn( $yn ) {
1263 return ( strtolower( $yn ) == 'y' );
1267 function do_feed() {
1270 $feed = get_query_var( 'feed' );
1272 // Remove the pad, if present.
1273 $feed = preg_replace( '/^_+/', '', $feed );
1275 if ( $feed == '' || $feed == 'feed' )
1276 $feed = get_default_feed();
1278 $hook = 'do_feed_' . $feed;
1279 if ( !has_action($hook) ) {
1280 $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), wp_specialchars($feed));
1284 do_action( $hook, $wp_query->is_comment_feed );
1288 * Load the RDF RSS 0.91 Feed template.
1292 function do_feed_rdf() {
1293 load_template( ABSPATH . WPINC . '/feed-rdf.php' );
1297 * Load the RSS 1.0 Feed Template
1301 function do_feed_rss() {
1302 load_template( ABSPATH . WPINC . '/feed-rss.php' );
1306 * Load either the RSS2 comment feed or the RSS2 posts feed.
1310 * @param bool $for_comments True for the comment feed, false for normal feed.
1312 function do_feed_rss2( $for_comments ) {
1313 if ( $for_comments )
1314 load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
1316 load_template( ABSPATH . WPINC . '/feed-rss2.php' );
1320 * Load either Atom comment feed or Atom posts feed.
1324 * @param bool $for_comments True for the comment feed, false for normal feed.
1326 function do_feed_atom( $for_comments ) {
1328 load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
1330 load_template( ABSPATH . WPINC . '/feed-atom.php' );
1334 * Display the robot.txt file content.
1336 * The echo content should be with usage of the permalinks or for creating the
1340 * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules.
1342 function do_robots() {
1343 header( 'Content-Type: text/plain; charset=utf-8' );
1345 do_action( 'do_robotstxt' );
1347 if ( '0' == get_option( 'blog_public' ) ) {
1348 echo "User-agent: *\n";
1349 echo "Disallow: /\n";
1351 echo "User-agent: *\n";
1357 function is_blog_installed() {
1360 // Check cache first. If options table goes away and we have true cached, oh well.
1361 if ( wp_cache_get('is_blog_installed') )
1364 $suppress = $wpdb->suppress_errors();
1365 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
1366 $wpdb->suppress_errors($suppress);
1368 $installed = !empty( $installed ) ? true : false;
1369 wp_cache_set('is_blog_installed', $installed);
1375 function wp_nonce_url( $actionurl, $action = -1 ) {
1376 $actionurl = str_replace( '&', '&', $actionurl );
1377 return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
1381 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
1382 $name = attribute_escape( $name );
1383 $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
1388 wp_referer_field( $echo, 'previous' );
1390 return $nonce_field;
1394 function wp_referer_field( $echo = true) {
1395 $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
1396 $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
1399 echo $referer_field;
1400 return $referer_field;
1403 function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
1404 $jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
1405 $ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to;
1406 $orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $ref ) ) . '" />';
1408 echo $orig_referer_field;
1409 return $orig_referer_field;
1413 function wp_get_referer() {
1414 if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
1415 $ref = $_REQUEST['_wp_http_referer'];
1416 else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
1417 $ref = $_SERVER['HTTP_REFERER'];
1419 if ( $ref !== $_SERVER['REQUEST_URI'] )
1425 function wp_get_original_referer() {
1426 if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
1427 return $_REQUEST['_wp_original_http_referer'];
1432 function wp_mkdir_p( $target ) {
1433 // from php.net/mkdir user contributed notes
1434 $target = str_replace( '//', '/', $target );
1435 if ( file_exists( $target ) )
1436 return @is_dir( $target );
1438 // Attempting to create the directory may clutter up our display.
1439 if ( @mkdir( $target ) ) {
1440 $stat = @stat( dirname( $target ) );
1441 $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
1442 @chmod( $target, $dir_perms );
1444 } elseif ( is_dir( dirname( $target ) ) ) {
1448 // If the above failed, attempt to create the parent node, then try again.
1449 if ( wp_mkdir_p( dirname( $target ) ) )
1450 return wp_mkdir_p( $target );
1455 // Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows')
1456 function path_is_absolute( $path ) {
1457 // this is definitive if true but fails if $path does not exist or contains a symbolic link
1458 if ( realpath($path) == $path )
1461 if ( strlen($path) == 0 || $path{0} == '.' )
1464 // windows allows absolute paths like this
1465 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
1468 // a path starting with / or \ is absolute; anything else is relative
1469 return (bool) preg_match('#^[/\\\\]#', $path);
1472 // Join two filesystem paths together (e.g. 'give me $path relative to $base')
1473 function path_join( $base, $path ) {
1474 if ( path_is_absolute($path) )
1477 return rtrim($base, '/') . '/' . ltrim($path, '/');
1480 // Returns an array containing the current upload directory's path and url, or an error message.
1481 function wp_upload_dir( $time = NULL ) {
1482 $siteurl = get_option( 'siteurl' );
1483 $upload_path = get_option( 'upload_path' );
1484 $upload_path = trim($upload_path);
1485 if ( empty($upload_path) )
1486 $dir = WP_CONTENT_DIR . '/uploads';
1488 $dir = $upload_path;
1490 // $dir is absolute, $path is (maybe) relative to ABSPATH
1491 $dir = path_join( ABSPATH, $dir );
1493 if ( !$url = get_option( 'upload_url_path' ) ) {
1494 if ( empty($upload_path) or ( $upload_path == $dir ) )
1495 $url = WP_CONTENT_URL . '/uploads';
1497 $url = trailingslashit( $siteurl ) . $upload_path;
1500 if ( defined('UPLOADS') ) {
1501 $dir = ABSPATH . UPLOADS;
1502 $url = trailingslashit( $siteurl ) . UPLOADS;
1509 if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
1510 // Generate the yearly and monthly dirs
1512 $time = current_time( 'mysql' );
1513 $y = substr( $time, 0, 4 );
1514 $m = substr( $time, 5, 2 );
1521 // Make sure we have an uploads dir
1522 if ( ! wp_mkdir_p( $dir ) ) {
1523 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir );
1524 return array( 'error' => $message );
1527 $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false );
1529 return apply_filters( 'upload_dir', $uploads );
1532 // return a filename that is sanitized and unique for the given directory
1533 function wp_unique_filename( $dir, $filename, $unique_filename_callback = NULL ) {
1534 $filename = strtolower( $filename );
1535 // separate the filename into a name and extension
1536 $info = pathinfo($filename);
1537 $ext = $info['extension'];
1538 $name = basename($filename, ".{$ext}");
1540 // edge case: if file is named '.ext', treat as an empty name
1541 if( $name === ".$ext" )
1544 // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
1545 if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
1546 $filename = $unique_filename_callback( $dir, $name );
1550 if ( empty( $ext ) )
1553 $ext = strtolower( ".$ext" );
1555 $filename = str_replace( $ext, '', $filename );
1556 // Strip % so the server doesn't try to decode entities.
1557 $filename = str_replace('%', '', sanitize_title_with_dashes( $filename ) ) . $ext;
1559 while ( file_exists( $dir . "/$filename" ) ) {
1560 if ( '' == "$number$ext" )
1561 $filename = $filename . ++$number . $ext;
1563 $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
1570 function wp_upload_bits( $name, $deprecated, $bits, $time = NULL ) {
1571 if ( empty( $name ) )
1572 return array( 'error' => __( "Empty filename" ) );
1574 $wp_filetype = wp_check_filetype( $name );
1575 if ( !$wp_filetype['ext'] )
1576 return array( 'error' => __( "Invalid file type" ) );
1578 $upload = wp_upload_dir( $time );
1580 if ( $upload['error'] !== false )
1583 $filename = wp_unique_filename( $upload['path'], $name );
1585 $new_file = $upload['path'] . "/$filename";
1586 if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
1587 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) );
1588 return array( 'error' => $message );
1591 $ifp = @ fopen( $new_file, 'wb' );
1593 return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
1595 @fwrite( $ifp, $bits );
1597 // Set correct file permissions
1598 $stat = @ stat( dirname( $new_file ) );
1599 $perms = $stat['mode'] & 0007777;
1600 $perms = $perms & 0000666;
1601 @ chmod( $new_file, $perms );
1604 $url = $upload['url'] . "/$filename";
1606 return array( 'file' => $new_file, 'url' => $url, 'error' => false );
1609 function wp_ext2type( $ext ) {
1610 $ext2type = apply_filters('ext2type', array(
1611 'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'),
1612 'video' => array('asf','avi','divx','dv','mov','mpg','mpeg','mp4','mpv','ogm','qt','rm','vob','wmv'),
1613 'document' => array('doc','pages','odt','rtf','pdf'),
1614 'spreadsheet' => array('xls','numbers','ods'),
1615 'interactive' => array('ppt','key','odp','swf'),
1616 'text' => array('txt'),
1617 'archive' => array('tar','bz2','gz','cab','dmg','rar','sea','sit','sqx','zip'),
1618 'code' => array('css','html','php','js'),
1620 foreach ( $ext2type as $type => $exts )
1621 if ( in_array($ext, $exts) )
1625 function wp_check_filetype( $filename, $mimes = null ) {
1626 // Accepted MIME types are set here as PCRE unless provided.
1627 $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
1628 'jpg|jpeg|jpe' => 'image/jpeg',
1629 'gif' => 'image/gif',
1630 'png' => 'image/png',
1631 'bmp' => 'image/bmp',
1632 'tif|tiff' => 'image/tiff',
1633 'ico' => 'image/x-icon',
1634 'asf|asx|wax|wmv|wmx' => 'video/asf',
1635 'avi' => 'video/avi',
1636 'mov|qt' => 'video/quicktime',
1637 'mpeg|mpg|mpe|mp4' => 'video/mpeg',
1638 'txt|c|cc|h' => 'text/plain',
1639 'rtx' => 'text/richtext',
1640 'css' => 'text/css',
1641 'htm|html' => 'text/html',
1642 'mp3|m4a' => 'audio/mpeg',
1643 'ra|ram' => 'audio/x-realaudio',
1644 'wav' => 'audio/wav',
1645 'ogg' => 'audio/ogg',
1646 'mid|midi' => 'audio/midi',
1647 'wma' => 'audio/wma',
1648 'rtf' => 'application/rtf',
1649 'js' => 'application/javascript',
1650 'pdf' => 'application/pdf',
1651 'doc' => 'application/msword',
1652 'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
1653 'wri' => 'application/vnd.ms-write',
1654 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
1655 'mdb' => 'application/vnd.ms-access',
1656 'mpp' => 'application/vnd.ms-project',
1657 'swf' => 'application/x-shockwave-flash',
1658 'class' => 'application/java',
1659 'tar' => 'application/x-tar',
1660 'zip' => 'application/zip',
1661 'gz|gzip' => 'application/x-gzip',
1662 'exe' => 'application/x-msdownload',
1663 // openoffice formats
1664 'odt' => 'application/vnd.oasis.opendocument.text',
1665 'odp' => 'application/vnd.oasis.opendocument.presentation',
1666 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
1667 'odg' => 'application/vnd.oasis.opendocument.graphics',
1668 'odc' => 'application/vnd.oasis.opendocument.chart',
1669 'odb' => 'application/vnd.oasis.opendocument.database',
1670 'odf' => 'application/vnd.oasis.opendocument.formula',
1677 foreach ( $mimes as $ext_preg => $mime_match ) {
1678 $ext_preg = '!\.(' . $ext_preg . ')$!i';
1679 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
1680 $type = $mime_match;
1681 $ext = $ext_matches[1];
1686 return compact( 'ext', 'type' );
1689 function wp_explain_nonce( $action ) {
1690 if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
1691 $verb = $matches[1];
1692 $noun = $matches[2];
1695 $trans['update']['attachment'] = array( __( 'Your attempt to edit this attachment: "%s" has failed.' ), 'get_the_title' );
1697 $trans['add']['category'] = array( __( 'Your attempt to add this category has failed.' ), false );
1698 $trans['delete']['category'] = array( __( 'Your attempt to delete this category: "%s" has failed.' ), 'get_catname' );
1699 $trans['update']['category'] = array( __( 'Your attempt to edit this category: "%s" has failed.' ), 'get_catname' );
1701 $trans['delete']['comment'] = array( __( 'Your attempt to delete this comment: "%s" has failed.' ), 'use_id' );
1702 $trans['unapprove']['comment'] = array( __( 'Your attempt to unapprove this comment: "%s" has failed.' ), 'use_id' );
1703 $trans['approve']['comment'] = array( __( 'Your attempt to approve this comment: "%s" has failed.' ), 'use_id' );
1704 $trans['update']['comment'] = array( __( 'Your attempt to edit this comment: "%s" has failed.' ), 'use_id' );
1705 $trans['bulk']['comments'] = array( __( 'Your attempt to bulk modify comments has failed.' ), false );
1706 $trans['moderate']['comments'] = array( __( 'Your attempt to moderate comments has failed.' ), false );
1708 $trans['add']['bookmark'] = array( __( 'Your attempt to add this link has failed.' ), false );
1709 $trans['delete']['bookmark'] = array( __( 'Your attempt to delete this link: "%s" has failed.' ), 'use_id' );
1710 $trans['update']['bookmark'] = array( __( 'Your attempt to edit this link: "%s" has failed.' ), 'use_id' );
1711 $trans['bulk']['bookmarks'] = array( __( 'Your attempt to bulk modify links has failed.' ), false );
1713 $trans['add']['page'] = array( __( 'Your attempt to add this page has failed.' ), false );
1714 $trans['delete']['page'] = array( __( 'Your attempt to delete this page: "%s" has failed.' ), 'get_the_title' );
1715 $trans['update']['page'] = array( __( 'Your attempt to edit this page: "%s" has failed.' ), 'get_the_title' );
1717 $trans['edit']['plugin'] = array( __( 'Your attempt to edit this plugin file: "%s" has failed.' ), 'use_id' );
1718 $trans['activate']['plugin'] = array( __( 'Your attempt to activate this plugin: "%s" has failed.' ), 'use_id' );
1719 $trans['deactivate']['plugin'] = array( __( 'Your attempt to deactivate this plugin: "%s" has failed.' ), 'use_id' );
1720 $trans['upgrade']['plugin'] = array( __( 'Your attempt to upgrade this plugin: "%s" has failed.' ), 'use_id' );
1722 $trans['add']['post'] = array( __( 'Your attempt to add this post has failed.' ), false );
1723 $trans['delete']['post'] = array( __( 'Your attempt to delete this post: "%s" has failed.' ), 'get_the_title' );
1724 $trans['update']['post'] = array( __( 'Your attempt to edit this post: "%s" has failed.' ), 'get_the_title' );
1726 $trans['add']['user'] = array( __( 'Your attempt to add this user has failed.' ), false );
1727 $trans['delete']['users'] = array( __( 'Your attempt to delete users has failed.' ), false );
1728 $trans['bulk']['users'] = array( __( 'Your attempt to bulk modify users has failed.' ), false );
1729 $trans['update']['user'] = array( __( 'Your attempt to edit this user: "%s" has failed.' ), 'get_author_name' );
1730 $trans['update']['profile'] = array( __( 'Your attempt to modify the profile for: "%s" has failed.' ), 'get_author_name' );
1732 $trans['update']['options'] = array( __( 'Your attempt to edit your settings has failed.' ), false );
1733 $trans['update']['permalink'] = array( __( 'Your attempt to change your permalink structure to: %s has failed.' ), 'use_id' );
1734 $trans['edit']['file'] = array( __( 'Your attempt to edit this file: "%s" has failed.' ), 'use_id' );
1735 $trans['edit']['theme'] = array( __( 'Your attempt to edit this theme file: "%s" has failed.' ), 'use_id' );
1736 $trans['switch']['theme'] = array( __( 'Your attempt to switch to this theme: "%s" has failed.' ), 'use_id' );
1738 if ( isset( $trans[$verb][$noun] ) ) {
1739 if ( !empty( $trans[$verb][$noun][1] ) ) {
1740 $lookup = $trans[$verb][$noun][1];
1741 $object = $matches[4];
1742 if ( 'use_id' != $lookup )
1743 $object = call_user_func( $lookup, $object );
1744 return sprintf( $trans[$verb][$noun][0], wp_specialchars($object) );
1746 return $trans[$verb][$noun][0];
1751 return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
1755 function wp_nonce_ays( $action ) {
1756 $title = __( 'WordPress Failure Notice' );
1757 $html = wp_specialchars( wp_explain_nonce( $action ) ) . '</p>';
1758 if ( wp_get_referer() )
1759 $html .= "<p><a href='" . remove_query_arg( 'updated', clean_url( wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
1760 wp_die( $html, $title);
1764 function wp_die( $message, $title = '' ) {
1767 if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
1768 if ( empty( $title ) ) {
1769 $error_data = $message->get_error_data();
1770 if ( is_array( $error_data ) && isset( $error_data['title'] ) )
1771 $title = $error_data['title'];
1773 $errors = $message->get_error_messages();
1774 switch ( count( $errors ) ) :
1779 $message = "<p>{$errors[0]}</p>";
1782 $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
1785 } elseif ( is_string( $message ) ) {
1786 $message = "<p>$message</p>";
1789 if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL )
1790 $admin_dir = WP_SITEURL . '/wp-admin/';
1791 elseif ( function_exists( 'get_bloginfo' ) && '' != get_bloginfo( 'wpurl' ) )
1792 $admin_dir = get_bloginfo( 'wpurl' ) . '/wp-admin/';
1793 elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false )
1796 $admin_dir = 'wp-admin/';
1798 if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) :
1799 if( !headers_sent() ){
1800 status_header( 500 );
1802 header( 'Content-Type: text/html; charset=utf-8' );
1805 if ( empty($title) ) {
1806 if ( function_exists( '__' ) )
1807 $title = __( 'WordPress › Error' );
1809 $title = 'WordPress › Error';
1813 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1814 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
1816 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1817 <title><?php echo $title ?></title>
1818 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
1820 if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) : ?>
1821 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install-rtl.css" type="text/css" />
1824 <body id="error-page">
1826 <?php echo $message; ?>
1834 function _config_wp_home( $url = '' ) {
1835 if ( defined( 'WP_HOME' ) )
1841 function _config_wp_siteurl( $url = '' ) {
1842 if ( defined( 'WP_SITEURL' ) )
1848 function _mce_set_direction( $input ) {
1851 if ( 'rtl' == $wp_locale->text_direction ) {
1852 $input['directionality'] = 'rtl';
1853 $input['plugins'] .= ',directionality';
1854 $input['theme_advanced_buttons1'] .= ',ltr';
1861 function smilies_init() {
1862 global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
1864 // don't bother setting up smilies if they are disabled
1865 if ( !get_option( 'use_smilies' ) )
1868 if ( !isset( $wpsmiliestrans ) ) {
1869 $wpsmiliestrans = array(
1870 ':mrgreen:' => 'icon_mrgreen.gif',
1871 ':neutral:' => 'icon_neutral.gif',
1872 ':twisted:' => 'icon_twisted.gif',
1873 ':arrow:' => 'icon_arrow.gif',
1874 ':shock:' => 'icon_eek.gif',
1875 ':smile:' => 'icon_smile.gif',
1876 ':???:' => 'icon_confused.gif',
1877 ':cool:' => 'icon_cool.gif',
1878 ':evil:' => 'icon_evil.gif',
1879 ':grin:' => 'icon_biggrin.gif',
1880 ':idea:' => 'icon_idea.gif',
1881 ':oops:' => 'icon_redface.gif',
1882 ':razz:' => 'icon_razz.gif',
1883 ':roll:' => 'icon_rolleyes.gif',
1884 ':wink:' => 'icon_wink.gif',
1885 ':cry:' => 'icon_cry.gif',
1886 ':eek:' => 'icon_surprised.gif',
1887 ':lol:' => 'icon_lol.gif',
1888 ':mad:' => 'icon_mad.gif',
1889 ':sad:' => 'icon_sad.gif',
1890 '8-)' => 'icon_cool.gif',
1891 '8-O' => 'icon_eek.gif',
1892 ':-(' => 'icon_sad.gif',
1893 ':-)' => 'icon_smile.gif',
1894 ':-?' => 'icon_confused.gif',
1895 ':-D' => 'icon_biggrin.gif',
1896 ':-P' => 'icon_razz.gif',
1897 ':-o' => 'icon_surprised.gif',
1898 ':-x' => 'icon_mad.gif',
1899 ':-|' => 'icon_neutral.gif',
1900 ';-)' => 'icon_wink.gif',
1901 '8)' => 'icon_cool.gif',
1902 '8O' => 'icon_eek.gif',
1903 ':(' => 'icon_sad.gif',
1904 ':)' => 'icon_smile.gif',
1905 ':?' => 'icon_confused.gif',
1906 ':D' => 'icon_biggrin.gif',
1907 ':P' => 'icon_razz.gif',
1908 ':o' => 'icon_surprised.gif',
1909 ':x' => 'icon_mad.gif',
1910 ':|' => 'icon_neutral.gif',
1911 ';)' => 'icon_wink.gif',
1912 ':!:' => 'icon_exclaim.gif',
1913 ':?:' => 'icon_question.gif',
1917 $siteurl = get_option( 'siteurl' );
1918 foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
1919 $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
1920 $smiley_masked = attribute_escape( trim( $smiley ) );
1921 $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
1926 * Merge user defined arguments into defaults array.
1928 * This function is used throughout WordPress to allow for both string or array
1929 * to be merged into another array.
1933 * @param string|array $args Value to merge with $defaults
1934 * @param array $defaults Array that serves as the defaults.
1935 * @return array Merged user defined values with defaults.
1937 function wp_parse_args( $args, $defaults = '' ) {
1938 if ( is_object( $args ) )
1939 $r = get_object_vars( $args );
1940 elseif ( is_array( $args ) )
1943 wp_parse_str( $args, $r );
1945 if ( is_array( $defaults ) )
1946 return array_merge( $defaults, $r );
1951 * Determines if Widgets library should be loaded.
1953 * Checks to make sure that the widgets library hasn't already been loaded. If
1954 * it hasn't, then it will load the widgets library and run an action hook.
1957 * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
1959 function wp_maybe_load_widgets() {
1960 if ( !function_exists( 'dynamic_sidebar' ) ) {
1961 require_once( ABSPATH . WPINC . '/widgets.php' );
1962 add_action( '_admin_menu', 'wp_widgets_add_menu' );
1967 * Append the Widgets menu to the themes main menu.
1970 * @uses $submenu The administration submenu list.
1972 function wp_widgets_add_menu() {
1974 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
1975 ksort( $submenu['themes.php'], SORT_NUMERIC );
1979 * Flush all output buffers for PHP 5.2.
1981 * Make sure all output buffers are flushed before our singletons our destroyed.
1985 function wp_ob_end_flush_all() {
1986 while ( @ob_end_flush() );
1990 * Load the correct database class file.
1992 * This function is used to load the database class file either at runtime or by
1993 * wp-admin/setup-config.php We must globalise $wpdb to ensure that it is
1994 * defined globally by the inline code in wp-db.php.
1997 * @global $wpdb WordPress Database Object
1999 function require_wp_db() {
2001 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
2002 require_once( WP_CONTENT_DIR . '/db.php' );
2004 require_once( ABSPATH . WPINC . '/wp-db.php' );
2008 * Load custom DB error or display WordPress DB error.
2010 * If a file exists in the wp-content directory named db-error.php, then it will
2011 * be loaded instead of displaying the WordPress DB error. If it is not found,
2012 * then the WordPress DB error will be displayed instead.
2014 * The WordPress DB error sets the HTTP status header to 500 to try to prevent
2015 * search engines from caching the message. Custom DB messages should do the
2021 function dead_db() {
2024 // Load custom DB error template, if present.
2025 if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
2026 require_once( WP_CONTENT_DIR . '/db-error.php' );
2030 // If installing or in the admin, provide the verbose message.
2031 if ( defined('WP_INSTALLING') || defined('WP_ADMIN') )
2032 wp_die($wpdb->error);
2034 // Otherwise, be terse.
2035 status_header( 500 );
2037 header( 'Content-Type: text/html; charset=utf-8' );
2039 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2040 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
2042 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2043 <title>Database Error</title>
2047 <h1>Error establishing a database connection</h1>
2055 * Converts value to positive integer.
2059 * @param mixed $maybeint data you wish to have convered to an absolute integer
2060 * @return int an absolute integer
2062 function absint( $maybeint ) {
2063 return abs( intval( $maybeint ) );
2067 * Determines if the blog can be accessed over SSL.
2069 * Determines if blog can be accessed over SSL by using cURL to access the site
2070 * using the https in the siteurl. Requires cURL extension to work correctly.
2074 * @return bool Whether or not SSL access is available
2076 function url_is_accessable_via_ssl($url)
2078 if (in_array('curl', get_loaded_extensions())) {
2079 $ssl = preg_replace( '/^http:\/\//', 'https://', $url );
2082 curl_setopt($ch, CURLOPT_URL, $ssl);
2083 curl_setopt($ch, CURLOPT_FAILONERROR, true);
2084 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2085 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
2089 $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
2092 if ($status == 200 || $status == 401) {
2100 * Secure URL, if available or the given URL.
2104 * @param string $url Complete URL path with transport.
2105 * @return string Secure or regular URL path.
2107 function atom_service_url_filter($url)
2109 if ( url_is_accessable_via_ssl($url) )
2110 return preg_replace( '/^http:\/\//', 'https://', $url );
2116 * Marks a function as deprecated and informs when it has been used.
2118 * There is a hook deprecated_function_run that will be called that can be used
2119 * to get the backtrace up to what file and function called the deprecated
2122 * The current behavior is to trigger an user error if WP_DEBUG is defined and
2125 * This function is to be used in every function in depreceated.php
2127 * @package WordPress
2132 * @uses do_action() Calls 'deprecated_function_run' and passes the function name and what to use instead.
2133 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
2135 * @param string $function The function that was called
2136 * @param string $version The version of WordPress that depreceated the function
2137 * @param string $replacement Optional. The function that should have been called
2139 function _deprecated_function($function, $version, $replacement=null) {
2141 do_action('deprecated_function_run', $function, $replacement);
2143 // Allow plugin to filter the output error trigger
2144 if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_function_trigger_error', true )) {
2145 if( !is_null($replacement) )
2146 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
2148 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
2153 * Marks a file as deprecated and informs when it has been used.
2155 * There is a hook deprecated_file_included that will be called that can be used
2156 * to get the backtrace up to what file and function included the deprecated
2159 * The current behavior is to trigger an user error if WP_DEBUG is defined and
2162 * This function is to be used in every file that is depreceated
2164 * @package WordPress
2169 * @uses do_action() Calls 'deprecated_file_included' and passes the file name and what to use instead.
2170 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
2172 * @param string $file The file that was included
2173 * @param string $version The version of WordPress that depreceated the function
2174 * @param string $replacement Optional. The function that should have been called
2176 function _deprecated_file($file, $version, $replacement=null) {
2178 do_action('deprecated_file_included', $file, $replacement);
2180 // Allow plugin to filter the output error trigger
2181 if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_file_trigger_error', true )) {
2182 if( !is_null($replacement) )
2183 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) );
2185 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) );
2190 * Is the server running earlier than 1.5.0 version of lighttpd
2194 * @return bool Whether the server is running lighttpd < 1.5.0
2196 function is_lighttpd_before_150() {
2197 $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' );
2198 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : '';
2199 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
2203 * Does the specified module exist in the apache config?
2207 * @param string $mod e.g. mod_rewrite
2208 * @param bool $default The default return value if the module is not found
2211 function apache_mod_loaded($mod, $default = false) {
2217 if ( function_exists('apache_get_modules') ) {
2218 $mods = apache_get_modules();
2219 if ( in_array($mod, $mods) )
2221 } elseif ( function_exists('phpinfo') ) {
2224 $phpinfo = ob_get_clean();
2225 if ( false !== strpos($phpinfo, $mod) )
2232 * File validates against allowed set of defined rules.
2234 * A return value of '1' means that the $file contains either '..' or './'. A
2235 * return value of '2' means that the $file contains ':' after the first
2236 * character. A return value of '3' means that the file is not in the allowed
2241 * @param string $file File path.
2242 * @param array $allowed_files List of allowed files.
2243 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
2245 function validate_file( $file, $allowed_files = '' ) {
2246 if ( false !== strpos( $file, '..' ))
2249 if ( false !== strpos( $file, './' ))
2252 if (':' == substr( $file, 1, 1 ))
2255 if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
2262 * Determine if SSL is used.
2266 * @return bool True if SSL, false if not used.
2269 return ( isset($_SERVER['HTTPS']) && 'on' == strtolower($_SERVER['HTTPS']) ) ? true : false;
2273 * Whether SSL login should be forced.
2277 * @param string|bool $force Optional.
2278 * @return bool True if forced, false if not forced.
2280 function force_ssl_login($force = '') {
2283 if ( '' != $force ) {
2284 $old_forced = $forced;
2293 * Whether to force SSL used for the Administration Panels.
2297 * @param string|bool $force
2298 * @return bool True if forced, false if not forced.
2300 function force_ssl_admin($force = '') {
2303 if ( '' != $force ) {
2304 $old_forced = $forced;
2313 * Guess the URL for the site.
2315 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
2322 function wp_guess_url() {
2323 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
2326 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
2327 $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);