$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - How to access deleted term inside delete_product_cat action|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - How to access deleted term inside delete_product_cat action

matteradmin9PV0评论

I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:

add_action('delete_product_cat', 'sync_cat_delete', 10, 1);

function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
    var_dump($deleted_term);
}

But when I do it, I get 500 internal server error

So what could be the issue?

Thanks

I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this:

add_action('delete_product_cat', 'sync_cat_delete', 10, 1);

function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
    var_dump($deleted_term);
}

But when I do it, I get 500 internal server error

So what could be the issue?

Thanks

Share Improve this question asked Dec 31, 2018 at 16:16 AL-KatebAL-Kateb 1033 bronze badges 6
  • where exactly would this be displaying? – rudtek Commented Dec 31, 2018 at 16:22
  • It would be displayed in the ajax response when a category is deleted, I placed var_dump there just for testing purposes, I could read the output with fiddler, an HTTP debugger. – AL-Kateb Commented Dec 31, 2018 at 16:30
  • 1 I think your add_action call specifies only a single function parameter ( 1 ) but your function actually takes 4 parameters – Tom J Nowell Commented Dec 31, 2018 at 17:00
  • @TomJNowell I figured that much, but according to the docs developer.wordpress/reference/hooks/delete_taxonomy there should be 4 parameters. – AL-Kateb Commented Dec 31, 2018 at 19:01
  • 1 So you need to change the number of parameters to 4, not 1 in your add_action(). – Jacob Peattie Commented Jan 1, 2019 at 1:55
 |  Show 1 more comment

1 Answer 1

Reset to default 1

You get 500 error, because you’ve added your filter incorrectly... It takes 4 params, but you register it as it was using only one.

add_action('delete_product_cat', 'sync_cat_delete', 10, 1); 
//  10 is priority, 1 is number of params to take

function sync_cat_delete($term, $tt_id, $deleted_term, $object_ids){
    var_dump($deleted_term);
}

So if you change that 1 to 4, it should be OK.

Post a comment

comment list (0)

  1. No comments so far