/** * Add log when announcement create or edit * * @since 0.1 * * @param string $new_status * @param string $old_status * @param object $post * * @return void */ public function announcment_log($new_status, $old_status, $post) { if ('erp_hr_announcement' != $post->post_type) { return; } if ('publish' !== $new_status) { return; } $overview = add_query_arg(array('page' => 'erp-hr'), admin_url('admin.php')); if ('publish' === $old_status) { $message = sprintf("<strong>%s</strong> announcement has been edited", $post->post_title); $change_type = 'edit'; } else { $message = sprintf("<strong>%s</strong> announcement has been created", $post->post_title); $change_type = 'add'; } erp_log()->add(['sub_component' => 'announcement', 'message' => $message, 'created_by' => get_current_user_id(), 'changetype' => $change_type]); }
/** * Prepare the class items * * @return void */ function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $per_page = 10; $current_page = $this->get_pagenum(); $offset = ($current_page - 1) * $per_page; $this->page_status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : '2'; $args = []; // only ncessary because we have sample data $args = array('offset' => $offset, 'number' => $per_page); if (isset($_REQUEST['filter_module']) && !empty($_REQUEST['filter_module'])) { $args['component'] = $_REQUEST['filter_module']; } if (isset($_REQUEST['filter_section']) && !empty($_REQUEST['filter_section'])) { $args['sub_component'] = $_REQUEST['filter_section']; } $this->items = erp_log()->get($args); $total_items = erp_log()->count($args); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); }