Example #1
0
/**
 * Displays the Orderby form
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_ideas_get_order_options() to get available orders
 * @uses   get_query_var() to get the selected order
 * @uses   wp_idea_stream_get_category() to get ideas category rewrite id (which is also its identifier)
 * @uses   wp_idea_stream_get_tag() to get ideas tag rewrite id (which is also its identifier)
 * @uses   esc_html() to sanitize output value
 * @uses   wp_idea_stream_is_pretty_links() to check if a custom permalink structure is set
 * @uses   wp_idea_stream_get_post_type() to get the post type identifier
 * @uses   wp_idea_stream_get_tag_url() to get the url to the current tag
 * @uses   wp_idea_stream_get_category_url() to get the url to the current category
 * @uses   wp_idea_stream_get_root_url() to get the main ideas archive page url
 * @uses   esc_url() to sanitize the url
 * @uses   esc_attr() to sanitize attributes
 * @uses   selected() to add the selected attribute to the selected option
 * @uses   apply_filters() call 'wp_idea_stream_ideas_order_form_action_url' to override the base url
 *                         call 'wp_idea_stream_ideas_order_form' to override the orderby form output
 * @return string Output for the search form.
 */
function wp_idea_stream_ideas_order_form()
{
    $order_options = wp_idea_stream_ideas_get_order_options();
    $order_value = get_query_var('orderby');
    $category = get_query_var(wp_idea_stream_get_category());
    $tag = get_query_var(wp_idea_stream_get_tag());
    $action = '';
    $hidden = '';
    if (!empty($order_value)) {
        $order_value = esc_html($order_value);
    } else {
        $order_value = 'date';
    }
    if (!wp_idea_stream_is_pretty_links()) {
        if (!empty($category)) {
            $hidden = "\n" . '<input type="hidden" name="' . esc_attr(wp_idea_stream_get_category()) . '" value="' . $category . '"/>';
        } else {
            if (!empty($tag)) {
                $hidden = "\n" . '<input type="hidden" name="' . esc_attr(wp_idea_stream_get_tag()) . '" value="' . $tag . '"/>';
            } else {
                $hidden = "\n" . '<input type="hidden" name="post_type" value="' . wp_idea_stream_get_post_type() . '"/>';
            }
        }
        // We need to set the action url
    } else {
        // Viewing tags
        if (wp_idea_stream_is_tag()) {
            $action = wp_idea_stream_get_tag_url($tag);
            // Viewing categgories
        } else {
            if (wp_idea_stream_is_category()) {
                $action = wp_idea_stream_get_category_url($category);
                // Defaults to roout url
            } else {
                $action = wp_idea_stream_get_root_url();
            }
        }
        /**
         * @param string $action the action form attribute
         * @param string the current category term slug if set
         * @param string the current tag term slug if set
         */
        $action = apply_filters('wp_idea_stream_ideas_order_form_action_url', $action, $category, $tag);
    }
    $order_form_html = '<form action="' . esc_url($action) . '" method="get" id="ideas-order-form" class="nav-form">' . $hidden;
    $order_form_html .= '<label><select name="orderby" id="ideas-order-box">';
    foreach ($order_options as $query_var => $label) {
        $order_form_html .= '<option value="' . esc_attr($query_var) . '" ' . selected($order_value, $query_var, false) . '>' . esc_html($label) . '</option>';
    }
    $order_form_html .= '</select></label>';
    $order_form_html .= '<input type="submit" id="ideas-order-submit" value="' . esc_attr__('Sort', 'wp-idea-stream') . '" /></form>';
    echo apply_filters('wp_idea_stream_ideas_order_form', $order_form_html);
}
Example #2
0
        /**
         * Display the form in Widgets Administration
         *
         * @package WP Idea Stream
         * @subpackage ideas/widgets
         *
         * @since 2.0.0
         *
         * @uses wp_idea_stream_ideas_get_order_options() to get available orders
         * @uses WP_Widget->get_field_id()
         * @uses WP_Widget->get_field_name()
         * @uses selected()
         */
        public function form($instance = array())
        {
            // Default to nothing
            $title = '';
            if (isset($instance['title'])) {
                $title = $instance['title'];
            }
            // Available 'orderbys'
            $orderby = wp_idea_stream_ideas_get_order_options();
            // The date choice is default so let's unset it
            unset($orderby['date']);
            // comment count is default, as it's possible to deactivate ratings
            $current_order = 'comment_count';
            if (!empty($instance['orderby'])) {
                $current_order = sanitize_text_field($instance['orderby']);
            }
            // Number default to 5
            $number = 5;
            if (!empty($instance['number'])) {
                $number = absint($instance['number']);
            }
            ?>

		<p>
			<label for="<?php 
            echo $this->get_field_id('title');
            ?>
"><?php 
            esc_html_e('Title:', 'wp-idea-stream');
            ?>
</label>
			<input type="text" class="widefat" id="<?php 
            echo $this->get_field_id('title');
            ?>
" name="<?php 
            echo $this->get_field_name('title');
            ?>
" value="<?php 
            echo esc_attr($title);
            ?>
" />
		</p>

		<p>
			<label for="<?php 
            echo $this->get_field_id('orderby');
            ?>
"><?php 
            esc_html_e('Type:', 'wp-idea-stream');
            ?>
</label>
			<select class="widefat" id="<?php 
            echo $this->get_field_id('orderby');
            ?>
" name="<?php 
            echo $this->get_field_name('orderby');
            ?>
">

				<?php 
            foreach ($orderby as $key_order => $order_name) {
                ?>

					<option value="<?php 
                echo esc_attr($key_order);
                ?>
" <?php 
                selected($key_order, $current_order);
                ?>
><?php 
                echo esc_html($order_name);
                ?>
</option>

				<?php 
            }
            ?>

			</select>
		</p>

		<p>
			<label for="<?php 
            echo $this->get_field_id('number');
            ?>
"><?php 
            _e('Number of ideas to show:', 'wp-idea-stream');
            ?>
</label>
			<input id="<?php 
            echo $this->get_field_id('number');
            ?>
" name="<?php 
            echo $this->get_field_name('number');
            ?>
" type="text" value="<?php 
            echo $number;
            ?>
" size="3" />
		</p>


		<?php 
        }