wordpress theme editor file upload code example

Example 1: how to add files in child theme in theme editor

add_action('after_setup_theme', function() {
	$file = get_stylesheet_directory() . '/my-file.php';
	if(!file_exists($file)) {
		include_once ABSPATH . 'wp-admin/includes/file.php';
		\WP_Filesystem();
		global $wp_filesystem;
		$wp_filesystem->put_contents($file, '', FS_CHMOD_FILE);
	}
});

Example 2: how to add files in child theme in theme editor

add_action('after_setup_theme', function() {
	$file = get_stylesheet_directory() . '/my-file.php';
	touch($file);
});

Tags:

Misc Example