Skip to content

Commit

Permalink
Merge pull request #54 from Automattic/trunk
Browse files Browse the repository at this point in the history
Alpha release Feb 15
  • Loading branch information
leogermani authored Feb 15, 2024
2 parents 9e9c801 + 6a05580 commit cd3d537
Show file tree
Hide file tree
Showing 60 changed files with 635 additions and 237 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "wordpress-plugin",
"license": "GPL-3.0",
"require-dev": {
"automattic/vipwpcs": "^2.0.0",
"wp-coding-standards/wpcs": "*",
"automattic/vipwpcs": "^3.0",
"wp-coding-standards/wpcs": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"yoast/phpunit-polyfills": "^1.0",
Expand Down
317 changes: 263 additions & 54 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,5 @@ public static function admin_init() {
* @return void
*/
public static function enqueue_scripts() {

}

}
4 changes: 1 addition & 3 deletions includes/class-crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public static function generate_secret_key() {
* @return string|false The decrypted message or false if the message could not be decrypted.
*/
public static function decrypt_message( $message, $secret_key, $nonce ) {

if ( ! $secret_key || ! is_string( $secret_key ) || ! $nonce || ! is_string( $nonce ) ) {
if ( ! $secret_key || ! is_string( $secret_key ) || ! $nonce || ! is_string( $nonce ) || ! is_string( $message ) ) {
return false;
}

Expand All @@ -54,7 +53,6 @@ public static function decrypt_message( $message, $secret_key, $nonce ) {
* @return string|WP_Error The encrypted message or WP_Error if the message could not be encrypted.
*/
public static function encrypt_message( $message, $secret_key, $nonce ) {

if ( ! $secret_key || ! is_string( $secret_key ) || ! $nonce || ! is_string( $nonce ) ) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion includes/class-debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public static function log( $message ) {
}
error_log( "[{$pid}] {$caller['file']}:{$caller['line']} {$message}" ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
}

}
8 changes: 5 additions & 3 deletions includes/class-distributor-customizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class Distributor_Customizations {
* @return void
*/
public static function init() {
require_once NEWSPACK_NETWORK_PLUGIN_DIR . '/includes/distributor-customizations/global.php';
Distributor_Customizations\Pull_Permissions::init();
Distributor_Customizations\Publication_Date::init();
Distributor_Customizations\Cache_Bug_Workaround::init();
Distributor_Customizations\Yoast_Primary_Cat::init();
Distributor_Customizations\Sync_Post_Status::init();
Distributor_Customizations\Canonical_Url::init();
Distributor_Customizations\Author_Distribution::init();
Distributor_Customizations\Author_Ingestion::init();
Distributor_Customizations\Authorship_Filters::init();
}


}
1 change: 0 additions & 1 deletion includes/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ public static function init() {
public static function activation_hook() {
add_role( NEWSPACK_NETWORK_READER_ROLE, __( 'Network Reader', 'newspack-network' ) ); // phpcs:ignore
}

}
3 changes: 0 additions & 3 deletions includes/class-rest-authenticaton.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public static function verify_signature( WP_REST_Request $request, $endpoint_id,
}

return true;

}

/**
Expand Down Expand Up @@ -154,7 +153,6 @@ public static function rest_pre_dispatch( $response, $handler, $request ) {
}

return $response;

}

/**
Expand All @@ -179,5 +177,4 @@ public static function allow_woo_read_endpoints( $permission, $context ) {
}
return $permission;
}

}
1 change: 0 additions & 1 deletion includes/class-site-role.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ public static function is_node() {
public static function sanitize( $role ) {
return in_array( $role, [ 'hub', 'node' ], true ) ? $role : false;
}

}
19 changes: 18 additions & 1 deletion includes/class-user-update-watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ class User_Update_Watcher {
'last_name',
'description',

// Shipping and Billing.
'billing_first_name',
'billing_last_name',
'billing_address_1',
'billing_address_2',
'billing_city',
'billing_state',
'billing_postcode',
'billing_country',
'shipping_first_name',
'shipping_last_name',
'shipping_address_1',
'shipping_address_2',
'shipping_city',
'shipping_state',
'shipping_postcode',
'shipping_country',

// Newspack.
'newspack_job_title',
'newspack_role',
Expand Down Expand Up @@ -259,5 +277,4 @@ public static function watch_meta_simple_local_avatar( $user_id, $new_value ) {
self::add_change( $user_id, 'meta', 'simple_local_avatar', $new_value );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public static function add_author_data_to_pull( $post_array ) {
}

return $post_array;

}

/**
Expand Down Expand Up @@ -135,7 +134,6 @@ private static function get_authors_for_distribution( $post ) {
}

return $authors;

}

/**
Expand Down Expand Up @@ -240,5 +238,4 @@ public static function after_coauthors_update( $response, $handler, $request ) {

return $response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public static function ingest_authors_for_post( $post_id, $distributed_authors )
Debugger::log( $coauthors );
$coauthors_plus->add_coauthors( $post_id, $coauthors );
}

}

/**
Expand All @@ -162,7 +161,5 @@ public static function handle_pull( $new_post_id, $connection, $post_array ) {
$distributed_authors = $post_array['newspack_network_authors'];

self::ingest_authors_for_post( $new_post_id, $distributed_authors );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public static function filter_coauthors( $coauthors, $post_id ) {
}

// Only filter posts that are still linked to the original post.
$distributor_post = new DistributorPost( $post_id );
if ( ! $distributor_post->is_linked ) {
// We check the dt_unlinked post meta to determine linked status.
// See: https://github.com/10up/distributor/blob/1f180d74db804a057f7331ce62338e571dd73350/docs/post-meta.md?plain=1#L38.
if ( get_post_meta( $post_id, 'dt_unlinked', true ) ) {
return $coauthors;
}

Expand Down Expand Up @@ -105,7 +106,6 @@ public static function newspack_author_bio_name( $author_name, $author_id, $auth
}

return $author_name;

}

/**
Expand All @@ -123,5 +123,4 @@ public static function author_link( $link, $author_id, $author_nicename ) {

return $link;
}

}
31 changes: 31 additions & 0 deletions includes/distributor-customizations/class-cache-bug-workaround.php
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' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ public static function wpseo_canonical_url( $canonical_url ) {

return self::filter_canonical_url( $canonical_url, $post );
}

}
51 changes: 51 additions & 0 deletions includes/distributor-customizations/class-publication-date.php
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 includes/distributor-customizations/class-pull-permissions.php
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 includes/distributor-customizations/class-sync-post-status.php
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;
}
}
Loading

0 comments on commit cd3d537

Please sign in to comment.