関数 wp_load_translations_early()
2014/11/22
高速翻訳を実行する関数の定義・・・翻訳ファイル 辞書関数
定義ファイル :/blog/wp-includes/load.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 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 | function wp_load_translations_early() { global $text_direction, $wp_locale; static $loaded = false; if ( $loaded ) return; $loaded = true; if ( function_exists( 'did_action' ) && did_action( 'init' ) ) return; // We need $wp_local_package require ABSPATH . WPINC . '/version.php'; // Translation and localization require_once ABSPATH . WPINC . '/pomo/mo.php'; require_once ABSPATH . WPINC . '/l10n.php'; require_once ABSPATH . WPINC . '/locale.php'; // General libraries require_once ABSPATH . WPINC . '/plugin.php'; $locales = $locations = array(); while ( true ) { if ( defined( 'WPLANG' ) ) { if ( '' == WPLANG ) break; $locales[] = WPLANG; } if ( isset( $wp_local_package ) ) $locales[] = $wp_local_package; if ( ! $locales ) break; if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) $locations[] = WP_LANG_DIR; if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) $locations[] = WP_CONTENT_DIR . '/languages'; if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) $locations[] = ABSPATH . 'wp-content/languages'; if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) $locations[] = ABSPATH . WPINC . '/languages'; if ( ! $locations ) break; $locations = array_unique( $locations ); foreach ( $locales as $locale ) { foreach ( $locations as $location ) { if ( file_exists( $location . '/' . $locale . '.mo' ) ) { load_textdomain( 'default', $location . '/' . $locale . '.mo' ); if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); break 2; } } } break; } $wp_locale = new WP_Locale(); } |
この関数は動きません。
1 2 3 | static $loaded = false; if ( $loaded ) return; |
必ずfalseになり、return します。
将来の為の実装なのかもしれません。
静的宣言 $loaded=false;
if ($loaded) は false なので成立しません。
ゆえに、if文を抜けて
$loaded=true;
となります。
以下関数を実行します。
2回目以降
$loaded=true;
なので、returnとなります。
以下のようなテストをしました。
1 2 3 4 5 6 7 8 9 10 | <?php function test() { static $loaded = false; if ($loaded){ return; } $loaded = true; print($loaded.'<hr>'); } ?> |
1 2 3 4 5 6 7 8 9 | <?php require('2.php'); print('1回目<br>'); test(); print('2回目<br>'); test(); print('3回目<br>'); test(); ?> |
実行結果は
となりました。
1回目のみif文以降を実行し2回目以降はreturnします。
このようなPGは初めて見ました。
まだまだ勉強が足りません。