Skip to content

Commit

Permalink
fix duplicate event logging
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsayan committed May 3, 2024
1 parent e3d5c0f commit 1b5cbb3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
29 changes: 19 additions & 10 deletions includes/sync/class-instawp-sync-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct() {
$this->restricted_cpts = (array) apply_filters( 'INSTAWP_CONNECT/Filters/two_way_sync_restricted_post_types', $this->restricted_cpts );

// Post Actions.
add_action( 'wp_after_insert_post', array( $this, 'handle_post' ), 999, 4 );
//add_action( 'wp_after_insert_post', array( $this, 'handle_post' ), 999, 4 );
add_action( 'elementor/document/after_save', array( $this, 'handle_elementor' ), 999 ); // elementor
add_action( 'before_delete_post', array( $this, 'delete_post' ), 10, 2 );
add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 3 );
Expand Down Expand Up @@ -79,6 +79,7 @@ public function handle_post( $post_id, $post, $update, $post_before ) {
}

$singular_name = InstaWP_Sync_Helpers::get_post_type_name( $post->post_type );

$this->handle_post_events( sprintf( __( '%s modified', 'instawp-connect' ), $singular_name ), 'post_change', $post, $post_before );
}

Expand Down Expand Up @@ -139,20 +140,28 @@ public function transition_post_status( $new_status, $old_status, $post ) {
return;
}

if ( $new_status === 'trash' && $new_status !== $old_status && $post->post_type !== 'customize_changeset' ) {
$event_name = sprintf( __( '%s trashed', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$this->handle_post_events( $event_name, 'post_trash', $post );
// Check auto save or revision.
if ( wp_is_post_autosave( $post->ID ) || wp_is_post_revision( $post->ID ) ) {
return;
}

if ( $new_status === 'draft' && $old_status === 'trash' ) {
if ( 'auto-draft' === $old_status && ( 'auto-draft' !== $new_status && 'inherit' !== $new_status ) ) {
$event_name = sprintf( __( '%s created', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$action = 'post_new';
} elseif ( 'auto-draft' === $new_status || ( 'new' === $old_status && 'inherit' === $new_status ) ) {
return;
} elseif ( 'trash' === $new_status ) {
$event_name = sprintf( __( '%s trashed', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$action = 'post_trash';
} elseif ( 'trash' === $old_status ) {
$event_name = sprintf( __( '%s restored', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$this->handle_post_events( $event_name, 'untrashed_post', $post );
$action = 'untrashed_post';
} else {
$event_name = sprintf( __( '%s modified', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$action = 'post_change';
}

if ( $old_status === 'auto-draft' && $new_status !== $old_status ) {
$event_name = sprintf( __( '%s created', 'instawp-connect' ), InstaWP_Sync_Helpers::get_post_type_name( $post->post_type ) );
$this->handle_post_events( $event_name, 'post_new', $post );
}
$this->handle_post_events( $event_name, $action, $post );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions instawp-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @wordpress-plugin
* Plugin Name: InstaWP Connect
* Description: 1-click WordPress plugin for Staging, Migrations, Management, Sync and Companion plugin for InstaWP.
* Version: 0.1.0.33
* Version: 0.1.0.34
* Author: InstaWP Team
* Author URI: https://instawp.com/
* License: GPL-3.0+
Expand All @@ -25,7 +25,7 @@

global $wpdb;

defined( 'INSTAWP_PLUGIN_VERSION' ) || define( 'INSTAWP_PLUGIN_VERSION', '0.1.0.33' );
defined( 'INSTAWP_PLUGIN_VERSION' ) || define( 'INSTAWP_PLUGIN_VERSION', '0.1.0.34' );
defined( 'INSTAWP_API_DOMAIN_PROD' ) || define( 'INSTAWP_API_DOMAIN_PROD', 'https://app.instawp.io' );

$wp_plugin_url = WP_PLUGIN_URL . '/' . plugin_basename( __DIR__ ) . '/';
Expand Down
20 changes: 10 additions & 10 deletions languages/instawp-connect.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-05-03 11:12+0000\n"
"POT-Creation-Date: 2024-05-03 13:44+0000\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
Expand Down Expand Up @@ -735,31 +735,31 @@ msgstr ""
msgid "Plugin could not be deleted."
msgstr ""

#: includes/sync/class-instawp-sync-post.php:82, includes/sync/class-instawp-sync-term.php:54
#: includes/sync/class-instawp-sync-post.php:83, includes/sync/class-instawp-sync-post.php:160, includes/sync/class-instawp-sync-term.php:54
msgid "%s modified"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:125, includes/sync/class-instawp-sync-term.php:76
#: includes/sync/class-instawp-sync-post.php:126, includes/sync/class-instawp-sync-term.php:76
msgid "%s deleted"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:143
msgid "%s trashed"
#: includes/sync/class-instawp-sync-post.php:157
msgid "%s restored"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:148
msgid "%s restored"
#: includes/sync/class-instawp-sync-post.php:154
msgid "%s trashed"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:153, includes/sync/class-instawp-sync-term.php:32
#: includes/sync/class-instawp-sync-post.php:149, includes/sync/class-instawp-sync-term.php:32
msgid "%s created"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:170
#: includes/sync/class-instawp-sync-post.php:179
msgid "Media created"
msgstr ""

#: includes/sync/class-instawp-sync-post.php:188
#: includes/sync/class-instawp-sync-post.php:197
msgid "Media updated"
msgstr ""

Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: clone, migrate, staging, backup, restore
Requires at least: 5.6
Tested up to: 6.5.2
Requires PHP: 5.6
Stable tag: 0.1.0.33
Stable tag: 0.1.0.34
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html

Expand Down Expand Up @@ -94,10 +94,10 @@ Need support or want to partner with us? Go to our [website](http://instawp.com/

== Changelog ==

= 0.1.0.34 =
- NEW - Added WooCommerce related APIs.
= 0.1.0.34 - 3 May 2024 =
- NEW - Added Expand/Collapse to migration visibility.
- FIX - Typos and untranslated strings.
- FIX - @ way sync duplicate event logging.

= 0.1.0.33 - 2 May 2024 =
- FIX - Fixed display of parent sites list for 2 way sync.
Expand Down

0 comments on commit 1b5cbb3

Please sign in to comment.