i have a class to activate the plugins when i set my theme to active but the class auto activate all plugins , how i can modify to activate only the plugins that i choose.
if ( ! class_exists( __NAMESPACE__ . '\Auto_Activate' ) ) {
class Auto_Activate extends Plugin {
protected $plugins = [];
public function __construct() {
parent::__construct();
$this->plugins = [
'woocommerce/woocommerce.php',
'ayyash-studio/ayyash-studio.php',
'other-plugin/main-file.php',
//...
];
}
protected function get_plugins() {
$plugins = $this->plugins;
$plugin = plugin_basename( self::get( 'file' ) );
if ( isset( $plugins[ $plugin ] ) ) unset( $plugins[ $plugin ] );
return apply_filters( self::get( 'slug' ), $plugins );
}
public function action_after_setup_theme() {
foreach( $this->get_plugins() as $plugin => $data )
if ( in_array( $plugin, array_keys( $this->plugins ) ) )
if ( is_wp_error( $result = activate_plugin( $plugin, ! empty( $data['Network'] ) ) ) )
error_log( self::get( 'slug' ) . ': ' . $result->get_error_message() );
}
public function filter_network_admin_plugin_action_links( $actions, $plugin ) {
if ( plugin_basename( self::get( 'file' ) ) !== $plugin &&
array_key_exists( 'deactivate', $actions ) &&
array_key_exists( $plugin, $this->get_plugins() ) )
unset( $actions['deactivate'] );
return $actions;
}
public function filter_plugin_action_links( $actions, $plugin ) {
if ( plugin_basename( self::get( 'file' ) ) !== $plugin &&
array_key_exists( 'deactivate', $actions ) &&
array_key_exists( $plugin, $this->get_plugins() ) )
unset( $actions['deactivate'] );
return $actions;
}
}
}