Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created July 30, 2020 17:15
Show Gist options
  • Save jchristopher/ef0b528251d736f4a7835b390644cd0d to your computer and use it in GitHub Desktop.
Save jchristopher/ef0b528251d736f4a7835b390644cd0d to your computer and use it in GitHub Desktop.
Log backtrace for SearchWP Post edit event
<?php
add_action( 'searchwp\source\post\drop', function( $args ) {
do_action( 'searchwp\debug\log', "Drop event for post {$args['post_id']}", 'backtrace' );
$e = new \Exception();
$trace = explode( "\n", $e->getTraceAsString() );
$trace = array_reverse( $trace );
array_shift( $trace );
array_pop( $trace );
$length = count( $trace );
$result = [];
for ( $i = 0; $i < $length; $i++ ) {
$result[] = ( $i + 1 ) . ')' . substr( $trace[ $i ], strpos( $trace[ $i ], ' ') );
}
do_action( 'searchwp\debug\log', "\n\t" . implode( "\n\t", $result ), 'backtrace' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment