| 1 |
<?php |
| 2 |
/** |
| 3 |
* Campaign categories/tags widget class. |
| 4 |
* |
| 5 |
* @package Charitable/Widgets/Charitable_Campaign_Terms_Widget |
| 6 |
* @category Class |
| 7 |
* @author David Bisset |
| 8 |
* @since 1.0.0 |
| 9 |
* @version 1.5.4 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Campaign_Terms_Widget' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Campaign_Terms_Widget class. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Charitable_Campaign_Terms_Widget extends WP_Widget { |
| 25 |
|
| 26 |
/** |
| 27 |
* Instantiate the widget and set up basic configuration. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 32 |
parent::__construct( |
| 33 |
'charitable_campaign_terms_widget', |
| 34 |
__( 'Campaign Categories / Tags', 'charitable' ), |
| 35 |
array( |
| 36 |
'description' => __( 'Displays your Charitable campaign categories or tags.', 'charitable' ), |
| 37 |
// 'customize_selective_refresh' => true |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Display the widget contents on the front-end. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* |
| 47 |
* @param array $args |
| 48 |
* @param array $instance |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function widget( $args, $instance ) { |
| 52 |
$view_args = array_merge( $args, $instance ); |
| 53 |
$template = array_key_exists( 'dropdown', $view_args ) && $view_args['dropdown'] ? 'widgets/campaign-terms-dropdown.php' : 'widgets/campaign-terms.php'; |
| 54 |
|
| 55 |
charitable_template( $template, $view_args ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Display the widget form in the admin. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* |
| 63 |
* @param array $instance The current settings for the widget options. |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function form( $instance ) { |
| 67 |
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
| 68 |
$taxonomy = isset( $instance['taxonomy'] ) ? $instance['taxonomy'] : 'campaign_category'; |
| 69 |
$show_count = isset( $instance['show_count'] ) && $instance['show_count']; |
| 70 |
$hide_empty = isset( $instance['hide_empty'] ) && $instance['hide_empty']; |
| 71 |
$dropdown = isset( $instance['dropdown'] ) && $instance['dropdown']; |
| 72 |
?> |
| 73 |
<p> |
| 74 |
<label for="<?php echo $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:', 'charitable' ) ?></label> |
| 75 |
<input type="text" name="<?php echo $this->get_field_name('title' ) ?>" id="<?php echo $this->get_field_id( 'title' ) ?>" value="<?php echo $title ?>"/> |
| 76 |
</p> |
| 77 |
<p> |
| 78 |
<label for="<?php echo $this->get_field_id( 'taxonomy' ) ?>"><?php _e( 'Taxonomy', 'charitable' ) ?></label> |
| 79 |
<select name="<?php echo $this->get_field_name('taxonomy' ) ?>" id="<?php echo $this->get_field_id( 'taxonomy' ) ?>"> |
| 80 |
<option value="campaign_category" <?php selected( 'campaign_category', $taxonomy ) ?>><?php _e( 'Categories', 'charitable' ) ?></option> |
| 81 |
<option value="campaign_tag" <?php selected( 'campaign_tag', $taxonomy ) ?>><?php _e( 'Tags', 'charitable' ) ?></option> |
| 82 |
</select> |
| 83 |
</p> |
| 84 |
<p> |
| 85 |
<label for="<?php echo $this->get_field_id( 'show_count' ) ?>"><?php _e( 'Show count:', 'charitable' ) ?></label> |
| 86 |
<input type="checkbox" name="<?php echo $this->get_field_name('show_count' ) ?>" id="<?php echo $this->get_field_id( 'show_count' ) ?>" <?php checked( $show_count ) ?> /> |
| 87 |
</p> |
| 88 |
<p> |
| 89 |
<label for="<?php echo $this->get_field_id( 'hide_empty' ) ?>"><?php _e( 'Hide empty:', 'charitable' ) ?></label> |
| 90 |
<input type="checkbox" name="<?php echo $this->get_field_name('hide_empty' ) ?>" id="<?php echo $this->get_field_id( 'hide_empty' ) ?>" <?php checked( $hide_empty ) ?> /> |
| 91 |
</p> |
| 92 |
<p> |
| 93 |
<label for="<?php echo $this->get_field_id( 'dropdown' ) ?>"><?php _e( 'Display as dropdown:', 'charitable' ) ?></label> |
| 94 |
<input type="checkbox" name="<?php echo $this->get_field_name( 'dropdown' ) ?>" id="<?php echo $this->get_field_id( 'dropdown' ) ?>" <?php checked( $dropdown ) ?> /> |
| 95 |
</p> |
| 96 |
<?php |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Update the widget settings in the admin. |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
* |
| 104 |
* @param array $new_instance The updated settings. |
| 105 |
* @param array $new_instance The old settings. |
| 106 |
* @return void |
| 107 |
*/ |
| 108 |
public function update( $new_instance, $old_instance ) { |
| 109 |
$instance = array(); |
| 110 |
$instance['title'] = isset( $new_instance['title'] ) ? $new_instance['title'] : $old_instance['title']; |
| 111 |
$instance['taxonomy'] = isset( $new_instance['taxonomy'] ) ? $new_instance['taxonomy'] : $old_instance['taxonomy']; |
| 112 |
$instance['show_count'] = isset( $new_instance['show_count'] ) && $new_instance['show_count'] == 'on'; |
| 113 |
$instance['hide_empty'] = isset( $new_instance['hide_empty'] ) && $new_instance['hide_empty'] == 'on'; |
| 114 |
$instance['dropdown'] = isset( $new_instance['dropdown'] ) && $new_instance['dropdown'] == 'on'; |
| 115 |
return $instance; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
endif; |