vc-progress-bar.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * Class WPBakeryShortCode_Vc_Progress_Bar
  7. */
  8. class WPBakeryShortCode_Vc_Progress_Bar extends WPBakeryShortCode {
  9. /**
  10. * @param $atts
  11. * @return mixed
  12. */
  13. public static function convertAttributesToNewProgressBar( $atts ) {
  14. if ( isset( $atts['values'] ) && strlen( $atts['values'] ) > 0 ) {
  15. $values = vc_param_group_parse_atts( $atts['values'] );
  16. if ( ! is_array( $values ) ) {
  17. $temp = explode( ',', $atts['values'] );
  18. $paramValues = array();
  19. foreach ( $temp as $value ) {
  20. $data = explode( '|', $value );
  21. $colorIndex = 2;
  22. $newLine = array();
  23. $newLine['value'] = isset( $data[0] ) ? $data[0] : 0;
  24. $newLine['label'] = isset( $data[1] ) ? $data[1] : '';
  25. if ( isset( $data[1] ) && preg_match( '/^\d{1,3}\%$/', $data[1] ) ) {
  26. $colorIndex ++;
  27. $newLine['value'] = (float) str_replace( '%', '', $data[1] );
  28. $newLine['label'] = isset( $data[2] ) ? $data[2] : '';
  29. }
  30. if ( isset( $data[ $colorIndex ] ) ) {
  31. $newLine['customcolor'] = $data[ $colorIndex ];
  32. }
  33. $paramValues[] = $newLine;
  34. }
  35. $atts['values'] = rawurlencode( wp_json_encode( $paramValues ) );
  36. }
  37. }
  38. return $atts;
  39. }
  40. }