diff --git a/.dev/tests/php/test-title-meta.php b/.dev/tests/php/test-title-meta.php index 01f49066..518e679f 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', diff --git a/includes/title-meta.php b/includes/title-meta.php index 07c4e490..ce8764a6 100644 --- a/includes/title-meta.php +++ b/includes/title-meta.php @@ -20,16 +20,24 @@ function setup() { add_filter( 'go_page_title_args', $n( 'hide_page_title' ) ); - register_meta( - 'post', - 'hide_page_title', - array( - 'sanitize_callback' => $n( 'hide_page_title_callback' ), - 'type' => 'string', - 'description' => __( 'Hide Page Title.', 'go' ), - 'show_in_rest' => true, - 'single' => true, - ) + add_action( + 'rest_api_init', + /** + * Register the meta field for the REST API. + */ + 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, + ) + ); + } ); }