|null */ protected $_actions; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore /** * Initialize the List Table. * * @since 1.0.0 */ public function __construct() { $screen = get_current_screen(); // Hide "Last Modified By" column by default. if ( false === get_user_option( "manage{$screen->id}columnshidden" ) ) { update_user_option( get_current_user_id(), "manage{$screen->id}columnshidden", array( 'table_last_modified_by' ), true ); } // @phpstan-ignore-next-line (WordPress Core's docblocks state wrong argument types in some places.) parent::__construct( array( 'singular' => 'tablepress-table', // Singular name of the listed records. 'plural' => 'tablepress-all-tables', // Plural name of the listed records. 'ajax' => false, // Does this list table support AJAX? 'screen' => $screen, // WP_Screen object. ) ); } /** * Set the data items (here: tables) that are to be displayed by the List Tables, and their original count. * * @since 1.0.0 * * @param string[] $items Tables to be displayed in the List Table. */ public function set_items( array $items ): void { $this->items = $items; $this->items_count = count( $items ); } /** * Check 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). */ #[\Override] public function ajax_user_can(): bool { return true; } /** * Get 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. */ #[\Override] public function get_columns(): array { $columns = array( 'cb' => $this->has_items() ? '' : '', // Checkbox for "Select all", but only if there are items in the table. // "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_author' => __( 'Author', 'tablepress' ), 'table_last_modified_by' => __( 'Last Modified By', 'tablepress' ), 'table_last_modified' => __( 'Last Modified', 'tablepress' ), ); return $columns; } /** * Get 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. */ #[\Override] protected function get_sortable_columns(): array { // 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 ), 'table_author' => array( 'author', false ), 'table_last_modified_by' => array( 'last_modified_by', false ), 'table_last_modified' => array( 'last_modified', 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. */ #[\Override] protected function get_default_primary_column_name(): string { return 'table_name'; } /** * Render a cell in the "cb" column. * * @since 1.0.0 * * @param array $item Data item for the current row. * @return string HTML content of the cell. */ #[\Override] protected function column_cb( /* array */ $item ): string { // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. $user_can_copy_table = current_user_can( 'tablepress_copy_table', $item['id'] ); $user_can_delete_table = current_user_can( 'tablepress_delete_table', $item['id'] ); $user_can_export_table = current_user_can( 'tablepress_export_table', $item['id'] ); if ( ! ( $user_can_copy_table || $user_can_delete_table || $user_can_export_table ) ) { return ''; } if ( '' === trim( $item['name'] ) ) { $item['name'] = __( '(no name)', 'tablepress' ); } return sprintf( // The `label-covers-full-cell` class on the