'url',
'title' => __( 'URL modifications', 'polylang' ),
'description' => __( 'Decide how your URLs will look like.', 'polylang' ),
'configure' => true,
) );
$this->links_model = &$polylang->links_model;
$this->page_on_front = &$polylang->static_pages->page_on_front;
}
/**
* Displays the fieldset to choose how the language is set
*
* @since 1.8
*/
protected function force_lang() {?>
%s',
$this->options['force_lang'] ? '' : 'checked="checked"',
esc_html__( 'The language is set from content', 'polylang' )
);?>
%s',
1 == $this->options['force_lang'] ? 'checked="checked"' : '',
$this->links_model->using_permalinks ? esc_html__( 'The language is set from the directory name in pretty permalinks', 'polylang' ) : esc_html__( 'The language is set from the code in the URL', 'polylang' )
);?>
' . esc_html( home_url( $this->links_model->using_permalinks ? 'en/my-post/' : '?lang=en&p=1' ) ) . '';?>
%s',
$this->links_model->using_permalinks ? '' : 'disabled="disabled"',
2 == $this->options['force_lang'] ? 'checked="checked"' : '',
esc_html__( 'The language is set from the subdomain name in pretty permalinks', 'polylang' )
);?>
' . esc_html( str_replace( array( '://', 'www.' ), array( '://en.', '' ), home_url( 'my-post/' ) ) ) . '';?>
%s',
$this->links_model->using_permalinks ? '' : 'disabled="disabled"',
3 == $this->options['force_lang'] ? 'checked="checked"' : '',
esc_html__( 'The language is set from different domains', 'polylang' )
);?>
%s',
$this->options['hide_default'] ? 'checked="checked"' :'',
esc_html__( 'Hide URL language information for default language', 'polylang' )
);?>
%s',
$this->links_model->using_permalinks ? '' : 'disabled="disabled"',
$this->options['rewrite'] ? 'checked="checked"' : '',
esc_html__( 'Remove /language/ in pretty permalinks', 'polylang' )
);?>
' . esc_html( home_url( 'en/' ) ) . '';?>
%s',
$this->links_model->using_permalinks ? '' : 'disabled="disabled"',
$this->options['rewrite'] ? '' : 'checked="checked"',
esc_html__( 'Keep /language/ in pretty permalinks', 'polylang' )
);?>
' . esc_html( home_url( 'language/en/' ) ) . '';?>
%s',
$this->options['redirect_lang'] ? 'checked="checked"' :'',
esc_html__( 'The front page url contains the language code instead of the page name or page id', 'polylang' )
);?>
model->post->get_language( $this->page_on_front );
$lang = $lang ? $lang : $this->model->get_language( $this->options['default_lang'] );
printf(
/* translators: %s are urls */
esc_html__( 'Example: %s instead of %s', 'polylang' ),
'' . esc_html( $this->links_model->home_url( $lang ) ) . '
',
'' . esc_html( _get_page_link( $this->page_on_front ) ) . '
'
); ?>
force_lang(); ?>
$this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>hide_default(); ?>
links_model->using_permalinks ) { ?>
$this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>rewrite(); ?>
page_on_front ) { ?>
redirect_lang(); ?>
$domain ) {
if ( empty( $domain ) ) {
$lang = $this->model->get_language( $key );
add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
/* translators: %s is a native language name */
__( 'Please enter a valid URL for %s.', 'polylang' ), $lang->name
) ) );
}
else {
$newoptions['domains'][ $key ] = esc_url_raw( trim( $domain ) );
}
}
}
foreach ( array( 'hide_default', 'redirect_lang' ) as $key ) {
$newoptions[ $key ] = isset( $options[ $key ] ) ? 1 : 0;
}
if ( 3 == $options['force_lang'] ) {
$newoptions['browser'] = $newoptions['hide_default'] = 0;
}
// Check if domains exist
if ( $newoptions['force_lang'] > 1 ) {
$this->check_domains( $newoptions );
}
return $newoptions; // Take care to return only validated options
}
/**
* Check if subdomains or domains are accessible
*
* @since 1.8
*
* @param array $options new set of options to test
*/
protected function check_domains( $options ) {
$options = array_merge( $this->options, $options );
$model = new PLL_Model( $options );
$links_model = $model->get_links_model();
foreach ( $this->model->get_languages_list() as $lang ) {
$url = add_query_arg( 'deactivate-polylang', 1, $links_model->home_url( $lang ) );
// Don't redefine vip_safe_wp_remote_get() as it has not the same signature as wp_remote_get()
$response = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( esc_url_raw( $url ) ) : wp_remote_get( esc_url_raw( $url ) );
$response_code = wp_remote_retrieve_response_code( $response );
if ( 200 != $response_code ) {
add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
/* translators: %s is an url */
__( 'Polylang was unable to access the URL %s. Please check that the URL is valid.', 'polylang' ), $url
) ) );
}
}
}
}