ulgm_activation_after
Fires after the ULGM plugin has been successfully activated on the WordPress site.
add_action( 'ulgm_activation_after', $callback, 10, 1 );
Description
Fires after the plugin's initial database tables and core pages have been set up during activation. Developers can use this hook to perform custom actions like further data seeding, initial configuration tasks, or triggering other plugin integrations immediately after the plugin is activated.
Usage
add_action( 'ulgm_activation_after', 'your_function_name', 10, 1 );
Examples
// Example usage of the ulgm_activation_after hook.
// This function will be executed after the core plugin activation steps are completed.
// It might be used to perform additional setup tasks, like creating initial default groups,
// setting up user roles, or sending a welcome email to the administrator.
add_action( 'ulgm_activation_after', function() {
// Let's create a default "Members" group if one doesn't exist.
$group_name = 'Members';
// Check if a group with this name already exists.
$args = array(
'name' => $group_name,
'fields' => 'ids', // We only need the IDs to check existence.
);
$existing_groups = get_posts( $args );
if ( empty( $existing_groups ) ) {
// If no group named "Members" exists, create it.
$group_data = array(
'name' => $group_name,
'description' => 'This is the default group for all members.',
'status' => 'public', // Or 'private' depending on your plugin's logic
);
// Assuming your plugin has a function to create groups, e.g., ulgm_create_group()
// If not, you'd interact with WordPress's post types directly.
$new_group_id = ulgm_create_group( $group_data ); // Replace with your actual group creation function
if ( ! is_wp_error( $new_group_id ) && $new_group_id ) {
// Log or do something with the newly created group ID.
error_log( "Default group '{$group_name}' created with ID: {$new_group_id}" );
} else {
error_log( "Failed to create default group '{$group_name}'." );
if ( is_wp_error( $new_group_id ) ) {
error_log( "Error: " . $new_group_id->get_error_message() );
}
}
}
}, 10, 0 ); // Priority 10, 0 accepted arguments.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/class-setup.php:112
public function activation() {
do_action( 'ulgm_activation_before' );
// Add Groups DB tables
$this->initialize_db();
// Add Group Management pages
$this->generate_groups_pages();
do_action( 'ulgm_activation_after' );
}