Skip to content

Instantly share code, notes, and snippets.

@polevaultweb
Created November 4, 2019 22:01
Show Gist options
  • Save polevaultweb/0f60fb6856c0a26fccdae2b76a861cd7 to your computer and use it in GitHub Desktop.
Save polevaultweb/0f60fb6856c0a26fccdae2b76a861cd7 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'pre_update_option_wp-oauth2-tokens', function ( $value, $old_value ) {
if ( empty( $old_value['google'] ) ) {
// Google not connected
return $value;
}
if ( ! empty( $old_value['google'] ) && ! empty( $value['google'] ) ) {
// Google still connected
return $value;
}
// Dropbox was connected, not anymore - let's trace what called this update
error_log( 'NF FU Google Disconnection' );
error_log( print_r( pvw_generateCallTrace(), true ) );
return $value;
}, 10, 2 );
function pvw_generateCallTrace() {
$e = new Exception();
$trace = explode( "\n", $e->getTraceAsString() );
// reverse array to make steps line up chronologically
$trace = array_reverse( $trace );
array_shift( $trace ); // remove {main}
array_pop( $trace ); // remove call to this method
$length = count( $trace );
$result = array();
for ( $i = 0; $i < $length; $i ++ ) {
$result[] = ( $i + 1 ) . ')' . substr( $trace[ $i ], strpos( $trace[ $i ], ' ' ) ); // replace '#someNum' with '$i)', set the right ordering
}
return "\t" . implode( "\n\t", $result );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment