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

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