| 1 |
<?php |
| 2 |
/** |
| 3 |
* Runs when WPGraphQL is de-activated |
| 4 |
* |
| 5 |
* This cleans up data that WPGraphQL stores |
| 6 |
* |
| 7 |
* @return void |
| 8 |
*/ |
| 9 |
function graphql_deactivation_callback() { |
| 10 |
|
| 11 |
if ( ! graphql_can_load_plugin() ) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
// Fire an action when WPGraphQL is de-activating |
| 16 |
do_action( 'graphql_deactivate' ); |
| 17 |
|
| 18 |
// Delete data during activation |
| 19 |
delete_graphql_data(); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Delete data on deactivation |
| 24 |
*/ |
| 25 |
function delete_graphql_data(): void { |
| 26 |
|
| 27 |
if ( ! class_exists( 'WPGraphQL' ) ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
// Check if the plugin is set to delete data or not |
| 32 |
$delete_data = get_graphql_setting( 'delete_data_on_deactivate' ); |
| 33 |
|
| 34 |
// If data is not set to delete, stop now |
| 35 |
if ( 'on' !== $delete_data ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
// Delete graphql version |
| 40 |
delete_option( 'wp_graphql_version' ); |
| 41 |
|
| 42 |
// Initialize the settings API |
| 43 |
$settings = new WPGraphQL\Admin\Settings\Settings(); |
| 44 |
$settings->init(); |
| 45 |
$settings->register_settings(); |
| 46 |
|
| 47 |
// Get all the registered settings fields |
| 48 |
$fields = $settings->settings_api->get_settings_fields(); |
| 49 |
|
| 50 |
// Loop over the registered settings fields and delete the options |
| 51 |
if ( ! empty( $fields ) && is_array( $fields ) ) { |
| 52 |
foreach ( $fields as $group => $fields ) { |
| 53 |
delete_option( $group ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
do_action( 'graphql_delete_data' ); |
| 58 |
} |
| 59 |
|