WordPress 4.7 Beta

WordPress 4.7 Beta 1がダウンロード可能になりました。
https://wordpress.org/news/2016/10/wordpress-4-7-beta-1/
まだベータ版で、テスターを募集しています。

そして、Beta 2, Beat 3, Beat 3もダウンロード可能になりました。 
https://wordpress.org/news/2016/11/wordpress-4-7-beta-2/

https://wordpress.org/news/2016/11/wordpress-4-7-beta-3/

https://wordpress.org/news/2016/11/wordpress-4-7-beta-4/
※Beta4では機能的な大きな変更はない様子です。

4.7は2016/12/6にリリース予定です。


2016/11/05 追記
2016/11/11 追記
2016/11/05 追記
2016/11/15 追記
2016/11/16 追記
2016/11/17 追記
ちょっと長くなってきたので記事を分けた方がいいかもしれません・・・

たくさんのバグフィックス以外に細かい新機能が追加されます。

新機能

  • 新しいデフォルトテーマ”Twenty Seventeen”
  • ビデオ動画をヘッダに使えるVideo Headers。Twenty Seventeenで試せます。
  • Set up your site in one flow
  • Custom CSS with live previews
  • User admin languages
  • PDF thumbnail previews
  • REST API content endpoints
  • WP_Hook
  • Custom bulk actions
  • Expanded Settings Registration API via register_setting().
  • For theme developers: Post type templates
  • More goodies for theme developers!
  • Locale switching
  • Comment allowed checks
  • Edit shortcuts
  • REST API endpoints
    • The DELETE response format has changed and may need to be accounted for.
    • Enabled querying by multiple post statuses.
    • Return an error when JSON decoding fails.
  • More developer notes
    • Fine grained capabilities for taxonomy terms
    • WP_Taxonomy
    • wp_list_sort() and WP_List_Util
    • Post type templates
    • New post type labels
    • Attributes for resource hints
  • REST API:The unfiltered_html capability is now respected and rest_base has been added to response objects of wp/v2/taxonomies and wp/v2/types, while get_allowed_query_vars() and the rest_get_post filter have been removed.
  • Attributes for resource hints
  • Roles/Capabilities:Added meta-caps for comment, term, and user meta, which are currently only used in the REST API.
  • I18N:Added the ability to change user’s locale back to site’s locale.
  • Custom CSS:Renamed the unfiltered_css meta capability to edit_css and added revisions support to the custom_css post type.
  • Edit shortcuts:Theme authors should take a look at the developer guide to the customizer preview’s visible edit shortcuts and update their themes to take advantage of them if not already implementing selective refresh.

なんだか、興味深い新機能がいろいろ追加されるようです。

興味をそそりそうなものを太字にしてみました。

ビデオ動画をヘッダに使えるVideo Headers

最近よくみかけるのですが、トップページに動画を表示する機能が新しいデフォルトテーマである「Twenty Seventeen」で実装されています。
設定の仕方は非常に簡単です。
カスタマイザーで「Header Media」を選択します。

4-7_twenty_seventeen_customizer1

そして表示されたヘッダのカスタマイズ画面で、
「Or, enter a YouTube URL:」
と表示されているテキストボックスにYoutubeのURLを入れるだけです。
ここでは、飼っていた猫の動画を入れています。
入力してフォーカスアウトすると、プレビューに反映されて動画が再生されます。

4-7_twenty_seventeen_customizer2

そして表画面では、当たり前ですがそのまま表示され、再生されます。

4-7_twenty_seventeen_dispmovie

動画をクリックすることで停止/再生することもできますが、停止させたくない場合は動画の埋め込み方に工夫が必要なのかもしれません。
また、Twenty SeventeenではYoutubeのURLを入れる欄しかなく、Youtube APIを使ってiframeで埋め込まれています。
これはこれで非常に手軽で、取り入れやすいですね。

その他のテーマであっても、テーマサポートのカスタムヘッダに追加することで、Video Headerを設定することができます。

add_theme_support( 'custom-header', array('video' => true));

下記の例はTwenty Tenです。

(カスタムヘッダ追加前)
before_custom_header

(カスタムヘッダ追加後)
after_custom_header

カスタマイザーで「ヘッダー画像」となっていたものが「ヘッダーメディア」に変わりました。

YoutubeのURLを設定しましたが、表画面はまだ何もしていないのでプレビューでは何の変化もありません。

twentyten_custom_header

ですので、ヘッダ画像を出力している箇所に

the_custom_header_markup();

を追加します。

Twenty Tenのheader.phpに追加してみたのがこちらのコード。
83行目あたりです。
分かりやすいように、インデントを無視して行頭から追記しています。

					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
if ( has_custom_header() ){
	the_custom_header_markup();
} else {
					if ( is_singular() && current_theme_supports( 'post-thumbnails' ) &&
							has_post_thumbnail( $post->ID ) &&
							( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
							$image[1] >= $header_image_width ) :
						// Houston, we have a new header image!
						echo get_the_post_thumbnail( $post->ID );
					elseif ( get_header_image() ) :
						// Compatibility with versions of WordPress prior to 3.4.
						if ( function_exists( 'get_custom_header' ) ) {
							$header_image_width  = get_custom_header()->width;
							$header_image_height = get_custom_header()->height;
						} else {
							$header_image_width  = HEADER_IMAGE_WIDTH;
							$header_image_height = HEADER_IMAGE_HEIGHT;
						}
					?>
						
					

ちょっと縦横比があってないので左右に黒い帯が出ていますが、反映されました。

twentyten_custom_header_after

if ( has_custom_header() ){

という分岐が正しいのかどうかちょっと自信がありませんが、YoutubeのURLを削除するとヘッダ画像が表示さるという、意図通りの動作はしています。

[adsense]

REST API content endpoints

今まではプラグインとして追加する必要のあったREST API V2が、標準機能として組み込まれます
では、V1との違いは何なのか・・・という前にWordPressのREST APIを使ったことがないのだった。

例えば、WordPressのURL末尾に以下の記述をくっつけるだけで、REST APIを使えます。
/wp-json/wp/v2/posts

このサイトであれば、
https://munyagu.com/wp-json/wp/v2/posts
いや、このサイトはまだ4.6.1(2016/11/11現在)なので、なんだか変なエラーが出るだけなんですけど、4.7のサイトではつらつらと投稿のリストがjson形式なんで、よく分からないけど表示されます。

V2ではstandards-driven interfaceということなので、APIは結構変更になっている様子です。

4.7で取得できたjsonがこちら。
こちらって見たからといって何もないですが。
rest-v2-json
これをJavaScriptで受け取ってエンコードすれば投稿オブジェクトのように取り扱えるわけです。

WP_Hook

WP_Hookクラスが追加されています。
何か、作成しているプラグインに影響があるかもしれません。
以下のURLに、影響があるケースが記載されています。

Case 1: コールバックを直接$wp_filterグローバル変数にセットしている

少なくとも私はそんなことはしていません。
$wp_filterグローバル変数の存在も今知りました。

Case 2: コールバックを除去する場合、$wp_filterグローバル変数から削除している

上に同じです。

Case 3: フックが配列かどうかをチェックしている

フックが追加されているかどうかのチェックですが、これも$wp_filterグローバル変数へのアクセスです。
例ではだめな例として

if ( isset( $wp_filter['save_post'] ) && is_array( $wp_filter['save_post'] ) ) {
    // do something
}

と書かれています。
正しく動作させるためには

if ( has_action( 'save_post' ) ) {
    // do something
}

です。

Case 4: $wp_filterグローバル変数のポインタを操作している

ちょっと飽きてきましたが、これも$wp_filter関連です。
phpには配列を操作する関数として、nextprevがありますが、これらを使ってコールバックの実行順序を制御しようとしても失敗する、ということのようです。

その他のケース

上記以外のケースでは、$wp_filterグローバル変数はこれまでどおり動作するようです。
推奨はされませんが、コールバックを反復処理したり実行順位を取得できるように、WP_HookクラスはArrayAccessインターフェイスやIteratorAggregateインターフェイスを実装しているので、そのメソッドを使うのがいいとのことです。
そんなことをしようと思ったことがないので、使うことになったら詳細を調べてみます。

要するに、$wp_filterを使うのはやめた方がいいということですね。
ちょっと緊張したのに、私にのプラグインには全く影響がないじゃないか。
他の影響があるかもしれないので、テストはしないといけませんけどね。

Custom bulk actions

調査中です。