'tablepress-table', // Singular name of the listed records. 'plural' => 'tablepress-editor-button-list', // Plural name of the listed records. 'ajax' => false, // Does this list table support AJAX? 'screen' => get_current_screen(), // WP_Screen object. ) ); } /** * Sets the data items (here: tables) that are to be displayed by the List Tables, and their original count. * * @since 1.0.0 * * @param array $items Tables to be displayed in the List Table. */ public function set_items( array $items ) { $this->items = $items; $this->items_count = count( $items ); } /** * Checks whether the user has permissions for certain AJAX actions. * (not used, but must be implemented in this child class) * * @since 1.0.0 * * @return bool true (Default value). */ public function ajax_user_can() { return true; } /** * Gets a list of columns in this List Table. * * Format: 'internal-name' => 'Column Title'. * * @since 1.0.0 * * @return array List of columns in this List Table. */ public function get_columns() { $columns = array( // "name" is special in WP, which is why we prefix every entry here, to be safe! 'table_id' => __( 'ID', 'tablepress' ), 'table_name' => __( 'Table Name', 'tablepress' ), 'table_description' => __( 'Description', 'tablepress' ), 'table_action' => __( 'Action', 'tablepress' ), ); return $columns; } /** * Gets a list of columns that are sortable. * * Format: 'internal-name' => array( $field for $item[ $field ], true for already sorted ). * * @since 1.0.0 * * @return array List of sortable columns in this List Table. */ protected function get_sortable_columns() { // No sorting on the Empty List placeholder. if ( ! $this->has_items() ) { return array(); } $sortable_columns = array( 'table_id' => array( 'id', true ), // true means its already sorted. 'table_name' => array( 'name', false ), 'table_description' => array( 'description', false ), ); return $sortable_columns; } /** * Gets the name of the default primary column. * * @since 1.7.0 * * @return string Name of the default primary column, in this case, the table name. */ protected function get_default_primary_column_name() { return 'table_name'; } /** * Renders a cell in the "table_id" column. * * @since 1.0.0 * * @param array $item Data item for the current row. * @return string HTML content of the cell. */ protected function column_table_id( array $item ) { return esc_html( $item['id'] ); } /** * Renders a cell in the "table_name" column. * * @since 1.0.0 * * @param array $item Data item for the current row. * @return string HTML content of the cell. */ protected function column_table_name( array $item ) { if ( '' === trim( $item['name'] ) ) { $item['name'] = __( '(no name)', 'tablepress' ); } return esc_html( $item['name'] ); } /** * Renders a cell in the "table_description" column. * * @since 1.0.0 * * @param array $item Data item for the current row. * @return string HTML content of the cell. */ protected function column_table_description( array $item ) { if ( '' === trim( $item['description'] ) ) { $item['description'] = __( '(no description)', 'tablepress' ); } return esc_html( $item['description'] ); } /** * Renders a cell in the "table_action" column, i.e. the "Insert" link. * * @since 1.0.0 * * @param array $item Data item for the current row. * @return string HTML content of the cell. */ protected function column_table_action( array $item ) { return ''; } /** * Holds the message to be displayed when there are no items in the table. * * @since 1.0.0 */ public function no_items() { _e( 'No tables found.', 'tablepress' ); if ( 0 === $this->items_count ) { echo ' ' . __( 'You should add or import a table on the TablePress screens to get started!', 'tablepress' ); } } /** * Generates the elements above or below the table (like bulk actions and pagination). * * In comparison with parent class, this has modified HTML (no nonce field), and a check whether there are items. * * @since 1.0.0 * * @param string $which Location ("top" or "bottom"). */ protected function display_tablenav( $which ) { if ( ! $this->has_items() ) { return; } ?>