Ejemplo n.º 1
0
 public static function get_instance()
 {
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
    /**
     * Output the main HTML interface of taxonomy/terms/posts
     *
     * @author Ronald Huereca <*****@*****.**>
     * @since 1.0.0
     * @access public
     * @uses reorder_by_term_interface_{post_type} WordPress action
     */
    public function output_interface()
    {
        $selected_tax = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : false;
        $taxonomies = get_object_taxonomies($this->post_type, 'objects');
        ?>
		<h3><?php 
        esc_html_e('Select a Taxonomy', 'reorder-by-term');
        ?>
</h3>
		<form id="reorder-taxonomy" method="get" action="<?php 
        echo esc_url($this->reorder_page);
        ?>
">
		<?php 
        foreach ($_GET as $key => $value) {
            if ('term' == $key || 'taxonomy' == $key || 'paged' == $key) {
                continue;
            }
            printf('<input type="hidden" value="%s" name="%s" />', esc_attr($value), esc_attr($key));
        }
        //Output non hierarchical posts
        $page = isset($_GET['paged']) ? absint($_GET['paged']) : 0;
        $offset = 0;
        if ($page > 1) {
            $offset = $this->offset * ($page - 1);
        }
        printf('<input type="hidden" id="reorder-offset" value="%s" />', absint($offset));
        ?>
		<select name="taxonomy">
			<?php 
        printf('<option value="none">%s</option>', esc_html__('Select a taxonomy', 'reorder-by-term'));
        foreach ($taxonomies as $tax_name => $taxonomy) {
            $label = $taxonomy->label;
            printf('<option value="%s" %s>%s</option>', esc_attr($tax_name), selected($tax_name, $selected_tax, false), esc_html($label));
        }
        ?>
		</select>
		</form>
        <?php 
        //Output Terms
        if ($selected_tax) {
            //Get Terms
            $plugin_slug = $this->post_type . '_order';
            $selected_terms_args = array('orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array('relation' => 'OR', array('key' => $plugin_slug, 'compare' => 'NOT EXISTS'), array('key' => $plugin_slug, 'value' => 0, 'compare' => '>=')), 'number' => $this->posts_per_page, 'offset' => $offset, 'hide_empty' => false, 'hierarchical' => false, 'parent' => 0, 'child_of' => false);
            add_filter('terms_clauses', array($this, 'filter_term_clauses'));
            $terms = get_terms($selected_tax, $selected_terms_args);
            remove_filter('terms_clauses', array($this, 'filter_term_clauses'));
            if ($terms) {
                ?>
        		<div><img src="<?php 
                echo esc_url(admin_url('images/loading.gif'));
                ?>
" id="loading-animation" /></div>
        		<?php 
                echo '<ul id="post-list">';
                foreach ($terms as $term) {
                    $this->output_row($term);
                }
                echo '</ul><!-- #post-list -->';
            }
            //Show pagination links
            $term_count = wp_count_terms($selected_tax, array('hide_empty' => false, 'parent' => 0));
            if ($term_count > 1) {
                echo '<div id="reorder-pagination">';
                $current_url = add_query_arg(array('paged' => '%#%'));
                $pagination_args = array('base' => $current_url, 'total' => floor($term_count / $this->posts_per_page), 'current' => $page == 0 ? 1 : $page);
                echo paginate_links($pagination_args);
                echo '</div>';
            }
            $options = MN_Reorder_Admin::get_instance()->get_plugin_options();
            if (!isset($options['reorder_terms_show_query']) || 'on' === $options['reorder_terms_show_query']) {
                printf('<h3>%s</h3>', esc_html__('Reorder Terms Query', 'reorder-terms'));
                printf('<p>%s</p>', esc_html__('You will need custom code to reorder terms.  Here are some example query arguments for get_terms.', 'reorder-terms'));
                $query = "\n\$query = array(\n    'orderby' => 'meta_value_num',\n    'order' => 'ASC',\n    'meta_query' => array(\n        'relation' => 'OR',\n        array(\n            'key' => '{$plugin_slug}',\n            'compare' => 'NOT EXISTS'\n        ),\n        array(\n            'key' => '{$plugin_slug}',\n            'value' => 0,\n            'compare' => '>='\n        )\n    ),\n    'hide_empty' => true,\n    'parent' => 0   \n);\n\$terms = get_terms( '{$selected_tax}', \$query );\n";
                printf('<blockquote><pre><code>%s</code></pre></blockquote>', esc_html(print_r($query, true)));
            }
        }
    }
Ejemplo n.º 3
0
 /**
  * Outputs settings section for showing a term query or not
  *
  * @author Ronald Huereca <*****@*****.**>
  * @since 1.1.0
  * @access public
  * @uses MN_Reorder_Admin WordPress object
  */
 public function add_settings_field_term_query()
 {
     $options = MN_Reorder_Admin::get_instance()->get_plugin_options();
     $selected = 'on';
     if (isset($options['reorder_terms_show_query'])) {
         $selected = $options['reorder_terms_show_query'];
     }
     printf('<p><input type="radio" name="metronet-reorder-posts[reorder_terms_show_query]" value="on" id="reorder_terms_show_query_yes" %s />&nbsp;<label for="reorder_terms_show_query_yes">%s</label></p>', checked('on', $selected, false), esc_html__('Yes', 'reorder-terms'));
     printf('<p><input type="radio" name="metronet-reorder-posts[reorder_terms_show_query]" value="off" id="reorder_terms_show_query_no" %s />&nbsp;<label for="reorder_terms_show_query_no">%s</label></p>', checked('off', $selected, false), esc_html__('No', 'reorder-terms'));
 }