Start New Polylang Translations With the Original Content
Pre-fills the title, content and excerpt of a new translation with the source post's text when you click the "+" icon in Polylang, so translators can work over the original instead of an empty editor.
Opens WPIDE on
Code
$wpide_source = function () {
if ( empty( $_GET['from_post'] ) || empty( $_GET['new_lang'] ) || ! function_exists( 'pll_get_post_language' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return null;
}
$post = get_post( absint( $_GET['from_post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
return $post && current_user_can( 'edit_post', $post->ID ) ? $post : null;
};
add_filter( 'default_title', function ( $title ) use ( $wpide_source ) {
$post = $wpide_source();
return $post ? $post->post_title : $title;
} );
add_filter( 'default_content', function ( $content ) use ( $wpide_source ) {
$post = $wpide_source();
return $post ? $post->post_content : $content;
} );
add_filter( 'default_excerpt', function ( $excerpt ) use ( $wpide_source ) {
$post = $wpide_source();
return $post ? $post->post_excerpt : $excerpt;
} );
Notes
Polylang's free version already copies taxonomies and custom fields; this adds the text. Only works for posts the user can edit.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.