Try this…
add_action('post_updated', 'myfunction');
function myfunction( $post_id ) {
global $post;
if (!file_exists("/www/foo/blog/wp-content/uploads/" . $post_id)) {
mkdir("/www/foo/blog/wp-content/uploads/" . $post_id, 0777);
}
}
NOTE: Change from save_posts
to post_updated
which will stop the duplicate issue as it fires on “publish” only and not every time you hit add new
or update
etc.
NOTE: I verified this for you by testing the snippet above – all good.
NOTE: You can also use (wp_upload_dir() . $post_id, 0777)
if you want a path that is more transportable or if you are developing a plugin or theme for public use.