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.php
889 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Functions |
| 4 | */ |
| 5 | |
| 6 | function wpmtst_support_url() { |
| 7 | return esc_url( '#' ); |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Return default translation from po/mo files if no active translation plugin. |
| 12 | * |
| 13 | * @since 2.23.2 |
| 14 | * @param $string |
| 15 | * |
| 16 | * @return string |
| 17 | */ |
| 18 | function wpmtst_l10n_default( $l10n_string ) { |
| 19 | return $l10n_string; |
| 20 | } |
| 21 | add_filter( 'wpmtst_l10n', 'wpmtst_l10n_default' ); |
| 22 | |
| 23 | /** |
| 24 | * Append custom fields to post object. |
| 25 | * Add thumbnail if included in field group. |
| 26 | * |
| 27 | * @param $post |
| 28 | * |
| 29 | * @return mixed |
| 30 | */ |
| 31 | function wpmtst_get_post( $post ) { |
| 32 | $custom = get_post_custom( $post->ID ); |
| 33 | $fields = wpmtst_get_custom_fields(); |
| 34 | |
| 35 | foreach ( $fields as $key => $field ) { |
| 36 | $name = $field['name']; |
| 37 | |
| 38 | if ( 'featured_image' === $name ) { |
| 39 | $post->thumbnail_id = get_post_thumbnail_id( $post->ID ); |
| 40 | } else { |
| 41 | if ( isset( $custom[ $name ] ) ) { |
| 42 | $post->$name = $custom[ $name ][0]; |
| 43 | } else { |
| 44 | $post->$name = ''; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return $post; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Helper: Format URL |
| 54 | * |
| 55 | * @param $url |
| 56 | * @return string |
| 57 | */ |
| 58 | function wpmtst_get_website( $url ) { |
| 59 | if ( ! preg_match( '~^(?:f|ht)tps?://~i', $url ) ) { |
| 60 | $url = 'https://' . $url; |
| 61 | } |
| 62 | |
| 63 | return $url; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Check whether a common script is already registered by file name |
| 68 | * instead of handle. |
| 69 | * |
| 70 | * === Used in older versions to check for Cycle script. === |
| 71 | * |
| 72 | * Why? Plugins are loaded before themes. Our plugin includes the Cycle |
| 73 | * slider. Some themes include it too. We only want to load it once. |
| 74 | * |
| 75 | * Load jQuery Cycle plugin (http://jquery.malsup.com/cycle/) only if |
| 76 | * any version of Cycle is not already registered by a theme or another |
| 77 | * plugin. Both versions of Cycle use same function name so we can't load |
| 78 | * both but either version will work for our purposes. |
| 79 | * http://jquery.malsup.com/cycle2/faq/ |
| 80 | * |
| 81 | * The WordPress function `wp_script_is` checks by *handle* within a plugin |
| 82 | * or theme but handles can be different so it misses it. |
| 83 | * wp_script_is( 'jquery-cycle', 'registered' ) |
| 84 | * http://codex.wordpress.org/Function_Reference/wp_script_is |
| 85 | * |
| 86 | * Jetpack's slideshow shortcode simply enqueues its own version of Cycle |
| 87 | * without registering first if and when the shortcode is rendered. No way |
| 88 | * to check for that. It does not seem to create a conflict now. (1.16) |
| 89 | * |
| 90 | * @param array $filenames possible versions of one script, |
| 91 | * e.g. plugin.js, plugin-min.js, plugin-1.2.js |
| 92 | * @return string |
| 93 | */ |
| 94 | function wpmtst_is_registered( $filenames ) { |
| 95 | global $wp_scripts; |
| 96 | |
| 97 | // Bail if called too early. |
| 98 | if ( ! $wp_scripts ) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | $script_handle = ''; |
| 103 | |
| 104 | foreach ( $wp_scripts->registered as $handle => $script ) { |
| 105 | if ( in_array( basename( $script->src ), $filenames, true ) ) { |
| 106 | $script_handle = $handle; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return $script_handle; |
| 112 | } |
| 113 | |
| 114 | if ( ! function_exists( 'get_page_by_slug' ) ) { |
| 115 | /** |
| 116 | * Get page ID by slug. |
| 117 | * |
| 118 | * Thanks http://wordpress.stackexchange.com/a/102845/32076 |
| 119 | * Does not require parent slug. |
| 120 | * |
| 121 | * @since 1.11.0 |
| 122 | */ |
| 123 | function get_page_by_slug( $page_slug, $output = OBJECT, $post_type = 'page' ) { |
| 124 | global $wpdb; |
| 125 | $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) ); |
| 126 | if ( $page ) { |
| 127 | return get_post( $page, $output ); |
| 128 | } else { |
| 129 | return null; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Reverse auto-p wrap shortcodes that stand alone |
| 136 | * |
| 137 | * @since 1.11.0 |
| 138 | */ |
| 139 | if ( ! function_exists( 'reverse_wpautop' ) ) { |
| 140 | function reverse_wpautop( $s ) { |
| 141 | // remove any new lines already in there |
| 142 | $s = str_replace( "\n", '', $s ); |
| 143 | |
| 144 | // remove all <p> |
| 145 | $s = str_replace( '<p>', '', $s ); |
| 146 | |
| 147 | // remove <br> |
| 148 | $s = str_replace( array( '<br />', '<br/>', '<br>' ), '', $s ); |
| 149 | |
| 150 | // remove </p> |
| 151 | $s = str_replace( '</p>', '', $s ); |
| 152 | |
| 153 | return $s; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Sort array based on 'order' element. |
| 159 | * |
| 160 | * @since 1.13 |
| 161 | */ |
| 162 | function wpmtst_uasort( $a, $b ) { |
| 163 | if ( $a['order'] === $b['order'] ) { |
| 164 | return 0; |
| 165 | } |
| 166 | return ( $a['order'] < $b['order'] ) ? -1 : 1; |
| 167 | } |
| 168 | |
| 169 | function wpmtst_get_custom_form_count() { |
| 170 | $forms = get_option( 'wpmtst_custom_forms' ); |
| 171 | return count( $forms ); |
| 172 | } |
| 173 | |
| 174 | function wpmtst_get_form_fields( $form_id = 1 ) { |
| 175 | $forms = get_option( 'wpmtst_custom_forms' ); |
| 176 | |
| 177 | if ( ! Strong_Testimonials_Extensions_Base::get_instance()->extension_enabled( 'strong-testimonials-multiple-forms' ) ) { |
| 178 | $form_id = 1; |
| 179 | } |
| 180 | |
| 181 | if ( isset( $forms[ $form_id ] ) ) { |
| 182 | $form = $forms[ $form_id ]; |
| 183 | } elseif ( isset( $forms[1] ) ) { |
| 184 | $form = $forms[1]; |
| 185 | } else { |
| 186 | $form = reset( $forms ); |
| 187 | } |
| 188 | |
| 189 | $fields = $form['fields']; |
| 190 | |
| 191 | return $fields; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Get only custom fields from all field groups. |
| 196 | * |
| 197 | * Used in post editor. |
| 198 | * |
| 199 | * @return array |
| 200 | */ |
| 201 | function wpmtst_get_custom_fields() { |
| 202 | $all_fields = array(); |
| 203 | $forms = get_option( 'wpmtst_custom_forms' ); |
| 204 | |
| 205 | if ( ! $forms ) { |
| 206 | return $all_fields; |
| 207 | } |
| 208 | // merge remaining form fields. |
| 209 | foreach ( $forms as $form ) { |
| 210 | |
| 211 | $custom_fields = array(); |
| 212 | if ( isset( $form['fields'] ) ) { |
| 213 | $fields = $form['fields']; |
| 214 | foreach ( $fields as $field ) { |
| 215 | if ( 'post' !== $field['record_type'] ) { |
| 216 | $custom_fields[ $field['name'] ] = $field; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | $all_fields = array_merge( $all_fields, $custom_fields ); |
| 221 | } |
| 222 | |
| 223 | return $all_fields; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Get all fields from all field groups. |
| 228 | * |
| 229 | * Used for admin list columns. |
| 230 | * |
| 231 | * @return array |
| 232 | */ |
| 233 | function wpmtst_get_all_fields() { |
| 234 | $forms = get_option( 'wpmtst_custom_forms' ); |
| 235 | $all_fields = array(); |
| 236 | |
| 237 | /** |
| 238 | * Use first custom form as the base because if we use 'default' |
| 239 | * and a field has 'admin_table' enabled in 'default' |
| 240 | * but not in any custom form, the column will still be shown. |
| 241 | */ |
| 242 | $key = array_key_exists( 1, $forms ) ? 1 : array_key_first( $forms ); |
| 243 | $fields = $forms[ $key ]['fields']; |
| 244 | |
| 245 | // replace key with field name |
| 246 | foreach ( $fields as $field ) { |
| 247 | $all_fields[ $field['name'] ] = $field; |
| 248 | } |
| 249 | |
| 250 | // merge remaining form fields |
| 251 | foreach ( $forms as $form ) { |
| 252 | $custom_fields = array(); |
| 253 | $fields = $form['fields']; |
| 254 | foreach ( $fields as $field ) { |
| 255 | $custom_fields[ $field['name'] ] = $field; |
| 256 | } |
| 257 | $all_fields = array_merge( $all_fields, $custom_fields ); |
| 258 | } |
| 259 | |
| 260 | return $all_fields; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Get all rating fields |
| 265 | * |
| 266 | * @return array |
| 267 | */ |
| 268 | function wpmtst_get_all_rating_fields() { |
| 269 | |
| 270 | $all_fields = wpmtst_get_all_fields(); |
| 271 | |
| 272 | $rating_fields = array(); |
| 273 | |
| 274 | foreach ( $all_fields as $key => $field ) : |
| 275 | if ( 'rating' !== $field['input_type'] ) { |
| 276 | continue; |
| 277 | } |
| 278 | $rating_fields[] = $field; |
| 279 | endforeach; |
| 280 | |
| 281 | return $rating_fields; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Get the built-in fields. |
| 286 | * |
| 287 | * @since 2.29.0 |
| 288 | */ |
| 289 | function wpmtst_get_builtin_fields() { |
| 290 | $builtin_fields = array( |
| 291 | 'post_date' => array( |
| 292 | 'name' => 'post_date', |
| 293 | 'label' => 'Post Date', |
| 294 | 'input_type' => 'date', |
| 295 | 'type' => 'date', |
| 296 | 'record_type' => 'builtin', |
| 297 | ), |
| 298 | 'submit_date' => array( |
| 299 | 'name' => 'submit_date', |
| 300 | 'label' => 'Submit Date', |
| 301 | 'input_type' => 'date', |
| 302 | 'type' => 'date', |
| 303 | 'record_type' => 'builtin', |
| 304 | ), |
| 305 | 'category' => array( |
| 306 | 'name' => 'category', |
| 307 | 'label' => 'Category', |
| 308 | 'input_type' => 'category', |
| 309 | 'type' => 'category', |
| 310 | 'record_type' => 'builtin', |
| 311 | ), |
| 312 | ); |
| 313 | |
| 314 | $options = get_option( 'wpmtst_options' ); |
| 315 | if ( isset( $options['include_platform'] ) && true === $options['include_platform'] ) { |
| 316 | $builtin_fields[] = array( |
| 317 | 'name' => 'platform', |
| 318 | 'label' => 'Platform', |
| 319 | 'input_type' => 'platform', |
| 320 | 'type' => 'platform', |
| 321 | 'record_type' => 'builtin', |
| 322 | ); |
| 323 | } |
| 324 | |
| 325 | return $builtin_fields; |
| 326 | } |
| 327 | |
| 328 | function wpmtst_get_image_sizes( $size = '' ) { |
| 329 | |
| 330 | global $_wp_additional_image_sizes; |
| 331 | |
| 332 | $sizes = array(); |
| 333 | $get_intermediate_image_sizes = get_intermediate_image_sizes(); |
| 334 | |
| 335 | /** |
| 336 | * Catch possibility of missing standard sizes. |
| 337 | * @since 2.2.5 |
| 338 | */ |
| 339 | if ( $get_intermediate_image_sizes ) { |
| 340 | // Create the full array with sizes and crop info |
| 341 | foreach ( $get_intermediate_image_sizes as $_size ) { |
| 342 | |
| 343 | if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ), true ) ) { |
| 344 | |
| 345 | $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' ); |
| 346 | $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' ); |
| 347 | $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' ); |
| 348 | } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { |
| 349 | |
| 350 | $sizes[ $_size ] = array( |
| 351 | 'width' => $_wp_additional_image_sizes[ $_size ]['width'], |
| 352 | 'height' => $_wp_additional_image_sizes[ $_size ]['height'], |
| 353 | 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'], |
| 354 | ); |
| 355 | |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // Sort by width |
| 360 | uasort( $sizes, 'wpmtst_compare_width' ); |
| 361 | |
| 362 | // Add option labels |
| 363 | foreach ( $sizes as $key => $dimensions ) { |
| 364 | $sizes[ $key ]['label'] = sprintf( '%s - %d x %d', $key, $dimensions['width'], $dimensions['height'] ); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | // Add extra options |
| 369 | $sizes['full'] = array( |
| 370 | 'label' => 'original size uploaded', |
| 371 | 'width' => 0, |
| 372 | 'height' => 0, |
| 373 | ); |
| 374 | $sizes['custom'] = array( |
| 375 | 'label' => 'custom size', |
| 376 | 'width' => 0, |
| 377 | 'height' => 0, |
| 378 | ); |
| 379 | |
| 380 | // Get only one size if found |
| 381 | if ( $size ) { |
| 382 | if ( isset( $sizes[ $size ] ) ) { |
| 383 | return $sizes[ $size ]; |
| 384 | } else { |
| 385 | return false; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return $sizes; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * @param $a |
| 394 | * @param $b |
| 395 | * |
| 396 | * @return int |
| 397 | */ |
| 398 | function wpmtst_compare_width( $a, $b ) { |
| 399 | if ( $a['width'] === $b['width'] ) { |
| 400 | return 0; |
| 401 | } |
| 402 | return ( $a['width'] < $b['width'] ) ? -1 : 1; |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * @return int |
| 407 | */ |
| 408 | function wpmtst_get_cat_count() { |
| 409 | return count( get_terms( 'wpm-testimonial-category', array( 'hide_empty' => false ) ) ); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Return a list of categories after removing any orderby filters. |
| 414 | * |
| 415 | * @since 2.2.3 If WPML is active, will find corresponding term ID in current language. |
| 416 | * |
| 417 | * @param int $cat_parent |
| 418 | * |
| 419 | * @return array|int|WP_Error |
| 420 | */ |
| 421 | function wpmtst_get_cats( $cat_parent = 0 ) { |
| 422 | return get_terms( |
| 423 | 'wpm-testimonial-category', |
| 424 | array( |
| 425 | 'hide_empty' => false, |
| 426 | 'parent' => $cat_parent, |
| 427 | ) |
| 428 | ); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * @param $value |
| 433 | * @param int $cat_parent |
| 434 | * @param int $level |
| 435 | */ |
| 436 | function wpmtst_nested_cats( $value, $cat_parent = 0, $level = 0 ) { |
| 437 | $cats = wpmtst_get_cats( $cat_parent ); |
| 438 | if ( $cats ) { |
| 439 | foreach ( $cats as $cat ) { |
| 440 | $selected = in_array( $cat->term_id, $value, true ) ? ' selected' : ''; |
| 441 | printf( '<option value="%s"%s>%s%s</option>', esc_attr( $cat->term_id ), esc_attr( $selected ), esc_html( str_repeat( ' ', $level ) ), esc_html( $cat->name ) ); |
| 442 | wpmtst_nested_cats( $value, $cat->term_id, $level + 1 ); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | function wpmtst_sort_array_by_name( $a, $b ) { |
| 448 | if ( $a['name'] === $b['name'] ) { |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | return ( $a['name'] < $b['name'] ) ? -1 : 1; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Allow disabling of client-side form validation via filter. |
| 457 | * |
| 458 | * @since 1.21.0 |
| 459 | * @deprecated since 2.18.1 |
| 460 | */ |
| 461 | function wpmtst_using_form_validation_script() { |
| 462 | return true; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Set iframe width of embedded videos. |
| 467 | * |
| 468 | * @since 2.6.0 |
| 469 | * @param $dimensions |
| 470 | * @param $url |
| 471 | * |
| 472 | * @return array |
| 473 | */ |
| 474 | function wpmtst_embed_size( $dimensions, $url ) { |
| 475 | $options = get_option( 'wpmtst_options' ); |
| 476 | $width = (int) $options['embed_width']; |
| 477 | if ( $width ) { |
| 478 | $dimensions = array( |
| 479 | 'width' => $width, |
| 480 | 'height' => min( ceil( $width * 1.5 ), 1000 ), |
| 481 | ); |
| 482 | } |
| 483 | |
| 484 | return $dimensions; |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Allow empty posts. |
| 489 | * |
| 490 | * @since 2.6.0 |
| 491 | * @param $maybe_empty |
| 492 | * @param $postarr |
| 493 | * |
| 494 | * @return bool |
| 495 | */ |
| 496 | function wpmtst_insert_post_empty_content( $maybe_empty, $postarr ) { |
| 497 | if ( 'wpm-testimonial' === $postarr['post_type'] ) { |
| 498 | return false; |
| 499 | } |
| 500 | |
| 501 | return $maybe_empty; |
| 502 | } |
| 503 | add_filter( 'wp_insert_post_empty_content', 'wpmtst_insert_post_empty_content', 10, 2 ); |
| 504 | |
| 505 | /** |
| 506 | * Display submit_date in Publish meta box under Published date. |
| 507 | * |
| 508 | * @param $post @since WordPress 4.4 |
| 509 | * @since 2.12.0 |
| 510 | */ |
| 511 | function wpmtst_post_submitbox_misc_actions( $post ) { |
| 512 | if ( ! $post ) { |
| 513 | global $post; |
| 514 | } |
| 515 | |
| 516 | if ( 'wpm-testimonial' === $post->post_type ) { |
| 517 | echo '<div class="wpmtst-pub-section">'; |
| 518 | echo '<span id="submit-timestamp"> '; |
| 519 | $submit_date = get_post_meta( $post->ID, 'submit_date', true ); |
| 520 | if ( $submit_date ) { |
| 521 | echo 'Submitted on: <strong>' . wp_kses_post( date_i18n( 'M j, Y @ H:i', strtotime( $submit_date ) ) ) . '</strong>'; |
| 522 | } else { |
| 523 | esc_html_e( 'No submit date', 'strong-testimonials' ); |
| 524 | } |
| 525 | echo '</span>'; |
| 526 | echo '</div>'; |
| 527 | } |
| 528 | } |
| 529 | add_action( 'post_submitbox_misc_actions', 'wpmtst_post_submitbox_misc_actions' ); |
| 530 | |
| 531 | /** |
| 532 | * @return mixed |
| 533 | */ |
| 534 | function wpmtst_get_background_defaults() { |
| 535 | return apply_filters( |
| 536 | 'wpmtst_default_template_background', |
| 537 | array( |
| 538 | 'color' => '', |
| 539 | 'type' => '', |
| 540 | 'preset' => '', |
| 541 | 'gradient1' => '', |
| 542 | 'gradient2' => '', |
| 543 | ) |
| 544 | ); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * @param null $preset |
| 549 | * |
| 550 | * TODO Move to options and add a filter. |
| 551 | * @return array|bool |
| 552 | */ |
| 553 | function wpmtst_get_background_presets( $preset = null ) { |
| 554 | $presets = array( |
| 555 | 'light-blue-gradient' => array( |
| 556 | 'label' => esc_html__( 'light blue gradient', 'strong-testimonials' ), |
| 557 | 'color' => '#E7EFFE', |
| 558 | 'color2' => '#B8CFFB', |
| 559 | ), |
| 560 | 'light-gray-gradient' => array( |
| 561 | 'label' => esc_html__( 'light gray gradient', 'strong-testimonials' ), |
| 562 | 'color' => '#FBFBFB', |
| 563 | 'color2' => '#EDEDED', |
| 564 | ), |
| 565 | 'light-green-mist-gradient' => array( |
| 566 | 'label' => esc_html__( 'light green mist gradient', 'strong-testimonials' ), |
| 567 | 'color' => '#F2FBE9', |
| 568 | 'color2' => '#E0F7CC', |
| 569 | ), |
| 570 | 'light-latte-gradient' => array( |
| 571 | 'label' => esc_html__( 'light latte gradient', 'strong-testimonials' ), |
| 572 | 'color' => '#F8F3EC', |
| 573 | 'color2' => '#E0C8AB', |
| 574 | ), |
| 575 | 'light-plum-gradient' => array( |
| 576 | 'label' => esc_html__( 'light plum gradient', 'strong-testimonials' ), |
| 577 | 'color' => '#F7EEF7', |
| 578 | 'color2' => '#E9D0E9', |
| 579 | ), |
| 580 | 'sky-blue-gradient' => array( |
| 581 | 'label' => esc_html__( 'sky blue gradient', 'strong-testimonials' ), |
| 582 | 'color' => '#E9F6FB', |
| 583 | 'color2' => '#C8E9F6', |
| 584 | ), |
| 585 | ); |
| 586 | |
| 587 | if ( $preset ) { |
| 588 | if ( isset( $presets[ $preset ] ) ) { |
| 589 | return $presets[ $preset ]; |
| 590 | } else { |
| 591 | return wpmtst_get_background_defaults(); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | return $presets; |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * Return the form success message. |
| 600 | * |
| 601 | * @since 2.18.0 |
| 602 | * |
| 603 | * @return mixed |
| 604 | */ |
| 605 | function wpmtst_get_success_message( $atts = false ) { |
| 606 | $message = wpautop( do_shortcode( wpmtst_get_form_message( 'submission-success' ) ) ); |
| 607 | $message = sprintf( '<div class="%s">%s</div>', 'wpmtst-testimonial-success', $message ); |
| 608 | |
| 609 | return apply_filters( 'wpmtst_form_success_message', $message, $atts ); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Does callback exist? |
| 614 | * |
| 615 | * @param $callback |
| 616 | * @since 2.18.0 |
| 617 | * |
| 618 | * @return bool |
| 619 | */ |
| 620 | // TODO Move to Utils class |
| 621 | function wpmtst_callback_exists( $callback ) { |
| 622 | if ( is_array( $callback ) ) { |
| 623 | $exists = method_exists( $callback[0], $callback[1] ); |
| 624 | } else { |
| 625 | $exists = function_exists( $callback ); |
| 626 | } |
| 627 | |
| 628 | return $exists; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Check for Divi Builder plugin. |
| 633 | * |
| 634 | * Its plugin version constant is inaccurate so get the version from the file header. |
| 635 | * |
| 636 | * @since 2.22.0 |
| 637 | * |
| 638 | * @return bool |
| 639 | */ |
| 640 | function wpmtst_divi_builder_active() { |
| 641 | $active = false; |
| 642 | if ( wpmtst_is_plugin_active( 'divi-builder/divi-builder.php' ) ) { |
| 643 | $plugin = get_file_data( WP_PLUGIN_DIR . '/divi-builder/divi-builder.php', array( 'version' => 'Version' ) ); |
| 644 | if ( isset( $plugin['version'] ) && version_compare( $plugin['version'], '2' ) > 0 ) { |
| 645 | $active = true; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | return $active; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Append custom fields to testimonial content in theme's single post template. |
| 654 | * |
| 655 | * @param $content |
| 656 | * @since 2.22.0 |
| 657 | * |
| 658 | * @return string |
| 659 | */ |
| 660 | function wpmtst_single_template_add_content( $content ) { |
| 661 | if ( is_singular( 'wpm-testimonial' ) || is_tax( 'wpm-testimonial-category' ) ) { |
| 662 | $content .= wpmtst_single_template_client(); |
| 663 | } |
| 664 | |
| 665 | return $content; |
| 666 | } |
| 667 | add_filter( 'the_content', 'wpmtst_single_template_add_content' ); |
| 668 | |
| 669 | /** |
| 670 | * Frequent plugin checks. |
| 671 | * |
| 672 | * A combination of an array of frequent plugin names, and core's is_plugin_active functions |
| 673 | * which are not available in front-end without loading plugin.php which is uncecessary. |
| 674 | * |
| 675 | * @param $plugin |
| 676 | * |
| 677 | * @return bool |
| 678 | */ |
| 679 | function wpmtst_is_plugin_active( $plugin = '' ) { |
| 680 | if ( ! $plugin ) { |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | $plugins = array( |
| 685 | 'wpml' => 'sitepress-multilingual-cms/sitepress.php', |
| 686 | 'polylang' => 'polylang/polylang.php', |
| 687 | 'lazy-loading-responsive-images' => 'lazy-loading-responsive-images/lazy-load-responsive-images.php', |
| 688 | ); |
| 689 | if ( isset( $plugins[ $plugin ] ) ) { |
| 690 | $plugin = $plugins[ $plugin ]; |
| 691 | } |
| 692 | |
| 693 | if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ) { |
| 694 | return true; |
| 695 | } |
| 696 | |
| 697 | if ( ! is_multisite() ) { |
| 698 | return false; |
| 699 | } |
| 700 | |
| 701 | $plugins = get_site_option( 'active_sitewide_plugins' ); |
| 702 | if ( isset( $plugins[ $plugin ] ) ) { |
| 703 | return true; |
| 704 | } |
| 705 | |
| 706 | return false; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Sanitize a textarea from user input. Based on sanitize_text_field. |
| 711 | * |
| 712 | * Check for invalid UTF-8, |
| 713 | * Convert single < characters to entity, |
| 714 | * strip all tags, |
| 715 | * strip octets. |
| 716 | * |
| 717 | * @since 2.11.8 |
| 718 | * |
| 719 | * @param string $text |
| 720 | * |
| 721 | * @return string |
| 722 | */ |
| 723 | function wpmtst_sanitize_textarea( $text ) { |
| 724 | $filtered = wp_check_invalid_utf8( $text ); |
| 725 | |
| 726 | if ( strpos( $filtered, '<' ) !== false ) { |
| 727 | $filtered = wp_pre_kses_less_than( $filtered ); |
| 728 | // This will NOT strip extra whitespace. |
| 729 | $filtered = wp_strip_all_tags( $filtered, false ); |
| 730 | } |
| 731 | |
| 732 | while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) { |
| 733 | $filtered = str_replace( $match[0], '', $filtered ); |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Filter a sanitized textarea string. |
| 738 | * |
| 739 | * @param string $filtered The sanitized string. |
| 740 | * @param string $str The string prior to being sanitized. |
| 741 | */ |
| 742 | return apply_filters( 'wpmtst_sanitize_textarea', $filtered, $text ); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Store values as 1 or 0 (never blank). |
| 747 | * |
| 748 | * Checked checkbox value is "on" but unchecked checkboxes are _not_ submitted. |
| 749 | * |
| 750 | * @param $input |
| 751 | * @param $key string Must be explicit. Do not simply loop through an input array. |
| 752 | * |
| 753 | * @return int |
| 754 | */ |
| 755 | function wpmtst_sanitize_checkbox( $input, $key ) { |
| 756 | if ( isset( $input[ $key ] ) ) { |
| 757 | if ( 'on' === $input[ $key ] ) { // checked checkbox |
| 758 | return true; |
| 759 | } else { // hidden input |
| 760 | return $input[ $key ] ? true : false; // 0 or 1 |
| 761 | } |
| 762 | } else { // unchecked checkbox |
| 763 | return false; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Trims a entire array recursively. |
| 769 | * |
| 770 | * @since 2.26.6 |
| 771 | * |
| 772 | * @props Jonas John |
| 773 | * @version 0.2 |
| 774 | * @link http://www.jonasjohn.de/snippets/php/trim-array.htm |
| 775 | * @param $input array|string |
| 776 | * |
| 777 | * @return array|string |
| 778 | */ |
| 779 | function wpmtst_trim_array( $input ) { |
| 780 | if ( ! is_array( $input ) ) { |
| 781 | return trim( $input ); |
| 782 | } |
| 783 | |
| 784 | return array_map( 'wpmtst_trim_array', $input ); |
| 785 | } |
| 786 | |
| 787 | if ( ! function_exists( 'normalize_empty_atts' ) ) { |
| 788 | /** |
| 789 | * Normalize empty shortcode attributes. |
| 790 | * |
| 791 | * Turns atts into tags - brilliant! |
| 792 | * Thanks http://wordpress.stackexchange.com/a/123073/32076 |
| 793 | * |
| 794 | * @param $atts |
| 795 | * |
| 796 | * @return mixed |
| 797 | */ |
| 798 | function normalize_empty_atts( $atts ) { |
| 799 | if ( ! empty( $atts ) ) { |
| 800 | foreach ( $atts as $attribute => $value ) { |
| 801 | if ( is_int( $attribute ) ) { |
| 802 | $atts[ strtolower( $value ) ] = true; |
| 803 | unset( $atts[ $attribute ] ); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return $atts; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | // @todo : check in addons to see if function is called somewhere, else delete it |
| 813 | if ( ! function_exists( 'wpmtst_round_to_half' ) ) { |
| 814 | /** |
| 815 | * Round to the nearest half. |
| 816 | * |
| 817 | * @param $value |
| 818 | * |
| 819 | * @since 2.31.0 |
| 820 | * @return float|int |
| 821 | */ |
| 822 | function wpmtst_round_to_half( $value ) { |
| 823 | if ( is_string( $value ) ) { |
| 824 | $value = (float) str_replace( ',', '.', $value ); |
| 825 | } |
| 826 | return round( (float) $value * 2 ) / 2; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | |
| 831 | if ( ! function_exists( 'wpmtst_strip_whitespace' ) ) { |
| 832 | /** |
| 833 | * Remove whitespace from HTML output. |
| 834 | * |
| 835 | * @param $html |
| 836 | * |
| 837 | * @return string |
| 838 | */ |
| 839 | function wpmtst_strip_whitespace( $html ) { |
| 840 | return preg_replace( '~>\s+<~', '><', trim( $html ) ); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if ( ! function_exists( 'wpmtst_current_url' ) ) { |
| 845 | /** |
| 846 | * Assemble and return the current URL. |
| 847 | * |
| 848 | * @since 2.31.0 |
| 849 | * @return string |
| 850 | */ |
| 851 | function wpmtst_current_url() { |
| 852 | global $wp; |
| 853 | |
| 854 | return home_url( add_query_arg( array(), $wp->request ) ); |
| 855 | } |
| 856 | } |
| 857 | if ( ! function_exists( 'get_formatted_views' ) ) { |
| 858 | |
| 859 | function get_formatted_views() { |
| 860 | $views = wpmtst_get_views(); |
| 861 | |
| 862 | $view_array = array( 'none' => esc_html__( 'None', 'strong-testimonials' ) ); |
| 863 | foreach ( $views as $view ) { |
| 864 | $view_array[ $view['id'] ] = esc_html( $view['name'] ); |
| 865 | } |
| 866 | return $view_array; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Get stars svg |
| 872 | * |
| 873 | * @return string |
| 874 | * @since 3.1.9 |
| 875 | */ |
| 876 | function wpmtst_get_star_svg( $type = 'star_solid' ) { |
| 877 | $star = array(); |
| 878 | |
| 879 | $star['star_solid'] = '<svg class="star_solid" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"></path></svg>'; |
| 880 | $star['star_regular'] = '<svg class="star_regular" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M528.1 171.5L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6zM388.6 312.3l23.7 138.4L288 385.4l-124.3 65.3 23.7-138.4-100.6-98 139-20.2 62.2-126 62.2 126 139 20.2-100.6 98z"></path></svg>'; |
| 881 | $star['star_half'] = '<svg class="star_half" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M508.55 171.51L362.18 150.2 296.77 17.81C290.89 5.98 279.42 0 267.95 0c-11.4 0-22.79 5.9-28.69 17.81l-65.43 132.38-146.38 21.29c-26.25 3.8-36.77 36.09-17.74 54.59l105.89 103-25.06 145.48C86.98 495.33 103.57 512 122.15 512c4.93 0 10-1.17 14.87-3.75l130.95-68.68 130.94 68.7c4.86 2.55 9.92 3.71 14.83 3.71 18.6 0 35.22-16.61 31.66-37.4l-25.03-145.49 105.91-102.98c19.04-18.5 8.52-50.8-17.73-54.6zm-121.74 123.2l-18.12 17.62 4.28 24.88 19.52 113.45-102.13-53.59-22.38-11.74.03-317.19 51.03 103.29 11.18 22.63 25.01 3.64 114.23 16.63-82.65 80.38z"></path></svg>'; |
| 882 | |
| 883 | if ( isset( $star[ $type ] ) ) { |
| 884 | return $star[ $type ]; |
| 885 | } |
| 886 | |
| 887 | return ''; |
| 888 | } |
| 889 |