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


I am building a plugin based on a boilerplate gerenrated on
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;

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’);

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?

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

Leave an answer