esc_html__( 'Critical CSS', 'fusion-builder' ), // Singular name of the listed records. 'plural' => esc_html__( 'Critical CSS', 'fusion-builder' ), // Plural name of the listed records. 'ajax' => false, // This table doesn't support ajax. 'class' => 'avada-critical-css-table', ] ); $this->columns = $this->get_columns(); $this->css_key_labels = [ 'global_post' => esc_html__( 'Global Single Post', 'fusion-builder' ), 'global_avada_portfolio' => esc_html__( 'Global Single Portfolio', 'fusion-builder' ), 'global_product' => esc_html__( 'Global Single Product', 'fusion-builder' ), ]; // Actions which need to removed from the URL after page reloads. $remove_actions = [ 'action', 'action2', 'post', '_wpnonce' ]; $this->url = remove_query_arg( $remove_actions, wp_unslash( $_SERVER['REQUEST_URI'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput } /** * Set the custom classes for table. * * @since 1.0 * @access public * @return array */ public function get_table_classes() { return [ 'widefat', 'striped' ]; } /** * Prepare the items for the table to process. * * @since 1.0 * @access public * @return void */ public function prepare_items() { $columns = $this->columns; $per_page = 10; $current_page = $this->get_pagenum(); $data = $this->table_data( $per_page, $current_page ); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $total = AWB_Critical_CSS()->get_total(); $this->set_pagination_args( [ 'total_items' => $total, 'per_page' => $per_page, ] ); $this->_column_headers = [ $columns, $hidden, $sortable ]; $this->items = $data; } /** * Override the parent columns method. Defines the columns to use in your listing table. * * @since 1.0 * @access public * @return array */ public function get_columns() { $columns = [ 'cb' => '', 'css_key' => esc_html__( 'Key', 'fusion-builder' ), 'mobile_css' => __( 'Mobile CSS', 'fusion-builder' ), 'desktop_css' => __( 'Desktop CSS', 'fusion-builder' ), 'updated_at' => __( 'Last Updated', 'fusion-builder' ), 'update' => __( 'Regenerate', 'fusion-builder' ), ]; return $columns; } /** * Define which columns are hidden * * @since 1.0 * @access public * @return array */ public function get_hidden_columns() { return []; } /** * Define the sortable columns * * @since 1.0 * @access public * @return array */ public function get_sortable_columns() { return [ 'id' => [ 'id', true ], 'css_key' => [ 'css_key', true ], 'updated_at' => [ 'updated_at', true ], ]; } /** * Get the table data. * * @since 1.0 * @access public * @param number $per_page Posts per page. * @param number $current_page - Current page number. * @return array */ private function table_data( $per_page = -1, $current_page = 0 ) { $data = []; // Make sure current-page and per-page are integers. $per_page = (int) $per_page; $current_page = (int) $current_page; $args = [ 'limit' => $per_page, 'offset' => ( $current_page - 1 ) * $per_page, 'where' => [], ]; // Add sorting. if ( isset( $_GET['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $args['order_by'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); // phpcs:ignore WordPress.Security.NonceVerification $args['order'] = ( isset( $_GET['order'] ) ) ? sanitize_text_field( wp_unslash( $_GET['order'] ) ) : 'ASC'; // phpcs:ignore WordPress.Security.NonceVerification } $codes = AWB_Critical_CSS()->get( $args ); foreach ( $codes as $code ) { $data[] = [ 'id' => $code->id, 'css_key' => $code->css_key, 'mobile_css' => $code->mobile_css, 'desktop_css' => $code->desktop_css, 'updated_at' => ! empty( $code->updated_at ) ? gmdate( 'M d Y', $code->updated_at ) : '', ]; } return $data; // phpcs:enable WordPress.Security.NonceVerification } /** * Define what data to show on each column of the table * * @since 1.0 * @access public * @param array $item Data. * @return void */ public function single_row( $item ) { $row_classes = ''; echo '