1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104:
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class Inbound_Logging_Automation {
static $log_limit;
public function __construct() {
self::$log_limit = apply_filters('inbound_automation_log_limit' , 500 );
}
public function add( $title = '', $message = '', $rule_id, $job_id , $type) {
$log_data = array(
'log_title' => $title,
'log_content' => base64_encode($message),
'rule_id' => $rule_id,
'job_id' => $job_id,
'log_type' => $type,
'log_datetime' => date( __('Y-m-d H:i:s' , 'ma' ) , current_time( 'timestamp', 0 ) )
);
return self::insert_log( $log_data );
}
function insert_log( $log_data = array() ) {
$logs_array = Inbound_Logging_Automation::get_logs( $log_data['rule_id'] );
$logs_array[] = $log_data;
if ( count($logs_array) > self::$log_limit ) {
$trim = count($logs_array) - self::$log_limit;
$logs_array = array_slice($logs_array, $trim);
}
update_post_meta( $log_data['rule_id'] , '_automation_logs' , json_encode($logs_array) );
}
public function get_logs( $rule_id = 0 ) {
$logs_encoded = get_post_meta( $rule_id , '_automation_logs' , true );
if ( !$logs_encoded ) {
$logs_array = array();
} else {
$logs_array = json_decode( $logs_encoded , true );
}
if ( !is_array($logs_array) ) {
$logs_array = array();
}
return $logs_array;
}
public function get_log_count( $object_id = 0, $type = null, $meta_query = null, $date_query = null ) {
}
}
$GLOBALS['inbound_automation_logs'] = new Inbound_Logging_Automation();
function inbound_record_log( $title = '', $message = '', $rule_id = 0, $job_id = '', $type = null ) {
global $inbound_automation_logs;
$inbound_automation_logs->add( $title, $message, $rule_id, $job_id, $type );
}