Guest User

Untitled

a guest
Oct 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * [cds_add_to_footer description]
  5. * DEBUG - output to footer only for logged-in admins
  6. * @return [type] [description]
  7. */
  8. function cds_add_to_footer(){
  9.  
  10. // Don't display for non-admin users
  11. if ( ! current_user_can( 'manage_options' ) )
  12. return;
  13.  
  14. // wp globals
  15. // global $wp_rewrite;
  16. // global $post;
  17.  
  18. //#1
  19. if (is_single() ) {
  20. global $post;
  21.  
  22. $categories = array();
  23. $category_nicknames = array();
  24. foreach((get_the_category($post->ID)) as $category) {
  25. $categories[] = $category;
  26. // add category slug to the $category_nicknames array
  27. $category_nicknames[] = $category->category_nicename;
  28. }
  29.  
  30. echo '<div class="cds debug" style="
  31. background: #f1f1f1;
  32. border: 3px solid black;
  33. position: relative;
  34. padding: 20px;
  35. ">';
  36.  
  37. highlight_string("\n<?php\n\$categories =\n" . var_export($categories, true) . ";\n?>");
  38. highlight_string("\n<?php\n\$category_nicknames =\n" . var_export($category_nicknames, true) . ";\n?>");
  39.  
  40. echo '</div><!-- /.cds.debug -->';
  41. }
  42.  
  43. }
  44. add_action('wp_footer','cds_add_to_footer');
Add Comment
Please, Sign In to add comment