• Resolved Myar

    (@myar)


    Hi,

    great plugin!

    But I have a question:
    How can I trigger the action to clear a post cache when the wordpress function wp_insert_comment is called?

    I have a standalone forum software and developed a plugin to insert comments from the forum to the comments of a post.
    So after getting the inforamtions from the forum post I call wp_insert_comment($data) and the comment ist created in the WP Database. But the cache for the post is not cleared so the comment that is submitted from the forum is not showing up immediately.
    How can I trigger your plugin function after submit the comment with wp_insert_comment?

    Can you help me here please?

Viewing 1 replies (of 1 total)
  • Plugin Author ekaterir

    (@ekaterir)

    Hello @myar,

    You can call a function called
    csnx_delete_current_page_cache_on_comments( $comment ) it’s located in
    snipe-nginx-cache/includes/cache-sniper-nginx-comments.php
    $comment can be an object or an id, the function will figure that out.
    So it can look something like this:

    require_once plugin_dir_path( __FILE__ ) . '../snipe-nginx-cache/includes/cache-sniper-nginx-comments.php';
    
    // get your comment object or id
    
    $commentSniper = new Cache_Sniper_Nginx_Comments();
    $commentSniper->csnx_delete_current_page_cache_on_comments( $comment );

    However, this will introduce a dependency in your plugin.
    I think there is a hook I can use to trigger cache clear on wp_insert_comment.

    You can try the approach described above for now and I will let you know when we implement the wp_insert_comment action hook.

    Thank you for raising the issue.

Viewing 1 replies (of 1 total)
  • The topic ‘How to trigger clear post cache on comment’ is closed to new replies.