WordPress.org

Make WordPress Core

Ticket #10619: wordpress_import_meta_serialized.patch

File wordpress_import_meta_serialized.patch, 1.5 KB (added by JonathanRogers, 9 years ago)

Disables maybe_serialize() when importing custom field values from WXR

  • wp-admin/import/wordpress.php

    === modified file 'wp-admin/import/wordpress.php'
     
    551551                // the filter can return false to skip a particular metadata key
    552552                $_key = apply_filters('import_post_meta_key', $key);
    553553                if ( $_key ) {
    554                         add_post_meta( $post_id, $_key, $value );
     554                  add_post_meta( $post_id, $_key, $value, false, false );
    555555                        do_action('import_post_meta', $post_id, $_key, $value);
    556556                }
    557557        }
  • wp-includes/post.php

    === modified file 'wp-includes/post.php'
     
    510510 * @param bool $unique Optional, default is false. Whether the same key should not be added.
    511511 * @return bool False for failure. True for success.
    512512 */
    513 function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) {
     513function add_post_meta($post_id, $meta_key, $meta_value, $unique = false, $serialize = true) {
    514514        if ( !$meta_key )
    515515                return false;
    516516
     
    526526        if ( $unique && $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = %s AND post_id = %d", $meta_key, $post_id ) ) )
    527527                return false;
    528528
    529         $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
     529        $meta_value = stripslashes_deep($meta_value);
     530        if ($serialize) $meta_value = maybe_serialize($meta_value);
    530531
    531532        $wpdb->insert( $wpdb->postmeta, compact( 'post_id', 'meta_key', 'meta_value' ) );
    532533