'', '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 ''; echo $this->single_row_columns( $item ); echo ''; } /** * Fallback column callback. * * @since 0.2 * * @param object $item Custom status as an object * @param string $column_name Name of the column as registered in $this->prepare_items() * @return string $output What will be rendered */ function column_default( $item, $column_name ) { global $ad_code_manager; switch ( $column_name ) { case 'priority': return esc_html( $item['priority'] ); break; case 'operator': return ( ! empty( $item['operator'] ) ) ? $item['operator'] : $ad_code_manager->logical_operator; default: // @todo need to make the first column (whatever it is filtered) to show row actions // Handle custom columns, if any if ( isset( $item['url_vars'][$column_name] ) ) return esc_html( $item['url_vars'][$column_name] ); break; } } /** * Column with a checkbox * Used for bulk actions * * @since 0.2.2 * * @param object $item Ad code as an object * @return string $output What will be rendered */ function column_cb( $item ) { $id = $item['post_id']; $output = ""; return $output; } /** * Display hidden information we need for inline editing */ function column_id( $item ) { global $ad_code_manager; $output = ''; return $output; } /** * */ function column_name( $item ) { $output = isset( $item['name'] ) ? esc_html( $item['name'] ) : esc_html( $item['url_vars']['name'] ); $output .= $this->row_actions_output( $item ); return $output; } /** * Display the conditionals for this ad code * * @since 0.2 */ function column_conditionals( $item ) { if ( empty( $item['conditionals'] ) ) return '' . __( 'None', 'ad-code-manager' ) . ''; $conditionals_html = ''; foreach ( $item['conditionals'] as $conditional ) { $conditionals_html .= '' . esc_html( $conditional['function'] ) . ' ' . esc_html( $conditional['arguments'][0] ) . '
'; } return $conditionals_html; } /** * Produce the action links and hidden HTML for inline editing * * @since 0.2 */ function row_actions_output( $item ) { $output = ''; // $row_actions['preview-ad-code'] = '' . __( 'Preview Ad Code', 'ad-code-manager' ) . ''; $row_actions['edit'] = '' . __( 'Edit Ad Code', 'ad-code-manager' ) . ''; $args = array( 'action' => 'acm_admin_action', 'method' => 'delete', 'id' => $item['post_id'], 'nonce' => wp_create_nonce( 'acm-admin-action' ), ); $delete_link = add_query_arg( $args, admin_url( 'admin-ajax.php' ) ); $row_actions['delete'] = '' . __( 'Delete', 'ad-code-manager' ) . ''; $output .= $this->row_actions( $row_actions ); return $output; } /** * Hidden form used for inline editing functionality * * @since 0.2 */ function inline_edit() { ?>