/** * Returns the parent theme domain path. No slash. * * @since 1.0.0 * @access protected * @return string */ function _carelib_get_parent_domain_path() { if (file_exists(carelib_get_parent_dir('languages'))) { return 'languages'; } $path = carelib_get_parent()->get('DomainPath'); return $path ? trim($path, '/') : 'languages'; }
/** * Gets the stylesheet files within the parent or child theme and checks if * they have the 'Style Name' header. If any files are found, they are * returned in an array. * * @since 1.0.0 * @access public * @return array */ function carelib_get_post_styles($post_type = 'post') { static $styles = array(); if (!empty($styles[$post_type])) { return $styles[$post_type]; } $styles[$post_type] = array(); $files = carelib_get_parent()->get_files('css', 2); if (is_child_theme()) { $files = array_merge($files, carelib_get_theme()->get_files('css', 2)); } foreach ($files as $file => $path) { $headers = get_file_data($path, array('Style Name' => 'Style Name', "{$post_type} Style" => "{$post_type} Style")); if (!empty($headers['Style Name'])) { $styles[$post_type][$file] = $headers['Style Name']; } elseif (!empty($headers["{$post_type} Style"])) { $styles[$post_type][$file] = $headers["{$post_type} Style"]; } } return $styles[$post_type] = array_flip($styles[$post_type]); }
/** * Returns a link to the parent theme URI. * * @since 1.0.0 * @access public * @return string */ function carelib_get_theme_link() { $theme = carelib_get_parent(); $allowed = array('abbr' => array('title' => true), 'acronym' => array('title' => true), 'code' => true, 'em' => true, 'strong' => true); // Note: URI is escaped via `WP_Theme::markup_header()`. return sprintf('<a class="theme-link" href="%s">%s</a>', $theme->display('ThemeURI'), wp_kses($theme->display('Name'), $allowed)); }
/** * Get an array of available custom templates with a specific header. * * Ideally, this function would be used to grab custom singular post templates. * It is a recreation of the WordPress page templates function because it * doesn't allow for other types of templates. * * @since 1.0.0 * @access public * @param string $post_type The name of the post type to get templates for. * @return array $post_templates The array of templates. */ function carelib_get_post_templates($post_type = 'post') { static $templates; if (!empty($templates) && isset($templates[$post_type])) { return $templates[$post_type]; } $post_templates = array(); // Get the theme PHP files one level deep. $files = carelib_get_parent()->get_files('php', 1); // If a child theme is active, get its files and merge with the parent theme files. if (is_child_theme()) { $files = array_merge($files, carelib_get_theme()->get_files('php', 1)); } foreach ($files as $file => $path) { // Get file data based on the post type singular name. $headers = get_file_data($path, array("{$post_type} Template" => "{$post_type} Template")); if (!empty($headers["{$post_type} Template"])) { $post_templates[$file] = $headers["{$post_type} Template"]; } } return $templates[$post_type] = array_flip($post_templates); }