admin管理员组文章数量:1278853
WordPress 5.8.1
functions.php
add_action( 'deleted_theme', 'nonverbis_delete_extra_table', 10, 2 );
function nonverbis_delete_extra_table( $stylesheet, $deleted ){
error_log("delete_extra_table", 0);
}
What I do:
The log is empty. I mean that everything that this function does is writing "delete_extra_table" to the log. I don't have a debugger, so, I use writing to log for the debug purpose.
But the log is empty. This means that either a hook is wrong. Or some params (10, 2). Or I confused something else (like log or something).
To the best of my understanding, this line should have appeared in the log after I had pressed "Delete".
Could you help me understand why nothing has been written to the log?
And of course, the table has not been dropped.
WordPress 5.8.1
functions.php
add_action( 'deleted_theme', 'nonverbis_delete_extra_table', 10, 2 );
function nonverbis_delete_extra_table( $stylesheet, $deleted ){
error_log("delete_extra_table", 0);
}
What I do:
The log is empty. I mean that everything that this function does is writing "delete_extra_table" to the log. I don't have a debugger, so, I use writing to log for the debug purpose.
But the log is empty. This means that either a hook is wrong. Or some params (10, 2). Or I confused something else (like log or something).
To the best of my understanding, this line should have appeared in the log after I had pressed "Delete".
Could you help me understand why nothing has been written to the log?
And of course, the table has not been dropped.
Share Improve this question edited Nov 2, 2021 at 19:16 Kifsif asked Nov 2, 2021 at 19:03 KifsifKifsif 1012 bronze badges 3 |1 Answer
Reset to default 0There are two direct actions that you can hook into while deleting a theme
do_action( 'delete_theme', $stylesheet );
And
do_action( 'deleted_theme', $stylesheet, $deleted );
Now about the error_log()
function, you seem to be missing a argument, the destination.
One of my debugging tool is a custom error_log function, this is its code.
error_log(print_r($some_value, true), 3, __DIR__ . '/log.txt');
error_log("\r\n\r\n", 3, __DIR__ . '/log.txt');
This will create a log.txt
file in the same folder where you called this functions. If you use this in functions.php
the log.txt
will be in the root of your theme.
本文标签: Catch the moment when theme is deleted
版权声明:本文标题:Catch the moment when theme is deleted 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741237546a2363318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
switch_theme
. Themes don’t normally create database tables. That sort of thing usually belongs in plugins, which have the appropriate capabilities for cleaning up when deleted. – Jacob Peattie Commented Nov 3, 2021 at 7:32