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

/**
 * Update old to new options.
 */
$args = new WP_Query(
	array(
		'post_type'      => 'sp_post_carousel',
		'post_status'    => 'any',
		'posts_per_page' => '300',
	)
);

$shortcode_ids = wp_list_pluck( $args->posts, 'ID' );
if ( count( $shortcode_ids ) > 0 ) {
	foreach ( $shortcode_ids as $shortcode_key => $shortcode_id ) {
		$shortcode_data        = get_post_meta( $shortcode_id, 'sp_pcp_view_options', true );
		$old_social_icon_shape = $shortcode_data['post_content_sorter']['pcp_social_share']['social_icon_shape'];
		if ( 'circle' === $old_social_icon_shape ) {
			$shortcode_data['post_content_sorter']['pcp_social_share']['social_icon_shape'] = 'pcp_circle';
		} elseif ( 'rounded' === $old_social_icon_shape ) {
			$shortcode_data['post_content_sorter']['pcp_social_share']['social_icon_shape'] = 'pcp_rounded';
		} elseif ( 'square' === $old_social_icon_shape ) {
			$shortcode_data['post_content_sorter']['pcp_social_share']['social_icon_shape'] = 'pcp_square';
		}
		$old_thumb_src = $shortcode_data['post_content_sorter']['pcp_post_thumb']['pcp_thumb_src'];
		if ( 'featured_image' !== $old_thumb_src ) {
			$shortcode_data['post_content_sorter']['pcp_post_thumb']['pcp_thumb_src_replace']     = array( 'image' );
			$shortcode_data['post_content_sorter']['pcp_post_thumb']['post_featured_thumb_found'] = 'even_featured_img_found';
		}

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

