• Is it possible to set the default settings when creating a GutenBee gallery block? For example when creating a GutenBee gallery, if the gallery type could start with Justified, have row height set to 250, margins 10, show captions, and link to the media file by default these make for a beautiful gallery. Each post I create has multiple gallery blocks making it a pain to configure every time. With the native WP gallery block I coded the following for functions.php which sets the default when inserting a block:

    function my_block_type_metadata($settings, $metadata)
    {
    if ($settings['name'] == 'core/gallery') {
    $settings['attributes']['sizeSlug']['default'] = 'medium';
    $settings['attributes']['columns']['default'] = 4;
    $settings['attributes']['linkTo']['default'] = 'media';
    }
    return $settings;
    }
    add_filter('block_type_metadata_settings', 'my_block_type_metadata', 10, 2);

    I tried to code a version for GutenBee but can’t even get a print out of the attributes. I got the name ‘gutenbee/justified-gallery’ from editing a post with Classic Editor. But perhaps the settings name is a little different?

    function gutenbee_metadata($settings, $metadata)
    {
    if ($settings['name'] == 'gutenbee/justified-gallery') {
    print_r($settings['attributes']);
    }
    return $settings;
    }
    add_filter('block_type_metadata_settings', 'gutenbee_metadata', 10, 2);

    Any pointers would be greatly appreciated.
    Warm regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Anastis Sourgoutsidis

    (@anastis)

    Hi Josh,

    add a new gallery block, change the settings that you want to be the defaults, and when you are ready, remove the images and click on the three dots button and then “Create pattern”. Type a name, such as “Justified gallery” or something else that will help you find it, and make sure the “Synced” checkbox is unchecked. Finally, press Add.

    Now you can add the “Justified gallery” pattern easily from the block inserter, with the defaults you specified. You essentially created a one-block pattern. No code necessary 😀

    Happy holidays!

    Thread Starter Josh Journey

    (@ljosh)

    @anastis Thank you very much for showing me this awesome technique!

    One issue remains which is creating a default image source. When editing a Gutenbee gallery block, the block setting > Image settings > Image Size only appears when there are images already selected for the block. When adding images, inserting, then removing images from a gallery; the ‘Add to Gallery’ button fades and does nothing on click (unless an image is added back). A gallery that has had images added requires images to allow being updated – a WP imposed restriction. Even when removing from the button ‘Add to Gallery’ attribute disabled=”disabled”, the button does nothing.

    Fortunately I can work around this and convert the gallery to HTML. Followed by manually removing the images, then set it back to visual:

    <div id="block-28470b-7621-84" class="wp-block-gutenbee-justified-gallery block-28470b-7621-84 wp-block-gutenbee-gallery-justified" data-gallery-type="justified" data-row-height="120" data-margins="1" data-last-row="nojustify" data-randomize="false">
    <div class="wp-block-gutenbee-gallery-content"></div>
    </div>

    This sets the Gutenbee to a blank gallery. But the gallery settings again require an already selected image to show the Image Size setting. In a future update could Gutenbee’s Image Size setting please display even if the gallery has 0 images? This would allow the creation of patterns with having a pre-selected image source but without having already selected images.

    Warm regards,
    Josh

    Plugin Author Anastis Sourgoutsidis

    (@anastis)

    Hi Josh,

    if I remember correctly, the image sizes dropdown is populated based on information returned by the images themeselves, so it’s (probably) not possible to pre-populate it before selecting any images.

    But, assuming you just need that to create patterns with a specific size, you should keep the block information when removing the images, i.e. the <!– wp:gutenbee/justified-gallery… and <!– /wp:gutenbee/justified-gallery –> lines:

    <!-- wp:gutenbee/justified-gallery {"uniqueId":"36d6e8-47d5-4a","size":"large"} -->
    <div id="block-36d6e8-47d5-4a" class="wp-block-gutenbee-justified-gallery block-36d6e8-47d5-4a wp-block-gutenbee-gallery-columns gutenbee-columns-3" data-gallery-type="columns" data-row-height="120" data-margins="1" data-last-row="nojustify" data-randomize="false"><div class="wp-block-gutenbee-gallery-content"></div></div>
    <!-- /wp:gutenbee/justified-gallery -->

    The “size”:”large” bit on the first line is the size I selected before I removed the image. Any images added to this gallery will then have this size preselected.

    Hope this helps.

    Thread Starter Josh Journey

    (@ljosh)

    @anastis Fantastic! Using your HTML comments was able to create a pattern with the image size pre-selected. Step one is to create a simple gallery, edit as HTML, remove all gallery items leaving the 2 parent DIVs. Then I place in your HTML comment above and below. Convert to visual. Attempt recovery. Save as pattern. Then place gallery blocks using this saved pattern. It’s working beautifully. 😊

    Thank you so much for all your help with setting defaults that work within our workflows. This is a huge improvement. Wishing you a wonderful week ahead.

    Warm regards.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.