Introduce require_if_theme_supports(), move post thumbnails functions to there own include and only included them if the theme supports them. See #10928 and [12132]

git-svn-id: http://svn.automattic.com/wordpress/trunk@12134 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-11-01 10:10:06 +00:00
parent 22ae6f36c0
commit 7251aff3f3
4 changed files with 61 additions and 35 deletions

View File

@ -0,0 +1,43 @@
<?php
/**
* WordPress Post Image Template Functions.
*
* Support for post thumbnails
* Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these.
*
* @package WordPress
* @subpackage Template
*/
function has_post_image( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return !! get_post_image_id( $post_id );
}
function get_post_image_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
function the_post_image( $size = 'thumbnail', $attr = '' ) {
echo get_the_post_image( NULL, $size, $attr );
}
function get_the_post_image( $post_id = NULL, $size = 'thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_image_id = get_post_image_id( $post_id );
$size = apply_filters( 'post_image_size', $size );
if ( $post_image_id ) {
do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
$html = wp_get_attachment_image( $post_image_id, $size, false, $attr );
do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
} else {
$html = '';
}
return apply_filters( 'post_image_html', $html, $post_id, $post_image_id );
}
?>

View File

@ -880,41 +880,6 @@ function walk_page_dropdown_tree() {
return call_user_func_array(array(&$walker, 'walk'), $args);
}
//
// Post images
//
function has_post_image( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return !! get_post_image_id( $post_id );
}
function get_post_image_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
function the_post_image( $size = 'thumbnail', $attr = '' ) {
echo get_the_post_image( NULL, $size, $attr );
}
function get_the_post_image( $post_id = NULL, $size = 'thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_image_id = get_post_image_id( $post_id );
$size = apply_filters( 'post_image_size', $size );
if ( $post_image_id ) {
do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
$html = wp_get_attachment_image( $post_image_id, $size, false, $attr );
do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
} else {
$html = '';
}
return apply_filters( 'post_image_html', $html, $post_id, $post_image_id );
}
//
// Attachments
//

View File

@ -1306,6 +1306,8 @@ function add_custom_image_header($header_callback, $admin_header_callback) {
/**
* Allows a theme to register its support of a certain feature
*
* Must be called in the themes functions.php file to work.
*
* @author Mark Jaquith
* @since 2.9
* @param string $feature the feature being added
@ -1329,4 +1331,17 @@ function current_theme_supports( $feature ) {
return ( isset( $_wp_theme_features[$feature] ) && $_wp_theme_features[$feature] );
}
/**
* Checks a theme's support for a given feature before loading the functions which implement it.
*
* @author Peter Westwood
* @since 2.9
* @param string $feature the feature being checked
* @param string $include the file containing the functions that implement the feature
*/
function require_if_theme_supports( $feature, $include) {
if ( current_theme_supports( $feature ) )
require ( $include );
}
?>

View File

@ -687,6 +687,9 @@ if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions
if ( file_exists(TEMPLATEPATH . '/functions.php') )
include(TEMPLATEPATH . '/functions.php');
// Load in support for template functions which the theme supports
require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-image-template.php' );
/**
* Runs just before PHP shuts down execution.
*