tomusborne / generateblocks

GenerateBlocks is a small collection of lightweight WordPress blocks that can accomplish nearly anything.
https://generateblocks.com
198 stars 23 forks source link

GB2.0.0 Beta.2 Button defaults in functions.php not applied correctly #1523

Closed njwgh closed 10 hours ago

njwgh commented 15 hours ago

Description

In GB 1.9.1 if you sync button style with theme in functions.php with code as per here: https://docs.generateblocks.com/article/sync-gb-button-style-with-generatepress-theme/ (I have included border-radius as well in my functions.php) then your button is styled as per those values in the backend and appears the same on frontend. In GB1.9.1 these are my buttons backend: gb-prev-button-backend fontend gb-prev-button-frontend

with GB2.0 (free version) you have two options for adding a button. The button block or a text block with button tag With the same button styles in customiser and same functions.php this is what it looks like backend: GB-new-button-and-text-blocks-backend frontend: GB-new-button-and-text-blocks-frontend

So these issues:

  1. default style is not applied in the backend for either block
  2. In frontend button style from customiser is not applied to button block
  3. In frontend text block with button tag is styled as per customiser but does not have the border radius that was specified in functions.php

Steps to reproduce

  1. Set button colours and font weight in customiser
  2. add to functions.php as per this link https://docs.generateblocks.com/article/sync-gb-button-style-with-generatepress-theme/ and include code for the border radius e.g. $defaults['button']['borderRadiusTopRight'] = '3'; $defaults['button']['borderRadiusTopLeft'] = '3'; $defaults['button']['borderRadiusBottomRight'] = '3'; $defaults['button']['borderRadiusBottomLeft'] = '3';
  3. add a button block to a page and add a text block to the page and choose button tag

Expected behavior

I would expect both types of buttons to appear styled with defaults in backend and frontend


tomusborne commented 10 hours ago

In 2.0, there is a new filter you can use that greatly simplifies the process.

For example, if you're using a theme like GeneratePress, you only need to add the button class to the button.

So, you could do this:

add_filter( 'generateblocks_default_button_attributes', function() {
    return [
        'className' => 'button',
    ];
} );

Now, every time you add a Button to your pages, it will come with that class and no other local styles.