| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * @package Polylang | |
| 4 | + */ | |
| 2 | 5 | |
| 3 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | 7 | exit; // Don't access directly |
| 5 | 8 | }; |
| @@ -26,10 +29,9 @@ | ||
| 26 | 29 | * |
| 27 | 30 | * @since 0.1 |
| 28 | 31 | */ |
| 29 | 32 | public function __construct() { |
| 30 | - require_once PLL_INC . '/functions.php'; // VIP functions | |
| 31 | - spl_autoload_register( array( $this, 'autoload' ) ); // Autoload classes | |
| 33 | + require_once __DIR__ . '/functions.php'; // VIP functions | |
| 32 | 34 | |
| 33 | 35 | // register an action when plugin is activating. |
| 34 | 36 | register_activation_hook( POLYLANG_BASENAME, array( 'PLL_Wizard', 'start_wizard' ) ); |
| 35 | 37 | |
| @@ -49,66 +51,18 @@ | ||
| 49 | 51 | if ( ! defined( 'PLL_OLT' ) || PLL_OLT ) { |
| 50 | 52 | PLL_OLT_Manager::instance(); |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | - // Extra code for compatibility with some plugins | |
| 54 | - // Loaded as soon as possible as we may need to act before other plugins are loaded | |
| 55 | + /* | |
| 56 | + * Loads the compatibility with some plugins and themes. | |
| 57 | + * Loaded as soon as possible as we may need to act before other plugins are loaded. | |
| 58 | + */ | |
| 55 | 59 | if ( ! defined( 'PLL_PLUGINS_COMPAT' ) || PLL_PLUGINS_COMPAT ) { |
| 56 | - PLL_Plugins_Compat::instance(); | |
| 60 | + PLL_Integrations::instance(); | |
| 57 | 61 | } |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | 64 | /** |
| 61 | - * Autoload classes | |
| 62 | - * | |
| 63 | - * @since 1.2 | |
| 64 | - * | |
| 65 | - * @param string $class | |
| 66 | - */ | |
| 67 | - public function autoload( $class ) { | |
| 68 | - // Not a Polylang class | |
| 69 | - if ( 0 !== strncmp( 'PLL_', $class, 4 ) ) { | |
| 70 | - return; | |
| 71 | - } | |
| 72 | - | |
| 73 | - $class = str_replace( '_', '-', strtolower( substr( $class, 4 ) ) ); | |
| 74 | - $dirs = array(); | |
| 75 | - $parts = explode( '-', $class ); | |
| 76 | - $parts = array_values( array_diff( $parts, array( 'frontend', 'admin', 'settings', 'advanced' ) ) ); | |
| 77 | - if ( isset( $parts[0] ) ) { | |
| 78 | - $dirs[] = PLL_MODULES_INC . "/{$parts[0]}"; | |
| 79 | - if ( isset( $parts[1] ) ) { | |
| 80 | - $dirs[] = PLL_MODULES_INC . "/{$parts[0]}-{$parts[1]}"; | |
| 81 | - if ( isset( $parts[2] ) && in_array( $parts[1], array( 'post', 'term' ) ) ) { | |
| 82 | - $dirs[] = PLL_MODULES_INC . "/{$parts[0]}-{$parts[2]}"; | |
| 83 | - } | |
| 84 | - } | |
| 85 | - } | |
| 86 | - | |
| 87 | - $dirs = array_merge( | |
| 88 | - array( | |
| 89 | - PLL_FRONT_INC, | |
| 90 | - PLL_MODULES_INC, | |
| 91 | - ), | |
| 92 | - $dirs, | |
| 93 | - array( | |
| 94 | - PLL_MODULES_INC . '/plugins', | |
| 95 | - PLL_INSTALL_INC, | |
| 96 | - PLL_ADMIN_INC, | |
| 97 | - PLL_SETTINGS_INC, | |
| 98 | - PLL_INC, | |
| 99 | - ) | |
| 100 | - ); | |
| 101 | - | |
| 102 | - foreach ( $dirs as $dir ) { | |
| 103 | - if ( file_exists( $file = "$dir/$class.php" ) ) { | |
| 104 | - require_once $file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable | |
| 105 | - return; | |
| 106 | - } | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | 65 | * Tells whether the current request is an ajax request on frontend or not |
| 112 | 66 | * |
| 113 | 67 | * @since 2.2 |
| 114 | 68 | * |
| @@ -173,8 +127,10 @@ | ||
| 173 | 127 | * Defines constants |
| 174 | 128 | * May be overridden by a plugin if set before plugins_loaded, 1 |
| 175 | 129 | * |
| 176 | 130 | * @since 1.6 |
| 131 | + * | |
| 132 | + * @return void | |
| 177 | 133 | */ |
| 178 | 134 | public static function define_constants() { |
| 179 | 135 | // Cookie name. no cookie will be used if set to false |
| 180 | 136 | if ( ! defined( 'PLL_COOKIE' ) ) { |
| @@ -201,8 +157,10 @@ | ||
| 201 | 157 | * Polylang initialization |
| 202 | 158 | * setups models and separate admin and frontend |
| 203 | 159 | * |
| 204 | 160 | * @since 1.2 |
| 161 | + * | |
| 162 | + * @return void | |
| 205 | 163 | */ |
| 206 | 164 | public function init() { |
| 207 | 165 | global $polylang; |
| 208 | 166 | |
| @@ -254,9 +212,9 @@ | ||
| 254 | 212 | } elseif ( PLL_ADMIN ) { |
| 255 | 213 | $class = 'PLL_Admin'; |
| 256 | 214 | } elseif ( self::is_rest_request() ) { |
| 257 | 215 | $class = 'PLL_REST_Request'; |
| 258 | - } elseif ( $model->get_languages_list() && empty( $_GET['deactivate-polylang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 216 | + } elseif ( $model->get_languages_list() ) { | |
| 259 | 217 | $class = 'PLL_Frontend'; |
| 260 | 218 | } |
| 261 | 219 | |
| 262 | 220 | /** |
| @@ -279,13 +237,16 @@ | ||
| 279 | 237 | * @param object $polylang |
| 280 | 238 | */ |
| 281 | 239 | do_action_ref_array( 'pll_pre_init', array( &$polylang ) ); |
| 282 | 240 | |
| 283 | - require_once PLL_INC . '/api.php'; // Loads the API | |
| 241 | + require_once __DIR__ . '/api.php'; // Loads the API | |
| 284 | 242 | |
| 285 | - if ( ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT ) { | |
| 286 | - PLL_WPML_Compat::instance(); // WPML API | |
| 287 | - PLL_WPML_Config::instance(); // wpml-config.xml | |
| 243 | + // Loads the modules. | |
| 244 | + $load_scripts = glob( POLYLANG_DIR . '/modules/*/load.php', GLOB_NOSORT ); | |
| 245 | + if ( is_array( $load_scripts ) ) { | |
| 246 | + foreach ( $load_scripts as $load_script ) { | |
| 247 | + require_once $load_script; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable | |
| 248 | + } | |
| 288 | 249 | } |
| 289 | 250 | |
| 290 | 251 | $polylang->init(); |
| 291 | 252 | |