Multilingual Press (free) : add custom post type support
17/04/2012: Updated for Multilingual Press 1.0.3
Multilingual Press plugin allows to have a multilingual WordPress, using a multisite installation. It does his job very well except it works only with posts and pages for the free version. If you want to enable it on your custom post types, you can either buy the pro version or follow two simple steps, after the break.
For this example, I'll add support for two post types named "book" and "gallery" (change according to your needs):
Open /wp-content/plugins/multilingual-press/multilingual-press.php in your favorite editor
- Line 655, replace :
if ( 'post' != $postdata[ 'post_type'] && 'page' != $postdata[ 'post_type'] )
return;
by :
if ( !in_array( $postdata['post_type'], array( 'post', 'page', 'book', 'gallery' ) ) )
return;
- Line 763, replace :
public function add_meta_boxes() {
global $post;
// Do we have linked elements?
$linked = mlp_get_linked_elements( $post->ID );
if ( ! $linked ) {
add_meta_box( 'multilingual_press_translate', __( 'Multilingual Press: Translate Post', $this->get_textdomain() ), array( $this, 'display_meta_box_translate' ), 'post', 'normal', 'high' );
add_meta_box( 'multilingual_press_translate', __( 'Multilingual Press: Translate Page', $this->get_textdomain() ), array( $this, 'display_meta_box_translate' ), 'page', 'normal', 'high' );
return;
}
// Register metaboxes
add_meta_box( 'multilingual_press_link', __( 'Multilingual Press: Linked posts', $this->get_textdomain() ), array( $this, 'display_meta_box' ), 'post', 'normal', 'high' );
add_meta_box( 'multilingual_press_link', __( 'Multilingual Press: Linked pages', $this->get_textdomain() ), array( $this, 'display_meta_box' ), 'page', 'normal', 'high' );
}
by :
public function add_meta_boxes() {
global $post;
$post_types = array('post', 'page', 'book', 'gallery');
// Do we have linked elements?
$linked = mlp_get_linked_elements( $post->ID );
foreach($post_types as $post_type){
if ( ! $linked ) {
add_meta_box( 'multilingual_press_translate', __( 'Multilingual Press: Translate Post', $this->get_textdomain() ), array( $this, 'display_meta_box_translate' ), $post_type, 'normal', 'high' );
} else {
add_meta_box( 'multilingual_press_link', __( 'Multilingual Press: Linked posts', $this->get_textdomain() ), array( $this, 'display_meta_box' ), $post_type, 'normal', 'high' );
}
}
}
Tags: Multilingual Press, tips & tricks
Trackback from your site.
Comments (4)
Victor M
| #
Nice Move!
I want to add support to a custom post type generated by other plugin (A Real Estate Listings one, by Firestorm). So I dont know the post type name should I add support for.
Where can I find the type (eg. book, gallery…) for that one and change accordingly in multilingual php?
Or is not that easy?
Reply
Alexis Nominé
| #
A quick way to know it is to have a look at the URL of the listing in the admin which should look like http://mydomain.com/wp-admin/edit.php?post_type=theposttype . That’s the last bit.
In your particular case, I had a quick look at how Firestorm’s plugin works, and it looks like it’s not using the standard WordPress structure but creates stuff in your database and queries it directly, which I think is a bad practice.
So I’m afraid my trick won’t work for you :S
I’d advise you to try some other more modern plugins if you can, or some paid solutions like WP Pro Real Estate or OpenDoor (I’m not affiliated with them but working on a real estate project right now 🙂 )
Cheers
Reply
Cbinger
| #
With the new Version 1.1.1 this way doesn’t work anymore. Do you have an update?
Reply
Alexis Nominé
| #
From what I see, you have to look at line 519 instead of 655 for the first instruction, and line 692 instead of 763 for the second one.
I’ve not tested it yet but it should work.
Cheers
Reply