Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active December 3, 2019 21:09
Show Gist options
  • Save woogists/1aaf78be99c6210435eae6d9d5e6aa09 to your computer and use it in GitHub Desktop.
Save woogists/1aaf78be99c6210435eae6d9d5e6aa09 to your computer and use it in GitHub Desktop.
[Extending][WooCommerce Plugin Developer Handbook] log WooCommerce data that can be useful for debugging purposes.
$label = __( 'Enable Logging', 'your-textdomain-here' );
$description = __( 'Enable the logging of errors.', 'your-textdomain-here' );
if ( defined( 'WC_LOG_DIR' ) ) {
$log_url = add_query_arg( 'tab', 'logs', add_query_arg( 'page', 'wc-status', admin_url( 'admin.php' ) ) );
$log_key = 'your-plugin-slug-here-' . sanitize_file_name( wp_hash( 'your-plugin-slug-here' ) ) . '-log';
$log_url = add_query_arg( 'log_file', $log_key, $log_url );
$label .= ' | ' . sprintf( __( '%1$sView Log%2$s', 'your-textdomain-here' ), '<a href="' . esc_url( $log_url ) . '">', '</a>' );
}
$form_fields['wc_yourpluginslug_debug'] = array(
'title' => __( 'Debug Log', 'your-textdomain-here' ),
'label' => $label,
'description' => $description,
'type' => 'checkbox',
'default' => 'no'
);
@alexminza
Copy link

Does not seem to work with the new log file name scheme that includes the file date - the link defaults to the first file in the logs list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment