From 379587d4bc28a67265cba6a1f1014641ea6e6d2a Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Mon, 1 Feb 2016 16:00:03 -0600 Subject: [PATCH] Initial support for private mappings --- lib/class-wp-rest-site-controller.php | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-site-controller.php b/lib/class-wp-rest-site-controller.php index dea1d96..3eca646 100644 --- a/lib/class-wp-rest-site-controller.php +++ b/lib/class-wp-rest-site-controller.php @@ -116,11 +116,25 @@ public function get_item_schema() { 'format' => 'uri', 'context' => array( 'view', 'edit' ), ), + 'admin_email' => array( + 'description' => __( 'Email Address' ), + 'type' => 'string', + 'format' => 'email', + 'context' => array( 'view', 'edit' ), + 'arg_options' => array( + 'sanitize_callback' => 'sanitize_email', + ), + ), 'users_can_register' => array( 'description' => __( 'Membership' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), ), + 'default_role' => array( + 'description' => __( 'New User Default Role' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + ), 'timezone_string' => array( 'description' => __( 'Timezone' ), 'type' => 'string', @@ -184,7 +198,7 @@ public function get_collection_params() { } /** - * Return an array of option name mappings + * Return an array of public option name mappings * * @return array */ @@ -206,6 +220,18 @@ public function get_item_mappings() { ); } + /** + * Return an array of private option name mappings + * + * @return array + */ + public function get_private_item_mappings() { + return array( + 'admin_email' => 'admin_email', + 'default_role' => 'default_role', + ); + } + /** * Return the mapped option name * @@ -215,6 +241,10 @@ public function get_item_mappings() { public function get_item_mapping( $option_name ) { $mappings = $this->get_item_mappings(); + if ( current_user_can( 'manage_options' ) ) { + $mappings = array_merge( $mappings, $this->get_private_item_mappings() ); + } + return isset( $mappings[ $option_name ] ) ? $mappings[ $option_name ] : false; }