Guest User

Untitled

a guest
Jan 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. namespace StackExchangeWordPress;
  2.  
  3. add_action( 'wp_loaded', __NAMESPACE__ . 'wp_loaded' );
  4. function wp_loaded() {
  5. $role = 'author';
  6. if( ! is_current_user_in_role( $role ) ) {
  7. return;
  8. }
  9. add_action( 'wp_enqueue_scripts', __NAMESPACE__ . 'wp_enqueue_scripts' );
  10. add_action( 'wp_footer', __NAMESPACE__ . 'wp_footer' );
  11. }
  12.  
  13. function wp_footer() { ?>
  14. <div class="hidden or-some-other-class-that-wont-be-shown">
  15. <!-- Some other HTML code -->
  16. </div>
  17. <?php }
  18.  
  19. function wp_enqueue_scripts() {
  20. //* Enqueue the CSS that will initially hide the hidden div
  21. //* Or it could be in another stylesheet already enqueued
  22. wp_enqueue_style( 'name-of-style', PATH_TO . 'style-name.css' );
  23.  
  24. //* In the javascript file, pop up the hidden div
  25. wp_enqueue_script( 'name-of-script', PATH_TO . 'script-name.js' );
  26. }
  27.  
  28. function is_current_user_in_role( $role ) {
  29. return in_array( $role, (array) wp_get_current_user()->roles )
  30. }
Add Comment
Please, Sign In to add comment