', 'name' => __( 'Name', 'nodebook' ), 'domain' => __( 'Domain', 'nodebook' ), 'contacts' => __( 'Contacts', 'nodebook' ), 'industry' => __( 'Industry', 'nodebook' ), 'city' => __( 'City', 'nodebook' ), 'country' => __( 'Country', 'nodebook' ), 'created' => __( 'Created', 'nodebook' ), ) ); } protected function get_sortable_columns() { return array( 'name' => array( 'name', false ), 'domain' => array( 'domain', false ), 'contacts' => array( 'contacts', true ), 'city' => array( 'city', false ), 'country' => array( 'country', false ), 'created' => array( 'created_at', true ), ); } protected function get_bulk_actions() { return array_filter( array( 'delete' => Nodebook_Team::can_delete() ? __( 'Delete', 'nodebook' ) : '', 'export' => Nodebook_Team::can_export() ? __( 'Export selected to CSV', 'nodebook' ) : '', ) ); } public static function process_bulk() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- nonce verified below once an action is present. $action = ''; foreach ( array( 'action', 'action2' ) as $k ) { if ( ! empty( $_REQUEST[ $k ] ) && '-1' !== $_REQUEST[ $k ] ) { $action = sanitize_key( wp_unslash( $_REQUEST[ $k ] ) ); break; } } $ids = isset( $_REQUEST['company'] ) ? array_map( 'absint', (array) wp_unslash( $_REQUEST['company'] ) ) : array(); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( ! in_array( $action, array( 'delete', 'export' ), true ) || ! $ids ) { return; } check_admin_referer( 'bulk-companies' ); if ( ! current_user_can( Nodebook_Admin::cap() ) || ( 'delete' === $action && ! Nodebook_Team::can_delete() ) || ( 'export' === $action && ! Nodebook_Team::can_export() ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'nodebook' ), 403 ); } if ( 'export' === $action ) { Nodebook_Csv::export_companies( array( 'ids' => $ids ) ); } Nodebook_Companies::delete( $ids ); Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-companies' ), 'deleted' ); } public function prepare_items() { $per_page = $this->get_items_per_page( 'nodebook_per_page', 25 ); // phpcs:disable WordPress.Security.NonceVerification.Recommended -- search/sort only. $r = Nodebook_Companies::query( array( 'search' => isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : '', 'orderby' => isset( $_GET['orderby'] ) ? sanitize_key( wp_unslash( $_GET['orderby'] ) ) : 'name', 'order' => isset( $_GET['order'] ) ? sanitize_key( wp_unslash( $_GET['order'] ) ) : 'asc', 'per_page' => $per_page, 'page' => $this->get_pagenum(), ) ); // phpcs:enable WordPress.Security.NonceVerification.Recommended $this->items = $r['rows']; $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), 'name' ); $this->set_pagination_args( array( 'total_items' => $r['total'], 'per_page' => $per_page, ) ); } public function no_items() { esc_html_e( 'No companies yet. They are created from form fields like “Company” and from business email domains.', 'nodebook' ); } protected function column_cb( $item ) { return ''; } protected function column_name( $item ) { $edit = Nodebook_Admin::url( 'nodebook-companies', array( 'action' => 'edit', 'id' => $item['id'] ) ); $delete = wp_nonce_url( admin_url( 'admin-post.php?action=nodebook_delete_company&id=' . $item['id'] ), 'nodebook_delete_company_' . $item['id'] ); $actions = array( 'edit' => '' . esc_html__( 'Open', 'nodebook' ) . '', 'delete' => '' . esc_html__( 'Delete', 'nodebook' ) . '', ); if ( ! Nodebook_Team::can_delete() ) { unset( $actions['delete'] ); } return '' . esc_html( $item['name'] ) . '' . $this->row_actions( $actions ); } protected function column_default( $item, $col ) { switch ( $col ) { case 'domain': return $item['domain'] ? esc_html( $item['domain'] ) : '—'; case 'contacts': return '' . esc_html( number_format_i18n( (int) $item['contacts'] ) ) . ''; case 'created': return wp_kses( Nodebook_Admin::ago( $item['created_at'] ), Nodebook_Admin::KSES ); default: return isset( $item[ $col ] ) ? esc_html( $item[ $col ] ) : esc_html( (string) apply_filters( 'nodebook_companies_column_' . $col, '', $item ) ); } } }