Follow us on

Codestar Support Forum » WordPress Plugins » Codestar Framework

HTML Code not Import Post MetaBox (Type: wp_editor)

  1. I have saved large HTML code but when I export all content from the WordPress dashboard Tools menu and import another site all content area working fine but only HTML code not showing on my site.

    Note: Please check the attachment screenshot image.

    Code:

    CSF::createSection($prefix.'_information_options',array(
    		'fields' => array(
    			array(
    				'id'    => 'tp_information_description',
    				'type'  => 'wp_editor',
    				'title' => esc_html__( 'Description','tourx' ),
    				'sanitize' => false,
    			),
    		)
    	));CopyCopied!
    Posted 1 year ago #

  2. Codestar
    Admin

    Hi,

    Welcome to support forum and thanks for purchasing.

    Let me explain this global issue.

    Firstly, The metabox framework has two database save option. "serialize" "unserialize".

    // Serialize saves data like this in db:
    {a:2 :{s:11:"Hello world";s:7 :":Another"}}
    
    // Unserialize saves like this in db:
    meta_data_name = "Hello world"
    meta_data_name = "Another"CopyCopied!

    "I think you know this, but I need to tell for easy understand."

    In this case I think you using "serialize" method and "textarea/wp_editor/code_editor" fields has new line is problem. I mean this:

    // If you put a new line, the serialize doesn't count correct.
    {a:2 :{s:10 :"Hello
    world";s:7 :":Another"}}
    
    It says s:10 but there are 11 chars.CopyCopied!

    That is why not importing xml data correctly.

    Actually, this is not a framework issue. It's global issue. ( https://wordpress.stackexchange.com/questions/42360/with-wordpress-importer-why-cant-i-import-post-meta-containing-a-multi-dimensi )

    Ok now, what is the solution ways ?

    You can return back to unserialize type. ( but all current data will gone, and you will re-code for your single.php get_post_meta things )

    You can try a repair serialize data filter and try to import again. for eg:

    function egenslab_repair_serialize_data( $post ) {
    
      $db_meta_key = '_prefix_metabox_options'; // update this!!!
    
      if ( ! empty( $post['postmeta'] ) ) {
    
        foreach ( $post['postmeta'] as $index => $meta ) {
    
          if ( $meta['key'] === $db_meta_key && ! empty( $meta['value'] ) && strpos( $meta['value'], "\n" ) !== false ) {
    
            $repaired_serialized_data = preg_replace_callback('/s[:](\d+):"(.*?)";/s', function ( $matches ) {
              return 's:'. strlen( $matches[2] ) .':"'. $matches[2] .'";';
            }, $meta['value'] );
    
            $post['postmeta'][ $index ]['value'] = $repaired_serialized_data;
    
          }
    
        }
    
      }
    
      return $post;
    
    }
    
    add_filter( 'wp_import_post_data_raw', 'egenslab_repair_serialize_data' );CopyCopied!

    Regards, Codestar

    Posted 1 year ago #
  3. Now WordPress Manual Import Working Fine but When I'm Import use One Click Demo Importer Plugin then I see same issue.

    Posted 1 year ago #
  4. 'sanitize' => false, How can i sanitize wp_editor html code ?

    Posted 1 year ago #

  5. Codestar
    Admin

    Hi,

    "One Click Demo Importer" uses WXR Importer. You can use this filter:

    function egenslab_wxr_repair_serialize_data( $meta ) {
    
      $meta_key = '_prefix_metabox_options'; // update this!!!
    
      if ( ! empty( $meta[ 'key' ] ) && $meta[ 'key' ] === $meta_key && ! empty( $meta[ 'value' ] ) && strpos( $meta['value'], "\n" ) !== false ) {
        $meta['value'] = preg_replace_callback('/s[:](\d+):"(.*?)";/s', function ( $matches ) {
          return 's:'. strlen( $matches[2] ) .':"'. $matches[2] .'";';
        }, $meta['value'] );
      }
    
      return $meta;
    
    }
    add_filter( 'wxr_importer.pre_process.post_meta', array( $this, 'egenslab_wxr_repair_serialize_data' ), 10, 2 );CopyCopied!

    "'sanitize' => false, How can i sanitize wp_editor html code ?" I didn't get this request. Can you further detail ?

    Regards, Codestar

    Posted 1 year ago #

  6. Codestar
    Admin

    Hi,

    Btw, I have another idea for that issue. Actually we can repair sanitized data in the wp_export progress. I mean:

    Go to your demo wordpress exporter (Where you export xml).
    Open the file /root/wp-admin/includes/export.php
    Go to line 622 and prepend repair code. It will look like this.

    <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
    <?php
      $meta_key = '_prefix_metabox_options'; // update this!!!
      if ( $meta->meta_key === $meta_key && ! empty( $meta->meta_value ) && strpos( $meta->meta_value, "\n" ) !== false ) { // update this!!!
        $meta->meta_value = preg_replace_callback('/s[:](\d+):"(.*?)";/s', function ( $matches ) {
          return 's:'. strlen( $matches[2] ) .':"'. $matches[2] .'";';
        }, $meta->meta_value );
      }
    ?>
    <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
    </wp:postmeta>CopyCopied!

    Export a new xml and try again

    In this idea, you do not need above filter codes. Remove them.

    Regards, Codestar

    Posted 1 year ago #