PUM_Admin_Upgrade_Routine_5::run()


Description Description


Source Source

File: includes/admin/upgrades/class-pum-admin-upgrade-routine-5.php

	public static function run() {
		if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
			wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), array( 'response' => 403 ) );
		}

		ignore_user_abort( true );

		if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
			@set_time_limit( 0 );
		}

		$upgrades  = PUM_Admin_Upgrades::instance();
		$completed = $upgrades->get_arg( 'completed' );
		$total     = $upgrades->get_arg( 'total' );

		// Set the correct total.
		if ( $total <= 1 ) {
			$popups = wp_count_posts( 'popup' );
			$total  = 0;
			foreach ( $popups as $status ) {
				$total += $status;
			}
			$upgrades->set_arg( 'total', $total );
		}

		$popups = pum_get_popups( array(
			'number' => $upgrades->get_arg( 'number' ),
			'page'   => $upgrades->get_arg( 'step' ),
			'status' => array( 'any', 'trash', 'auto-draft' ),
			'order'  => 'ASC',
		) );

		if ( $popups ) {

			foreach ( $popups as $popup ) {

				/**
				 * Initialize the popup meta values for core analytics.
				 */
				PUM_Admin_Upgrade_Routine_5::initialize_analytics( $popup->ID );

				$completed ++;
			}

			if ( $completed < $total ) {
				$upgrades->set_arg( 'completed', $completed );
				PUM_Admin_Upgrade_Routine_5::next_step();
			}

		}

		// Check for popup analytics extension and import those stats if available.
		$total_open_count = get_option( 'popup_analytics_total_opened_count', 0 );

		// Set the sites total open count.
		update_option( 'pum_total_open_count', $total_open_count );

		// If is multisite add this blogs total to the site totals.
		if ( function_exists( 'is_multisite' ) && is_multisite() ) {
			$site_total_open_count = get_site_option( 'pum_site_total_open_count', 0 );
			update_site_option( 'pum_site_total_open_count', $site_total_open_count + $total_open_count );
		}

			/**
		 * TODO Move this to v1.5 routines.
		 */
		/*
		// Check for popup analytics extension and import those stats if available.
		$total_conversion_count = get_site_option( 'popup_analytics_total_conversion_count', 0 );

		// Set the sites total open count.
		update_site_option( 'pum_total_conversion_count', $total_conversion_count );
		 */

		PUM_Admin_Upgrade_Routine_5::done();
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.