Last active
August 29, 2015 14:17
-
-
Save eri-trabiccolo/688e0e6c1772c7894839 to your computer and use it in GitHub Desktop.
Hide some featured pages in FPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('wp_head', 'change_fp_ids'); | |
function change_fp_ids(){ | |
add_filter('fpc_featured_pages_ids', 'my_fp_ids', 20); | |
function my_fp_ids( $fp_ids ){ | |
$role_page = array( | |
// Role => Page/Post name | |
'administrator' => 'Blog', | |
'editor' => 'A', | |
); | |
// do nothing if in admin backend or in the customize | |
if ( is_admin() || TC___::$instance -> is_customizing ) | |
return $fp_ids; | |
$current_user_role = get_current_user_role(); | |
if ( ! array_key_exists( $current_user_role, $role_page ) ) | |
return $fp_ids; | |
$i = 0; | |
foreach ( $fp_ids as $fp_id ){ | |
$fp_page_id = esc_attr( tc__f( '__get_fpc_option' , 'tc_featured_page_'.$fp_id) ); | |
/* now you have the id of the page/post and you can make your checks on it */ | |
/* if this check fails keep the fp_id otherwise unset it */ | |
if ( $role_page[ $current_user_role ] == get_the_title($fp_page_id) ){ | |
array_splice( $fp_ids, $i, 1); | |
} | |
$i++; | |
} | |
return $fp_ids; | |
} | |
} | |
if (! function_exists('get_current_user_role') ){ | |
function get_current_user_role() { | |
if ( is_user_logged_in() ) { | |
global $current_user; | |
$user_role = $current_user->roles[0]; | |
return $user_role; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment