From 864036e1dbf8aa751d5cafd534afdd4524cd8b3d Mon Sep 17 00:00:00 2001 From: Simon Wheatley Date: Thu, 20 Aug 2015 21:18:09 +0100 Subject: [PATCH 1/4] Custom meta field translation UI: Allow the `Babble_Meta_Field` object to update the value before saving --- class-jobs.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/class-jobs.php b/class-jobs.php index 4e1485a..656465d 100755 --- a/class-jobs.php +++ b/class-jobs.php @@ -677,6 +677,8 @@ public function save_job( $job_id, WP_Post $job ) { foreach ( $objects['meta'] as $meta_key => $meta_field ) { + $value = $meta_field->update( $value, $job ); + $value = wp_kses_post( $meta_data[ $meta_key ] ); update_post_meta( $job->ID, "bbl_meta_{$meta_key}", $value ); From 79dee30968de7df093eed15682a1d5170f0fa60e Mon Sep 17 00:00:00 2001 From: Simon Wheatley Date: Thu, 20 Aug 2015 21:20:13 +0100 Subject: [PATCH 2/4] Custom meta field translation UI: If the value is not a string, then `wp_kses` might break it, so don't apply this --- class-jobs.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/class-jobs.php b/class-jobs.php index 656465d..e8eb8d2 100755 --- a/class-jobs.php +++ b/class-jobs.php @@ -679,7 +679,13 @@ public function save_job( $job_id, WP_Post $job ) { $value = $meta_field->update( $value, $job ); + // If the Babble_Meta_Field object update mathod as returned + // something that is not a string, it will break if we apply + // wp_kses to it + // @TODO: Perhaps there's some kind of wp_kses_deep we can use? Would that cause issues with some field/data types? + if ( is_string( $value ) ) { $value = wp_kses_post( $meta_data[ $meta_key ] ); + } update_post_meta( $job->ID, "bbl_meta_{$meta_key}", $value ); From d64baf21987d29503888ef1f7d0042fad57733d6 Mon Sep 17 00:00:00 2001 From: Simon Wheatley Date: Thu, 20 Aug 2015 21:21:15 +0100 Subject: [PATCH 3/4] Custom meta field translation UI: If we want to output structured HTML in the output side, we can't escape it, so use `wp_kses` instead --- templates-admin/translation-editor-meta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates-admin/translation-editor-meta.php b/templates-admin/translation-editor-meta.php index c741390..2793a96 100644 --- a/templates-admin/translation-editor-meta.php +++ b/templates-admin/translation-editor-meta.php @@ -12,7 +12,7 @@ get_input( "bbl_translation[meta][{$key}]", $translation ); ?>
- get_output() ); ?> + get_output() ); ?>
From 01b72dd88ac4eb1cc2f49a526d6fbf0e7f05c7d4 Mon Sep 17 00:00:00 2001 From: Simon Wheatley Date: Thu, 20 Aug 2015 22:16:18 +0100 Subject: [PATCH 4/4] Custom meta field translation UI: Need to set the $value variable before acting on it, doh --- class-jobs.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/class-jobs.php b/class-jobs.php index e8eb8d2..2136eb0 100755 --- a/class-jobs.php +++ b/class-jobs.php @@ -677,6 +677,8 @@ public function save_job( $job_id, WP_Post $job ) { foreach ( $objects['meta'] as $meta_key => $meta_field ) { + $value = $meta_data[ $meta_key ]; + $value = $meta_field->update( $value, $job ); // If the Babble_Meta_Field object update mathod as returned @@ -684,7 +686,7 @@ public function save_job( $job_id, WP_Post $job ) { // wp_kses to it // @TODO: Perhaps there's some kind of wp_kses_deep we can use? Would that cause issues with some field/data types? if ( is_string( $value ) ) { - $value = wp_kses_post( $meta_data[ $meta_key ] ); + $value = wp_kses_post( $value ); } update_post_meta( $job->ID, "bbl_meta_{$meta_key}", $value );