Skip to content
This repository has been archived by the owner on Aug 14, 2019. It is now read-only.

Support for private option mappings #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lib/class-wp-rest-site-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would just be the edit context, as it's private information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbachhuber OK for some reason I was thinking that we would expose these in GET requests too if the user was authenticated with the proper capability.

'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',
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*
Expand All @@ -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;
}

Expand Down