PluginProbe
WPGraphQL / 2.22.1
WPGraphQL v2.22.1
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / deactivation.php

deactivation.php in WPGraphQL 2.22.1, at deactivation.php

59 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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