From cc9f7f081de67cbc9cad323efbe3cb4d4804ffe5 Mon Sep 17 00:00:00 2001 From: r-a-y Date: Thu, 8 Oct 2020 18:01:08 -0700 Subject: [PATCH 1/2] Add 'auth_callback' argument to register_meta(). Because the 'unpublish_timestamp' meta key is marked as protected, no one is able to able to update the unpublish timestamp by default. This commit adds the 'auth_callback' argument and uses current_user_can( 'edit_posts' ) to determine whether the current user can update the unpublish timestamp. --- inc/post-meta.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/inc/post-meta.php b/inc/post-meta.php index 1e7cfbb..974ac81 100644 --- a/inc/post-meta.php +++ b/inc/post-meta.php @@ -28,10 +28,13 @@ function register_meta( string $post_type ) : void { } register_post_meta( $post_type, Unpublish\POST_META_KEY, [ - 'description' => __( 'Unpublish time', 'unpublish' ), - 'show_in_rest' => true, - 'single' => true, - 'type' => 'integer', + 'description' => __( 'Unpublish time', 'unpublish' ), + 'show_in_rest' => true, + 'single' => true, + 'type' => 'integer', + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, ] ); } From 7fc7296b232cda0404df66f3edf77a0ebc6c29a1 Mon Sep 17 00:00:00 2001 From: r-a-y Date: Thu, 8 Oct 2020 18:11:13 -0700 Subject: [PATCH 2/2] Remove whitespace. --- inc/post-meta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/post-meta.php b/inc/post-meta.php index 974ac81..0374a62 100644 --- a/inc/post-meta.php +++ b/inc/post-meta.php @@ -32,7 +32,7 @@ function register_meta( string $post_type ) : void { 'show_in_rest' => true, 'single' => true, 'type' => 'integer', - 'auth_callback' => function () { + 'auth_callback' => function() { return current_user_can( 'edit_posts' ); }, ] );