-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
deactivation.php
73 lines (60 loc) · 1.49 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Deactivation Hook
*
* @package WPGraphql\Login
* @since 0.0.1
*/
declare( strict_types = 1 );
namespace WPGraphQL\Login;
/**
* Runs when WPGraphQL is de-activated.
*
* This cleans up data that WPGraphQL stores.
*
* @since 0.0.1
*/
function deactivation_callback(): callable {
return static function (): void {
// Fire an action when WPGraphQL is de-activating.
do_action( 'graphql_login_deactivate' );
// Delete data during activation.
delete_data();
};
}
/**
* Delete data on deactivation.
*
* @since 0.0.1
*/
function delete_data(): void {
// Check if the plugin is set to delete data or not.
$delete_data = graphql_login_get_setting( 'delete_data_on_deactivate' );
// Bail if not set to delete.
if ( empty( $delete_data ) ) {
return;
}
// Delete plugin version.
delete_option( 'wp_graphql_login_version' );
// Initialize the settings API.
$settings = \WPGraphQL\Login\Admin\Settings::get_all_settings();
if ( empty( $settings ) ) {
return;
}
// Get all the setting keys across various groups.
$settings = array_reduce(
$settings,
static function ( $carry, $item ) {
return array_merge( $carry, array_keys( $item ) );
},
[]
);
// Loop over the registered settings fields and delete the options.
if ( ! empty( $settings ) && is_array( $settings ) ) {
foreach ( array_keys( $settings ) as $option_name ) {
delete_option( $option_name );
}
}
// Fire an action when data is deleted.
do_action( 'graphql_login_delete_data' );
}