* Helper logging and debug functions.
* Check whether the plugin works in a debug mode.
function wpforms_debug(): bool {
if ( ( defined( 'WPFORMS_DEBUG' ) && true === WPFORMS_DEBUG ) && is_super_admin() ) {
* Filters wpforms_debug status.
* @param bool $debug WPForms debug status.
return (bool) apply_filters( 'wpforms_debug', $debug );
* Helper function to display debug data.
* @param mixed $data What to dump - can be any type.
* @param bool $do_echo Whether to print or return. The default is to print.
function wpforms_debug_data( $data, bool $do_echo = true ) {
if ( ! wpforms_debug() ) {
if ( is_array( $data ) || is_object( $data ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
$data = print_r( $data, true );
.wpforms-debug textarea {
background: #f6f7f7 !important;
font-family: Consolas, Menlo, Monaco, monospace;
.postbox .wpforms-debug {
.postbox .wpforms-debug:not(:first-of-type) {
.postbox .wpforms-debug textarea {
margin-top: 0 !important;
<div class="wpforms-debug">
<textarea readonly>=================== WPFORMS DEBUG ===================%s</textarea>
"\n\n" . esc_html( $data )
* Allow developers to determine whether the debug data should be displayed.
* Works only in debug mode (`WPFORMS_DEBUG` constant is `true`).
* @param bool $allow_display True by default.
$allow_display = apply_filters( 'wpforms_debug_data_allow_display', true );
if ( $do_echo && $allow_display ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* @param string $title Title of a log message.
* @param mixed $message Content of a log message.
* @param array $args Expected keys: type, form_id, meta, parent, force.
function wpforms_log( $title = '', $message = '', $args = [] ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
// Skip if logs disabled in Tools -> Logs.
if ( empty( $args['force'] ) && ! wpforms_setting( 'logs-enable' ) ) {
* Compare error levels to determine if we should log.
* Current supported levels:
* - Conditional Logic (conditional_logic)
$types = ! empty( $args['type'] ) ? (array) $args['type'] : [ 'error' ];
// Skip invalid logs types.
$log_types = Log::get_log_types();
foreach ( $types as $key => $type ) {
if ( ! isset( $log_types[ $type ] ) ) {
* @param mixed $message Log message.
* @param string $title Log title.
* @param array $args Log arguments.
$message = apply_filters( 'wpforms_log_message', $message, $title, $args );
// Make arrays and objects look nice.
if ( is_array( $message ) || is_object( $message ) ) {
$message = '<pre>' . esc_html( print_r( $message, true ) ) . '</pre>'; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
// Filter logs types from Tools -> Logs page.
$logs_types = wpforms_setting( 'logs-types' );
if ( $logs_types && empty( array_intersect( $logs_types, $types ) ) ) {
// Filter user roles from Tools -> Logs page.
$current_user = function_exists( 'wp_get_current_user' ) ? wp_get_current_user() : null;
$current_user_id = $current_user->ID ?? 0;
$current_user_roles = $current_user->roles ?? [];
$logs_user_roles = wpforms_setting( 'logs-user-roles' );
if ( $logs_user_roles && empty( array_intersect( $logs_user_roles, $current_user_roles ) ) ) {
// Filter logs users from Tools -> Logs page.
$logs_users = wpforms_setting( 'logs-users' );
if ( $logs_users && ! in_array( $current_user_id, $logs_users, true ) ) {
$log = wpforms()->obj( 'log' );
if ( ! $log || ! method_exists( $log, 'add' ) ) {
isset( $args['form_id'] ) ? absint( $args['form_id'] ) : 0,
isset( $args['parent'] ) ? absint( $args['parent'] ) : 0,
* Wrapper for set_time_limit to see if it is enabled.
* @param int $limit Time limit.
function wpforms_set_time_limit( $limit = 0 ) {
if ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) ) {
@set_time_limit( $limit ); // @codingStandardsIgnoreLine