From 23fa1a30aef4cbbaa673178a64df912d185d05a2 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 14:31:19 -0400 Subject: [PATCH 1/7] Fix where register_meta is hooked --- includes/title-meta.php | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/includes/title-meta.php b/includes/title-meta.php index 07c4e490d..2a9447b37 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -20,11 +20,34 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); + add_action( 'rest_api_init', $n( 'register_meta' ) ); + +} + +function register_meta() { + register_meta( 'post', 'hide_page_title', array( - 'sanitize_callback' => $n( 'hide_page_title_callback' ), + /** + * Hide page title meta callback + * + * @param string $status Hide page title status (eg: enable, disabled). + * + * @return string Whether or not the page title should be enabled or not. + */ + 'sanitize_callback' => function( $status ) { + $status = strtolower( trim( $status ) ); + + if ( ! in_array( $status, array( 'enabled', 'disabled' ), true ) ) { + + $status = ''; + + } + + return $status; + }, 'type' => 'string', 'description' => __( 'Hide Page Title.', 'go' ), 'show_in_rest' => true, @@ -34,27 +57,6 @@ function setup() { } -/** - * Hide page title meta callback - * - * @param string $status Hide page title status (eg: enable, disabled). - * - * @return string Whether or not the page title should be enabled or not. - */ -function hide_page_title_callback( $status ) { - - $status = strtolower( trim( $status ) ); - - if ( ! in_array( $status, array( 'enabled', 'disabled' ), true ) ) { - - $status = ''; - - } - - return $status; - -} - /** * Hide page title box * From d2edb805bf7eeafbc7a1195bcda1e0631e09d897 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 14:49:48 -0400 Subject: [PATCH 2/7] Refactor --- includes/title-meta.php | 62 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/includes/title-meta.php b/includes/title-meta.php index 2a9447b37..7e4afc55c 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -20,40 +20,40 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); - add_action( 'rest_api_init', $n( 'register_meta' ) ); + add_action( 'rest_api_init', function() { + register_meta( + 'post', + 'hide_page_title', + array( + 'sanitize_callback' => 'Go\Title_Meta\hide_page_title_callback', + 'type' => 'string', + 'description' => __( 'Hide Page Title.', 'go' ), + 'show_in_rest' => true, + 'single' => true, + ) + ); + } ); } -function register_meta() { - - register_meta( - 'post', - 'hide_page_title', - array( - /** - * Hide page title meta callback - * - * @param string $status Hide page title status (eg: enable, disabled). - * - * @return string Whether or not the page title should be enabled or not. - */ - 'sanitize_callback' => function( $status ) { - $status = strtolower( trim( $status ) ); - - if ( ! in_array( $status, array( 'enabled', 'disabled' ), true ) ) { - - $status = ''; - - } - - return $status; - }, - 'type' => 'string', - 'description' => __( 'Hide Page Title.', 'go' ), - 'show_in_rest' => true, - 'single' => true, - ) - ); +/** + * Hide page title meta callback + * + * @param string $status Hide page title status (eg: enable, disabled). + * + * @return string Whether or not the page title should be enabled or not. + */ +function hide_page_title_callback( $status ) { + + $status = strtolower( trim( $status ) ); + + if ( ! in_array( $status, array( 'enabled', 'disabled' ), true ) ) { + + $status = ''; + + } + + return $status; } From ff61ac9edd62a67e94456df7177ccd90cb9de27f Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 14:52:14 -0400 Subject: [PATCH 3/7] Refactor --- includes/title-meta.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/includes/title-meta.php b/includes/title-meta.php index 7e4afc55c..8b8b5a68c 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -20,19 +20,22 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); - add_action( 'rest_api_init', function() { - register_meta( - 'post', - 'hide_page_title', - array( - 'sanitize_callback' => 'Go\Title_Meta\hide_page_title_callback', - 'type' => 'string', - 'description' => __( 'Hide Page Title.', 'go' ), - 'show_in_rest' => true, - 'single' => true, - ) - ); - } ); + add_action( + 'rest_api_init', + function() { + register_meta( + 'post', + 'hide_page_title', + array( + 'sanitize_callback' => 'Go\Title_Meta\hide_page_title_callback', + 'type' => 'string', + 'description' => __( 'Hide Page Title.', 'go' ), + 'show_in_rest' => true, + 'single' => true, + ) + ); + } + ); } From 999c1d6630c173ae9cabe047a8cdf44d16b3dfc2 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 14:53:05 -0400 Subject: [PATCH 4/7] Add doc comment for register_meta --- includes/title-meta.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/title-meta.php b/includes/title-meta.php index 8b8b5a68c..ce8764a66 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -22,6 +22,9 @@ function setup() { add_action( 'rest_api_init', + /** + * Register the meta field for the REST API. + */ function() { register_meta( 'post', From f0e6fb2aaf475c3178343d3f74bbe6238e6d0f2a Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 15:05:19 -0400 Subject: [PATCH 5/7] Update test --- .dev/tests/php/test-title-meta.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dev/tests/php/test-title-meta.php b/.dev/tests/php/test-title-meta.php index 01f49066a..518e679fa 100644 --- a/.dev/tests/php/test-title-meta.php +++ b/.dev/tests/php/test-title-meta.php @@ -61,6 +61,8 @@ function test_hide_page_title_non_page() { */ function test_hide_page_title_callback() { + do_action( 'rest_api_init' ); + $post_title_visible = $this->factory->post->create( [ 'post_title' => 'Show Post title', From d11027cca57a43cc76dfbe40b741f9e2ed5983c5 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 15:06:37 -0400 Subject: [PATCH 6/7] Retrigger test --- includes/title-meta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/title-meta.php b/includes/title-meta.php index ce8764a66..fbf5703fd 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -21,7 +21,7 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); add_action( - 'rest_api_init', + 'rest_api_init', /** * Register the meta field for the REST API. */ From 4afd5b4dd6a8b887ff870a97692cb18f9853c7d1 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 8 Apr 2025 15:06:46 -0400 Subject: [PATCH 7/7] Retrigger test --- includes/title-meta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/title-meta.php b/includes/title-meta.php index fbf5703fd..ce8764a66 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -21,7 +21,7 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); add_action( - 'rest_api_init', + 'rest_api_init', /** * Register the meta field for the REST API. */