diff --git a/inc/class-external-permalinks-redux-block-editor.php b/inc/class-external-permalinks-redux-block-editor.php index 2feb7ee97a79c0dec33b6bea39666b6f5e32c1a5..b6b737cebeebd3b9a70ca61c3f4b7fbce61eba19 100644 --- a/inc/class-external-permalinks-redux-block-editor.php +++ b/inc/class-external-permalinks-redux-block-editor.php @@ -41,9 +41,59 @@ class External_Permalinks_Redux_Block_Editor { * @return void */ protected function _setup() { + add_action( 'rest_api_init', array( $this, 'register_meta' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue' ) ); } + /** + * Register meta for access in block editor. + * + * @return void + */ + public function register_meta() { + global $wp_version; + + if ( + ! function_exists( 'register_meta' ) + || version_compare( $wp_version, '4.6.0', '<' ) + ) { + return; + } + + register_meta( + 'post', + external_permalinks_redux::get_instance()->meta_key_target, + array( + 'default' => '', + 'description' => __( + 'Redirect destination', + 'external-permalinks-redux' + ), + 'type' => 'string', + 'sanitize_callback' => 'esc_url_raw', + 'show_in_rest' => true, + 'single' => true, + ) + ); + + register_meta( + 'post', + external_permalinks_redux::get_instance()->meta_key_type, + array( + // Matches fallback in `external_permalinks_redux::get_redirect_data()` + 'default' => 302, + 'description' => __( + 'Redirect status code', + 'external-permalinks-redux' + ), + 'type' => 'integer', + 'sanitize_callback' => 'absint', + 'show_in_rest' => true, + 'single' => true, + ) + ); + } + /** * Enqueue block-editor script. *