Additional menu

Get MemberPress today! Start getting paid for the content you create! Get MemberPress Now
  1. Home
  2. Knowledge Base
  3. Advanced Topics
  4. Developer Tools
  5. How To Add User Meta via Rest API (Developer Tools)

How To Add User Meta via Rest API (Developer Tools)

MemberPress Developer Tools add-on allows you to add or update user meta via your REST requests.

But first, you must modify and add the following script to your site. Change the list of allowed keys to match the keys you need:

function define_mepr_api_usermeta_keys($allowed_keys, $user) {
  $allowed_keys['mepr_birthday'] = 'mepr_birthday';
  $allowed_keys['mepr_company'] = 'mepr_company';
  $allowed_keys['any_user_meta_you_need_here'] = 'any_user_meta_you_need_here';
  return $allowed_keys;
}
add_filter('mepr_developer_tools_member_valid_user_metas', 'define_mepr_api_usermeta_keys', 11, 2);

We recommend putting this into something like the WPCode plugin (please check this article for details: How to add custom code snippets in WPCode), or if you're using a child theme, then the functions.php file should work as well.

Once the keys are defined, you can then send these keys as parameters in your Create/Update Member requests.

$ curl -X POST "http://yourdomain.com/wp-json/mp/v1/members" \
       -H "MEMBERPRESS-API-KEY: API-KEY-HERE" \
       -d email="zapier@test.com" \
       -d username="zapier@test.com" \
       -d first_name=Zapier \
       -d last_name=test \
       -d mepr_birthday="12/22/1989"  \
       -d mepr_company="Walmart" \
       -d any_user_meta_you_need_here="Some Value Here"
Was this article helpful?

Related Articles

computer girl

Get MemberPress today!

Start getting paid for the content you create.