It so happened that in WordPress the territory of the theme is understood only as files, functions and scripts that affect the appearance of your theme. All functionality, such as custom post types, widgets, secondary files are transferred to Сore plugin.
The advantage of using the Core plugin is that after disabling or deleting the theme custom post types, widgets created by the theme will remain working.
Сore plugin example
Create a folder in the directory with the theme and name it – plugins. Inside which create another folder mycustomtheme-core.
In mycustomtheme-core create a file mycustomtheme-core.php and add the code below. It is also recommended to create an empty index.php file in the plugin folder for security.
<?php /* Plugin Name: MyCustomTheme Core Plugin URI: https://mywebsite.com/plugin Description: A plugin that expands the functionality of my theme Version: 1.0 Author: AuthorName Author URI: https://mywebsite.com License: GPLv2 or later Text Domain: your-textdomain-here */ if (!function_exists('add_action')) { echo ''; exit; // check from what place the plug-in is started } //In the plugin directory, create an inc folder and transfer all the necessary files to it require plugin_dir_path( __FILE__ ) . 'inc/widget.php'; require plugin_dir_path( __FILE__ ) . 'inc/custom-post-type.php' require plugin_dir_path( __FILE__ ) . 'inc/acf.php' ?>
How to display a warning about the need to activate additional plugins after activating the theme is described in this article Connecting the necessary plugins for yours WordPress theme: