Multiple Hooks Triggering handle_post
-
Issue:?Your plugin hooks the?
handle_post
?method to both?publish_post
?and?wp_insert_post
?actions:
This means that?handle_post
?is executed twice for a single post creation:- Once when the post is published (
publish_post
). - Again when the post is inserted into the database (
wp_insert_post
).
Recommendation:?Remove the?
wp_insert_post
?hook and rely solely on the?publish_post
?hook. This ensures that?handle_post
?is only triggered once when the post is actually published, reducing the risk of conflicts.Modified Constructor:
public function __construct() {
add_action('publish_post', [$this, 'handle_post'], 10, 2);
// Remove the following line to prevent double execution
// add_action('wp_insert_post', [$this, 'handle_post'], 10, 3);
add_action('admin_menu', [$this, 'add_settings_page']);
add_action('admin_init', [$this, 'register_settings']);
add_action('plugins_loaded', [$this, 'load_plugin_textdomain']);
// Set up logging
$upload_dir = wp_upload_dir();
$this->log_file = $upload_dir['basedir'] . '/bluesky_poster_log.txt';
$this->log(__("Plugin initialized", 'simple-auto-poster-for-bluesky'));
} - Once when the post is published (
- You must be logged in to reply to this topic.