Title: Multiple Hooks Triggering handle_post
Last modified: November 22, 2024

---

# Multiple Hooks Triggering handle_post

 *  Resolved [Rick Hoekman](https://wordpress.org/support/users/rhoekman/)
 * (@rhoekman)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/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:
 *     ```wp-block-code
       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'));}
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [Emma Blackwell](https://wordpress.org/support/users/lunaraurora/)
 * (@lunaraurora)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/multiple-hooks-triggering-handle_post/#post-18162525)
 * [@rhoekman](https://wordpress.org/support/users/rhoekman/) thanks so much for
   your suggestion, will be in the next update

Viewing 1 replies (of 1 total)

The topic ‘Multiple Hooks Triggering handle_post’ is closed to new replies.

 * ![](https://ps.w.org/simple-auto-poster-for-bluesky/assets/icon-256x256.png?rev
   =3166681)
 * [Simple Auto-Poster for Bluesky](https://wordpress.org/plugins/simple-auto-poster-for-bluesky/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-auto-poster-for-bluesky/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-auto-poster-for-bluesky/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-auto-poster-for-bluesky/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-auto-poster-for-bluesky/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-auto-poster-for-bluesky/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Emma Blackwell](https://wordpress.org/support/users/lunaraurora/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/multiple-hooks-triggering-handle_post/#post-18162525)
 * Status: resolved