'item', // singular name of the listed records 'plural' => 'items', // plural name of the listed records 'ajax' => false // does this table support ajax? )); } /** * Returns the default column item * * @param object $item * @param string $column_name * @return void */ public function column_default($item, $column_name) { return $item[$column_name]; } /** * Returns cb column html to be rendered. * * @param array $item - data for the columns on the current row * * @return string - the html to be rendered */ public function column_cb($item) { return sprintf( '', /* $1%s */ $this->_args['singular'], // Let's simply repurpose the table's singular label /* $2%s */ $item['id'] // The value of the checkbox should be the record's id ); } /** * Returns created column html to be rendered. * * @param array - data for the columns on the current row * * @return string - the html to be rendered */ public function column_created($item) { $tab = strip_tags($_REQUEST['tab']); $delete_url = sprintf('admin.php?page=%s&tab=%s&action=%s&id=%s', AIOWPSEC_MAIN_MENU_SLUG, $tab, 'delete_audit_log', $item['id']); // Add nonce to delete URL $delete_url_nonce = wp_nonce_url($delete_url, "delete_audit_log", "aiowps_nonce"); // Build row actions $actions = array( 'delete' => ''.__('Delete').'', ); // Return the user_login contents return sprintf('%1$s %2$s', /* $1%s */ date('Y-m-d H:i:s', $item['created']), /* $2%s */ $this->row_actions($actions) ); } /** * Returns event type column html to be rendered. * * @param array - data for the columns on the current row * * @return string - the html to be rendered */ public function column_event_type($item) { if (empty($item['event_type'])) return __('No event type available.', 'all-in-one-wp-security-and-firewall'); $output = isset(AIOWPSecurity_Audit_Events::$event_types[$item['event_type']]) ? AIOWPSecurity_Audit_Events::$event_types[$item['event_type']] : $item['event_type']; return $output; } /** * Returns details column html to be rendered. * * @param array - data for the columns on the current row * * @return string - the html to be rendered */ public function column_details($item) { $details = json_decode($item['details'], true); if (!is_array($details)) return $item['details']; if (array_key_exists('core_updated', $details)) { $info = $details['core_updated']; return sprintf(__('WordPress updated from version %s to %s', 'all-in-one-wp-security-and-firewall'), $info['old_version'], $info['new_version']); } elseif (array_key_exists('plugin', $details)) { $info = $details['plugin']; return sprintf(__('Plugin', 'all-in-one-wp-security-and-firewall').': %s %s %s (v%s)', $info['name'], $info['network'], $info['action'], $info['version']); } elseif (array_key_exists('theme', $details)) { $info = $details['theme']; if ('activated' == $info['action']) { return sprintf(__('Theme', 'all-in-one-wp-security-and-firewall').': %s %s', $info['name'], $info['action']); } else { return sprintf(__('Theme', 'all-in-one-wp-security-and-firewall').': %s %s %s (v%s)', $info['name'], $info['network'], $info['action'], $info['version']); } } elseif (array_key_exists('entity_changed', $details)) { $info = $details['entity_changed']; if ($info['entity']) { return sprintf(__('Entity: "%s" has changed, please check the stacktrace for more details', 'all-in-one-wp-security-and-firewall'), $info['entity']); } else { return __('An unknown entity has changed, please check the stacktrace for more details', 'all-in-one-wp-security-and-firewall'); } } elseif (array_key_exists('translation_updated', $details)) { $info = $details['translation_updated']; if ('core' == $info['type']) { return sprintf(__('Core %s translations updated to version %s', 'all-in-one-wp-security-and-firewall'), $info['language'], $info['version']); } elseif ('plugin' == $info['type']) { return sprintf(__('Plugin "%s" %s translations updated to version %s', 'all-in-one-wp-security-and-firewall'), $info['slug'], $info['language'], $info['version']); } elseif ('theme' == $info['type']) { return sprintf(__('Theme "%s" %s translations updated to version %s', 'all-in-one-wp-security-and-firewall'), $info['slug'], $info['language'], $info['version']); } } elseif (array_key_exists('failed_login', $details)) { $info = $details['failed_login']; if ($info['imported']) { return __('Event imported from the failed logins table', 'all-in-one-wp-security-and-firewall'); } elseif ($info['known']) { return sprintf(__('Failed login attempt with a known username: %s', 'all-in-one-wp-security-and-firewall'), $info['username']); } else { return sprintf(__('Failed login attempt with a unknown username: %s', 'all-in-one-wp-security-and-firewall'), $info['username']); } } elseif (array_key_exists('successful_login', $details)) { $info = $details['successful_login']; return sprintf(__('Successful login with username: %s', 'all-in-one-wp-security-and-firewall'), $info['username']); } elseif (array_key_exists('user_registration', $details)) { $info = $details['user_registration']; if ('admin' == $info['type']) { return sprintf(__('Admin %s registered new user: %s', 'all-in-one-wp-security-and-firewall'), $info['admin_username'], $info['registered_username']); } elseif ('pending' == $info['type']) { return sprintf(__('User %s registered and set to pending', 'all-in-one-wp-security-and-firewall'), $info['registered_username']); } elseif ('registered' == $info['type']) { return sprintf(__('User %s registered', 'all-in-one-wp-security-and-firewall'), $info['registered_username']); } } elseif (array_key_exists('table_migration', $details)) { $info = $details['table_migration']; if ($info['success']) { return sprintf(__('Successfully migrated the `%s` table data to the `%s` table', 'all-in-one-wp-security-and-firewall'), $info['from_table'], $info['to_table']); } else { return sprintf(__('Failed to migrate the `%s` table data to the `%s` table', 'all-in-one-wp-security-and-firewall'), $info['from_table'], $info['to_table']); } } return $item['details']; } /** * Returns stack trace column html to be rendered. * * @param array - data for the columns on the current row * * @return string - the html to be rendered */ public function column_stacktrace($item) { if (empty($item['stacktrace'])) return __('No stack trace available.', 'all-in-one-wp-security-and-firewall'); $stacktrace = maybe_unserialize($item['stacktrace']); ob_start(); var_dump($stacktrace); $stacktrace_output = ob_get_contents(); ob_end_clean(); $output = sprintf('%s', $item['id'], esc_html__('Stack trace', 'all-in-one-wp-security-and-firewall'), esc_html__('Show trace', 'all-in-one-wp-security-and-firewall')); $output .= sprintf('
', $item['id'], htmlspecialchars($stacktrace_output)); return $output; } /** * Sets the columns for the table * * @return array */ public function get_columns() { $columns = array( 'cb' => '', //Render a checkbox 'id' => 'ID', 'created' => __('Date and time', 'all-in-one-wp-security-and-firewall'), 'level' => __('Level', 'all-in-one-wp-security-and-firewall'), 'network_id' => __('Network ID', 'all-in-one-wp-security-and-firewall'), 'site_id' => __('Site ID', 'all-in-one-wp-security-and-firewall'), 'username' => __('Username', 'all-in-one-wp-security-and-firewall'), 'ip' => __('IP', 'all-in-one-wp-security-and-firewall'), 'event_type' => __('Event', 'all-in-one-wp-security-and-firewall'), 'details' => __('Details', 'all-in-one-wp-security-and-firewall'), 'stacktrace' => __('Stack trace', 'all-in-one-wp-security-and-firewall') ); return $columns; } /** * Sets which of the columns the table data can be sorted by * * @return array */ public function get_sortable_columns() { $sortable_columns = array( 'created' => array('created', false), 'network_id' => array('network_id', false), 'site_id' => array('site_id', false), 'level' => array('level', false), 'username' => array('username', false), 'ip' => array('ip', false), 'event_type' => array('event_type', false), 'details' => array('details', false), 'stacktrace' => array('stacktrace', false) ); return $sortable_columns; } /** * This function will display a list of bulk actions for the list table * * @return void */ public function get_bulk_actions() { $actions = array( 'delete_all' => __('Delete all', 'all-in-one-wp-security-and-firewall'), 'delete_selected' => __('Delete selected', 'all-in-one-wp-security-and-firewall'), 'delete_filtered' => __('Delete filtered', 'all-in-one-wp-security-and-firewall') ); return $actions; } /** * This function will process the bulk action request, $search_term and $filters are only used if the user is trying to bulk delete the filtered items * * @param string $search_term - the search string * @param array $filters - the filters * * @return void */ private function process_bulk_action($search_term, $filters) { if (empty($_REQUEST['_wpnonce']) || !isset($_REQUEST['_wp_http_referer'])) return; $result = AIOWPSecurity_Utility_Permissions::check_nonce_and_user_cap($_REQUEST['_wpnonce'], 'bulk-items'); if (is_wp_error($result)) return; global $wpdb; $audit_log_tbl = AIOWPSEC_TBL_AUDIT_LOG; if ('delete_all' === $this->current_action()) { // Process delete bulk actions $this->delete_audit_event_records(array(), true); } elseif ('delete_selected' === $this->current_action()) { if (!isset($_REQUEST['item'])) { AIOWPSecurity_Admin_Menu::show_msg_error_st(__('Please select some records using the checkboxes', 'all-in-one-wp-security-and-firewall')); } else { $this->delete_audit_event_records($_REQUEST['item']); } } elseif ('delete_filtered' === $this->current_action()) { $where_sql = $this->get_audit_list_where_sql($search_term, $filters); $results = $wpdb->get_results("SELECT id FROM {$audit_log_tbl} {$where_sql}", 'ARRAY_A'); $items = array_column($results, 'id'); $this->delete_audit_event_records($items); } } /** * Outputs extra controls to be displayed between bulk actions and pagination * * @param string $which - where we are outputting content (top or bottom) * * @return void */ protected function extra_tablenav($which) { switch ($which) { case 'top': ?>