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

104 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Settings class for browser language preference detection
8 *
9 * @since 1.8
10 */
11 class PLL_Settings_Browser extends PLL_Settings_Module {
12 /**
13 * Stores the display order priority.
14 *
15 * @var int
16 */
17 public $priority = 20;
18
19 /**
20 * Constructor
21 *
22 * @since 1.8
23 *
24 * @param object $polylang polylang object
25 */
26 public function __construct( &$polylang ) {
27 $this->options = &$polylang->options;
28 parent::__construct(
29 $polylang,
30 array(
31 'module' => 'browser',
32 'title' => __( 'Detect browser language', 'polylang' ),
33 'description' => __( 'When the front page is visited, set the language according to the browser preference', 'polylang' ),
34 'active_option' => $this->is_available() ? 'browser' : false,
35 )
36 );
37
38 if ( ! class_exists( 'PLL_Xdata_Domain', true ) ) {
39 add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) );
40 }
41 }
42
43 /**
44 * Tells if the option is available
45 *
46 * @since 2.0
47 *
48 * @return bool
49 */
50 protected function is_available() {
51 return ( 3 > $this->options['force_lang'] ) || class_exists( 'PLL_Xdata_Domain', true );
52 }
53
54 /**
55 * Tells if the module is active
56 *
57 * @since 1.8
58 *
59 * @return bool
60 */
61 public function is_active() {
62 return $this->is_available() ? parent::is_active() : false;
63 }
64
65 /**
66 * Displays the javascript to handle dynamically the change in url modifications
67 * as the preferred browser language is not used when the language is set from different domains
68 *
69 * @since 1.8
70 */
71 public function print_js() {
72 wp_enqueue_script( 'jquery' );
73
74 if ( parent::is_active() && 3 > $this->options['force_lang'] ) {
75 $func = 'removeClass( "inactive" ).addClass( "active" )';
76 $link = sprintf( '<span class="deactivate">%s</span>', $this->action_links['deactivate'] );
77 }
78 else {
79 $func = 'removeClass( "active" ).addClass( "inactive" )';
80 $link = sprintf( '<span class="activate">%s</span>', $this->action_links['activate'] );
81 }
82
83 $deactivated = sprintf( '<span class="deactivated">%s</span>', $this->action_links['deactivated'] );
84
85 ?>
86 <script type='text/javascript'>
87 //<![CDATA[
88 ( function( $ ){
89 $( "input[name='force_lang']" ).change( function() {
90 var value = $( this ).val();
91 if ( 3 > value ) {
92 $( "#pll-module-browser" ).<?php echo $func; // phpcs:ignore WordPress.Security.EscapeOutput ?>.children( "td" ).children( ".row-actions" ).html( '<?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput ?>' );
93 }
94 else {
95 $( "#pll-module-browser" ).removeClass( "active" ).addClass( "inactive" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $deactivated; // phpcs:ignore WordPress.Security.EscapeOutput ?>' );
96 }
97 } );
98 } )( jQuery );
99 // ]]>
100 </script>
101 <?php
102 }
103 }
104