My answer to this is not to continue down this path. It is a good idea to be able to choose a template
from the customizer, however, this code looks like it is attempting to save all page data as options and theme mods, and that is a bad idea.
-
Theme Mods are a single option row in the database, and specific to ONLY the theme you are using. Therefore, any data saved to it is lost to any other theme you may want to use in the future.
-
Options are single rows in a single table with limited columns and are not considered post data in WordPress, outside of this concept.
Selecting a page_template
or other post_meta
is available in the Customizer, as seen in a few plugins that are viable for this type of situation.