Skip to content

Commit

Permalink
Merge pull request #1083 from alleyinteractive/hotfix/963-apple-news-…
Browse files Browse the repository at this point in the history
…sections-meta

Fix issue with apple_news_section throwing notice when being cast as a string
  • Loading branch information
srtfisher authored Mar 14, 2024
2 parents 8e94a3f + 4040b20 commit 6ce402a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 12 additions & 6 deletions admin/class-admin-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ public function __construct() {
'default' => '',
],
'apple_news_metadata' => [
'default' => '',
'default' => [],
'sanitize_callback' => function ( $value ) {
return ! empty( $value ) && is_string( $value ) ? json_decode( $value, true ) : $value;
},
'show_in_rest' => [
'prepare_callback' => 'apple_news_json_encode',
],
'type' => 'array',
],
'apple_news_pullquote' => [
'default' => '',
Expand All @@ -159,11 +160,16 @@ public function __construct() {
'default' => '',
],
'apple_news_sections' => [
'default' => '',
'sanitize_callback' => 'apple_news_sanitize_selected_sections',
'show_in_rest' => [
'prepare_callback' => 'apple_news_json_encode',
'default' => [],
'show_in_rest' => [
'schema' => [
'items' => [
'type' => 'string',
],
'type' => 'array',
],
],
'type' => 'array',
],
'apple_news_suppress_video_url' => [
'default' => false,
Expand Down Expand Up @@ -192,7 +198,7 @@ function ( $key ) {
}
)
: $meta_keys;
}
}
);

add_action(
Expand Down
5 changes: 2 additions & 3 deletions assets/js/pluginsidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ function Sidebar() {
const [metadataRaw, setMetadataRaw] = usePostMetaValue('apple_news_metadata');
const [pullquoteText, setPullquoteText] = usePostMetaValue('apple_news_pullquote');
const [pullquotePosition, setPullquotePosition] = usePostMetaValue('apple_news_pullquote_position');
const [selectedSectionsRaw, setSelectedSectionsRaw] = usePostMetaValue('apple_news_sections');
const [selectedSections, setSelectedSectionsRaw] = usePostMetaValue('apple_news_sections');
const [slug, setSlug] = usePostMetaValue('apple_news_slug');
const [suppressVideoURL, setSuppressVideoURL] = usePostMetaValue('apple_news_suppress_video_url');
const [useImageComponent, setUseImageComponent] = usePostMetaValue('apple_news_use_image_component');

// Decode selected sections.
const metadata = safeJsonParseArray(metadataRaw);
const selectedSections = safeJsonParseArray(selectedSectionsRaw);

/**
* A helper function for setting metadata.
Expand All @@ -110,7 +109,7 @@ function Sidebar() {
* A helper function for setting selected sections.
* @param {Array} next - The array of selected sections to set.
*/
const setSelectedSections = (next) => setSelectedSectionsRaw(JSON.stringify(next));
const setSelectedSections = (next) => setSelectedSectionsRaw(next);

/**
* A helper function for displaying a notification to the user.
Expand Down

0 comments on commit 6ce402a

Please sign in to comment.