/** * Initialize the plugin. * * @wp-hook plugins_loaded * * @return void */ function mlp_init() { global $pagenow, $wp_version, $wpdb; $plugin_path = plugin_dir_path(__FILE__); $plugin_url = plugins_url('/', __FILE__); $assets_base = 'assets'; if (!class_exists('Mlp_Load_Controller')) { require $plugin_path . 'inc/autoload/Mlp_Load_Controller.php'; } $loader = new Mlp_Load_Controller($plugin_path . 'inc'); $data = new Mlp_Plugin_Properties(); $data->set('loader', $loader->get_loader()); $locations = new Mlp_Internal_Locations(); $locations->add_dir($plugin_path, $plugin_url, 'plugin'); $assets_locations = array('css' => 'css', 'js' => 'js', 'images' => 'images', 'flags' => 'images/flags'); foreach ($assets_locations as $type => $dir) { $locations->add_dir($plugin_path . $assets_base . '/' . $dir, $plugin_url . $assets_base . '/' . $dir, $type); } $data->set('locations', $locations); $data->set('plugin_file_path', __FILE__); $data->set('plugin_base_name', plugin_basename(__FILE__)); $headers = get_file_data(__FILE__, array('text_domain_path' => 'Domain Path', 'plugin_uri' => 'Plugin URI', 'plugin_name' => 'Plugin Name', 'version' => 'Version')); foreach ($headers as $name => $value) { $data->set($name, $value); } if (!mlp_pre_run_test($pagenow, $data, $wp_version, $wpdb)) { return; } $mlp = new Multilingual_Press($data, $wpdb); $mlp->setup(); }
/** * Bootstraps MultilingualPress. * * @since 3.0.0 * * @return bool Whether or not MultilingualPress was bootstrapped successfully. * * @throws BadMethodCallException if called on a MultilingualPress instance that has already been bootstrapped. */ public function bootstrap() { if ($this->is_bootstrapped) { throw new BadMethodCallException('Cannot bootstrap a MultilingualPress instance that has already been bootstrapped.'); } /** * Fires right before MultilingualPress gets bootstrapped. * * Hook here to register custom service providers. * * @since 3.0.0 * * @param static $multilingualpress MultilingualPress instance. */ do_action('multilingualpress.bootstrap', $this); static::$container->lock(); // TODO: Eventually remove the following block. class_exists('Mlp_Load_Controller') or (require __DIR__ . '/inc/autoload/Mlp_Load_Controller.php'); new \Mlp_Load_Controller(static::$container['multilingualpress.properties']->plugin_dir_path() . '/src/inc'); if (!$this->check_installation()) { return false; } $this->bootstrap_service_providers(); $needs_modules = $this->needs_modules(); if ($needs_modules) { /** * Fires right before MultilingualPress registers any modules. * * @since 3.0.0 */ do_action('multilingualpress.register_modules'); $this->register_modules(); } unset($this->modules); static::$container->bootstrap(); $this->is_bootstrapped = true; // TODO: Remove as soon as the old front controller has been replaced completely. class_exists('Multilingual_Press') or (require __DIR__ . '/inc/Multilingual_Press.php'); // TODO: Refactor according to new architecure. $old_controller = new \Multilingual_Press(static::$container); $old_controller->prepare_plugin_data(); if (!$needs_modules) { return true; } load_plugin_textdomain('multilingual-press'); if (is_admin()) { $this->bootstrap_admin(); } else { $this->bootstrap_front_end(); } // TODO: Refactor according to new architecure. $old_controller->setup(); return true; }