/** * This function locates and loads templates based on arguments. Optionally an array of data can be passed * that will be extract()ed and the template will have access to the $data. If data is passed, WordPress * global variables can be included as well. The template file can also be required once if necessary. * * Verify if the file exists in the theme first, then load the plugin template if necessary as a fallback. */ function note_get_template_part($slug, $name = '', $data = array(), $wp_globals = false, $require_once = false) { // note_get_template_part filter $template = apply_filters('note_get_template_part', note_locate_template_part($slug, $name), $slug, $name); // Finally, if we have a template, lets load it if ($template) { // If data was passed we have to require() the files if (is_array($data) && !empty($data)) { $data = apply_filters('note_get_template_part_data', $data, $slug, $name); // WordPress Globals if ($wp_globals) { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; } // Extract the data for use in the template extract($data, EXTR_SKIP); // Skip collisions unset($data); // We don't need the $data var anymore // Require Once if ($require_once) { require_once $template; } else { require $template; } } else { load_template($template, $require_once); } } }
/** * This function returns the correct template name for the selected template. It will use * the template ID as the fallback template name. */ public function get_template($template_id) { // Does this template id exist in templates? if ($this->is_valid_template($template_id) && isset($this->templates[$template_id]['template']) && !empty($this->templates[$template_id]['template'])) { $template_id = $this->templates[$template_id]['template']; } // Fallback to the default template if the requested template doesn't exist if (!note_locate_template_part($this->base_template_dir . '/' . $template_id)) { $template_id = 'default'; } // TODO: Add a filter to allow for adjustments // Return the template return $template_id; }