egeo
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: Adding a button in admin bar for POST-ing json dataI 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)