This commit is contained in:
nguyen dung
2022-02-18 16:43:41 +07:00
commit 39b8cb3612
4470 changed files with 1378320 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
<?php
add_action( 'widgets_init', 'ux_blocks_widget' );
function ux_blocks_widget() {
register_widget( 'Flatsome_UX_Blocks_Widget' );
}
/**
* Recent_Posts widget class
*
* @since 2.8.0
*/
class Flatsome_UX_Blocks_Widget extends WP_Widget {
function __construct() {
$widget_ops = array( 'classname' => 'block_widget', 'description' => __('A widget that displays a Block ', 'flatsome'), 'customize_selective_refresh' => true);
$control_ops = array('id_base' => 'block_widget' );
parent::__construct( 'block_widget', __('Flatsome Blocks', 'flatsome'), $widget_ops, $control_ops );
}
function widget($args, $instance) {
$cache = wp_cache_get('block_widget', 'widget');
if ( !is_array($cache) )
$cache = array();
if ( ! isset( $args['widget_id'] ) )
$args['widget_id'] = $this->id;
if ( isset( $cache[ $args['widget_id'] ] ) ) {
echo $cache[ $args['widget_id'] ];
return;
}
ob_start();
extract($args);
?>
<?php echo $before_widget; ?>
<?php if (!empty($instance['title']) ) echo $before_title . $instance['title'] . $after_title; ?>
<?php if(!empty($instance['block'])) echo do_shortcode('[block id="'.$instance['block'].'"]'); ?>
<?php echo $after_widget; ?>
<?php
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('block_widget', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags($new_instance['title']);
$instance['block'] = ( ! empty( $new_instance['block'] ) ) ? strip_tags( $new_instance['block'] ) : '';
$this->flush_widget_cache();
return $instance;
}
function flush_widget_cache() {
wp_cache_delete('block_widget', 'widget');
}
function form( $instance ) {
$blocks = array(false => '-- None --');
$posts = flatsome_get_post_type_items('blocks');
if($posts){
foreach ($posts as $value) {
$blocks[$value->post_name] = $value->post_title;
}
}
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$instance['block'] = isset( $instance['block'] ) ? esc_attr( $instance['block'] ) : '';
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'flatsome' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id( 'block' ); ?>"><?php _e( 'Block:', 'flatsome' ); ?></label>
<select class="widefat" name="<?php echo $this->get_field_name( 'block' ); ?>" id="<?php echo $this->get_field_id( 'block' ); ?>">
<?php foreach ($blocks as $key => $value) {
echo '<option '.selected( $instance['block'], $key).' value="'.$key.'">'.$value.'</option>';
} ?>
</select></p>
<p>You can edit blocks with the UX Builder if you hover them in the front-end.<br/><a href="http://docs.uxthemes.com/article/237-ux-builder-how-to-use-blocks" target="_blank">Learn more about Blocks</a></p>
<?php
}
}
?>

View File

@@ -0,0 +1,146 @@
<?php
add_action( 'widgets_init', 'recent_posts_widget' );
function recent_posts_widget() {
register_widget( 'Flatsome_Recent_Post_Widget' );
}
/**
* Recent_Posts widget class
*
* @since 2.8.0
*/
class Flatsome_Recent_Post_Widget extends WP_Widget {
function __construct() {
$widget_ops = array( 'classname' => 'flatsome_recent_posts', 'description' => __('A widget that displays recent posts ', 'flatsome'), 'customize_selective_refresh' => true);
$control_ops = array( 'id_base' => 'flatsome_recent_posts' );
parent::__construct( 'flatsome_recent_posts', __('Flatsome Recent Posts', 'flatsome'), $widget_ops, $control_ops );
}
function widget($args, $instance) {
$cache = wp_cache_get('widget_recent_posts', 'widget');
if ( !is_array($cache) )
$cache = array();
if ( !isset( $args['widget_id'] ) )
$args['widget_id'] = $this->id;
if ( isset( $cache[ $args['widget_id'] ] ) ) {
echo $cache[ $args['widget_id'] ];
return;
}
ob_start();
extract($args);
if ( empty( $instance['image'] ) ) $instance['image'] = false;
$is_image = $instance['image'] ? 'true' : 'false';
if ( empty( $instance['date-stamp'] ) ) $instance['date-stamp'] = false;
$is_date_stamp = $instance['date-stamp'] ? 'true' : 'false';
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'flatsome') : $instance['title'], $instance, $this->id_base);
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
$number = 10;
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
if ($r->have_posts()) :
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php echo '<ul>'; ?>
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<?php
$image_style = '';
if($is_image == 'true' && has_post_thumbnail() && $is_date_stamp == 'true') {
$image_style = 'style="background: linear-gradient( rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.2) ), url('.wp_get_attachment_thumb_url(get_post_thumbnail_id(get_the_ID()) ).'); color:#fff; text-shadow:1px 1px 0px rgba(0,0,0,.5); border:0;"';
}
else if($is_image == 'true' && has_post_thumbnail() && $is_date_stamp == 'false') {
$image_style = 'style="background: url('.wp_get_attachment_thumb_url(get_post_thumbnail_id(get_the_ID()) ).'); border:0;"';
}
?>
<li class="recent-blog-posts-li">
<div class="flex-row recent-blog-posts align-top pt-half pb-half">
<div class="flex-col mr-half">
<div class="badge post-date <?php if($is_image == 'false') echo 'badge-small';?> badge-<?php echo flatsome_option('blog_badge_style'); ?>">
<div class="badge-inner bg-fill" <?php echo $image_style;?>>
<?php if($is_date_stamp == 'true' || !has_post_thumbnail() || $is_image == 'false') { ?>
<span class="post-date-day"><?php echo get_the_time('d', get_the_ID()); ?></span><br>
<span class="post-date-month is-xsmall"><?php echo get_the_time('M', get_the_ID()); ?></span>
<?php } ?>
</div>
</div>
</div>
<div class="flex-col flex-grow">
<a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
<span class="post_comments op-7 block is-xsmall"><?php comments_popup_link( '', __( '<strong>1</strong> Comment', 'flatsome' ), __( '<strong>%</strong> Comments', 'flatsome' ) ); ?></span>
</div>
</div>
</li>
<?php endwhile; ?>
<?php echo '</ul>'; ?>
<?php echo $after_widget; ?>
<?php
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
endif;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_recent_posts', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['image'] = $new_instance['image'];
$instance['date-stamp'] = $new_instance['date-stamp'];
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['widget_recent_entries']) )
delete_option('widget_recent_entries');
return $instance;
}
function flush_widget_cache() {
wp_cache_delete('widget_recent_posts', 'widget');
}
function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$instance['image'] = isset( $instance['image'] ) ? $instance['image'] : false;
$instance['date-stamp'] = isset( $instance['date-stamp'] ) ? $instance['date-stamp'] : false;
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'flatsome' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:', 'flatsome' ); ?></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>
<p><input class="checkbox" type="checkbox" <?php checked($instance['image'], 'on'); ?> id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" />
<label for="<?php echo $this->get_field_id( 'image' ); ?>"><?php _e( 'Show thumbnail', 'flatsome' ); ?></label></p>
<p><input class="checkbox" type="checkbox" <?php checked($instance['date-stamp'], 'on'); ?> id="<?php echo $this->get_field_id('date-stamp'); ?>" name="<?php echo $this->get_field_name('date-stamp'); ?>" />
<label for="<?php echo $this->get_field_id( 'date-stamp' ); ?>"><?php _e( 'Show date stamp on thumbnail', 'flatsome' ); ?></label>
<?php echo '<p><small>' . __('* If a featured image is not set or the "Show Thumbnail" option is disabled, the date stamp will always be displayed.', 'flatsome') . '</small></p>'; ?></p>
<?php
}
}
?>

View File

@@ -0,0 +1,126 @@
<?php
/**
* Adds Upsell_Widget.
*/
function register_upsell_widget() {
register_widget( 'Upsell_Widget' );
}
add_action( 'widgets_init', 'register_upsell_widget' );
class Upsell_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'upsell_widget', // Base ID
'Flatsome Upsell Products', // Name
array( 'description' => __( 'Add upsell products to product page', 'flatsome' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
global $product;
/* Disable if not on product page */
if(!function_exists('is_product') || !is_product()) return;
$upsells = $product->get_upsell_ids();
if ( sizeof( $upsells ) == 0 ) return;
extract( $args );
if ( isset( $instance[ 'title' ] ) ) {
$title = apply_filters( 'widget_title', $instance['title'] );
}
else {
$title = __( 'Complete the look', 'flatsome' );
}
$meta_query = WC()->query->get_meta_query();
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => 9,
'orderby' => 'rand',
'post__in' => $upsells,
'post__not_in' => array( $product->get_id() ),
'meta_query' => $meta_query
);
$products = new WP_Query( $args );
echo $before_widget;
if ($products->have_posts()) :
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<ul class="up-sell product_list_widget">
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product-small' ); ?>
<?php endwhile; // end of the loop. ?>
</ul>
<?php
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
endif;
echo $after_widget;
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Complete the look', 'flatsome' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title','wordpress'); ?></label>
<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 ); ?>" />
</p>
<?php
}
} // class Foo_Widget