Total theme compatibility
-
I ran into a compatibility gap with Total Theme / Total Theme Core and wanted to share both the root cause and a working fix in case it’s useful for a future update.
The problem
The
hcbrwpb_visible_for_rolesattribute has no effect onvcex_*shortcodes (e.g.vcex_flex_container,vcex_heading,vcex_button, etc.). Those are Total Theme Core’s own elements and they never pass through WPBakery’svc_shortcode_outputfilter, which is the only hook this plugin uses.Total Theme Core registers
vcex_*shortcodes via WordPress’s nativeadd_shortcodeand renders them through its ownShortcode_Abstract::output()method. That method returns HTML directly without firingvc_shortcode_output.The fix
Total Theme Core has its own pre-render filter called
vcex_maybe_display_shortcode. It fires a filterable boolean before anyvcex_*element renders, and at that point the raw shortcode attributes, includinghcbrwpb_visible_for_roles, are still intact (before they get stripped byvcex_shortcode_atts()).Hooking there applies the same role logic to all
vcex_*elements. Here’s a drop-in snippet (child themefunctions.phpor a mu-plugin):<?php
/**
* Extends "Hide Content by Role for WPBakery" to cover vcex_* shortcodes.
*
* The plugin hooks vc_shortcode_output, which WPBakery fires only for its own
* native elements. Total Theme Core's vcex_* elements bypass that filter and
* render via Shortcode_Abstract::output(), which calls vcex_maybe_display_shortcode
* before doing anything else — so we hook there instead.
*/
add_filter('vcex_maybe_display_shortcode', function (bool $display, string $tag, array $atts): bool {
if (!$display || empty($atts['hcbrwpb_visible_for_roles'])) {
return $display;
}
$allowed_roles = array_map('trim', explode(',', $atts['hcbrwpb_visible_for_roles']));
if (in_array('logged_out', $allowed_roles, true) && !is_user_logged_in()) {
return true;
}
$user = get_userdata(get_current_user_id());
if ($user) {
foreach ($allowed_roles as $role) {
if (in_array($role, (array) $user->roles, true)) {
return true;
}
}
}
return false;
}, 10, 3);The original
vc_shortcode_outputhook still handles WPBakery-native elements (vc_row,vc_column, etc.) as expected. This just fills the gap for Total Theme Core’s elements.Ideally this (or an equivalent integration file) could ship in the plugin’s
/integrations/folder alongside the existingsalient.php.
You must be logged in to reply to this topic.