get_attributes(); /** * Set default blocks attributes to avoid errors */ $attributes['className'] = array( 'type' => 'string', 'default' => '', ); if ( class_exists( 'JET_SM\Gutenberg\Block_Manager' ) && class_exists( 'JET_SM\Gutenberg\Block_Manager' ) ) { $this->set_css_scheme(); $this->set_style_manager_instance(); $this->add_style_manager_options(); } register_block_type( $this->namespace . $this->get_name(), array( 'attributes' => $attributes, 'render_callback' => array( $this, 'render_callback' ), 'script' => $this->get_script_depends(), 'style' => $this->get_style_depends(), 'editor_script' => $this->get_editor_script_depends(), 'editor_style' => $this->get_editor_style_depends(), ) ); } public function get_script_depends() { return ''; } public function get_style_depends() { return ''; } public function get_editor_script_depends() { return 'jet-smart-filters'; } public function get_editor_style_depends() { return 'jet-smart-filters'; } /** * Return attributes array */ public function get_attributes() { return array( '__internalWidgetId' => array( 'type' => 'string', 'default' => '', ), // General 'filter_id' => array( 'type' => 'number', 'default' => 0, ), 'content_provider' => array( 'type' => 'string', 'default' => 'not-selected', ), 'apply_type' => array( 'type' => 'string', 'default' => 'ajax', ), 'apply_on' => array( 'type' => 'string', 'default' => 'value', ), 'apply_button' => array( 'type' => 'boolean', 'default' => false, ), 'hide_apply_button' => array( 'type' => 'boolean', 'default' => false, ), 'apply_button_text' => array( 'type' => 'string', 'default' => __( 'Apply filter', 'jet-smart-filters' ), ), 'apply_redirect' => array( 'type' => 'boolean', 'default' => false, ), 'redirect_path' => array( 'type' => 'string', 'default' => '', ), 'remove_filters_text' => array( 'type' => 'string', 'default' => __( 'Remove filters', 'jet-smart-filters' ), ), 'show_label' => array( 'type' => 'boolean', 'default' => false, ), 'filters_label' => array( 'type' => 'string', 'default' => __( 'Active filters:', 'jet-smart-filters' ), ), 'typing_min_letters_count' => array( 'type' => 'number', 'default' => 3, ), 'tags_label' => array( 'type' => 'string', 'default' => __( 'Active tags:', 'jet-smart-filters' ), ), 'clear_item' => array( 'type' => 'boolean', 'default' => true, ), 'clear_item_label' => array( 'type' => 'string', 'default' => __( 'Clear', 'jet-smart-filters' ), ), 'rating_icon' => array( 'type' => 'string', 'default' => 'fa fa-star', ), 'sorting_label' => array( 'type' => 'string', 'default' => '', ), 'sorting_placeholder' => array( 'type' => 'string', 'default' => __( 'Sort...', 'jet-smart-filters' ), ), 'sorting_list' => array( 'type' => 'array', 'default' => array( array( 'title' => __( 'By title from lowest to highest', 'jet-smart-filters' ), 'orderby' => 'title', 'order' => 'ASC' ), array( 'title' => __( 'By title from highest to lowest', 'jet-smart-filters' ), 'orderby' => 'title', 'order' => 'DESC' ), array( 'title' => __( 'By date from lowest to highest', 'jet-smart-filters' ), 'orderby' => 'date', 'order' => 'ASC' ), array( 'title' => __( 'By date from highest to lowest', 'jet-smart-filters' ), 'orderby' => 'date', 'order' => 'DESC' ) ), 'items' => [ 'type' => 'object' ] ), 'query_id' => array( 'type' => 'string', 'default' => '', ), // Indexer 'apply_indexer' => array( 'type' => 'boolean', 'default' => false, ), 'show_counter' => array( 'type' => 'boolean', 'default' => false, ), 'counter_prefix' => array( 'type' => 'string', 'default' => '(', ), 'counter_suffix' => array( 'type' => 'string', 'default' => ')', ), 'show_items_rule' => array( 'type' => 'string', 'default' => 'show', ), 'change_items_rule' => array( 'type' => 'string', 'default' => 'always', ), // Filter Options 'show_items_label' => array( 'type' => 'boolean', 'default' => true, ), 'filter_image_size' => array( 'type' => 'string', 'default' => 'full', ), // Pagination Controls 'enable_items' => array( 'type' => 'boolean', 'default' => true, ), 'pages_center_offset' => array( 'type' => 'number', 'default' => 0, ), 'pages_end_offset' => array( 'type' => 'number', 'default' => 0, ), 'enable_prev_next' => array( 'type' => 'boolean', 'default' => true, ), 'prev_text' => array( 'type' => 'string', 'default' => __( 'Prev Text', 'jet-smart-filters' ), ), 'next_text' => array( 'type' => 'string', 'default' => __( 'Next Text', 'jet-smart-filters' ), ), 'enable_load_more' => array( 'type' => 'boolean', 'default' => false, ), 'load_more_text' => array( 'type' => 'string', 'default' => __( 'Load More', 'jet-smart-filters' ), ), 'autoscroll' => array( 'type' => 'boolean', 'default' => true, ), 'provider_top_offset' => array( 'type' => 'number', 'default' => 0, ), // Additional Settings 'search_enabled' => array( 'type' => 'boolean', 'default' => false, ), 'search_placeholder' => array( 'type' => 'string', 'default' => __( 'Search...', 'jet-smart-filters' ), ), 'moreless_enabled' => array( 'type' => 'boolean', 'default' => false, ), 'less_items_count' => array( 'type' => 'number', 'default' => 5, ), 'more_text' => array( 'type' => 'string', 'default' => __( 'More', 'jet-smart-filters' ), ), 'less_text' => array( 'type' => 'string', 'default' => __( 'Less', 'jet-smart-filters' ), ), 'dropdown_enabled' => array( 'type' => 'boolean', 'default' => false, ), 'dropdown_placeholder' => array( 'type' => 'string', 'default' => __( 'Select some options', 'jet-smart-filters' ), ), 'scroll_enabled' => array( 'type' => 'boolean', 'default' => false, ), 'scroll_height' => array( 'type' => 'number', 'default' => 290, ), ); } /** * Set style manager class instance */ public function set_style_manager_instance() { $name = $this->namespace . $this->get_name(); $this->block_manager = JET_SM\Gutenberg\Block_Manager::get_instance(); $this->controls_manager = new JET_SM\Gutenberg\Controls_Manager( $name ); } /** * Add style block options */ public function add_style_manager_options() {} /** * Set css classes */ public function set_css_scheme() { $this->css_scheme = []; } /** * Is editor context */ public function is_editor() { return isset( $_REQUEST['context'] ) && $_REQUEST['context'] === 'edit' ? true : false; } /** * Return callback */ public function render_callback( $settings = array() ) { jet_smart_filters()->set_filters_used(); // Enqueue assets for Date Period block if ( $this->get_name() === 'date-period' ) { wp_enqueue_script( 'air-datepicker' ); wp_enqueue_style( 'air-datepicker' ); } if ( empty( $settings['filter_id'] ) ) { return $this->is_editor() ? __( 'Please select a filter', 'jet-smart-filters' ) : false; } if ( empty( $settings['content_provider'] ) || $settings['content_provider'] === 'not-selected' ) { return $this->is_editor() ? __( 'Please select a provider', 'jet-smart-filters' ) : false; } if ( 'submit' === $settings['apply_on'] && in_array( $settings['apply_type'], ['ajax', 'mixed'] ) ) { $apply_type = $settings['apply_type'] . '-reload'; } else { $apply_type = $settings['apply_type']; } $filter_id = $settings['filter_id']; $base_class = 'jet-smart-filters-' . $this->get_name(); $provider = $settings['content_provider']; $query_id = ! empty( $settings['query_id'] ) ? $settings['query_id'] : 'default'; $show_label = $settings['show_label']; $show_items_label = $settings['show_items_label']; $show_decorator = true; $filter_image_size = $settings['filter_image_size']; $rating_icon = ''; $apply_indexer = $settings['apply_indexer']; $indexer_class = ''; $show_counter = false; $show_items_rule = 'show'; $change_items_rule = $settings['change_items_rule']; // search $search_enabled = ! empty( $settings['search_enabled'] ) ? filter_var( $settings['search_enabled'], FILTER_VALIDATE_BOOLEAN ) : false; $search_placeholder = ! empty( $settings['search_placeholder'] ) && $search_enabled ? $settings['search_placeholder'] : false; // more/less $less_items_count = ! empty( $settings['moreless_enabled'] ) && ! empty( $settings['less_items_count'] ) ? (int)$settings['less_items_count'] : false; $more_text = ! empty( $settings['more_text'] ) ? $settings['more_text'] : false; $less_text = ! empty( $settings['less_text'] ) ? $settings['less_text'] : false; // dropdown $dropdown_enabled = ! empty( $settings['dropdown_enabled'] ) ? $settings['dropdown_enabled'] : false; $dropdown_placeholder = ! empty( $settings['dropdown_placeholder'] ) ? $settings['dropdown_placeholder'] : false; // scroll $scroll_height = ! empty( $settings['scroll_enabled'] ) && ! empty( $settings['scroll_height'] ) ? (int)$settings['scroll_height'] : false; if ( $apply_indexer ) { $indexer_class = 'jet-filter-indexed'; $show_counter = $settings['show_counter'] === true ? 'yes' : false; $show_items_rule = $settings['show_items_rule']; if ( $show_counter ) { $counter_prefix = ! empty( $settings['counter_prefix'] ) ? $settings['counter_prefix'] : false; $counter_suffix = ! empty( $settings['counter_suffix'] ) ? $settings['counter_suffix'] : false; } } jet_smart_filters()->admin_bar_register_item( $filter_id ); ob_start(); printf( '