Guest User

Untitled

a guest
May 7th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. add_action('wp_head', 'change_fp_ids');
  2. function change_fp_ids(){
  3. add_filter('fpc_featured_pages_ids', 'my_fp_ids', 20);
  4. function my_fp_ids( $fp_ids ){
  5. $role_page = array(
  6. // Role => Page/Post name
  7. 'administrator' => 'Blog',
  8. 'editor' => 'A',
  9. );
  10. // do nothing if in admin backend or in the customize
  11. if ( is_admin() || TC___::$instance -> is_customizing )
  12. return $fp_ids;
  13.  
  14. $current_user_role = get_current_user_role();
  15.  
  16. if ( ! array_key_exists( $current_user_role, $role_page ) )
  17. return $fp_ids;
  18.  
  19. $i = 0;
  20. foreach ( $fp_ids as $fp_id ){
  21. $fp_page_id = esc_attr( tc__f( '__get_fpc_option' , 'tc_featured_page_'.$fp_id) );
  22. /* now you have the id of the page/post and you can make your checks on it */
  23. /* if this check fails keep the fp_id otherwise unset it */
  24. if ( $role_page[ $current_user_role ] == get_the_title($fp_page_id) ){
  25. array_splice( $fp_ids, $i, 1);
  26. }
  27. $i++;
  28. }
  29. return $fp_ids;
  30. }
  31. }
  32. if (! function_exists('get_current_user_role') ){
  33. function get_current_user_role() {
  34. if ( is_user_logged_in() ) {
  35. global $current_user;
  36. $user_role = $current_user->roles[0];
  37. return $user_role;
  38. }
  39. return false;
  40. }
  41. }
Add Comment
Please, Sign In to add comment