roles = $roles; $this->seeder = $seeder; $this->salt = $salt; } /** * Bootstrap. * * @return void */ public function bootstrap() { register_activation_hook( SURECART_PLUGIN_FILE, [ $this, 'activate' ] ); register_deactivation_hook( SURECART_PLUGIN_FILE, [ $this, 'deactivate' ] ); } /** * Create roles on plugin activation. * * @return void */ public function activate() { // Create roles. $this->roles->create(); // Seed pages and forms. $this->seeder->seed(); // Add the encryption key to the wp-config.php file. $this->salt->write(); } /** * On deactivation logic. * * @return void */ public function deactivate() { // clear webhooks. RegisteredWebhook::delete(); // Drop the cached rules so WordPress rebuilds them without our post types on // the next request. Flushing here would just re-save them, since our post // types are still registered in the request doing the deactivating. delete_option( 'rewrite_rules' ); } /** * Remove roles and all data. * * @return void */ public function uninstall() { // remove roles. $this->roles->delete(); // remove pages that were automatically seeded. $this->seeder->delete(); // remove all forms. $this->removeFormPosts(); // remove all options from the options table. $this->removeOptions(); // remove all tables. $this->removeTables(); } /** * Remove all tables. * * @return void */ public function removeTables() { // Delete the integration table. $integrations = new \SureCart\Database\Tables\Integrations( new \SureCart\Database\Table() ); $integrations->uninstall(); } /** * Remove all posts from our post type. * * @return void */ public function removeFormPosts() { // remove all form posts. $form_ids = get_posts( [ 'post_type' => 'sc_form', 'numberposts' => -1, 'fields' => 'ids', ] ); foreach ( $form_ids as $form_id ) { wp_delete_post( $form_id, true ); } } /** * Remove all our options from the options table. * * @return void */ public function removeOptions() { delete_option( 'surecart_registered_webhook' ); delete_option( 'surecart_previous_webhook' ); delete_option( 'surecart_order-confirmation_page_id' ); delete_option( 'surecart_dashboard_page_id' ); delete_option( 'surecart_checkout_sc_form_id' ); delete_option( 'surecart_use_esm_loader' ); delete_option( 'surecart_checkout_page_id' ); delete_option( 'sc_api_token' ); delete_option( 'sc_previous_account' ); delete_option( 'sc_uninstall' ); delete_option( 'surecart_order_bump_design' ); delete_option( NpsSurveyNotice::LAST_SUBMITTED_OPTION ); delete_option( NpsSurveyNotice::NPS_SURVEY_ID ); delete_option( 'surecart_mcp_abilities_enabled' ); delete_option( 'surecart_mcp_edit_abilities_enabled' ); delete_option( 'surecart_mcp_delete_abilities_enabled' ); } }