Пример #1
0
 /**
  * Sets up the package on first run.
  *
  * @return bool
  */
 protected function maybe_install()
 {
     if (false !== $this->options->installed()) {
         return;
     }
     // Schedule recurring event.
     wp_schedule_event(time(), 'hourly', Options::CRON_KEY);
     // Set the installed flag.
     $this->options->set_installed(Options::PLUGIN_VERSION);
     $this->options->update();
 }
Пример #2
0
 /**
  * Adds a row to the wp plugin list table for each handled plugin.
  *
  * @param bool   $show Whether or not to show this plugin.
  * @param string $type Plugin type.
  *
  * @return bool
  */
 public function show_advanced_plugins($show, $type)
 {
     if ('dropins' !== $type) {
         return $show;
     }
     global $plugins;
     foreach ($this->options->paths_index() as $plugin => $path) {
         $plugins['mustuse'][$plugin] = get_plugin_data($path, false, false);
     }
     return $show;
 }
Пример #3
0
 /**
  * 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();
 }