啊,我找到了。
您可以使用after_setup_theme
行动挂钩。所以它会像
add_action(\'after_setup_theme\', [\'\\Recruitment\\recruitment\', \'create_table\']);
更新的代码
$theme = wp_get_theme();
if ( $theme->name == \'My THEME NAME\' ) {
global $wpdb;
global $charset_collate;
$sql = "CREATE TABLE IF NOT EXISTS ... $charset_collate;";
require_once ABSPATH . \'wp-admin/includes/upgrade.php\';
dbDelta( $sql );
add_option( \'ab_db_version\', self::$db_version );
}
// in another file
add_action(\'after_switch_theme\', [\'\\Recruitment\\recruitment\', \'create_table\']);