WordPress.org

Ready to get started?Download WordPress

Forums

Attachments
Migrate custom post types automatically (WPML compatible) (3 posts)

  1. sebastian.friedrich
    Member
    Posted 1 year ago #

    (WPMS v.3.5.1 + WPML, Attachments v.3.3.2)

    I just want to post some ideas here related to the migration of attachments attached to custom post type posts.

    Problem was, that I hit the migration button before overriding the default attachment instance in functions.php. Doing so, only attachment from type 'page' and 'post' become migrated, and then there is the migration option missing in the admin view! I guess, that there some people out there making the same fault.

    First, I reseted the option for migration this way:
    get the migraton button back

    Then I edited the following lines (all changes related to class.attachments.migrate.php):

    deleted:

    foreach( $legacy_attachments_settings['post_types'] as $post_type => $value )
    	if( $value ) $post_types[] = $post_type;

    because due to migration process, it is not necessary to scan for registered posttypes. In every case the old data will become obsolete, so everything has to be converted on every migration process. So, just modify the query below to post_type=>'any':

    $args = array(
    	'post_type'         => 'any', // get all posts of every type or custom type
    	'post_status'       => 'any',
    	'posts_per_page'    => -1,
    	'meta_key'          => '_attachments',
    	'suppress_filters'	=> true // suppress filters, so that wpml does not hook in and wp returns every language
    );

    Also in this place, add 'suppress_filters', so that WPML plugin will not be able to filter to records from the blogs current admin language only, but return really all languages.

    Clear obsolete meta-data from database - added this after line 149:

    // clean up database
    delete_post_meta( $query->post->ID, '_attachments' );

    As an alternate you can manually run a sql query and remove all records with '_attachments' as meta_key in table 'postmeta', so you have the possibility to verify successful migration first.

    By the way: To my opinion it is not quite optimal, that there is a default instance of attachments without registering that. It is difficult, to remove that instance, override it is simpler.
    The line
    define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );
    only works in wp-config.php for me, I guess in functions.php it is too late. Defining plugin specific configuraton in the wp-config is probably not best practice.

    http://wordpress.org/extend/plugins/attachments/

  2. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you for the feedback. I'll add the flag to suppress_filters, it'll be implemented in the next release in an hour or two. The reason Attachments 1.x settings are used and looped through to determine post type names is because if you've set up a CPT with exclude_search set to true, the migration will overlook those entries. Using the settings from the legacy version ensures that we're migrating data intended to be in use prior to the upgrade. I'm going to hold off on deleting the legacy data because I'm still refining the migration process and don't want to leave people without their original data. After the migration process the data will just sit as unused records. I'll also check into a better way of disabling the default instance as I agree it's more favorable to edit functions.php instead of wp-config.php. Thanks for the feedback!

  3. sebastian.friedrich
    Member
    Posted 1 year ago #

    ok fine, looking foward to the next version :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic