Advertisement
Guest User

WPML duplicate_master_post - 0.02

a guest
Feb 18th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. function duplicate_master_post($post_id, $post, $update){
  2.     global $sitepress, $iclTranslationManagement;
  3.    
  4.     $only_cpt   = array();
  5.     $only_cpt[] = 'book';
  6.    
  7.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  8.         return;
  9.     }
  10.     // don't save for revisions
  11.     if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
  12.         return;
  13.     }
  14.     // only duplicate when publishing
  15.     if ($post->post_status != 'publish') {
  16.         return;
  17.     }
  18.     // avoid recursion
  19.     remove_action('wp_insert_post', 'duplicate_master_post', 10);
  20.  
  21.     if ( !isset( $iclTranslationManagement ) ) {
  22.         $iclTranslationManagement = new TranslationManagement;
  23.     }
  24.        
  25.     $post_type = get_post_type( $post_id );
  26.     if ( $sitepress->is_translated_post_type( $post_type ) && in_array( $post_type, $only_cpt ) ) {
  27.         $iclTranslationManagement->make_duplicates_all( $post_id );
  28.     }
  29. }
  30. add_action('wp_insert_post', 'duplicate_master_post', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement