PluginProbe
Polylang / 1.8
Polylang v1.8
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / settings / settings-browser.php

settings-browser.php in Polylang 1.8, at settings/settings-browser.php

76 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Settings class for browser language preference detection
5 *
6 * @since 1.8
7 */
8 class PLL_Settings_Browser extends PLL_Settings_Module {
9 /*
10 * constructor
11 *
12 * @since 1.8
13 *
14 * @param object $polylang polylang object
15 */
16 public function __construct( &$polylang ) {
17 parent::__construct( $polylang, array(
18 'module' => 'browser',
19 'title' => __( 'Detect browser language', 'polylang' ),
20 'description' => __( 'When the front page is visited, set the language according to the browser preference', 'polylang' ),
21 'active_option' => 3 > $polylang->options['force_lang'] ? 'browser' : false,
22 ) );
23
24 add_action( 'admin_print_footer_scripts', array( &$this, 'print_js' ) );
25 }
26
27 /*
28 * tells if the module is active
29 *
30 * @since 1.8
31 *
32 * @return bool
33 */
34 public function is_active() {
35 return 3 > $this->options['force_lang'] ? parent::is_active() : false;
36 }
37
38 /*
39 * displays the javascript to handle dynamically the change in url modifications
40 * as the preferred browser language is not used when the language is set from different domains
41 *
42 * @since 1.8
43 */
44 public function print_js() {
45 wp_enqueue_script( 'jquery' );
46
47 if ( parent::is_active() && 3 > $this->options['force_lang'] ) {
48 $func = 'removeClass( "inactive" ).addClass( "active" )';
49 $link = sprintf( '<span class="deactivate">%s</span>', $this->action_links['deactivate'] );
50 }
51 else {
52 $func = 'removeClass( "active" ).addClass( "inactive" )';
53 $link = sprintf( '<span class="activate">%s</span>', $this->action_links['activate'] );
54 }
55
56 $deactivated = sprintf( '<span class="deactivated">%s</span>', $this->action_links['deactivated'] );
57
58 ?>
59 <script type='text/javascript'>
60 //<![CDATA[
61 ( function( $ ){
62 $( "input[name='force_lang']" ).change( function() {
63 var value = $( this ).val();
64 if ( 3 > value ) {
65 $( "#pll-module-browser" ).<?php echo $func;?>.children( "td" ).children( ".row-actions" ).html( '<?php echo $link; ?>' );
66 }
67 else {
68 $( "#pll-module-browser" ).removeClass( "active" ).addClass( "inactive" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $deactivated; ?>' );
69 }
70 } );
71 } )( jQuery );
72 // ]]>
73 </script><?php
74 }
75 }
76