| Server IP : 68.178.247.200 / Your IP : 216.73.217.131 Web Server : Apache System : Linux p3plzcpnl489463.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64 User : x9dppmxs4rgd ( 8559391) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/x9dppmxs4rgd/public_html/wp-content/themes/grace-church/fw/widgets/ |
Upload File : |
<?php
/**
* Add function to widgets_init that will load our widget.
*/
add_action( 'widgets_init', 'grace_church_widget_recent_reviews_load' );
/**
* Register our widget.
*/
function grace_church_widget_recent_reviews_load() {
register_widget('grace_church_widget_recent_reviews');
}
/**
* recent_reviews Widget class.
*/
class grace_church_widget_recent_reviews extends WP_Widget {
/**
* Widget setup.
*/
function __construct() {
/* Widget settings. */
$widget_ops = array('classname' => 'widget_recent_reviews', 'description' => esc_html__('Recent reviews', 'grace-church'));
/* Widget control settings. */
$control_ops = array('width' => 200, 'height' => 250, 'id_base' => 'grace_church_widget_recent_reviews');
/* Create the widget. */
parent::__construct( 'grace_church_widget_recent_reviews', esc_html__('Grace-Church - Recent reviews', 'grace-church'), $widget_ops, $control_ops );
// Add thumb sizes into list
grace_church_add_thumb_sizes( array( 'layout' => 'widgets', 'w' => 75, 'h' => 75, 'h_crop' => 75, 'title'=>__('Widgets', 'grace-church') ) );
}
/**
* How to display the widget on the screen.
*/
function widget($args, $instance) {
extract($args);
global $post;
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : '');
$number = isset($instance['number']) ? (int) $instance['number'] : '';
$show_date = isset($instance['show_date']) ? (int) $instance['show_date'] : 0;
$show_image = isset($instance['show_image']) ? (int) $instance['show_image'] : 0;
$show_author = isset($instance['show_author']) ? (int) $instance['show_author'] : 0;
$show_counters = isset($instance['show_counters']) ? (int) $instance['show_counters'] : 0;
$show_counters = $show_counters==2 ? 'stars' : ($show_counters==1 ? 'rating' : '');
$post_type = isset($instance['post_type']) ? $instance['post_type'] : 'post';
$category = isset($instance['category']) ? (int) $instance['category'] : 0;
$taxonomy = grace_church_get_taxonomy_categories_by_post_type($post_type);
$output = '';
$post_rating = 'reviews_avg'.(grace_church_get_theme_option('reviews_first')=='author' ? '' : '2');
$args = array(
'post_type' => $post_type,
'post_status' => current_user_can('read_private_pages') && current_user_can('read_private_posts') ? array('publish', 'private') : 'publish',
'post_password' => '',
'posts_per_page' => $number,
'ignore_sticky_posts' => true,
'order' => 'DESC',
'orderby' => 'date',
'meta_query' => array(
array(
'key' => $post_rating,
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC'
)
)
);
if ($category > 0) {
if ($taxonomy=='category')
$args['cat'] = $category;
else {
$args['tax_query'] = array(
array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $category
)
);
}
}
$ex = grace_church_get_theme_option('exclude_cats');
if (!empty($ex)) {
$args['category__not_in'] = explode(',', $ex);
}
$q = new WP_Query($args);
/* Loop posts */
if ($q->have_posts()) {
$post_number = 0;
while ($q->have_posts()) { $q->the_post();
$post_number++;
require(grace_church_get_file_dir('templates/_parts/widgets-posts.php'));
if ($post_number >= $number) break;
}
}
wp_reset_postdata();
if (!empty($output)) {
/* Before widget (defined by themes). */
echo ($before_widget);
/* Display the widget title if one was input (before and after defined by themes). */
if ($title) echo ($before_title) . ($title) . ($after_title);
echo '
<div class="recent_reviews">
' . ($output) . '
</div>
';
/* After widget (defined by themes). */
echo ($after_widget);
}
}
/**
* Update the widget settings.
*/
function update($new_instance, $old_instance) {
$instance = $old_instance;
/* Strip tags for title and comments count to remove HTML (important for text inputs). */
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['show_date'] = (int) $new_instance['show_date'];
$instance['show_image'] = (int) $new_instance['show_image'];
$instance['show_author'] = (int) $new_instance['show_author'];
$instance['show_counters'] = (int) $new_instance['show_counters'];
$instance['category'] = (int) $new_instance['category'];
$instance['post_type'] = strip_tags( $new_instance['post_type'] );
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form($instance) {
// Set up some default widget settings
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'number' => '4',
'show_date' => '1',
'show_image' => '1',
'show_author' => '1',
'show_counters' => '1',
'category' => '0',
'post_type' => 'post'
)
);
$title = $instance['title'];
$number = (int) $instance['number'];
$show_date = (int) $instance['show_date'];
$show_image = (int) $instance['show_image'];
$show_author = (int) $instance['show_author'];
$show_counters = (int) $instance['show_counters'];
$post_type = $instance['post_type'];
$category = (int) $instance['category'];
$posts_types = grace_church_get_list_posts_types(false);
$categories = grace_church_get_list_terms(false, grace_church_get_taxonomy_categories_by_post_type($post_type));
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Widget title:', 'grace-church'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" value="<?php echo esc_attr($title); ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('post_type')); ?>"><?php esc_html_e('Post type:', 'grace-church'); ?></label>
<select id="<?php echo esc_attr($this->get_field_id('post_type')); ?>" name="<?php echo esc_attr($this->get_field_name('post_type')); ?>" style="width:100%;" onchange="grace_church_admin_change_post_type(this);">
<?php
if (is_array($posts_types) && count($posts_types) > 0) {
foreach ($posts_types as $type => $type_name) {
echo '<option value="'.esc_attr($type).'"'.($post_type==$type ? ' selected="selected"' : '').'>'.esc_html($type_name).'</option>';
}
}
?>
</select>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('category')); ?>"><?php esc_html_e('Category:', 'grace-church'); ?></label>
<select id="<?php echo esc_attr($this->get_field_id('category')); ?>" name="<?php echo esc_attr($this->get_field_name('category')); ?>" style="width:100%;">
<option value="0"><?php esc_html_e('-- Any category --', 'grace-church'); ?></option>
<?php
if (is_array($categories) && count($categories) > 0) {
foreach ($categories as $cat_id => $cat_name) {
echo '<option value="'.esc_attr($cat_id).'"'.($category==$cat_id ? ' selected="selected"' : '').'>'.esc_html($cat_name).'</option>';
}
}
?>
</select>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('number')); ?>"><?php esc_html_e('Number posts to show:', 'grace-church'); ?></label>
<input type="text" id="<?php echo esc_attr($this->get_field_id('number')); ?>" name="<?php echo esc_attr($this->get_field_name('number')); ?>" value="<?php echo esc_attr($number); ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('show_image')); ?>_1"><?php esc_html_e('Show post image:', 'grace-church'); ?></label><br />
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_image')); ?>_1" name="<?php echo esc_attr($this->get_field_name('show_image')); ?>" value="1" <?php echo ($show_image==1 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_image')); ?>_1"><?php esc_html_e('Show', 'grace-church'); ?></label>
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_image')); ?>_0" name="<?php echo esc_attr($this->get_field_name('show_image')); ?>" value="0" <?php echo ($show_image==0 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_image')); ?>_0"><?php esc_html_e('Hide', 'grace-church'); ?></label>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('show_author')); ?>_1"><?php esc_html_e('Show post author:', 'grace-church'); ?></label><br />
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_author')); ?>_1" name="<?php echo esc_attr($this->get_field_name('show_author')); ?>" value="1" <?php echo ($show_author==1 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_author')); ?>_1"><?php esc_html_e('Show', 'grace-church'); ?></label>
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_author')); ?>_0" name="<?php echo esc_attr($this->get_field_name('show_author')); ?>" value="0" <?php echo ($show_author==0 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_author')); ?>_0"><?php esc_html_e('Hide', 'grace-church'); ?></label>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('show_date')); ?>_1"><?php esc_html_e('Show post date:', 'grace-church'); ?></label><br />
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_date')); ?>_1" name="<?php echo esc_attr($this->get_field_name('show_date')); ?>" value="1" <?php echo ($show_date==1 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_date')); ?>_1"><?php esc_html_e('Show', 'grace-church'); ?></label>
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_date')); ?>_0" name="<?php echo esc_attr($this->get_field_name('show_date')); ?>" value="0" <?php echo ($show_date==0 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_date')); ?>_0"><?php esc_html_e('Hide', 'grace-church'); ?></label>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_1"><?php esc_html_e('Show post counters:', 'grace-church'); ?></label><br />
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_2" name="<?php echo esc_attr($this->get_field_name('show_counters')); ?>" value="2" <?php echo ($show_counters==2 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_2"><?php esc_html_e('As stars', 'grace-church'); ?></label>
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_1" name="<?php echo esc_attr($this->get_field_name('show_counters')); ?>" value="1" <?php echo ($show_counters==1 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_1"><?php esc_html_e('As icon', 'grace-church'); ?></label>
<input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_0" name="<?php echo ($this->get_field_name('show_counters')); ?>" value="0" <?php echo ($show_counters==0 ? ' checked="checked"' : ''); ?> />
<label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?>_0"><?php esc_html_e('Hide', 'grace-church'); ?></label>
</p>
<?php
}
}
?>