Skip to content

Commit

Permalink
Merge pull request #881 from alleyinteractive/hotfix/APPLE-98/v2.2.2
Browse files Browse the repository at this point in the history
APPLE-98 Prepare v2.2.2
  • Loading branch information
kevinfodness authored Aug 20, 2021
2 parents 577520a + 51ec413 commit 78636fd
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 731 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Publish to Apple News

The Publish to Apple News plugin enables your WordPress blog content to be published to your Apple News channel.
The Publish to Apple News plugin enables your WordPress content to be published to your Apple News channel.

* Convert your WordPress content into Apple News format automatically.
* Create a custom design for your Apple News content with no programming knowledge required.
Expand All @@ -10,7 +10,7 @@ The Publish to Apple News plugin enables your WordPress blog content to be publi
* Handles image galleries and popular embeds like YouTube and Vimeo that are supported by Apple News.
* Automatically adjust advertisement settings.

To enable content from your WordPress blog to be published to your Apple News channel, you must obtain and enter Apple News API credentials from Apple.
To enable content from your WordPress site to be published to your Apple News channel, you must obtain and enter Apple News API credentials from Apple.

Please see the [Apple Developer](https://developer.apple.com/) and [Apple News Publisher documentation](https://developer.apple.com/news-publisher/) and terms on Apple's website for complete information.

Expand Down
57 changes: 27 additions & 30 deletions admin/apple-actions/index/class-push.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,31 @@ private function push( $user_id = null ) {
$meta['data']['maturityRating'] = $maturity_rating;
}

// Add custom metadata fields.
$custom_meta = get_post_meta( $this->id, 'apple_news_metadata', true );
if ( ! empty( $custom_meta ) && is_array( $custom_meta ) ) {
foreach ( $custom_meta as $metadata ) {
// Ensure required fields are set.
if ( empty( $metadata['key'] ) || empty( $metadata['type'] ) || ! isset( $metadata['value'] ) ) {
continue;
}

// If the value is an array, we have to decode it from JSON.
$value = $metadata['value'];
if ( 'array' === $metadata['type'] ) {
$value = json_decode( $metadata['value'] );

// If the user entered a bad value for the array, bail out without adding it.
if ( empty( $value ) || ! is_array( $value ) ) {
continue;
}
}

// Add the custom metadata field to the article metadata.
$meta['data'][ $metadata['key'] ] = $value;
}
}

// Ignore if the post is already in sync.
if ( $this->is_post_in_sync( $json, $meta, $bundles ) ) {
throw new \Apple_Actions\Action_Exception(
Expand Down Expand Up @@ -406,7 +431,6 @@ private function push( $user_id = null ) {
private function process_errors( $errors ) {
// Get the current alert settings.
$component_alerts = $this->get_setting( 'component_alerts' );
$json_alerts = $this->get_setting( 'json_alerts' );

// Initialize the alert message.
$alert_message = '';
Expand Down Expand Up @@ -434,39 +458,13 @@ private function process_errors( $errors ) {
}
}

// Check for JSON errors.
if ( ! empty( $errors[0]['json_errors'] ) ) {
if ( ! empty( $alert_message ) ) {
$alert_message .= '|';
}

// Merge all errors into a single message.
$json_errors = implode( ', ', $errors[0]['json_errors'] );

// Add these to the message.
if ( 'warn' === $json_alerts ) {
$alert_message .= sprintf(
// translators: token is a list of errors.
__( 'The following JSON errors were detected when publishing to Apple News: %s', 'apple-news' ),
$json_errors
);
} elseif ( 'fail' === $json_alerts ) {
$alert_message .= sprintf(
// translators: token is a list of errors.
__( 'The following JSON errors were detected and prevented publishing to Apple News: %s', 'apple-news' ),
$json_errors
);
}
}

// See if we found any errors.
if ( empty( $alert_message ) ) {
return;
}

// Proceed based on component alert settings.
if ( ( 'fail' === $component_alerts && ! empty( $errors[0]['component_errors'] ) )
|| ( 'fail' === $json_alerts && ! empty( $errors[0]['json_errors'] ) ) ) {
if ( 'fail' === $component_alerts && ! empty( $errors[0]['component_errors'] ) ) {
// Remove the pending designation if it exists.
delete_post_meta( $this->id, 'apple_news_api_pending' );

Expand All @@ -478,8 +476,7 @@ private function process_errors( $errors ) {

// Throw an exception.
throw new \Apple_Actions\Action_Exception( $alert_message );
} elseif ( ( 'warn' === $component_alerts && ! empty( $errors[0]['component_errors'] ) )
|| ( 'warn' === $json_alerts && ! empty( $errors[0]['json_errors'] ) ) ) {
} elseif ( 'warn' === $component_alerts && ! empty( $errors[0]['component_errors'] ) ) {
\Admin_Apple_Notice::error( $alert_message, $user_id );
}
}
Expand Down
5 changes: 5 additions & 0 deletions admin/partials/page-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
?>
<div class="wrap apple-news-settings">
<h1><?php esc_html_e( 'Manage Settings', 'apple-news' ); ?></h1>
<?php if ( Apple_News::is_initialized() ) : ?>
<div class="notice notice-success">
<p><?php esc_html_e( 'The Apple News channel config has been successfully added.', 'apple-news' ); ?></p>
</div>
<?php endif; ?>
<form method="post" action="" id="apple-news-settings-form">
<?php wp_nonce_field( 'apple_news_options' ); ?>
<input type="hidden" name="action" value="apple_news_options" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public function __construct( $page ) {
'type' => array( 'none', 'warn', 'fail' ),
'description' => __( 'If a post has a component that is unsupported by Apple News, choose "none" to generate no alert, "warn" to provide an admin warning notice, or "fail" to generate a notice and stop publishing.', 'apple-news' ),
),
'json_alerts' => array(
'label' => __( 'JSON Alerts', 'apple-news' ),
'type' => array( 'none', 'warn', 'fail' ),
'description' => __( 'If a post has invalid JSON that may cause display issues in Apple News, choose "none" to generate no alert, "warn" to provide an admin warning notice, or "fail" to generate a notice and stop publishing.', 'apple-news' ),
),
'use_remote_images' => array(
'label' => __( 'Use Remote Images?', 'apple-news' ),
'type' => array( 'yes', 'no' ),
Expand All @@ -68,7 +63,7 @@ public function __construct( $page ) {
$this->groups = array(
'alerts' => array(
'label' => __( 'Alerts', 'apple-news' ),
'settings' => array( 'component_alerts', 'json_alerts' ),
'settings' => array( 'component_alerts' ),
),
'images' => array(
'label' => __( 'Image Settings', 'apple-news' ),
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.2.1
* Version: 2.2.2
* Author: Alley
* Author URI: https://alley.co
* Text Domain: apple-news
Expand Down
25 changes: 0 additions & 25 deletions includes/apple-exporter/builders/class-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,6 @@ protected function build() {
}
}

// Add custom metadata fields.
$custom_meta = get_post_meta( $this->content_id(), 'apple_news_metadata', true );
if ( ! empty( $custom_meta ) && is_array( $custom_meta ) ) {
foreach ( $custom_meta as $metadata ) {
// Ensure required fields are set.
if ( empty( $metadata['key'] ) || empty( $metadata['type'] ) || ! isset( $metadata['value'] ) ) {
continue;
}

// If the value is an array, we have to decode it from JSON.
$value = $metadata['value'];
if ( 'array' === $metadata['type'] ) {
$value = json_decode( $metadata['value'] );

// If the user entered a bad value for the array, bail out without adding it.
if ( empty( $value ) || ! is_array( $value ) ) {
continue;
}
}

// Add the custom metadata field to the article metadata.
$meta[ $metadata['key'] ] = $value;
}
}

/**
* Modifies the metadata for a post.
*
Expand Down
1 change: 0 additions & 1 deletion includes/apple-exporter/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Settings {
'component_alerts' => 'none',
'full_bleed_images' => 'no',
'html_support' => 'yes',
'json_alerts' => 'warn',
'post_types' => array( 'post' ),
'show_metabox' => 'yes',
'use_remote_images' => 'yes',
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 @@ -39,7 +39,7 @@ class Apple_News {
* @var string
* @access public
*/
public static $version = '2.2.1';
public static $version = '2.2.2';

/**
* 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.2.1",
"version": "2.2.2",
"license": "GPLv3",
"main": "index.php",
"engines": {
Expand Down
9 changes: 7 additions & 2 deletions 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: 4.0
Tested up to: 5.8
Requires PHP: 5.6
Stable tag: 2.2.1
Stable tag: 2.2.2
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl.html

Expand All @@ -25,7 +25,7 @@ The 'Publish to Apple News' plugin enables WordPress sites with approved Apple N
* Handles image galleries and popular embeds like YouTube and Vimeo that are supported by Apple News.
* Automatically adjust advertisement settings.

To enable content from your WordPress blog to be published to your Apple News channel, you must obtain and enter Apple News API credentials from Apple.
To enable content from your WordPress site to be published to your Apple News channel, you must obtain and enter Apple News API credentials from Apple.

Please see the [Apple Developer](https://developer.apple.com/) and [Apple News Publisher documentation](https://developer.apple.com/news-publisher/) and terms on Apple's website for complete information.

Expand All @@ -46,6 +46,11 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for

== Changelog ==

= 2.2.2 =
* Bugfix: Moved custom metadata fields to the request level rather than the article level to align them with existing metadata properties like isPaid and isHidden.
* Bugfix: Removed JSON alerts setting, as it no longer does anything.
* Enhancement: Shows a confirmation message to the user when channel credentials are successfully saved, since the channel ID, key, and secret fields are no longer visible following the update to using .papi files to configure credentials.

= 2.2.1 =
* Bugfix: Fixed a bug with .papi file upload that occurred when any of the three fields (channel_id, key, secret) contained a character that was not alphanumeric or a hyphen (e.g., /), which would cause the field to get cut short, thereby causing API requests to fail.

Expand Down
Loading

0 comments on commit 78636fd

Please sign in to comment.