'item', 'plural' => 'items', 'ajax' => true, 'screen' => WP_Helper::get_wp_screen(), ); $args = wp_parse_args( $args, $defaults ); parent::__construct( $args ); if ( method_exists( $this, 'manage_columns' ) ) { static::$columns = static::manage_columns( array() ); } } /** * Manage columns for the table. * * @param array $columns Existing columns. * * @return array * * @since 4.5.2 */ abstract public static function manage_columns( $columns ): array; /** * Get default per page. * * @return int * * @since 4.5.2 */ abstract public static function get_default_per_page(): int; /** * Register cron job if applicable. * * @param array $crons Existing crons. * * @return array * * @since 4.5.2 */ public static function add_cron_job( $crons ) { // Default implementation: no cron. return $crons; } /** * Prepare items for display. * * @since 4.5.2 */ public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $this->_column_headers = array( $columns, $hidden, $sortable ); $this->handle_table_actions(); $this->fetch_table_data(); $hidden = get_user_option( 'manage' . WP_Helper::get_wp_screen()->id . 'columnshidden', false ); if ( ! $hidden ) { $hidden = array(); } $this->_column_headers = array( static::$columns, $hidden, $sortable ); $this->set_pagination_args( array( 'total_items' => $this->count, 'per_page' => self::get_screen_option_per_page(), 'total_pages' => ceil( $this->count / self::get_screen_option_per_page() ), ) ); } /** * Returns an associative array containing the bulk actions * * @since 1.0.0 * * @return array */ public function get_bulk_actions() { /** * On hitting apply in bulk actions the url params are set as * ?action=bulk-download&paged=1&action2=-1 * * Action and action2 are set based on the triggers above or below the table */ $actions = array( 'delete' => __( 'Delete Records', '0-day-analytics' ), ); return $actions; } /** * Fetch table data. To be implemented by subclasses. * * @param array $args - Arguments for fetching data. * * @since 4.5.2 */ abstract public function fetch_table_data( array $args = array() ); /** * Handle table actions. To be implemented by subclasses. * * @since 4.5.2 */ abstract protected function handle_table_actions(); }