/**
  * register our custom templates in the wp cache, overriding the menu that wp uses
  * thanks to http://www.wpexplorer.com/wordpress-page-templates-plugin
  */
 public function register_custom_templates($attrs)
 {
     $page_templates = [];
     foreach (Page_Template::getAll() as $template) {
         $page_templates[$template->name] = $template->name;
         unset($template);
     }
     // Create the key used for the themes cache
     $cache_key = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet());
     // Retrieve the cache list. If it doesn't exist, or it's empty prepare an array
     $templates = wp_get_theme()->get_page_templates();
     if (empty($templates)) {
         $templates = array();
     }
     // New cache, therefore remove the old one
     wp_cache_delete($cache_key, 'themes');
     // Now add our template to the list of templates by merging our templates with the existing templates array from the cache.
     $templates = array_merge($templates, $page_templates);
     // Add the modified cache to allow WordPress to pick it up for listing available templates
     wp_cache_add($cache_key, $templates, 'themes', 1800);
     return $attrs;
 }