brasofilo

SO 23866327

Jun 22nd, 2014
212
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('admin_menu', 'add_auxiliary_menu');
  2. add_action("wp_ajax_callbackFunction","callbackFunction");
  3. add_action("wp_ajax_nopriv_callbackFunction","callbackFunction");
  4.  
  5. function add_auxiliary_menu()
  6. {
  7.     add_menu_page(
  8.         'TB',
  9.         '<span style="color:#e57300;">Thickbox</span>',
  10.         'edit_pages',
  11.         'thickbox-press-this',
  12.         'menu_page_content',
  13.         '', // icon default for empty
  14.         1  // create before Dashboard menu item
  15.     );
  16. }
  17.  
  18. function menu_page_content()
  19. {
  20.     ?>
  21.     <div id="icon-post" class="icon32"></div>
  22.     <h2>Press-This in a Thickbox</h2>
  23.  
  24.     <div style="width:50%; padding: 5px;" class="updated" >
  25.         <p><a class="button-secondary" href="#" id="open-tb"><?php _e( 'Press not this' ); ?></a></p>
  26.     </div>
  27.     <p><?php echo_users(false); ?></p>
  28.     <script type="text/javascript">
  29.     jQuery(document).ready(function($) {  
  30.         $("#open-tb").click(function() {                
  31.             $.post("<?php echo admin_url("admin-ajax.php"); ?>", {"action": "callbackFunction"}, function(response) {
  32.                 console.dir(response);
  33.             });
  34.         });
  35.     });            
  36.     </script>
  37.     <?php
  38. }
  39.  
  40. function callbackFunction(){
  41.     echo_users();
  42.     die();
  43. }
  44.  
  45. function echo_users($ajax=true)
  46. {
  47.     $blogusers = get_users();
  48.     $br = $ajax ? '|' : '<br/>';
  49.     foreach ($blogusers as $user) {
  50.         echo $user->user_email.$br;
  51.     }
  52. }
RAW Paste Data