Inventory_Presser_Admin_Options::callback_additional_listings_page()

Outputs a table to manage additional inventory listing pages.


Description

Helps users create an additional inventory archive at example.com/[cash-deals] that contains vehicles that have a value for field [Down Payment].


Return

(void)


Source

File: includes/admin/class-admin-options.php

	public function callback_additional_listings_page() {
		?>
		<div id="additional_listings_pages_settings">
			<table class="wp-list-table widefat striped additional_listings_pages">
				<thead>
					<tr>
						<th><?php esc_html_e( 'Active', 'inventory-presser' ); ?></th>
						<th><?php esc_html_e( 'Title', 'inventory-presser' ); ?></th>
						<th><?php esc_html_e( 'URL path', 'inventory-presser' ); ?></th>
						<th><?php esc_html_e( 'Filter field', 'inventory-presser' ); ?></th>
						<th><?php esc_html_e( 'Operator', 'inventory-presser' ); ?></th>
						<th><?php esc_html_e( 'Value', 'inventory-presser' ); ?></th>
						<th></th>
					</tr>
				</thead>
				<tbody>
				<?php

				// output a row for each saved additional listing page + one blank.
				$additional_listings = Inventory_Presser_Additional_Listings_Pages::additional_listings_pages_array();
				$keys                = array(
					'url_path',
					'key',
					'operator',
					'value',
				);
				$page_count          = count( $additional_listings );
				for ( $a = 0; $a < $page_count; $a++ ) {
					foreach ( $keys as $key ) {
						if ( ! isset( $additional_listings[ $a ][ $key ] ) ) {
							$additional_listings[ $a ][ $key ] = '';
						}
					}

					?>
					<tr id="row_<?php echo esc_attr( $a ); ?>">
						<td class="active">
							<?php
							printf(
								'<input type="checkbox" id="additional_listings_pages_active_%1$s" name="%2$s[additional_listings_pages][%1$s][active]" %3$s />',
								esc_attr( $a ),
								esc_attr( INVP::OPTION_NAME ),
								checked( true, $additional_listings[ $a ]['active'] ?? true, false )
							);
							?>
						</td>
						<td>
							<?php
							// text box for page title.
							printf(
								'<input type="text" id="additional_listings_pages_title_%1$s" name="%2$s[additional_listings_pages][%1$s][title]" value="%3$s" />',
								esc_attr( $a ),
								esc_attr( INVP::OPTION_NAME ),
								esc_attr( $additional_listings[ $a ]['title'] ?? '' )
							);
							?>
							</td>
						<td>
							<?php
							// url path.
							printf(
								'%1$s/<input type="text" id="additional_listings_pages_slug_%2$s" name="%3$s[additional_listings_pages][%2$s][url_path]" class="additional_listings_pages_slug" value="%4$s" />',
								esc_url( site_url() ),
								esc_attr( $a ),
								esc_attr( INVP::OPTION_NAME ),
								esc_attr( $additional_listings[ $a ]['url_path'] ?? '' )
							);
							?>
							</td>
						<td>
							<?php
							// select list of vehicle fields.
							echo $this->html_select_vehicle_keys(
								array(
									'id'    => 'additional_listings_pages_key_' . $a,
									'name'  => INVP::OPTION_NAME . '[additional_listings_pages][' . $a . '][key]',
									'class' => 'filter-key',
								),
								$additional_listings[ $a ]['key'] ?? ''
							);
							?>
							</td>
						<td>
							<?php
							// select list of operators.
							echo $this->html_select_operator(
								array(
									'id'    => 'additional_listings_pages_operator_' . $a,
									'name'  => INVP::OPTION_NAME . '[additional_listings_pages][' . $a . '][operator]',
									'class' => 'operator',
								),
								$additional_listings[ $a ]['operator'] ?? ''
							);
							?>
							</td>
						<td>
							<?php
							// text box for comparison value.
							printf(
								'<input type="text" id="additional_listings_pages_value_%1$s" name="%2$s[additional_listings_pages][%1$s][value]" value="%3$s" />',
								esc_attr( $a ),
								esc_attr( INVP::OPTION_NAME ),
								esc_attr( $additional_listings[ $a ]['value'] ?? '' )
							);
							?>
							</td>
						<td>
							<a href="<?php echo esc_url( site_url( $additional_listings[ $a ]['url_path'] ?? '' ) ); ?>" class="button action" title="<?php esc_attr__( 'View this page', 'inventory-presser' ); ?>"><span class="dashicons dashicons-welcome-view-site"></span></a><button class="button action delete-button" id="delete_<?php echo esc_attr( $a ); ?>" title="<?php esc_attr__( 'Delete this page', 'inventory-presser' ); ?>"><span class="dashicons dashicons-trash"></span></button>
						</td>
					</tr>
					<?php

				}

				?>
				</tbody>
			</table>
			<button class="button action" id="add_additional_listings_page"><?php esc_html_e( 'Add Listings Page', 'inventory-presser' ); ?></button>
		</div>
		<?php
	}