Guest User

Untitled

a guest
Nov 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. function duplicate_wp_robot_imported_posts_for_wpml( $post_id, $post = null )
  2. {
  3. if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  4. return;
  5.  
  6. if( is_object( $post ) && isset( $post->post_type ) && $post->post_type == 'post' )
  7. {
  8. $new = $post;
  9. $new->ID = null;
  10.  
  11. remove_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
  12.  
  13. if( ! is_wp_error( $spanish_id = wp_insert_post( $new ) ) )
  14. {
  15. global $wpdb;
  16. add_post_meta( $spanish_id, '_icl_lang_duplicate_of', $post_id );
  17. $oldtrid = $wpdb->get_var( $wpdb->prepare( 'SELECT translation_id FROM wp_icl_translations WHERE element_type = "post_post" AND element_id = %d', $post_id ) );
  18.  
  19. if( isset( $oldtrid ) && ! is_wp_error( $oldtrid ) )
  20. $wpdb->query( $wpdb->prepare( 'insert into %sicl_translations ( element_type,element_id, trid, language_code, source_language ) values( "post_post", %d, %s, "es","en" )', $wpdb->prefix, $spanish_id, $oldtrid ) );
  21. else
  22. {
  23. if( isset( $oldtrid ) )
  24. wp_die( sprintf( '<pre class="debug">%s</pre>', print_r( $oldtrid, 1 ) ) );
  25. }
  26. }
  27. else
  28. wp_die( $spanish_id->get_error_message() );
  29.  
  30.  
  31. add_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
  32. }
  33. }
  34. add_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
Add Comment
Please, Sign In to add comment