Files
acrib.es/wp-content/mu-plugins/acrib-core.php
Malin 0e036366dd fix: extend Kadence title-section hide to all pages with title:hide meta
Add a dynamic wp_head hook that reads _kadence_post_layout per page and injects
page-scoped CSS to hide .entry-hero.page-hero-section and remove boxed content
styling whenever title:hide or layout:fullwidth is set. Targets page-id-{N} so
it does not affect legal pages that intentionally show the Kadence title banner.
MU-plugin bumped to v1.3.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 20:46:55 +02:00

167 lines
6.7 KiB
PHP

<?php
/**
* ACRIB Core MU-Plugin
* Always-on: custom footer, security hardening, performance tweaks.
* @version 1.2
*/
// --- Remove Kadence default copyright footer ---
// template-hooks.php is included at the root of functions.php, so the action
// is added before after_setup_theme fires. Priority 999 removes it after.
add_action('after_setup_theme', function () {
remove_action('kadence_footer', 'Kadence\footer_markup');
remove_action('kadence_footer_html', 'Kadence\footer_html');
}, 999);
// --- Transparent header body class on homepage (Kadence Pro workaround) ---
// Kadence's layout/component.php adds non-transparent-header at priority 10.
// We run at 999 to remove it and add transparent-header (used by Kadence JS).
add_filter('body_class', function ($classes) {
if (is_front_page()) {
$classes = array_diff($classes, ['non-transparent-header', 'mobile-non-transparent-header']);
$classes[] = 'transparent-header';
$classes[] = 'mobile-transparent-header';
}
return $classes;
}, 999);
// --- Footer: bottom bar with legal links + Cloud Host credit ---
add_action('wp_footer', function () {
$year = date('Y');
$legal_url = home_url('/aviso-legal/');
$pp_url = home_url('/politica-privacidad/');
$cookie_url = home_url('/politica-cookies/');
?>
<div class="acrib-footer-bottom">
<div class="acrib-footer-bottom-inner">
<p class="acrib-footer-copyright">
&copy; <?php echo $year; ?> <strong>ACRIB</strong> &mdash; Asociaci&oacute;n Casa Rom&acirc;neasc&#259; de las Islas Baleares
</p>
<ul class="acrib-footer-legal-links">
<li><a href="<?php echo esc_url($legal_url); ?>">Aviso Legal</a></li>
<li><a href="<?php echo esc_url($pp_url); ?>">Privacidad</a></li>
<li><a href="<?php echo esc_url($cookie_url); ?>">Cookies</a></li>
</ul>
<p class="acrib-footer-hosted">
Hosted &amp; Maintained by <a href="https://cloudhost.es" target="_blank" rel="noopener noreferrer">Cloud Host</a>
</p>
</div>
</div>
<?php
}, 100);
// --- Security headers ---
add_action('send_headers', function () {
if (!is_admin()) {
header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
}
});
// --- Disable XML-RPC ---
add_filter('xmlrpc_enabled', '__return_false');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wp_shortlink_wp_head');
// --- Disable REST API user enumeration ---
add_filter('rest_endpoints', function ($endpoints) {
unset($endpoints['/wp/v2/users'], $endpoints['/wp/v2/users/(?P<id>[\d]+)']);
return $endpoints;
});
// --- Disable emoji (reduces ~20KB page weight) ---
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
// --- Limit post revisions ---
if (!defined('WP_POST_REVISIONS')) {
define('WP_POST_REVISIONS', 3);
}
// --- Global: hide Kadence title section on pages with custom heroes ---
// Kadence free ignores _kadence_post_layout title:hide meta.
// We read it ourselves and output the fix for any page that set it.
add_action('wp_head', function () {
if (is_singular()) {
$layout = get_post_meta(get_the_ID(), '_kadence_post_layout', true);
$meta = $layout ? json_decode($layout, true) : [];
$hide_title = isset($meta['title']) && $meta['title'] === 'hide';
$full_width = isset($meta['layout']) && $meta['layout'] === 'fullwidth';
if ($hide_title || $full_width) {
$rules = [];
if ($hide_title) {
$rules[] = '.page-id-' . get_the_ID() . ' .entry-hero.page-hero-section{display:none!important}';
}
if ($full_width) {
// Remove boxed content wrap styling added by content-style-boxed body class
$rules[] = '.page-id-' . get_the_ID() . ' .entry-content-wrap{padding:0!important;box-shadow:none!important;margin:0!important;background:none!important}';
$rules[] = '.page-id-' . get_the_ID() . ' .content-area{max-width:100%!important;padding:0!important}';
}
if ($rules) {
echo '<style id="acrib-page-fixes-' . get_the_ID() . '">' . implode("\n", $rules) . '</style>' . "\n";
}
}
}
}, 5);
// --- Homepage: inject critical CSS fixes ---
add_action('wp_head', function () {
if (!is_front_page()) return;
echo '<style id="acrib-homepage-fixes">
/* ── Transparent header overlay on homepage ───────────────────────── */
/* Position header absolutely so it overlays the hero without pushing */
/* content down — this is the Kadence Pro "transparent header" effect. */
.home #masthead.site-header{
position:absolute;
top:0;left:0;right:0;
z-index:1000;
background:transparent!important;
box-shadow:none!important;
}
/* Remove the top padding/margin Kadence normally adds to offset the header */
.home .content-area,
.home .site-content,
.home #content{
margin-top:0!important;
padding-top:0!important;
}
/* Remove Kadence blank page-title section above hero (title:hide meta ignored) */
.home .entry-hero.page-hero-section{display:none!important}
/* Remove bottom margin that creates gap after the last section */
.home .content-area{margin-bottom:0!important}
/* Remove boxed content styling on homepage */
.home .entry-content-wrap{
padding:0!important;
box-shadow:none!important;
margin:0!important;
background:none!important;
}
/* ── Hero: fill exactly one viewport height ───────────────────────── */
.acrib-hero.wp-block-cover{
height:100svh!important;
height:100vh!important;
min-height:0!important;
}
/* Centre hero content; padding-top clears the overlaid header */
.acrib-hero .wp-block-cover__inner-container{
height:100%!important;
min-height:0!important;
display:flex!important;
flex-direction:column!important;
align-items:center!important;
justify-content:center!important;
padding:80px 2rem 3rem!important;
box-sizing:border-box!important;
}
</style>' . "\n";
}, 5);