Action uncanny-continuing-education-credits

ceu_activation_before

Fires immediately before the plugin's main activation process runs.

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

Description

Fires just before the plugin performs its core activation tasks, including database initialization. Developers can use this hook to perform custom actions before the plugin is fully set up, such as registering custom post types or setting up initial options.


Usage

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

Examples

/**
 * Example of hooking into the 'ceu_activation_before' action.
 *
 * This function will be executed right before the plugin's core activation logic.
 * It's a good place to perform checks or set up initial configurations.
 */
add_action( 'ceu_activation_before', function() {
	// Check if the current user has the 'activate_plugins' capability.
	// This is a common security check to ensure only authorized users can trigger activation.
	if ( ! current_user_can( 'activate_plugins' ) ) {
		// If the user doesn't have the capability, exit early to prevent unexpected actions.
		// In a real scenario, you might log this or display a user-friendly message
		// (though direct output here might be tricky depending on context).
		return;
	}

	// Example: Check if a required third-party plugin is already active.
	// If not, you might set a flag to notify the user later or even halt activation.
	$required_plugin_slug = 'another-essential-plugin/another-essential-plugin.php';
	if ( ! is_plugin_active( $required_plugin_slug ) ) {
		// For demonstration, let's store a transient to show a notice after activation.
		// In a real plugin, you'd likely have a more robust notification system.
		set_transient( 'ceu_missing_dependency_notice', true, 60 * 60 ); // Show notice for 1 hour.
	}

	// Example: Create a default option if it doesn't exist.
	// This could be a setting that needs an initial value on activation.
	if ( false === get_option( 'ceu_default_setting' ) ) {
		update_option( 'ceu_default_setting', 'initial_value' );
	}

}, 10, 0 ); // 10 is the default priority, 0 is the number of 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/config.php:148

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