Multiple Hooks Triggering handle_post
-
Issue: Your plugin hooks the
handle_postmethod to bothpublish_postandwp_insert_postactions:
This means thathandle_postis 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_posthook and rely solely on thepublish_posthook. This ensures thathandle_postis 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 (
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Multiple Hooks Triggering handle_post’ is closed to new replies.