WordPressの処理の流れ
だいたいこんな感じ。
- □ index.php
ユーザがアクセスするファイル - wp-blog-header.php を読み込む↓
- □ wp-blog-header.php
WP環境とテンプレートをロードする為のファイル - wp_load.php を読み込む↓
- □ wp_load.php
Bootstrap用file - wp_config.php を読み込む↓
- □ wp_config.php
ブログ毎のユニークな設定ファイル - MySQL の設定
- Unique Key と Salt の設定
- 言語設定(WP_LANG)
- デバッグモード設定( WP_DEBUG)
- wp-settings.php を読み込む↓
- □ wp-settings.php
WordPressで必要な定数/グローバル変数/関数/クラスの設定を行う -
【WordPressのコアの初期化】
▼コア部分で利用する定数/変数/関数の初期化
- 初期化に必要なファイルの読み込み
- 定数の初期化(wp_initial_constants())
▼事前処理
- PHPとMySQLのバージョンをチェック(wp_check_php_mysql_versions())
- マジッククオートをOFFに
- タイムゾーンをUTCに設定
- register globalsをOFFに
- $_SERVER 変数のサーバ環境によって発生する差異を修正(wp_fix_server_vars())
- IISとか、GGIモードで動かした場合とか
- ファビコンとしてリクエストされた場合の処理(wp_fabicon_request())
- メンテナンスモードかチェック(wp_maintenance())
- タイマーをセット(timer_start())
- デバッグモードかチェック(wp_debug_mode())
- キャッシュの処理(キャッシュが有効の場合は advanced-cashe.phpを読み込み)
- WP_LANG_DIRの設定(wp_set_lang_dir())
- コア部分で必要なファイルを読み込み
▼DB関連の初期化
- wpdbクラスを読み込む(require_wp_db())
- データベースの接続及び処理を担当する wpdb クラスを読み込む
- wpdbクラス内部dでは、MySQL 関数を利用している模様
- データベースのプレフィックスと、フィールドの型を設定(wp_set_wpdb_vars())
- オブジェクトキャッシュ処理(wp_start_object_cache())(デフォルトではOFF)
▼コアの初期化残処理
- フィルター/アクション/フックおよび多言語化対応の初期化
- マルチサイトの初期化(デフォルトではOFF)
- SHOTINIT定数がtrueであれば以上で初期化終了 [デフォルトはfalse]
以上で最低限必要な初期化処理完了
【WordPressの初期化】
▼多言語対応/インストール/関数等の初期化
- 多言語処理用ファイルの読み込み(l10n.php)
- インストールされていなかったらインストーラーを起動(wp_not_installed())
- 残りの必要なファイル群を読み込み
- class-wp-walker.php
- class-wp-ajax-response.php
- formatting.php
- capabilities.php
- query.php
- theme.php
- user.php
- meta.php
- general-template.php
- link-template.php
- author-template.php
- post.php
- post-template.php
- category.php
- category-template.php
- comment.php
- comment-template.php
- rewrite.php
- feed.php
- bookmark.php
- bookmark-template.php
- kses.php
- cron.php
- deprecated.php
- script-loader.php
- taxonomy.php
- update.php
- canonical.php
- shortcodes.php
- media.php
- http.php
- class-http.php
- widgets.php
- nav-menu.php
- nav-menu-template.php
- admin-bar.php
- class-wp-walker.php
▼マルチサイトとプラグインの初期化
- マルチサイトで必要なファイルの読み込み
- プラグインディレクトリ定数の設定(wp_plugin_directory_constants())
- ”muplugins_loaded”アクションを実行(do_action( 'muplugins_loaded' ))
▼プラグインの読み込み
- クッキーの設定(wp_cookie_constants())
- SSLの設定(wp_ssl_constants())
- 共用グローバル変数の定義(vars.php)
- タクソノミーとポストタイプの初期化(create_initial_taxonomies(); create_initial_post_types();)
- テーマディレクトリの登録
- アクティブなプラグインを読み込み
- pluggable な関数を読み込み(pluggable.php, pluggable-deprecated.php)
- 内部エンコーディング設定(wp_set_internal_encoding())
- キャッシュが有効であればキャッシュの事後読み込み(wp_cache_postload())
- ”plugins_loaded”アクション実行(do_action( 'plugins_loaded' ))
▼サニタイズ処理
- wp_functionality_constants()
- マジッククオートと$_REQUESTの設定(wp_magic_quotes())
- ”sanitize_comment_cookies”アクション実行(do_action( 'sanitize_comment_cookies' ))
▼WP_Query / WP_Rewrite / WP / WP_Widget の初期化
- WordPress Query Object の作成($wp_the_query = new WP_Query())
- WP_Rewriteオブジェクトの作成($wp_rewrite = new WP_Rewrite())
- WordPressオブジェクトの作成($wp = new WP())
- WidgetFactoryオブジェクトの作成($wp_widget_factory = new WP_Widget_Factory())
▼テーマの初期化
- ”setup_theme”アクション実行(do_action( 'setup_themes' ))
- テンプレート用定数の設定(wp_templating_constants())
- load_default_textdomain()
- Find the blog locale
- テーマ用関数の読み込み(STYLESHEETPATH . '/functions.php', TEMPLATEPATH . '/function.php')
- ”after_setup_theme”アクション実行(do_action( 'after_setup_theme' ))
- Load any template functions the theme supports
▼WPの初期化
- register_shutdown_function( 'shutdown_action_hook' );
- 現在アクセスしているユーザー用にWPをセットアップ($wp->init())
- ”init”アクションを実行(do_action( 'init' ))
- check site status (is_multisit())
- ”wp_loaded”アクションを実行(do_action( 'wp_loaded' ))
- 初期化に必要なファイルの読み込み
- □ wp-settings.php
- □ wp_config.php
- wp-config.phpがない場合は、最低限の環境を読み込み、wp-config.phpを作成するようにメッセージを表示する。
- wp_config.php を読み込む↓
- □ wp_load.php
- wp() 関数を実行(クエリーが処理される)
- template-loader.php を読み込む↓
- wp_load.php を読み込む↓
- □ wp-blog-header.php
- wp-blog-header.php を読み込む↓
blogに書こうかなと思っているもの
JavaScriptで多重継承もどき
コンストラクタ関数内で継承したいクラスのコンストラクタ関数を下記のように実行すると"多重継承のようなもの"ができるようです。
参考 : No Multiple Inheritance - MDC
//継承元1 function SuperClass1(prop1) { this.prop1 = prop1; }; //継承元2 function SuperClass2(prop2) { this.prop2 = prop2; }; //子クラス function SubClass(prop1, prop2, prop3) { //多重継承 this.superClass1 = SuperClass1; this.superClass1(prop1); this.superClass2 = SuperClass2; this.superClass2(prop2); this.prop3 = prop3; }; var subClass = new SubClass("a", "b", "c"); console.log( subClass.prop1 ); // a console.log( subClass.prop2 ); // b console.log( subClass.prop3 ); // c
通常の継承
// 親クラスコンストラクタ /** * 商品オブジェクトを作成 * @param {string} name 商品名 * @param {number} price 値段 * @constructor */ function Product(name,price) { this.name = name || "無題"; this.price = price || 0; }; /** * 名前を表示 */ Product.prototype.displayName = function() { alert(this.name); }; //子クラスコンストラクタ /** * 本オブジェクトを作成 * @param {string} name 商品名 * @param {number} price 値段 * @param {string} author 著者名 * @constructor * @extends {Product} */ function Book(name, price, author) { //親クラスのコンストラクタを実行 this.constructor(name, price); this.author = author; }; //Productクラスを継承 Book.prototype = new Product; /** * 名前を表示する * @override */ Book.prototype.displayName = function() { console.log(this.name); //オーバーライド元のメソッドを呼び出す方法1 this.superDisplayName= Product.prototype.displayName; this.superDisplayName(); //オーバーライド元のメソッドを呼び出す方法2 Product.prototype.displayName.apply(this, []); }; var book1 = new Book("我が輩は猫である", 800, "夏目漱石"); book1.displayName();
多重継承もどき(インターフェースもどき)
//親クラスコンストラクタ /** * 商品オブジェクトを作成 * @param {string} name 商品名 * @param {number} price 値段 * @constructor */ function Product(name,price) { this.name = name || "無題"; this.price = price || 0; }; /** * 名前を表示 */ Product.prototype.displayName = function() { alert(this.name); }; //インターフェースコンストラクタ /** * @interface */ function IMedia(mediaType) { this.mediaType = mediaType; }; /** * メディアタイプを返す * @return {string} */ IMedia.prototype.getMediaType = function() {}; //子クラスコンストラクタ /** * 書籍オブジェクトを作成 * @param {string} name 商品名 * @param {number} price 値段 * @param {string} author 著者名 * @constructor * @extends {Product} * @implements {IMedia} */ function Book(name, price, author) { //親クラスのコンストラクタを実行 this.constructor(name, price); //IMediaを多重継承 this.media = IMedia; this.media("paper"); this.author = author; }; //Productクラスを継承 Book.prototype = new Product; /** * 名前を表示する * @override */ Book.prototype.displayName = function() { console.log(this.name); //オーバーライド元のメソッドを呼び出す方法1 this.superDisplayName= Product.prototype.displayName; this.superDisplayName(); //オーバーライド元のメソッドを呼び出す方法2 Product.prototype.displayName.apply(this, []); }; //メソッドは継承されないので子クラスで実装 /** * メディアタイプを返す * @return {string} */ Book.prototype.getMediaType = function() { return this.mediaType; }; var book1 = new Book("我が輩は猫である", 800, "夏目漱石"); book1.displayName(); console.log( book1.getMediaType() );
WordPress 3.0 で、カスタムテンプレートプラグインを使っているとカスタム投稿タイプで画像が挿入できなくなる
custom-field-template.php の下記の箇所を書き換えると直る。
/* オリジナル */ /* function media_send_to_custom_field($html) { $options = $this->get_custom_field_template_data(); $out = '<script type="text/javascript">' . "\n" . ' // <![CDATA[' . "\n" . ' var win = window.dialogArguments || opener || parent || top;' . "\n" . ' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" . '// ]]>' . "\n" . '</script>' . "\n"; echo $out; if ($options['custom_field_template_use_multiple_insert']) { return; } else { exit(); } } */ /* 修正済み */ function media_send_to_custom_field($html) { $options = $this->get_custom_field_template_data(); $out = '<script type="text/javascript">' . "\n" . ' /* <![CDATA[ */' . "\n" . ' var win = window.dialogArguments || opener || parent || top;' . "\n" . //' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" . ' if(typeof win.send_to_custom_field == "function") {' . "\n" . ' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" . ' } else {' . "\n" . ' win.send_to_editor("' . addslashes($html) . '");' . "\n" . ' }' . "\n" . '/* ]]> */' . "\n" . '</script>' . "\n"; echo $out; if ($options['custom_field_template_use_multiple_insert']) { return; } else { exit(); } }
via http://wordpress.org/support/topic/317991/page/2?replies=56
SVGが利用可能かどうかJavaScriptで調べる方法
Modernizr 1.5 より抜粋
return !!document.createElementNS && !!document.createElementNS( "http://www.w3.org/2000/svg", "svg").createSVGRect;