Created
October 11, 2017 06:10
-
-
Save jaylong255/a7a86b497d7d4d748971a1bd9b74edde to your computer and use it in GitHub Desktop.
wp-rest
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
/* | |
honestly, i only use wp-rest now for ajax, so mine would actually look somehting like this: | |
*/ | |
add_action('rest_api_init',function($server){ | |
register_rest_route('my-plugin/v1','/add-email',array( | |
'methods' => 'POST', | |
'callback' => array($this,'add_email') //and i use class-based name-spacing and auto-loading as you can see | |
) ); | |
}); | |
// then we do the work down here in the function (this generic method is fine because it's inside a class) | |
public function add_email(){ | |
// in here we would get our post data by accessing $_POST vars | |
// we would then call the acf function for update_field() i forget what it actually is | |
$field = update_field($some_id,$_POST['field']); | |
return $field; // at least true or false, probably an id value for true | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment