/** * Require all plugin files stored in the autoloader option entry. */ public function require_plugin_files() { $files = $this->options->plugins(); $update = false; foreach ($this->options->paths_index() as $basename => $path) { if (file_exists($path)) { require_once $path; } // Plugin activation hook. if ($files[$basename]['firstrun']) { do_action(sprintf('activate_%s', $basename)); $files[$basename]['firstrun'] = 0; $update = true; } } if ($update) { $this->options->set_plugins($files); $this->options->update(); } }
/** * Generate the autoloader options entry. */ public function regenerate_autoloader() { $this->json = new Json(sprintf('%s/composer.json', $this->options->project_path())); $this->lock = new Lock(sprintf('%s/composer.lock', $this->options->project_path())); // Is this kosher? require_once sprintf('%swp-admin/includes/plugin.php', ABSPATH); if (is_null($packages_array = $this->lock->mu_plugin_packages())) { $packages_array = []; } $plugins_array = []; foreach ($this->json->paths() as $name => $path) { if ($path === $this->json->mu_plugin_path() && 'type:' !== substr($name, 0, 5)) { $packages_array[] = $this->lock->package_by_name($name); } } $packages_array = array_filter(array_unique($packages_array)); foreach ($packages_array as $package) { list($vendor, $name) = explode('/', $package->name()); $mu_path = str_replace(['{$name}', '{$type}', '{$vendor}'], [$name, $package->type(), $vendor], $this->json->mu_plugin_path()); $path = sprintf('%s%s', trailingslashit($this->options->project_path()), trailingslashit($mu_path)); $files = glob(sprintf('%s*.php', trailingslashit($path)), GLOB_NOSORT); if (false === $files) { continue; } foreach ($files as $file) { $data = get_plugin_data($file, false, false); // Verify this is a plugin file. if (empty($data['Name'])) { continue; } $basename = plugin_basename($file); $data = ['type' => $package->type(), 'vendor' => $vendor, 'firstrun' => array_key_exists($basename, $this->options->plugins()) ? false : true]; $plugins_array[$basename] = $data; } } // Update database entry. $this->options->set_path($this->json->mu_plugin_path()); $this->options->set_plugins($plugins_array); $this->options->update(); }