pmpro_loadTemplate

Loads a template from one of the default paths (PMPro plugin or theme), or from filtered path.

Description

(string) pmpro_loadTemplate( (constant) $page_name = null, (string) $where = 'local', (string) $type = 'pages', (string) $ext = 'php' ); 

Returns (string)

- The HTML for the template. TODO - Allow localized template files to be loaded?

Parameters (4)

0. $page_name — Optional. (constant) => null
- Name of the page/template
1. $where — Optional. (string) => 'local'
- local or url (whether to load from FS or over http)
2. $type — Optional. (string) => 'pages'
- Type of template (valid: email or pages,, adminpages, preheader)
3. $ext — Optional. (string) => 'php'
- File extension ('php', html,, htm, etc)

Usage

  1. if ( !function_exists( 'pmpro_loadTemplate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // - Name of the page/template 
  5. $page_name = null; 
  6.  
  7. // - `local` or `url` (whether to load from FS or over http) 
  8. $where = 'local'; 
  9.  
  10. // - Type of template (valid: 'email' or 'pages', 'adminpages', 'preheader') 
  11. $type = 'pages'; 
  12.  
  13. // - File extension ('php', 'html', 'htm', etc) 
  14. $ext = 'php'; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = pmpro_loadTemplate($page_name, $where, $type, $ext); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function pmpro_loadTemplate($page_name = null, $where = 'local', $type = 'pages', $ext = 'php' ) 
  2. // called from page handler shortcode 
  3. if (is_null($page_name)) 
  4. global $pmpro_page_name; 
  5. $page_name = $pmpro_page_name; 
  6.  
  7. if ($where == 'local') { 
  8. // template paths inorderof priority (array gets reversed) 
  9. $default_templates = array( 
  10. PMPRO_DIR . "/{$type}/{$page_name}.{$ext}", // default plugin path 
  11. get_template_directory() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // parent theme 
  12. get_stylesheet_directory() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // child / active theme 
  13. ); 
  14. } elseif( $where == 'url' ) { 
  15. // template paths inorderof priority (array gets reversed) 
  16. $default_templates = array( 
  17. PMPRO_URL . "/{$type}/{$page_name}.{$ext}", // default plugin path 
  18. get_template_directory_uri() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // parent theme 
  19. get_stylesheet_directory_uri() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // child / active theme 
  20. ); 
  21.  
  22. // Valid types: 'email', 'pages' 
  23. $templates = apply_filters("pmpro_{$type}_custom_template_path", $default_templates, $page_name, $type, $where, $ext); 
  24. $user_templates = array_diff($templates, $default_templates); 
  25.  
  26. //user specified a custom template path, so it has priority. 
  27. if (!empty($user_templates)) 
  28. $templates = $user_templates; 
  29.  
  30. //last element included in the array is the most first one we try to load 
  31. $templates = array_reverse($templates); 
  32.  
  33. // look for template file to include 
  34. ob_start(); 
  35. foreach($templates as $template_path) 
  36. {  
  37. // If loading a local file, check if it exists first 
  38. if($where == 'url' || file_exists($template_path)) 
  39. include $template_path; 
  40. break; 
  41. $template = ob_get_clean(); 
  42.  
  43. // return template content 
  44. return $template;