PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.0
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.0
3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 3.0.0 3.0.1 All 71 releases
stockpack / extra / captions.php

captions.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 3.7.0, at extra/captions.php

54 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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