[wp-hackers] jQuery x-editable with update_user_meta?

J.D. Grimes jdg at codesymphony.co
Sun Oct 27 19:32:38 UTC 2013


Yes, this is possible. A very basic example of how you would handle the request with PHP is here https://github.com/vitalets/x-editable/blob/gh-pages/backend-samples/php/post.php

You will need to fill in the value for pk in your JS, which means you'll need to pull the ID from the database and use wp_localize_script() to pass it on to the JS. Here is an example function (based on this http://wpseek.com/blog/2010/how-to-get-the-meta-id-by-meta-key/80/) to pull the meta id from the database:

function get_user_mid_by_key( $user_id, $meta_key ) {
  global $wpdb;
  $mid = $wpdb->get_var( $wpdb->prepare("SELECT meta_id FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
  if( $mid != '' )
    return (int)$mid;
 
  return false;
}

Then when the request comes in you can use update_metadata_by_mid() (http://wpseek.com/update_metadata_by_mid/) to update the value in the database.

-J.D.

On Oct 26, 2013, at 10:22 PM, BenderisGreat <greglancaster71 at gmail.com> wrote:

> Looking to use this jQuery plugin with an update_user_meta option on a
> profile page.  Ex. would be click your location, or mood and it allows for
> inline editing and updating.  It uses a unique ajaxOptions setting that I
> cant seem to get working with wordpress. 
> 
> http://vitalets.github.io/x-editable/index.html
> <http://vitalets.github.io/x-editable/index.html>   - the x-editable plugin
> 
> http://jsfiddle.net/xBB5x/62/ <http://jsfiddle.net/xBB5x/62/>   - JSFiddle
> of x-editable working outside wordpress - but unsure how it would work
> within WP.
> 
> Mostly looking for someone to verify if this would work, and explain how the
> data would be passed (for example the 'pk' field looks for a row in the DB,
> maybe it would be possible to substiture that with something different? 
> That or pk needs to be redefined I think? 
> 
> 
> 
> --
> View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/jQuery-x-editable-with-update-user-meta-tp42641.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list