| 1 | <?php |
|---|
| 2 | require 'wp-load.php'; |
|---|
| 3 | |
|---|
| 4 | add_action('wp_ajax_mysettings_save' , 'mysettings_save'); |
|---|
| 5 | |
|---|
| 6 | function mysettings_save() { |
|---|
| 7 | //DO SOMETHING USEFULL HERE |
|---|
| 8 | exit('It worked!'); |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | ?> |
|---|
| 12 | <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> |
|---|
| 13 | <form> |
|---|
| 14 | <p><input type="text" name="my_settings_field" value=""></p> |
|---|
| 15 | <button>Save</button> |
|---|
| 16 | <?php settings_fields('my_settings'); ?> |
|---|
| 17 | </form> |
|---|
| 18 | <script> |
|---|
| 19 | $('form').submit(function(event){ |
|---|
| 20 | event.preventDefault(); |
|---|
| 21 | |
|---|
| 22 | $.post('wp-admin/admin-ajax.php?action=mysettings_save', $(this).serialize(), function(data){ console.log(data); }); |
|---|
| 23 | }); |
|---|
| 24 | </script> |
|---|