diff --git a/README.md b/README.md index 5d81960a..2367642c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ See the wiki for [usage instructions](https://github.com/alleyinteractive/apple- ### Source ### Changelog -See the tag archive for the [changelog](https://github.com/alleyinteractive/apple-news/tags). +See the release archive for the [changelog](https://github.com/alleyinteractive/apple-news/releases). ## Development Process diff --git a/admin/apple-actions/index/class-push.php b/admin/apple-actions/index/class-push.php index 09e066a7..8e3298f2 100644 --- a/admin/apple-actions/index/class-push.php +++ b/admin/apple-actions/index/class-push.php @@ -13,7 +13,9 @@ use Admin_Apple_Notice; use Admin_Apple_Sections; +use Apple_Actions\Action_Exception; use Apple_Actions\API_Action; +use Apple_Exporter\Settings; /** * A class to handle a push request from the admin. @@ -58,8 +60,8 @@ class Push extends API_Action { /** * Constructor. * - * @param \Apple_Exporter\Settings $settings A settings object containing settings at load time. - * @param int $id The ID for the content object to be pushed. + * @param Settings $settings A settings object containing settings at load time. + * @param int $id The ID for the content object to be pushed. */ public function __construct( $settings, $id ) { parent::__construct( $settings ); @@ -74,7 +76,7 @@ public function __construct( $settings, $id ) { * @param int $user_id Optional. The ID of the user performing the action. Defaults to the current user ID. * @access public * @return boolean - * @throws \Apple_Actions\Action_Exception If the push fails. + * @throws Action_Exception If the push fails. */ public function perform( $doing_async = false, $user_id = null ) { if ( 'yes' === $this->settings->get( 'api_async' ) && false === $doing_async ) { @@ -139,7 +141,7 @@ private function generate_checksum( $json, $meta = [], $bundles = [], $force = f * @param array $meta Optional. Metadata for the article. Defaults to empty array. * @param array $bundles Optional. Any bundles that will be sent with the article. Defaults to empty array. * @return boolean - * @throws \Apple_Actions\Action_Exception If the post could not be found. + * @throws Action_Exception If the post could not be found. */ private function is_post_in_sync( $json, $meta = [], $bundles = [] ) { $in_sync = true; @@ -147,7 +149,7 @@ private function is_post_in_sync( $json, $meta = [], $bundles = [] ) { // Ensure the post (still) exists. Async operations might result in this function being run against a non-existent post. $post = get_post( $this->id ); if ( ! $post ) { - throw new \Apple_Actions\Action_Exception( esc_html( __( 'Apple News Error: Could not find post with id ', 'apple-news' ) . $this->id ) ); + throw new Action_Exception( esc_html( __( 'Apple News Error: Could not find post with id ', 'apple-news' ) . $this->id ) ); } // Compare checksums to determine whether the article is in sync or not. @@ -181,19 +183,19 @@ private function is_post_in_sync( $json, $meta = [], $bundles = [] ) { * Updates the current relevant metadata stored for the post. * * @access private - * @throws \Apple_Actions\Action_Exception If there was an error getting the article from the API. + * @throws Action_Exception If there was an error getting the article from the API. */ private function get() { // Ensure we have a valid ID. $apple_id = get_post_meta( $this->id, 'apple_news_api_id', true ); if ( empty( $apple_id ) ) { - throw new \Apple_Actions\Action_Exception( esc_html__( 'This post does not have a valid Apple News ID, so it cannot be retrieved from the API.', 'apple-news' ) ); + throw new Action_Exception( esc_html__( 'This post does not have a valid Apple News ID, so it cannot be retrieved from the API.', 'apple-news' ) ); } // Get the article from the API. $result = $this->get_api()->get_article( $apple_id ); if ( empty( $result->data->revision ) ) { - throw new \Apple_Actions\Action_Exception( esc_html__( 'The Apple News API returned invalid data for this article since the revision is empty.', 'apple-news' ) ); + throw new Action_Exception( esc_html__( 'The Apple News API returned invalid data for this article since the revision is empty.', 'apple-news' ) ); } // Update the revision. @@ -205,11 +207,11 @@ private function get() { * * @param int $user_id Optional. The ID of the user performing the push. Defaults to current user. * @access private - * @throws \Apple_Actions\Action_Exception If unable to push. + * @throws Action_Exception If unable to push. */ private function push( $user_id = null ) { if ( ! $this->is_api_configuration_valid() ) { - throw new \Apple_Actions\Action_Exception( esc_html__( 'Your Apple News API settings seem to be empty. Please fill in the API key, API secret and API channel fields in the plugin configuration page.', 'apple-news' ) ); + throw new Action_Exception( esc_html__( 'Your Apple News API settings seem to be empty. Please fill in the API key, API secret and API channel fields in the plugin configuration page.', 'apple-news' ) ); } /** @@ -224,7 +226,7 @@ private function push( $user_id = null ) { * @param int $post_id The ID of the post. */ if ( apply_filters( 'apple_news_skip_push', false, $this->id ) ) { - throw new \Apple_Actions\Action_Exception( + throw new Action_Exception( sprintf( // Translators: Placeholder is a post ID. esc_html__( 'Skipped push of article %d due to the apple_news_skip_push filter.', 'apple-news' ), @@ -274,7 +276,7 @@ private function push( $user_id = null ) { // If any of the terms for the current post are in the list of term IDs that should be skipped, bail out. if ( array_intersect( $term_ids, $skip_term_ids ) ) { - throw new \Apple_Actions\Action_Exception( + throw new Action_Exception( sprintf( // Translators: Placeholder is a post ID. esc_html__( 'Skipped push of article %d due to the presence of a skip push taxonomy term.', 'apple-news' ), @@ -294,7 +296,7 @@ private function push( $user_id = null ) { $this->sections = Admin_Apple_Sections::get_sections_for_post( $this->id ); // Generate the JSON for the article. - list( $json, $bundles, $errors ) = $this->generate_article(); + [ $json, $bundles, $errors ] = $this->generate_article(); // Process errors. $this->process_errors( $errors ); @@ -390,7 +392,7 @@ private function push( $user_id = null ) { // Ignore if the post is already in sync. if ( $this->is_post_in_sync( $json, $meta, $bundles ) ) { - throw new \Apple_Actions\Action_Exception( + throw new Action_Exception( sprintf( // Translators: Placeholder is a post ID. esc_html__( 'Skipped push of article %d to Apple News because it is already in sync.', 'apple-news' ), @@ -451,9 +453,9 @@ private function push( $user_id = null ) { $this->clean_workspace(); if ( str_contains( $e->getMessage(), 'WRONG_REVISION' ) ) { - throw new \Apple_Actions\Action_Exception( esc_html__( 'Apple News Error: It seems like the article was updated by another call. If the problem persists, try removing and pushing again.', 'apple-news' ) ); + throw new Action_Exception( esc_html__( 'Apple News Error: It seems like the article was updated by another call. If the problem persists, try removing and pushing again.', 'apple-news' ) ); } else { - throw new \Apple_Actions\Action_Exception( esc_html__( 'There has been an error with the Apple News API: ', 'apple-news' ) . esc_html( $e->getMessage() ) ); + throw new Action_Exception( esc_html__( 'There has been an error with the Apple News API: ', 'apple-news' ) . esc_html( $e->getMessage() ) ); } } @@ -487,7 +489,7 @@ private function push( $user_id = null ) { * * @param array $errors Array of errors to be processed. * @access private - * @throws \Apple_Actions\Action_Exception If set to fail on component errors. + * @throws Action_Exception If set to fail on component errors. */ private function process_errors( $errors ) { // Get the current alert settings. @@ -536,7 +538,7 @@ private function process_errors( $errors ) { $this->clean_workspace(); // Throw an exception. - throw new \Apple_Actions\Action_Exception( esc_html( $alert_message ) ); + throw new Action_Exception( esc_html( $alert_message ) ); } elseif ( 'warn' === $component_alerts && ! empty( $errors[0]['component_errors'] ) ) { \Admin_Apple_Notice::error( $alert_message, $user_id ); } @@ -581,7 +583,7 @@ private function generate_article() { * @param string $json The JSON to be sanitized. * @access private * @return string - * @throws \Apple_Actions\Action_Exception If the JSON is invalid. + * @throws Action_Exception If the JSON is invalid. */ private function sanitize_json( $json ) { /** @@ -590,7 +592,7 @@ private function sanitize_json( $json ) { */ $decoded = json_decode( $json ); if ( ! $decoded ) { - throw new \Apple_Actions\Action_Exception( esc_html__( 'The Apple News JSON is invalid and cannot be published.', 'apple-news' ) ); + throw new Action_Exception( esc_html__( 'The Apple News JSON is invalid and cannot be published.', 'apple-news' ) ); } else { return wp_json_encode( $decoded ); } diff --git a/admin/class-admin-apple-news.php b/admin/class-admin-apple-news.php index fc39a0e4..e8aaefc3 100644 --- a/admin/class-admin-apple-news.php +++ b/admin/class-admin-apple-news.php @@ -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' => '', @@ -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, @@ -192,7 +198,7 @@ function ( $key ) { } ) : $meta_keys; - } + } ); add_action( diff --git a/apple-news.php b/apple-news.php index b480ff29..b4997c3d 100644 --- a/apple-news.php +++ b/apple-news.php @@ -14,7 +14,7 @@ * Plugin Name: Publish to Apple News * Plugin URI: http://github.com/alleyinteractive/apple-news * Description: Export and sync posts to Apple format. - * Version: 2.4.6 + * Version: 2.4.7 * Author: Alley * Author URI: https://alley.com * Text Domain: apple-news diff --git a/assets/js/pluginsidebar/sidebar.jsx b/assets/js/pluginsidebar/sidebar.jsx index 0372364a..273f7027 100644 --- a/assets/js/pluginsidebar/sidebar.jsx +++ b/assets/js/pluginsidebar/sidebar.jsx @@ -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. @@ -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. diff --git a/includes/apple-exporter/builders/class-components.php b/includes/apple-exporter/builders/class-components.php index 103909ad..7ff15c3b 100644 --- a/includes/apple-exporter/builders/class-components.php +++ b/includes/apple-exporter/builders/class-components.php @@ -864,14 +864,17 @@ private function meta_components() { if ( ! ( $component instanceof Component ) ) { continue; } + $component = $component->to_array(); - // If the cover isn't first, give it a different layout. - if ( 'header' === $component['role'] && 0 !== $i ) { - $component['layout'] = 'headerBelowTextPhotoLayout'; - } + if ( is_array( $component ) ) { + // If the cover isn't first, give it a different layout. + if ( ! empty( $component['role'] ) && 'header' === $component['role'] && 0 !== $i ) { + $component['layout'] = 'headerBelowTextPhotoLayout'; + } - $components[] = $component; + $components[] = $component; + } } return $components; diff --git a/includes/class-apple-news.php b/includes/class-apple-news.php index 001d61fc..c83b77bf 100644 --- a/includes/class-apple-news.php +++ b/includes/class-apple-news.php @@ -50,7 +50,7 @@ class Apple_News { * @var string * @access public */ - public static string $version = '2.4.6'; + public static string $version = '2.4.7'; /** * Link to support for the plugin on WordPress.org. diff --git a/package-lock.json b/package-lock.json index 828a6966..085511fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "publish-to-apple-news", - "version": "2.4.6", + "version": "2.4.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "publish-to-apple-news", - "version": "2.4.6", + "version": "2.4.7", "hasInstallScript": true, "license": "GPLv3", "dependencies": { diff --git a/package.json b/package.json index 29e09a03..e63c7e05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publish-to-apple-news", - "version": "2.4.6", + "version": "2.4.7", "license": "GPLv3", "main": "index.php", "engines": { diff --git a/readme.txt b/readme.txt index fec2f4af..4ab052bc 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: publish, apple, news, iOS Requires at least: 6.3 Tested up to: 6.4.2 Requires PHP: 8.0 -Stable tag: 2.4.6 +Stable tag: 2.4.7 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl.html @@ -46,6 +46,10 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for == Changelog == += 2.4.7 = + +* Bugfix: #1083 - Resolved issues with the `apple_news_sections` meta throwing a PHP notice. + = 2.4.6 = * Bugfix: #1057 - Resolved type error on Automation admin screen