Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install the Customizr-Polylang bridge code
// ====================================================================================================================
// Customizr-Polylang bridge: Makes the Customizr theme or the Featured Pages Unlimited
// plugin compatible with Polylang; Runs only if Polylang is active;
// ====================================================================================================================
// If Polylang is active, hook function on the admin pages
if ( function_exists( 'pll_register_string' ) ) add_action( 'admin_init', 'pll_tc_strings_setup' );
function pll_tc_strings_setup() {
// Find out what code we're running for our featured pages.
$running_fpu = ( class_exists( 'TC_fpu' ) );
$running_customizr = ( ( wp_get_theme()->Template ) == 'customizr' );
$running_customizr_pro = ( ( wp_get_theme()->Template ) == 'customizr-pro' );
$pll_tc_options = array();
$pll_tc_areas = array();
if ( $running_fpu || $running_customizr_pro ) { // Running Featured Pages Unlimited plugin: Setup FPU-defined featured page strings
// Get FPU options / get array of featured pages / set Polylang's translation group
$pll_tc_options = get_option( 'tc_unlimited_featured_pages' );
$pll_tc_areas = TC_utils_fpu::$instance->tc_get_custom_fp_nb();
$polylang_group = 'Featured Pages Unlimited';
// If also running Customizr, include front page slider name in our options array
if ( $running_customizr || $running_customizr_pro ) {
$pll_cust_options = get_option('tc_theme_options');
if ( $pll_cust_options['tc_front_slider'] ){ // is FALSE if option isn't set
$pll_tc_options['tc_front_slider'] = $pll_cust_options['tc_front_slider'];
}
}
}
if ( $running_customizr || $running_customizr_pro ) { // Running Customizr alone, without FPU: Setup Customizr-defined featured page strings
// Get Customizr options / get array of featured pages / set Polylang's translation group
$pll_tc_options = array_merge( $pll_tc_options , get_option( 'tc_theme_options' ) );
$pll_tc_areas = array_unique( array_merge( $pll_tc_areas , TC_init::$instance->fp_ids ) ); // returns array( 'one' , 'two' , 'three' )
$polylang_group = 'Customizr';
}
// Add featured pages button text to Polylang's string translation panel
if ( isset( $pll_tc_options['tc_featured_page_button_text'] ) )
pll_register_string( 'Featured pages button text', $pll_tc_options['tc_featured_page_button_text'], $polylang_group );
// Add featured pages excerpt text to Polylang's string translation panel
foreach ( $pll_tc_areas as $area ) {
if ( isset( $pll_tc_options['tc_featured_text_'.$area] ) )
pll_register_string( 'Featured text '.$area.'(200 char. max)', $pll_tc_options['tc_featured_text_'.$area], $polylang_group );
}
// Add front page slider name to Polylang's string translation panel
if ( isset( $pll_tc_options['tc_front_slider'] ) )
pll_register_string( 'Front page slider name', $pll_tc_options['tc_front_slider'], 'Customizr' );
}
// If Polylang is active, translate/swap featured page buttons/text/link and slider
if ( function_exists( 'pll_get_post' ) && function_exists( 'pll__' ) ) {
// Set hook prefix if running FPU. If not, default to Customizr. (Hooks won't be called anyway if neither is running)
$pll_tc_hook_prefix = ( class_exists( 'TC_fpu' ) ) ? 'fpc_' : 'tc_fp_';
// Substitute any page id with the equivalent page in current language (if found)
add_filter( $pll_tc_hook_prefix.'id', 'pll_tc_page_id' );
function pll_tc_page_id( $fp_page_id ) {
return is_int( pll_get_post( $fp_page_id ) ) ? pll_get_post( $fp_page_id ) : $fp_page_id;
}
// Substitute the featured page button text with the current language button text
add_filter( $pll_tc_hook_prefix.'button_text', 'pll__' );
// Substitute the featured page text with the translated featured page text
add_filter( $pll_tc_hook_prefix.'text', 'pll__' );
// Substitute any registered slider name
add_filter( 'tc_slider_name_id', 'pll__' );
}
@Nikeo

This comment has been minimized.

Copy link
Owner Author

@Nikeo Nikeo commented Jan 5, 2015

@Nikeo

This comment has been minimized.

Copy link
Owner Author

@Nikeo Nikeo commented Jan 5, 2015

Added a check on customizr-pro installed

$running_customizr_pro = ( ( wp_get_theme()->Template ) == 'customizr-pro' );
@eri-trabiccolo

This comment has been minimized.

Copy link

@eri-trabiccolo eri-trabiccolo commented Jan 5, 2015

made a new version,
though Nguyen is getting issue with it + customizr-pro. we'll see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.