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
No related branches found
No related tags found
1 merge request!14Add native block-editor support
...@@ -22,16 +22,16 @@ const View = ( { setTarget, setType, target, type } ) => { ...@@ -22,16 +22,16 @@ const View = ( { setTarget, setType, target, type } ) => {
'To restore the original permalink, remove the link entered above.', 'To restore the original permalink, remove the link entered above.',
'external-permalinks-redux' 'external-permalinks-redux'
) } ) }
onChange={ setTarget }
type="url" type="url"
value={ target } value={ target }
onChange={ setTarget }
/> />
<SelectControl <SelectControl
label={ __( 'Redirect Type:', 'external-permalinks-redux' ) } label={ __( 'Redirect Type:', 'external-permalinks-redux' ) }
options={ statusCodes }
selected={ type }
onChange={ setType } onChange={ setType }
options={ statusCodes }
value={ type }
/> />
</> </>
); );
......
...@@ -42,6 +42,7 @@ class External_Permalinks_Redux_Block_Editor { ...@@ -42,6 +42,7 @@ class External_Permalinks_Redux_Block_Editor {
*/ */
protected function _setup() { protected function _setup() {
add_action( 'rest_api_init', array( $this, 'register_meta' ) ); 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' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue' ) );
} }
...@@ -93,6 +94,29 @@ class External_Permalinks_Redux_Block_Editor { ...@@ -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. * Enqueue block-editor script.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment