Advertisement
Osama_Mersal

Untitled

Feb 27th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. add_filter( 'wpml_pb_shortcode_encode', 'wpml_pb_shortcode_encode_urlencoded_json', 10, 3 );
  2. function wpml_pb_shortcode_encode_urlencoded_json( $string, $encoding, $original_string ) {
  3. if ( 'urlencoded_json' === $encoding ) {
  4. $output = array();
  5. foreach ( $original_string as $combined_key => $value ) {
  6. $parts = explode( '_', $combined_key );
  7. $i = array_pop( $parts );
  8. $key = implode( '_', $parts );
  9. $output[ $i ][ $key ] = $value;
  10. }
  11. $string = urlencode( json_encode( $output ) );
  12. }
  13. return $string;
  14. }
  15.  
  16. add_filter( 'wpml_pb_shortcode_decode', 'wpml_pb_shortcode_decode_urlencoded_json', 10, 3 );
  17. function wpml_pb_shortcode_decode_urlencoded_json( $string, $encoding, $original_string ) {
  18. if ( 'urlencoded_json' === $encoding ) {
  19. $rows = json_decode( urldecode( $original_string ), true );
  20. $string = array();
  21. foreach ( $rows as $i => $row ) {
  22. foreach ( $row as $key => $value ) {
  23. if ( in_array( $key, array( 'title', 'substring', 'btn_text', 'btn_link', 'price', 'label', 'value', 'y_values' ) ) ) {
  24. $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
  25. } else {
  26. $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
  27. }
  28. }
  29. }
  30. }
  31. return $string;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement