Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Gutenberg block widgets #662

Merged
merged 17 commits into from
Jan 12, 2024

Conversation

crftwrk
Copy link
Member

@crftwrk crftwrk commented Dec 24, 2023

Closes #471

Because #660 disables classic widgets we should provide support for block widgets. This PR adds Bootstrap to following block widgets:

  • Search form-control/btn-outline-secondary/input-group/btn text/icon
  • Categories select/list-group
  • Archives select/list-group
  • Latest Posts list-group
  • Latest Comments list-group
  • Calendar table

Demo: https://dev.bootscore.me/theme/blocks/

In the sidebar are the widgets that come with a new WP installation wrapped in .card, in main content are the same widgets with different/advanced settings.

I have stolen this idea from the Understrap theme using render_block_core for this purpose and adapted it to our needs.

Cards in sidebar

To get widgets in sidebar work properly, .card component has been removed in widget register. Cards can be added by using Group blocks and adding classes to the blocks advanced settings:

Group class card
| - H2 class card-header h6
| - Group class card-body
  | - Block widget
Group class card
| - H2 class card-header h6
| - Block widget Categories/Archives/... class list-group-flush

Search form

Replacing the WP search icon with Font Awesome works only if svg is formatted this way. Overriding function in child must have same formatting, including the indentation tab for the function. Don't ask me why.

/**
 * Change search btn and icon
 */
  function bootscore_block_widget_search_classes($block_content, $block) {

    $search  = array(
      'wp-block-search__input ',
      'wp-block-search__input"',
      'wp-block-search__button ',
      '<svg class="search-icon" viewBox="0 0 24 24" width="24" height="24">
                    <path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"></path>
                </svg>'
    );
    $replace = array(
      'wp-block-search__input form-control ',
      'wp-block-search__input form-control"',
      'wp-block-search__button btn btn-primary ',
      '<i class="fa-solid fa-glasses"></i>'
    );

    if (isset($block['attrs']['buttonPosition']) && 'button-inside' === $block['attrs']['buttonPosition']) {
      $search[]  = 'wp-block-search__inside-wrapper';
      $replace[] = 'wp-block-search input-group';
    }

    return str_replace($search, $replace, $block_content);
  }

What else?

  • Moved outdated scripts & styles to deprecated
  • Renamed _recycle_bin.scss into _deprecated.scss
  • Renamed _wc_recycle_bin.scss into _wc_deprecated.scss

@justinkruit IYLIMI

@crftwrk crftwrk marked this pull request as draft December 24, 2023 10:42
@crftwrk crftwrk marked this pull request as ready for review December 29, 2023 09:51
@justinkruit
Copy link
Member

@crftwrk you still got more changes to do? 😉

@crftwrk
Copy link
Member Author

crftwrk commented Jan 1, 2024

@justinkruit not yet, it‘s good for now.

Copy link
Member

@justinkruit justinkruit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only got the one comment, other than that; impressive!

inc/blocks/block-widget-categories.php Show resolved Hide resolved
@justinkruit justinkruit self-requested a review January 12, 2024 13:11
@justinkruit justinkruit merged commit 6651f8a into main Jan 12, 2024
@justinkruit justinkruit deleted the Add-support-to-Gutenberg-block-widgets branch January 12, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feature Request] Add BS5 Navwalker support for WP NAV Widgets
2 participants