get_block_editor_settings()


WordPressのget_block_editor_settings()関数は、ブロックエディターの設定を取得するために使用されます。この関数は、エディターの設定をカスタマイズする際に役立ちます。

構文

get_block_editor_settings( array $custom_settings, WP_Block_Editor_Context $context );

引数の説明:

  • $custom_settings (array) — カスタム設定を追加するための配列。
  • $context (WP_Block_Editor_Context) — ブロックエディターのコンテキストを指定するオブジェクト。

例1: 基本的な設定の取得

ブロックエディターのデフォルト設定を取得します。

$settings = get_block_editor_settings( array(), new WP_Block_Editor_Context() );

例2: カスタム設定の追加

ブロックエディターにカスタム設定を追加します。

$custom_settings = array( 'customOption' => true ); $settings = get_block_editor_settings( $custom_settings, new WP_Block_Editor_Context() );

例3: 特定の投稿タイプの設定を取得

特定の投稿タイプのブロックエディター設定を取得します。

$context = new WP_Block_Editor_Context( array( 'post' => get_post( get_the_ID() ) ) ); $settings = get_block_editor_settings( array(), $context );

例4: カスタムブロックスタイルの追加

ブロックエディターにカスタムスタイルを追加します。

$custom_settings = array( 'styles' => array( array( 'css' => '.custom-class { color: red; }' ) ) ); $settings = get_block_editor_settings( $custom_settings, new WP_Block_Editor_Context() );

例5: ブロックエディターのサポート機能を無効化

ブロックエディターの特定の機能を無効にします。

$custom_settings = array( 'supports' => array( 'align' => false ) ); $settings = get_block_editor_settings( $custom_settings, new WP_Block_Editor_Context() );

例6: カスタムブロックパターンの追加

ブロックエディターにカスタムパターンを追加します。

$custom_settings = array( 'patterns' => array( array( 'title' => 'Custom Pattern', 'content' => '<!-- wp:paragraph --><p>Custom content</p><!-- /wp:paragraph -->' ) ) ); $settings = get_block_editor_settings( $custom_settings, new WP_Block_Editor_Context() );

例7: ブロックエディターのカラーパレットをカスタマイズ

ブロックエディターのカラーパレットを変更します。

$custom_settings = array( 'colors' => array( array( 'name' => 'Red', 'slug' => 'red', 'color' => '#ff0000' ) ) ); $settings = get_block_editor_settings( $custom_settings, new WP_Block_Editor_Context() );

注意点

  • カスタム設定を追加する際は、既存の設定を上書きしないように注意してください。
  • コンテキストを正しく指定しないと、意図しない設定が適用される可能性があります。

関連機能: