plugin development – register_activation_hook doesn’t execute without add_action(‘init’,’some-function’)

Question

I am building a plugin based on a boilerplate gerenrated on wppb.me
The problem I am having is getting the register_activation_hook to actually execute without following it with add_action

This is the code segment in promo-card.php

define(‘PROMO_DIR_PATH’, plugin_dir_path(FILE));

function activate_promo_card() {
log_me(‘activate_promo_card function start’); /* debug logger call */
require_once (PROMO_DIR_PATH . ‘includes/class-promo-card-activator.php’);
$promoCreate=new Promo_Card_Activator;
$promoCreate->promo_db_master_create();
$promoCreate->promo_db_detail_create();
}

function deactivate_promo_card() {
log_me(‘deactivate_promo_card function start’); /* debug logger call */
require_once (PROMO_DIR_PATH . ‘includes/class-promo-card-deactivator.php’);
Promo_Card_Deactivator::deactivate();
}

register_activation_hook( PROMO_DIR_PATH, ‘activate_promo_card’ );
//add_action(‘init’, ‘activate_promo_card’);
register_deactivation_hook( PROMO_DIR_PATH, ‘deactivate_promo_card’ );
//add_action(‘init’, ‘deactivate_promo_card’);

If I use the add_action then it fires the function in all cases which is not good.
What am I missing?

0
Doveman 2 months 2023-04-11T11:59:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse