// https://stackoverflow.com/questions/33265780/how-to-print-to-console-from-a-php-file-in-wordpress // Source - https://stackoverflow.com/a/67449528 // Posted by Martin Braun, modified by community. See post 'Timeline' for change history // Retrieved 2026-06-02, License - CC BY-SA 4.0 function console_log(): string { list( , $caller ) = debug_backtrace( false ); $action = current_action(); $encoded_args = []; foreach ( func_get_args() as $arg ) try { if ( is_object( $arg ) ) { $extract_props = function( $obj ) use ( &$extract_props ): array { $members = []; $class = get_class( $obj ); foreach ( ( new ReflectionClass( $class ) )->getProperties() as $prop ) { $prop->setAccessible( true ); $name = $prop->getName(); if ( isset( $obj->{$name} ) ) { $value = $prop->getValue( $obj ); if ( is_array( $value ) ) { $members[$name] = []; foreach ( $value as $item ) { if ( is_object( $item ) ) { $itemArray = $extract_props( $item ); $members[$name][] = $itemArray; } else { $members[$name][] = $item; } } } else if ( is_object( $value ) ) { $members[$name] = $extract_props( $value ); } else $members[$name] = $value; } } return $members; }; $encoded_args[] = json_encode( $extract_props( $arg ) ); } else { $encoded_args[] = json_encode( $arg ); } } catch ( Exception $ex ) { $encoded_args[] = '`' . print_r( $arg, true ) . '`'; } $msg = '`📜`, `' . ( array_key_exists( 'class', $caller ) ? $caller['class'] : "\x3croot\x3e" ) . '\\\\' . $caller['function'] . '()`, ' . ( strlen( $action ) > 0 ? '`🪝`, `' . $action . '`, ' : '' ) . '` ➡️ `, ' . implode( ', ', $encoded_args ); $html = ''; add_action( 'wp_enqueue_scripts', function() use ( $html ) { echo $html; } ); add_action( 'admin_enqueue_scripts', function() use ( $html ) { echo $html; } ); error_log( $msg ); return $html; }