get_block_bindings_source()


WordPressのget_block_bindings_source()関数は、ブロックバインディングのソースを取得するために使用されます。この関数は、特定のバインディングソースを取得するために利用されます。

構文

get_block_bindings_source( string $source_name );
  • $source_name(string) — 取得するバインディングソースの名前を指定します。

例1: 基本的な使用例

この例では、特定のバインディングソースを取得します。

$source = get_block_bindings_source( 'core/post-featured-image' );

例2: バインディングソースの存在確認

この例では、バインディングソースが存在するかどうかを確認します。

if ( get_block_bindings_source( 'core/post-title' ) ) { echo 'ソースが存在します'; }

例3: カスタムバインディングソースの取得

カスタムバインディングソースを取得する例です。

$custom_source = get_block_bindings_source( 'my-plugin/custom-source' );

例4: バインディングソースのプロパティを表示

取得したバインディングソースのプロパティを表示します。

$source = get_block_bindings_source( 'core/post-content' ); print_r( $source );

例5: バインディングソースを使用してデータを取得

バインディングソースを使用してデータを取得する例です。

$source = get_block_bindings_source( 'core/post-excerpt' ); echo $source->get_data();

例6: バインディングソースの登録

新しいバインディングソースを登録する例です。

register_block_bindings_source( 'my-plugin/custom-source', array( 'label' => 'Custom Source' ) );

例7: バインディングソースの削除

登録されたバインディングソースを削除する例です。

unregister_block_bindings_source( 'my-plugin/custom-source' );

例8: バインディングソースの一覧を取得

登録されているすべてのバインディングソースを取得します。

$sources = get_all_registered_block_bindings_sources(); print_r( $sources );

注意点

  • バインディングソースが存在しない場合、get_block_bindings_source()nullを返します。
  • カスタムバインディングソースを使用する場合は、事前に登録が必要です。

関連機能: