PLL_Settings_Browser

Settings class for browser language preference detection.

Defined (1)

The class is defined in the following location(s).

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