From 79c5bec1cad4154e96dc9d87235e726f44510f46 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sat, 11 Jun 2022 18:10:27 -0700
Subject: [PATCH] Localize script with all configurable options.

---
 external-permalinks-redux.php                 | 20 +++++++++++--------
 ...external-permalinks-redux-block-editor.php | 13 ++++++++++++
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/external-permalinks-redux.php b/external-permalinks-redux.php
index 7af66bf..f0d8d79 100644
--- a/external-permalinks-redux.php
+++ b/external-permalinks-redux.php
@@ -180,20 +180,24 @@ class external_permalinks_redux {
 			return;
 		}
 
-		foreach ( $this->post_types as $post_type ) {
-			if (
-				function_exists( 'use_block_editor_for_post_type' )
-				&& use_block_editor_for_post_type( $post_type )
-			) {
-				return;
-			}
+		$this->post_types = array_flip( $this->post_types );
 
+		foreach ( array_keys( $this->post_types ) as $post_type ) {
 			$title = apply_filters( 'epr_metabox_title', '', $post_type );
 
-			if ( ! $title ) {
+			if ( empty( $title ) ) {
 				$title = __( 'External Permalinks Redux', 'external-permalinks-redux' );
 			}
 
+			$this->post_types[ $post_type ] = $title;
+
+			if (
+				function_exists( 'use_block_editor_for_post_type' )
+				&& use_block_editor_for_post_type( $post_type )
+			) {
+				continue;
+			}
+
 			add_meta_box( 'external-permalinks-redux', $title, array( $this, 'meta_box' ), $post_type, 'normal' );
 
 			unset( $title );
diff --git a/inc/class-external-permalinks-redux-block-editor.php b/inc/class-external-permalinks-redux-block-editor.php
index 93a9f25..2feb7ee 100644
--- a/inc/class-external-permalinks-redux-block-editor.php
+++ b/inc/class-external-permalinks-redux-block-editor.php
@@ -66,5 +66,18 @@ class External_Permalinks_Redux_Block_Editor {
 			$asset_data['version'],
 			true
 		);
+
+		wp_localize_script(
+			$asset_handle,
+			'externalPermalinksReduxConfig',
+			array(
+				'metaKeys'    => array(
+					'target' => external_permalinks_redux::get_instance()->meta_key_target,
+					'type'   => external_permalinks_redux::get_instance()->meta_key_type,
+				),
+				'postTypes'   => external_permalinks_redux::get_instance()->post_types,
+				'statusCodes' => external_permalinks_redux::get_instance()->status_codes,
+			)
+		);
 	}
 }
-- 
GitLab