Skip to content

Commit

Permalink
Auto-post fixes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pjv committed Jun 7, 2023
1 parent d109c6f commit 5cef237
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions classes/class-nostrtium-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 6 additions & 2 deletions classes/class-nostrtium.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down Expand Up @@ -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 = "";

Expand Down
4 changes: 2 additions & 2 deletions nostrtium.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) . '/');
Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5cef237

Please sign in to comment.