<?php
/**
 * Updater file to update old options.
 */

update_option( 'smart_post_show_pro_version', '3.0.2' );
update_option( 'smart_post_show_pro_db_version', '3.0.2' );

$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 );

		if ( ! is_array( $view_options ) ) {
			continue;
		}

		$popup_height_width = isset( $view_options['popup_height_width']['top-bottom'] )
			? $view_options['popup_height_width']
			: array(
				'left-right' => 1050,
				'top-bottom' => 700,
				'unit'       => 'px',
			);

		$view_options['pcp_popup_width']['all']   = $popup_height_width['left-right'];
		$view_options['pcp_popup_width']['unit']  = $popup_height_width['unit'];
		$view_options['pcp_popup_height']['all']  = $popup_height_width['top-bottom'];
		$view_options['pcp_popup_height']['unit'] = $popup_height_width['unit'];

		update_post_meta( $shortcode_id, 'sp_pcp_view_options', $view_options );
	}
}
