diff --git a/assets/src/js/panel-body.js b/assets/src/js/panel-body.js index 3bbc8c15297ecc6d76ae0b8de0d6072706a58081..6ed214cf8d5d795c16dd97b2b3623a5b857cc183 100644 --- a/assets/src/js/panel-body.js +++ b/assets/src/js/panel-body.js @@ -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 } /> </> ); diff --git a/inc/class-external-permalinks-redux-block-editor.php b/inc/class-external-permalinks-redux-block-editor.php index c3720dc2813f46bc7da9a1856f7d63fe1f05f295..c02f3bf4c37f2ca1351253eef97101e87c21efdd 100644 --- a/inc/class-external-permalinks-redux-block-editor.php +++ b/inc/class-external-permalinks-redux-block-editor.php @@ -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. *