forked from wp-graphql/wp-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeactivation.php
37 lines (30 loc) · 908 Bytes
/
deactivation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* Runs when WPGraphQL is de-activated
*
* This cleans up data that WPGraphQL stores
*
* @return void
*/
function graphql_deactivation_callback() {
// Check if the plugin is set to delete data or not
$delete_data = get_graphql_setting( 'delete_data_on_deactivate' );
// If data is not set to delete, stop now
if ( "on" !== $delete_data ) {
return;
}
// Initialize the settings API
$settings = new WPGraphQL\Admin\Settings\Settings();
$settings->init();
$settings->register_settings();
// Get all the registered settings fields
$fields = $settings->settings_api->get_settings_fields();
// Loop over the registered settings fields and delete the options
if ( ! empty( $fields ) && is_array( $fields ) ) {
foreach( $fields as $group => $fields ) {
delete_option( $group );
}
}
// Fire an action when WPGraphQL is de-activating
do_action( 'graphql_deactivate' );
}