Skip to content

Instantly share code, notes, and snippets.

@ahmadnaser
Forked from eri-trabiccolo/hide_fp_fpu.php
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadnaser/df5e919447574cfe6111 to your computer and use it in GitHub Desktop.
Save ahmadnaser/df5e919447574cfe6111 to your computer and use it in GitHub Desktop.
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