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

Filter refactor #575

Merged
merged 24 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d7e18a
Replace functions with filters in sidebar.php
justinkruit Sep 15, 2023
afb590d
Replace bootscore_container_class
justinkruit Sep 15, 2023
c1d8393
Replace bootscore_container_class in page-templates
justinkruit Sep 15, 2023
d01bd42
Replace bootscore_container_class in single-templates
justinkruit Sep 15, 2023
1d6c386
top-nav-search-collapse bootscore_container_class replacement
justinkruit Sep 15, 2023
e903f0d
Add filter to scss compiler
justinkruit Sep 15, 2023
94239fc
Make bootscore_main_col_class a filter
justinkruit Sep 15, 2023
4ebdd63
Make fontawesome toggleable
justinkruit Sep 15, 2023
f1d8939
Support for older child themes
justinkruit Sep 15, 2023
594c872
Remove old functions
justinkruit Sep 15, 2023
fdb033d
Merge branch 'main' into filter-refactor
justinkruit Nov 24, 2023
edb28d3
Merge
justinkruit Jan 12, 2024
afb2e55
Add filter for offcanvas title
justinkruit Jan 12, 2024
442fbed
Make offvanvas titles filters
justinkruit Jan 12, 2024
3624d2a
Rename bootscore_container_class filter
justinkruit Jan 12, 2024
2c64b0c
Make the logo a filter
justinkruit Jan 12, 2024
87417d7
Rename bootscore_main_col_class filter
justinkruit Jan 12, 2024
07e3bde
Rename bootscore_sidebar_col_class filter
justinkruit Jan 12, 2024
bdc467c
Rename more filters
justinkruit Jan 12, 2024
bb500da
Add filters to the block_content
justinkruit Jan 12, 2024
78b92fd
Add bootscore/content/spacer_class filter
justinkruit Jan 12, 2024
8b726b2
Merge branch 'main' into filter-refactor
justinkruit Feb 23, 2024
6ac4ed6
Merge pull request #690 from bootscore/main
crftwrk Feb 23, 2024
febfbab
Merge pull request #691 from bootscore/main
crftwrk Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

get_header();
?>
<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', '404'); ?> py-5 mt-5">
<div id="primary" class="content-area">

<main id="main" class="site-main">
Expand Down
4 changes: 2 additions & 2 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'archive'); ?> py-5 mt-5">
<div id="primary" class="content-area">

<?php bs_after_primary(); ?>

<div class="row">
<div class="<?= bootscore_main_col_class(); ?>">
<div class="<?= apply_filters('bootscore_main_col_class', 'col') ?>">

<main id="main" class="site-main">

Expand Down
4 changes: 2 additions & 2 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<footer>

<div class="bootscore-footer bg-body-tertiary pt-5 pb-3">
<div class="<?= bootscore_container_class(); ?>">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'footer'); ?>">

<!-- Top Footer Widget -->
<?php if (is_active_sidebar('top-footer')) : ?>
Expand Down Expand Up @@ -73,7 +73,7 @@
</div>

<div class="bootscore-info bg-body-tertiary text-body-tertiary border-top py-2 text-center">
<div class="<?= bootscore_container_class(); ?>">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'footer-copyright'); ?>">
<?php if (is_active_sidebar('footer-info')) : ?>
<?php dynamic_sidebar('footer-info'); ?>
<?php endif; ?>
Expand Down
1 change: 0 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require_once('inc/breadcrumb.php'); // Breadcrumb
require_once('inc/columns.php'); // Main/sidebar column width and breakpoints
require_once('inc/comments.php'); // Comments
require_once('inc/container.php'); // Container class
require_once('inc/enable-html.php'); // Enable HTML in category and author description
require_once('inc/enqueue.php'); // Enqueue scripts and styles
require_once('inc/excerpt.php'); // Adds excerpt to pages
Expand Down
3 changes: 1 addition & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

<nav id="nav-main" class="navbar navbar-expand-lg">

<div class="<?= bootscore_container_class(); ?>">

<div class=" <?= apply_filters('bootscore_container_class', 'container', 'header'); ?>">
<!-- Navbar Brand -->
<a class="navbar-brand xs d-md-none" href="<?= esc_url(home_url()); ?>"><img src="<?= esc_url(get_stylesheet_directory_uri()); ?>/img/logo/logo-sm.svg" alt="logo" class="logo xs"></a>
<a class="navbar-brand md d-none d-md-block" href="<?= esc_url(home_url()); ?>"><img src="<?= esc_url(get_stylesheet_directory_uri()); ?>/img/logo/logo.svg" alt="logo" class="logo md"></a>
Expand Down
57 changes: 13 additions & 44 deletions inc/columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,29 @@
/**
* Columns
*
* @package Bootscore
* @package Bootscore
* @version 5.3.3
*/


// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

defined('ABSPATH') || exit;

/**
* Make main content col dynamic if sidebar widgets exists
* @return string
*/
if (!function_exists('bootscore_main_col_class')) {
function bootscore_main_col_class() {
if (!is_active_sidebar('sidebar-1')) {
// Sidebar is empty
return "col";
} else {
// Sidebar has widgets
return "col-md-8 col-lg-9";
}
}
}


/**
* Sidebar column width and breakpoints
* @return string
* Determines the CSS class for the main column based on the presence of a sidebar.
*
* @param string $string The default CSS class for the main column.
*
* @return string The CSS class for the main column. If a sidebar is active, it will return "col-md-8 col-lg-9". Otherwise, it will return the provided $string.
*/
if (!function_exists('bootscore_sidebar_col_class')) {
function bootscore_sidebar_col_class() {
return "col-md-4 col-lg-3 order-first order-md-last";
function bootscore_main_col_class_sidebar($string) {
if (is_active_sidebar('sidebar-1')) {
// Sidebar is not empty
return "col-md-8 col-lg-9";
}
}


/**
* Sidebar responsive offcanvas toggler
* @return string
*/
if (!function_exists('bootscore_sidebar_toggler_class')) {
function bootscore_sidebar_toggler_class() {
return "d-md-none btn btn-outline-primary w-100 mb-4 d-flex justify-content-between align-items-center";
}
return $string;
}

add_filter('bootscore_main_col_class', 'bootscore_main_col_class_sidebar');

/**
* Sidebar responsive offcanvas breakpoint and placement
* @return string
*/
if (!function_exists('bootscore_sidebar_offcanvas_class')) {
function bootscore_sidebar_offcanvas_class() {
return "offcanvas-md offcanvas-end";
}
}
23 changes: 0 additions & 23 deletions inc/container.php

This file was deleted.

24 changes: 24 additions & 0 deletions inc/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,27 @@ function bsfaCode($atts) {

;
add_shortcode('bsfa', 'bsfaCode');

/*
* Check if the old functions which were used for simple classes are used in the child theme
* If so, we transform them to use the new filter hooks
*/
if (function_exists('bootscore_main_col_class')) {
add_filter('bootscore_main_col_class', 'bootscore_main_col_class', 100);
}

if (function_exists('bootscore_sidebar_col_class')) {
add_filter('bootscore_sidebar_col_class', 'bootscore_sidebar_col_class', 100);
}

if (function_exists('bootscore_sidebar_toggler_class')) {
add_filter('bootscore_sidebar_toggler_class', 'bootscore_sidebar_toggler_class', 100);
}

if (function_exists('bootscore_sidebar_offcanvas_class')) {
add_filter('bootscore_sidebar_offcanvas_class', 'bootscore_sidebar_offcanvas_class', 100);
}

if (function_exists('bootscore_container_class')) {
add_filter('bootscore_container_class', 'bootscore_container_class', 100);
}
8 changes: 5 additions & 3 deletions inc/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Enqueue styles & scripts
*
* @package Bootscore
* @package Bootscore
* @version 5.3.3
*/


// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
defined('ABSPATH') || exit;


/**
Expand All @@ -33,7 +33,9 @@ function bootscore_scripts() {
wp_enqueue_style('bootscore-style', get_stylesheet_uri(), array(), $modificated_styleCss);

// Fontawesome
wp_enqueue_style('fontawesome', get_template_directory_uri() . '/fontawesome/css/all.min.css', array(), $modificated_fontawesomeCss);
if (apply_filters('bootscore_load_fontawesome', true)) {
wp_enqueue_style('fontawesome', get_template_directory_uri() . '/fontawesome/css/all.min.css', array(), $modificated_fontawesomeCss);
}

// Bootstrap JS
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/lib/bootstrap.bundle.min.js', array(), $modificated_bootstrapJs, true);
Expand Down
2 changes: 2 additions & 0 deletions inc/scss-compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function bootscore_compile_scss() {
$compiler->setOutputStyle(\ScssPhp\ScssPhp\OutputStyle::COMPRESSED);
}

$compiler = apply_filters('bootscore_scss_compiler', $compiler);

try {
if ($last_modified > $stored_modified || !file_exists($css_file) || $is_environment_dev && !$skip_environment_check) {
$compiled = $compiler->compileString(file_get_contents($scss_file));
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

get_header();
?>
<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-4">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'index'); ?> py-5 mt-4">
<div id="primary" class="content-area">

<!-- Hook to add something nice -->
Expand Down Expand Up @@ -115,7 +115,7 @@
<?php endif; ?>
<!-- Post List -->
<div class="row">
<div class="<?= bootscore_main_col_class(); ?>">
<div class="<?= apply_filters('bootscore_main_col_class', 'col'); ?>">
<!-- Grid Layout -->
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-blank-with-container.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?>">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'page-blank-with-container'); ?>">
<div id="primary" class="content-area">

<!-- Hook to add something nice -->
Expand Down
6 changes: 3 additions & 3 deletions page-templates/page-full-width-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

<?php $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); ?>
<header class="entry-header featured-full-width-img height-75 bg-dark text-light mb-3" style="background-image: url('<?= $thumb['0']; ?>')">
<div class="<?= bootscore_container_class(); ?> entry-header h-100 d-flex align-items-end pb-3">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'page-full-width-image'); ?> entry-header h-100 d-flex align-items-end pb-3">
<div>
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
</div>
</header>

<div class="<?= bootscore_container_class(); ?> pb-5">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'page-full-width-image'); ?> pb-5">

<!-- 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'); ?>">

<div class="entry-content">
<?php the_content(); ?>
Expand Down
4 changes: 2 additions & 2 deletions page-templates/page-sidebar-left.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'page-sidebar-left'); ?> py-5 mt-5">
<div id="primary" class="content-area">

<!-- Hook to add something nice -->
<?php bs_after_primary(); ?>

<div class="row">
<?php get_sidebar(); ?>
<div class="<?= bootscore_main_col_class(); ?> order-first order-md-last">
<div class="<?= apply_filters('bootscore_main_col_class', 'col'); ?> order-first order-md-last">

<main id="main" class="site-main">

Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-sidebar-none.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'page-sidebar-none'); ?> py-5 mt-5">
<div id="primary" class="content-area">

<!-- Hook to add something nice -->
Expand Down
4 changes: 2 additions & 2 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'page'); ?> py-5 mt-5">
<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'); ?>">
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Great 👍


<main id="main" class="site-main">

Expand Down
4 changes: 2 additions & 2 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

get_header();
?>
<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-5">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'search'); ?> py-5 mt-5">
<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'); ?>">

<main id="main" class="site-main">

Expand Down
6 changes: 3 additions & 3 deletions sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
return;
}
?>
<div class="<?= bootscore_sidebar_col_class(); ?>">
<div class="<?= apply_filters('bootscore_sidebar_col_class', 'col-md-4 col-lg-3 order-first order-md-last'); ?>">
<aside id="secondary" class="widget-area">

<button class="<?= bootscore_sidebar_toggler_class(); ?>" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar">
<button class="<?= apply_filters('bootscore_sidebar_toggler_class', 'd-md-none btn btn-outline-primary w-100 mb-4 d-flex justify-content-between align-items-center') ?>" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar">
<?php esc_html_e('Open side menu', 'bootscore'); ?> <i class="fa-solid fa-ellipsis-vertical"></i>
</button>

<div class="<?= bootscore_sidebar_offcanvas_class(); ?>" tabindex="-1" id="sidebar" aria-labelledby="sidebarLabel">
<div class="<?= apply_filters('bootscore_sidebar_offcanvas_class', 'offcanvas-md offcanvas-end') ?>" tabindex="-1" id="sidebar" aria-labelledby="sidebarLabel">
<div class="offcanvas-header">
<span class="h5 offcanvas-title" id="sidebarLabel"><?php esc_html_e('Sidebar', 'bootscore'); ?></span>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#sidebar" aria-label="Close"></button>
Expand Down
6 changes: 3 additions & 3 deletions single-templates/single-full-width-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
<?php the_post(); ?>
<?php $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); ?>
<header class="entry-header featured-full-width-img height-75 bg-dark text-light mb-3" style="background-image: url('<?= $thumb['0']; ?>')">
<div class="<?= bootscore_container_class(); ?> entry-header h-100 d-flex align-items-end pb-3">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'single-full-width-image'); ?> entry-header h-100 d-flex align-items-end pb-3">
<div>
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
</div>
</header>

<div class="<?= bootscore_container_class(); ?> pb-5">
<div class="<?= apply_filters('bootscore_container_class', 'container', 'single-full-width-image'); ?> pb-5">

<!-- Hook to add something nice -->
<?php bs_after_primary(); ?>

<?php the_breadcrumb(); ?>

<div class="row">
<div class="<?= bootscore_main_col_class(); ?>">
<div class="<?= apply_filters('bootscore_main_col_class', 'col'); ?>">

<div class="entry-content">
<?php bootscore_category_badge(); ?>
Expand Down
4 changes: 2 additions & 2 deletions single-templates/single-sidebar-left.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
get_header();
?>

<div id="content" class="site-content <?= bootscore_container_class(); ?> py-5 mt-4">
<div id="content" class="site-content <?= apply_filters('bootscore_container_class', 'container', 'single-sidebar-left'); ?> py-5 mt-4">
<div id="primary" class="content-area">

<!-- Hook to add something nice -->
Expand All @@ -19,7 +19,7 @@

<div class="row">
<?php get_sidebar(); ?>
<div class="<?= bootscore_main_col_class(); ?> order-first order-md-last">
<div class="<?= apply_filters('bootscore_main_col_class', 'col'); ?> order-first order-md-last">

<main id="main" class="site-main">

Expand Down
Loading