2016-11-22 75 views

回答

3

我認爲你正在尋找的鉤draft_to_publish

如果你是想只在一個新的崗位,我會考慮在帖子的發佈目標發送電子郵件。你甚至可以看看transition_post_status掛鉤,只是實現條件,如果帖子被編輯了,這樣的事情可能工作:

function so_post_40744782($new_status, $old_status, $post) { 
    if ($new_status == 'publish' && $old_status != 'publish') { 
     $author = "foobar"; 
     $message = "We wanted to notify you a new post has been published."; 
     wp_mail($author, "New Post Published", $message); 
    } 
} 
add_action('transition_post_status', 'so_post_40744782', 10, 3); 
+0

的ID這將是在那裏我開始爲好。這裏有一些關於它的更多信息:https://codex.wordpress.org/Post_Status_Transitions – AndyWarren

+1

@AndyWarren我只是在想這個,並做了一個編輯。 –

+0

這些參數是什麼:'so_post_40744782',10,3? – yarek

0

你應該以充分理解問題讀取來自WordPress的法典Post Status Transitions

覆蓋大多數情況下,比如,一個可能的解決方案是:

add_action('draft_to_publish', 'postPublished'); 
add_action('future_to_publish', 'postPublished'); 
add_action('private_to_publish', 'postPublished');