ceu_deactivation_before
Fires immediately before the plugin is deactivated, allowing for pre-deactivation tasks.
add_action( 'ceu_deactivation_before', $callback, 10, 1 );
Description
Fires immediately before the plugin's deactivation process begins. Developers can use this hook to perform cleanup tasks, save transient data, or initiate any necessary actions right before the plugin is deactivated. It runs exclusively during plugin deactivation.
Usage
add_action( 'ceu_deactivation_before', 'your_function_name', 10, 1 );
Examples
/**
* Clean up user meta data related to CEU courses upon plugin deactivation.
* This function runs before the main deactivation logic.
*/
function my_ceu_cleanup_user_meta() {
// Get all users
$users = get_users();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
// Delete specific user meta keys associated with CEU course progress or completion.
// Replace 'ceu_course_progress_' and 'ceu_course_completed_' with actual meta keys used by your plugin.
delete_user_meta( $user->ID, 'ceu_course_progress_' . 'some_course_id' );
delete_user_meta( $user->ID, 'ceu_course_completed_' . 'another_course_id' );
// You might also want to delete transient data or options related to user progress
delete_transient( 'ceu_user_dashboard_cache_' . $user->ID );
}
}
// If there are any global options related to CEU deactivation that need cleaning up,
// you can do it here as well. For example, disabling certain features or removing settings.
// update_option( 'ceu_enable_feature_x', false );
}
add_action( 'ceu_deactivation_before', 'my_ceu_cleanup_user_meta', 10, 0 ); // Priority 10, accepts 0 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:198
function deactivation() {
do_action( 'ceu_deactivation_before' );
do_action( 'ceu_deactivation_after' );
}