PluginProbe
Cooked – Recipe Management / 1.16.1
Cooked – Recipe Management v1.16.1
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / includes / class.cooked-post-types.php

class.cooked-post-types.php in Cooked – Recipe Management 1.16.1, at includes/class.cooked-post-types.php

583 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Types
4 *
5 * @package Cooked
6 * @subpackage Post Types
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Cooked_Post_Types Class
15 *
16 * This class handles the post type creation.
17 *
18 * @since 1.0.0
19 */
20 class Cooked_Post_Types {
21
22 function __construct() {
23 register_activation_hook( COOKED_PLUGIN_FILE, [&$this, 'activation'] );
24 register_deactivation_hook( COOKED_PLUGIN_FILE, [ __CLASS__, 'deactivation' ] );
25
26 add_action( 'init', [&$this, 'init'] );
27 add_filter( 'admin_init', [&$this, 'init_roles'] );
28 add_action( 'after_setup_theme', [&$this, 'image_sizes'] );
29 add_action( 'wp_head', [&$this, 'cooked_meta_tags'], 5 );
30 add_action( 'manage_cp_recipe_posts_custom_column', [&$this, 'custom_columns_data'], 10, 2 );
31
32 add_filter( 'enter_title_here', [&$this, 'change_new_recipe_title'] );
33 add_filter( 'query_vars', [&$this, 'add_query_vars_filter'] );
34 add_filter( 'manage_cp_recipe_posts_columns', [&$this, 'custom_columns'] );
35 add_filter( 'nav_menu_css_class', [&$this, 'cooked_nav_classes'], 10, 2 );
36 add_filter( 'redirect_canonical', [&$this, 'disable_canonical_redirect'], 10, 2 );
37
38 // Taxonomy Titles
39 add_action( 'template_redirect', [&$this, 'remove_default_title_tag'] );
40 add_filter( 'the_title', [&$this, 'taxonomy_page_title'], 10, 2 );
41 add_filter( 'pre_wp_nav_menu', [&$this, 'disable_taxonomy_page_title'], 10, 2 );
42 add_filter( 'wp_nav_menu_items', [&$this, 'enable_taxonomy_page_title'], 10, 2 );
43 add_filter( 'wp_title', [&$this, 'taxonomy_meta_title'], 10 );
44
45 // Add a post display state for special pages.
46 add_filter( 'display_post_states', [&$this, 'add_display_post_states' ], 10, 2 );
47 }
48
49 function disable_taxonomy_page_title( $nav_menu, $args ) {
50 remove_filter( 'the_title', [&$this, 'taxonomy_page_title'], 10 );
51 return $nav_menu;
52 }
53
54 function enable_taxonomy_page_title( $items, $args ) {
55 add_filter( 'the_title', [&$this, 'taxonomy_page_title'], 10, 2 );
56 return $items;
57 }
58
59 function taxonomy_page_title( $title = '', $id = 0 ) {
60 if ( is_admin() ) return $title;
61
62 global $wp_query, $post, $_cooked_settings;
63 $browse_page_id = Cooked_Multilingual::get_browse_page_id();
64
65 if ( is_page( $browse_page_id ) && $id == $browse_page_id && isset($wp_query->query['cp_recipe_category']) && taxonomy_exists('cp_recipe_category') && term_exists( $wp_query->query['cp_recipe_category'], 'cp_recipe_category' ) ):
66 $cooked_term = get_term_by( 'slug', $wp_query->query['cp_recipe_category'], 'cp_recipe_category' );
67 return $cooked_term->name;
68 endif;
69
70 return $title;
71 }
72
73 function taxonomy_meta_title( $title = '' ) {
74 global $wp_query, $post, $_cooked_settings;
75 $browse_page_id = Cooked_Multilingual::get_browse_page_id();
76
77 if ( is_page( $browse_page_id ) && $post->ID == $browse_page_id && isset($wp_query->query['cp_recipe_category']) && taxonomy_exists('cp_recipe_category') && term_exists( $wp_query->query['cp_recipe_category'], 'cp_recipe_category' ) ):
78 $cooked_term = get_term_by( 'slug', $wp_query->query['cp_recipe_category'], 'cp_recipe_category' );
79 return $cooked_term->name;
80 endif;
81
82 return $title;
83 }
84
85 function custom_columns( $columns ) {
86 $new_columns = [];
87 foreach( $columns as $key => $val ):
88 $new_columns[$key] = $val;
89 if ( $key == 'cb' ):
90 $new_columns['featured_image'] = __( 'Photo', 'cooked' );
91 endif;
92 endforeach;
93 return $new_columns;
94 }
95
96 function custom_columns_data( $column, $post_id ) {
97 if ( $column == 'featured_image' ):
98 echo '<span class="cooked-admin-recipes-list-image">';
99 echo wp_kses_post( get_the_post_thumbnail( $post_id, 'thumbnail' ) );
100 echo '</span>';
101 endif;
102 }
103
104 public static function cooked_nav_classes( $classes, $item ) {
105 global $_cooked_settings;
106 $blog_page_id = get_option( 'page_for_posts', false );
107 $browse_page_id = Cooked_Multilingual::get_browse_page_id();
108
109 if ( ( is_post_type_archive( 'cp_recipe' ) || is_singular( 'cp_recipe' ) )
110 && $item->object_id == $blog_page_id ){
111 $classes = array_diff( $classes, ['current_page_parent'] );
112 }
113
114 if ( ( is_post_type_archive( 'cp_recipe' ) || is_singular( 'cp_recipe' ) )
115 && $item->object_id == $browse_page_id && is_array($classes) && !in_array( 'current_page_parent', $classes ) ){
116 $classes[] = 'current_page_parent';
117 }
118
119 return $classes;
120 }
121
122 public static function cooked_meta_tags() {
123 global $_cooked_settings, $post, $wp_query;
124
125 if ( isset($_cooked_settings['advanced']) && !empty($_cooked_settings['advanced']) && in_array( 'disable_meta_tags', $_cooked_settings['advanced'] ) )
126 return false;
127
128 if ( isset($wp_query->query['cp_recipe_category']) && taxonomy_exists('cp_recipe_category') && term_exists( $wp_query->query['cp_recipe_category'], 'cp_recipe_category' ) ) {
129 $cooked_term = get_term_by( 'slug', $wp_query->query['cp_recipe_category'], 'cp_recipe_category' );
130 }
131
132 // Browse page.
133 if ( isset( $cooked_term ) && $cooked_term->name ) {
134 ?><title><?php echo esc_html($cooked_term->name) . ' / ' . esc_html(get_bloginfo('name')); ?></title>
135 <meta name="description" content="<?php echo esc_attr( $cooked_term->description ); ?>">
136 <meta property="og:title" content="<?php echo esc_attr( $cooked_term->name ); ?>">
137 <meta property="og:description" content="<?php echo esc_attr( $cooked_term->description ); ?>"><?php
138 }
139
140 // Single recipe.
141 if ( isset( $post->post_type ) && $post->post_type == 'cp_recipe' ) {
142 ob_start();
143
144 $recipe = get_post( $post->ID );
145 $recipe_settings = Cooked_Recipes::get( $post->ID, true );
146 $image_url = false;
147
148 if ( has_post_thumbnail($recipe) ) {
149 $image_url = get_the_post_thumbnail_url( $recipe, 'cooked-large' );
150 }
151
152 $description = '';
153 if (!empty($recipe_settings['seo_description'])):
154 $description = wp_strip_all_tags( preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', wp_specialchars_decode( $recipe_settings['seo_description'], ENT_QUOTES ) ) );
155 elseif (!empty($recipe_settings['excerpt'])):
156 $description = wp_strip_all_tags( preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $recipe_settings['excerpt']) );
157 elseif (!empty($recipe_settings['title'])):
158 $description = $recipe_settings['title'];
159 endif;
160 ?>
161
162 <meta name="description" content="<?php echo esc_attr( $description ); ?>">
163 <meta property="og:type" content="website">
164 <meta property="og:title" content="<?php echo esc_attr( $post->post_title ); ?>">
165 <meta property="og:description" content="<?php echo esc_attr( $description ); ?>">
166 <meta property="og:image" content="<?php echo esc_attr( $image_url ); ?>">
167 <meta property="og:locale" content="<?php echo esc_attr( get_locale() ); ?>">
168 <meta property="og:url" content="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php
169
170 echo wp_kses( ob_get_clean(), [
171 'meta' => [
172 'name' => true,
173 'content' => true,
174 'property' => true,
175 ],
176 ] );
177 }
178 }
179
180 public static function add_query_vars_filter( $vars ) {
181 $vars[] = 'servings';
182 $vars[] = 'measurement_system';
183
184 return $vars;
185 }
186
187 public function remove_default_title_tag() {
188 global $wp_query;
189 if ( isset($wp_query->query['cp_recipe_category']) && taxonomy_exists('cp_recipe_category') && term_exists( $wp_query->query['cp_recipe_category'], 'cp_recipe_category' ) ) {
190 remove_action( 'wp_head', '_wp_render_title_tag', 1 );
191 }
192 }
193
194 public static function activation() {
195 self::init();
196 self::init_roles();
197 flush_rewrite_rules();
198 }
199
200 public static function deactivation() {
201 delete_option( 'rewrite_rules' );
202 }
203
204 public static function init_roles() {
205 // Clean up for any old caps or caps that were inserted incorrectly.
206 if ( $role_object = get_role( 'subscriber' ) ) {
207 if ( $role_object->has_cap( 'edit_cp_recipes' ) ) {
208 Cooked_Roles::clean_caps();
209 }
210 }
211
212 Cooked_Roles::add_roles();
213 Cooked_Roles::add_caps();
214 }
215
216 public static function init() {
217 $_cooked_settings = Cooked_Settings::get();
218 $_cooked_taxonomies = Cooked_Taxonomies::get();
219
220 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Display-only Settings API query vars.
221 $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
222 $settings_updated = isset( $_GET['settings-updated'] ) ? rest_sanitize_boolean( wp_unslash( $_GET['settings-updated'] ) ) : false;
223 // phpcs:enable WordPress.Security.NonceVerification.Recommended
224
225 // Security check: Only allow settings update from admin area with proper permissions
226 if ( $settings_updated && is_admin() && current_user_can('manage_options') && $page === 'cooked_settings' ) {
227 // Recipe Permalink
228 $permalink_parts = explode( '/', $_cooked_settings['recipe_permalink'] );
229 if ( isset( $permalink_parts[1] ) ):
230 foreach ( $permalink_parts as $key => $part ):
231 $part = sanitize_title_with_dashes( $part, null, 'save');
232 $permalink_parts[$key] = sanitize_title_with_dashes( $part, null, 'save');
233 endforeach;
234 $recipe_permalink = implode( '/', $permalink_parts );
235 else:
236 $recipe_permalink = sanitize_title_with_dashes( $_cooked_settings['recipe_permalink'], null, 'save');
237 endif;
238
239 // Recipe Author Permalink
240 $permalink_parts = explode( '/', $_cooked_settings['recipe_author_permalink'] );
241 if ( isset( $permalink_parts[1] ) ):
242 foreach( $permalink_parts as $key => $part ):
243 $part = sanitize_title_with_dashes( $part, null, 'save');
244 $permalink_parts[$key] = sanitize_title_with_dashes( $part, null, 'save');
245 endforeach;
246 $recipe_author_permalink = implode( '/', $permalink_parts );
247 else:
248 $recipe_author_permalink = sanitize_title_with_dashes( $_cooked_settings['recipe_author_permalink'], null, 'save');
249 endif;
250
251 // Recipe Category Permalink
252 $permalink_parts = explode( '/', $_cooked_settings['recipe_category_permalink'] );
253 if ( isset( $permalink_parts[1] ) ):
254 foreach ( $permalink_parts as $key => $part ):
255 $part = sanitize_title_with_dashes( $part, null, 'save');
256 $permalink_parts[$key] = sanitize_title_with_dashes( $part, null, 'save');
257 endforeach;
258 $recipe_category_permalink = implode( '/', $permalink_parts );
259 else:
260 $recipe_category_permalink = sanitize_title_with_dashes( $_cooked_settings['recipe_category_permalink'], null, 'save');
261 endif;
262
263 $taxonomy_settings_update = apply_filters( 'cooked_taxonomy_settings_update', [
264 'recipe_permalink' => (!$_cooked_settings['recipe_permalink'] ? 'recipes' : $recipe_permalink),
265 'recipe_author_permalink' => (!$_cooked_settings['recipe_author_permalink'] || 'author' == $_cooked_settings['recipe_author_permalink'] ? 'recipe-author' : $recipe_author_permalink),
266 'recipe_category_permalink' => (!$_cooked_settings['recipe_category_permalink'] ? 'recipe-category' : $recipe_category_permalink)
267 ]);
268
269 foreach ( $taxonomy_settings_update as $setting_key => $setting_value ) {
270 $_cooked_settings[ $setting_key ] = $setting_value;
271 }
272
273 update_option( 'cooked_settings', $_cooked_settings );
274 update_option( 'cooked_settings_saved', true );
275
276 flush_rewrite_rules();
277 }
278
279 global $cooked_taxonomies_for_menu;
280
281 // Register taxonomies first (only once)
282 if ( !empty($_cooked_taxonomies) ) {
283 foreach ( $_cooked_taxonomies as $slug => $args ) {
284 register_taxonomy( $slug, ['cp_recipe'], $args );
285 add_rewrite_tag("%{$slug}%", '([^/]+)');
286
287 $cooked_taxonomies_for_menu[] = [
288 'menu' => 'cooked_recipes_menu',
289 'name' => $args['labels']['menu_name'],
290 'capability' => 'manage_categories',
291 'url' => 'edit-tags.php?taxonomy=' . $slug . '&post_type=cp_recipe'
292 ];
293 }
294 }
295
296 // Get all browse page translations (including default)
297 $browse_pages = Cooked_Multilingual::get_all_browse_pages();
298
299 // Create rewrite rules for each browse page translation
300 foreach ( $browse_pages as $lang => $page_data ) {
301 self::add_browse_page_rewrite_rules( $page_data['id'], $page_data['slug'], $_cooked_taxonomies );
302 }
303
304 add_rewrite_tag('%cooked_search_s%', '([^&]+)');
305 add_rewrite_tag('%cooked_browse_sort_by%', '([^&]+)');
306
307 $post_types = self::get();
308 if ( !empty($post_types) ) {
309 foreach ( $post_types as $slug => $args ) {
310 register_post_type( $slug, $args );
311 }
312 }
313 }
314
315 /**
316 * Add rewrite rules for a specific browse page
317 *
318 * @param int $page_id The browse page ID
319 * @param string|null $page_slug The browse page slug/path (empty string for homepage, null if invalid)
320 * @param array $taxonomies The registered taxonomies
321 */
322 private static function add_browse_page_rewrite_rules( $page_id, $page_slug, $taxonomies ) {
323 // Page ID is required, but slug can be empty string (for homepage)
324 if ( ! $page_id || $page_slug === null ) {
325 return;
326 }
327
328 // Get base path - either parent page slug or empty (for homepage)
329 $base_path = $page_slug !== '' ? $page_slug . '/' : '';
330
331 // Add taxonomy rewrite rules
332 if ( !empty($taxonomies) ) {
333 foreach ( $taxonomies as $slug => $args ) {
334 // Taxonomy search sort pagination
335 add_rewrite_rule(
336 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/search/([^/]*)/sort/([^/]*)/page/([^/]*)/?',
337 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]&cooked_search_s=$matches[2]&cooked_browse_sort_by=$matches[3]&paged=$matches[4]',
338 'top'
339 );
340
341 // Taxonomy search sort
342 add_rewrite_rule(
343 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/search/([^/]*)/sort/([^/]*)/?',
344 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]&cooked_search_s=$matches[2]&cooked_browse_sort_by=$matches[3]',
345 'top'
346 );
347
348 // Taxonomy sort pagination
349 add_rewrite_rule(
350 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/sort/([^/]*)/page/([^/]*)/?',
351 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]&cooked_browse_sort_by=$matches[2]&paged=$matches[3]',
352 'top'
353 );
354
355 // Taxonomy sort
356 add_rewrite_rule(
357 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/sort/([^/]*)/?',
358 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]&cooked_browse_sort_by=$matches[2]',
359 'top'
360 );
361
362 // Taxonomy search
363 add_rewrite_rule(
364 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/search/([^/]*)/?',
365 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]&cooked_search_s=$matches[2]',
366 'top'
367 );
368
369 // Taxonomy pagination
370 add_rewrite_rule(
371 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/page/([^/]*)/?',
372 'index.php?page_id=' . $page_id . '&paged=$matches[2]&' . $slug . '=$matches[1]',
373 'top'
374 );
375
376 // Taxonomy
377 add_rewrite_rule(
378 '^' . $base_path . $args['rewrite']['slug'] . '/([^/]*)/?',
379 'index.php?page_id=' . $page_id . '&' . $slug . '=$matches[1]',
380 'top'
381 );
382 }
383 }
384
385 // Search sort pagination
386 add_rewrite_rule(
387 '^' . $base_path . 'search/([^/]*)/sort/([^/]*)/page/([^/]*)/?',
388 'index.php?page_id=' . $page_id . '&cooked_search_s=$matches[1]&cooked_browse_sort_by=$matches[2]&paged=$matches[3]',
389 'top'
390 );
391
392 // Search sort
393 add_rewrite_rule(
394 '^' . $base_path . 'search/([^/]*)/sort/([^/]*)/?',
395 'index.php?page_id=' . $page_id . '&cooked_search_s=$matches[1]&cooked_browse_sort_by=$matches[2]',
396 'top'
397 );
398
399 // Sort Pagination
400 add_rewrite_rule(
401 '^' . $base_path . 'sort/([^/]*)/page/([^/]*)/?',
402 'index.php?page_id=' . $page_id . '&cooked_browse_sort_by=$matches[1]&paged=$matches[2]',
403 'top'
404 );
405
406 // Sort
407 add_rewrite_rule(
408 '^' . $base_path . 'sort/([^/]*)/?',
409 'index.php?page_id=' . $page_id . '&cooked_browse_sort_by=$matches[1]',
410 'top'
411 );
412
413 // Search
414 add_rewrite_rule(
415 '^' . $base_path . 'search/([^/]*)/?',
416 'index.php?page_id=' . $page_id . '&cooked_search_s=$matches[1]',
417 'top'
418 );
419
420 // Pagination
421 add_rewrite_rule(
422 '^' . $base_path . 'page/([^/]*)/?',
423 'index.php?page_id=' . $page_id . '&paged=$matches[1]',
424 'top'
425 );
426
427 // Plain - only add for non-homepage pages (WordPress handles homepage already)
428 if ( $page_slug !== '' ) {
429 add_rewrite_rule(
430 '^' . $page_slug . '/?$',
431 'index.php?page_id=' . $page_id,
432 'top'
433 );
434 }
435 }
436
437 public static function image_sizes() {
438 add_image_size( 'cooked-profile-photo', 150, 150, true );
439 add_image_size( 'cooked-square', 700, 700, true );
440 add_image_size( 'cooked-medium', 700, 525, true );
441 add_image_size( 'cooked-large', 2000, 2000 );
442 }
443
444 public static function get() {
445 global $_cooked_settings;
446
447 $recipe_permalink = isset($_cooked_settings['recipe_permalink']) && $_cooked_settings['recipe_permalink'] ? $_cooked_settings['recipe_permalink'] : 'recipes';
448 $public_recipes = true;
449 $has_archive_slug = sanitize_title_with_dashes( __('Recipe Archive', 'cooked') );
450 $exclude_from_search = false;
451
452 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only print view flag.
453 if ( !isset($_GET['print']) && isset( $_cooked_settings['advanced'] ) && in_array( 'disable_public_recipes', $_cooked_settings['advanced'] ) ) {
454 $public_recipes = false;
455 $has_archive_slug = false;
456 $exclude_from_search = true;
457 }
458
459 if ( isset( $_cooked_settings['advanced'] ) && in_array( 'disable_cp_recipe_archive', $_cooked_settings['advanced'] ) ) {
460 $has_archive_slug = false;
461 }
462
463 $post_types = apply_filters( 'cooked_post_types', [
464 'cp_recipe' => [
465 'labels' => [
466 'name' => _x( 'Recipes', 'post type general name', 'cooked' ),
467 'singular_name' => _x( 'Recipe', 'post type singular name', 'cooked' ),
468 'menu_name' => __('Recipes', 'cooked'),
469 'name_admin_bar' => __('Recipe', 'cooked'),
470 'add_new' => __('Add New', 'cooked'),
471 'add_new_item' => __('Add New Recipe', 'cooked'),
472 'new_item' => __('New Recipe', 'cooked'),
473 'edit_item' => __('Edit Recipe', 'cooked'),
474 'view_item' => __('View Recipe', 'cooked'),
475 'all_items' => __('All Recipes', 'cooked'),
476 'search_items' => __('Search Recipes', 'cooked'),
477 'not_found' => __('No recipes found.', 'cooked'),
478 'not_found_in_trash' => __('No recipes found in trash.', 'cooked')
479 ],
480 'description' => __('Recipes', 'cooked'),
481 'public' => $public_recipes,
482 'show_ui' => true,
483 'show_in_admin_bar' => true,
484 'show_in_menu' => 'cooked_recipes_menu',
485 'show_in_rest' => true,
486 'rest_base' => 'cooked_recipe',
487 'rest_controller_class' => 'WP_REST_Posts_Controller',
488 'exclude_from_search' => $exclude_from_search,
489 'has_archive' => $has_archive_slug,
490 'menu_position' => 25,
491 'supports' => ['title', 'editor', 'thumbnail', 'comments', 'author'],
492 'rewrite' => [
493 'with_front' => false,
494 'slug' => $recipe_permalink
495 ]
496 ]
497 ]
498 );
499
500 return $post_types;
501 }
502
503 public function change_new_recipe_title($title) {
504 $screen = get_current_screen();
505 if ('cp_recipe' == $screen->post_type) {
506 $title = __('Recipe title ...', 'cooked');
507 }
508
509 return $title;
510 }
511
512 /**
513 * Add a post display state for special Cooked pages in the page list table.
514 *
515 * @param array $post_states An array of post display states.
516 * @param WP_Post $post The current post object.
517 */
518 public function add_display_post_states( $post_states, $post ) {
519 global $_cooked_settings;
520
521 // Check both the main browse page and any translations
522 $main_browse_page_id = !empty($_cooked_settings['browse_page']) ? $_cooked_settings['browse_page'] : false;
523 $browse_pages = Cooked_Multilingual::get_all_browse_pages();
524
525 // Check if this post is the main browse page or any translation
526 $is_browse_page = ( $main_browse_page_id == $post->ID );
527 if ( ! $is_browse_page && ! empty( $browse_pages ) ) {
528 foreach ( $browse_pages as $lang => $page_data ) {
529 if ( $page_data['id'] == $post->ID ) {
530 $is_browse_page = true;
531 break;
532 }
533 }
534 }
535
536 if ( $is_browse_page ) {
537 $post_states['cooked_page_for_browse_recipes'] = __( 'Cooked Browse Recipes Page', 'cooked' );
538 }
539
540 return $post_states;
541 }
542
543 /**
544 * Disable canonical redirects for Cooked URLs on the homepage
545 *
546 * @param string $redirect_url The redirect URL
547 * @param string $requested_url The originally requested URL
548 * @return string|bool The redirect URL or false to prevent redirect
549 */
550 public function disable_canonical_redirect($redirect_url, $requested_url) {
551 global $_cooked_settings;
552 $_cooked_taxonomies = Cooked_Taxonomies::get();
553
554 // Only process if this is the homepage
555 if (!is_front_page()) {
556 return $redirect_url;
557 }
558
559 // Check if any Cooked query vars are present
560 $cooked_query_vars = [
561 'cooked_search_s',
562 'cooked_browse_sort_by',
563 'paged'
564 ];
565
566 // Add taxonomy query vars
567 if (!empty($_cooked_taxonomies)) {
568 foreach ( $_cooked_taxonomies as $slug => $args ) {
569 $cooked_query_vars[] = $slug;
570 }
571 }
572
573 foreach ($cooked_query_vars as $var) {
574 if (get_query_var($var)) {
575 return false;
576 }
577 }
578
579 return $redirect_url;
580 }
581
582 }
583