| 1 |
<?php |
| 2 |
|
| 3 |
// helper function for featured_image caption |
| 4 |
if ( ! function_exists( 'stockpack_featured_image_caption' ) ) { |
| 5 |
function stockpack_featured_image_caption( $attachment_id = null ) { |
| 6 |
$stockpack_settings = StockpackSettings::get_instance(); |
| 7 |
if ( $stockpack_settings->get_featured_caption_setting() !== 'yes' ) { |
| 8 |
return ''; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! $attachment_id ) { |
| 12 |
$attachment_id = get_post_thumbnail_id(); |
| 13 |
if ( ! $attachment_id ) { |
| 14 |
return ''; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
return stockpack_fetch_caption( $attachment_id ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
if ( ! function_exists( 'stockpack_add_caption' ) ) { |
| 23 |
function stockpack_add_caption( $html ) { |
| 24 |
return $html . stockpack_featured_image_caption(); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
if ( ! function_exists( 'stockpack_fetch_caption' ) ) { |
| 29 |
function stockpack_fetch_caption( $attachment_id ) { |
| 30 |
$caption = wp_get_attachment_caption( $attachment_id ); |
| 31 |
|
| 32 |
if ( $caption ) { |
| 33 |
return '<figcaption class="stockpack-caption">' . $caption . '</figcaption>'; |
| 34 |
} |
| 35 |
|
| 36 |
return ''; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! function_exists( 'stockpack_add_caption_to_featured_image' ) ) { |
| 41 |
function stockpack_add_caption_to_featured_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) { |
| 42 |
// some themes have support already. |
| 43 |
$my_theme = wp_get_theme(); |
| 44 |
$excluded = apply_filters( 'stockpack_excluded_themes_caption', array( 'Bimber' ) ); |
| 45 |
if ( in_array( $my_theme->get( 'Name' ), $excluded ) ) { |
| 46 |
return $html; |
| 47 |
} |
| 48 |
|
| 49 |
return $html . stockpack_featured_image_caption( $post_thumbnail_id ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
add_filter( 'post_thumbnail_html', 'stockpack_add_caption_to_featured_image', 10, 5 ); |
| 54 |
|