Answer the question
In order to leave comments, you need to log in
How to run the function if a post is published or there is a “tick”?
Good afternoon!
I wrote my own crossposting of posts in VKontakte (yes, yes, I know that there are plugins for this, but I love "mine" :) )
// кросспостинг вконтакте
add_action('transition_post_status', 'send_to_cross_post', '100', '3');
function send_to_cross_post($new_status, $old_status, $post){
if (($new_status == 'publish' && $old_status != 'publish')) {
cross_post($post); // отправляем в функцию кросспостинга
}
}
Answer the question
In order to leave comments, you need to log in
1. And if you remove $old_status != 'publish'?
2. Adding directly "before the publish button" is not very easy, why hack. Use add_metabox.
3. Why not put your function call on save_post instead of transition_post_status? And it additionally checks whether autosave is being done and whether the status is appropriate ('pusblish', so that drafts do not fly away).
UPD: Clarification and solution in the comments to the answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question