← All changes
|
includes/Editors/BlockEditor/Blocks/ArchiveList.php
+13
-45
4.8.2
→
3.8.9
View file →
| @@ -1,13 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | -// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- core block query; tax filtering required. | |
| 2 | + | |
| 3 | 3 | namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks; |
| 4 | 4 | |
| 5 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | - exit; | |
| 7 | -} | |
| 8 | - | |
| 9 | - | |
| 10 | 5 | use WPDeveloper\BetterDocs\Editors\BlockEditor\Block; |
| 11 | 6 | |
| 12 | 7 | class ArchiveList extends Block { |
| 13 | 8 | |
| @@ -38,35 +33,22 @@ | ||
| 38 | 33 | return [ |
| 39 | 34 | 'blockId' => '', |
| 40 | 35 | 'nested_subcategory' => false, |
| 41 | 36 | 'order' => 'asc', |
| 42 | - 'orderby' => 'betterdocs_order', | |
| 37 | + 'orderby' => 'title', | |
| 43 | 38 | 'layout' => 'layout-1', |
| 44 | 39 | 'list_icon' => 'far fa-file-alt', |
| 45 | 40 | 'postsPerPageLayoutTwo' => -1, |
| 46 | 41 | 'listIconImageUrl' => '', |
| 47 | - 'pagination' => false, | |
| 48 | - 'listTitleTag' => 'h2', | |
| 49 | - 'listEntryHeadingTag' => 'h3' | |
| 42 | + 'pagination' => false | |
| 50 | 43 | ]; |
| 51 | 44 | } |
| 52 | 45 | |
| 53 | 46 | public function render( $attributes, $content ) { |
| 54 | - if ( $this->attributes['layout'] == 'layout-2' ) { | |
| 55 | - // Layout 2 is handled by Pro version | |
| 56 | - add_action( 'archive_handbook_list', [$this, 'render_handbook_view'] ); | |
| 57 | - } | |
| 58 | 47 | $this->views( 'widgets/block-archive-list' ); |
| 59 | 48 | } |
| 60 | 49 | |
| 61 | - public function render_handbook_view() { | |
| 62 | - // This method can be overridden by Pro version | |
| 63 | - } | |
| 64 | - | |
| 65 | 50 | public function view_params() { |
| 66 | - // Sanitize the layout attribute to prevent path traversal (LFI). | |
| 67 | - $this->attributes['layout'] = sanitize_file_name( $this->attributes['layout'] ); | |
| 68 | - | |
| 69 | 51 | global $wp_query; |
| 70 | 52 | $_term_slug = ''; |
| 71 | 53 | if ( isset( $wp_query->query ) && array_key_exists( 'doc_category', $wp_query->query ) ) { |
| 72 | 54 | $_term_slug = $wp_query->query['doc_category']; |
| @@ -100,22 +82,16 @@ | ||
| 100 | 82 | } |
| 101 | 83 | |
| 102 | 84 | $term = ! empty( get_term_by( 'slug', $_term_slug, 'doc_category' ) ) ? get_term_by( 'slug', $_term_slug, 'doc_category' ) : get_term_by( 'slug', $_term_slug, 'doc_tag' ); |
| 103 | 85 | |
| 104 | - // Determine posts per page based on pagination settings | |
| 105 | - $posts_per_page = -1; // default: show all posts | |
| 106 | - if ( $this->attributes['pagination'] && ( $this->attributes['layout'] == 'layout-1' || $this->attributes['layout'] == 'layout-3' || $this->attributes['layout'] == 'layout-4' ) ) { | |
| 107 | - $posts_per_page = isset( $this->attributes['postsPerPageLayoutTwo'] ) && $this->attributes['postsPerPageLayoutTwo'] > 0 | |
| 108 | - ? $this->attributes['postsPerPageLayoutTwo'] | |
| 109 | - : 10; | |
| 110 | - } | |
| 111 | - | |
| 112 | 86 | $_docs_query = [ |
| 113 | 87 | 'term_id' => isset( $term->term_id ) ? $term->term_id : 0, |
| 114 | 88 | 'orderby' => $this->attributes['orderby'], |
| 115 | 89 | 'order' => $this->attributes['order'], |
| 90 | + 'postsOrderBy' => $this->attributes['orderby'], | |
| 91 | + 'postsOrder' => $this->attributes['order'], | |
| 116 | 92 | 'kb_slug' => '', |
| 117 | - 'posts_per_page' => $posts_per_page, | |
| 93 | + 'posts_per_page' => $term == false ? 5 : -1, | |
| 118 | 94 | 'term_slug' => isset( $term->slug ) ? $term->slug : '' |
| 119 | 95 | ]; |
| 120 | 96 | |
| 121 | 97 | $default_params = [ |
| @@ -122,29 +98,21 @@ | ||
| 122 | 98 | 'term' => $term, |
| 123 | 99 | 'nested_subcategory' => (bool) $this->attributes['nested_subcategory'], |
| 124 | 100 | 'list_icon_name' => ! empty( $this->attributes['listIconImageUrl'] ) ? [ 'value' => [ 'url' => str_replace( 'blob:', '', $this->attributes['listIconImageUrl'] ) ] ] : ( ! empty( $this->attributes['list_icon'] ) ? [ 'value' => [ 'url' => $this->attributes['list_icon'] ] ] : ( ! empty( betterdocs()->settings->get( 'docs_list_icon' ) ) ? [ 'value' => [ 'url' => betterdocs()->settings->get( 'docs_list_icon' )['url'] ] ] : [] ) ), |
| 125 | 101 | 'query_args' => betterdocs()->query->docs_query_args( $_docs_query ), |
| 126 | - 'title_tag' => $this->attributes['listEntryHeadingTag'] ?? 'h2', | |
| 127 | - 'docs_list_title_tag' => $this->attributes['listTitleTag'] ?? 'h2', | |
| 102 | + 'title_tag' => 'h2', | |
| 128 | 103 | 'layout' => $this->attributes['layout'], |
| 129 | - 'posts_per_page' => $posts_per_page, | |
| 104 | + 'posts_per_page' => $this->attributes['postsPerPageLayoutTwo'], | |
| 130 | 105 | 'list_icon_url' => '', |
| 131 | 106 | 'layout_type' => 'block', |
| 132 | - 'archive_layout' => $this->attributes['layout'] | |
| 107 | + 'archive_layout' => 'layout-1' | |
| 133 | 108 | ]; |
| 134 | 109 | |
| 135 | - if ( $this->attributes['pagination'] && ( $this->attributes['layout'] == 'layout-1' || $this->attributes['layout'] == 'layout-3' || $this->attributes['layout'] == 'layout-4' ) ) { | |
| 136 | - $page = get_query_var( 'paged' ) != '' ? get_query_var( 'paged' ) : 1; | |
| 137 | - | |
| 138 | - // Use postsPerPageLayoutTwo for layouts 2, 3, and 4 | |
| 139 | - $posts_per_page = isset( $this->attributes['postsPerPageLayoutTwo'] ) && $this->attributes['postsPerPageLayoutTwo'] > 0 | |
| 140 | - ? $this->attributes['postsPerPageLayoutTwo'] | |
| 141 | - : 10; | |
| 142 | - | |
| 143 | - $default_params['query_args']['paged'] = $page; | |
| 144 | - $default_params['query_args']['posts_per_page'] = $posts_per_page; | |
| 110 | + if ( $this->attributes['pagination'] && $this->attributes['layout'] == 'layout-1' || $this->attributes['pagination'] && $this->attributes['layout'] == 'layout-3' ) { | |
| 111 | + $page = get_query_var( 'paged' ) != '' ? get_query_var( 'paged' ) : 1; | |
| 112 | + $default_params['query_args']['paged'] = $page; | |
| 113 | + $default_params['query_args']['posts_per_page'] = 10; | |
| 145 | 114 | $default_params['page'] = $page; |
| 146 | - $default_params['posts_per_page'] = $posts_per_page; | |
| 147 | 115 | $default_params['pagination'] = $this->attributes['pagination']; |
| 148 | 116 | } |
| 149 | 117 | |
| 150 | 118 | return $default_params; |