Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function duplicate_wp_robot_imported_posts_for_wpml( $post_id, $post = null )
- {
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- if( is_object( $post ) && isset( $post->post_type ) && $post->post_type == 'post' )
- {
- $new = $post;
- $new->ID = null;
- remove_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
- if( ! is_wp_error( $spanish_id = wp_insert_post( $new ) ) )
- {
- global $wpdb;
- add_post_meta( $spanish_id, '_icl_lang_duplicate_of', $post_id );
- $oldtrid = $wpdb->get_var( $wpdb->prepare( 'SELECT translation_id FROM wp_icl_translations WHERE element_type = "post_post" AND element_id = %d', $post_id ) );
- if( isset( $oldtrid ) && ! is_wp_error( $oldtrid ) )
- $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 ) );
- else
- {
- if( isset( $oldtrid ) )
- wp_die( sprintf( '<pre class="debug">%s</pre>', print_r( $oldtrid, 1 ) ) );
- }
- }
- else
- wp_die( $spanish_id->get_error_message() );
- add_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
- }
- }
- add_action( 'save_post', 'duplicate_wp_robot_imported_posts_for_wpml', 10, 2 );
Add Comment
Please, Sign In to add comment