| @@ -80,19 +80,8 @@ | ||
| 80 | 80 | $term_id = (int) $payload['term_id']; |
| 81 | 81 | $page = (int) ( isset( $payload['page'] ) ? $payload['page'] : 1 ); |
| 82 | 82 | $is_archive = (bool) ( isset( $payload['is_archive'] ) ? $payload['is_archive'] : false ); |
| 83 | 83 | |
| 84 | - // This route is public, so the request may only narrow the loop to a | |
| 85 | - // post type or taxonomy the site already exposes to visitors. sanitize_key | |
| 86 | - // fixes the spelling, not the visibility: without this an anonymous | |
| 87 | - // request could point an archive loop at an internal post type. | |
| 88 | - if ( ! empty( $payload['archive_post_type'] ) && ! is_post_type_viewable( (string) $payload['archive_post_type'] ) ) { | |
| 89 | - return $this->empty_response( $term_id, $post_id, 400 ); | |
| 90 | - } | |
| 91 | - if ( ! empty( $taxonomy ) && ! is_taxonomy_viewable( (string) $taxonomy ) ) { | |
| 92 | - return $this->empty_response( $term_id, $post_id, 400 ); | |
| 93 | - } | |
| 94 | - | |
| 95 | 84 | /* ---------------- ARCHIVE LOGIC (UNCHANGED) ---------------- */ |
| 96 | 85 | |
| 97 | 86 | if ( $is_archive ) { |
| 98 | 87 | |
| @@ -141,9 +130,19 @@ | ||
| 141 | 130 | $loop_builder_block = $this->find_block_in_theme_templates( $loop_builder_block_id, 'ablocks/loop-builder' ); |
| 142 | 131 | } |
| 143 | 132 | |
| 144 | 133 | if ( ! $loop_builder_block ) { |
| 145 | - return $this->empty_response( $term_id, $post_id, 404 ); | |
| 134 | + return new WP_REST_Response( | |
| 135 | + [ | |
| 136 | + 'success' => false, | |
| 137 | + 'data' => [ | |
| 138 | + 'html' => '', | |
| 139 | + 'term_id' => $term_id, | |
| 140 | + 'post_id' => $post_id, | |
| 141 | + ], | |
| 142 | + ], | |
| 143 | + 404 | |
| 144 | + ); | |
| 146 | 145 | } |
| 147 | 146 | |
| 148 | 147 | $block_data = [ 'parentAttributes' => $loop_builder_block['attrs'] ]; |
| 149 | 148 | $blocks = [ $loop_builder_block ]; |
| @@ -161,23 +160,9 @@ | ||
| 161 | 160 | if ( $is_archive && ! empty( $payload['archive_post_type'] ) ) { |
| 162 | 161 | $query_vars['post_type'] = $payload['archive_post_type']; |
| 163 | 162 | } |
| 164 | 163 | |
| 165 | - // "Load more" asks for page N and receives the first N pages at once, so | |
| 166 | - // the request's page number multiplies the stored page size. It comes | |
| 167 | - // from an anonymous request, so bound the result: at most | |
| 168 | - // `ablocks/loop_builder/max_posts_per_request` posts (never fewer than | |
| 169 | - // one stored page), however large the page number. | |
| 170 | - $per_page = (int) $query_vars['posts_per_page']; | |
| 171 | - $max_posts = (int) apply_filters( 'ablocks/loop_builder/max_posts_per_request', 100, $block_data['parentAttributes'] ); | |
| 172 | - if ( $per_page < 1 ) { | |
| 173 | - // A loop set to show every post still gets the bound. | |
| 174 | - $query_vars['posts_per_page'] = max( 1, $max_posts ); | |
| 175 | - } else { | |
| 176 | - $max_posts = max( $per_page, $max_posts ); | |
| 177 | - $page = max( 1, min( $page, (int) ceil( $max_posts / $per_page ) ) ); | |
| 178 | - $query_vars['posts_per_page'] = min( $per_page * $page, $max_posts ); | |
| 179 | - } | |
| 164 | + $query_vars['posts_per_page'] = $query_vars['posts_per_page'] * $page; | |
| 180 | 165 | |
| 181 | 166 | if ( ! empty( $taxonomy ) && $term_id ) { |
| 182 | 167 | $query_vars['tax_query'] = [ |
| 183 | 168 | [ |
| @@ -222,25 +207,8 @@ | ||
| 222 | 207 | 'post_id' => $post_id, |
| 223 | 208 | ], |
| 224 | 209 | ], |
| 225 | 210 | 200 |
| 226 | - ); | |
| 227 | - } | |
| 228 | - | |
| 229 | - /** | |
| 230 | - * The response for a request that cannot be rendered. | |
| 231 | - */ | |
| 232 | - private function empty_response( $term_id, $post_id, $status ) { | |
| 233 | - return new WP_REST_Response( | |
| 234 | - [ | |
| 235 | - 'success' => false, | |
| 236 | - 'data' => [ | |
| 237 | - 'html' => '', | |
| 238 | - 'term_id' => $term_id, | |
| 239 | - 'post_id' => $post_id, | |
| 240 | - ], | |
| 241 | - ], | |
| 242 | - $status | |
| 243 | 211 | ); |
| 244 | 212 | } |
| 245 | 213 | |
| 246 | 214 | /** |