<?php
update_option( 'smart_post_show_pro_version', '2.5.3' );
update_option( 'smart_post_show_pro_db_version', '2.5.3' );

$args = new WP_Query(
	array(
		'post_type'      => 'sp_post_carousel',
		'post_status'    => 'any',
		'posts_per_page' => '600',
	)
);

$shortcode_ids = wp_list_pluck( $args->posts, 'ID' );
if ( count( $shortcode_ids ) > 0 ) {
	foreach ( $shortcode_ids as $shortcode_key => $shortcode_id ) {
		$view_options  = get_post_meta( $shortcode_id, 'sp_pcp_view_options', true );
		$layouts       = get_post_meta( $shortcode_id, 'sp_pcp_layouts', true );
		$layout_preset = isset( $layouts['pcp_layout_preset'] ) ? $layouts['pcp_layout_preset'] : 'carousel_layout';
		if ( 'grid_layout' === $layout_preset ) {
			$grid_style = isset( $view_options['pcp_grid_style'] ) ? $view_options['pcp_grid_style'] : 'even';
			if ( 'masonry' === $grid_style ) {
				$layouts['pcp_layout_preset'] = 'masonry_layout';
			}
		}

		update_post_meta( $shortcode_id, 'sp_pcp_layouts', $layouts );
	}
}
