/** * Add individual plugin to our collection of plugins. * * If the required keys are not set or the plugin has already * been registered, the plugin is not added. * * @since 2.0.0 * * @param array $plugin Array of plugin arguments. */ public function register($plugin) { if (empty($plugin['slug']) || empty($plugin['name'])) { return; } if (empty($plugin['slug']) || !is_string($plugin['slug']) || isset($this->plugins[$plugin['slug']])) { return; } $defaults = array('name' => '', 'slug' => '', 'source' => 'repo', 'required' => false, 'version' => '', 'force_activation' => false, 'force_deactivation' => false, 'external_url' => '', 'is_callable' => ''); // Prepare the received data. $plugin = wp_parse_args($plugin, $defaults); // Standardize the received slug. $plugin['slug'] = $this->sanitize_key($plugin['slug']); // Forgive users for using string versions of booleans or floats for version number. $plugin['version'] = (string) $plugin['version']; $plugin['source'] = empty($plugin['source']) ? 'repo' : $plugin['source']; $plugin['required'] = TGM_Utils::validate_bool($plugin['required']); $plugin['force_activation'] = TGM_Utils::validate_bool($plugin['force_activation']); $plugin['force_deactivation'] = TGM_Utils::validate_bool($plugin['force_deactivation']); // Enrich the received data. $plugin['file_path'] = $this->_get_plugin_basename_from_slug($plugin['slug']); $plugin['source_type'] = $this->get_plugin_source_type($plugin['source']); // Set the class properties. $this->plugins[$plugin['slug']] = $plugin; $this->sort_order[$plugin['slug']] = $plugin['name']; // Should we add the force activation hook ? if (true === $plugin['force_activation']) { $this->has_forced_activation = true; } // Should we add the force deactivation hook ? if (true === $plugin['force_deactivation']) { $this->has_forced_deactivation = true; } }