Skip to content

Commit

Permalink
Merge branch 'develop' into fix/349
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk authored Jan 9, 2024
2 parents 30d31b4 + 14b56e6 commit 76eb110
Show file tree
Hide file tree
Showing 15 changed files with 8,611 additions and 4,337 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- id: changed-files
uses: tj-actions/changed-files@v36
uses: tj-actions/changed-files@v41
with:
files: |
**/*.php
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [2.0.2] - 2023-11-29
### Added
- New snippet detailing how to disable automatic content updates (props [@dkotter](https://github.com/dkotter), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1145](https://github.com/10up/distributor/pull/1145)).

### Changed
- Show proper external connection status error messages when the status is checked (props [@theskinnyghost](https://github.com/theskinnyghost), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1140](https://github.com/10up/distributor/pull/1140)).
- Updated our docs around how to connect two pieces of existing content (props [@dkotter](https://github.com/dkotter), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1145](https://github.com/10up/distributor/pull/1145)).
- Bump WordPress "tested up to" version 6.4 (props [@severine-pozzo](https://github.com/severine-pozzo), [@QAharshalkadu](https://github.com/QAharshalkadu), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#1151](https://github.com/10up/distributor/pull/1151)).

### Fixed
- Copy the htaccess file when initilizing the E2E test environment (props [@peterwilsoncc](https://github.com/peterwilsoncc), [@theskinnyghost](https://github.com/theskinnyghost), [@dkotter](https://github.com/dkotter) via [#1143](https://github.com/10up/distributor/pull/1143)).
- Prevent early publishing of scheduled posts when pulled internally (props [@peterwilsoncc](https://github.com/peterwilsoncc), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@maxledoux](https://github.com/maxledoux), [@pcrumm](https://github.com/pcrumm) via [#1156](https://github.com/10up/distributor/pull/1156)).
- Avoid a PHP fatal error when pulling content that has previously been pulled into a different network site (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1159](https://github.com/10up/distributor/pull/1159)).

### Security
- Bump `postcss` from 8.4.24 to 8.4.31 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@ravinderk](https://github.com/ravinderk) via [#1141](https://github.com/10up/distributor/pull/1141)).
- Bump `@babel/traverse` from 7.22.5 to 7.23.2 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1147](https://github.com/10up/distributor/pull/1147)).

## [2.0.1] - 2023-09-18
### Changed
- Update from Cypress v10 to v13 (props [@dkotter](https://github.com/dkotter), [@iamdharmesh](https://github.com/iamdharmesh), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#1128](https://github.com/10up/distributor/pull/1128)).
Expand Down Expand Up @@ -486,6 +504,7 @@ This adds a post type selector when viewing the Pull Content list for both exter
- Initial closed release.

[Unreleased]: https://github.com/10up/distributor/compare/trunk...develop
[2.0.2]: https://github.com/10up/distributor/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/10up/distributor/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/10up/distributor/compare/1.9.1...2.0.0
[1.9.1]: https://github.com/10up/distributor/compare/1.9.0...1.9.1
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> Distributor is a WordPress plugin that makes it easy to distribute and reuse content across your websites — whether in a single multisite or across the web.
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Tests](https://github.com/10up/distributor/actions/workflows/test.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/test.yml) [![Linting](https://github.com/10up/distributor/actions/workflows/lint.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/lint.yml) [![Code scanning](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml) [![Release Version](https://img.shields.io/github/release/10up/distributor.svg)](https://github.com/10up/distributor/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v6.3%20tested-success.svg) [![License](https://img.shields.io/github/license/10up/distributor.svg)](https://github.com/10up/distributor/blob/develop/LICENSE.md)
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Tests](https://github.com/10up/distributor/actions/workflows/test.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/test.yml) [![Linting](https://github.com/10up/distributor/actions/workflows/lint.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/lint.yml) [![Code scanning](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml) [![Release Version](https://img.shields.io/github/release/10up/distributor.svg)](https://github.com/10up/distributor/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v6.4%20tested-success.svg) [![License](https://img.shields.io/github/license/10up/distributor.svg)](https://github.com/10up/distributor/blob/develop/LICENSE.md)

*You can learn more about Distributor's features at [DistributorPlugin.com](https://distributorplugin.com) and documentation at the [Distributor documentation site](https://10up.github.io/distributor/).*

Expand Down
4 changes: 2 additions & 2 deletions distributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/10up/distributor
* Update URI: https://distributorplugin.com
* Description: Makes it easy to distribute and reuse content across your websites, whether inside of a multisite or across the web.
* Version: 2.0.1
* Version: 2.0.2
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up Inc.
Expand All @@ -28,7 +28,7 @@
exit; // Exit if accessed directly.
}

define( 'DT_VERSION', '2.0.1' );
define( 'DT_VERSION', '2.0.2' );
define( 'DT_PLUGIN_FILE', preg_replace( '#^.*plugins/(.*)$#i', '$1', __FILE__ ) );
define( 'DT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'DT_PLUGIN_FULL_FILE', __FILE__ );
Expand Down
22 changes: 19 additions & 3 deletions docs/snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,27 @@ add_action( 'plugins_loaded', function() {
*
* This filter is used to filter the arguments sent to the remote server during a push. The below code snippet passes the original published date to the new pushed post and sets the same published date instead of setting it as per the current time.
*/
add_filter( 'dt_push_post_args', function( $post_body, $post ) {
$post_body['post_date'] = $post->post_date;
add_filter( 'dt_push_post_args', function( $post_body, $post, $args, $connection ) {

// When pushing to an external connection, we use the REST API, so the name of the field is `date`.
// But when pushing to an internal connection, the attributes are sent to wp_insert_post, which expects `post_date`.
$field_prefix =( $connection instanceof \Distributor\ExternalConnections\WordPressExternalConnection ) ? '' : 'post_';

$post_body[ $field_prefix . 'date'] = $post->post_date;
$post_body[ $field_prefix . 'date_gmt'] = $post->post_date_gmt;

return $post_body;
}, 10, 2 );
}, 10, 4 );

/**
* This filters the the arguments passed into wp_insert_post during a pull
*/
add_filter( 'dt_pull_post_args', function( $post_array, $remote_id, $post ) {
$post_array['post_date'] = $post->post_date;
$post_array['post_date_gmt'] = $post->post_date_gmt;

return $post_array;
}, 10, 3 );
```

### Automatically unlink posts
Expand Down
24 changes: 22 additions & 2 deletions includes/classes/DistributorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ protected function post_data() {
'excerpt' => $this->post->post_excerpt,
'parent' => ! empty( $this->post->post_parent ) ? (int) $this->post->post_parent : 0,
'status' => $this->post->post_status,
'date' => $this->post->post_date,
'date_gmt' => $this->post->post_date_gmt,

'distributor_media' => $this->get_media(),
'distributor_terms' => $this->get_terms(),
'distributor_meta' => $this->get_meta(),
Expand Down Expand Up @@ -857,11 +860,19 @@ protected function to_insert( $args = array() ) {
if ( ! empty( $args['remote_post_id'] ) ) {
// Updating an existing post.
$insert['ID'] = (int) $args['remote_post_id'];
// Never update the post status when updating a post.
unset( $insert['post_status'] );
} elseif ( ! empty( $args['post_status'] ) ) {
$insert['post_status'] = $args['post_status'];
}

if ( ! empty( $args['post_status'] ) ) {
$insert['post_status'] = $args['post_status'];
if (
isset( $insert['post_status'] )
&& 'future' === $insert['post_status']
) {
// Set the post date to the future date.
$insert['post_date'] = $post_data['date'];
$insert['post_date_gmt'] = $post_data['date_gmt'];
}

// Post meta used by wp_insert_post, wp_update_post.
Expand Down Expand Up @@ -921,6 +932,15 @@ protected function to_pull_list( $args = array() ) {
protected function to_rest( $rest_args = array() ) {
$post_data = $this->post_data();

/*
* Unset dates.
*
* External connections do not allow for the pulling or pushing of
* scheduled posts so these can be ignored.
*/
unset( $post_data['date'] );
unset( $post_data['date_gmt'] );

if ( ! empty( $post_data['parent'] ) ) {
$post_data['distributor_original_post_parent'] = (int) $post_data['parent'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ public function pull( $items ) {
$current_blog_id = get_current_blog_id();

if ( ! empty( $post_props['meta']['dt_connection_map'] ) ) {
foreach ( $post_props['meta']['dt_connection_map'] as $distributed ) {
foreach ( $post_props['meta']['dt_connection_map'] as $connection_type => $distributed ) {
$distributed = maybe_unserialize( $distributed );

if ( array_key_exists( $current_blog_id, $distributed['internal'] ) ) {
if ( 'internal' === $connection_type && array_key_exists( $current_blog_id, $distributed ) ) {
$dt_pull_messages['duplicated'] = 1;
continue 2;
}
Expand Down
Loading

0 comments on commit 76eb110

Please sign in to comment.