Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
100.00% covered (success)
100.00%
3 / 3
CRAP
n/a
0 / 0
bh_wp_autologin_urls_clear_transients
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
bh_wp_autologin_urls_delete_settings
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
bh_wp_autologin_urls_drop_table
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Fired when the plugin is uninstalled.
4 *
5 * When populating this file, consider the following flow
6 * of control:
7 *
8 * - This method should be static
9 * - Check if the $_REQUEST content actually is the plugin name
10 * - Run an admin referrer check to make sure it goes through authentication
11 * - Verify the output of $_GET makes sense
12 * - Repeat with other user roles. Best directly by using the links/query string parameters.
13 * - Repeat things for multisite. Once for a single site in the network, once sitewide.
14 *
15 * This file may be updated more in future version of the Boilerplate; however, this is the
16 * general skeleton and outline for how the file should work.
17 *
18 * For more information, see the following discussion:
19 * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
20 *
21 * @link       https://BrianHenry.ie
22 * @since      1.0.0
23 *
24 * @package    bh-wp-autologin-urls
25 */
26
27// If uninstall not called from WordPress, then exit.
28if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
29    throw new \Exception( 'WP_UNINSTALL_PLUGIN not defined' );
30}
31
32use BrianHenryIE\WP_Autologin_URLs\Settings_Interface;
33
34/**
35 * Delete the passwords stored as transients in wp_options.
36 *
37 * phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
38 * phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
39 */
40function bh_wp_autologin_urls_clear_transients(): void {
41    global $wpdb;
42
43    $wpdb->query(
44        $wpdb->prepare(
45            "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
46            $wpdb->esc_like( '_transient_bh_autologin_bh_autologin_%' ),
47            $wpdb->esc_like( '_transient_timeout_bh_autologin_%' )
48        )
49    );
50}
51bh_wp_autologin_urls_clear_transients();
52
53/**
54 * Delete each of the wp_options entries used by the plugin.
55 *
56 * @see Settings_Interface
57 */
58function bh_wp_autologin_urls_delete_settings(): void {
59
60    // TODO: ReflectionClass::getConstants.
61
62    delete_option( 'bh_wp_autologin_urls_seconds_until_expiry' );
63    delete_option( 'bh_wp_autologin_urls_is_admin_enabled' );
64    delete_option( 'bh_wp_autologin_urls_subject_filter_regex_dictionary' );
65}
66bh_wp_autologin_urls_delete_settings();
67
68
69/**
70 * Delete the database table used to save the passwords.
71 *
72 * phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
73 */
74function bh_wp_autologin_urls_drop_table(): void {
75    global $wpdb;
76
77    $wpdb->query(
78        "DROP TABLE IF EXISTS {$wpdb->prefix}autologin_urls"
79    );
80}
81bh_wp_autologin_urls_drop_table();