Action uncanny-continuing-education-credits

ceu_activation_after

Fires after the core plugin has been activated.

add_action( 'ceu_activation_after', $callback, 10, 1 );

Description

Fires after the plugin's database has been initialized and the redirect option is set during activation. Developers can use this hook to perform any actions that should occur immediately after the core activation process, such as additional setup tasks or custom notification displays.


Usage

add_action( 'ceu_activation_after', 'your_function_name', 10, 1 );

Examples

/**
 * Handle actions after plugin activation.
 *
 * This function is hooked into 'ceu_activation_after' and performs
 * essential setup tasks after the plugin has been activated.
 */
add_action( 'ceu_activation_after', function() {
	// Check if the user is an administrator before proceeding.
	if ( ! current_user_can( 'manage_options' ) ) {
		return;
	}

	// Set a flag to redirect to the license page on the first activation.
	// This option is checked in the main plugin file or an admin notice handler.
	update_option( 'ceu_needs_license_setup', 'yes' );

	// Optionally, create a default configuration or role if needed.
	// For example, if the plugin introduces custom post types or user roles.
	// This is a simplified example; a real-world scenario might involve
	// more complex setup logic.
	if ( get_option( 'ceu_default_settings_created' ) !== 'yes' ) {
		// Example: Create a default setting.
		$default_options = array(
			'ceu_enable_feature_x' => true,
			'ceu_default_theme'    => 'light',
		);
		foreach ( $default_options as $option_name => $option_value ) {
			if ( false === get_option( $option_name ) ) {
				add_option( $option_name, $option_value );
			}
		}
		update_option( 'ceu_default_settings_created', 'yes' );
	}

	// Log the activation event for debugging or auditing purposes.
	// In a real application, you might use a dedicated logging function or a plugin.
	error_log( 'CEU Plugin activated. Initial setup complete.' );

}, 10, 0 ); // 10 is the default priority, 0 means no arguments are accepted.

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/config.php:154

public function activation() {

		do_action( 'ceu_activation_before' );
		self::initialize_db();

		// On first activation, redirect to toolkit license page
		update_option( 'ceu_activation_redirect', 'yes' );

		do_action( 'ceu_activation_after' );

	}


Scroll to Top