mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-07 08:07:16 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -41,11 +41,13 @@ abstract class WP_REST_Meta_Fields {
|
||||
* @see register_rest_field()
|
||||
*/
|
||||
public function register_field() {
|
||||
register_rest_field( $this->get_rest_field_type(), 'meta', array(
|
||||
'get_callback' => array( $this, 'get_value' ),
|
||||
'update_callback' => array( $this, 'update_value' ),
|
||||
'schema' => $this->get_field_schema(),
|
||||
));
|
||||
register_rest_field(
|
||||
$this->get_rest_field_type(), 'meta', array(
|
||||
'get_callback' => array( $this, 'get_value' ),
|
||||
'update_callback' => array( $this, 'update_value' ),
|
||||
'schema' => $this->get_field_schema(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +64,7 @@ abstract class WP_REST_Meta_Fields {
|
||||
$response = array();
|
||||
|
||||
foreach ( $fields as $meta_key => $args ) {
|
||||
$name = $args['name'];
|
||||
$name = $args['name'];
|
||||
$all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false );
|
||||
if ( $args['single'] ) {
|
||||
if ( empty( $all_values ) ) {
|
||||
@@ -174,7 +176,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
'rest_cannot_delete',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -182,7 +187,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not delete meta value from database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -209,7 +217,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
'rest_cannot_update',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -244,7 +255,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -254,7 +268,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -275,12 +292,15 @@ abstract class WP_REST_Meta_Fields {
|
||||
*/
|
||||
protected function update_meta_value( $object_id, $meta_key, $name, $value ) {
|
||||
$meta_type = $this->get_meta_type();
|
||||
if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) {
|
||||
if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) {
|
||||
return new WP_Error(
|
||||
'rest_cannot_update',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -300,7 +320,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -342,7 +365,7 @@ abstract class WP_REST_Meta_Fields {
|
||||
'default' => isset( $args['default'] ) ? $args['default'] : null,
|
||||
);
|
||||
|
||||
$rest_args = array_merge( $default_args, $rest_args );
|
||||
$rest_args = array_merge( $default_args, $rest_args );
|
||||
$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
|
||||
|
||||
$type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null;
|
||||
@@ -356,7 +379,7 @@ abstract class WP_REST_Meta_Fields {
|
||||
$rest_args['schema']['items'] = array(
|
||||
'type' => $rest_args['type'],
|
||||
);
|
||||
$rest_args['schema']['type'] = 'array';
|
||||
$rest_args['schema']['type'] = 'array';
|
||||
}
|
||||
|
||||
$registered[ $name ] = $rest_args;
|
||||
|
||||
Reference in New Issue
Block a user