Skip to content

Snippet: Hide WPBakery Page Builder Shortcode Settings From Specific Users

function myprefix_hide_vc_params() {

	// Only run function as needed and make sure WPBMap class exists
	if ( ! class_exists( 'WPBMap' )
		|| ! is_admin()
		|| current_user_can( 'manage_options' ) // change this accordingly
	) {
		return;
	}

	// Array of params to hide
	$hide_params = array( 'unique_id', 'classes', 'visibility', 'style' );

	// Loop through the vc map and update the params to hide them
	$get_shortcodes = WPBMap::getShortCodes();
	foreach ( $get_shortcodes as $shortcode ) {
        if ( empty( $shortcode['params'] ) ) continue;
        $base = $shortcode['base'];
        $params = $shortcode['params'];
        $new_params = array();
        foreach ( $params as $param ) {
            $param_name = isset( $param['param_name'] ) ? $param['param_name'] : '';
            if ( in_array( $param_name, $hide_params ) ) {
                $param['type'] = 'hidden';
                $param['weight'] = -1;
            }
            $new_params[] = $param;
        }
        vc_map_update( $base, 'params', $new_params );
    }


}
add_action( 'init', 'myprefix_hide_vc_params', 99 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top