-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Filter refactor #575
Filter refactor #575
Conversation
Cool, I'm in. Outdated scripts we have to put to https://github.com/bootscore/bootscore/blob/main/inc/deprecated.php to keep functionality for overridden templates. While we are here, do we want include deny direct access and version as described in #367 in this PR? Version should be 5.3.4. Lines 1 to 14 in 00a418b
|
The new commit f1d8939 checks if the child theme has the old function included, and if it does, it will use that old return value as the filter. This way the update won't be a breaking change (yet). |
Think changing the classes of titles etc. will go a bit too much ;-) |
Didn't mean the classes in this case, but the text like "menu". Having such strings replaceable is what makes the filters in woocommerce so "powerful". We could also go that route. |
Understand, I‘m in. We have to list all of them in the docs. |
What do you think of this idea @crftwrk?
to if ( is_account_page() && apply_filters('bootscore_wc_actions_hide_account_on_account_page', true)) { |
Yes, this seems to be a good idea 🙏 |
page.php
Outdated
<div id="primary" class="content-area"> | ||
|
||
<!-- Hook to add something nice --> | ||
<?php bs_after_primary(); ?> | ||
|
||
<div class="row"> | ||
<div class="<?= bootscore_main_col_class(); ?>"> | ||
<div class="<?= apply_filters('bootscore_main_col_class', 'col'); ?>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may create issues, because col
isn't enough. If main content has for example a large image, col
takes the entire width of the container and pushes sidebar down. It has to checked if a sidebar is active or not. See this very first PR #7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has already been taken care of in https://github.com/bootscore/bootscore/pull/575/files#diff-3846047656cf4544ef294790e2718df92ab98bcbae795b605a52832e1ea11d84R30 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great 👍
If possible, create the positioning of the sidebars or where they should appear. For example, natively switch sides or even not show it on the single-product page |
Time to rename all the filters, I want them with / instead of _ 😇 |
I think this version of the PR is ready to be reviewed and merged. The buttons haven't been done, but for now that would lead to additional clutter in the theme. Maybe we could transform the button into a function to call with all the details in an array? Then the array can be added as a filter in the function itself. Something like (first argument is just a name for the location and help the filter) <?= bootscore_button('offcanvas/search', ['text' => '<i class="fa-solid fa-magnifying-glass"></i><span class="visually-hidden-focusable">Search</span>', 'class' => 'btn btn-outline-secondary d-lg-none ms-1 ms-md-2 top-nav-search-md']); |
Upstream main
Upstream main
Tried function container_class($string, $location) {
if ($location == 'header') {
return "container-fluid";
}
return $string;
}
add_filter('bootscore_container_class', 'container_class', 10, 2); and add_filter('bootscore_load_fontawesome', '__return_false'); but nothing happens? |
Since the original commit, filters have been renamed. The ones you need are |
Got it, works fine. Possible to add multiple locations here? if ($location == 'header') { |
Of course. All the locations are set in the places the filter is being called in the template files. So for example here: Line 23 in febfbab
$location will be footer (third argument in the apply_filters function). This has been done as much as possible throughout all the locations filters have been added.
|
No, I mean targeting multiple files in one function like if location header, footer, page-sidebar-left. If so, what is the snippet if i want to target containers only in header and footer? |
If you want to want to have a fluid container in both the header and footer, it will be like this: function container_class($string, $location) {
if ($location == 'header' || $location == 'footer') {
return "container-fluid";
}
return $string;
}
add_filter('bootscore/container_class', 'container_class', 10, 2); As simple as that 😄 |
Exactly what I'm searching for 👍 |
I love it, but I need more information how to use them in the docs. Can you drop a quick example how to change roughly the main-col breakpoints/width and sidebar breakpoints/width included the toggler plus product cols? This will prevent us from answering issues. ;-) |
Writing out some examples of the filters, will drop them this evening! |
Thank you. Should this function not wrapped in Lines 21 to 30 in febfbab
|
In that case they can just add another filter 😄 |
Here are a handful of examples that I could think of. A lot of things are possible with filters, and developers can make changes for niche situations in their own theme. Disable FontAwesomeadd_filter('bootscore/load_fontawesome', '__return_false'); Set a new logofunction set_bootstrap_logo($logo, $size) {
if ($size === 'small') {
return get_stylesheet_directory_uri() . '/path/to/small-logo.svg';
}
return get_stylesheet_directory_uri() . '/path/to/normal-logo.svg';
}
add_filter('bootscore/logo', 'set_bootstrap_logo', 10, 2); Set the offcanvas titlefunction set_offcanvas_title($title) {
return 'My Menu';
}
add_filter('bootscore/offcanvas/navbar/title', 'set_offcanvas_title'); Set the content spacer on an archive page of the post type "product"function set_content_spacer($spacer) {
if (is_post_type_archive('product')) {
return 'mt-5';
}
return $spacer;
}
add_filter('bootscore/content/spacer_class', 'set_content_spacer'); Change the container class in the header and footerfunction container_class($string, $location) {
if ($location == 'header' || $location == 'footer') {
return "container-fluid";
}
return $string;
}
add_filter('bootscore/container_class', 'container_class', 10, 2); Make changes in inc/blocks/block-widget-archives.phpfunction change_block_widget_archives($block_content, $block) {
// do something with $block_content
return $block_content;
}
add_filter('bootscore/block/archives/content', 'change_block_widget_archives', 10, 2); Disable the SCSS compileradd_filter('bootscore/scss/disable_compiler', '__return_true'); Change the col size when the sidebar is active (other sizes than default)function change_content_col_size($col_size) {
if (is_active_sidebar('sidebar-1')) {
return "col-md-6 col-lg-7";
}
return $col_size;
}
add_filter('bootscore/main/col_class', 'change_content_col_size');
function change_sidebar_col_size($col_size) {
return "col-md-6 col-lg-5 order-first order-md-last";
}
add_filter('bootscore/sidebar/col_class', 'change_sidebar_col_size'); Remove order-first order-md-last from sidebarfunction remove_order_first_last($col_class) {
return str_replace('order-first order-md-last', '', $col_class);
}
add_filter('bootscore/sidebar/col_class', 'remove_order_first_last'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it and this is damn hot, thank you! As i see, there is no single recipe how to use them, but offers many possibilities. For the docs we should start with simple examples how to change the containers and main-col breakpoints and adding more examples from time to time.
@justinkruit I am on the docs part for the filters right now, but I can't get this to work? function change_content_col_size($col_size) {
if (is_active_sidebar('sidebar-1')) {
return "col-md-6 col-lg-7";
}
return $col_size;
}
add_filter('bootscore/main/col_class', 'change_content_col_size');
function change_sidebar_col_size($col_size) {
return "col-md-6 col-lg-5 order-first order-md-last";
}
add_filter('bootscore/sidebar/col_class', 'change_sidebar_col_size') |
Let me try that in a couple of hours when I'm home. It does seem correct. |
@crftwrk Found the issue, it's because we renamed the hooks (again). add_filter('bootscore/class/col/main', 'change_content_col_size');
add_filter('bootscore/class/col/sidebar', 'change_sidebar_col_size'); Use these and it should work. |
Thanks, it works for the sidebar but not for the main content? |
Where do you place the code to test? |
https://dev.bootscore.me/category/clerkship/ Sidebar is below the main-col function change_content_col_size($col_size) {
if (is_active_sidebar('sidebar-1')) {
return "col-lg-6 ";
}
return $col_size;
}
add_filter('bootscore/class/col/main', 'change_content_col_size');
function change_sidebar_col_size($col_size) {
return "col-lg-6 order-first order-lg-last";
}
add_filter('bootscore/class/col/sidebar', 'change_sidebar_col_size'); |
I mean, where in the code did you place it? File name and line |
Of course functions.php in child. is it something here https://github.com/bootscore/bootscore/blob/main/inc/columns.php? |
So this is the reason. This happens because of the "priority" system in the filters. To quote the documentation:
In this case, the child is loaded before the parent. So this line is executed after the code in the child, overriding it. To make it work, add a priority of 11 to our new filter (10 being the default). Now it will be executed after the code of the main theme, effectively overriding it. function change_content_col_size($col_size) {
if (is_active_sidebar('sidebar-1')) {
return "col-lg-6 ";
}
return $col_size;
}
add_filter('bootscore/class/col/main', 'change_content_col_size', 11); Fun fact: because the code in columns.php has already executed, the |
Got it, thanks. Sometimes things are so simple... ;-) |
Adding a lot of filters to replace the small functions with.
This will make it easier to make changes for other developers.
bootscore_sidebar_col_class
into a filter (6d7e18a)bootscore_sidebar_toggler_class
into a filter (6d7e18a)bootscore_sidebar_offcanvas_class
into a filter (6d7e18a)bootscore_container_class
into a filter (afb590d c1d8393 d01bd42 1d6c386)An example is included below.
bootscore_main_col_class
into a filter (94239fc)$compiler
before the compile happens (e903f0d)Examples
Change the container of the header to
container-fluid
:Turn off Font Awesome