예제 #1
0
 /**
  * Registers the log post type.
  *
  * @since 1.0.0
  */
 public function register_post_type()
 {
     $log_args = array('labels' => array('name' => __('WPForms Logs', 'wpforms'), 'menu_name' => __('Logs', 'wpforms')), 'public' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_ui' => false, 'query_var' => false, 'rewrite' => false, 'capability_type' => 'post', 'supports' => array('title', 'editor'), 'can_export' => false, 'show_in_menu' => 'wpforms-overview');
     if (wpforms_debug()) {
         $log_args['show_ui'] = true;
     }
     register_post_type('wpforms_log', apply_filters('wpforms_log_cpt', $log_args));
 }
예제 #2
0
/**
 * Log helper.
 *
 * @since 1.0.0
 * @param string $title
 * @param string $message
 * @param array $args
 */
function wpforms_log($title = '', $message = '', $args = array())
{
    // Require log title
    if (empty($title)) {
        return;
    }
    // Force logging everything when in debug mode
    if (!wpforms_debug()) {
        /**
         * Compare error levels to determine if we should log.
         * Current supported levels:
         * - Errors (error)
         * - Spam (spam)
         * - Entries (entry)
         * - Payments (payment)
         * - Providers (provider)
         * - Conditional Logic (conditional_logic)
         */
        $type = !empty($args['type']) ? (array) $args['type'] : array('error');
        $levels = get_option('wpforms_logging', array());
        $lvls = array_intersect($type, $levels);
        if (empty($lvls)) {
            return;
        }
    }
    // Meta
    if (!empty($args['form_id'])) {
        $meta = array('form' => absint($args['form_id']));
    } elseif (!empty($args['meta'])) {
        $meta = $args['meta'];
    } else {
        $meta = '';
    }
    // Parent
    $parent = !empty($args['parent']) ? $args['parent'] : 0;
    // Make arrays and objects look nice
    if (is_array($message) || is_object($message)) {
        $message = '<pre>' . print_r($message, true) . '</pre>';
    }
    // Create log entry
    wpforms()->logs->add($title, $message, $parent, $parent, $meta);
}