Skip to content

Commit

Permalink
Merge pull request #1062 from alleyinteractive/release/v2.4.7
Browse files Browse the repository at this point in the history
Release/v2.4.7
  • Loading branch information
srtfisher authored Mar 15, 2024
2 parents d6bd2a4 + d3a419f commit 08f7b46
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 22 additions & 20 deletions admin/apple-actions/index/class-push.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand All @@ -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 ) {
Expand Down Expand Up @@ -139,15 +141,15 @@ 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;

// 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.
Expand Down Expand Up @@ -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.
Expand All @@ -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' ) );
}

/**
Expand All @@ -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' ),
Expand Down Expand Up @@ -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' ),
Expand All @@ -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 );
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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() ) );
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 ) {
/**
Expand All @@ -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 );
}
Expand Down
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
2 changes: 1 addition & 1 deletion apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
13 changes: 8 additions & 5 deletions includes/apple-exporter/builders/class-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publish-to-apple-news",
"version": "2.4.6",
"version": "2.4.7",
"license": "GPLv3",
"main": "index.php",
"engines": {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08f7b46

Please sign in to comment.