Polylang

Controls the plugin, as well as activation, and deactivation.

Defined (1)

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

/include/class-polylang.php  
  1. class Polylang { 
  2.  
  3. /** 
  4. * constructor 
  5. * @since 0.1 
  6. */ 
  7. public function __construct() { 
  8. require_once PLL_INC . '/functions-wpcom-vip.php'; // VIP functions 
  9. spl_autoload_register( array( $this, 'autoload' ) ); // autoload classes 
  10.  
  11. $install = new PLL_Install( POLYLANG_BASENAME ); 
  12.  
  13. // stopping here if we are going to deactivate the plugin ( avoids breaking rewrite rules ) 
  14. if ( $install->is_deactivation() ) { 
  15. return; 
  16.  
  17. // plugin initialization 
  18. // take no action before all plugins are loaded 
  19. add_action( 'plugins_loaded', array( $this, 'init' ), 1 ); 
  20.  
  21. // override load text domain waiting for the language to be defined 
  22. // here for plugins which load text domain as soon as loaded :( 
  23. if ( ! defined( 'PLL_OLT' ) || PLL_OLT ) { 
  24. PLL_OLT_Manager::instance(); 
  25.  
  26. // extra code for compatibility with some plugins 
  27. // loaded as soon as possible as we may need to act before other plugins are loaded 
  28. if ( ! defined( 'PLL_PLUGINS_COMPAT' ) || PLL_PLUGINS_COMPAT ) { 
  29. PLL_Plugins_Compat::instance(); 
  30.  
  31. /** 
  32. * autoload classes 
  33. * @since 1.2 
  34. * @param string $class 
  35. */ 
  36. public function autoload( $class ) { 
  37. // not a Polylang class 
  38. if ( 0 !== strncmp( 'PLL_', $class, 4 ) ) { 
  39. return; 
  40.  
  41. $class = str_replace( '_', '-', strtolower( substr( $class, 4 ) ) ); 
  42. $to_find = array( 'media', 'share', 'slug', 'slugs', 'sync', 'translate', 'wpml', 'xdata' ); 
  43. $dir = implode( '-', array_intersect( explode( '-', $class ), $to_find ) ); 
  44.  
  45. $dirs = array( 
  46. PLL_FRONT_INC,  
  47. PLL_MODULES_INC,  
  48. PLL_MODULES_INC . "/$dir",  
  49. PLL_MODULES_INC . '/plugins',  
  50. PLL_INSTALL_INC,  
  51. PLL_ADMIN_INC,  
  52. PLL_SETTINGS_INC,  
  53. PLL_INC,  
  54. ); 
  55.  
  56. foreach ( $dirs as $dir ) { 
  57. if ( file_exists( $file = "$dir/$class.php" ) ) { 
  58. require_once $file; 
  59. return; 
  60.  
  61. /** 
  62. * defines constants 
  63. * may be overriden by a plugin if set before plugins_loaded, 1 
  64. * @since 1.6 
  65. */ 
  66. static public function define_constants() { 
  67. // cookie name. no cookie will be used if set to false 
  68. if ( ! defined( 'PLL_COOKIE' ) ) { 
  69. define( 'PLL_COOKIE', 'pll_language' ); 
  70.  
  71. // avoid loading polylang admin for frontend ajax requests 
  72. // special test for plupload which does not use jquery ajax and thus does not pass our ajax prefilter 
  73. // special test for customize_save done in frontend but for which we want to load the admin 
  74. if ( ! defined( 'PLL_AJAX_ON_FRONT' ) ) { 
  75. $in = isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], array( 'upload-attachment', 'customize_save' ) ); 
  76. define( 'PLL_AJAX_ON_FRONT', defined( 'DOING_AJAX' ) && DOING_AJAX && empty( $_REQUEST['pll_ajax_backend'] ) && ! $in ); 
  77.  
  78. // admin 
  79. if ( ! defined( 'PLL_ADMIN' ) ) { 
  80. define( 'PLL_ADMIN', defined( 'DOING_CRON' ) || ( is_admin() && ! PLL_AJAX_ON_FRONT ) ); 
  81.  
  82. // settings page whatever the tab 
  83. if ( ! defined( 'PLL_SETTINGS' ) ) { 
  84. define( 'PLL_SETTINGS', is_admin() && ( ( isset( $_GET['page'] ) && 0 === strpos( $_GET['page'], 'mlang' ) ) || ! empty( $_REQUEST['pll_ajax_settings'] ) ) ); 
  85.  
  86. /** 
  87. * Polylang initialization 
  88. * setups models and separate admin and frontend 
  89. * @since 1.2 
  90. */ 
  91. public function init() { 
  92. global $polylang; 
  93.  
  94. self::define_constants(); 
  95. $options = get_option( 'polylang' ); 
  96.  
  97. // plugin upgrade 
  98. if ( $options && version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { 
  99. $upgrade = new PLL_Upgrade( $options ); 
  100. if ( ! $upgrade->upgrade() ) { // if the version is too old 
  101. return; 
  102.  
  103. // Make sure that this filter is *always* added before PLL_Model::get_languages_list() is called for the first time 
  104. add_filter( 'pll_languages_list', array( 'PLL_Static_Pages', 'pll_languages_list' ), 2, 2 ); // before PLL_Links_Model 
  105.  
  106. /** 
  107. * Filter the model class to use 
  108. * /!\ this filter is fired *before* the $polylang object is available 
  109. * @since 1.5 
  110. * @param string $class either PLL_Model or PLL_Admin_Model 
  111. */ 
  112. $class = apply_filters( 'pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model' ); 
  113. $model = new $class( $options ); 
  114. $links_model = $model->get_links_model(); 
  115.  
  116. if ( PLL_SETTINGS ) { 
  117. $polylang = new PLL_Settings( $links_model ); 
  118. elseif ( PLL_ADMIN ) { 
  119. $polylang = new PLL_Admin( $links_model ); 
  120. // do nothing on frontend if no language is defined 
  121. elseif ( $model->get_languages_list() && empty( $_GET['deactivate-polylang'] ) ) { 
  122. $polylang = new PLL_Frontend( $links_model ); 
  123.  
  124. if ( ! $model->get_languages_list() ) { 
  125. /** 
  126. * Fires when no language has been defined yet 
  127. * Used to load overriden textdomains 
  128. * @since 1.2 
  129. */ 
  130. do_action( 'pll_no_language_defined' ); 
  131.  
  132. if ( ! empty( $polylang ) ) { 
  133. /** 
  134. * Fires after the $polylang object is created and before the API is loaded 
  135. * @since 2.0 
  136. * @param object $polylang 
  137. */ 
  138. do_action_ref_array( 'pll_pre_init', array( &$polylang ) ); 
  139.  
  140. require_once PLL_INC.'/api.php'; // loads the API 
  141.  
  142. if ( ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT ) { 
  143. PLL_WPML_Compat::instance(); // WPML API 
  144. PLL_WPML_Config::instance(); // wpml-config.xml 
  145.  
  146. $polylang->init(); 
  147.  
  148. /** 
  149. * Fires after the $polylang object and the API is loaded 
  150. * @since 1.7 
  151. * @param object $polylang 
  152. */ 
  153. do_action_ref_array( 'pll_init', array( &$polylang ) );