Skip to content
This repository was archived by the owner on Nov 9, 2020. It is now read-only.

Commit 9729737

Browse files
committed
Releasing 1.4.1
1 parent c7847c9 commit 9729737

File tree

5 files changed

+180
-167
lines changed

5 files changed

+180
-167
lines changed

categories-for-anspress.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Plugin URI: http://anspress.io/downloads/categories-for-anspress
1616
* Description: Extension for AnsPress. Add categories in AnsPress.
1717
* Donate link: https://www.paypal.com/cgi-bin/webscr?business=rah12@live.com&cmd=_xclick&item_name=Donation%20to%20AnsPress%20development
18-
* Version: 1.4
18+
* Version: 1.4.1
1919
* Author: Rahul Aryan
2020
* Author URI: http://anspress.io
2121
* Text Domain: categories_for_anspress
@@ -64,7 +64,8 @@ class Categories_For_AnsPress
6464
public static function get_instance() {
6565

6666
if ( ! self::$instance ) {
67-
self::$instance = new Categories_For_AnsPress(); }
67+
self::$instance = new Categories_For_AnsPress();
68+
}
6869

6970
return self::$instance;
7071
}
@@ -78,14 +79,17 @@ public function __construct() {
7879
return; // AnsPress not installed.
7980
}
8081
if ( ! defined( 'CATEGORIES_FOR_ANSPRESS_DIR' ) ) {
81-
define( 'CATEGORIES_FOR_ANSPRESS_DIR', plugin_dir_path( __FILE__ ) ); }
82+
define( 'CATEGORIES_FOR_ANSPRESS_DIR', plugin_dir_path( __FILE__ ) );
83+
}
8284

8385
if ( ! defined( 'CATEGORIES_FOR_ANSPRESS_URL' ) ) {
84-
define( 'CATEGORIES_FOR_ANSPRESS_URL', plugin_dir_url( __FILE__ ) ); }
86+
define( 'CATEGORIES_FOR_ANSPRESS_URL', plugin_dir_url( __FILE__ ) );
87+
}
8588

8689
$this->includes();
8790

8891
ap_register_page( ap_get_category_slug(), __( 'Category', 'categories-for-anspress' ), array( $this, 'category_page' ), false );
92+
8993
ap_register_page( ap_get_categories_slug(), __( 'Categories', 'categories-for-anspress' ), array( $this, 'categories_page' ) );
9094

9195
add_action( 'init', array( $this, 'textdomain' ) );
@@ -109,7 +113,6 @@ public function __construct() {
109113
add_action( 'question_category_edit_form_fields', array( $this, 'image_field_edit' ) );
110114
add_action( 'create_question_category', array( $this, 'save_image_field' ) );
111115
add_action( 'edited_question_category', array( $this, 'save_image_field' ) );
112-
add_action( 'widgets_init', array( $this, 'register_widget' ) );
113116
add_action( 'ap_rewrite_rules', array( $this, 'rewrite_rules' ), 10, 3 );
114117
add_filter( 'ap_default_pages', array( $this, 'category_default_page' ) );
115118
add_filter( 'ap_default_page_slugs', array( $this, 'default_page_slugs' ) );
@@ -135,13 +138,13 @@ public function category_page() {
135138
$category_id = sanitize_title( get_query_var( 'q_cat' ) );
136139

137140
$question_args = array(
138-
'tax_query' => array(
139-
array(
140-
'taxonomy' => 'question_category',
141-
'field' => is_numeric( $category_id ) ? 'id' : 'slug',
142-
'terms' => array( $category_id ),
141+
'tax_query' => array(
142+
array(
143+
'taxonomy' => 'question_category',
144+
'field' => is_numeric( $category_id ) ? 'id' : 'slug',
145+
'terms' => array( $category_id ),
146+
),
143147
),
144-
),
145148
);
146149

147150
$question_category = get_term_by( 'slug', $category_id, 'question_category' );
@@ -638,7 +641,8 @@ public function save_image_field($termID) {
638641
$termMeta = get_option( 'ap_cat_'.$termID );
639642

640643
if ( ! is_array( $termMeta ) ) {
641-
$termMeta = array(); }
644+
$termMeta = array();
645+
}
642646

643647
if ( isset( $_POST['ap_category_image_url'] ) && isset( $_POST['ap_category_image_id'] ) ) {
644648

@@ -661,14 +665,6 @@ public function save_image_field($termID) {
661665
}
662666
}
663667

664-
/**
665-
* Register category widget
666-
* @return void
667-
*/
668-
public function register_widget() {
669-
register_widget( 'AnsPress_Category_Widget' );
670-
}
671-
672668
/**
673669
* Add category pages rewrite rule
674670
* @param array $rules AnsPress rules.

categories-widget.php

Lines changed: 93 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
<?php
2+
/**
3+
* AnsPress category widget.
4+
* @package Categories_For_AnsPress
5+
*/
6+
7+
/**
8+
* Register AnsPress category widget
9+
* @since unknown
10+
*/
211
class AnsPress_Category_Widget extends WP_Widget {
312

4-
public function AnsPress_Category_Widget() {
5-
// Instantiate the parent object
6-
parent::__construct( false, '(AnsPress) Categories', array('description', __('Display AnsPress categories', 'ap')) );
13+
public function __construct() {
14+
// Instantiate the parent object.
15+
parent::__construct(
16+
'AnsPress_Category_Widget',
17+
'(AnsPress) Categories',
18+
array( 'description', __('Display AnsPress categories', 'ap' ) ) );
719
}
820

921
public function widget( $args, $instance ) {
@@ -23,114 +35,109 @@ public function widget( $args, $instance ) {
2335
'order' => $instance['order'],
2436
);
2537

26-
$categories = get_terms( 'question_category' , $cat_args);
38+
$categories = get_terms( 'question_category' , $cat_args );
2739
?>
2840

29-
<ul id="ap-categories-widget" class="ap-cat-wid clearfix">
41+
<ul id="ap-categories-widget" class="ap-cat-wid clearfix">
3042
<?php
31-
foreach($categories as $key => $category) :
32-
$sub_cat_count = count(get_term_children( $category->term_id, 'question_category' ));
43+
foreach ( $categories as $key => $category ) :
44+
$sub_cat_count = count(get_term_children( $category->term_id, 'question_category' ) );
3345
?>
34-
<li class="clearfix">
35-
<a class="ap-cat-image" href="<?php echo get_category_link( $category );?>"><?php echo ap_get_category_image($category->term_id); ?></a>
46+
<li class="clearfix">
47+
<a class="ap-cat-image" href="<?php echo get_category_link( $category );?>"><?php echo ap_get_category_image($category->term_id ); ?></a>
3648
<a class="ap-cat-wid-title" href="<?php echo get_category_link( $category );?>">
3749
<?php echo $category->name; ?>
38-
</a>
39-
<div class="ap-cat-count">
40-
<span><?php printf(_n('%d Question', '%d Questions', $category->count), $category->count); ?></span>
41-
<?php if($sub_cat_count > 0) : ?>
42-
<span><?php printf(__('%d Child', 'ap'), $sub_cat_count); ?></span>
50+
</a>
51+
<div class="ap-cat-count">
52+
<span><?php printf(_n('%d Question', '%d Questions', $category->count ), $category->count ); ?></span>
53+
<?php if ( $sub_cat_count > 0 ) : ?>
54+
<span><?php printf(__('%d Child', 'ap' ), $sub_cat_count ); ?></span>
4355
<?php endif; ?>
44-
</div>
45-
</li>
56+
</div>
57+
</li>
4658
<?php endforeach; ?>
47-
</ul>
59+
</ul>
4860

4961
<?php
5062
echo $args['after_widget'];
5163
}
5264

5365
public function form( $instance ) {
54-
if ( isset( $instance[ 'title' ] ) )
55-
$title = $instance[ 'title' ];
56-
else
57-
$title = __( 'Categories', 'ap' );
58-
59-
if ( isset( $instance[ 'hide_empty' ] ) )
60-
$hide_empty = $instance[ 'hide_empty' ];
61-
else
62-
$hide_empty = false;
63-
64-
if ( isset( $instance[ 'parent' ] ) )
65-
$parent = $instance[ 'parent' ];
66-
else
67-
$parent = 0;
68-
69-
if ( isset( $instance[ 'number' ] ) )
70-
$number = $instance[ 'number' ];
71-
else
72-
$number = 10;
73-
74-
if ( isset( $instance[ 'orderby' ] ) )
75-
$orderby = $instance[ 'orderby' ];
76-
else
77-
$orderby = 'count';
78-
79-
if ( isset( $instance[ 'order' ] ) )
80-
$order = $instance[ 'order' ];
81-
else
82-
$order = 'DESC';
66+
if ( isset( $instance[ 'title' ] ) ) {
67+
$title = $instance[ 'title' ]; } else {
68+
$title = __( 'Categories', 'ap' ); }
8369

84-
$cat_args = array(
85-
'hide_empty' => false,
86-
'orderby' => 'count',
87-
'order' => 'DESC',
88-
);
89-
$categories = get_terms( 'question_category' , $cat_args);
70+
if ( isset( $instance[ 'hide_empty' ] ) ) {
71+
$hide_empty = $instance[ 'hide_empty' ]; } else {
72+
$hide_empty = false; }
73+
74+
if ( isset( $instance[ 'parent' ] ) ) {
75+
$parent = $instance[ 'parent' ]; } else {
76+
$parent = 0; }
77+
78+
if ( isset( $instance[ 'number' ] ) ) {
79+
$number = $instance[ 'number' ]; } else {
80+
$number = 10; }
81+
82+
if ( isset( $instance[ 'orderby' ] ) ) {
83+
$orderby = $instance[ 'orderby' ]; } else {
84+
$orderby = 'count'; }
85+
86+
if ( isset( $instance[ 'order' ] ) ) {
87+
$order = $instance[ 'order' ]; } else {
88+
$order = 'DESC'; }
89+
90+
$cat_args = array(
91+
'hide_empty' => false,
92+
'orderby' => 'count',
93+
'order' => 'DESC',
94+
);
95+
$categories = get_terms( 'question_category' , $cat_args );
9096

9197
?>
92-
<p>
98+
<p>
9399
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'ap' ); ?></label>
94100
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
95-
</p>
96-
<p>
101+
</p>
102+
<p>
97103
<label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>"><?php _e( 'Hide empty:', 'ap' ); ?></label>
98-
<input class="widefat" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" type="checkbox" value="1" <?php checked( true, $hide_empty);?>>
99-
</p>
100-
<p>
104+
<input class="widefat" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" type="checkbox" value="1" <?php checked( true, $hide_empty );?>>
105+
</p>
106+
<p>
101107
<label for="<?php echo $this->get_field_id( 'parent' ); ?>"><?php _e( 'Parent:', 'ap' ); ?></label>
102108
<select class="widefat" id="<?php echo $this->get_field_id( 'parent' ); ?>" name="<?php echo $this->get_field_name( 'parent' ); ?>">
103-
<option value="0"><?php _e('Top level', 'ap'); ?></option>
109+
<option value="0"><?php _e('Top level', 'ap' ); ?></option>
104110
<?php
105-
if($categories)
106-
foreach($categories as $c)
107-
echo '<option value="'.$c->term_id.'" '.selected($parent, $c->term_id ).'>'.$c->name.'</option>';
111+
if ( $categories ) {
112+
foreach ( $categories as $c ) {
113+
echo '<option value="'.$c->term_id.'" '.selected($parent, $c->term_id ).'>'.$c->name.'</option>'; }
114+
}
108115

109116
?>
110-
</select>
111-
</p>
112-
<p>
117+
</select>
118+
</p>
119+
<p>
113120
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number:', 'ap' ); ?></label>
114121
<input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>">
115-
</p>
116-
<p>
122+
</p>
123+
<p>
117124
<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order By:', 'ap' ); ?></label>
118125
<select class="widefat" id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>">
119-
<option value="none" <?php echo selected($orderby, 'none' ); ?>><?php _e('None', 'ap'); ?></option>
120-
<option value="count" <?php echo selected($orderby, 'count' ); ?>><?php _e('Count', 'ap'); ?></option>
121-
<option value="id" <?php echo selected($orderby, 'id' ); ?>><?php _e('ID', 'ap'); ?></option>
122-
<option value="name" <?php echo selected($orderby, 'name' ); ?>><?php _e('Name', 'ap'); ?></option>
123-
<option value="slug" <?php echo selected($orderby, 'slug' ); ?>><?php _e('Slug', 'ap'); ?></option>
124-
<option value="term_group" <?php echo selected($orderby, 'term_group' ); ?>><?php _e('Term group', 'ap'); ?></option>
125-
</select>
126-
</p>
127-
<p>
126+
<option value="none" <?php echo selected($orderby, 'none' ); ?>><?php _e('None', 'ap' ); ?></option>
127+
<option value="count" <?php echo selected($orderby, 'count' ); ?>><?php _e('Count', 'ap' ); ?></option>
128+
<option value="id" <?php echo selected($orderby, 'id' ); ?>><?php _e('ID', 'ap' ); ?></option>
129+
<option value="name" <?php echo selected($orderby, 'name' ); ?>><?php _e('Name', 'ap' ); ?></option>
130+
<option value="slug" <?php echo selected($orderby, 'slug' ); ?>><?php _e('Slug', 'ap' ); ?></option>
131+
<option value="term_group" <?php echo selected($orderby, 'term_group' ); ?>><?php _e('Term group', 'ap' ); ?></option>
132+
</select>
133+
</p>
134+
<p>
128135
<label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', 'ap' ); ?></label>
129136
<select class="widefat" id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>">
130-
<option value="DESC" <?php echo selected($order, 'DESC' ); ?>><?php _e('DESC', 'ap'); ?></option>
131-
<option value="ASC" <?php echo selected($order, 'ASC' ); ?>><?php _e('ASC', 'ap'); ?></option>
132-
</select>
133-
</p>
137+
<option value="DESC" <?php echo selected($order, 'DESC' ); ?>><?php _e('DESC', 'ap' ); ?></option>
138+
<option value="ASC" <?php echo selected($order, 'ASC' ); ?>><?php _e('ASC', 'ap' ); ?></option>
139+
</select>
140+
</p>
134141
<?php
135142
}
136143

@@ -156,3 +163,9 @@ public function update( $new_instance, $old_instance ) {
156163
return $instance;
157164
}
158165
}
166+
167+
function ap_category_register_widgets() {
168+
register_widget( 'AnsPress_Category_Widget' );
169+
}
170+
171+
add_action( 'widgets_init', 'ap_category_register_widgets' );

0 commit comments

Comments
 (0)