| 1 |
<?php |
| 2 |
// phpcs:disable WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- shortcode exposes user-driven exclusion attribute. |
| 3 |
namespace WPDeveloper\BetterDocs\Shortcodes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
|
| 10 |
use WPDeveloper\BetterDocs\Utils\Helper; |
| 11 |
use WPDeveloper\BetterDocs\Core\Shortcode; |
| 12 |
|
| 13 |
class CategoryGridThree extends Shortcode { |
| 14 |
protected $layout_class = 'layout-3'; |
| 15 |
|
| 16 |
public function get_name() { |
| 17 |
return 'betterdocs_category_grid_3'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_style_depends() { |
| 21 |
return [ 'betterdocs-category-grid' ]; |
| 22 |
} |
| 23 |
|
| 24 |
public function get_script_depends() { |
| 25 |
return [ 'betterdocs-category-grid' ]; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Summary of default_attributes |
| 30 |
* @return array |
| 31 |
*/ |
| 32 |
public function default_attributes() { |
| 33 |
return [ |
| 34 |
'sidebar_list' => false, |
| 35 |
'taxonomy' => 'doc_category', |
| 36 |
'show_icon' => true, |
| 37 |
'category_icon' => 'folder', |
| 38 |
'masonry' => false, |
| 39 |
'posts_per_page' => $this->settings->get( 'posts_number', 0 ), |
| 40 |
'orderby' => $this->settings->get( 'alphabetically_order_post', 'betterdocs_order' ), |
| 41 |
'order' => $this->settings->get( 'docs_order', 'ASC' ), |
| 42 |
'show_count' => false, |
| 43 |
'count_suffix' => '', |
| 44 |
'count_suffix_singular' => '', |
| 45 |
'column' => 4, //$this->settings->get( 'column_number' ), |
| 46 |
'terms' => '', |
| 47 |
'terms_orderby' => '', |
| 48 |
'terms_order' => '', |
| 49 |
'terms_include' => '', |
| 50 |
'terms_exclude' => '', |
| 51 |
'terms_offset' => '', |
| 52 |
'kb_slug' => '', |
| 53 |
'multiple_knowledge_base' => false, |
| 54 |
'disable_customizer_style' => false, |
| 55 |
'title_tag' => 'h2', |
| 56 |
'category_title_link' => true, |
| 57 |
'layout_type' => '', |
| 58 |
'list_icon_url' => false, |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
public function generate_attributes() { |
| 63 |
$attributes = [ |
| 64 |
'class' => [ |
| 65 |
'betterdocs-category-grid-inner-wrapper', |
| 66 |
$this->layout_class |
| 67 |
] |
| 68 |
]; |
| 69 |
|
| 70 |
if ( ! is_singular( 'docs' ) && ! is_tax( 'doc_category' ) && ! is_tax( 'doc_tag' ) ) { |
| 71 |
$attributes['class'][] = 'layout-flex'; |
| 72 |
|
| 73 |
if ( $this->isset( 'column' ) ) { |
| 74 |
$_column_val = $this->attributes['column']; |
| 75 |
} else { |
| 76 |
$_column_val = $this->settings->get( 'column_number' ); |
| 77 |
} |
| 78 |
|
| 79 |
$attributes['class'][] = 'docs-col-' . $_column_val; |
| 80 |
$attributes['data-column_desktop'] = esc_html( $_column_val ); |
| 81 |
$attributes['style'] = "--column: $_column_val;"; |
| 82 |
} |
| 83 |
|
| 84 |
return $attributes; |
| 85 |
} |
| 86 |
|
| 87 |
public function header_layout_sequence( $sequence, $layout, $widget_type, $args ) { |
| 88 |
return [ 'category_icon', 'category_title' ]; |
| 89 |
} |
| 90 |
|
| 91 |
public function render( $atts, $content = null ) { |
| 92 |
if ( (bool) $this->attributes['sidebar_list'] ) { |
| 93 |
add_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_layout_sequence' ], 10, 4 ); |
| 94 |
} |
| 95 |
|
| 96 |
$this->views( 'layouts/base' ); |
| 97 |
|
| 98 |
if ( (bool) $this->attributes['sidebar_list'] ) { |
| 99 |
remove_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_layout_sequence' ], 10 ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
public function view_params() { |
| 104 |
$category_title_link = isset( $this->attributes['category_title_link'] ) ? $this->attributes['category_title_link'] : ''; |
| 105 |
|
| 106 |
$terms_query = $this->query->terms_query( |
| 107 |
[ |
| 108 |
'taxonomy' => $this->attributes['taxonomy'], |
| 109 |
'multiple_kb' => ( $this->attributes['multiple_knowledge_base'] && ! empty( $this->attributes['kb_slug'] ) ) ? true : false, |
| 110 |
'kb_slug' => $this->attributes['kb_slug'], |
| 111 |
'terms' => $this->attributes['terms'], |
| 112 |
'order' => $this->attributes['terms_order'], |
| 113 |
'orderby' => $this->attributes['terms_orderby'] |
| 114 |
] |
| 115 |
); |
| 116 |
|
| 117 |
if ( $this->attributes['terms_include'] ) { |
| 118 |
$terms_query['include'] = $this->attributes['terms_include']; |
| 119 |
} |
| 120 |
|
| 121 |
if ( $this->attributes['terms_exclude'] ) { |
| 122 |
$terms_query['exclude'] = $this->attributes['terms_exclude']; |
| 123 |
} |
| 124 |
|
| 125 |
if ( $this->attributes['terms_offset'] ) { |
| 126 |
$terms_query['offset'] = (int) $this->attributes['terms_offset']; |
| 127 |
} |
| 128 |
|
| 129 |
$inner_wrapper_attr = $this->generate_attributes(); |
| 130 |
|
| 131 |
$docs_query = [ |
| 132 |
'orderby' => $this->attributes['orderby'], |
| 133 |
'order' => $this->attributes['order'], |
| 134 |
'posts_per_page' => $this->attributes['posts_per_page'] |
| 135 |
]; |
| 136 |
|
| 137 |
return [ |
| 138 |
'wrapper_attr' => [ 'class' => [ 'betterdocs-category-grid-three-wrapper' ] ], |
| 139 |
'inner_wrapper_attr' => $inner_wrapper_attr, |
| 140 |
'layout' => 'layout-3', |
| 141 |
'widget_type' => 'category-grid', |
| 142 |
'terms_query_args' => $terms_query, |
| 143 |
'docs_query_args' => $docs_query, |
| 144 |
'show_header' => true, |
| 145 |
'show_list' => true, |
| 146 |
'show_title' => true, |
| 147 |
'show_button' => false, |
| 148 |
'button_text' => '', |
| 149 |
'category_title_link' => $category_title_link, |
| 150 |
'layout_type' => $this->attributes['layout_type'], |
| 151 |
'list_icon_url' => $this->attributes['list_icon_url'], |
| 152 |
]; |
| 153 |
} |
| 154 |
} |
| 155 |
|