PluginProbe
Powerkit – Supercharge your WordPress Site / 2.3.0
Powerkit – Supercharge your WordPress Site v2.3.0
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.3.0, at core/core-powerkit-helpers.php

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