コード例 #1
0
 /**
  * Load Page Variables
  * @param string $json
  * @return void
  */
 public function loadVariables($json)
 {
     $this->variables = array();
     if (!empty($json)) {
         // Parse from JSON String
         $variables = json_decode($json, true);
         if (!empty($variables) && is_array($variables)) {
             // Page Variables
             $this->variables = $variables;
         }
     }
     // Load Template Variables
     if ($this->template instanceof Page_Template) {
         $this->template->getVariables($this);
     }
 }
コード例 #2
0
 /**
  * Get Skin's Page Templates
  * @param boolean $reload
  * @return array
  */
 public function getTemplates($reload = false)
 {
     if (!is_array($this->templates) || $reload) {
         $this->templates = array();
         $order = array();
         $tplDir = $this->checkDir('tpl/pages/');
         if (!empty($tplDir)) {
             // Scan Directories
             foreach (glob($tplDir . '*', GLOB_ONLYDIR | GLOB_MARK) as $dir) {
                 $config = $dir . 'config.json';
                 if (file_exists($config)) {
                     $template = new Page_Template($dir);
                     $this->templates[$template->getName()] = $template;
                     $order[$template->getName()] = $template->getOrder();
                 } else {
                     // Scan Sub-Directories
                     foreach (glob($dir . '*', GLOB_ONLYDIR | GLOB_MARK) as $dir) {
                         $config = $dir . 'config.json';
                         if (file_exists($config)) {
                             $template = new Page_Template($dir);
                             $this->templates[$template->getName()] = $template;
                             $order[$template->getName()] = $template->getOrder();
                         }
                     }
                 }
             }
         }
         // Re-Order Templates
         array_multisort($order, SORT_ASC, $this->templates);
     }
     return $this->templates;
 }
 /**
  * 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;
 }