Skip to content

Instantly share code, notes, and snippets.

@MervinHernandez
Created February 5, 2019 05:11
Show Gist options
  • Save MervinHernandez/a77a632c57727109f0a40801571d20bd to your computer and use it in GitHub Desktop.
Save MervinHernandez/a77a632c57727109f0a40801571d20bd to your computer and use it in GitHub Desktop.
Pro Theme - User Role Condition Display Global Block
<?php
// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to Pro in this file.
// =============================================================================
// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================
/* HIDE Global Block */
/* STEP 1 - Edit the role attribute here in this function*/
add_shortcode('maybe-show-gb', 'maybe_show_gb');
function maybe_show_gb($atts = array()){
extract(shortcode_atts(array(
'gb' => '',
'role' => 'affilaite',
), $atts));
$user = wp_get_current_user();
if( in_array( $role, (array) $user->roles ) && is_numeric($gb) ) {
ob_start();
echo do_shortcode('[cs_gb id=' . $gb. ']');
return ob_get_clean();
}
return null;
}
/* STEP 2 - Call Shortcode
Use the following shortcode, wherever you'd like to call the
global block to be displayed
[maybe-show-gb gb='67067' role='affiliate']
Reminder: edit the id number, to correspond with your global block
ID number (visible in the global blocks lsit)
Done!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment