Categories::form( array $instance )

Description #

Widget form.

Parameters #

  • $instance
    array (Required) From instance.

Source #

File: addons/categories/widget.php

	public function form( $instance ) {
		$title       = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Categories', 'anspress-question-answer' );
		$hide_empty  = ! empty( $instance['hide_empty'] ) ? $instance['hide_empty'] : false;
		$parent      = ! empty( $instance['parent'] ) ? $instance['parent'] : 0;
		$number      = ! empty( $instance['number'] ) ? $instance['number'] : 10;
		$orderby     = ! empty( $instance['orderby'] ) ? $instance['orderby'] : 'count';
		$order       = ! empty( $instance['order'] ) ? $instance['order'] : 'DESC';
		$icon_height = ! empty( $instance['icon_height'] ) ? $instance['icon_height'] : '32';
		$icon_width  = ! empty( $instance['icon_width'] ) ? $instance['icon_width'] : '32';

		$cat_args = array(
			'taxonomy'   => 'question_category',
			'hide_empty' => false,
			'orderby'    => 'count',
			'order'      => 'DESC',
		);

		$categories = get_terms( $cat_args );
		?>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>"><?php esc_attr_e( 'Hide empty:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_empty' ) ); ?>" type="checkbox" value="1" <?php checked( true, $hide_empty ); ?>>
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'parent' ) ); ?>"><?php esc_attr_e( 'Parent:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'parent' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'parent' ) ); ?>">
				<option value="0"><?php esc_attr_e( 'Top level', 'anspress-question-answer' ); ?></option>
				<?php
				if ( $categories ) {
					foreach ( $categories as $c ) {
						echo '<option value="' . (int) $c->term_id . '" ' . selected( $parent, $c->term_id ) . '>' . esc_html( $c->name ) . '</option>';
					}
				}

				?>
			</select>
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php esc_attr_e( 'Number:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>">
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php esc_attr_e( 'Order By:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>">
				<option value="none" <?php echo selected( $orderby, 'none' ); ?>><?php esc_attr_e( 'None', 'anspress-question-answer' ); ?></option>
				<option value="count" <?php echo selected( $orderby, 'count' ); ?>><?php esc_attr_e( 'Count', 'anspress-question-answer' ); ?></option>
				<option value="id" <?php echo selected( $orderby, 'id' ); ?>><?php esc_attr_e( 'ID', 'anspress-question-answer' ); ?></option>
				<option value="name" <?php echo selected( $orderby, 'name' ); ?>><?php esc_attr_e( 'Name', 'anspress-question-answer' ); ?></option>
				<option value="slug" <?php echo selected( $orderby, 'slug' ); ?>><?php esc_attr_e( 'Slug', 'anspress-question-answer' ); ?></option>
				<option value="term_group" <?php echo selected( $orderby, 'term_group' ); ?>><?php esc_attr_e( 'Term group', 'anspress-question-answer' ); ?></option>
			</select>
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php esc_attr_e( 'Order:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>">
				<option value="DESC" <?php echo selected( $order, 'DESC' ); ?>><?php esc_attr_e( 'DESC', 'anspress-question-answer' ); ?></option>
				<option value="ASC" <?php echo selected( $order, 'ASC' ); ?>><?php esc_attr_e( 'ASC', 'anspress-question-answer' ); ?></option>
			</select>
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'icon_width' ) ); ?>"><?php esc_attr_e( 'Icon width:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'icon_width' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_width' ) ); ?>" type="text" value="<?php echo esc_attr( $icon_width ); ?>">
		</p>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'icon_height' ) ); ?>"><?php esc_attr_e( 'Icon height:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'icon_height' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_height' ) ); ?>" type="text" value="<?php echo esc_attr( $icon_height ); ?>">
		</p>
		<?php
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment