Unable to override editor default block template for wp_insert_post()
-
Hello, I’m trying to override the default blocks created when using
wp_insert_post()
.To do this I’ve tested on 2 different filter hooks in my custom plugin. My debug logs show that the function is called & the template is being updated. (
tribe_events_editor_default_template
&tribe_events_editor_default_classic_template
) It works fine when using the default “Add New” link.However, I am still seeing the blocks created on my new Event & looking through the plugin code I cannot figure out why.
Here is my custom filter hook callback functions:
function wwg_events_editor_template( $template, $post_type, $args ) {
error_log( 'Postype: ' . $post_type );
if ( $post_type === Tribe__Events__Main::POSTTYPE ) {
error_log( 'Before: ' . print_r($template, TRUE) );
$template = [];
$template[] = [
'core/paragraph',
[
'placeholder' => __( 'Add Description...', 'the-events-calendar' ),
],
];
error_log( 'After: ' . print_r($template, TRUE) );
}
return $template;
}
add_filter( 'tribe_events_editor_default_template', 'wwg_events_editor_template', 500, 3 );
function wwg_events_class_editor_template( $template ) {
error_log( 'Postype: ' . $post_type );
if ( $post_type === Tribe__Events__Main::POSTTYPE ) {
error_log( 'Before: ' . print_r($template, TRUE) );
$template = [];
$template[] = [
'core/paragraph',
[
'placeholder' => __( 'Add Description...', 'the-events-calendar' ),
],
];
error_log( 'After: ' . print_r($template, TRUE) );
}
return $template;
}
add_filter( 'tribe_events_editor_default_classic_template', 'wwg_events_class_editor_template', 500 );Here is what is generated on a new event post:
<!-- wp:tribe/event-datetime /-->
<!-- wp:tribe/featured-image /-->
<!-- wp:tribe/event-links /-->
<!-- wp:tribe/classic-event-details /-->
<!-- wp:tribe/event-venue /-->
<!-- wp:tribe/tickets --><div class="wp-block-tribe-tickets">
</div><!-- /wp:tribe/tickets -->
<!-- wp:tribe/rsvp /-->
<!-- wp:tribe/attendees /-->
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.