have_posts() ) { // set up postdata $query->the_post(); // let's first decode our Attachments data $existing_attachments = get_post_meta( $query->post->ID, '_attachments', false ); $post_attachments = array(); // check to make sure we've got data if( is_array( $existing_attachments ) && count( $existing_attachments ) > 0 ) { // loop through each existing attachment foreach( $existing_attachments as $attachment ) { // decode and unserialize the data $data = unserialize( base64_decode( $attachment ) ); array_push( $post_attachments, array( 'id' => stripslashes( $data['id'] ), 'title' => stripslashes( $data['title'] ), 'caption' => stripslashes( $data['caption'] ), 'order' => stripslashes( $data['order'] ) )); } // sort attachments if( count( $post_attachments ) > 1 ) { usort( $post_attachments, 'attachments_cmp' ); } } // we have our Attachments entries // let's check to see if we're migrating after population has taken place $existing_attachments = get_post_meta( $query->post->ID, 'attachments', false ); if( !isset( $existing_attachments[0] ) ) $existing_attachments[0] = ''; $existing_attachments = json_decode( $existing_attachments[0] ); if( !is_object( $existing_attachments ) ) $existing_attachments = new stdClass(); // we'll loop through the legacy Attachments and save them in the new format foreach( $post_attachments as $legacy_attachment ) { // convert to the new format $converted_attachment = array( 'id' => $legacy_attachment['id'] ); // fields are technically optional so we'll add those separately // we're also going to encode them in the same way the main class does if( $title ) $converted_attachment['fields'][$title] = htmlentities( stripslashes( $legacy_attachment['title'] ), ENT_QUOTES ); if( $caption ) $converted_attachment['fields'][$caption] = htmlentities( stripslashes( $legacy_attachment['caption'] ), ENT_QUOTES ); // check to see if the existing Attachments have our target instance if( !isset( $existing_attachments->$instance ) ) { // the instance doesn't exist so we need to create it $existing_attachments->$instance = array(); } // we need to convert our array to an object $converted_attachment['fields'] = (object) $converted_attachment['fields']; $converted_attachment = (object) $converted_attachment; // append this legacy attachment to the existing instance array_push( $existing_attachments->$instance, $converted_attachment ); } // we're done! let's save everything in our new format $existing_attachments = json_encode( $existing_attachments ); // save it to the database update_post_meta( $query->post->ID, 'attachments', $existing_attachments ); // increment our counter $count++; } return $count; } if( isset( $_GET['dismiss'] ) ) { if( !wp_verify_nonce( $_GET['nonce'], 'attachments-dismiss') ) wp_die( __( 'Invalid request', 'attachments' ) ); add_option( 'attachments_ignore_migration', true, '', 'no' ); } ?>
revert to the old version of Attachments you may do so by downgrading the plugin install itself, or adding the following to your', 'attachments' ); ?> wp-config.php:
define( 'ATTACHMENTS_LEGACY', true );
you will need to trigger a migration to the new format.", 'attachments' ); ?>
instances. An instance is equivalent to a meta box on an edit screen and it has a number of properties you can customize. Please read the README for more information.', 'attachments' ); ?> .
: .
found_posts ) : ?> wp-config.php:
define( 'ATTACHMENTS_LEGACY', true );
wp-config.php:
define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );
functions.php: