PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.38
Strong Testimonials v2.38
3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / includes / functions-image.php
strong-testimonials / includes Last commit date
integrations 7 years ago class-strong-form.php 7 years ago class-strong-log.php 7 years ago class-strong-mail.php 7 years ago class-strong-templates.php 7 years ago class-strong-testimonials-order.php 7 years ago class-strong-testimonials-privacy.php 7 years ago class-strong-testimonials-render.php 7 years ago class-strong-testimonials-shortcode-average.php 7 years ago class-strong-testimonials-shortcode-count.php 7 years ago class-strong-testimonials-shortcode.php 7 years ago class-strong-view-display.php 7 years ago class-strong-view-form.php 7 years ago class-strong-view-slideshow.php 7 years ago class-strong-view.php 7 years ago class-walker-strong-category-checklist-front.php 7 years ago deprecated.php 7 years ago filters.php 7 years ago functions-activation.php 7 years ago functions-content.php 7 years ago functions-image.php 7 years ago functions-rating.php 7 years ago functions-template-form.php 7 years ago functions-template.php 7 years ago functions-views.php 7 years ago functions.php 7 years ago l10n-polylang.php 7 years ago l10n-wpml.php 7 years ago post-types.php 7 years ago retro.php 7 years ago scripts.php 7 years ago widget2.php 7 years ago
functions-image.php
169 lines
1 <?php
2 /**
3 * Featured image functions.
4 */
5
6 /**
7 * @param null $size
8 *
9 * @return mixed|string
10 */
11 function wpmtst_get_thumbnail( $size = null ) {
12 if ( ! WPMST()->atts( 'thumbnail' ) )
13 return '';
14
15 // let arg override view setting
16 $size = ( null === $size ) ? WPMST()->atts( 'thumbnail_size' ) : $size ;
17 if ( 'custom' == $size ) {
18 $size = array( WPMST()->atts( 'thumbnail_width' ), WPMST()->atts( 'thumbnail_height' ) );
19 }
20
21 $id = get_the_ID();
22 $img = '';
23
24 // check for a featured image
25 if ( has_post_thumbnail( $id ) ) {
26
27 // show featured image
28 $img = get_the_post_thumbnail( $id, $size );
29
30 } else {
31
32 // no featured image, now what?
33
34 if ( 'yes' == WPMST()->atts( 'gravatar' ) ) {
35 // view > gravatar > show gravatar (use default, if not found)
36
37 $img = get_avatar( wpmtst_get_field( 'email' ), apply_filters( 'wpmtst_gravatar_size', $size ) );
38
39 } elseif ( 'if' == WPMST()->atts( 'gravatar' ) ) {
40 // view > gravatar > show gravatar only if found (and has email)
41
42 if ( wpmtst_get_field( 'email' ) ) {
43 // get_avatar will return false if not found (via filter)
44 $img = get_avatar( wpmtst_get_field( 'email' ), apply_filters( 'wpmtst_gravatar_size', $size ) );
45 }
46 }
47
48 }
49
50 return apply_filters( 'wpmtst_thumbnail_img', $img, $id );
51 }
52
53 /**
54 * Filter the thumbnail image.
55 * Used to add link for a lightbox. Will not affect avatars.
56 *
57 * @param $img
58 * @param $post_id
59 *
60 * @since 1.23.0
61 * @since 2.9.4 classes and filter
62 * @since 2.30.0 lightbox_class
63 *
64 * @return string
65 */
66 function wpmtst_thumbnail_img( $img, $post_id ) {
67 if ( WPMST()->atts( 'lightbox' ) ) {
68 $url = wp_get_attachment_url( get_post_thumbnail_id( $post_id ) );
69 if ( $url ) {
70 $class_array = array( WPMST()->atts( 'lightbox_class' ) );
71 $classes = join( ' ', array_unique( apply_filters( 'wpmtst_thumbnail_link_class', $class_array ) ) );
72 $img = sprintf( '<a class="%s" href="%s">%s</a>', $classes, esc_url( $url ), $img );
73 }
74 }
75 return $img;
76 }
77 add_filter( 'wpmtst_thumbnail_img', 'wpmtst_thumbnail_img', 10, 2 );
78
79 /**
80 * Exclude testimonial thumbnails from Lazy Loading Responsive Images plugin.
81 *
82 * @param $attr
83 * @param $attachment
84 * @param $size
85 *
86 * @since 2.27.0
87 *
88 * @return array
89 */
90 function wpmtst_exclude_from_lazyload( $attr, $attachment, $size ) {
91 $options = get_option( 'wpmtst_options' );
92 if ( isset( $options['no_lazyload'] ) && $options['no_lazyload'] ) {
93 if ( 'wpm-testimonial' == get_post_type( $attachment->post_parent ) ) {
94 $attr['data-no-lazyload'] = 1;
95 }
96 }
97
98 return $attr;
99 }
100
101 /**
102 * Add filter if Lazy Loading Responsive Images plugin is active.
103 *
104 * @since 2.27.0
105 */
106 function wpmtst_lazyload_check() {
107 if ( wpmtst_is_plugin_active( 'lazy-loading-responsive-images' ) ) {
108 add_filter( 'wp_get_attachment_image_attributes', 'wpmtst_exclude_from_lazyload', 10, 3 );
109 }
110 }
111 add_action( 'init', 'wpmtst_lazyload_check' );
112
113 /**
114 * Filter the gravatar size.
115 *
116 * @param array|string $size
117 * @since 1.23.0
118 * @return mixed
119 */
120 function wpmtst_gravatar_size_filter( $size = array( 150, 150 ) ) {
121 // avatars are square so get the width of the requested size
122 if ( is_array( $size ) ) {
123 // if dimension array
124 $gravatar_size = $size[0];
125 } else {
126 // if named size
127 $image_sizes = wpmtst_get_image_sizes();
128 $gravatar_size = $image_sizes[$size]['width'];
129 }
130
131 return $gravatar_size;
132 }
133 add_filter( 'wpmtst_gravatar_size', 'wpmtst_gravatar_size_filter' );
134
135 /**
136 * Checks to see if the specified email address has a Gravatar image.
137 *
138 * Thanks Tom McFarlin https://tommcfarlin.com/check-if-a-user-has-a-gravatar/
139 * @param $email_address string The email of the address of the user to check
140 * @return bool Whether or not the user has a gravatar
141 * @since 1.23.0
142 */
143 function wpmtst_has_gravatar( $email_address ) {
144 // Build the Gravatar URL by hashing the email address
145 $url = 'http://www.gravatar.com/avatar/' . md5( strtolower( trim ( $email_address ) ) ) . '?d=404';
146
147 // Now check the headers...
148 $headers = @get_headers( $url );
149
150 // If 200 is found, the user has a Gravatar; otherwise, they don't.
151 return preg_match( '|200|', $headers[0] ) ? true : false;
152 }
153
154 /**
155 * Before assembling avatar HTML.
156 *
157 * @param $url
158 * @param $id_or_email
159 * @param $args
160 *
161 * @return bool
162 */
163 function wpmtst_get_avatar( $url, $id_or_email, $args ) {
164 if ( 'if' == WPMST()->atts( 'gravatar' ) && ! wpmtst_has_gravatar( $id_or_email ) )
165 return false;
166
167 return $url;
168 }
169