• Resolved luk3v

    (@luk3v)


    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 /-->
    • This topic was modified 2 months ago by luk3v.
    • This topic was modified 2 months ago by luk3v.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support tristan083

    (@tristan083)

    Hi @luk3v ,

    Thank you for reaching out.

    We have the following knowledgebase article that may help provide insights to your situation: Setting Default Blocks in the Block Editor.

    I would like to note that per our Support Policy, we cannot provide full support for Customization or third-party integrations, even if we have a guide on our Knowledge base.

    Plugin Support Darian

    (@d0153)

    Hi there,

    I hope you’re doing well. I just wanted to touch base and check in with you. It’s been a little while since we’ve heard from you. I was just curious if you had the chance to review the reply above.

    Let me know if there’s anything I can assist you with.

    Thread Starter luk3v

    (@luk3v)

    Hi @d0153, yes I just reviewed the knowledgebase article but it doesn’t explain anything about how the block editor template works differently if using wp_insert_post().

    I’ll look more into the code again soon but I guess the root issues is that I couldn’t find where the default blocks I pasted in were being generated from.

    • This reply was modified 1 month, 4 weeks ago by luk3v.
    Plugin Support Darian

    (@d0153)

    Hi @luk3v

    Thanks for your response. I will make sure to share this with the team and keep you updated as soon as I hear back from them.

    Plugin Support Darian

    (@d0153)

    Hi @luk3v

    Thank you for patiently waiting.

    I have received a response from one of my colleagues. Please see the message below:

    The short answer is that wp_insert_post() does not run through the editor template system.

    The fact that the filters are triggered is strange, but it might be just part of the process only when it is manually created. I would suggest debugging $args to see if there is a hint there

    Let me know if you have further questions or concerns.

    Plugin Support Darian

    (@d0153)

    Hi there,

    It seems like it has been some time since we received a response from you, therefore, I will consider this matter as resolved. If you require any further assistance, please do not hesitate to start a new thread.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.