elementor
1 year ago
logs
1 month ago
strong-testimonials-beaver-block
1 year ago
submodules
8 months 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-defaults.php
1 month ago
class-strong-testimonials-form.php
1 month ago
class-strong-testimonials-order.php
1 year ago
class-strong-testimonials-privacy.php
1 year ago
class-strong-testimonials-render.php
1 month ago
class-strong-testimonials-templates.php
1 year ago
class-strong-testimonials-view-shortcode.php
2 days ago
class-strong-testimonials-view-widget.php
1 year ago
class-strong-view-display.php
1 month ago
class-strong-view-form.php
2 days ago
class-strong-view-slideshow.php
1 month ago
class-strong-view.php
11 months ago
class-walker-strong-category-checklist-front.php
1 year ago
deprecated.php
1 year ago
filters.php
1 month ago
functions-activation.php
1 month ago
functions-content.php
11 months ago
functions-image.php
5 months ago
functions-rating.php
1 year ago
functions-template-form.php
2 days ago
functions-template.php
4 months ago
functions-views.php
1 year ago
functions.php
1 month ago
l10n-polylang.php
1 year ago
l10n-wpml.php
1 year ago
post-types.php
2 days ago
retro.php
1 year ago
scripts.php
1 month ago
functions-template.php
721 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template Functions |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * Template function for showing a View. |
| 8 | * |
| 9 | * @since 1.25.0 |
| 10 | * |
| 11 | * @param null $id |
| 12 | */ |
| 13 | function strong_testimonials_view( $id = null ) { |
| 14 | if ( ! $id ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | $out = array(); |
| 19 | $pairs = array(); |
| 20 | $atts = array( 'id' => $id ); |
| 21 | $out = WPMST()->render->prerender( $atts ); |
| 22 | $out = WPMST()->render->parse_view( $out, $pairs, $atts ); |
| 23 | |
| 24 | echo WPMST()->shortcode->render_view( $out ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Print the current post title with optional markup. |
| 29 | * |
| 30 | * @since 2.26.0 Add optional link to post. |
| 31 | * |
| 32 | * @param string $before |
| 33 | * @param string $after |
| 34 | */ |
| 35 | |
| 36 | function wpmtst_the_title( $tag = '', $wrapper_class = '' ) { |
| 37 | $title = get_the_title(); |
| 38 | $options = get_option( 'wpmtst_options' ); |
| 39 | |
| 40 | $tag = apply_filters( 'wpmtst_the_title_tag', $tag ); |
| 41 | if ( ! empty( $tag ) ) { |
| 42 | $before = '<' . $tag . ' class="' . $wrapper_class . '">'; |
| 43 | $after = '</' . $tag . '>'; |
| 44 | } |
| 45 | if ( WPMST()->atts( 'title' ) && $title ) { |
| 46 | if ( 'none' !== WPMST()->atts( 'title_link' ) && '0' !== WPMST()->atts( 'title_link' ) ) { |
| 47 | if ( ( ! isset( $options['disable_rewrite'] ) || false === $options['disable_rewrite'] ) && ( 'wpmtst_testimonial' === WPMST()->atts( 'title_link' ) || '1' === WPMST()->atts( 'title_link' ) ) ) { |
| 48 | $before .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">'; |
| 49 | $after = '</a>' . $after; |
| 50 | } else { |
| 51 | $id = get_the_ID(); |
| 52 | $url_field = WPMST()->atts( 'title_link' ); |
| 53 | $external_url = get_post_meta( $id, $url_field, true ); |
| 54 | |
| 55 | if ( '' !== $external_url && ! is_array( $external_url ) ) { |
| 56 | $before .= '<a href="' . esc_url( $external_url ) . '" rel="bookmark" target="_blank">'; |
| 57 | $after = '</a>' . $after; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | $before = apply_filters( 'wpmtst_the_title_before', $before ); |
| 63 | $after = apply_filters( 'wpmtst_the_title_after', $after ); |
| 64 | |
| 65 | if ( WPMST()->atts( 'title' ) !== 'hidden' ) { |
| 66 | the_title( $before, $after ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Display the testimonial content. |
| 72 | * |
| 73 | * @since 1.24.0 |
| 74 | * |
| 75 | * @since 2.4.0 Run content through core WordPress filters only, instead of all filters |
| 76 | * added to the_excerpt() or the_content() in order to to be compatible with |
| 77 | * NextGEN Gallery and to prevent other plugins from unconditionally adding |
| 78 | * content like share buttons, etc. |
| 79 | * |
| 80 | * @since 2.11.5 Run specific filters on `wpmtst_the_content` hook. |
| 81 | * |
| 82 | * @since 2.20.0 For automatic excerpts, run `wpautop` after truncating. |
| 83 | * Add `wp_make_content_images_responsive`. |
| 84 | * |
| 85 | * @since 2.26.0 Using content filters instead of direct function calls. |
| 86 | * Using custom get_*() functions to allow filter selectivity. |
| 87 | */ |
| 88 | function wpmtst_the_content() { |
| 89 | /** |
| 90 | * Use this hook to remove specific content filters. |
| 91 | * |
| 92 | * @since 2.26.0 |
| 93 | */ |
| 94 | do_action( 'wpmtst_before_content_filters' ); |
| 95 | |
| 96 | echo apply_filters( 'wpmtst_get_the_content', '' ); |
| 97 | |
| 98 | /** |
| 99 | * Restore content filters that were removed. |
| 100 | * |
| 101 | * @since 2.26.0 |
| 102 | */ |
| 103 | do_action( 'wpmtst_after_content_filters' ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Like the_excerpt(). |
| 108 | * |
| 109 | * @since 2.33.0 |
| 110 | */ |
| 111 | function wpmtst_the_excerpt() { |
| 112 | echo wpmtst_the_excerpt_filtered(); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * The ellipsis on read-more's. |
| 117 | * |
| 118 | * @since 2.33.0 |
| 119 | */ |
| 120 | function wpmtst_ellipsis() { |
| 121 | if ( apply_filters( 'wpmtst_use_ellipsis', true ) ) { |
| 122 | return apply_filters( 'wpmtst_ellipsis', __( '…', 'strong-testimonials' ) ); |
| 123 | } |
| 124 | |
| 125 | return ''; |
| 126 | } |
| 127 | |
| 128 | function wpmtst_prepend_ellipsis( $more ) { |
| 129 | return wpmtst_ellipsis() . ' ' . $more; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Assemble link to secondary "Read more" page. |
| 134 | * |
| 135 | * @since 2.10.0 |
| 136 | */ |
| 137 | function wpmtst_read_more_page() { |
| 138 | $atts = WPMST()->atts(); |
| 139 | |
| 140 | if ( $atts['more_page'] && $atts['more_page_id'] ) { |
| 141 | $permalink = ''; |
| 142 | if ( is_numeric( $atts['more_page_id'] ) ) { |
| 143 | $permalink = wpmtst_get_permalink( $atts['more_page_id'] ); |
| 144 | } |
| 145 | $permalink = apply_filters( 'wpmtst_readmore_page_link', $permalink, $atts ); |
| 146 | |
| 147 | if ( $permalink ) { |
| 148 | $default_view = wpmtst_get_view_default(); |
| 149 | |
| 150 | if ( isset( $atts['more_page_text'] ) && $atts['more_page_text'] ) { |
| 151 | $link_text = $atts['more_page_text']; |
| 152 | } else { |
| 153 | $link_text = $default_view['more_page_text']; |
| 154 | } |
| 155 | |
| 156 | $link_text = apply_filters( 'wpmtst_read_more_page_link_text', $link_text, $atts ); |
| 157 | |
| 158 | if ( 'wpmtst_after_testimonial' === $atts['more_page_hook'] ) { |
| 159 | $classname = 'readmore'; |
| 160 | } else { |
| 161 | $classname = 'readmore-page'; |
| 162 | } |
| 163 | $classname = apply_filters( 'wpmtst_read_more_page_class', $classname ); |
| 164 | echo apply_filters( 'wpmtst_read_more_page_output', sprintf( '<div class="%s"><a href="%s">%s</a></div>', esc_attr( $classname ), esc_url( $permalink ), wp_kses_post( $link_text ) ) ); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * L10n filter on read-more-page link. |
| 171 | * |
| 172 | * @since 2.23.0 As separate function. |
| 173 | * |
| 174 | * @param $text |
| 175 | * @param $atts |
| 176 | * |
| 177 | * @return string |
| 178 | */ |
| 179 | function wpmtst_read_more_page_link_text_l10n( $text, $atts ) { |
| 180 | return apply_filters( |
| 181 | 'wpmtst_l10n', |
| 182 | $text, |
| 183 | 'strong-testimonials-read-more', |
| 184 | sprintf( 'View %s : Read more (page or post)', $atts['view'] ) |
| 185 | ); |
| 186 | } |
| 187 | add_filter( 'wpmtst_read_more_page_link_text', 'wpmtst_read_more_page_link_text_l10n', 10, 2 ); |
| 188 | |
| 189 | /** |
| 190 | * L10n filter on read-more-post link. |
| 191 | * |
| 192 | * @since 2.29.0 |
| 193 | * |
| 194 | * @param $text |
| 195 | * @param $atts |
| 196 | * |
| 197 | * @return string |
| 198 | */ |
| 199 | function wpmtst_read_more_post_link_text_l10n( $text, $atts ) { |
| 200 | return apply_filters( |
| 201 | 'wpmtst_l10n', |
| 202 | $text, |
| 203 | 'strong-testimonials-read-more', |
| 204 | sprintf( 'View %s : Read more (testimonial)', $atts['view'] ) |
| 205 | ); |
| 206 | } |
| 207 | add_filter( 'wpmtst_read_more_post_link_text', 'wpmtst_read_more_post_link_text_l10n', 10, 2 ); |
| 208 | |
| 209 | /** |
| 210 | * Get permalink by ID or slug. |
| 211 | * |
| 212 | * @since 1.25.0 |
| 213 | * |
| 214 | * @param $page_id |
| 215 | * |
| 216 | * @return false|string |
| 217 | */ |
| 218 | function wpmtst_get_permalink( $page_id ) { |
| 219 | if ( ! is_numeric( $page_id ) ) { |
| 220 | $page = get_page_by_path( $page_id ); |
| 221 | $page_id = $page->ID; |
| 222 | } |
| 223 | |
| 224 | return get_permalink( $page_id ); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Prevent page scroll when clicking the More link. |
| 229 | * |
| 230 | * @since 2.10.0 |
| 231 | * |
| 232 | * @param $link |
| 233 | * |
| 234 | * @return mixed |
| 235 | */ |
| 236 | function wpmtst_remove_more_link_scroll( $link ) { |
| 237 | if ( 'wpm-testimonial' === get_post_type() ) { |
| 238 | $link = preg_replace( '|#more-[0-9]+|', '', $link ); |
| 239 | } |
| 240 | |
| 241 | return $link; |
| 242 | } |
| 243 | add_filter( 'the_content_more_link', 'wpmtst_remove_more_link_scroll' ); |
| 244 | |
| 245 | /** |
| 246 | * Display the thumbnail. |
| 247 | * |
| 248 | * TODO WP 4.2+ has better filters. |
| 249 | * |
| 250 | * @param null $size |
| 251 | * @param string $before |
| 252 | * @param string $after |
| 253 | */ |
| 254 | function wpmtst_the_thumbnail( $size = null, $before = '<div class="wpmtst-testimonial-image testimonial-image">', $after = '</div>' ) { |
| 255 | if ( ! WPMST()->atts( 'thumbnail' ) ) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | $img = wpmtst_get_thumbnail( $size ); |
| 260 | if ( $img ) { |
| 261 | echo $before . $img . $after; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Print the date. |
| 267 | * |
| 268 | * @param string $format |
| 269 | * @param string $wrapper_class |
| 270 | */ |
| 271 | function wpmtst_the_date( $format = '', $wrapper_class = '' ) { |
| 272 | global $post; |
| 273 | if ( ! $post ) { |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | if ( ! $format ) { |
| 278 | $format = get_option( 'date_format' ); |
| 279 | } |
| 280 | |
| 281 | $the_date = apply_filters( 'wpmtst_the_date', mysql2date( $format, $post->post_date ), $format, $post ); |
| 282 | echo '<div class="' . esc_attr( $wrapper_class ) . '">' . esc_attr( $the_date ) . '</div>'; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Display the client section. |
| 287 | * |
| 288 | * @since 1.21.0 |
| 289 | */ |
| 290 | function wpmtst_the_client() { |
| 291 | $atts = WPMST()->atts(); |
| 292 | if ( isset( $atts['client_section'] ) ) { |
| 293 | echo wpmtst_client_section( $atts['client_section'] ); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Assemble the client section. |
| 299 | * |
| 300 | * @since 1.21.0 |
| 301 | * |
| 302 | * @param array $client_section An array of client fields. |
| 303 | * |
| 304 | * @return mixed |
| 305 | */ |
| 306 | function wpmtst_client_section( $client_section ) { |
| 307 | |
| 308 | $html = ''; |
| 309 | |
| 310 | foreach ( $client_section as $field ) { |
| 311 | $html .= wpmtst_the_custom_field( $field ); |
| 312 | } |
| 313 | |
| 314 | return $html; |
| 315 | } |
| 316 | |
| 317 | function wpmtst_the_custom_field( $field ) { |
| 318 | global $post; |
| 319 | |
| 320 | $options = get_option( 'wpmtst_options' ); |
| 321 | $custom_fields = wpmtst_get_custom_fields(); |
| 322 | |
| 323 | $output = ''; |
| 324 | $field_name = $field['field']; |
| 325 | |
| 326 | if ( isset( $custom_fields[ $field_name ] ) ) { |
| 327 | $field['prop'] = $custom_fields[ $field_name ]; |
| 328 | } else { |
| 329 | $field['prop'] = array(); |
| 330 | } |
| 331 | |
| 332 | // Check for callback first. |
| 333 | if ( isset( $field['prop']['action_output'] ) && $field['prop']['action_output'] ) { |
| 334 | $value = get_post_meta( $post->ID, $field_name, true ); |
| 335 | $output = apply_filters( $field['prop']['action_output'], $field, $value ); |
| 336 | } elseif ( has_filter( 'wpmtst_output_' . $field_name ) ) { |
| 337 | $value = get_post_meta( $post->ID, $field_name, true ); |
| 338 | $output = apply_filters( 'wpmtst_output_' . $field_name, $field, $value ); |
| 339 | } else { |
| 340 | switch ( $field['type'] ) { |
| 341 | case 'link': |
| 342 | case 'link2': |
| 343 | // use default if missing |
| 344 | if ( ! isset( $field['link_text'] ) ) { |
| 345 | $field['link_text'] = 'value'; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Get link text and an alternate in case the URL is empty; |
| 350 | * e.g. display the domain if no company name given |
| 351 | * but don't display 'LinkedIn' if no URL given. |
| 352 | */ |
| 353 | switch ( $field['link_text'] ) { |
| 354 | case 'custom': |
| 355 | $text = $field['link_text_custom']; |
| 356 | $output = ''; |
| 357 | break; |
| 358 | case 'label': |
| 359 | $text = $field['prop']['label']; |
| 360 | $output = ''; |
| 361 | break; |
| 362 | default: // value |
| 363 | $text = get_post_meta( $post->ID, $field_name, true ); |
| 364 | // if no URL (next condition), show the alternate (the field) |
| 365 | $output = $text; |
| 366 | } |
| 367 | |
| 368 | if ( $field['url'] ) { |
| 369 | $url = get_post_meta( $post->ID, $field['url'], true ); |
| 370 | if ( $url ) { |
| 371 | if ( isset( $field['new_tab'] ) && $field['new_tab'] ) { |
| 372 | $newtab = ' target="_blank"'; |
| 373 | } else { |
| 374 | $newtab = ''; |
| 375 | } |
| 376 | |
| 377 | // TODO Abstract this global fallback technique. |
| 378 | $is_nofollow = get_post_meta( $post->ID, 'nofollow', true ); |
| 379 | if ( 'default' === $is_nofollow || '' === $is_nofollow ) { |
| 380 | // convert default to (yes|no) |
| 381 | $is_nofollow = $options['nofollow'] ? 'yes' : 'no'; |
| 382 | } |
| 383 | if ( 'yes' === $is_nofollow ) { |
| 384 | $nofollow = 'nofollow'; |
| 385 | } else { |
| 386 | $nofollow = ''; |
| 387 | } |
| 388 | |
| 389 | $is_noopener = get_post_meta( $post->ID, 'noopener', true ); |
| 390 | if ( 'default' === $is_noopener || '' === $is_noopener ) { |
| 391 | // convert default to (yes|no) |
| 392 | $is_noopener = $options['noopener'] ? 'yes' : 'no'; |
| 393 | } |
| 394 | if ( 'yes' === $is_noopener ) { |
| 395 | $noopener = 'noopener'; |
| 396 | } else { |
| 397 | $noopener = ''; |
| 398 | } |
| 399 | |
| 400 | $is_noreferrer = get_post_meta( $post->ID, 'noreferrer', true ); |
| 401 | if ( 'default' === $is_noreferrer || '' === $is_noreferrer ) { |
| 402 | // convert default to (yes|no) |
| 403 | $is_noreferrer = $options['noreferrer'] ? 'yes' : 'no'; |
| 404 | } |
| 405 | if ( 'yes' === $is_noreferrer ) { |
| 406 | $noreferrer = 'noreferrer'; |
| 407 | } else { |
| 408 | $noreferrer = ''; |
| 409 | } |
| 410 | |
| 411 | if ( ! empty( $noopener ) || ! empty( $nofollow ) || ! empty( $noreferrer ) ) { |
| 412 | $rel = sprintf( ' rel="%s %s %s"', esc_attr( $nofollow ), esc_attr( $noopener ), esc_attr( $noreferrer ) ); |
| 413 | } else { |
| 414 | $rel = ''; |
| 415 | } |
| 416 | |
| 417 | // if field empty, use domain instead |
| 418 | if ( ! $text || is_array( $text ) ) { |
| 419 | $text = preg_replace( '(^https?://)', '', $url ); |
| 420 | } |
| 421 | $output = sprintf( '<a href="%s"%s%s>%s</a>', esc_url( $url ), $newtab, $rel, wp_kses_post( $text ) ); |
| 422 | } |
| 423 | } |
| 424 | break; |
| 425 | |
| 426 | case 'date': |
| 427 | $format = isset( $field['format'] ) && $field['format'] ? $field['format'] : get_option( 'date_format' ); |
| 428 | |
| 429 | // Fall back to post_date if submit_date missing. |
| 430 | $the_date = get_post_meta( $post->ID, $field_name, true ); |
| 431 | $the_date = $the_date ? $the_date : $post->post_date; |
| 432 | $the_date = mysql2date( $format, $the_date ); |
| 433 | |
| 434 | if ( get_option( 'date_format' ) !== $format ) { |
| 435 | // Requires PHP 5.3+ |
| 436 | if ( version_compare( PHP_VERSION, '5.3' ) >= 0 ) { |
| 437 | $new_date = DateTime::createFromFormat( get_option( 'date_format' ), $the_date ); |
| 438 | if ( $new_date ) { |
| 439 | $the_date = $new_date->format( $format ); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | $output = apply_filters( 'wpmtst_the_date', $the_date, $format, $post ); |
| 445 | break; |
| 446 | |
| 447 | case 'category': |
| 448 | // 1. Get all terms for testimonial |
| 449 | $categories = get_the_terms( $post->ID, 'wpm-testimonial-category' ); |
| 450 | // 2, Check for errors |
| 451 | if ( $categories && ! is_wp_error( $categories ) ) { |
| 452 | $list = array(); |
| 453 | // 3. Check if should display parent cats, child cats, or both. |
| 454 | if ( isset( $field['category_show'] ) && 'both' !== $field['category_show'] ) { |
| 455 | if ( 'parent' === $field['category_show'] ) { |
| 456 | foreach ( $categories as $cat ) { |
| 457 | // 3.1 Include only categories that don't have parents |
| 458 | if ( 0 === $cat->parent ) { |
| 459 | $list[] = $cat->name; |
| 460 | } |
| 461 | } |
| 462 | $output = implode( ', ', $list ); |
| 463 | } elseif ( 'child' === $field['category_show'] ) { |
| 464 | foreach ( $categories as $cat ) { |
| 465 | // 3.2 Include only categories that have parents |
| 466 | if ( 0 !== $cat->parent ) { |
| 467 | $list[] = $cat->name; |
| 468 | } |
| 469 | } |
| 470 | $output = implode( ', ', $list ); |
| 471 | } |
| 472 | } else { |
| 473 | foreach ( $categories as $cat ) { |
| 474 | // 3.3 Include all categories |
| 475 | $list[] = $cat->name; |
| 476 | } |
| 477 | $output = implode( ', ', $list ); |
| 478 | } |
| 479 | } else { |
| 480 | $output = ''; |
| 481 | } |
| 482 | break; |
| 483 | |
| 484 | case 'shortcode': |
| 485 | if ( isset( $field['prop']['shortcode_on_display'] ) && $field['prop']['shortcode_on_display'] ) { |
| 486 | $output = do_shortcode( $field['prop']['shortcode_on_display'] ); |
| 487 | } |
| 488 | break; |
| 489 | |
| 490 | case 'rating': |
| 491 | $output = get_post_meta( $post->ID, $field_name, true ); |
| 492 | // Check default value |
| 493 | if ( '' === $output && isset( $field['prop']['default_display_value'] ) && $field['prop']['default_display_value'] ) { |
| 494 | $output = $field['prop']['default_display_value']; |
| 495 | } |
| 496 | // Convert number to stars |
| 497 | if ( $output ) { |
| 498 | $output = wpmtst_star_rating_display( $output, 'in-view', false ); |
| 499 | } |
| 500 | break; |
| 501 | |
| 502 | case 'platform': |
| 503 | $platform = get_post_meta( $post->ID, $field_name, true ); |
| 504 | |
| 505 | if ( $platform ) { |
| 506 | $output = wpmtst_platform_display( $platform ); |
| 507 | } |
| 508 | |
| 509 | break; |
| 510 | |
| 511 | case 'checkbox': |
| 512 | // we output the checkbox value from view |
| 513 | $output = ''; |
| 514 | if ( isset( $field['custom_label'] ) && ! empty( $field['custom_label'] ) ) { |
| 515 | $output = sprintf( '%s: ', esc_attr( $field['custom_label'] ) ); |
| 516 | } |
| 517 | if ( get_post_meta( $post->ID, $field_name, true ) ) { |
| 518 | $output .= esc_attr( $field['checked_value_custom'] ); |
| 519 | } else { |
| 520 | $output .= esc_attr( $field['unchecked_value'] ); |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | default: |
| 525 | // text field |
| 526 | $output = get_post_meta( $post->ID, $field_name, true ); |
| 527 | $output = wp_kses_post( $output ); |
| 528 | if ( '' === $output && isset( $field['prop']['default_display_value'] ) && $field['prop']['default_display_value'] ) { |
| 529 | $output = $field['prop']['default_display_value']; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | if ( is_array( $output ) ) { |
| 535 | return ''; |
| 536 | } |
| 537 | |
| 538 | if ( $output ) { |
| 539 | if ( isset( $field['before'] ) && $field['before'] ) { |
| 540 | $output = '<span class="wpmtst-testimonial-field-before testimonial-field-before">' . $field['before'] . '</span>' . $output; |
| 541 | } |
| 542 | $output = '<div class="wpmtst-testimonial-field testimonial-field ' . esc_attr( $field['class'] ) . '">' . $output . '</div>'; |
| 543 | } |
| 544 | |
| 545 | return $output; |
| 546 | } |
| 547 | |
| 548 | function wpmtst_container_class() { |
| 549 | echo esc_attr( apply_filters( 'wpmtst_container_class', WPMST()->atts( 'container_class' ) ) ); |
| 550 | } |
| 551 | |
| 552 | function wpmtst_container_data() { |
| 553 | $data_array = apply_filters( 'wpmtst_container_data', WPMST()->atts( 'container_data' ) ); |
| 554 | if ( $data_array && is_array( $data_array ) ) { |
| 555 | $parts = array(); |
| 556 | foreach ( $data_array as $attr => $value ) { |
| 557 | $attr = sanitize_key( $attr ); |
| 558 | $value = esc_attr( (string) $value ); |
| 559 | $parts[] = sprintf( ' data-%s="%s"', $attr, $value ); |
| 560 | } |
| 561 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Each part built from sanitize_key and esc_attr. |
| 562 | echo implode( '', $parts ); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | function wpmtst_content_class() { |
| 567 | echo esc_attr( apply_filters( 'wpmtst_content_class', WPMST()->atts( 'content_class' ) ) ); |
| 568 | } |
| 569 | |
| 570 | function wpmtst_post_class( $args = null ) { |
| 571 | echo esc_attr( apply_filters( 'wpmtst_post_class', WPMST()->atts( 'post_class' ) . ' post-' . get_the_ID(), $args ) ); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Echo custom field. |
| 576 | * |
| 577 | * @since 1.11.0 |
| 578 | * |
| 579 | * @param null $field |
| 580 | * @param array $args |
| 581 | */ |
| 582 | function wpmtst_field( $field = null, $args = array() ) { |
| 583 | echo wpmtst_get_field( $field, $args ); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Fetch custom field. |
| 588 | * |
| 589 | * Thanks to Matthew Harris. |
| 590 | * |
| 591 | * @link https://github.com/cdillon/strong-testimonials/issues/2 |
| 592 | * |
| 593 | * @param $field |
| 594 | * @param array $args |
| 595 | * |
| 596 | * @since 1.15.7 |
| 597 | * |
| 598 | * @return mixed|string |
| 599 | */ |
| 600 | function wpmtst_get_field( $field, $args = array() ) { |
| 601 | if ( ! $field ) { |
| 602 | return ''; |
| 603 | } |
| 604 | |
| 605 | global $post; |
| 606 | |
| 607 | switch ( $field ) { |
| 608 | |
| 609 | // Apply a character limit to post content. |
| 610 | case 'truncated': |
| 611 | $html = wpmtst_truncate( $post->post_content, $args['char_limit'] ); |
| 612 | break; |
| 613 | |
| 614 | // Get the custom field. |
| 615 | default: |
| 616 | $html = get_post_meta( $post->ID, $field, true ); |
| 617 | } |
| 618 | |
| 619 | return $html; |
| 620 | } |
| 621 | |
| 622 | if ( ! function_exists( 'wpmtst_standard_pagination' ) ) : |
| 623 | /** |
| 624 | * Custom pagination. Pluggable. |
| 625 | * |
| 626 | * Thanks http://callmenick.com/post/custom-wordpress-loop-with-pagination |
| 627 | */ |
| 628 | function wpmtst_standard_pagination() { |
| 629 | $query = WPMST()->get_query(); |
| 630 | $numpages = $query->max_num_pages ? $query->max_num_pages : 1; |
| 631 | $paged = wpmtst_get_paged(); |
| 632 | $options = WPMST()->atts( 'pagination_settings' ); |
| 633 | |
| 634 | $pagination_args = array( |
| 635 | // Required |
| 636 | 'total' => $numpages, |
| 637 | 'current' => $paged, |
| 638 | // Options |
| 639 | 'show_all' => isset( $options['show_all'] ) ? $options['show_all'] : false, |
| 640 | 'end_size' => isset( $options['end_size'] ) ? $options['end_size'] : 1, |
| 641 | 'mid_size' => isset( $options['mid_size'] ) ? $options['mid_size'] : 2, |
| 642 | 'prev_next' => isset( $options['prev_next'] ) ? $options['prev_next'] : true, |
| 643 | 'prev_text' => isset( $options['prev_text'] ) ? $options['prev_text'] : __( '« Previous', 'strong-testimonials' ), |
| 644 | 'next_text' => isset( $options['next_text'] ) ? $options['next_text'] : __( 'Next »', 'strong-testimonials' ), |
| 645 | 'before_page_number' => isset( $options['before_page_number'] ) ? $options['before_page_number'] : '', |
| 646 | 'after_page_number' => isset( $options['after_page_number'] ) ? $options['after_page_number'] : '', |
| 647 | ); |
| 648 | |
| 649 | $paginate_links = paginate_links( apply_filters( 'wpmtst_pagination_args', $pagination_args ) ); |
| 650 | |
| 651 | if ( $paginate_links ) { |
| 652 | echo "<nav class='nav-links'>"; |
| 653 | echo $paginate_links; |
| 654 | echo '</nav>'; |
| 655 | } |
| 656 | } |
| 657 | endif; |
| 658 | |
| 659 | /** |
| 660 | * If paged, return the current page number. |
| 661 | * |
| 662 | * @return int|mixed |
| 663 | */ |
| 664 | function wpmtst_get_paged() { |
| 665 | if ( is_front_page() ) { |
| 666 | return get_query_var( 'page' ) ? intval( get_query_var( 'page' ) ) : 1; |
| 667 | } |
| 668 | return get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | // alternate pagination style |
| 673 | function wpmtst_new_pagination_2() { |
| 674 | $query = WPMST()->get_query(); |
| 675 | if ($query->max_num_pages > 1) { ?> |
| 676 | <nav class="prev-next-posts"> |
| 677 | <div class="prev-posts-link"> |
| 678 | <?php echo get_next_posts_link( 'Older Entries', $query->max_num_pages ); // display older posts link ?> |
| 679 | </div> |
| 680 | <div class="next-posts-link"> |
| 681 | <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?> |
| 682 | </div> |
| 683 | </nav> |
| 684 | <?php } |
| 685 | } |
| 686 | */ |
| 687 | |
| 688 | if ( ! function_exists( 'wpmtst_single_template_client' ) ) : |
| 689 | /** |
| 690 | * Single testimonial custom fields. Pluggable. |
| 691 | * |
| 692 | * @since 2.22.0 |
| 693 | */ |
| 694 | function wpmtst_single_template_client() { |
| 695 | $html = ''; |
| 696 | $view = wpmtst_find_single_template_view(); |
| 697 | if ( $view && isset( $view['client_section'] ) ) { |
| 698 | foreach ( $view['client_section'] as $field ) { |
| 699 | if ( 'rating' === $field['type'] ) { |
| 700 | wp_enqueue_style( 'wpmtst-rating-display' ); |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | $html .= '<div class="testimonial-client normal">'; |
| 706 | $html .= wpmtst_client_section( $view['client_section'] ); |
| 707 | $html .= '</div>'; |
| 708 | } |
| 709 | |
| 710 | return $html; |
| 711 | } |
| 712 | endif; |
| 713 | |
| 714 | function wpmtst_platform_display( $platform ) { |
| 715 | ob_start(); |
| 716 | ?> |
| 717 | <img title="<?php echo esc_attr( __( 'posted on ', 'strong-testimonials' ) . $platform ); ?>" width="20" height="20" src="<?php echo esc_attr( WPMTST_ASSETS_IMG ); ?>/platform_icons/<?php echo esc_attr( $platform ); ?>.svg"/> |
| 718 | <?php |
| 719 | return ob_get_clean(); |
| 720 | } |
| 721 |