From 5cef237b84b41fb407f39c7952105c428c72f40c Mon Sep 17 00:00:00 2001 From: pjv Date: Wed, 7 Jun 2023 09:37:10 -0500 Subject: [PATCH] Auto-post fixes * Auto-post only on first publication - not updates of old posts. * Auto post only of type 'post' (currently not pages or custom post types). * Fix not saving auto publish settings to running settings instance. --- classes/class-nostrtium-settings.php | 1 + classes/class-nostrtium.php | 8 ++++++-- nostrtium.php | 4 ++-- readme.txt | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/classes/class-nostrtium-settings.php b/classes/class-nostrtium-settings.php index 771364e..8a29e95 100644 --- a/classes/class-nostrtium-settings.php +++ b/classes/class-nostrtium-settings.php @@ -51,6 +51,7 @@ public function get_auto_publish_settings() { } public function set_auto_publish_settings(array $ap) { update_option('nostrtium-auto-publish', $ap); + $this->auto_publish_settings = $ap; } public function save_auto_publish_settings() { check_ajax_referer('nostrtium-ajax-nonce', 'security'); diff --git a/classes/class-nostrtium.php b/classes/class-nostrtium.php index 539b1a0..dbe7eea 100644 --- a/classes/class-nostrtium.php +++ b/classes/class-nostrtium.php @@ -36,7 +36,7 @@ private function __construct() { add_action('wp_ajax_pjv_nostrtium_post_note', [$this, 'post_note']); } - add_action('publish_post', [$this, 'maybe_publish_post_to_nostr'], 10, 2); + add_action('transition_post_status', [$this, 'maybe_publish_post_to_nostr'], 10, 3); add_action('plugins_loaded', [$this, 'check_version']); } @@ -80,7 +80,11 @@ public function enqueue($page) { } } - public function maybe_publish_post_to_nostr($post_id, $post) { + public function maybe_publish_post_to_nostr($new_status, $old_status, $post) { + // only post on initial publication, not on updates + // no revisions, currently only posts (not pages, not custom types) + if (($new_status != "publish") || ($post->post_type != "post") || ($old_status == "publish")) return; + if (!$post->_nostrtium_posted && $this->settings->auto_publish_settings['autoPublish']) { $note = ""; diff --git a/nostrtium.php b/nostrtium.php index 2be3963..222e010 100644 --- a/nostrtium.php +++ b/nostrtium.php @@ -8,7 +8,7 @@ * Author URI: https://github.com/pjv * Text Domain: nostrtium * Domain Path: /languages - * Version: 0.7.0 + * Version: 0.7.1 * Requires at least 6.0 * Requires PHP 8.1 * License Unlicense @@ -21,7 +21,7 @@ exit; } -define('PJV_NOSTRTIUM_VERSION', '0.7.0'); +define('PJV_NOSTRTIUM_VERSION', '0.7.1'); define('PJV_NOSTRTIUM_DIR', plugin_dir_path(__FILE__)); define('PJV_NOSTRTIUM_DEFAULT_USER_ROLE', 'edit_posts'); define('PJV_NOSTRTIUM_STORAGE', wp_upload_dir()['basedir'] . '/nostrtium_' . md5(LOGGED_IN_SALT) . '/'); diff --git a/readme.txt b/readme.txt index 10d14b5..b58d08f 100644 --- a/readme.txt +++ b/readme.txt @@ -65,6 +65,11 @@ The manual installation method involves downloading the plugin and then uploadin == Changelog == += 0.7.1 = +* Auto-post only on first publication - not updates of old posts. +* Auto post only of type 'post' (currently not pages or custom post types). +* Fix not saving auto publish settings to running settings instance. + = 0.7.0 = * Allow auto posting excerpt, permalink, or both on publication of WordPress post. * NOTE: If you have installed a prior version, this update requires you to re-enter your private key on the Nostrtium settings page. This is a one-time occurrence.