Friday, September 16, 2022
HomeWordPress Developmentplugins - Neither update_option nor delete_option fires in deactivation hook

plugins – Neither update_option nor delete_option fires in deactivation hook


I’ve a plugin. And the next code:

operate activate_my_plugin(){
  // my_option worth right here: 1
  update_option('my_option',0,true); // I've tried with and with out final  parameter     
  // my_option worth right here: 0
}

operate deactivate_my_plugin{
  // my_option worth right here: 1
  delete_option('my_option');
  // my_option worth right here: 1 
  
  // or

  // my_option worth right here: 1 
  update_option('my_option',2); 
  // my_option worth right here: 1
}

operate xyz(){
  // my_option worth right here: 1 or 0
  if(!get_option('my_option')){
    // my_option worth right here: 1
    update_option('my_option',1);
    // my_option worth right here: 1
  }
}

register_activation_hook(__FILE__, __NAMESPACE__ . 'activate_my_plugin');
register_deactivation_hook(__FILE__, __NAMESPACE__ . 'deactivate_my_plugin');

add_action('init','xyz');

The deactivation hook is certainly firing, however for some cause, it will not replace the choice to a brand new worth or delete it. What am I lacking right here?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments