'', 'id' => __( 'ID', 'ad-code-manager' ), 'name' => __( 'Name', 'ad-code-manager' ), 'priority' => __( 'Priority', 'ad-code-manager' ), 'operator' => __( 'Logical Operator', 'ad-code-manager' ), 'conditionals' => __( 'Conditionals', 'ad-code-manager' ), ) ); // Fail-safe for misconfiguration $required_before = array( 'id' => __( 'ID', 'ad-code-manager' ), 'cb' => '', ); $required_after = array( 'priority' => __( 'Priority', 'ad-code-manager' ), 'operator' => __( 'Logical Operator', 'ad-code-manager' ), 'conditionals' => __( 'Conditionals', 'ad-code-manager' ), ); $columns = array_merge( $required_before, $columns, $required_after ); return $columns; } /** * Define bulk actions to allow users to mass delete ad codes * * @since 0.2.2 * * @return array $bulk_actions All of the bulk actions permitted on the List Table */ function get_bulk_actions() { $bulk_actions = array( 'delete' => __( 'Delete', 'ad-code-manager' ), ); return $bulk_actions; } /** * Prepare the table with different parameters, pagination, columns and table elements */ function prepare_items() { global $ad_code_manager; $screen = get_current_screen(); $this->items = $ad_code_manager->get_ad_codes(); if ( empty( $this->items ) ) return; /* -- Pagination parameters -- */ //Number of elements in your table? $totalitems = count( $this->items ); //return the total number of affected rows //How many to display per page? $perpage = apply_filters( 'acm_list_table_per_page', 25 ); //Which page is this? $paged = !empty( $_GET["paged"] ) ? intval( $_GET["paged"] ) : ''; //Page Number if ( empty( $paged ) || !is_numeric( $paged ) || $paged<=0 ) { $paged=1; } //How many pages do we have in total? $totalpages = ceil( $totalitems/$perpage ); //adjust the query to take pagination into account if ( ! empty( $paged ) && !empty( $perpage ) ) { $offset = ( $paged - 1 ) * $perpage; } /* -- Register the pagination -- */ $this->set_pagination_args( array( "total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $perpage, ) ); //The pagination links are automatically built according to those parameters /* -- Register the Columns -- */ $columns = $this->get_columns(); $hidden = array( 'id', ); $this->_column_headers = array( $columns, $hidden, $this->get_sortable_columns() ) ; /** * Items are set in Ad_Code_Manager class * All we need to do is to prepare it for pagination */ $this->items = array_slice( $this->items, $offset, $perpage ); } /** * Message to be displayed if there are no ad codes found * * @since 0.2 */ function no_items() { _e( 'No ad codes have been configured.', 'ad-code-manager' ); } /** * Prepare and echo a single ad code row * * @since 0.2 */ function single_row( $item ) { static $alternate_class = ''; $alternate_class = ( $alternate_class == '' ? ' alternate' : '' ); $row_class = ' class="term-static' . $alternate_class . '"'; echo '