Last active
February 3, 2020 08:10
-
-
Save JudeRosario/5ee991e5301e27e8239d to your computer and use it in GitHub Desktop.
BuddyPress update xProfile via AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready( function() { | |
jQuery("#appointment-edit-form-submit").click( function() { | |
// THIS CAUSED THE ERRORS | |
app_email = jQuery(this).attr("app_email") | |
app_phone = jQuery(this).attr("app_phone") | |
jQuery.ajax({ | |
type : "post", | |
dataType : "json", | |
url : localhost://wp-admin/admin-ajax.php?action=save_xprofile, | |
data : {action: "save_xprofile", app_email : app_email, app_phone: app_phone}, | |
success: function(response) { | |
if(response.type == "success") { | |
alert("Settings are updated") | |
} | |
else { | |
alert("Settings not updated") | |
} | |
} | |
}) | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function edit_appointment_settings_xprofile(){ | |
$profileuser = wp_get_current_user(); | |
?> | |
<h3><?php _e("Appointments+ Settings", 'appointments'); ?></h3> | |
<form method="post" action =" "id="appointment-edit-form" class="standard-form"> | |
<table class="form-table"> | |
<tr> | |
<th><label><?php _e("My email for A+", 'appointments'); ?></label></th> | |
<td> | |
<input type="text" style="width:25em" name="app_email" value="<?php echo get_user_meta( $profileuser->ID, 'app_email', true ) ?>" <?php echo $is_readonly ?> /> | |
</td> | |
</tr> | |
<tr> | |
<th><label><?php _e("My Phone", 'appointments'); ?></label></th> | |
<td> | |
<input type="text" style="width:25em" name="app_phone" value="<?php echo get_user_meta( $profileuser->ID, 'app_phone', true ) ?>"<?php echo $is_readonly ?> /> | |
</td> | |
</tr> | |
<input name="action" type="hidden" value="save_xprofile" /> | |
</table> | |
<div class="submit"> | |
<input type="submit" name="appointment-edit-form-submit" id="appointment-edit-form-submit" value="Save" /> | |
</div> | |
<script type="text/javascript"> | |
</script> | |
<? | |
} | |
function save_appointment_settings_xprofile(){ | |
$profileuser = wp_get_current_user(); | |
if ( isset( $_POST['app_email'] ) ) | |
update_user_meta( $profileuser->ID, 'app_email', $_POST['app_email'] ); | |
if ( isset( $_POST['app_phone'] ) ) | |
update_user_meta( $profileuser->ID, 'app_phone', $_POST['app_phone'] ); | |
die(); | |
} | |
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( __FILE__ ) . 'ajax.js', array( 'jquery' ) ); | |
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); | |
add_action('wp_ajax_save_xprofile', 'save_appointment_settings_xprofile'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment