| @@ -8,8 +8,13 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | namespace MainWP\Dashboard\Module\Log; |
| 11 | 11 | |
| 12 | +// Exit if accessed directly. | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + exit; | |
| 15 | +} | |
| 16 | + | |
| 12 | 17 | /** |
| 13 | 18 | * Class Log_Connector |
| 14 | 19 | * |
| 15 | 20 | * @package MainWP\Dashboard |
| @@ -28,8 +33,14 @@ | ||
| 28 | 33 | * @var array |
| 29 | 34 | */ |
| 30 | 35 | public $actions = array(); |
| 31 | 36 | |
| 37 | + /** | |
| 38 | + * Filter registered for this connector | |
| 39 | + * | |
| 40 | + * @var array | |
| 41 | + */ | |
| 42 | + public $filters = array(); | |
| 32 | 43 | |
| 33 | 44 | /** |
| 34 | 45 | * Holds connector registration status flag. |
| 35 | 46 | * |
| @@ -58,8 +69,14 @@ | ||
| 58 | 69 | foreach ( $this->actions as $action ) { |
| 59 | 70 | add_action( $action, array( $this, 'callback' ), 10, 99 ); |
| 60 | 71 | } |
| 61 | 72 | |
| 73 | + if ( ! empty( $this->filters ) && is_array( $this->filters ) ) { | |
| 74 | + foreach ( $this->filters as $filter ) { | |
| 75 | + add_action( $filter, array( $this, 'callback' ), 10, 99 ); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 62 | 79 | $this->is_registered = true; |
| 63 | 80 | } |
| 64 | 81 | |
| 65 | 82 | /** |
| @@ -110,8 +127,19 @@ | ||
| 110 | 127 | $user_id = $data['user_id']; |
| 111 | 128 | $state = $data['state']; |
| 112 | 129 | } |
| 113 | 130 | return call_user_func_array( array( Log_Manager::instance()->log, 'log' ), compact( 'connector', 'message', 'args', 'site_id', 'context', 'action', 'state', 'user_id' ) ); |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Log record. | |
| 135 | + * | |
| 136 | + * @param array $recordarr sprintf (and extra) arguments to use. | |
| 137 | + * | |
| 138 | + * @return bool|WP_Error True if updated, otherwise false|WP_Error | |
| 139 | + */ | |
| 140 | + public function log_record( $recordarr ) { //phpcs:ignore -- NOSONAR - compatible. | |
| 141 | + return call_user_func_array( array( Log_Manager::instance()->log, 'log_record' ), compact( 'recordarr' ) ); | |
| 114 | 142 | } |
| 115 | 143 | |
| 116 | 144 | /** |
| 117 | 145 | * Compare two values and return changed keys if they are arrays |