AP_Questions_Widget::form( array $instance )

Description #

Widget form.

Parameters #

  • $instance
    array (Required) Form instance.

Source #

File: widgets/questions.php

	public function form( $instance ) {
		$title        = __( 'Questions', 'anspress-question-answer' );
		$order_by     = 'active';
		$limit        = 5;
		$category_ids = '';

		if ( isset( $instance['title'] ) ) {
			$title = $instance['title'];
		}

		if ( isset( $instance['order_by'] ) ) {
			$order_by = $instance['order_by'];
		}

		if ( isset( $instance['limit'] ) ) {
			$limit = $instance['limit'];
		}

		if ( isset( $instance['category_ids'] ) ) {
			$category_ids = $instance['category_ids'];
		}

		?>
		<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( 'order_by' ) ); ?>"><?php esc_attr_e( 'Order by:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'order_by' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'order_by' ) ); ?>">
				<option <?php selected( $order_by, 'active' ); ?> value="active"><?php esc_attr_e( 'Active', 'anspress-question-answer' ); ?></option>
				<option <?php selected( $order_by, 'newest' ); ?> value="newest"><?php esc_attr_e( 'Newest', 'anspress-question-answer' ); ?></option>
				<option <?php selected( $order_by, 'voted' ); ?> value="voted"><?php esc_attr_e( 'Voted', 'anspress-question-answer' ); ?></option>
				<option <?php selected( $order_by, 'answers' ); ?> value="answers"><?php esc_attr_e( 'Answers', 'anspress-question-answer' ); ?></option>
				<option <?php selected( $order_by, 'unanswered' ); ?> value="unanswered"><?php esc_attr_e( 'Unanswered', 'anspress-question-answer' ); ?></option>
			</select>
		</p>
		<?php if ( taxonomy_exists( 'question_category' ) ) : ?>
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Category IDs:', 'anspress-question-answer' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'category_ids' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'category_ids' ) ); ?>" type="text" value="<?php echo esc_attr( $category_ids ); ?>">
				<small><?php esc_attr_e( 'Comma separated AnsPress category ids', 'anspress-question-answer' ); ?></small>
			</p>
		<?php endif; ?>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php esc_attr_e( 'Limit:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>">
		</p>

		<?php

		return 'noform';
	}

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