PUM_Admin_Upgrade_Routine_6::run()

Run the update.


Description Description


Source Source

File: includes/admin/upgrades/class-pum-admin-upgrade-routine-6.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' );

		// Install new themes
		pum_install_built_in_themes();

		// Refresh CSS transients
		pum_reset_assets();

		// 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',
		) );

		PUM_Admin_Upgrade_Routine_6::setup_valid_themes();

		// Delete All old meta keys.
		PUM_Admin_Upgrade_Routine_6::delete_all_old_meta_keys();

		// Delete All orphaned meta keys.
		PUM_Admin_Upgrade_Routine_6::delete_all_orphaned_meta_keys();

		PUM_Admin_Upgrade_Routine_6::process_popup_cats_tags();

		if ( $popups ) {

			foreach ( $popups as $popup ) {

				// Check that each popup has a valid theme id
				if ( ! array_key_exists( $popup->get_theme_id(), PUM_Admin_Upgrade_Routine_6::$valid_themes ) ) {
					// Set a valid theme.
					update_post_meta( $popup->ID, 'popup_theme', PUM_Admin_Upgrade_Routine_6::$default_theme );
				}

				$completed ++;
			}

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

		}

		PUM_Admin_Upgrade_Routine_6::done();
	}


Top ↑

User Contributed Notes User Contributed Notes

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