vc-btn.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder shortcodes
  7. *
  8. * @package WPBakeryPageBuilder
  9. *
  10. */
  11. /**
  12. * Class WPBakeryShortCode_Vc_Btn
  13. * @since 4.5
  14. */
  15. class WPBakeryShortCode_Vc_Btn extends WPBakeryShortCode {
  16. /**
  17. * @param $atts
  18. * @return mixed
  19. */
  20. public static function convertAttributesToButton3( $atts ) {
  21. // size btn1 to size btn2
  22. $btn1_sizes = array(
  23. 'wpb_regularsize',
  24. 'btn-large',
  25. 'btn-small',
  26. 'btn-mini',
  27. );
  28. if ( isset( $atts['size'] ) && in_array( $atts['size'], $btn1_sizes, true ) ) {
  29. $atts['size'] = str_replace( $btn1_sizes, array(
  30. 'md',
  31. 'lg',
  32. 'sm',
  33. 'xs',
  34. ), $atts['size'] );
  35. }
  36. // Convert Btn1 href+target attributes to Btn2 `link` attribute
  37. if ( ! isset( $atts['link'] ) && isset( $atts['href'] ) && strlen( $atts['href'] ) > 0 ) {
  38. $link = $atts['href'];
  39. $target = isset( $atts['target'] ) ? $atts['target'] : '';
  40. $title = isset( $atts['title'] ) ? $atts['title'] : $link;
  41. $atts['link'] = 'url:' . rawurlencode( $link ) . '|title:' . $title . ( strlen( $target ) > 0 ? '|target:' . rawurlencode( $target ) : '' );
  42. }
  43. if ( ( ! isset( $atts['add_icon'] ) || 'true' !== $atts['add_icon'] ) && isset( $atts['icon'] ) && strlen( $atts['icon'] ) > 0 && 'none' !== $atts['icon'] ) {
  44. // old icon from btn1 is set, let's convert it to new btn
  45. $atts['add_icon'] = 'true';
  46. $atts['icon_type'] = 'pixelicons';
  47. $atts['icon_align'] = 'right';
  48. $atts['icon_pixelicons'] = 'vc_pixel_icon vc_pixel_icon-' . str_replace( 'wpb_', '', $atts['icon'] );
  49. }
  50. $haystack = array(
  51. 'rounded',
  52. 'square',
  53. 'round',
  54. 'outlined',
  55. 'square_outlined',
  56. );
  57. if ( isset( $atts['style'] ) && in_array( $atts['style'], $haystack, true ) ) {
  58. switch ( $atts['style'] ) {
  59. case 'rounded':
  60. $atts['style'] = 'flat';
  61. $atts['shape'] = 'rounded';
  62. break;
  63. case 'square':
  64. $atts['style'] = 'flat';
  65. $atts['shape'] = 'square';
  66. break;
  67. case 'round':
  68. $atts['style'] = 'flat';
  69. $atts['shape'] = 'round';
  70. break;
  71. case 'outlined':
  72. $atts['style'] = 'outline';
  73. break;
  74. case 'square_outlined':
  75. $atts['style'] = 'outline';
  76. $atts['shape'] = 'square';
  77. break;
  78. }
  79. }
  80. return $atts;
  81. }
  82. /**
  83. * @param $title
  84. *
  85. * @return string
  86. * @since 4.5
  87. */
  88. protected function outputTitle( $title ) {
  89. $icon = $this->settings( 'icon' );
  90. return '<h4 class="wpb_element_title"><span class="vc_general vc_element-icon vc_btn3-icon' . ( ! empty( $icon ) ? ' ' . $icon : '' ) . '"></span></h4>';
  91. }
  92. }