a8cteam51 / safety-net

Scrub options, deactivate denylisted plugins, and delete user data on development sites.
17 stars 1 forks source link

Deactivate webhooks #111

Closed NickGreen closed 5 months ago

NickGreen commented 10 months ago

Can't think of any reason why a development site should be sending information to a 3rd party website via webhooks, so let's see if we can disable all of the existing webhooks that you might find here: /wp-admin/admin.php?page=wc-settings&tab=advanced&section=webhooks

Alternately, we might be able to delete them if that's the best option.

Screenshot of webhooks settings page: SCR-20231113-nzif

NickGreen commented 5 months ago

I think we ought to be able to run something like this when the plugin is running its deletion stuff:

function disable_woocommerce_webhooks() {
    $webhooks = wc_get_webhooks( array( 'status' => 'active' ) );

    if ( ! empty( $webhooks ) ) {
        foreach ( $webhooks as $webhook_id ) {
            $webhook = new WC_Webhook( $webhook_id );
            $webhook->set_status( 'disabled' );
            $webhook->save();
        }
    }
}
NickGreen commented 5 months ago

Alternately, if we wanted to just wipe them, we could do so from the DB like this:

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_webhook');
DELETE FROM wp_posts WHERE post_type = 'shop_webhook';

EDIT: this is old info. Webhooks are now stored in the wp_wc_webhooks table

NickGreen commented 5 months ago

Did both here: https://github.com/a8cteam51/safety-net/pull/119