/** * Access to the single instance of the class * * @since 1.7 * * @return object */ public static function instance() { if (empty(self::$instance)) { self::$instance = new self(); } return self::$instance; }
public function __construct() { // FIXME maybe not available on every installations but widely used by WP plugins spl_autoload_register(array(&$this, 'autoload')); // autoload classes $install = new PLL_Install(POLYLANG_BASENAME); // stopping here if we are going to deactivate the plugin (avoids breaking rewrite rules) if ($install->is_deactivation()) { return; } // plugin initialization // take no action before all plugins are loaded add_action('plugins_loaded', array(&$this, 'init'), 1); // override load text domain waiting for the language to be defined // here for plugins which load text domain as soon as loaded :( if (!defined('PLL_OLT') || PLL_OLT) { PLL_OLT_Manager::instance(); } // loads the API require_once PLL_INC . '/api.php'; // WPML API if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT) { PLL_WPML_Compat::instance(); } // extra code for compatibility with some plugins if (!defined('PLL_PLUGINS_COMPAT') || PLL_PLUGINS_COMPAT) { PLL_Plugins_Compat::instance(); } }
/** * Polylang initialization * setups models and separate admin and frontend * * @since 1.2 */ public function init() { global $polylang; self::define_constants(); $options = get_option('polylang'); // plugin upgrade if ($options && version_compare($options['version'], POLYLANG_VERSION, '<')) { $upgrade = new PLL_Upgrade($options); if (!$upgrade->upgrade()) { // if the version is too old return; } } // Make sure that this filter is *always* added before PLL_Model::get_languages_list() is called for the first time add_filter('pll_languages_list', array('PLL_Static_Pages', 'pll_languages_list'), 2, 2); // before PLL_Links_Model /** * Filter the model class to use * /!\ this filter is fired *before* the $polylang object is available * * @since 1.5 * * @param string $class either PLL_Model or PLL_Admin_Model */ $class = apply_filters('pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model'); $model = new $class($options); $links_model = $model->get_links_model(); if (PLL_SETTINGS) { $polylang = new PLL_Settings($links_model); } elseif (PLL_ADMIN) { $polylang = new PLL_Admin($links_model); } elseif ($model->get_languages_list() && empty($_GET['deactivate-polylang'])) { $polylang = new PLL_Frontend($links_model); } if (!$model->get_languages_list()) { /** * Fires when no language has been defined yet * Used to load overriden textdomains * * @since 1.2 */ do_action('pll_no_language_defined'); } if (!empty($polylang)) { /** * Fires after the $polylang object is created and before the API is loaded * * @since 2.0 * * @param object $polylang */ do_action_ref_array('pll_pre_init', array(&$polylang)); require_once PLL_INC . '/api.php'; // loads the API if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT) { PLL_WPML_Compat::instance(); // WPML API PLL_WPML_Config::instance(); // wpml-config.xml } $polylang->init(); /** * Fires after the $polylang object and the API is loaded * * @since 1.7 * * @param object $polylang */ do_action_ref_array('pll_init', array(&$polylang)); } }
function icl_translate($context, $name, $string = false, $bool = false, &$has_translation = null, $lang = null) { // FIXME WPML can automatically registers the string based on an option if (empty($string)) { $string = PLL_WPML_Compat::instance()->get_string_by_context_and_name($context, $name); } return empty($lang) ? pll__($string) : pll_translate_string($string, $lang); }
public function init() { global $polylang; self::define_constants(); $options = get_option('polylang'); // plugin upgrade if ($options && version_compare($options['version'], POLYLANG_VERSION, '<')) { $upgrade = new PLL_Upgrade($options); if (!$upgrade->upgrade()) { // if the version is too old return; } } // /!\ this filter is fired *before* the $polylang object is available $class = apply_filters('pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model'); $model = new $class($options); $links_model = $model->get_links_model(); add_filter('pll_languages_list', array('PLL_Static_Pages', 'pll_languages_list'), 2, 2); // before PLL_Links_Model if (PLL_SETTINGS) { $polylang = new PLL_Settings($links_model); } elseif (PLL_ADMIN) { $polylang = new PLL_Admin($links_model); } elseif ($model->get_languages_list() && empty($_GET['deactivate-polylang'])) { $polylang = new PLL_Frontend($links_model); } if (!$model->get_languages_list()) { do_action('pll_no_language_defined'); // to load overriden textdomains } if (!empty($polylang)) { require_once PLL_INC . '/api.php'; // loads the API if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT) { PLL_WPML_Compat::instance(); // WPML API PLL_WPML_Config::instance(); // wpml-config.xml } $polylang->init(); do_action('pll_init', $polylang); } }