Skip to content

Instantly share code, notes, and snippets.

View okrg's full-sized avatar
🏠
Working from home

Rolo okrg

🏠
Working from home
View GitHub Profile
@scottopolis
scottopolis / wp-api-user-meta.php
Last active April 18, 2020 19:13
Add user meta to the WP-API
<?php
/* Adds all user meta to the /wp-json/wp/v2/user/[id] endpoint */
function sb_user_meta( $data, $field_name, $request ) {
if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] );
}
if ( !$user_meta ) {
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
}
(function($){
var url = JP_POST_EDITOR.root;
url += '/posts';
function getPostsByUser( defaultID ) {
url += '?filter[author]=';
url += JP_POST_EDITOR.userID;
url += '&filter[posts_per_page]=20';
$.ajax({