Varsayıyorum 'product'
. Bu yeni 'product'
gönderisi oluşturulduğunda bir işlev (kullanıcı oluşturulmuş) gerçekleştirmenin bir yolu var mı?
Functions.php içinde:
function mynewproduct(){
myfunction();
}
add_action( 'new_product', 'mynewproduct' );
Daha fazla ve resmi belgeler için buraya bakın:
Merhaba @dotty:
/wp-includes/post.php
dosyasındaki wp_insert_post()
işlevinin sonuna bir göz atın (WordPress 3.0.1'de 2148 - 2392 arasındaki satırlarda. WordPress'in bu işlevi yazı gönderme ve güncelleme için kullandığını unutmayın. )
Sonunda aşağıdaki koda sahiptir. Bu koddan wp_transition_post_status()
çağrısını tanımlayabilirsiniz (biraz daha fazlası için) ve eylem kancalarına sahibiz edit_post
, post_updated
, save_post
ve wp_insert_post
( açıkçası bu sadece iki yerine neden ikinci ikimiz var one. ) İhtiyaçlarınıza uygun olanlardan herhangi birini kullanabilirsiniz:
<?php
wp_transition_post_status($data['post_status'], $previous_status, $post);
if ( $update ) {
do_action('edit_post', $post_ID, $post);
$post_after = get_post($post_ID);
do_action( 'post_updated', $post_ID, $post_after, $post_before);
}
do_action('save_post', $post_ID, $post);
do_action('wp_insert_post', $post_ID, $post);
return $post_ID;
Ve @Jan Fabry belirtildiği gibi, wp_transition_post_status()
içinde bulunan eylem kancaları var (WordPress 3.0.1'de 2713 - 2717, /wp-includes/post.php
adreslerinde.) uygun şekilde kullanın:
<?php
function wp_transition_post_status($new_status, $old_status, $post) {
do_action('transition_post_status', $new_status, $old_status, $post);
do_action("${old_status}_to_$new_status", $post);
do_action("${new_status}_$post->post_type", $post->ID, $post);
}
wp_transition_post_status
işlevi çağrılacak ve bu, "${new_status}_$post->post_type"
eylemini tetikleyecektir, böylece product
publish
durumuna geçerse, publish_product
eylemi tetiklenir.