• I’ve been having issues today with my quest theme site, and most seem to have worked themselves out, except now all my line breaks have rn (sometimes rnrnrn) and it’s breaking my code so that nothing is working properly. I’ve read this has something to do with a php error, but I’m not sure how to fix it. Is there anything I can do to make it work again?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author pacethemes

    (@pacethemes)

    Hello

    I am not 100% suer about the issue and would need your confirmation, below might be the fix for the issue, but i can’t confirm as i could not reproduce the \r\n in my local setup.

    Add the below code in the child theme functions.php and then edit the page with the issue and please let us know if it fixes the issue

    <?php
    if ( ! class_exists( 'PT_PageBuilder_Helper' ) ) :
    	/**
    	 * Helper class for PT_PageBuilder
    	 *
    	 */
    	class PT_PageBuilder_Helper {
    
    		/**
    		 * Generates Attributes
    		 *
    		 * @return string $content
    		 */
    		public static function GetAttributes( $array, $attributes ) {
    			$content = "";
    
    			foreach ( $attributes as $attribute ) {
    				if ( array_key_exists( $attribute, $array ) && $array[ $attribute ] !== '' ) {
    					$value = esc_attr( $array[ $attribute ] );
    					$content .= " $attribute='$value'";
    				}
    			}
    
    			return $content;
    		}
    
    		/**
    		 * Generates Data Attributes
    		 *
    		 * @return string $content
    		 */
    		public static function GetDataAttributes( $values, $properties ) {
    			$content = "";
    			foreach ( $properties as $prop ) {
    				if ( array_key_exists( $prop, $values ) ) {
    					$attr  = str_replace( '_', '-', $prop );
    					$value = esc_attr( $values[ $prop ] );
    					$content .= " data-$attr='$value'";
    				}
    			}
    
    			return $content;
    		}
    
    		public static function getContent( $module ) {
    			return isset( $module['content'] ) ? stripslashes( $module['content'] ) : "";
    		}
    
    		/**
    		 * Decodes Page Builder Meta Data if it's encoded, uses <code>json_decode</code> and <code>htmlspecialchars_decode</code>
    		 * @since  1.2.5
    		 *
    		 * @return array
    		 */
    		public static function decode_pb_section_metadata( $meta ) {
    			// If the meta is an array we are dealing with non encoded older Meta Data
    			if ( is_array( $meta ) ) {
    				return $meta;
    			}
    			// Escape unicode characters properly
    			// $meta = preg_replace( '/\\\u([0-9a-f]{4})/i', '\\\\\\u$1', $meta ); print_r($meta);
    			// $meta = preg_replace( '/u([0-9a-f]{4})/i', '\\\\\\u$1', $meta );
    
    			// $meta = preg_replace( '/\\\"/i', '\\\\\\"', $meta );
    
    			// $meta = preg_replace( '/\(n)|\(r)/', '\\$1"', $meta );
    
    			// Escape the slash characters as we will unslash before decoding
    			$meta = addcslashes($meta, '\\');
    
    			// Perform json decode on the meta, for unicode characters add extra slashes so that the wp_unslash function doesn't strip them
    			$decoded = json_decode( wp_unslash( $meta ), true );
    
    			// Convert quotes (single and double) entities back to quotes
    			if ( is_array( $decoded ) ) {
    				$decoded = self::normalize_meta_data( $decoded );
    			}
    
    			return $decoded;
    
    		}
    
    		/**
    		 * Encodes Page Builder Meta Data to json format to handle PHP <code>serialize</code> issues with UTF8 characters
    		 * WordPress <code>update_post_meta</code> serializes the data and in some cases (probably depends on hostng env.)
    		 * the serialized data is not being unserialized
    		 * Uses <code>json_encode</code>
    		 *
    		 * @since  1.2.5
    		 *
    		 * @return string
    		 */
    		public static function encode_pb_section_metadata( $meta ) {
    
    			if ( ! is_array( $meta ) ) {
    				return wp_slash( $meta );
    			}
    
    			return wp_slash( json_encode( self::sanitize_meta_data( $meta ) ) );
    		}
    
    		/**
    		 * Sanitizes Page Builder Meta Data
    		 * Converts quotes and tags to html entities so that json_encode doesn't have issues
    		 * @since  1.2.7
    		 *
    		 * @return array
    		 */
    		public static function sanitize_meta_data( $arr ) {
    			$result = array();
    			foreach ( $arr as $key => $value ) {
    				if ( is_array( $value ) ) {
    					$value = self::sanitize_meta_data( $value );
    				} else if ( $key === 'content' ) {
    					// try to unslash first incase the server already escaped quotes
    					$value = htmlspecialchars( wp_unslash( $value ), ENT_QUOTES );
    				}
    				$result[ $key ] = $value;
    			}
    
    			return $result;
    		}
    
    		/**
    		 * Normalizes Page Builder Meta Data
    		 * Converts quotes and tags html entities back to their original state
    		 * @since  1.2.7
    		 *
    		 * @return array
    		 */
    		public static function normalize_meta_data( $arr ) {
    			$result = array();
    			foreach ( $arr as $key => $value ) {
    				if ( is_array( $value ) ) {
    					$value = self::normalize_meta_data( $value );
    				} else if ( $key === 'content' ) {
    					$value = htmlspecialchars_decode( $value, ENT_QUOTES );
    				}
    				$result[ $key ] = $value;
    			}
    
    			return $result;
    		}
    
    	}
    endif;

    I’m getting this same issue – running Mac OS/X 10.7.5 – but it’s more annoying than destructive.
    It occurs when I go to “Text” from “Visual” and then publish the page. If I don’t move between the two tabs, it seems to be okay…but I’ve not thoroughly tested it.

    I get the same problem – also caused by moving between Text and Visual view before publishing. The problem occurs if I publish whilst in Text view.

    Mac OS X 10.11, Chrome 45.0.2454.101

    Theme Author pacethemes

    (@pacethemes)

    Hello

    Have you tried the solution mentioned in the last reply ? I will be adding this to the Theme in the next release – v1.3.0 scheduled for this weekend, till then please use the above workaround

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘rn in my code’ is closed to new replies.