MultilingualPress compatibility

MultilingualPress is an excellent solution to configure your WordPress sites in multiple languages. The WordPress multisite base is used to configure a site for each language. So, the MultilingualPress plugin makes the connections between the different contents in an efficient and easy way. With much less server performance load than WPML or similar.

The problem we have is that Bricks and MultilingualPress currently don’t get along very well.
There is a problem with regenerating CSS files after saving changes in the editor of a page or post (or modifying a custom field). The bricks CSS is removed and the layout is broken.

To solve this, for now, you must have the CSS configured in inline mode. So everything works fine. But at the level of performance and optimization, it is better to have external CSS files.

I have configured a custom function for the functions.php of the child-theme, in which after 2 seconds of doing a “save_post”, the Bricks CSS of that post or page that has been updated is regenerated. This small action solves the problem that the brick design breaks.

It may not be the best way and could lead to problems. For this reason, I have added this compatibility to the Bricks “idea board”. But in the meantime, I leave you the code in case it can help someone.


function custom_schedule_css_regeneration_on_save_post( $post_id ) {
 if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
 return;
 }
 $timestamp = time() + 2;
 wp_schedule_single_event( $timestamp, 'custom_regenerate_bricks_css', array( $post_id ) );
}
add_action( 'save_post', 'custom_schedule_css_regeneration_on_save_post' );

function custom_regenerate_bricks_css( $post_id ) {

 if ( class_exists( '\Bricks\Assets_Files' ) && method_exists( '\Bricks\Assets_Files', 'generate_post_css_file' ) ) {
 $area = \Bricks\Templates::get_template_type( $post_id );
 $elements = \Bricks\Database::get_data( $post_id, $area );
 \Bricks\Assets_Files::generate_post_css_file( $post_id, $area, $elements );
 }
}
add_action( 'custom_regenerate_bricks_css', 'custom_regenerate_bricks_css', 10, 1 );


1 Like

Fantastic, I am just looking into buying MultilingualPress. This will be helpful.