PluginProbe
Powerkit – Supercharge your WordPress Site / 2.4.4
Powerkit – Supercharge your WordPress Site v2.4.4
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / core / core-powerkit-helpers.php

core-powerkit-helpers.php in Powerkit – Supercharge your WordPress Site 2.4.4, at core/core-powerkit-helpers.php

831 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The basic helpers functions
4 *
5 * @package Powerkit
6 * @subpackage Core
7 * @version 1.0.0
8 * @since 1.0.0
9 */
10
11 /**
12 * Output error message.
13 *
14 * @param string $message The error message.
15 */
16 function powerkit_alert_warning( $message ) {
17 if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
18 ?>
19 <p class="pk-alert pk-alert-warning" role="alert">
20 <object>
21 <?php call_user_func( 'printf', '%s', $message ); ?>
22 </object>
23
24 <?php esc_html_e( ' Don’t worry, this error is visible to site admins only, and your site visitors won’t see it.', 'powerkit' ); ?>
25 </p>
26 <?php
27 }
28 }
29
30 /**
31 * Processing path of style.
32 *
33 * @param string $path URL to the stylesheet.
34 */
35 function powerkit_style( $path ) {
36 // Check RTL.
37 if ( is_rtl() ) {
38 return $path;
39 }
40
41 // Check Dev.
42 $dev = POWERKIT_PATH . 'assets/css/powerkit-dev.css';
43
44 if ( file_exists( $dev ) ) {
45 return str_replace( '.css', '-dev.css', $path );
46 }
47
48 return $path;
49 }
50
51 /**
52 * Check post views module.
53 *
54 * @return string Type.
55 */
56 function powerkit_post_views_enabled() {
57
58 // Post Views Counter.
59 if ( class_exists( 'Post_Views_Counter' ) ) {
60 return 'post_views';
61 }
62
63 // Powerkit Post Views.
64 if ( powerkit_module_enabled( 'post_views' ) ) {
65 return 'pk_post_views';
66 }
67 }
68
69 /**
70 * Process shortcode atts.
71 *
72 * @param array $atts Attributes in shortcode tag.
73 */
74 function powerkit_shortcode_atts( $atts ) {
75 if ( is_array( $atts ) ) {
76 foreach ( $atts as $name => $val ) {
77 if ( is_string( $val ) && 'true' === $val ) {
78 $atts[ $name ] = true;
79 }
80 if ( is_string( $val ) && 'false' === $val ) {
81 $atts[ $name ] = false;
82 }
83 }
84 }
85 return $atts;
86 }
87
88 /**
89 * Retrieves a post meta field for the given post ID.
90 *
91 * @param int $post_id Post ID.
92 * @param string $key Optional. The meta key to retrieve. By default, returns
93 * data for all keys. Default empty.
94 * @param bool $single Optional. If true, returns only the first value for the specified meta key.
95 * This parameter has no effect if $key is not specified. Default false.
96 * @param mixed $default Default value.
97 * @return mixed Will be an array if $single is false. Will be value of the meta
98 * field if $single is true.
99 */
100 function powerkit_get_post_metadata( $post_id, $key = '', $single = false, $default = null ) {
101
102 if ( ! metadata_exists( 'post', $post_id, $key ) && $default ) {
103 return $default;
104 }
105
106 return get_metadata( 'post', $post_id, $key, $single );
107 }
108
109 /**
110 * Get locale in uniform format.
111 */
112 function powerkit_get_locale() {
113
114 $locale = get_locale();
115
116 if ( preg_match( '#^[a-z]{2}\-[A-Z]{2}$#', $locale ) ) {
117 $locale = str_replace( '-', '_', $locale );
118 } elseif ( preg_match( '#^[a-z]{2}$#', $locale ) ) {
119 if ( function_exists( 'mb_strtoupper' ) ) {
120 $locale .= '_' . mb_strtoupper( $locale, 'UTF-8' );
121 } else {
122 $locale .= '_' . mb_strtoupper( $locale );
123 }
124 }
125
126 if ( empty( $locale ) ) {
127 $locale = 'en_US';
128 }
129
130 return apply_filters( 'powerkit_locale', $locale );
131 }
132
133 /**
134 * Get rounded number.
135 *
136 * @param int $number Input number.
137 * @param int $min_value Minimum value to round number.
138 * @param int $decimal How may decimals shall be in the rounded number.
139 */
140 function powerkit_get_round_number( $number, $min_value = 1000, $decimal = 1 ) {
141 if ( $number < $min_value ) {
142 return number_format_i18n( $number );
143 }
144 $alphabets = array(
145 1000000000 => esc_html__( 'B', 'powerkit' ),
146 1000000 => esc_html__( 'M', 'powerkit' ),
147 1000 => esc_html__( 'K', 'powerkit' ),
148 );
149 foreach ( $alphabets as $key => $value ) {
150 if ( $number >= $key ) {
151 return number_format_i18n( round( $number / $key, $decimal ), $decimal ) . $value;
152 }
153 }
154 }
155
156 /**
157 * Convert dates to readable format
158 *
159 * @param string $a Time string (timeformat).
160 * @return string Formatted time.
161 */
162 function powerkit_relative_time( $a ) {
163
164 // Get current timestampt.
165 $b = strtotime( 'now' );
166
167 // Get timestamp when tweet created.
168 $c = strtotime( $a );
169
170 // Get difference.
171 $d = $b - $c;
172
173 // Calculate different time values.
174 $minute = 60;
175 $hour = $minute * 60;
176 $day = $hour * 24;
177 $week = $day * 7;
178
179 if ( is_numeric( $d ) && $d > 0 ) :
180
181 // If less then 3 seconds.
182 if ( $d < 3 ) {
183 return esc_html__( 'right now', 'powerkit' );
184 }
185
186 // If less then minute.
187 if ( $d < $minute ) {
188 return floor( $d ) . esc_html__( ' seconds ago', 'powerkit' );
189 }
190
191 // If less then 2 minutes.
192 if ( $d < $minute * 2 ) {
193 return esc_html__( 'about 1 minute ago', 'powerkit' );
194 }
195
196 // If less then hour.
197 if ( $d < $hour ) {
198 return floor( $d / $minute ) . esc_html__( ' minutes ago', 'powerkit' );
199 }
200
201 // If less then 2 hours.
202 if ( $d < $hour * 2 ) {
203 return esc_html__( 'about 1 hour ago', 'powerkit' );
204 }
205
206 // If less then day.
207 if ( $d < $day ) {
208 return floor( $d / $hour ) . esc_html__( ' hours ago', 'powerkit' );
209 }
210
211 // If more then day, but less then 2 days.
212 if ( $d > $day && $d < $day * 2 ) {
213 return esc_html__( 'yesterday', 'powerkit' );
214 }
215
216 // If less then year.
217 if ( $d < $day * 365 ) {
218 return floor( $d / $day ) . esc_html__( ' days ago', 'powerkit' );
219 }
220
221 // else return more than a year.
222 return esc_html__( 'over a year ago', 'powerkit' );
223 endif;
224 }
225
226 /**
227 * Truncates string with specified length
228 *
229 * @param string $string Text string.
230 * @param int $length Letters length.
231 * @param string $etc End truncate.
232 * @param bool $break_words Break words or not.
233 * @return string
234 */
235 function powerkit_str_truncate( $string, $length = 80, $etc = '&hellip;', $break_words = false ) {
236 if ( 0 === $length ) {
237 return '';
238 }
239
240 if ( function_exists( 'mb_strlen' ) ) {
241
242 // MultiBite string functions.
243 if ( mb_strlen( $string ) > $length ) {
244 $length -= min( $length, mb_strlen( $etc ) );
245 if ( ! $break_words ) {
246 $string = preg_replace( '/\s+?(\S+)?$/', '', mb_substr( $string, 0, $length + 1 ) );
247 }
248
249 return mb_substr( $string, 0, $length ) . $etc;
250 }
251 } else {
252
253 // Default string functions.
254 if ( strlen( $string ) > $length ) {
255 $length -= min( $length, strlen( $etc ) );
256 if ( ! $break_words ) {
257 $string = preg_replace( '/\s+?(\S+)?$/', '', substr( $string, 0, $length + 1 ) );
258 }
259
260 return substr( $string, 0, $length ) . $etc;
261 }
262 }
263
264 return $string;
265 }
266
267 /**
268 * Set number to Short Form
269 *
270 * @param int $n The number.
271 * @param int $decimal The decimal.
272 */
273 function powerkit_abridged_number( $n, $decimal = 1 ) {
274
275 // First strip any formatting.
276 $n = (float) str_replace( ',', '', $n );
277
278 // Is this a number?
279 if ( ! is_numeric( $n ) ) {
280 return false;
281 }
282
283 // Return current count.
284 if ( $n < 1000 ) {
285 return number_format_i18n( $n );
286 }
287
288 // Add suffix.
289 $suffix = array(
290 1000000000 => esc_html__( 'B', 'powerkit' ), // Billion.
291 1000000 => esc_html__( 'M', 'powerkit' ), // Million.
292 1000 => esc_html__( 'K', 'powerkit' ), // Thousand.
293 );
294 foreach ( $suffix as $k => $v ) {
295 if ( $n >= $k ) {
296 return number_format_i18n( $n / $k, $decimal ) . $v;
297 }
298 }
299 }
300
301 /**
302 * Time ago
303 *
304 * @param string $time The time.
305 * @return string
306 */
307 function powerkit_timing_ago( $time ) {
308 $periods = array( esc_html__( 'second', 'powerkit' ), esc_html__( 'minute', 'powerkit' ), esc_html__( 'hour', 'powerkit' ), esc_html__( 'day', 'powerkit' ), esc_html__( 'week', 'powerkit' ), esc_html__( 'month', 'powerkit' ), esc_html__( 'year', 'powerkit' ), esc_html__( 'decade', 'powerkit' ) );
309 $lengths = array( '60', '60', '24', '7', '4.35', '12', '10' );
310
311 $now = time();
312
313 $difference = $now - $time;
314 $tense = esc_html__( 'ago', 'powerkit' );
315
316 $lengths_count = count( $lengths );
317
318 for ( $j = 0; $difference >= $lengths[ $j ] && $j < $lengths_count - 1; $j++ ) {
319 $difference /= $lengths[ $j ];
320 }
321
322 $difference = round( $difference );
323
324 if ( 1 !== $difference ) {
325 $periods[ $j ] .= 's';
326 }
327
328 return "$difference $periods[$j] {$tense} ";
329 }
330
331 /**
332 * Encode data
333 *
334 * @param mixed $content The content.
335 * @param string $secret_key The key.
336 * @return string
337 */
338 function powerkit_encode_data( $content, $secret_key = 'powerkit' ) {
339
340 $content = wp_json_encode( $content );
341
342 return base64_encode( $content );
343 }
344
345 /**
346 * Decode data
347 *
348 * @param string $content The content.
349 * @param string $secret_key The key.
350 * @return string
351 */
352 function powerkit_decode_data( $content, $secret_key = 'powerkit' ) {
353
354 $content = base64_decode( $content );
355
356 return json_decode( $content );
357 }
358
359 /**
360 * Encrypt data
361 *
362 * @param mixed $content The content.
363 * @param string $secret_key The key.
364 * @return string
365 */
366 function powerkit_encrypt_data( $content, $secret_key = 'powerkit' ) {
367
368 $content = maybe_serialize( $content );
369
370 if ( function_exists( 'openssl_encrypt' ) && function_exists( 'hash' ) ) {
371 $encrypt_method = 'AES-256-CBC';
372
373 $key = hash( 'sha256', $secret_key );
374 $iv = substr( hash( 'sha256', 'secret key' ), 0, 16 );
375
376 return base64_encode( openssl_encrypt( $content, $encrypt_method, $key, 0, $iv ) );
377 } else {
378 return base64_encode( $content );
379 }
380 }
381
382 /**
383 * Decrypt data
384 *
385 * @param string $content The content.
386 * @param string $secret_key The key.
387 * @return string
388 */
389 function powerkit_decrypt_data( $content, $secret_key = 'powerkit' ) {
390
391 if ( function_exists( 'openssl_encrypt' ) && function_exists( 'hash' ) ) {
392 $encrypt_method = 'AES-256-CBC';
393
394 $key = hash( 'sha256', $secret_key );
395 $iv = substr( hash( 'sha256', 'secret key' ), 0, 16 );
396
397 $content = openssl_decrypt( base64_decode( $content ), $encrypt_method, $key, 0, $iv );
398 } else {
399 $content = base64_decode( $content );
400 }
401
402 $content = maybe_unserialize( $content );
403
404 return $content;
405 }
406
407 /**
408 * Get the user uuid
409 *
410 * @return string
411 */
412 function powerkit_get_user_uuid() {
413 if ( getenv( 'HTTP_CLIENT_IP' ) ) {
414 return getenv( 'HTTP_CLIENT_IP' );
415 } elseif ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
416 return getenv( 'HTTP_X_FORWARDED_FOR' );
417 } elseif ( getenv( 'HTTP_X_FORWARDED' ) ) {
418 return getenv( 'HTTP_X_FORWARDED' );
419 } elseif ( getenv( 'HTTP_FORWARDED_FOR' ) ) {
420 return getenv( 'HTTP_FORWARDED_FOR' );
421 } elseif ( getenv( 'HTTP_FORWARDED' ) ) {
422 return getenv( 'HTTP_FORWARDED' );
423 } elseif ( getenv( 'REMOTE_ADDR' ) ) {
424 return getenv( 'REMOTE_ADDR' );
425 }
426
427 return uniqid( 'x', true );
428 }
429
430 /**
431 * Convert by title Cyrillic characters to Latin characters
432 *
433 * @param string $text The text.
434 */
435 function powerkit_text_with_translit( $text ) {
436
437 $gost = array(
438 'А' => 'A',
439 'Б' => 'B',
440 'В' => 'V',
441 'Г' => 'G',
442 'Ѓ' => 'G`',
443 'Ґ' => 'G`',
444 'Д' => 'D',
445 'Е' => 'E',
446 'Ё' => 'YO',
447 'Є' => 'YE',
448 'Ж' => 'ZH',
449 'З' => 'Z',
450 '�
451 ' => 'Z',
452 'И' => 'I',
453 'Й' => 'Y',
454 'Ј' => 'J',
455 'І' => 'I',
456 'Ї' => 'YI',
457 'К' => 'K',
458 'Ќ' => 'K',
459 'Л' => 'L',
460 'Љ' => 'L',
461 'М' => 'M',
462 'Н' => 'N',
463 'Њ' => 'N',
464 'О' => 'O',
465 'П' => 'P',
466 'Р' => 'R',
467 'С' => 'S',
468 'Т' => 'T',
469 'У' => 'U',
470 'Ў' => 'U',
471 'Ф' => 'F',
472 'Х' => 'H',
473 'Ц' => 'TS',
474 'Ч' => 'CH',
475 'Џ' => 'DH',
476 'Ш' => 'SH',
477 'Щ' => 'SHH',
478 'Ъ' => '``',
479 'Ы' => 'YI',
480 'Ь' => '`',
481 'Э' => 'E`',
482 'Ю' => 'YU',
483 'Я' => 'YA',
484 'а' => 'a',
485 'б' => 'b',
486 'в' => 'v',
487 'г' => 'g',
488 'ѓ' => 'g',
489 'ґ' => 'g',
490 'д' => 'd',
491 'е' => 'e',
492 'ё' => 'yo',
493 'є' => 'ye',
494 'ж' => 'zh',
495 'з' => 'z',
496 'ѕ' => 'z',
497 'и' => 'i',
498 'й' => 'y',
499 'ј' => 'j',
500 'і' => 'i',
501 'ї' => 'yi',
502 'к' => 'k',
503 'ќ' => 'k',
504 'л' => 'l',
505 'љ' => 'l',
506 'м' => 'm',
507 'н' => 'n',
508 'њ' => 'n',
509 'о' => 'o',
510 'п' => 'p',
511 'р' => 'r',
512 'с' => 's',
513 'т' => 't',
514 'у' => 'u',
515 'ў' => 'u',
516 'ф' => 'f',
517 '�
518 ' => 'h',
519 'ц' => 'ts',
520 'ч' => 'ch',
521 'џ' => 'dh',
522 'ш' => 'sh',
523 'щ' => 'shh',
524 'ь' => '',
525 'ы' => 'yi',
526 'ъ' => "'",
527 'э' => 'e`',
528 'ю' => 'yu',
529 'я' => 'ya',
530 );
531
532 return strtr( $text, $gost );
533 }
534
535 /**
536 * Check social links exists.
537 */
538 function powerkit_social_links_exists() {
539 if ( ! powerkit_module_enabled( 'social_links' ) ) {
540 return;
541 }
542
543 if ( get_option( 'powerkit_social_links_multiple_list' ) ) {
544 return true;
545 }
546 }
547
548 /**
549 * Check mailchimp form exists.
550 *
551 * @param string $id The list ID.
552 */
553 function powerkit_mailchimp_form_exists( $id = 'default' ) {
554 if ( ! powerkit_module_enabled( 'opt_in_forms' ) ) {
555 return;
556 }
557
558 $token = get_option( 'powerkit_mailchimp_token' );
559
560 if ( $token ) {
561
562 if ( ! $id || 'default' === $id ) {
563 $id = get_option( 'powerkit_mailchimp_list' );
564 }
565
566 if ( $id ) {
567 return true;
568 }
569 }
570 }
571
572 /**
573 * Check share buttons exists.
574 *
575 * @param string $location The location.
576 */
577 function powerkit_share_buttons_exists( $location ) {
578 if ( ! powerkit_module_enabled( 'share_buttons' ) ) {
579 return;
580 }
581
582 if ( ! get_option( "powerkit_share_buttons_{$location}_display" ) ) {
583 return;
584 }
585
586 $accounts = get_option( "powerkit_share_buttons_{$location}_multiple_list", array( 'facebook', 'twitter', 'pinterest' ) );
587
588 if ( $accounts ) {
589 return true;
590 }
591 }
592
593 /**
594 * Get the available image sizes
595 */
596 function powerkit_get_available_image_sizes() {
597 $wais = & $GLOBALS['_wp_additional_image_sizes'];
598
599 $sizes = array();
600 $image_sizes = get_intermediate_image_sizes();
601
602 if ( is_array( $image_sizes ) && $image_sizes ) {
603 foreach ( $image_sizes as $size ) {
604 if ( in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ), true ) ) {
605 $sizes[ $size ] = array(
606 'width' => get_option( "{$size}_size_w" ),
607 'height' => get_option( "{$size}_size_h" ),
608 'crop' => (bool) get_option( "{$size}_crop" ),
609 );
610 } elseif ( isset( $wais[ $size ] ) ) {
611 $sizes[ $size ] = array(
612 'width' => $wais[ $size ]['width'],
613 'height' => $wais[ $size ]['height'],
614 'crop' => $wais[ $size ]['crop'],
615 );
616 }
617
618 // Size registered, but has 0 width and height.
619 if ( 0 === (int) $sizes[ $size ]['width'] && 0 === (int) $sizes[ $size ]['height'] ) {
620 unset( $sizes[ $size ] );
621 }
622 }
623 }
624
625 return $sizes;
626 }
627
628 /**
629 * Gets the data of a specific image size.
630 *
631 * @param string $size Name of the size.
632 */
633 function powerkit_get_image_size( $size ) {
634 if ( ! is_string( $size ) ) {
635 return;
636 }
637
638 $sizes = powerkit_get_available_image_sizes();
639
640 return isset( $sizes[ $size ] ) ? $sizes[ $size ] : false;
641 }
642
643 /**
644 * Get the list available image sizes
645 */
646 function powerkit_get_list_available_image_sizes() {
647 $intermediate_image_sizes = get_intermediate_image_sizes();
648
649 $image_sizes = array();
650
651 foreach ( $intermediate_image_sizes as $size ) {
652 $image_sizes[ $size ] = $size;
653
654 $data = powerkit_get_image_size( $size );
655
656 if ( isset( $data['width'] ) || isset( $data['height'] ) ) {
657
658 $width = '~';
659 $height = '~';
660
661 if ( isset( $data['width'] ) && $data['width'] ) {
662 $width = $data['width'] . 'px';
663 }
664 if ( isset( $data['height'] ) && $data['height'] ) {
665 $height = $data['height'] . 'px';
666 }
667
668 $image_sizes[ $size ] .= sprintf( ' [%s, %s]', $width, $height );
669 }
670 }
671
672 $image_sizes = apply_filters( 'powerkit_list_available_image_sizes', $image_sizes );
673
674 return $image_sizes;
675 }
676
677 /**
678 * Get fields array for Button in some PK blocks
679 *
680 * @param string $field_prefix Field prefix.
681 * @param string $section_name Section name.
682 * @param array $active_callback Active callback.
683 */
684 function powerkit_get_gutenberg_button_fields( $field_prefix = 'button', $section_name = '', $active_callback = array() ) {
685
686 $fields = array(
687 array(
688 'key' => $field_prefix . 'Style',
689 'label' => esc_html__( 'Style', 'powerkit' ),
690 'section' => $section_name,
691 'type' => 'select',
692 'default' => '',
693 'choices' => array(
694 '' => esc_html__( 'Default', 'powerkit' ),
695 'outline' => esc_html__( 'Outline', 'powerkit' ),
696 'squared' => esc_html__( 'Squared', 'powerkit' ),
697 ),
698 'active_callback' => $active_callback,
699 ),
700 array(
701 'key' => $field_prefix . 'Size',
702 'label' => esc_html__( 'Size', 'powerkit' ),
703 'section' => $section_name,
704 'type' => 'select',
705 'default' => '',
706 'choices' => array(
707 '' => esc_html__( 'Default', 'powerkit' ),
708 'sm' => esc_html__( 'Small', 'powerkit' ),
709 'lg' => esc_html__( 'Large', 'powerkit' ),
710 ),
711 'active_callback' => $active_callback,
712 ),
713 array(
714 'key' => $field_prefix . 'FullWidth',
715 'label' => esc_html__( 'Full Width', 'powerkit' ),
716 'section' => $section_name,
717 'type' => 'toggle',
718 'default' => false,
719 'active_callback' => $active_callback,
720 ),
721 array(
722 'key' => $field_prefix . 'ColorBg',
723 'label' => esc_html__( 'Background Color', 'powerkit' ),
724 'section' => $section_name,
725 'type' => 'color',
726 'default' => '',
727 'output' => array(
728 array(
729 'element' => '$ .wp-block-button a.wp-block-button__link',
730 'property' => 'background-color',
731 'suffix' => '!important',
732 ),
733 ),
734 'active_callback' => $active_callback,
735 ),
736 array(
737 'key' => $field_prefix . 'ColorBgHover',
738 'label' => esc_html__( 'Background Color Hover', 'powerkit' ),
739 'section' => $section_name,
740 'type' => 'color',
741 'default' => '',
742 'output' => array(
743 array(
744 'element' => '$ .wp-block-button a.wp-block-button__link:hover, $ .wp-block-button a.wp-block-button__link:focus',
745 'property' => 'background-color',
746 'suffix' => '!important',
747 ),
748 ),
749 'active_callback' => $active_callback,
750 ),
751 array(
752 'key' => $field_prefix . 'ColorText',
753 'label' => esc_html__( 'Text Color', 'powerkit' ),
754 'section' => $section_name,
755 'type' => 'color',
756 'default' => '',
757 'output' => array(
758 array(
759 'element' => '$ .wp-block-button__link',
760 'property' => 'color',
761 'suffix' => '!important',
762 ),
763 ),
764 'active_callback' => $active_callback,
765 ),
766 array(
767 'key' => $field_prefix . 'ColorTextHover',
768 'label' => esc_html__( 'Text Color Hover', 'powerkit' ),
769 'section' => $section_name,
770 'type' => 'color',
771 'default' => '',
772 'output' => array(
773 array(
774 'element' => '$ .wp-block-button a.wp-block-button__link:hover, $ .wp-block-button a.wp-block-button__link:focus',
775 'property' => 'color',
776 'suffix' => '!important',
777 ),
778 ),
779 'active_callback' => $active_callback,
780 ),
781 );
782
783 return $fields;
784 }
785
786 /**
787 * Print core/button in some PK blocks
788 *
789 * @param string $text Text of button.
790 * @param string $url Url of button.
791 * @param string $target Target.
792 * @param string $field_prefix Field prefix.
793 * @param array $attributes Attributes.
794 */
795 function powerkit_print_gutenberg_blocks_button( $text, $url, $target = '', $field_prefix = 'button', $attributes ) {
796 $class_name = 'wp-block-button';
797 $link_class_name = 'wp-block-button__link';
798
799 // Style.
800 if ( isset( $attributes[ $field_prefix . 'Style' ] ) && $attributes[ $field_prefix . 'Style' ] ) {
801 $class_name .= ' is-style-' . $attributes[ $field_prefix . 'Style' ];
802 }
803
804 // Size.
805 if ( isset( $attributes[ $field_prefix . 'Size' ] ) && $attributes[ $field_prefix . 'Size' ] ) {
806 $class_name .= ' is-pk-button-size-' . $attributes[ $field_prefix . 'Size' ];
807 }
808
809 // FullWidth.
810 if ( isset( $attributes[ $field_prefix . 'FullWidth' ] ) && $attributes[ $field_prefix . 'FullWidth' ] ) {
811 $class_name .= ' is-pk-button-full-width';
812 }
813
814 // Color.
815 if ( isset( $attributes[ $field_prefix . 'ColorText' ] ) && $attributes[ $field_prefix . 'ColorText' ] ) {
816 $link_class_name .= ' has-text-color';
817 }
818
819 // Background.
820 if ( isset( $attributes[ $field_prefix . 'ColorBg' ] ) && $attributes[ $field_prefix . 'ColorBg' ] ) {
821 $link_class_name .= ' has-background';
822 }
823 ?>
824 <div class="<?php echo esc_attr( $class_name ); ?>">
825 <a class="<?php echo esc_attr( $link_class_name ); ?>" href="<?php echo esc_url( $url ); ?>" target="<?php echo esc_attr( $target ); ?>">
826 <?php echo wp_kses_post( $text ); ?>
827 </a>
828 </div>
829 <?php
830 }
831