PluginProbe
Polylang / 3.2.3
Polylang v3.2.3
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 3.2.3, at settings/settings-browser.php

108 lines 2.9 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, redirects to itself in the browser preferred language. As this doesn\'t work if it is cached, Polylang will attempt to disable the front page cache for known cache plugins.', '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 * @return void
72 */
73 public function print_js() {
74 wp_enqueue_script( 'jquery' );
75
76 if ( parent::is_active() && 3 > $this->options['force_lang'] ) {
77 $func = 'removeClass( "inactive" ).addClass( "active" )';
78 $link = sprintf( '<span class="deactivate">%s</span>', $this->action_links['deactivate'] );
79 }
80 else {
81 $func = 'removeClass( "active" ).addClass( "inactive" )';
82 $link = sprintf( '<span class="activate">%s</span>', $this->action_links['activate'] );
83 }
84
85 $deactivated = sprintf( '<span class="deactivated">%s</span>', $this->action_links['deactivated'] );
86
87 ?>
88 <script type='text/javascript'>
89 //<![CDATA[
90 jQuery(
91 function( $ ){
92 $( "input[name='force_lang']" ).on( 'change', function() {
93 var value = $( this ).val();
94 if ( 3 > value ) {
95 $( "#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 ?>' );
96 }
97 else {
98 $( "#pll-module-browser" ).removeClass( "active" ).addClass( "inactive" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $deactivated; // phpcs:ignore WordPress.Security.EscapeOutput ?>' );
99 }
100 } );
101 }
102 );
103 // ]]>
104 </script>
105 <?php
106 }
107 }
108