You need activated_plugin
. It fires after a plugin has been activated but note that if a plugin is silently activated (such as during an update), the hook doesn’t fire.
Here’s an example:
add_action( 'activated_plugin', function( $plugin, $network_wide ) {
// $plugin is a string (the path to main plugin file).
}, 10, 2 );
Thank you Henry, but we already tried this hook.
Maybe I should give you some code:
class SKS_Test {
public function __construct() {
add_action( 'activated_plugin', array( $this, 'activated_plugin' ), 99, 1 );
}
public function activated_plugin( $plugin ) {
if ( $plugin == 'buddypress/bp-loader.php' && ! get_option( 'sks_installed', false ) ) {
$bp_active_components = get_option( 'bp-active-components', array() );
$bp_active_components['groups'] = 1;
delete_transient( '_bp_is_new_install' );
delete_transient( '_bp_activation_redirect' );
update_option( 'bp-active-components', $bp_active_components );
update_option( 'hide-loggedout-adminbar', 1 );
}
}
}
The group component is still disabled in the settings of BuddyPress 🙁
Can you var_dump $bp_active_components
just to see what we have in the db?
This is the output of the get_option:
array (
)
And this is, what update_option use to store:
array (
'groups' => 1,
)
Can you let me know what output you get from this?
add_action( 'bp_loaded', function() {
var_dump( bp_get_option( 'bp-active-components' ) );
} );
@schweizersolutions With your current solution:
1) If BuddyPress is loaded in this context, I’d strongly recommend you use bp_update_option
instead of update_option
as this supports all the different configurations of BuddyPress install/configuration.
2) If you look at bp_version_updater
or bp_core_admin_components_settings_handler
for example, it does what you’re doing, but it runs the installation routines afterwards. I’d recommend you copy the logic from bp_core_admin_components_settings_handler
.
3) An alternate approach is to filter the bp_new_install_default_components
array as long as you can put that in place before BuddyPress loads.
4) I think activated_plugin
might be too early, i.e. before BuddyPress installs. I am not sure, I can’t test right now. BuddyPress’ core routines start from plugins_loaded
, and I think that’ll have already be triggered before activated_plugin
, so the behaviour will be undefined (i.e. it might install on the next page load, or part-install immediately, and I have no idea if this will break stuff).
Hope this helps