Skip to content

Live previews don't work for oEmbed fields within a repeatable group #1157

@johnbillion

Description

@johnbillion

Expected Behavior:

When an oembed field type is present within a repeatable group, it should function as normal.

Actual Behavior:

The live Ajax-powered embed preview does not function, because the call to cmb2_ajax() never triggers, and thus its Ajax handlers are never registered. Ref:

CMB2/includes/CMB2.php

Lines 1444 to 1449 in 393388b

case 'oembed':
// Initiate oembed Ajax hooks.
cmb2_ajax();
break;

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

  1. Register a repeatable group and place an oembed field type in it.
  2. Paste an embed URL into the oEmbed URL input field.
  3. Observe that the live preview doesn't function. The Ajax call responds with 0 because there's no registered Ajax handler for the oEmbed preview.

CMB2 Field Registration Code:

add_action( 'cmb2_init', function() {
	// Meta box
	$cmb_main_box = new_cmb2_box( [
		'id'           => 'main_box',
		'title'        => 'Main Content',
		'object_types' => [
			'post',
		],
	] );

	// Repeatable embed group
	$cmb_embed_group = $cmb_main_box->add_field( [
		'id'         => 'embeds',
		'repeatable' => true,
		'type'       => 'group',
	] );

	// Repeatable field: embed
	$cmb_main_box->add_group_field( $cmb_embed_group, [
		'id'      => 'url',
		'name'    => 'Embed URL',
		'type'    => 'oembed',
	] );
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions