Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2. function cfgeo_settings_javascript() { ?>
  3. <script type="text/javascript" >
  4. (function($){
  5. $(document).ready(function(){
  6. $("input[id^='cf_geo_'], select[id^='cf_geo_'], textarea[id^='cf_geo_']").on("change keyup", function(){
  7. var This = $(this),
  8. name = This.attr("name"),
  9. value = This.val(),
  10. data = {};
  11.  
  12. data['action'] = 'cfgeo_settings';
  13. data[name] = value;
  14.  
  15. console.log(data);
  16. console.log(ajaxurl);
  17.  
  18. $.post(ajaxurl, data).done(function(returns){
  19. console.log(returns);
  20. });
  21. });
  22. });
  23. }(window.jQuery));
  24. </script> <?php
  25. }
  26. add_action( 'admin_footer', 'cfgeo_settings_javascript');
  27.  
  28. function cfgeo_settings_callback() {
  29. global $wpdb; // this is how you get access to the database
  30. var_dump($_POST);
  31. if (isset($_POST)) {
  32. // Do the saving
  33. $front_page_elements = array();
  34. $updates=array();
  35. foreach($_POST as $key=>$val){
  36. if($key != 'cfgeo_settings')
  37. update_option($key, esc_attr($val));
  38. }
  39. echo 'true';
  40. }
  41. else
  42. echo 'false';
  43.  
  44. wp_die(); // this is required to terminate immediately and return a proper response
  45. }
  46. add_action( 'wp_ajax_cfgeo_settings', 'cfgeo_settings_callback');
  47. ?>
  48.  
  49. Object {action: "cfgeo_settings", cf_geo_enable_ssl: "true"}
  50. admin.php?page=cf-geoplugin-settings:1733 /wp-admin/admin-ajax.php
  51. admin.php?page=cf-geoplugin-settings:1736 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement