Files
bedrock/src/filters.php
Kalen Johnson 2124163de0 Namespaces on own line (#1712)
`namespace` declarations appear on their own line in PHP FIG examples as well as in common PHP frameworks. While not officially part of PSR-2, we should still follow this common practice of not putting `namespace` declaration on the same line as `<?php`.

- http://www.php-fig.org/psr/psr-2/
- https://github.com/laravel/laravel/blob/master/app/User.php#L1-L3
- https://github.com/symfony/filesystem/blob/master/Filesystem.php#L1-L12
- https://github.com/zendframework/zend-mail/blob/master/src/Address.php#L1-L10
2016-09-09 04:24:09 -07:00

56 lines
1.4 KiB
PHP

<?php
namespace App;
use Roots\Sage\Template;
use Roots\Sage\Template\Wrapper;
/**
* Determine which pages should NOT display the sidebar
* @link https://codex.wordpress.org/Conditional_Tags
*/
add_filter('sage/display_sidebar', function ($display) {
// The sidebar will NOT be displayed if ANY of the following return true
return $display ? !in_array(true, [
is_404(),
is_front_page(),
is_page_template('templates/template-custom.php'),
]) : $display;
});
/**
* Add <body> classes
*/
add_filter('body_class', function (array $classes) {
// Add page slug if it doesn't exist
if (is_single() || is_page() && !is_front_page()) {
if (!in_array(basename(get_permalink()), $classes)) {
$classes[] = basename(get_permalink());
}
}
// Add class if sidebar is active
if (display_sidebar()) {
$classes[] = 'sidebar-primary';
}
return $classes;
});
/**
* Add "… Continued" to the excerpt
*/
add_filter('excerpt_more', function () {
return ' &hellip; <a href="' . get_permalink() . '">' . __('Continued', 'sage') . '</a>';
});
/**
* Use theme wrapper
*/
add_filter('template_include', function ($main) {
if (!is_string($main) && !(is_object($main) && method_exists($main, '__toString'))) {
return $main;
}
return ((new Template(new Wrapper($main)))->layout());
}, 109);