• Resolved fkoomek

    (@fkoomek)


    Hello.
    I am trying to set some defaults, for example for a button. I found this code here

    add_filter( 'generateblocks_defaults', function( $defaults ) { $color_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_color_defaults() ); $defaults['button']['backgroundColor'] = $color_settings['form_button_background_color']; $defaults['button']['backgroundColorHover'] = $color_settings['form_button_background_color_hover']; $defaults['button']['textColor'] = $color_settings['form_button_text_color']; $defaults['button']['textColorHover'] = $color_settings['form_button_text_color_hover']; $defaults['button']['paddingTop'] = '10'; $defaults['button']['paddingRight'] = '20'; $defaults['button']['paddingBottom'] = '10'; $defaults['button']['paddingLeft'] = '20'; return $defaults; } );

    But it’s not working.

    Then I tried this filter

    add_filter( 'generateblocks_default_button_attributes', function( $attributes ) {
    return $attributes;
    }

    Which works but not on initial inserting of the element in Gutebnerg, only after saving or opening block settings. Is it somehow possible to set correctly the defaults?
    Thank you.

    Radan

    • This topic was modified 6 days, 12 hours ago by fkoomek.
    • This topic was modified 6 days, 12 hours ago by fkoomek.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support ying

    (@yingscarlett)

    Hi there,

    Are you using v2 blocks now?

    If so, try this instead:

    add_filter( 'generateblocks_default_button_attributes', function() {
    $color_settings = wp_parse_args(
    get_option( 'generate_settings', array() ),
    generate_get_color_defaults()
    );
    return [
    'styles' => [
    'display' => 'inline-flex',
    'alignItems' => 'center',
    'backgroundColor' => $color_settings['form_button_background_color'],
    'color' => $color_settings['form_button_text_color'],
    'paddingTop' => '1rem',
    'paddingRight' => '2rem',
    'paddingBottom' => '1rem',
    'paddingLeft' => '2rem',
    'textDecoration' => 'none',
    '&:is(:hover, :focus)' => [
    'backgroundColor' => $color_settings['form_button_background_color_hover'],
    'color' => $color_settings['form_button_text_color_hover'],
    ],
    ],
    ];
    } );
    Thread Starter fkoomek

    (@fkoomek)

    Hello.
    Thank you for your reply.
    I am using the latest version 2.0.1 but your code unfortunately doesn’t work

    Radan

    Plugin Support ying

    (@yingscarlett)

    I’ve updated my code, please give it another try.

    Thread Starter fkoomek

    (@fkoomek)

    That did it. Many thanks ??

    Radan

    • This reply was modified 6 days, 8 hours ago by fkoomek.
    Plugin Support ying

    (@yingscarlett)

    You are welcome ? ??

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