save_post trigerred twice

I am trying to add more functionality to the update button. My end result is that I wish to call a python script but for now I am messing around with writing a log file. This is resulting in the log file being written to twice. Can someone help me?

 add_action('save_post', 'test',10,2);

function test($id, $post) 
{
    if ($post-post_type != 'item'){
        return;
    }

     if (defined('DOING_AUTOSAVE')  DOING_AUTOSAVE ) {
        return;
    }

    if (wp_is_post_revision($id)) {
        return;
    }

    if (wp_is_post_autosave($id)) {
        return;
    }

    $tmp = fopen(dirname(__file__).'/my_logs.txt', a+); 
    fwrite($tmp,\n.$id. - Fail\n);
    fclose($tmp);     
           

}

I added the following:

 if(did_action($save_post)==0){
    $tmp = fopen(dirname(__file__).'/my_logs.txt', a+); 
    fwrite($tmp,\n.did_action($save_post). - Fail\n);
    fclose($tmp);     
}

but still I am getting:

0 - Fail

0 - Fail

Topic save-post php hooks Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.