-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Automattic/trunk
Alpha release Feb 15
- Loading branch information
Showing
60 changed files
with
635 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,5 @@ public static function admin_init() { | |
* @return void | ||
*/ | ||
public static function enqueue_scripts() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
includes/distributor-customizations/class-cache-bug-workaround.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Newspack Distributor Bug Workaround | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Distributor_Customizations; | ||
|
||
/** | ||
* Class to workaround a bug in the Distributor plugin that affects site running with memcached. | ||
* | ||
* This is a workaround the bug fixed in https://github.com/10up/distributor/pull/1185 | ||
* Until that fix is released, we need to keep this workaround. | ||
*/ | ||
class Cache_Bug_Workaround { | ||
|
||
/** | ||
* Initialize hooks | ||
*/ | ||
public static function init() { | ||
add_action( 'init', [ __CLASS__, 'workaround' ] ); | ||
} | ||
|
||
/** | ||
* Deletes the buggy cache key | ||
*/ | ||
public static function workaround() { | ||
wp_cache_delete( 'dt_media::{$post_id}', 'dt::post' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
includes/distributor-customizations/class-publication-date.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Newspack Distributor Publication Date tweak. | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Distributor_Customizations; | ||
|
||
/** | ||
* Class to keep the publication date on the distributed posts. | ||
*/ | ||
class Publication_Date { | ||
|
||
/** | ||
* Initialize hooks | ||
*/ | ||
public static function init() { | ||
add_filter( 'dt_push_post_args', [ __CLASS__, 'filter_push_post_args' ], 10, 2 ); | ||
add_filter( 'dt_pull_post_args', [ __CLASS__, 'filter_pull_post_args' ], 10, 3 ); | ||
} | ||
|
||
/** | ||
* Filter the arguments sent to the remote server during a push | ||
* | ||
* @param array $post_body The post data to be sent to the Node. | ||
* @param WP_Post $post The post object. | ||
*/ | ||
public static function filter_push_post_args( $post_body, $post ) { | ||
// Pass the original published date to the new pushed post and set the same published date | ||
// instead of setting it to the current time. | ||
$post_body['date'] = $post->post_date; | ||
$post_body['date_gmt'] = $post->post_date_gmt; | ||
|
||
return $post_body; | ||
} | ||
|
||
/** | ||
* Keep the publication date on the new pulled post | ||
* | ||
* @param array $post_array The post data to be sent to the Node. | ||
* @param int $remote_id The remote post ID. | ||
* @param WP_Post $post The post object. | ||
*/ | ||
public static function filter_pull_post_args( $post_array, $remote_id, $post ) { | ||
$post_array['post_date'] = $post->post_date; | ||
$post_array['post_date_gmt'] = $post->post_date_gmt; | ||
|
||
return $post_array; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
includes/distributor-customizations/class-pull-permissions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Newspack Distributor Tweak who can pull content | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Distributor_Customizations; | ||
|
||
/** | ||
* Class to allow editors to pull content | ||
*/ | ||
class Pull_Permissions { | ||
|
||
/** | ||
* Initialize hooks | ||
*/ | ||
public static function init() { | ||
add_filter( 'dt_capabilities', [ __CLASS__, 'filter_distributor_menu_cap' ] ); | ||
add_filter( 'dt_pull_capabilities', [ __CLASS__, 'filter_distributor_menu_cap' ] ); | ||
} | ||
|
||
/** | ||
* Allow editors to pull content | ||
*/ | ||
public static function filter_distributor_menu_cap() { | ||
return 'edit_others_posts'; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
includes/distributor-customizations/class-sync-post-status.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Newspack Distributor Sync post status | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Distributor_Customizations; | ||
|
||
/** | ||
* Class to sync post status when a post is trashed or restored from trash | ||
*/ | ||
class Sync_Post_Status { | ||
|
||
const POST_STATUS_META_NAME = 'newspack_network_post_status'; | ||
|
||
/** | ||
* Initialize hooks. | ||
*/ | ||
public static function init() { | ||
add_filter( 'dt_subscription_post_args', [ __CLASS__, 'filter_subscription_post_args' ], 10, 2 ); | ||
add_action( 'dt_process_subscription_attributes', [ __CLASS__, 'process_attributes' ], 10, 2 ); | ||
add_action( 'dt_process_distributor_attributes', [ __CLASS__, 'process_attributes' ], 10, 2 ); | ||
} | ||
|
||
/** | ||
* Process distributed post attributes after the distribution has completed. | ||
* | ||
* @param WP_Post $post The post object. | ||
*/ | ||
public static function process_attributes( $post ) { | ||
$origin_post_status = get_post_meta( $post->ID, self::POST_STATUS_META_NAME, true ); | ||
$current_post_status = get_post_status( $post->ID ); | ||
if ( $origin_post_status && $origin_post_status !== $current_post_status ) { | ||
wp_update_post( | ||
[ | ||
'ID' => $post->ID, | ||
'post_status' => $origin_post_status, | ||
] | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Send primary category slug to the Node when updating a post. | ||
* | ||
* @param array $post_body The post data to be sent to the Node. | ||
* @param WP_Post $post The post object. | ||
*/ | ||
public static function filter_subscription_post_args( $post_body, $post ) { | ||
// Attaching the post status only on updates (so not in filter_push_post_args). | ||
// By default, only published posts are distributable, so there's no need to attach the post status on new posts. | ||
$distributable_statuses = [ 'publish', 'trash' ]; | ||
if ( in_array( $post->post_status, $distributable_statuses, true ) ) { | ||
$post_body['post_data']['distributor_meta'][ self::POST_STATUS_META_NAME ] = $post->post_status; | ||
} | ||
return $post_body; | ||
} | ||
} |
Oops, something went wrong.