INVP::delete_all_data()

This function will operate as an uninstall utility. Removes all the data we have added to the database including vehicle posts, their attachments, the option that holds settings, and terms in custom taxonomies.

On This Page


Return Return

(void)


Top ↑

Source Source

File: includes/class-invp.php

	public static function delete_all_data() {
		// During uninstall.php runs, the main plugin file is not loaded.
		if ( ! defined( 'INVP_PLUGIN_FILE_PATH' ) ) {
			define( 'INVP_PLUGIN_FILE_PATH', dirname( __DIR__ ) . '/inventory-presser.php' );
		}

		// delete all the vehicles.
		self::delete_all_inventory();

		// delete unattached photos with meta keys that identify them as vehicle photos.
		self::delete_attachment_orphans();

		// delete pages created during activation.
		// uninstall.php doesn't load the whole plugin but calls this method.
		if ( ! class_exists( 'Inventory_Presser_Allow_Inventory_As_Home_Page' ) ) {
			include_once plugin_dir_path( INVP_PLUGIN_FILE_PATH ) . 'includes/class-allow-inventory-as-home-page.php';
		}
		Inventory_Presser_Allow_Inventory_As_Home_Page::delete_pages();

		// delete all terms.
		if ( ! is_multisite() ) {
			self::delete_all_terms_on_blog();

			// delete the option where all this plugin's settings are stored.
			delete_option( self::OPTION_NAME );
		} else {
			$sites = get_sites(
				array(
					'network' => 1,
					'limit'   => apply_filters( 'invp_query_limit', 1000, __METHOD__ ),
				)
			);
			foreach ( $sites as $site ) {
				switch_to_blog( $site->blog_id );

				self::delete_all_terms_on_blog();

				// delete the option where all this plugin's settings are stored.
				delete_option( self::OPTION_NAME );

				restore_current_blog();
			}
		}

		do_action( 'invp_delete_all_data' );
	}