esc_html__( 'Filters Widget', 'filter-everything' ), 'show_instance_in_rest' => false, ) ); } /** * 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 ) { extract( $args ); $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; $show_selected_class = ( !empty( $instance['chips'] ) ) ? ' wpc-show-on-desktop' : ''; $show_count = ( !empty( $instance['show_count'] ) ) ? $instance['show_count'] : ''; $set_id = isset( $instance['id'] ) ? preg_replace('/[^\d]?/', '', $instance['id'] ) : 0; // Display nothing if preview mode if( isset( $_GET['legacy-widget-preview'] ) || isset( $_GET['_locale'] ) ){ return; } if( isset( $_POST['action'] ) && $_POST['action'] === 'elementor_ajax' ){ echo ''.esc_html__( 'Filters Widget', 'filter-everything' ).''; return; } /** * @feature Add ability to choose what filter Set to display in widget settings */ $debug_mode = flrt_is_debug_mode(); $container = Container::instance(); $wpManager = $container->getWpManager(); if( ! $wpManager->getQueryVar( 'allowed_filter_page' ) ){ if( $debug_mode ){ if( defined('FLRT_FILTERS_PRO') ){ echo '

'; echo sprintf( wp_kses( __( 'No one Filter Set is related with this page. You can configure it in the Filter Set location field.', 'filter-everything' ), array( 'a' => array('href' => true) ) ), admin_url( 'edit.php?post_type=filter-set' ) ); echo '

'; }else{ if( is_singular() ){ echo '

'; echo sprintf( wp_kses( __( 'The free version of the plugin does not support filtering on singular pages. But PRO version supports.', 'filter-everything' ), array( 'a' => array('href' => true) ) ), esc_url(FLRT_PLUGIN_LINK .'/?get_pro=true') ); echo '

'; }else{ echo '

'; echo sprintf( wp_kses( __( 'No one Filter Set is configured for this post type pages. You can create a new Filter Set for them.', 'filter-everything' ), array( 'a' => array('href' => true) ) ), admin_url( 'edit.php?post_type=filter-set' ) ); echo '

'; } } flrt_debug_title(); } return false; } $templateManager = $container->getTemplateManager(); $em = $container->getEntityManager(); $fss = $container->getFilterSetService(); $urlManager = new UrlManager(); $has_not_empty_children = []; $theSet = flrt_the_set( $set_id ); if( ! $theSet ){ return false; } $setId = $theSet['ID']; $posType = $theSet['filtered_post_type']; $set = $fss->getSet( $theSet['ID'] ); $chipsObj = new Chips(true, array($setId) ); $chips = $chipsObj->getChips(); $set_edit_url = ( isset( $theSet['ID'] )) ? admin_url('post.php?post='.$theSet['ID'].'&action=edit') : admin_url( 'edit.php?post_type=filter-set' ); $related_filters = $em->getSetsRelatedFilters( array( $theSet ) ); $found_posts = flrt_posts_found_quantity( $setId, true ); $actionUrl = $urlManager->getFormActionUrl(true); if( empty( $related_filters ) ){ if( $debug_mode ){ echo '

'; echo sprintf( wp_kses( __( 'There are no filters in the Filter Set yet. Please add them to the Filter Set related to this page.', 'filter-everything' ), array( 'a' => array('href' => true) ) ), $set_edit_url ); echo '

'; flrt_debug_title(); } return false; } echo $before_widget; echo '
'."\n"; // Open/Closed status class $widgetContentClass = flrt_filters_widget_content_class($setId); if( flrt_get_experimental_option('disable_buttons') !== 'on' ) { flrt_filters_button($setId, $widgetContentClass); } echo '
'; echo ''; if ( ! empty( $title ) ) { echo '
'."\n"; echo $before_title . $title . $after_title; echo '
'."\n"; } echo flrt_spinner_html(); echo '
'; echo '
'."\r\n"; if( $show_count ){ flrt_posts_found( $setId ); } // Add selected terms for mobile widget echo '
'; $templateManager->includeFrontView( 'chips', array( 'chips' => $chips, 'setid' => $setId ) ); echo '
'; foreach ( $related_filters as $filter ){ $entityObj = $em->getEntityByFilter( $filter, $posType ); $entityObj->setExcludedTerms( $filter['exclude'] ); $terms = $entityObj->getTerms(); if( $filter['hierarchy'] === 'yes' ){ $has_not_empty_children = flrt_get_parents_with_not_empty_children( $terms, 'count' ); } // Create a list with excluded empty terms if( ( $set['hide_empty']['value'] === 'yes' ) || ( isset( $set['hide_empty_filter'] ) && $set['hide_empty_filter']['value'] === 'yes' ) ){ $allWpQueriedPostIds = $em->getAllSetWpQueriedPostIds( $setId ); $checkTerms = $terms; foreach ($checkTerms as $index => $term) { if( $filter['hierarchy'] === 'yes' ){ if( empty( array_intersect( $allWpQueriedPostIds, $term->posts ) ) && ! in_array( $term->term_id, $has_not_empty_children ) ){ unset($checkTerms[$index]); } }else{ if( empty( array_intersect( $allWpQueriedPostIds, $term->posts ) ) ){ unset($checkTerms[$index]); } } } } // Remove empty terms, if such option is enabled if( $set['hide_empty']['value'] === 'yes' && ($filter['entity'] !== 'post_meta_num') ) { $terms = $checkTerms; } // Hide Filter if there are no posts in its terms if( isset( $set['hide_empty_filter'] ) && $set['hide_empty_filter']['value'] === 'yes' ){ if( $filter['entity'] === 'post_meta_num' ){ // Temporary not ideal solution if( $terms[0]->max === NULL && $terms[1]->min === NULL ){ // Huh, finally continue; } }else{ if( empty( $checkTerms ) ){ // Huh, finally continue; } } } $terms = flrt_extract_objects_vars( $terms, array( 'term_id', 'slug', 'name', 'count', 'cross_count', 'max', 'min', 'absMax', 'absMin', 'parent') ); // Hook terms before display to allow developers modify them. $terms = apply_filters( 'wpc_terms_before_display', $terms, $filter, $set, $urlManager ); $templateManager->includeFrontView( apply_filters( 'wpc_view_include_filename', $filter['view'], $filter ), array( 'filter' => $filter, 'terms' => $terms, 'set' => $set, 'url_manager' => $urlManager ) ); } echo '
'."\r\n"; echo '
' . "\r\n"; if( current_user_can( 'manage_options' ) ){ echo '
'; echo sprintf( wp_kses( __( 'Edit Filter Set', 'filter-everything' ), array( 'a' => array('href' => true) ) ), $set_edit_url ); echo '
'; } echo '
' . "\r\n"; // Show button, that opens bottom filters container $wpc_mobile_width = flrt_get_mobile_width(); echo ''."\r\n"; echo '
'."\n"; // echo $after_widget; } public function form( $instance ) { $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; $chips = isset( $instance['chips'] ) ? (bool) $instance['chips'] : false; $show_count = isset( $instance['show_count'] ) ? (bool) $instance['show_count'] : true; ?>

/>

/>