PluginProbe
Polylang / 2.1.2
Polylang v2.1.2
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 2.1.2, at settings/settings-browser.php

90 lines 2.4 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 /**
11 * Constructor
12 *
13 * @since 1.8
14 *
15 * @param object $polylang polylang object
16 */
17 public function __construct( &$polylang ) {
18 parent::__construct( $polylang, array(
19 'module' => 'browser',
20 'title' => __( 'Detect browser language', 'polylang' ),
21 'description' => __( 'When the front page is visited, set the language according to the browser preference', 'polylang' ),
22 'active_option' => $this->is_available() ? 'browser' : false,
23 ) );
24
25 if ( ! class_exists( 'PLL_Xdata_Domain', true ) ) {
26 add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) );
27 }
28 }
29
30 /**
31 * Tells if the option is available
32 *
33 * @since 2.0
34 *
35 * @return bool
36 */
37 protected function is_available() {
38 return ( 3 > $this->options['force_lang'] ) || class_exists( 'PLL_Xdata_Domain', true );
39 }
40
41 /**
42 * Tells if the module is active
43 *
44 * @since 1.8
45 *
46 * @return bool
47 */
48 public function is_active() {
49 return $this->is_available() ? parent::is_active() : false;
50 }
51
52 /**
53 * Displays the javascript to handle dynamically the change in url modifications
54 * as the preferred browser language is not used when the language is set from different domains
55 *
56 * @since 1.8
57 */
58 public function print_js() {
59 wp_enqueue_script( 'jquery' );
60
61 if ( parent::is_active() && 3 > $this->options['force_lang'] ) {
62 $func = 'removeClass( "inactive" ).addClass( "active" )';
63 $link = sprintf( '<span class="deactivate">%s</span>', $this->action_links['deactivate'] );
64 }
65 else {
66 $func = 'removeClass( "active" ).addClass( "inactive" )';
67 $link = sprintf( '<span class="activate">%s</span>', $this->action_links['activate'] );
68 }
69
70 $deactivated = sprintf( '<span class="deactivated">%s</span>', $this->action_links['deactivated'] );
71
72 ?>
73 <script type='text/javascript'>
74 //<![CDATA[
75 ( function( $ ){
76 $( "input[name='force_lang']" ).change( function() {
77 var value = $( this ).val();
78 if ( 3 > value ) {
79 $( "#pll-module-browser" ).<?php echo $func;?>.children( "td" ).children( ".row-actions" ).html( '<?php echo $link; ?>' );
80 }
81 else {
82 $( "#pll-module-browser" ).removeClass( "active" ).addClass( "inactive" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $deactivated; ?>' );
83 }
84 } );
85 } )( jQuery );
86 // ]]>
87 </script><?php
88 }
89 }
90