Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'wpml_pb_shortcode_encode', 'wpml_pb_shortcode_encode_urlencoded_json', 10, 3 );
- function wpml_pb_shortcode_encode_urlencoded_json( $string, $encoding, $original_string ) {
- if ( 'urlencoded_json' === $encoding ) {
- $output = array();
- foreach ( $original_string as $combined_key => $value ) {
- $parts = explode( '_', $combined_key );
- $i = array_pop( $parts );
- $key = implode( '_', $parts );
- $output[ $i ][ $key ] = $value;
- }
- $string = urlencode( json_encode( $output ) );
- }
- return $string;
- }
- add_filter( 'wpml_pb_shortcode_decode', 'wpml_pb_shortcode_decode_urlencoded_json', 10, 3 );
- function wpml_pb_shortcode_decode_urlencoded_json( $string, $encoding, $original_string ) {
- if ( 'urlencoded_json' === $encoding ) {
- $rows = json_decode( urldecode( $original_string ), true );
- $string = array();
- foreach ( $rows as $i => $row ) {
- foreach ( $row as $key => $value ) {
- if ( in_array( $key, array( 'title', 'substring', 'btn_text', 'btn_link', 'price', 'label', 'value', 'y_values' ) ) ) {
- $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
- } else {
- $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
- }
- }
- }
- }
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement