WordPressを読む 10-1 /blog/wp-includes/functions.php 1 完了
2014/11/29
目次
/blog/wp-includes/functions.php 1
読込元 : /blog/wp-settings.php
読込元 : /blog/wp-load.php
4630行あります。
長すぎるので分割しました。(WordPress4.01)
1-24まであります。
1 2 3 4 5 6 7 8 | <?php /** * Main WordPress API * * @package WordPress */ require( ABSPATH . WPINC . '/option.php' ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /** * Convert given date string into a different format. * * $format should be either a PHP date format string, e.g. 'U' for a Unix * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. * * If $translate is true then the given date and format string will * be passed to date_i18n() for translation. * * @since 0.71 * * @param string $format Format of the date to return. * @param string $date Date string to convert. * @param bool $translate Whether the return date should be translated. Default true. * @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty. */ function mysql2date( $format, $date, $translate = true ) { if ( empty( $date ) ) return false; if ( 'G' == $format ) return strtotime( $date . ' +0000' ); $i = strtotime( $date ); if ( 'U' == $format ) return $i; if ( $translate ) return date_i18n( $format, $i ); else return date( $format, $i ); } |
mysql2date()
mysql書式の日付をPHPのdate()関数が受け付ける書式に変換します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** * Retrieve the current time based on specified type. * * The 'mysql' type will return the time in the format for MySQL DATETIME field. * The 'timestamp' type will return the current timestamp. * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d'). * * If $gmt is set to either '1' or 'true', then both types will use GMT time. * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option. * * @since 1.0.0 * * @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date * format string (e.g. 'Y-m-d'). * @param int|bool $gmt Optional. Whether to use GMT timezone. Default false. * @return int|string Integer if $type is 'timestamp', string otherwise. */ function current_time( $type, $gmt = 0 ) { switch ( $type ) { case 'mysql': return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); case 'timestamp': return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); default: return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); } } |
current_time()
現在の日時を取得する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | /** * Retrieve the date in localized format, based on timestamp. * * If the locale specifies the locale month and weekday, then the locale will * take over the format for the date. If it isn't, then the date format string * will be used instead. * * @since 0.71 * * @param string $dateformatstring Format to display the date. * @param bool|int $unixtimestamp Optional. Unix timestamp. Default false. * @param bool $gmt Optional. Whether to use GMT timezone. Default false. * * @return string The date, translated if locale specifies it. */ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { global $wp_locale; $i = $unixtimestamp; if ( false === $i ) { if ( ! $gmt ) $i = current_time( 'timestamp' ); else $i = time(); // we should not let date() interfere with our // specially computed timestamp $gmt = true; } /* * Store original value for language with untypical grammars. * See http://core.trac.wordpress.org/ticket/9396 */ $req_format = $dateformatstring; $datefunc = $gmt? 'gmdate' : 'date'; if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) { $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) ); $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) ); $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday ); $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) ); $datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) ); $dateformatstring = ' '.$dateformatstring; $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); } $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); $timezone_formats_re = implode( '|', $timezone_formats ); if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { $timezone_string = get_option( 'timezone_string' ); if ( $timezone_string ) { $timezone_object = timezone_open( $timezone_string ); $date_object = date_create( null, $timezone_object ); foreach( $timezone_formats as $timezone_format ) { if ( false !== strpos( $dateformatstring, $timezone_format ) ) { $formatted = date_format( $date_object, $timezone_format ); $dateformatstring = ' '.$dateformatstring; $dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring ); $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); } } } } $j = @$datefunc( $dateformatstring, $i ); /** * Filter the date formatted based on the locale. * * @since 2.8.0 * * @param string $j Formatted date string. * @param string $req_format Format to display the date. * @param int $i Unix timestamp. * @param bool $gmt Whether to convert to GMT for time. Default false. */ $j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt ); return $j; } |
date_i18n()
日付/時刻を書式化した文字列を取得する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Convert integer number to format based on the locale. * * @since 2.3.0 * * @param int $number The number to convert based on locale. * @param int $decimals Optional. Precision of the number of decimal places. Default 0. * @return string Converted number in string format. */ function number_format_i18n( $number, $decimals = 0 ) { global $wp_locale; $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); /** * Filter the number formatted based on the locale. * * @since 2.8.0 * * @param string $formatted Converted number in string format. */ return apply_filters( 'number_format_i18n', $formatted ); } |
number_format_i18n()
数値を1000位毎にグループ化して国際化対応にフォーマットする
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /** * Convert number of bytes largest unit bytes will fit into. * * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts * number of bytes to human readable number by taking the number of that unit * that the bytes will go into it. Supports TB value. * * Please note that integers in PHP are limited to 32 bits, unless they are on * 64 bit architecture, then they have 64 bit size. If you need to place the * larger size then what PHP integer type will hold, then use a string. It will * be converted to a double, which should always have 64 bit length. * * Technically the correct unit names for powers of 1024 are KiB, MiB etc. * * @since 2.3.0 * * @param int|string $bytes Number of bytes. Note max integer size for integers. * @param int $decimals Optional. Precision of number of decimal places. Default 0. * @return bool|string False on failure. Number string on success. */ function size_format( $bytes, $decimals = 0 ) { $quant = array( // ========================= 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 ) if ( doubleval($bytes) >= $mag ) return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; return false; } |
size_format()
数値を1000桁毎(1024)にグループ化してサイズフォーマットする