Advertisement
gilzow

Scan for controllers marked as a template

Mar 3rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. needs $theme_dir to be defined
  2. needs templates to have the Custom Page Template syntax
  3.  
  4. <?php
  5. /*
  6. Template Name: My Custom Page
  7. */
  8.  
  9. ##
  10.  
  11. $templates = $this->get_page_templates();
  12.  
  13. ##
  14.  
  15.       function get_page_templates() {
  16.  
  17.                 $page_templates = array();
  18.  
  19.                 $files = (array) glob(trailingslashit($theme_dir)."*.php",GLOB_BRACE);
  20.  
  21.                 foreach ( $files as $full_path ) {
  22.                         if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) )
  23.                                 continue;
  24.  
  25.                         $file_chunks = explode(trailingslashit($theme_dir),$full_path);
  26.                         $array_k = $file_chunks[1];
  27.  
  28.                         $page_templates[ $array_k ] = _cleanup_header_comment( $header[1] );
  29.                 }
  30.  
  31.                 return $page_templates;
  32.  
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement