PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.2.8
Strong Testimonials v3.2.8
3.3.6 3.3.5 3.3.4 3.3.3 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
elementor 1 year ago logs 1 year ago strong-testimonials-beaver-block 1 year ago submodules 1 year ago class-strong-gutemberg.php 1 year ago class-strong-log.php 1 year ago class-strong-mail.php 1 year ago class-strong-testimonials-average-shortcode.php 1 year ago class-strong-testimonials-count-shortcode.php 1 year ago class-strong-testimonials-form.php 1 year ago class-strong-testimonials-order.php 1 year ago class-strong-testimonials-privacy.php 1 year ago class-strong-testimonials-render.php 1 year ago class-strong-testimonials-templates.php 1 year ago class-strong-testimonials-view-shortcode.php 1 year ago class-strong-testimonials-view-widget.php 1 year ago class-strong-view-display.php 1 year ago class-strong-view-form.php 1 year ago class-strong-view-slideshow.php 1 year ago class-strong-view.php 1 year ago class-walker-strong-category-checklist-front.php 1 year ago deprecated.php 1 year ago filters.php 1 year ago functions-activation.php 1 year ago functions-content.php 1 year ago functions-image.php 1 year ago functions-rating.php 1 year ago functions-template-form.php 1 year ago functions-template.php 1 year ago functions-views.php 1 year ago functions.php 1 year ago l10n-polylang.php 1 year ago l10n-wpml.php 1 year ago post-types.php 1 year ago retro.php 1 year ago scripts.php 1 year ago
functions-image.php
287 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' ) && ! is_admin() ) {
13 return '';
14 }
15
16 // let arg override view setting
17 $size = ( null === $size ) ? WPMST()->atts( 'thumbnail_size' ) : $size;
18 if ( 'custom' === $size ) {
19 $size = array( WPMST()->atts( 'thumbnail_width' ), WPMST()->atts( 'thumbnail_height' ) );
20 }
21
22 $id = get_the_ID();
23 $img = '';
24
25 // check for a featured image
26 if ( has_post_thumbnail( $id ) ) {
27
28 // show featured image
29 $img = get_the_post_thumbnail( $id, $size );
30
31 } else {
32
33 // no featured image, now what?
34
35 if ( 'yes' === WPMST()->atts( 'gravatar' ) ) {
36 // view > gravatar > show gravatar (use default, if not found)
37
38 $img = get_avatar( wpmtst_get_field( 'email' ), apply_filters( 'wpmtst_gravatar_size', $size ) );
39
40 } elseif ( 'if' === WPMST()->atts( 'gravatar' ) ) {
41 // view > gravatar > show gravatar only if found (and has email)
42
43 if ( wpmtst_get_field( 'email' ) ) {
44 // get_avatar will return false if not found (via filter)
45 $img = get_avatar( wpmtst_get_field( 'email' ), apply_filters( 'wpmtst_gravatar_size', $size ) );
46 }
47 }
48 $img = apply_filters( 'wpmtst_thumbnail_default_img', $img, $id, $size );
49 }
50
51 return apply_filters( 'wpmtst_thumbnail_img', $img, $id, $size );
52 }
53
54 /**
55 * Filter the thumbnail image.
56 * Used to add link for a lightbox. Will not affect avatars.
57 *
58 * @param $img
59 * @param $post_id
60 *
61 * @since 1.23.0
62 * @since 2.9.4 classes and filter
63 * @since 2.30.0 lightbox_class
64 *
65 * @return string
66 */
67 function wpmtst_thumbnail_img( $img, $post_id, $size ) {
68 if ( WPMST()->atts( 'lightbox' ) ) {
69 $url = wp_get_attachment_url( get_post_thumbnail_id( $post_id ) );
70 if ( $url ) {
71 $class_array = array( WPMST()->atts( 'lightbox_class' ) );
72 $classes = implode( ' ', array_unique( apply_filters( 'wpmtst_thumbnail_link_class', $class_array ) ) );
73 $img = sprintf( '<a class="%s" href="%s">%s</a>', $classes, esc_url( $url ), $img );
74 }
75 }
76 return $img;
77 }
78 add_filter( 'wpmtst_thumbnail_img', 'wpmtst_thumbnail_img', 10, 3 );
79
80
81 /**
82 * Exclude testimonial thumbnails from Lazy Loading Responsive Images plugin.
83 *
84 * @param $attr
85 * @param $attachment
86 * @param $size
87 *
88 * @since 2.27.0
89 *
90 * @return array
91 */
92 function wpmtst_exclude_from_lazyload( $attr, $attachment, $size ) {
93 $options = get_option( 'wpmtst_options' );
94
95 if ( isset( $options['no_lazyload_plugin'] ) && $options['no_lazyload_plugin'] ) {
96 if ( 'wpm-testimonial' === get_post_type( $attachment->post_parent ) ) {
97 $attr['data-no-lazyload'] = 1;
98 }
99 }
100
101 return $attr;
102 }
103 /**
104 * Add filter if Lazy Loading Responsive Images plugin is active.
105 *
106 * @since 2.27.0
107 */
108 function wpmtst_lazyload_check() {
109 if ( wpmtst_is_plugin_active( 'lazy-loading-responsive-images' ) ) {
110 add_filter( 'wp_get_attachment_image_attributes', 'wpmtst_exclude_from_lazyload', 10, 3 );
111 }
112 }
113 add_action( 'init', 'wpmtst_lazyload_check' );
114
115 /**
116 * Enable lazy load
117 *
118 * @param $attr
119 * @param $attachment
120 * @param $size
121 *
122 * @since 2.27.0
123 *
124 * @return array
125 */
126 function wpmtst_add_lazyload( $attr, $attachment, $size ) {
127 if ( ! function_exists( 'wp_lazy_loading_enabled' ) || ! apply_filters( 'wp_lazy_loading_enabled', true, 'img', 'strong_testimonials_has_lazyload' ) ) {
128 $options = get_option( 'wpmtst_options' );
129
130 if ( isset( $options['lazyload'] ) && $options['lazyload'] ) {
131 if ( 'wpm-testimonial' === get_post_type( $attachment->post_parent ) && ! is_admin() ) {
132 $attr['class'] .= ' lazy-load';
133 $attr['data-src'] = $attr['src'];
134 $attr['data-srcset'] = $attr['srcset'];
135 unset( $attr['src'] );
136 unset( $attr['srcset'] );
137 }
138 }
139 }
140
141 return $attr;
142 }
143 add_filter( 'wp_get_attachment_image_attributes', 'wpmtst_add_lazyload', 10, 3 );
144
145 /**
146 * Filter the gravatar size.
147 *
148 * @param array|string $size
149 * @since 1.23.0
150 * @return mixed
151 */
152 function wpmtst_gravatar_size_filter( $size = array( 150, 150 ) ) {
153 // avatars are square so get the width of the requested size
154 if ( is_array( $size ) ) {
155 // if dimension array
156 $gravatar_size = $size[0];
157 } else {
158 // if named size
159 $image_sizes = wpmtst_get_image_sizes();
160 $gravatar_size = $image_sizes[ $size ]['width'];
161 }
162
163 return $gravatar_size;
164 }
165 add_filter( 'wpmtst_gravatar_size', 'wpmtst_gravatar_size_filter' );
166
167 /**
168 * Checks to see if the specified email address has a Gravatar image.
169 *
170 * Thanks Tom McFarlin https://tommcfarlin.com/check-if-a-user-has-a-gravatar/
171 * @param $email_address string The email of the address of the user to check
172 * @return bool Whether or not the user has a gravatar
173 * @since 1.23.0
174 */
175 function wpmtst_has_gravatar( $email_address ) {
176 // Build the Gravatar URL by hashing the email address
177 $url = 'http://www.gravatar.com/avatar/' . md5( strtolower( trim( $email_address ) ) ) . '?d=404';
178
179 // Now check the headers...
180 $headers = get_headers( $url, 1 );
181
182 // Check if headers were retrieved successfully
183 if ( ! is_array( $headers ) || ! isset( $headers[0] ) ) {
184 return false;
185 }
186
187 // If 200 is found, the user has a Gravatar; otherwise, they don't.
188 return preg_match( '|200|', $headers[0] ) ? true : false;
189 }
190
191 /**
192 * Before assembling avatar HTML.
193 *
194 * @param $url
195 * @param $id_or_email
196 * @param $args
197 *
198 * @return bool
199 */
200 function wpmtst_get_avatar( $url, $id_or_email, $args ) {
201 if ( 'if' === WPMST()->atts( 'gravatar' ) && ! wpmtst_has_gravatar( $id_or_email ) ) {
202 return false;
203 }
204
205 return $url;
206 }
207
208
209 function wpmtst_thumbnail_img_platform( $img, $post_id, $size ) {
210
211 $platform = get_post_meta( $post_id, 'platform', true );
212 if ( ! $platform ) {
213 return $img;
214 }
215
216 $img = apply_filters( 'wpmtst_thumbnail_img_platform_' . $platform, $img, $post_id, $size );
217
218 return $img;
219 }
220 add_filter( 'wpmtst_thumbnail_img', 'wpmtst_thumbnail_img_platform', 10, 3 );
221
222
223 function wpmtst_thumbnail_img_platform_general( $img, $post_id, $size ) {
224
225 $platform_user_photo = get_post_meta( $post_id, 'platform_user_photo', true );
226 if ( ! $platform_user_photo || ! wpmtst_is_valid_image_url( $platform_user_photo ) ) {
227 return $img;
228 }
229
230 //calculate width & height based on size
231 if ( is_array( $size ) ) {
232 $width = $size[0];
233 $height = $size[1];
234 } else {
235 $sizes = wpmtst_get_image_sizes( $size );
236 $width = $sizes['width'];
237 $height = $sizes['height'];
238 }
239
240 return sprintf( '<img src="%s" %s %s/>', $platform_user_photo, $width ? "width='{$width}'" : '', $height ? "height='{$height}'" : '' );
241 }
242 add_filter( 'wpmtst_thumbnail_img_platform_facebook', 'wpmtst_thumbnail_img_platform_general', 10, 3 );
243 add_filter( 'wpmtst_thumbnail_img_platform_google', 'wpmtst_thumbnail_img_platform_general', 10, 3 );
244 add_filter( 'wpmtst_thumbnail_img_platform_yelp', 'wpmtst_thumbnail_img_platform_general', 10, 3 );
245 add_filter( 'wpmtst_thumbnail_img_platform_zomato', 'wpmtst_thumbnail_img_platform_general', 10, 3 );
246
247
248 function wpmtst_thumbnail_img_platform_woocommerce( $img, $post_id, $size ) {
249
250 $options = get_option( 'wpmtst_importer_options' );
251 if ( '' === $options['email_field'] ) {
252 return $img;
253 }
254
255 $email = get_post_meta( $post_id, $options['email_field'], true );
256 if ( ! $email ) {
257 return $img;
258 }
259
260 //calculate width & height based on size
261 if ( is_array( $size ) ) {
262 $width = $size[0];
263 $height = $size[1];
264 } else {
265 $sizes = wpmtst_get_image_sizes( $size );
266 $width = $sizes['width'];
267 $height = $sizes['height'];
268 }
269
270 return sprintf( '<img src="%s" %s %s/>', get_avatar_url( $email ), $width ? "width='{$width}'" : '', $height ? "height='{$height}'" : '' );
271 }
272 add_filter( 'wpmtst_thumbnail_img_platform_woocommerce', 'wpmtst_thumbnail_img_platform_woocommerce', 10, 3 );
273
274 function wpmtst_is_valid_image_url( $url ) {
275 $headers = get_headers( $url, 1 );
276
277 if ( false === $headers ) {
278 return false;
279 }
280
281 if ( isset( $headers[0] ) && strpos( $headers[0], '200 OK' ) !== false ) {
282 return true;
283 }
284
285 return false;
286 }
287