Title: Adding a button in admin bar for POST-ing json data
Last modified: August 22, 2016

---

# Adding a button in admin bar for POST-ing json data

 *  Resolved [egeo](https://wordpress.org/support/users/egeo/)
 * (@egeo)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/adding-a-button-in-admin-bar-for-post-ing-json-data/)
 * Hello all,
 * Is there a way to add a json-POST button into wp admin bar. Up to now I ve found
   methods like add_menu and add_node but I still havent found a way to add the 
   POST code somewhere as an argument.
 * Any help is really appreciated – thank you in advance for your time

Viewing 1 replies (of 1 total)

 *  Thread Starter [egeo](https://wordpress.org/support/users/egeo/)
 * (@egeo)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/adding-a-button-in-admin-bar-for-post-ing-json-data/#post-5365360)
 * I found a way:
 * I used a plugin to set the button on the upper part of wp-admin page with add_node(
   $args). Used the function ‘wp_enqueue_script’ and hook ‘admin_enqueue_scripts’.
   Then added a js folder within my plugin file containing the appropriate js file
   to take the input of a hypothetical form and post it.
 * PHP FUNCTIONS
 *     ```
       function my_jsonpost_script() {
       	wp_enqueue_script(
       		'submitform',
       		plugins_url() . '/admin-button-plugin/js/jsonpost.js',
       		array( 'jquery' )
       	);
       }
   
       add_action( 'admin_enqueue_scripts', 'my_jsonpost_script' );
   
       function custom_button_example($wp_admin_bar){
       $args = array(
       'id' => 'custom-button',
       'title' => 'Custom Button',
       'href' => '#',
       'meta' => array(
       'class' => 'custom-button-class'
       )
       );
       $wp_admin_bar->add_node($args);
       ```
   
 * JS FILE
 *     ```
       (function($) {
         $(document).ready(function(){
   
           $("a.ab-item").click(function(){
   
       	var url = '/users/' + $('#user_id').val();
           $('#myform').attr('action', url);
           var data = JSON.stringify({
               "userdata": $('#user_data').val()
           })
           $('<input type="hidden" name="json"/>').val(data).appendTo('#myform');
           $("#myform").submit();
   
             window.alert(data);
             return false;
           })
        });
       }(jQuery));
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Adding a button in admin bar for POST-ing json data’ is closed to new
replies.

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [json](https://wordpress.org/support/topic-tag/json/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * 1 reply
 * 1 participant
 * Last reply from: [egeo](https://wordpress.org/support/users/egeo/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/adding-a-button-in-admin-bar-for-post-ing-json-data/#post-5365360)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
