From a65353de3afa90683e9721ee294da376bf60a423 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Thu, 21 May 2020 13:06:58 -0400
Subject: [PATCH 1/9] Copy in Largo's metabox function file, which will cause
errors for its reliance upon largo_add_meta_box and largo_register_meta_input
---
functions.php | 5 ++++-
library/metabox-subhead.php | 45 +++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 library/metabox-subhead.php
diff --git a/functions.php b/functions.php
index d825b94..6f6869f 100755
--- a/functions.php
+++ b/functions.php
@@ -56,6 +56,9 @@
/** Customizer Additions */
require_once( 'library/bs-customizer-additions.php' );
+/** The "Subhead" metabox and related functions */
+require_once( 'library/metabox-subhead.php' );
+
/** Required and Recommended Plugins */
require_once( 'library/class-tgm-plugin-activation.php' );
require_once( 'library/bs-plugin-activation.php' );
@@ -142,4 +145,4 @@ function calhealth_post_bottom_widget_area() {
dynamic_sidebar( 'article-bottom' );
}
}
-add_action( 'calhealth_post_bottom_widget_area', 'calhealth_post_bottom_widget_area' );
\ No newline at end of file
+add_action( 'calhealth_post_bottom_widget_area', 'calhealth_post_bottom_widget_area' );
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
new file mode 100644
index 0000000..587fc05
--- /dev/null
+++ b/library/metabox-subhead.php
@@ -0,0 +1,45 @@
+ID );
+ wp_nonce_field( 'largo_meta_box_nonce', 'meta_box_nonce' );
+ ?>
+
+
+
+
Date: Fri, 22 May 2020 01:00:42 -0400
Subject: [PATCH 2/9] Test submission results in all the errors.
---
library/metabox-subhead.php | 58 ++++++++++++++++++++++++++++++-------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index 587fc05..3c6910f 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -11,7 +11,7 @@
function subtitle_meta_box_display() {
global $post;
$values = get_post_custom( $post->ID );
- wp_nonce_field( 'largo_meta_box_nonce', 'meta_box_nonce' );
+ wp_nonce_field( 'subtitle_meta_box_nonce', 'subtitle_meta_box_nonce' );
?>
Date: Fri, 22 May 2020 15:19:37 -0400
Subject: [PATCH 3/9] Pass correct number of vars to the post
---
library/metabox-subhead.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index 3c6910f..0f6ba4c 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -32,7 +32,7 @@ function subtitle_meta_box_display() {
* @param bool $update whether the post is being updated
* @return null
*/
-function subtitle_meta_box_save( $post_id, $post, $update ) {
+function subtitle_meta_box_save( $post_id, $post, $update = false ) {
if ( ! wp_verify_nonce( $_POST['subtitle_meta_box_nonce'], $_POST['subtitle_meta_box_nonce'] ) ) {
return;
}
@@ -60,7 +60,7 @@ function subtitle_meta_box_save( $post_id, $post, $update ) {
return $subtitle;
}
-add_action( 'save_post', 'subtitle_meta_box_save', 10, 2 );
+add_action( 'save_post', 'subtitle_meta_box_save', 10, 3 );
/**
* Register our subtitle metabox
From e8166c580c369d9e5356ca669f9d4094660d53f1 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Fri, 22 May 2020 17:34:40 -0400
Subject: [PATCH 4/9] Register the post meta, to see if that helps
---
library/metabox-subhead.php | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index 0f6ba4c..1122e65 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -3,6 +3,26 @@
* Functions related to meta boxes
*/
+/**
+ * Register the 'subtitle' post meta
+ */
+function subtitle_meta_box_register_post_meta() {
+ return register_post_meta(
+ 'post',
+ 'subtitle',
+ array(
+ 'object_subtype' => 'post',
+ 'type' => 'string',
+ 'description' => __( 'The subhead, deck, subtitle, or lead is a preface shown on article pages below the main title.' , 'allonsy' ),
+ 'single' => true,
+ 'sanitize_callback' => 'sanitize_textarea_field',
+ // 'auth_callback' => '',
+ 'show_in_rest' => true,
+ ),
+ );
+}
+add_action( 'init', 'subtitle_meta_box_register_post_meta' );
+
/**
* Output the subtitle metabox.
*
@@ -33,7 +53,13 @@ function subtitle_meta_box_display() {
* @return null
*/
function subtitle_meta_box_save( $post_id, $post, $update = false ) {
+ if ( ! isset( $_POST['subtitle_meta_box_nonce'] ) ) {
+ error_log(var_export( 'subtitle meta box nonce not set', true));
+ return;
+ }
+
if ( ! wp_verify_nonce( $_POST['subtitle_meta_box_nonce'], $_POST['subtitle_meta_box_nonce'] ) ) {
+ error_log(var_export( 'subtitle meta box nonce not valid', true));
return;
}
From 2a639c0858f90b7731c809c7172606c59c54af81 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Fri, 22 May 2020 17:35:06 -0400
Subject: [PATCH 5/9] Add subtitle debugging output on single.php
---
single.php | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/single.php b/single.php
index 010bd0e..eafee4d 100755
--- a/single.php
+++ b/single.php
@@ -28,6 +28,13 @@
id="post-">
+ %1$s
',
+ var_export( $subtitle, true )
+ );
+ ?>
From 51f136f8f3d7f6730a45d59a5b940d5b1c6292c2 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Tue, 2 Jun 2020 11:42:05 -0400
Subject: [PATCH 6/9] Remove logging from subhead
---
library/metabox-subhead.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index 1122e65..2d0dcc7 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -76,7 +76,6 @@ function subtitle_meta_box_save( $post_id, $post, $update = false ) {
}
$subtitle = wp_kses_post( $_POST['subtitle'] );
- error_log(var_export( $subtitle, true));
if ( ! empty( $subtitle ) ) {
update_post_meta( $post_id, 'subtitle', $subtitle );
From b15ec67980d918851a5789410e71a0d3e3e28fb6 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Tue, 2 Jun 2020 22:58:11 -0400
Subject: [PATCH 7/9] Fix the subtitle so it saves.
---
library/metabox-subhead.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index 2d0dcc7..db17de5 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -58,7 +58,7 @@ function subtitle_meta_box_save( $post_id, $post, $update = false ) {
return;
}
- if ( ! wp_verify_nonce( $_POST['subtitle_meta_box_nonce'], $_POST['subtitle_meta_box_nonce'] ) ) {
+ if ( ! wp_verify_nonce( $_POST['subtitle_meta_box_nonce'], 'subtitle_meta_box_nonce' ) ) {
error_log(var_export( 'subtitle meta box nonce not valid', true));
return;
}
From 56d746b49599c7948c0ca06fb557d0657e3cb2cf Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Tue, 2 Jun 2020 23:08:15 -0400
Subject: [PATCH 8/9] Output subtitle on single template
---
single.php | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/single.php b/single.php
index eafee4d..4fcd9a1 100755
--- a/single.php
+++ b/single.php
@@ -30,10 +30,17 @@
%1$s
',
- var_export( $subtitle, true )
- );
+ if ( ! empty( $subtitle ) ) {
+ // should be single value post meta, but if it isn't....
+ if ( is_array( $subtitle ) ) {
+ $subtitle = $subtitle[0];
+ }
+
+ printf(
+ '%1$s
',
+ esc_html( $subtitle ),
+ );
+ }
?>
From 9c9338ed10146adb4b7c823e5018fb29937ad303 Mon Sep 17 00:00:00 2001
From: Ben Keith
Date: Tue, 2 Jun 2020 23:22:15 -0400
Subject: [PATCH 9/9] visually hide the label for the form, correct
misconceptions about what isn't allowed in this meta field
---
library/metabox-subhead.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/library/metabox-subhead.php b/library/metabox-subhead.php
index db17de5..d709b11 100644
--- a/library/metabox-subhead.php
+++ b/library/metabox-subhead.php
@@ -33,14 +33,14 @@ function subtitle_meta_box_display() {
$values = get_post_custom( $post->ID );
wp_nonce_field( 'subtitle_meta_box_nonce', 'subtitle_meta_box_nonce' );
?>
-
+
-
+