Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Database
File: Logger.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Abstracts_logger
[3] Fix | Delete
*
[4] Fix | Delete
* Handles custom logging for Ninja Forms and Ninja Forms Extensions.
[5] Fix | Delete
*
[6] Fix | Delete
* PSR-3 and WordPress Compliant where applicable.
[7] Fix | Delete
*/
[8] Fix | Delete
final class NF_Database_Logger extends NF_Abstracts_Logger
[9] Fix | Delete
{
[10] Fix | Delete
protected $_current = array();
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Logs with an arbitrary level.
[14] Fix | Delete
*
[15] Fix | Delete
* @param mixed $level
[16] Fix | Delete
* @param string $message
[17] Fix | Delete
* @param array $context
[18] Fix | Delete
* @return null
[19] Fix | Delete
*/
[20] Fix | Delete
public function log( $level, $message, array $context = array() )
[21] Fix | Delete
{
[22] Fix | Delete
$message = $this->interpolate( $message, $context );
[23] Fix | Delete
[24] Fix | Delete
// Create Log Object
[25] Fix | Delete
$log = Ninja_Forms()->form()->object()->get();
[26] Fix | Delete
$log->update_setting( 'type', 'log' )
[27] Fix | Delete
->update_setting( 'level', $level )
[28] Fix | Delete
->update_setting( 'message', $message );
[29] Fix | Delete
[30] Fix | Delete
foreach ($context as $key => $value) {
[31] Fix | Delete
$log->update_setting($key, maybe_serialize($value));
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
// Add to Database
[35] Fix | Delete
$log->save();
[36] Fix | Delete
[37] Fix | Delete
// Add to Current Property Array
[38] Fix | Delete
$this->_current[ $level ][] = $log;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Get current logs for the request lifecycle
[43] Fix | Delete
*
[44] Fix | Delete
* @param string $level
[45] Fix | Delete
* @return array
[46] Fix | Delete
*/
[47] Fix | Delete
public function get_current( $level = '' )
[48] Fix | Delete
{
[49] Fix | Delete
return ( $level ) ? $this->_current[ $level ] : $this->_current;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Interpolates context values into the message placeholders.
[54] Fix | Delete
*
[55] Fix | Delete
* @param $message
[56] Fix | Delete
* @param array $context
[57] Fix | Delete
* @return string
[58] Fix | Delete
*/
[59] Fix | Delete
protected function interpolate( $message, array $context = array() )
[60] Fix | Delete
{
[61] Fix | Delete
// build a replacement array with braces around the context keys
[62] Fix | Delete
$replace = array();
[63] Fix | Delete
foreach ($context as $key => $val) {
[64] Fix | Delete
[65] Fix | Delete
if( is_array( $val ) ) continue;
[66] Fix | Delete
[67] Fix | Delete
$replace['{' . $key . '}'] = $val;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
// interpolate replacement values into the message and return
[71] Fix | Delete
return strtr($message, $replace);
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function