| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 4 | exit; // Don't access directly |
| 8 | 5 | }; |
| @@ -29,9 +26,10 @@ | ||
| 29 | 26 | * |
| 30 | 27 | * @since 0.1 |
| 31 | 28 | */ |
| 32 | 29 | public function __construct() { |
| 33 | - require_once __DIR__ . '/functions.php'; // VIP functions | |
| 30 | + require_once PLL_INC . '/functions.php'; // VIP functions | |
| 31 | + spl_autoload_register( array( $this, 'autoload' ) ); // Autoload classes | |
| 34 | 32 | |
| 35 | 33 | // register an action when plugin is activating. |
| 36 | 34 | register_activation_hook( POLYLANG_BASENAME, array( 'PLL_Wizard', 'start_wizard' ) ); |
| 37 | 35 | |
| @@ -51,18 +49,66 @@ | ||
| 51 | 49 | if ( ! defined( 'PLL_OLT' ) || PLL_OLT ) { |
| 52 | 50 | PLL_OLT_Manager::instance(); |
| 53 | 51 | } |
| 54 | 52 | |
| 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 | - */ | |
| 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 | |
| 59 | 55 | if ( ! defined( 'PLL_PLUGINS_COMPAT' ) || PLL_PLUGINS_COMPAT ) { |
| 60 | - PLL_Integrations::instance(); | |
| 56 | + PLL_Plugins_Compat::instance(); | |
| 61 | 57 | } |
| 62 | 58 | } |
| 63 | 59 | |
| 64 | 60 | /** |
| 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 | + /** | |
| 65 | 111 | * Tells whether the current request is an ajax request on frontend or not |
| 66 | 112 | * |
| 67 | 113 | * @since 2.2 |
| 68 | 114 | * |
| @@ -127,10 +173,8 @@ | ||
| 127 | 173 | * Defines constants |
| 128 | 174 | * May be overridden by a plugin if set before plugins_loaded, 1 |
| 129 | 175 | * |
| 130 | 176 | * @since 1.6 |
| 131 | - * | |
| 132 | - * @return void | |
| 133 | 177 | */ |
| 134 | 178 | public static function define_constants() { |
| 135 | 179 | // Cookie name. no cookie will be used if set to false |
| 136 | 180 | if ( ! defined( 'PLL_COOKIE' ) ) { |
| @@ -157,10 +201,8 @@ | ||
| 157 | 201 | * Polylang initialization |
| 158 | 202 | * setups models and separate admin and frontend |
| 159 | 203 | * |
| 160 | 204 | * @since 1.2 |
| 161 | - * | |
| 162 | - * @return void | |
| 163 | 205 | */ |
| 164 | 206 | public function init() { |
| 165 | 207 | global $polylang; |
| 166 | 208 | |
| @@ -212,9 +254,9 @@ | ||
| 212 | 254 | } elseif ( PLL_ADMIN ) { |
| 213 | 255 | $class = 'PLL_Admin'; |
| 214 | 256 | } elseif ( self::is_rest_request() ) { |
| 215 | 257 | $class = 'PLL_REST_Request'; |
| 216 | - } elseif ( $model->get_languages_list() ) { | |
| 258 | + } elseif ( $model->get_languages_list() && empty( $_GET['deactivate-polylang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 217 | 259 | $class = 'PLL_Frontend'; |
| 218 | 260 | } |
| 219 | 261 | |
| 220 | 262 | /** |
| @@ -237,16 +279,13 @@ | ||
| 237 | 279 | * @param object $polylang |
| 238 | 280 | */ |
| 239 | 281 | do_action_ref_array( 'pll_pre_init', array( &$polylang ) ); |
| 240 | 282 | |
| 241 | - require_once __DIR__ . '/api.php'; // Loads the API | |
| 283 | + require_once PLL_INC . '/api.php'; // Loads the API | |
| 242 | 284 | |
| 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 | - } | |
| 285 | + if ( ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT ) { | |
| 286 | + PLL_WPML_Compat::instance(); // WPML API | |
| 287 | + PLL_WPML_Config::instance(); // wpml-config.xml | |
| 249 | 288 | } |
| 250 | 289 | |
| 251 | 290 | $polylang->init(); |
| 252 | 291 | |