PluginProbe
eRecht24 Legal Texts / trunk
eRecht24 Legal Texts vtrunk
4.1.0 4.0.5 4.0.4 4.0.3 trunk 4.0.0 4.0.1 4.0.2
erecht24 / uninstall.php

uninstall.php in eRecht24 Legal Texts trunk, at uninstall.php

101 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin uninstall cleanup.
4 *
5 * @package ERecht24LegalText
6 */
7
8 defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
9
10 $erecht24_option_name = 'erecht24_legal_text_settings';
11
12 /**
13 * Decrypt a value stored by Settings::encrypt_value() – standalone copy for uninstall context.
14 *
15 * @param string $value Stored value.
16 * @return string
17 */
18 $erecht24_decrypt = static function ( string $value ): string {
19 if ( '' === $value || 0 !== strpos( $value, 'enc::' ) ) {
20 return $value;
21 }
22 if ( ! function_exists( 'openssl_decrypt' ) || ! defined( 'AUTH_KEY' ) || ! defined( 'AUTH_SALT' ) ) {
23 return '';
24 }
25 $decoded = base64_decode( substr( $value, 5 ), true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- decoding binary IV+ciphertext, not obfuscation
26 if ( false === $decoded || strlen( $decoded ) < 17 ) {
27 return '';
28 }
29 $key = substr( hash( 'sha256', AUTH_KEY . AUTH_SALT ), 0, 32 );
30 $iv = substr( $decoded, 0, 16 );
31 $enc = substr( $decoded, 16 );
32 $dec = openssl_decrypt( $enc, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv );
33 return false !== $dec ? $dec : '';
34 };
35
36 $erecht24_delete_registered_client = static function () use ( $erecht24_option_name, $erecht24_decrypt ): void {
37 $settings = get_option( $erecht24_option_name, array() );
38
39 if ( ! is_array( $settings ) ) {
40 return;
41 }
42
43 $raw_key = ! empty( $settings['api_key'] ) && is_scalar( $settings['api_key'] ) ? (string) $settings['api_key'] : '';
44 $api_key = sanitize_text_field( $erecht24_decrypt( $raw_key ) );
45 $client_id = ! empty( $settings['client_id'] ) ? absint( $settings['client_id'] ) : 0;
46
47 if ( '' === $api_key || 1 > $client_id || ! function_exists( 'wp_remote_request' ) ) {
48 return;
49 }
50
51 wp_remote_request(
52 'https://api.e-recht24.de/v1/clients/' . absint( $client_id ),
53 array(
54 'method' => 'DELETE',
55 'timeout' => 5,
56 'redirection' => 3,
57 'headers' => array(
58 'Accept' => 'application/json',
59 'Content-Type' => 'application/json; charset=utf-8',
60 'eRecht24' => $api_key,
61 'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . home_url( '/' ),
62 ),
63 )
64 );
65 };
66
67 if ( is_multisite() ) {
68 $erecht24_sites = get_sites(
69 array(
70 'fields' => 'ids',
71 'number' => 0,
72 )
73 );
74
75 foreach ( $erecht24_sites as $erecht24_site_id ) {
76 switch_to_blog( (int) $erecht24_site_id );
77 $erecht24_delete_registered_client();
78 delete_option( $erecht24_option_name );
79 delete_option( 'erecht24_v3_migrated' );
80 delete_option( 'erecht24_api_key_settings' );
81 delete_option( 'erecht24_api_client_settings' );
82 delete_option( 'erecht24_google_analytics_settings' );
83 delete_option( 'erecht24_imprint_settings' );
84 delete_option( 'erecht24_privacy_policy_settings' );
85 delete_option( 'erecht24_privacy_policy_social_media_settings' );
86 restore_current_blog();
87 }
88
89 return;
90 }
91
92 $erecht24_delete_registered_client();
93 delete_option( $erecht24_option_name );
94 delete_option( 'erecht24_v3_migrated' );
95 delete_option( 'erecht24_api_key_settings' );
96 delete_option( 'erecht24_api_client_settings' );
97 delete_option( 'erecht24_google_analytics_settings' );
98 delete_option( 'erecht24_imprint_settings' );
99 delete_option( 'erecht24_privacy_policy_settings' );
100 delete_option( 'erecht24_privacy_policy_social_media_settings' );
101