raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Theme, template, and stylesheet functions.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Template
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Retrieve name of the current stylesheet.
mp-wp_genesis 11 *
mp-wp_genesis 12 * The theme name that the administrator has currently set the front end theme
mp-wp_genesis 13 * as.
mp-wp_genesis 14 *
mp-wp_genesis 15 * For all extensive purposes, the template name and the stylesheet name are
mp-wp_genesis 16 * going to be the same for most cases.
mp-wp_genesis 17 *
mp-wp_genesis 18 * @since 1.5.0
mp-wp_genesis 19 * @uses apply_filters() Calls 'stylesheet' filter on stylesheet name.
mp-wp_genesis 20 *
mp-wp_genesis 21 * @return string Stylesheet name.
mp-wp_genesis 22 */
mp-wp_genesis 23 function get_stylesheet() {
mp-wp_genesis 24 return apply_filters('stylesheet', get_option('stylesheet'));
mp-wp_genesis 25 }
mp-wp_genesis 26
mp-wp_genesis 27 /**
mp-wp_genesis 28 * Retrieve stylesheet directory path for current theme.
mp-wp_genesis 29 *
mp-wp_genesis 30 * @since 1.5.0
mp-wp_genesis 31 * @uses apply_filters() Calls 'stylesheet_directory' filter on stylesheet directory and theme name.
mp-wp_genesis 32 *
mp-wp_genesis 33 * @return string Path to current theme directory.
mp-wp_genesis 34 */
mp-wp_genesis 35 function get_stylesheet_directory() {
mp-wp_genesis 36 $stylesheet = get_stylesheet();
mp-wp_genesis 37 $stylesheet_dir = get_theme_root() . "/$stylesheet";
mp-wp_genesis 38 return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
mp-wp_genesis 39 }
mp-wp_genesis 40
mp-wp_genesis 41 /**
mp-wp_genesis 42 * Retrieve stylesheet directory URI.
mp-wp_genesis 43 *
mp-wp_genesis 44 * @since 1.5.0
mp-wp_genesis 45 *
mp-wp_genesis 46 * @return string
mp-wp_genesis 47 */
mp-wp_genesis 48 function get_stylesheet_directory_uri() {
mp-wp_genesis 49 $stylesheet = get_stylesheet();
mp-wp_genesis 50 $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
mp-wp_genesis 51 return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
mp-wp_genesis 52 }
mp-wp_genesis 53
mp-wp_genesis 54 /**
mp-wp_genesis 55 * Retrieve URI of current theme stylesheet.
mp-wp_genesis 56 *
mp-wp_genesis 57 * The stylesheet file name is 'style.css' which is appended to {@link
mp-wp_genesis 58 * get_stylesheet_directory_uri() stylesheet directory URI} path.
mp-wp_genesis 59 *
mp-wp_genesis 60 * @since 1.5.0
mp-wp_genesis 61 * @uses apply_filters() Calls 'stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI.
mp-wp_genesis 62 *
mp-wp_genesis 63 * @return string
mp-wp_genesis 64 */
mp-wp_genesis 65 function get_stylesheet_uri() {
mp-wp_genesis 66 $stylesheet_dir_uri = get_stylesheet_directory_uri();
mp-wp_genesis 67 $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
mp-wp_genesis 68 return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
mp-wp_genesis 69 }
mp-wp_genesis 70
mp-wp_genesis 71 /**
mp-wp_genesis 72 * Retrieve localized stylesheet URI.
mp-wp_genesis 73 *
mp-wp_genesis 74 * The stylesheet directory for the localized stylesheet files are located, by
mp-wp_genesis 75 * default, in the base theme directory. The name of the locale file will be the
mp-wp_genesis 76 * locale followed by '.css'. If that does not exist, then the text direction
mp-wp_genesis 77 * stylesheet will be checked for existence, for example 'ltr.css'.
mp-wp_genesis 78 *
mp-wp_genesis 79 * The theme may change the location of the stylesheet directory by either using
mp-wp_genesis 80 * the 'stylesheet_directory_uri' filter or the 'locale_stylesheet_uri' filter.
mp-wp_genesis 81 * If you want to change the location of the stylesheet files for the entire
mp-wp_genesis 82 * WordPress workflow, then change the former. If you just have the locale in a
mp-wp_genesis 83 * separate folder, then change the latter.
mp-wp_genesis 84 *
mp-wp_genesis 85 * @since 2.1.0
mp-wp_genesis 86 * @uses apply_filters() Calls 'locale_stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI.
mp-wp_genesis 87 *
mp-wp_genesis 88 * @return string
mp-wp_genesis 89 */
mp-wp_genesis 90 function get_locale_stylesheet_uri() {
mp-wp_genesis 91 global $wp_locale;
mp-wp_genesis 92 $stylesheet_dir_uri = get_stylesheet_directory_uri();
mp-wp_genesis 93 $dir = get_stylesheet_directory();
mp-wp_genesis 94 $locale = get_locale();
mp-wp_genesis 95 if ( file_exists("$dir/$locale.css") )
mp-wp_genesis 96 $stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
mp-wp_genesis 97 elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
mp-wp_genesis 98 $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
mp-wp_genesis 99 else
mp-wp_genesis 100 $stylesheet_uri = '';
mp-wp_genesis 101 return apply_filters('locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
mp-wp_genesis 102 }
mp-wp_genesis 103
mp-wp_genesis 104 /**
mp-wp_genesis 105 * Retrieve name of the current theme.
mp-wp_genesis 106 *
mp-wp_genesis 107 * @since 1.5.0
mp-wp_genesis 108 * @uses apply_filters() Calls 'template' filter on template option.
mp-wp_genesis 109 *
mp-wp_genesis 110 * @return string Template name.
mp-wp_genesis 111 */
mp-wp_genesis 112 function get_template() {
mp-wp_genesis 113 return apply_filters('template', get_option('template'));
mp-wp_genesis 114 }
mp-wp_genesis 115
mp-wp_genesis 116 /**
mp-wp_genesis 117 * Retrieve current theme directory.
mp-wp_genesis 118 *
mp-wp_genesis 119 * @since 1.5.0
mp-wp_genesis 120 * @uses apply_filters() Calls 'template_directory' filter on template directory path and template name.
mp-wp_genesis 121 *
mp-wp_genesis 122 * @return string Template directory path.
mp-wp_genesis 123 */
mp-wp_genesis 124 function get_template_directory() {
mp-wp_genesis 125 $template = get_template();
mp-wp_genesis 126 $template_dir = get_theme_root() . "/$template";
mp-wp_genesis 127 return apply_filters('template_directory', $template_dir, $template);
mp-wp_genesis 128 }
mp-wp_genesis 129
mp-wp_genesis 130 /**
mp-wp_genesis 131 * Retrieve theme directory URI.
mp-wp_genesis 132 *
mp-wp_genesis 133 * @since 1.5.0
mp-wp_genesis 134 * @uses apply_filters() Calls 'template_directory_uri' filter on template directory URI path and template name.
mp-wp_genesis 135 *
mp-wp_genesis 136 * @return string Template directory URI.
mp-wp_genesis 137 */
mp-wp_genesis 138 function get_template_directory_uri() {
mp-wp_genesis 139 $template = get_template();
mp-wp_genesis 140 $template_dir_uri = get_theme_root_uri() . "/$template";
mp-wp_genesis 141 return apply_filters('template_directory_uri', $template_dir_uri, $template);
mp-wp_genesis 142 }
mp-wp_genesis 143
mp-wp_genesis 144 /**
mp-wp_genesis 145 * Retrieve theme data from parsed theme file.
mp-wp_genesis 146 *
mp-wp_genesis 147 * The description will have the tags filtered with the following HTML elements
mp-wp_genesis 148 * whitelisted. The <b>'a'</b> element with the <em>href</em> and <em>title</em>
mp-wp_genesis 149 * attributes. The <b>abbr</b> element with the <em>title</em> attribute. The
mp-wp_genesis 150 * <b>acronym<b> element with the <em>title</em> attribute allowed. The
mp-wp_genesis 151 * <b>code</b>, <b>em</b>, and <b>strong</b> elements also allowed.
mp-wp_genesis 152 *
mp-wp_genesis 153 * The style.css file must contain theme name, theme URI, and description. The
mp-wp_genesis 154 * data can also contain author URI, author, template (parent template),
mp-wp_genesis 155 * version, status, and finally tags. Some of these are not used by WordPress
mp-wp_genesis 156 * administration panels, but are used by theme directory web sites which list
mp-wp_genesis 157 * the theme.
mp-wp_genesis 158 *
mp-wp_genesis 159 * @since 1.5.0
mp-wp_genesis 160 *
mp-wp_genesis 161 * @param string $theme_file Theme file path.
mp-wp_genesis 162 * @return array Theme data.
mp-wp_genesis 163 */
mp-wp_genesis 164 function get_theme_data( $theme_file ) {
mp-wp_genesis 165 $themes_allowed_tags = array(
mp-wp_genesis 166 'a' => array(
mp-wp_genesis 167 'href' => array(),'title' => array()
mp-wp_genesis 168 ),
mp-wp_genesis 169 'abbr' => array(
mp-wp_genesis 170 'title' => array()
mp-wp_genesis 171 ),
mp-wp_genesis 172 'acronym' => array(
mp-wp_genesis 173 'title' => array()
mp-wp_genesis 174 ),
mp-wp_genesis 175 'code' => array(),
mp-wp_genesis 176 'em' => array(),
mp-wp_genesis 177 'strong' => array()
mp-wp_genesis 178 );
mp-wp_genesis 179
mp-wp_genesis 180 $theme_data = implode( '', file( $theme_file ) );
mp-wp_genesis 181 $theme_data = str_replace ( '\r', '\n', $theme_data );
mp-wp_genesis 182 preg_match( '|Theme Name:(.*)$|mi', $theme_data, $theme_name );
mp-wp_genesis 183 preg_match( '|Theme URI:(.*)$|mi', $theme_data, $theme_uri );
mp-wp_genesis 184 preg_match( '|Description:(.*)$|mi', $theme_data, $description );
mp-wp_genesis 185
mp-wp_genesis 186 if ( preg_match( '|Author URI:(.*)$|mi', $theme_data, $author_uri ) )
mp-wp_genesis 187 $author_uri = clean_url( trim( $author_uri[1]) );
mp-wp_genesis 188 else
mp-wp_genesis 189 $author_uri = '';
mp-wp_genesis 190
mp-wp_genesis 191 if ( preg_match( '|Template:(.*)$|mi', $theme_data, $template ) )
mp-wp_genesis 192 $template = wp_kses( trim( $template[1] ), $themes_allowed_tags );
mp-wp_genesis 193 else
mp-wp_genesis 194 $template = '';
mp-wp_genesis 195
mp-wp_genesis 196 if ( preg_match( '|Version:(.*)|i', $theme_data, $version ) )
mp-wp_genesis 197 $version = wp_kses( trim( $version[1] ), $themes_allowed_tags );
mp-wp_genesis 198 else
mp-wp_genesis 199 $version = '';
mp-wp_genesis 200
mp-wp_genesis 201 if ( preg_match('|Status:(.*)|i', $theme_data, $status) )
mp-wp_genesis 202 $status = wp_kses( trim( $status[1] ), $themes_allowed_tags );
mp-wp_genesis 203 else
mp-wp_genesis 204 $status = 'publish';
mp-wp_genesis 205
mp-wp_genesis 206 if ( preg_match('|Tags:(.*)|i', $theme_data, $tags) )
mp-wp_genesis 207 $tags = array_map( 'trim', explode( ',', wp_kses( trim( $tags[1] ), array() ) ) );
mp-wp_genesis 208 else
mp-wp_genesis 209 $tags = array();
mp-wp_genesis 210
mp-wp_genesis 211 $name = $theme = wp_kses( trim( $theme_name[1] ), $themes_allowed_tags );
mp-wp_genesis 212 $theme_uri = clean_url( trim( $theme_uri[1] ) );
mp-wp_genesis 213 $description = wptexturize( wp_kses( trim( $description[1] ), $themes_allowed_tags ) );
mp-wp_genesis 214
mp-wp_genesis 215 if ( preg_match( '|Author:(.*)$|mi', $theme_data, $author_name ) ) {
mp-wp_genesis 216 if ( empty( $author_uri ) ) {
mp-wp_genesis 217 $author = wp_kses( trim( $author_name[1] ), $themes_allowed_tags );
mp-wp_genesis 218 } else {
mp-wp_genesis 219 $author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $author_uri, __( 'Visit author homepage' ), wp_kses( trim( $author_name[1] ), $themes_allowed_tags ) );
mp-wp_genesis 220 }
mp-wp_genesis 221 } else {
mp-wp_genesis 222 $author = __('Anonymous');
mp-wp_genesis 223 }
mp-wp_genesis 224
mp-wp_genesis 225 return array( 'Name' => $name, 'Title' => $theme, 'URI' => $theme_uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status, 'Tags' => $tags );
mp-wp_genesis 226 }
mp-wp_genesis 227
mp-wp_genesis 228 /**
mp-wp_genesis 229 * Retrieve list of themes with theme data in theme directory.
mp-wp_genesis 230 *
mp-wp_genesis 231 * The theme is broken, if it doesn't have a parent theme and is missing either
mp-wp_genesis 232 * style.css and, or index.php. If the theme has a parent theme then it is
mp-wp_genesis 233 * broken, if it is missing style.css; index.php is optional. The broken theme
mp-wp_genesis 234 * list is saved in the {@link $wp_broken_themes} global, which is displayed on
mp-wp_genesis 235 * the theme list in the administration panels.
mp-wp_genesis 236 *
mp-wp_genesis 237 * @since 1.5.0
mp-wp_genesis 238 * @global array $wp_broken_themes Stores the broken themes.
mp-wp_genesis 239 * @global array $wp_themes Stores the working themes.
mp-wp_genesis 240 *
mp-wp_genesis 241 * @return array Theme list with theme data.
mp-wp_genesis 242 */
mp-wp_genesis 243 function get_themes() {
mp-wp_genesis 244 global $wp_themes, $wp_broken_themes;
mp-wp_genesis 245
mp-wp_genesis 246 if ( isset($wp_themes) )
mp-wp_genesis 247 return $wp_themes;
mp-wp_genesis 248
mp-wp_genesis 249 $themes = array();
mp-wp_genesis 250 $wp_broken_themes = array();
mp-wp_genesis 251 $theme_loc = $theme_root = get_theme_root();
mp-wp_genesis 252 if ( '/' != WP_CONTENT_DIR ) // don't want to replace all forward slashes, see Trac #4541
mp-wp_genesis 253 $theme_loc = str_replace(WP_CONTENT_DIR, '', $theme_root);
mp-wp_genesis 254
mp-wp_genesis 255 // Files in wp-content/themes directory and one subdir down
mp-wp_genesis 256 $themes_dir = @ opendir($theme_root);
mp-wp_genesis 257 if ( !$themes_dir )
mp-wp_genesis 258 return false;
mp-wp_genesis 259
mp-wp_genesis 260 while ( ($theme_dir = readdir($themes_dir)) !== false ) {
mp-wp_genesis 261 if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
mp-wp_genesis 262 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
mp-wp_genesis 263 continue;
mp-wp_genesis 264 $stylish_dir = @ opendir($theme_root . '/' . $theme_dir);
mp-wp_genesis 265 $found_stylesheet = false;
mp-wp_genesis 266 while ( ($theme_file = readdir($stylish_dir)) !== false ) {
mp-wp_genesis 267 if ( $theme_file == 'style.css' ) {
mp-wp_genesis 268 $theme_files[] = $theme_dir . '/' . $theme_file;
mp-wp_genesis 269 $found_stylesheet = true;
mp-wp_genesis 270 break;
mp-wp_genesis 271 }
mp-wp_genesis 272 }
mp-wp_genesis 273 @closedir($stylish_dir);
mp-wp_genesis 274 if ( !$found_stylesheet ) { // look for themes in that dir
mp-wp_genesis 275 $subdir = "$theme_root/$theme_dir";
mp-wp_genesis 276 $subdir_name = $theme_dir;
mp-wp_genesis 277 $theme_subdir = @ opendir( $subdir );
mp-wp_genesis 278 while ( ($theme_dir = readdir($theme_subdir)) !== false ) {
mp-wp_genesis 279 if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
mp-wp_genesis 280 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
mp-wp_genesis 281 continue;
mp-wp_genesis 282 $stylish_dir = @ opendir($subdir . '/' . $theme_dir);
mp-wp_genesis 283 $found_stylesheet = false;
mp-wp_genesis 284 while ( ($theme_file = readdir($stylish_dir)) !== false ) {
mp-wp_genesis 285 if ( $theme_file == 'style.css' ) {
mp-wp_genesis 286 $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
mp-wp_genesis 287 $found_stylesheet = true;
mp-wp_genesis 288 break;
mp-wp_genesis 289 }
mp-wp_genesis 290 }
mp-wp_genesis 291 @closedir($stylish_dir);
mp-wp_genesis 292 }
mp-wp_genesis 293 }
mp-wp_genesis 294 @closedir($theme_subdir);
mp-wp_genesis 295 $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
mp-wp_genesis 296 }
mp-wp_genesis 297 }
mp-wp_genesis 298 }
mp-wp_genesis 299 if ( is_dir( $theme_dir ) )
mp-wp_genesis 300 @closedir( $theme_dir );
mp-wp_genesis 301
mp-wp_genesis 302 if ( !$themes_dir || !$theme_files )
mp-wp_genesis 303 return $themes;
mp-wp_genesis 304
mp-wp_genesis 305 sort($theme_files);
mp-wp_genesis 306
mp-wp_genesis 307 foreach ( (array) $theme_files as $theme_file ) {
mp-wp_genesis 308 if ( !is_readable("$theme_root/$theme_file") ) {
mp-wp_genesis 309 $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
mp-wp_genesis 310 continue;
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 $theme_data = get_theme_data("$theme_root/$theme_file");
mp-wp_genesis 314
mp-wp_genesis 315 $name = $theme_data['Name'];
mp-wp_genesis 316 $title = $theme_data['Title'];
mp-wp_genesis 317 $description = wptexturize($theme_data['Description']);
mp-wp_genesis 318 $version = $theme_data['Version'];
mp-wp_genesis 319 $author = $theme_data['Author'];
mp-wp_genesis 320 $template = $theme_data['Template'];
mp-wp_genesis 321 $stylesheet = dirname($theme_file);
mp-wp_genesis 322
mp-wp_genesis 323 $screenshot = false;
mp-wp_svg-screens... 324 foreach ( array('svg', 'png', 'gif', 'jpg', 'jpeg') as $ext ) {
mp-wp_genesis 325 if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
mp-wp_genesis 326 $screenshot = "screenshot.$ext";
mp-wp_genesis 327 break;
mp-wp_genesis 328 }
mp-wp_genesis 329 }
mp-wp_genesis 330
mp-wp_genesis 331 if ( empty($name) ) {
mp-wp_genesis 332 $name = dirname($theme_file);
mp-wp_genesis 333 $title = $name;
mp-wp_genesis 334 }
mp-wp_genesis 335
mp-wp_genesis 336 if ( empty($template) ) {
mp-wp_genesis 337 if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
mp-wp_genesis 338 $template = dirname($theme_file);
mp-wp_genesis 339 else
mp-wp_genesis 340 continue;
mp-wp_genesis 341 }
mp-wp_genesis 342
mp-wp_genesis 343 $template = trim($template);
mp-wp_genesis 344
mp-wp_genesis 345 if ( !file_exists("$theme_root/$template/index.php") ) {
mp-wp_genesis 346 $parent_dir = dirname(dirname($theme_file));
mp-wp_genesis 347 if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
mp-wp_genesis 348 $template = "$parent_dir/$template";
mp-wp_genesis 349 } else {
mp-wp_genesis 350 $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
mp-wp_genesis 351 continue;
mp-wp_genesis 352 }
mp-wp_genesis 353 }
mp-wp_genesis 354
mp-wp_genesis 355 $stylesheet_files = array();
mp-wp_genesis 356 $template_files = array();
mp-wp_genesis 357
mp-wp_genesis 358 $stylesheet_dir = @ dir("$theme_root/$stylesheet");
mp-wp_genesis 359 if ( $stylesheet_dir ) {
mp-wp_genesis 360 while ( ($file = $stylesheet_dir->read()) !== false ) {
mp-wp_genesis 361 if ( !preg_match('|^\.+$|', $file) ) {
mp-wp_genesis 362 if ( preg_match('|\.css$|', $file) )
mp-wp_genesis 363 $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
mp-wp_genesis 364 elseif ( preg_match('|\.php$|', $file) )
mp-wp_genesis 365 $template_files[] = "$theme_loc/$stylesheet/$file";
mp-wp_genesis 366 }
mp-wp_genesis 367 }
mp-wp_genesis 368 }
mp-wp_genesis 369
mp-wp_genesis 370 $template_dir = @ dir("$theme_root/$template");
mp-wp_genesis 371 if ( $template_dir ) {
mp-wp_genesis 372 while(($file = $template_dir->read()) !== false) {
mp-wp_genesis 373 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
mp-wp_genesis 374 $template_files[] = "$theme_loc/$template/$file";
mp-wp_genesis 375 }
mp-wp_genesis 376 }
mp-wp_genesis 377
mp-wp_genesis 378 $template_dir = dirname($template_files[0]);
mp-wp_genesis 379 $stylesheet_dir = dirname($stylesheet_files[0]);
mp-wp_genesis 380
mp-wp_genesis 381 if ( empty($template_dir) )
mp-wp_genesis 382 $template_dir = '/';
mp-wp_genesis 383 if ( empty($stylesheet_dir) )
mp-wp_genesis 384 $stylesheet_dir = '/';
mp-wp_genesis 385
mp-wp_genesis 386 // Check for theme name collision. This occurs if a theme is copied to
mp-wp_genesis 387 // a new theme directory and the theme header is not updated. Whichever
mp-wp_genesis 388 // theme is first keeps the name. Subsequent themes get a suffix applied.
mp-wp_genesis 389 // The Default and Classic themes always trump their pretenders.
mp-wp_genesis 390 if ( isset($themes[$name]) ) {
mp-wp_genesis 391 if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
mp-wp_genesis 392 ('default' == $stylesheet || 'classic' == $stylesheet) ) {
mp-wp_genesis 393 // If another theme has claimed to be one of our default themes, move
mp-wp_genesis 394 // them aside.
mp-wp_genesis 395 $suffix = $themes[$name]['Stylesheet'];
mp-wp_genesis 396 $new_name = "$name/$suffix";
mp-wp_genesis 397 $themes[$new_name] = $themes[$name];
mp-wp_genesis 398 $themes[$new_name]['Name'] = $new_name;
mp-wp_genesis 399 } else {
mp-wp_genesis 400 $name = "$name/$stylesheet";
mp-wp_genesis 401 }
mp-wp_genesis 402 }
mp-wp_genesis 403
mp-wp_genesis 404 $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot, 'Tags' => $theme_data['Tags']);
mp-wp_genesis 405 }
mp-wp_genesis 406
mp-wp_genesis 407 // Resolve theme dependencies.
mp-wp_genesis 408 $theme_names = array_keys($themes);
mp-wp_genesis 409
mp-wp_genesis 410 foreach ( (array) $theme_names as $theme_name ) {
mp-wp_genesis 411 $themes[$theme_name]['Parent Theme'] = '';
mp-wp_genesis 412 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
mp-wp_genesis 413 foreach ( (array) $theme_names as $parent_theme_name ) {
mp-wp_genesis 414 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
mp-wp_genesis 415 $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
mp-wp_genesis 416 break;
mp-wp_genesis 417 }
mp-wp_genesis 418 }
mp-wp_genesis 419 }
mp-wp_genesis 420 }
mp-wp_genesis 421
mp-wp_genesis 422 $wp_themes = $themes;
mp-wp_genesis 423
mp-wp_genesis 424 return $themes;
mp-wp_genesis 425 }
mp-wp_genesis 426
mp-wp_genesis 427 /**
mp-wp_genesis 428 * Retrieve theme data.
mp-wp_genesis 429 *
mp-wp_genesis 430 * @since 1.5.0
mp-wp_genesis 431 *
mp-wp_genesis 432 * @param string $theme Theme name.
mp-wp_genesis 433 * @return array|null Null, if theme name does not exist. Theme data, if exists.
mp-wp_genesis 434 */
mp-wp_genesis 435 function get_theme($theme) {
mp-wp_genesis 436 $themes = get_themes();
mp-wp_genesis 437
mp-wp_genesis 438 if ( array_key_exists($theme, $themes) )
mp-wp_genesis 439 return $themes[$theme];
mp-wp_genesis 440
mp-wp_genesis 441 return null;
mp-wp_genesis 442 }
mp-wp_genesis 443
mp-wp_genesis 444 /**
mp-wp_genesis 445 * Retrieve current theme display name.
mp-wp_genesis 446 *
mp-wp_genesis 447 * If the 'current_theme' option has already been set, then it will be returned
mp-wp_genesis 448 * instead. If it is not set, then each theme will be iterated over until both
mp-wp_genesis 449 * the current stylesheet and current template name.
mp-wp_genesis 450 *
mp-wp_genesis 451 * @since 1.5.0
mp-wp_genesis 452 *
mp-wp_genesis 453 * @return string
mp-wp_genesis 454 */
mp-wp_genesis 455 function get_current_theme() {
mp-wp_genesis 456 if ( $theme = get_option('current_theme') )
mp-wp_genesis 457 return $theme;
mp-wp_genesis 458
mp-wp_genesis 459 $themes = get_themes();
mp-wp_genesis 460 $theme_names = array_keys($themes);
mp-wp_genesis 461 $current_template = get_option('template');
mp-wp_genesis 462 $current_stylesheet = get_option('stylesheet');
mp-wp_genesis 463 $current_theme = 'WordPress Default';
mp-wp_genesis 464
mp-wp_genesis 465 if ( $themes ) {
mp-wp_genesis 466 foreach ( (array) $theme_names as $theme_name ) {
mp-wp_genesis 467 if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
mp-wp_genesis 468 $themes[$theme_name]['Template'] == $current_template ) {
mp-wp_genesis 469 $current_theme = $themes[$theme_name]['Name'];
mp-wp_genesis 470 break;
mp-wp_genesis 471 }
mp-wp_genesis 472 }
mp-wp_genesis 473 }
mp-wp_genesis 474
mp-wp_genesis 475 update_option('current_theme', $current_theme);
mp-wp_genesis 476
mp-wp_genesis 477 return $current_theme;
mp-wp_genesis 478 }
mp-wp_genesis 479
mp-wp_genesis 480 /**
mp-wp_genesis 481 * Retrieve path to themes directory.
mp-wp_genesis 482 *
mp-wp_genesis 483 * Does not have trailing slash.
mp-wp_genesis 484 *
mp-wp_genesis 485 * @since 1.5.0
mp-wp_genesis 486 * @uses apply_filters() Calls 'theme_root' filter on path.
mp-wp_genesis 487 *
mp-wp_genesis 488 * @return string Theme path.
mp-wp_genesis 489 */
mp-wp_genesis 490 function get_theme_root() {
mp-wp_genesis 491 return apply_filters('theme_root', WP_CONTENT_DIR . "/themes");
mp-wp_genesis 492 }
mp-wp_genesis 493
mp-wp_genesis 494 /**
mp-wp_genesis 495 * Retrieve URI for themes directory.
mp-wp_genesis 496 *
mp-wp_genesis 497 * Does not have trailing slash.
mp-wp_genesis 498 *
mp-wp_genesis 499 * @since 1.5.0
mp-wp_genesis 500 *
mp-wp_genesis 501 * @return string Themes URI.
mp-wp_genesis 502 */
mp-wp_genesis 503 function get_theme_root_uri() {
mp-wp_genesis 504 return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl'));
mp-wp_genesis 505 }
mp-wp_genesis 506
mp-wp_genesis 507 /**
mp-wp_genesis 508 * Retrieve path to file without the use of extension.
mp-wp_genesis 509 *
mp-wp_genesis 510 * Used to quickly retrieve the path of file without including the file
mp-wp_genesis 511 * extension. It will also check the parent template, if the file exists, with
mp-wp_genesis 512 * the use of {@link locate_template()}. Allows for more generic file location
mp-wp_genesis 513 * without the use of the other get_*_template() functions.
mp-wp_genesis 514 *
mp-wp_genesis 515 * Can be used with include() or require() to retrieve path.
mp-wp_genesis 516 * <code>
mp-wp_genesis 517 * if( '' != get_query_template( '404' ) )
mp-wp_genesis 518 * include( get_query_template( '404' ) );
mp-wp_genesis 519 * </code>
mp-wp_genesis 520 * or the same can be accomplished with
mp-wp_genesis 521 * <code>
mp-wp_genesis 522 * if( '' != get_404_template() )
mp-wp_genesis 523 * include( get_404_template() );
mp-wp_genesis 524 * </code>
mp-wp_genesis 525 *
mp-wp_genesis 526 * @since 1.5.0
mp-wp_genesis 527 *
mp-wp_genesis 528 * @param string $type Filename without extension.
mp-wp_genesis 529 * @return string Full path to file.
mp-wp_genesis 530 */
mp-wp_genesis 531 function get_query_template($type) {
mp-wp_genesis 532 $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
mp-wp_genesis 533 return apply_filters("{$type}_template", locate_template(array("{$type}.php")));
mp-wp_genesis 534 }
mp-wp_genesis 535
mp-wp_genesis 536 /**
mp-wp_genesis 537 * Retrieve path of 404 template in current or parent template.
mp-wp_genesis 538 *
mp-wp_genesis 539 * @since 1.5.0
mp-wp_genesis 540 *
mp-wp_genesis 541 * @return string
mp-wp_genesis 542 */
mp-wp_genesis 543 function get_404_template() {
mp-wp_genesis 544 return get_query_template('404');
mp-wp_genesis 545 }
mp-wp_genesis 546
mp-wp_genesis 547 /**
mp-wp_genesis 548 * Retrieve path of archive template in current or parent template.
mp-wp_genesis 549 *
mp-wp_genesis 550 * @since 1.5.0
mp-wp_genesis 551 *
mp-wp_genesis 552 * @return string
mp-wp_genesis 553 */
mp-wp_genesis 554 function get_archive_template() {
mp-wp_genesis 555 return get_query_template('archive');
mp-wp_genesis 556 }
mp-wp_genesis 557
mp-wp_genesis 558 /**
mp-wp_genesis 559 * Retrieve path of author template in current or parent template.
mp-wp_genesis 560 *
mp-wp_genesis 561 * @since 1.5.0
mp-wp_genesis 562 *
mp-wp_genesis 563 * @return string
mp-wp_genesis 564 */
mp-wp_genesis 565 function get_author_template() {
mp-wp_genesis 566 return get_query_template('author');
mp-wp_genesis 567 }
mp-wp_genesis 568
mp-wp_genesis 569 /**
mp-wp_genesis 570 * Retrieve path of category template in current or parent template.
mp-wp_genesis 571 *
mp-wp_genesis 572 * Works by retrieving the current category ID, for example 'category-1.php' and
mp-wp_genesis 573 * will fallback to category.php template, if the ID category file doesn't
mp-wp_genesis 574 * exist.
mp-wp_genesis 575 *
mp-wp_genesis 576 * @since 1.5.0
mp-wp_genesis 577 * @uses apply_filters() Calls 'category_template' on file path of category template.
mp-wp_genesis 578 *
mp-wp_genesis 579 * @return string
mp-wp_genesis 580 */
mp-wp_genesis 581 function get_category_template() {
mp-wp_genesis 582 $template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php', 'category.php'));
mp-wp_genesis 583 return apply_filters('category_template', $template);
mp-wp_genesis 584 }
mp-wp_genesis 585
mp-wp_genesis 586 /**
mp-wp_genesis 587 * Retrieve path of tag template in current or parent template.
mp-wp_genesis 588 *
mp-wp_genesis 589 * Works by retrieving the current tag name, for example 'tag-wordpress.php' and will
mp-wp_genesis 590 * fallback to tag.php template, if the name tag file doesn't exist.
mp-wp_genesis 591 *
mp-wp_genesis 592 * @since 2.3.0
mp-wp_genesis 593 * @uses apply_filters() Calls 'tag_template' on file path of tag template.
mp-wp_genesis 594 *
mp-wp_genesis 595 * @return string
mp-wp_genesis 596 */
mp-wp_genesis 597 function get_tag_template() {
mp-wp_genesis 598 $template = locate_template(array("tag-" . get_query_var('tag') . '.php', 'tag.php'));
mp-wp_genesis 599 return apply_filters('tag_template', $template);
mp-wp_genesis 600 }
mp-wp_genesis 601
mp-wp_genesis 602 /**
mp-wp_genesis 603 * Retrieve path of taxonomy template in current or parent template.
mp-wp_genesis 604 *
mp-wp_genesis 605 * Retrieves the taxonomy and term, if term is available. The template is
mp-wp_genesis 606 * prepended with 'taxonomy-' and followed by both the taxonomy string and
mp-wp_genesis 607 * the taxonomy string followed by a dash and then followed by the term.
mp-wp_genesis 608 *
mp-wp_genesis 609 * The taxonomy and term template is checked and used first, if it exists.
mp-wp_genesis 610 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
mp-wp_genesis 611 * template is used. If none of the files exist, then it will fall back on to
mp-wp_genesis 612 * index.php.
mp-wp_genesis 613 *
mp-wp_genesis 614 * @since unknown (2.6.0 most likely)
mp-wp_genesis 615 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
mp-wp_genesis 616 *
mp-wp_genesis 617 * @return string
mp-wp_genesis 618 */
mp-wp_genesis 619 function get_taxonomy_template() {
mp-wp_genesis 620 $taxonomy = get_query_var('taxonomy');
mp-wp_genesis 621 $term = get_query_var('term');
mp-wp_genesis 622
mp-wp_genesis 623 $templates = array();
mp-wp_genesis 624 if ( $taxonomy && $term )
mp-wp_genesis 625 $templates[] = "taxonomy-$taxonomy-$term.php";
mp-wp_genesis 626 if ( $taxonomy )
mp-wp_genesis 627 $templates[] = "taxonomy-$taxonomy.php";
mp-wp_genesis 628
mp-wp_genesis 629 $templates[] = "taxonomy.php";
mp-wp_genesis 630
mp-wp_genesis 631 $template = locate_template($templates);
mp-wp_genesis 632 return apply_filters('taxonomy_template', $template);
mp-wp_genesis 633 }
mp-wp_genesis 634
mp-wp_genesis 635 /**
mp-wp_genesis 636 * Retrieve path of date template in current or parent template.
mp-wp_genesis 637 *
mp-wp_genesis 638 * @since 1.5.0
mp-wp_genesis 639 *
mp-wp_genesis 640 * @return string
mp-wp_genesis 641 */
mp-wp_genesis 642 function get_date_template() {
mp-wp_genesis 643 return get_query_template('date');
mp-wp_genesis 644 }
mp-wp_genesis 645
mp-wp_genesis 646 /**
mp-wp_genesis 647 * Retrieve path of home template in current or parent template.
mp-wp_genesis 648 *
mp-wp_genesis 649 * Attempts to locate 'home.php' first before falling back to 'index.php'.
mp-wp_genesis 650 *
mp-wp_genesis 651 * @since 1.5.0
mp-wp_genesis 652 * @uses apply_filters() Calls 'home_template' on file path of home template.
mp-wp_genesis 653 *
mp-wp_genesis 654 * @return string
mp-wp_genesis 655 */
mp-wp_genesis 656 function get_home_template() {
mp-wp_genesis 657 $template = locate_template(array('home.php', 'index.php'));
mp-wp_genesis 658 return apply_filters('home_template', $template);
mp-wp_genesis 659 }
mp-wp_genesis 660
mp-wp_genesis 661 /**
mp-wp_genesis 662 * Retrieve path of page template in current or parent template.
mp-wp_genesis 663 *
mp-wp_genesis 664 * First attempt is to look for the file in the '_wp_page_template' page meta
mp-wp_genesis 665 * data. The second attempt, if the first has a file and is not empty, is to
mp-wp_genesis 666 * look for 'page.php'.
mp-wp_genesis 667 *
mp-wp_genesis 668 * @since 1.5.0
mp-wp_genesis 669 *
mp-wp_genesis 670 * @return string
mp-wp_genesis 671 */
mp-wp_genesis 672 function get_page_template() {
mp-wp_genesis 673 global $wp_query;
mp-wp_genesis 674
mp-wp_genesis 675 $id = (int) $wp_query->post->ID;
mp-wp_genesis 676 $template = get_post_meta($id, '_wp_page_template', true);
mp-wp_genesis 677
mp-wp_genesis 678 if ( 'default' == $template )
mp-wp_genesis 679 $template = '';
mp-wp_genesis 680
mp-wp_genesis 681 $templates = array();
mp-wp_genesis 682 if ( !empty($template) && !validate_file($template) )
mp-wp_genesis 683 $templates[] = $template;
mp-wp_genesis 684
mp-wp_genesis 685 $templates[] = "page.php";
mp-wp_genesis 686
mp-wp_genesis 687 return apply_filters('page_template', locate_template($templates));
mp-wp_genesis 688 }
mp-wp_genesis 689
mp-wp_genesis 690 /**
mp-wp_genesis 691 * Retrieve path of paged template in current or parent template.
mp-wp_genesis 692 *
mp-wp_genesis 693 * @since 1.5.0
mp-wp_genesis 694 *
mp-wp_genesis 695 * @return string
mp-wp_genesis 696 */
mp-wp_genesis 697 function get_paged_template() {
mp-wp_genesis 698 return get_query_template('paged');
mp-wp_genesis 699 }
mp-wp_genesis 700
mp-wp_genesis 701 /**
mp-wp_genesis 702 * Retrieve path of search template in current or parent template.
mp-wp_genesis 703 *
mp-wp_genesis 704 * @since 1.5.0
mp-wp_genesis 705 *
mp-wp_genesis 706 * @return string
mp-wp_genesis 707 */
mp-wp_genesis 708 function get_search_template() {
mp-wp_genesis 709 return get_query_template('search');
mp-wp_genesis 710 }
mp-wp_genesis 711
mp-wp_genesis 712 /**
mp-wp_genesis 713 * Retrieve path of single template in current or parent template.
mp-wp_genesis 714 *
mp-wp_genesis 715 * @since 1.5.0
mp-wp_genesis 716 *
mp-wp_genesis 717 * @return string
mp-wp_genesis 718 */
mp-wp_genesis 719 function get_single_template() {
mp-wp_genesis 720 return get_query_template('single');
mp-wp_genesis 721 }
mp-wp_genesis 722
mp-wp_genesis 723 /**
mp-wp_genesis 724 * Retrieve path of attachment template in current or parent template.
mp-wp_genesis 725 *
mp-wp_genesis 726 * The attachment path first checks if the first part of the mime type exists.
mp-wp_genesis 727 * The second check is for the second part of the mime type. The last check is
mp-wp_genesis 728 * for both types separated by an underscore. If neither are found then the file
mp-wp_genesis 729 * 'attachment.php' is checked and returned.
mp-wp_genesis 730 *
mp-wp_genesis 731 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and
mp-wp_genesis 732 * finally 'text_plain.php'.
mp-wp_genesis 733 *
mp-wp_genesis 734 * @since 2.0.0
mp-wp_genesis 735 *
mp-wp_genesis 736 * @return string
mp-wp_genesis 737 */
mp-wp_genesis 738 function get_attachment_template() {
mp-wp_genesis 739 global $posts;
mp-wp_genesis 740 $type = explode('/', $posts[0]->post_mime_type);
mp-wp_genesis 741 if ( $template = get_query_template($type[0]) )
mp-wp_genesis 742 return $template;
mp-wp_genesis 743 elseif ( $template = get_query_template($type[1]) )
mp-wp_genesis 744 return $template;
mp-wp_genesis 745 elseif ( $template = get_query_template("$type[0]_$type[1]") )
mp-wp_genesis 746 return $template;
mp-wp_genesis 747 else
mp-wp_genesis 748 return get_query_template('attachment');
mp-wp_genesis 749 }
mp-wp_genesis 750
mp-wp_genesis 751 /**
mp-wp_genesis 752 * Retrieve path of comment popup template in current or parent template.
mp-wp_genesis 753 *
mp-wp_genesis 754 * Checks for comment popup template in current template, if it exists or in the
mp-wp_genesis 755 * parent template. If it doesn't exist, then it retrieves the comment-popup.php
mp-wp_genesis 756 * file from the default theme. The default theme must then exist for it to
mp-wp_genesis 757 * work.
mp-wp_genesis 758 *
mp-wp_genesis 759 * @since 1.5.0
mp-wp_genesis 760 * @uses apply_filters() Calls 'comments_popup_template' filter on path.
mp-wp_genesis 761 *
mp-wp_genesis 762 * @return string
mp-wp_genesis 763 */
mp-wp_genesis 764 function get_comments_popup_template() {
mp-wp_genesis 765 $template = locate_template(array("comments-popup.php"));
mp-wp_genesis 766 if ('' == $template)
mp-wp_genesis 767 $template = get_theme_root() . '/default/comments-popup.php';
mp-wp_genesis 768
mp-wp_genesis 769 return apply_filters('comments_popup_template', $template);
mp-wp_genesis 770 }
mp-wp_genesis 771
mp-wp_genesis 772 /**
mp-wp_genesis 773 * Retrieve the name of the highest priority template file that exists.
mp-wp_genesis 774 *
mp-wp_genesis 775 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
mp-wp_genesis 776 * inherit from a parent theme can just overload one file.
mp-wp_genesis 777 *
mp-wp_genesis 778 * @since 2.7.0
mp-wp_genesis 779 *
mp-wp_genesis 780 * @param array $template_names Array of template files to search for in priority order.
mp-wp_genesis 781 * @param bool $load If true the template file will be loaded if it is found.
mp-wp_genesis 782 * @return string The template filename if one is located.
mp-wp_genesis 783 */
mp-wp_genesis 784 function locate_template($template_names, $load = false) {
mp-wp_genesis 785 if (!is_array($template_names))
mp-wp_genesis 786 return '';
mp-wp_genesis 787
mp-wp_genesis 788 $located = '';
mp-wp_genesis 789 foreach($template_names as $template_name) {
mp-wp_genesis 790 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
mp-wp_genesis 791 $located = STYLESHEETPATH . '/' . $template_name;
mp-wp_genesis 792 break;
mp-wp_genesis 793 } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
mp-wp_genesis 794 $located = TEMPLATEPATH . '/' . $template_name;
mp-wp_genesis 795 break;
mp-wp_genesis 796 }
mp-wp_genesis 797 }
mp-wp_genesis 798
mp-wp_genesis 799 if ($load && '' != $located)
mp-wp_genesis 800 load_template($located);
mp-wp_genesis 801
mp-wp_genesis 802 return $located;
mp-wp_genesis 803 }
mp-wp_genesis 804
mp-wp_genesis 805 /**
mp-wp_genesis 806 * Require once the template file with WordPress environment.
mp-wp_genesis 807 *
mp-wp_genesis 808 * The globals are set up for the template file to ensure that the WordPress
mp-wp_genesis 809 * environment is available from within the function. The query variables are
mp-wp_genesis 810 * also available.
mp-wp_genesis 811 *
mp-wp_genesis 812 * @since 1.5.0
mp-wp_genesis 813 *
mp-wp_genesis 814 * @param string $_template_file Path to template file.
mp-wp_genesis 815 */
mp-wp_genesis 816 function load_template($_template_file) {
mp-wp_genesis 817 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
mp-wp_genesis 818
mp-wp_genesis 819 if ( is_array($wp_query->query_vars) )
mp-wp_genesis 820 extract($wp_query->query_vars, EXTR_SKIP);
mp-wp_genesis 821
mp-wp_genesis 822 require_once($_template_file);
mp-wp_genesis 823 }
mp-wp_genesis 824
mp-wp_genesis 825 /**
mp-wp_genesis 826 * Display localized stylesheet link element.
mp-wp_genesis 827 *
mp-wp_genesis 828 * @since 2.1.0
mp-wp_genesis 829 */
mp-wp_genesis 830 function locale_stylesheet() {
mp-wp_genesis 831 $stylesheet = get_locale_stylesheet_uri();
mp-wp_genesis 832 if ( empty($stylesheet) )
mp-wp_genesis 833 return;
mp-wp_genesis 834 echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
mp-wp_genesis 835 }
mp-wp_genesis 836
mp-wp_genesis 837 /**
mp-wp_genesis 838 * Start preview theme output buffer.
mp-wp_genesis 839 *
mp-wp_genesis 840 * Will only preform task if the user has permissions and template and preview
mp-wp_genesis 841 * query variables exist.
mp-wp_genesis 842 *
mp-wp_genesis 843 * @since 2.5.0
mp-wp_genesis 844 */
mp-wp_genesis 845 function preview_theme() {
mp-wp_genesis 846 if ( ! (isset($_GET['template']) && isset($_GET['preview'])) )
mp-wp_genesis 847 return;
mp-wp_genesis 848
mp-wp_genesis 849 if ( !current_user_can( 'switch_themes' ) )
mp-wp_genesis 850 return;
mp-wp_genesis 851
mp-wp_genesis 852 $_GET['template'] = preg_replace('|[^a-z0-9_.-]|i', '', $_GET['template']);
mp-wp_genesis 853
mp-wp_genesis 854 if ( validate_file($_GET['template']) )
mp-wp_genesis 855 return;
mp-wp_genesis 856
mp-wp_genesis 857 add_filter('template', create_function('', "return '{$_GET['template']}';") );
mp-wp_genesis 858
mp-wp_genesis 859 if ( isset($_GET['stylesheet']) ) {
mp-wp_genesis 860 $_GET['stylesheet'] = preg_replace('|[^a-z0-9_.-]|i', '', $_GET['stylesheet']);
mp-wp_genesis 861 if ( validate_file($_GET['stylesheet']) )
mp-wp_genesis 862 return;
mp-wp_genesis 863 add_filter('stylesheet', create_function('', "return '{$_GET['stylesheet']}';") );
mp-wp_genesis 864 }
mp-wp_genesis 865
mp-wp_genesis 866 ob_start( 'preview_theme_ob_filter' );
mp-wp_genesis 867 }
mp-wp_genesis 868 add_action('setup_theme', 'preview_theme');
mp-wp_genesis 869
mp-wp_genesis 870 /**
mp-wp_genesis 871 * Callback function for ob_start() to capture all links in the theme.
mp-wp_genesis 872 *
mp-wp_genesis 873 * @since unknown
mp-wp_genesis 874 * @access private
mp-wp_genesis 875 *
mp-wp_genesis 876 * @param string $content
mp-wp_genesis 877 * @return string
mp-wp_genesis 878 */
mp-wp_genesis 879 function preview_theme_ob_filter( $content ) {
mp-wp_genesis 880 return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content );
mp-wp_genesis 881 }
mp-wp_genesis 882
mp-wp_genesis 883 /**
mp-wp_genesis 884 * Manipulates preview theme links in order to control and maintain location.
mp-wp_genesis 885 *
mp-wp_genesis 886 * Callback function for preg_replace_callback() to accept and filter matches.
mp-wp_genesis 887 *
mp-wp_genesis 888 * @since unknown
mp-wp_genesis 889 * @access private
mp-wp_genesis 890 *
mp-wp_genesis 891 * @param array $matches
mp-wp_genesis 892 * @return string
mp-wp_genesis 893 */
mp-wp_genesis 894 function preview_theme_ob_filter_callback( $matches ) {
mp-wp_genesis 895 if ( strpos($matches[4], 'onclick') !== false )
mp-wp_genesis 896 $matches[4] = preg_replace('#onclick=([\'"]).*?(?<!\\\)\\1#i', '', $matches[4]); //Strip out any onclicks from rest of <a>. (?<!\\\) means to ignore the '" if its escaped by \ to prevent breaking mid-attribute.
mp-wp_genesis 897 if (
mp-wp_genesis 898 ( false !== strpos($matches[3], '/wp-admin/') )
mp-wp_genesis 899 ||
mp-wp_genesis 900 ( false !== strpos($matches[3], '://') && 0 !== strpos($matches[3], get_option('home')) )
mp-wp_genesis 901 ||
mp-wp_genesis 902 ( false !== strpos($matches[3], '/feed/') )
mp-wp_genesis 903 ||
mp-wp_genesis 904 ( false !== strpos($matches[3], '/trackback/') )
mp-wp_genesis 905 )
mp-wp_genesis 906 return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4];
mp-wp_genesis 907
mp-wp_genesis 908 $link = add_query_arg( array('preview' => 1, 'template' => $_GET['template'], 'stylesheet' => @$_GET['stylesheet'] ), $matches[3] );
mp-wp_genesis 909 if ( 0 === strpos($link, 'preview=1') )
mp-wp_genesis 910 $link = "?$link";
mp-wp_genesis 911 return $matches[1] . attribute_escape( $link ) . $matches[4];
mp-wp_genesis 912 }
mp-wp_genesis 913
mp-wp_genesis 914 /**
mp-wp_genesis 915 * Switches current theme to new template and stylesheet names.
mp-wp_genesis 916 *
mp-wp_genesis 917 * @since unknown
mp-wp_genesis 918 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
mp-wp_genesis 919 *
mp-wp_genesis 920 * @param string $template Template name
mp-wp_genesis 921 * @param string $stylesheet Stylesheet name.
mp-wp_genesis 922 */
mp-wp_genesis 923 function switch_theme($template, $stylesheet) {
mp-wp_genesis 924 update_option('template', $template);
mp-wp_genesis 925 update_option('stylesheet', $stylesheet);
mp-wp_genesis 926 delete_option('current_theme');
mp-wp_genesis 927 $theme = get_current_theme();
mp-wp_genesis 928 do_action('switch_theme', $theme);
mp-wp_genesis 929 }
mp-wp_genesis 930
mp-wp_genesis 931 /**
mp-wp_genesis 932 * Checks that current theme files 'index.php' and 'style.css' exists.
mp-wp_genesis 933 *
mp-wp_genesis 934 * Does not check the 'default' theme. The 'default' theme should always exist
mp-wp_genesis 935 * or should have another theme renamed to that template name and directory
mp-wp_genesis 936 * path. Will switch theme to default if current theme does not validate.
mp-wp_genesis 937 * You can use the 'validate_current_theme' filter to return FALSE to
mp-wp_genesis 938 * disable this functionality.
mp-wp_genesis 939 *
mp-wp_genesis 940 * @since 1.5.0
mp-wp_genesis 941 *
mp-wp_genesis 942 * @return bool
mp-wp_genesis 943 */
mp-wp_genesis 944 function validate_current_theme() {
mp-wp_genesis 945 // Don't validate during an install/upgrade.
mp-wp_genesis 946 if ( defined('WP_INSTALLING') || !apply_filters( 'validate_current_theme', true ) )
mp-wp_genesis 947 return true;
mp-wp_genesis 948
mp-wp_genesis 949 if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) {
mp-wp_genesis 950 switch_theme('default', 'default');
mp-wp_genesis 951 return false;
mp-wp_genesis 952 }
mp-wp_genesis 953
mp-wp_genesis 954 if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) {
mp-wp_genesis 955 switch_theme('default', 'default');
mp-wp_genesis 956 return false;
mp-wp_genesis 957 }
mp-wp_genesis 958
mp-wp_genesis 959 return true;
mp-wp_genesis 960 }
mp-wp_genesis 961
mp-wp_genesis 962 /**
mp-wp_genesis 963 * Retrieve theme modification value for the current theme.
mp-wp_genesis 964 *
mp-wp_genesis 965 * If the modification name does not exist, then the $default will be passed
mp-wp_genesis 966 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
mp-wp_genesis 967 * string the template directory URI and the second string the stylesheet
mp-wp_genesis 968 * directory URI.
mp-wp_genesis 969 *
mp-wp_genesis 970 * @since 2.1.0
mp-wp_genesis 971 * @uses apply_filters() Calls 'theme_mod_$name' filter on the value.
mp-wp_genesis 972 *
mp-wp_genesis 973 * @param string $name Theme modification name.
mp-wp_genesis 974 * @param bool|string $default
mp-wp_genesis 975 * @return string
mp-wp_genesis 976 */
mp-wp_genesis 977 function get_theme_mod($name, $default = false) {
mp-wp_genesis 978 $theme = get_current_theme();
mp-wp_genesis 979
mp-wp_genesis 980 $mods = get_option("mods_$theme");
mp-wp_genesis 981
mp-wp_genesis 982 if ( isset($mods[$name]) )
mp-wp_genesis 983 return apply_filters( "theme_mod_$name", $mods[$name] );
mp-wp_genesis 984
mp-wp_genesis 985 return apply_filters( "theme_mod_$name", sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()) );
mp-wp_genesis 986 }
mp-wp_genesis 987
mp-wp_genesis 988 /**
mp-wp_genesis 989 * Update theme modification value for the current theme.
mp-wp_genesis 990 *
mp-wp_genesis 991 * @since 2.1.0
mp-wp_genesis 992 *
mp-wp_genesis 993 * @param string $name Theme modification name.
mp-wp_genesis 994 * @param string $value theme modification value.
mp-wp_genesis 995 */
mp-wp_genesis 996 function set_theme_mod($name, $value) {
mp-wp_genesis 997 $theme = get_current_theme();
mp-wp_genesis 998
mp-wp_genesis 999 $mods = get_option("mods_$theme");
mp-wp_genesis 1000
mp-wp_genesis 1001 $mods[$name] = $value;
mp-wp_genesis 1002
mp-wp_genesis 1003 update_option("mods_$theme", $mods);
mp-wp_genesis 1004 wp_cache_delete("mods_$theme", 'options');
mp-wp_genesis 1005 }
mp-wp_genesis 1006
mp-wp_genesis 1007 /**
mp-wp_genesis 1008 * Remove theme modification name from current theme list.
mp-wp_genesis 1009 *
mp-wp_genesis 1010 * If removing the name also removes all elements, then the entire option will
mp-wp_genesis 1011 * be removed.
mp-wp_genesis 1012 *
mp-wp_genesis 1013 * @since 2.1.0
mp-wp_genesis 1014 *
mp-wp_genesis 1015 * @param string $name Theme modification name.
mp-wp_genesis 1016 * @return null
mp-wp_genesis 1017 */
mp-wp_genesis 1018 function remove_theme_mod( $name ) {
mp-wp_genesis 1019 $theme = get_current_theme();
mp-wp_genesis 1020
mp-wp_genesis 1021 $mods = get_option("mods_$theme");
mp-wp_genesis 1022
mp-wp_genesis 1023 if ( !isset($mods[$name]) )
mp-wp_genesis 1024 return;
mp-wp_genesis 1025
mp-wp_genesis 1026 unset($mods[$name]);
mp-wp_genesis 1027
mp-wp_genesis 1028 if ( empty($mods) )
mp-wp_genesis 1029 return remove_theme_mods();
mp-wp_genesis 1030
mp-wp_genesis 1031 update_option("mods_$theme", $mods);
mp-wp_genesis 1032 wp_cache_delete("mods_$theme", 'options');
mp-wp_genesis 1033 }
mp-wp_genesis 1034
mp-wp_genesis 1035 /**
mp-wp_genesis 1036 * Remove theme modifications option for current theme.
mp-wp_genesis 1037 *
mp-wp_genesis 1038 * @since 2.1.0
mp-wp_genesis 1039 */
mp-wp_genesis 1040 function remove_theme_mods() {
mp-wp_genesis 1041 $theme = get_current_theme();
mp-wp_genesis 1042
mp-wp_genesis 1043 delete_option("mods_$theme");
mp-wp_genesis 1044 }
mp-wp_genesis 1045
mp-wp_genesis 1046 /**
mp-wp_genesis 1047 * Retrieve text color for custom header.
mp-wp_genesis 1048 *
mp-wp_genesis 1049 * @since 2.1.0
mp-wp_genesis 1050 * @uses HEADER_TEXTCOLOR
mp-wp_genesis 1051 *
mp-wp_genesis 1052 * @return string
mp-wp_genesis 1053 */
mp-wp_genesis 1054 function get_header_textcolor() {
mp-wp_genesis 1055 return get_theme_mod('header_textcolor', HEADER_TEXTCOLOR);
mp-wp_genesis 1056 }
mp-wp_genesis 1057
mp-wp_genesis 1058 /**
mp-wp_genesis 1059 * Display text color for custom header.
mp-wp_genesis 1060 *
mp-wp_genesis 1061 * @since 2.1.0
mp-wp_genesis 1062 */
mp-wp_genesis 1063 function header_textcolor() {
mp-wp_genesis 1064 echo get_header_textcolor();
mp-wp_genesis 1065 }
mp-wp_genesis 1066
mp-wp_genesis 1067 /**
mp-wp_genesis 1068 * Retrieve header image for custom header.
mp-wp_genesis 1069 *
mp-wp_genesis 1070 * @since 2.1.0
mp-wp_genesis 1071 * @uses HEADER_IMAGE
mp-wp_genesis 1072 *
mp-wp_genesis 1073 * @return string
mp-wp_genesis 1074 */
mp-wp_genesis 1075 function get_header_image() {
mp-wp_genesis 1076 return get_theme_mod('header_image', HEADER_IMAGE);
mp-wp_genesis 1077 }
mp-wp_genesis 1078
mp-wp_genesis 1079 /**
mp-wp_genesis 1080 * Display header image path.
mp-wp_genesis 1081 *
mp-wp_genesis 1082 * @since 2.1.0
mp-wp_genesis 1083 */
mp-wp_genesis 1084 function header_image() {
mp-wp_genesis 1085 echo get_header_image();
mp-wp_genesis 1086 }
mp-wp_genesis 1087
mp-wp_genesis 1088 /**
mp-wp_genesis 1089 * Add callbacks for image header display.
mp-wp_genesis 1090 *
mp-wp_genesis 1091 * The parameter $header_callback callback will be required to display the
mp-wp_genesis 1092 * content for the 'wp_head' action. The parameter $admin_header_callback
mp-wp_genesis 1093 * callback will be added to Custom_Image_Header class and that will be added
mp-wp_genesis 1094 * to the 'admin_menu' action.
mp-wp_genesis 1095 *
mp-wp_genesis 1096 * @since 2.1.0
mp-wp_genesis 1097 * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display.
mp-wp_genesis 1098 *
mp-wp_genesis 1099 * @param callback $header_callback Call on 'wp_head' action.
mp-wp_genesis 1100 * @param callback $admin_header_callback Call on administration panels.
mp-wp_genesis 1101 */
mp-wp_genesis 1102 function add_custom_image_header($header_callback, $admin_header_callback) {
mp-wp_genesis 1103 if ( ! empty($header_callback) )
mp-wp_genesis 1104 add_action('wp_head', $header_callback);
mp-wp_genesis 1105
mp-wp_genesis 1106 if ( ! is_admin() )
mp-wp_genesis 1107 return;
mp-wp_genesis 1108 require_once(ABSPATH . 'wp-admin/custom-header.php');
mp-wp_genesis 1109 $GLOBALS['custom_image_header'] = new Custom_Image_Header($admin_header_callback);
mp-wp_genesis 1110 add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
mp-wp_genesis 1111 }
mp-wp_genesis 1112
mp-wp_genesis 1113 ?>