Skip to content
Snippets Groups Projects
Commit f0fdf6a8 authored by Erick Hitter's avatar Erick Hitter
Browse files

Allow meta to be edited via REST API

parent 744cbf7c
Branches
Tags
1 merge request!14Add native block-editor support
......@@ -22,16 +22,16 @@ const View = ( { setTarget, setType, target, type } ) => {
'To restore the original permalink, remove the link entered above.',
'external-permalinks-redux'
) }
onChange={ setTarget }
type="url"
value={ target }
onChange={ setTarget }
/>
<SelectControl
label={ __( 'Redirect Type:', 'external-permalinks-redux' ) }
options={ statusCodes }
selected={ type }
onChange={ setType }
options={ statusCodes }
value={ type }
/>
</>
);
......
......@@ -42,6 +42,7 @@ class External_Permalinks_Redux_Block_Editor {
*/
protected function _setup() {
add_action( 'rest_api_init', array( $this, 'register_meta' ) );
add_filter( 'is_protected_meta', array( $this, 'allow_meta_updates' ), 10, 3 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue' ) );
}
......@@ -93,6 +94,29 @@ class External_Permalinks_Redux_Block_Editor {
);
}
/**
* Allow meta updates from REST API.
*
* @param bool $protected Whether meta is protected or not.
* @param string $meta_key Meta key.
* @param string $meta_type Meta key type.
* @return bool
*/
public function allow_meta_updates( $protected, $meta_key, $meta_type ) {
if ( 'post' !== $meta_type ) {
return $protected;
}
if (
$meta_key === external_permalinks_redux::get_instance()->meta_key_target
|| $meta_key === external_permalinks_redux::get_instance()->meta_key_type
) {
return false;
}
return $protected;
}
/**
* Enqueue block-editor script.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment