Skip to content

Commit 08b2903

Browse files
committed
fix: use constant
1 parent e1cef22 commit 08b2903

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/plugin.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
class Plugin
1919
{
20+
public const QUERY_VAR_IS_PFCPT = 'is_page_for_custom_post_type';
21+
2022
public const OPTION_PREFIX = 'page_for_';
2123

2224
public const OPTION_PAGE_IDS = 'pages_for_custom_post_type';
@@ -516,7 +518,7 @@ public function on_slug_change(int $post_ID, WP_Post $post_after, WP_Post $post_
516518
public function is_query_page_for_custom_post_type(?WP_Query $query = null): bool
517519
{
518520
$q = $query === null ? $GLOBALS['wp_query'] : $query;
519-
return isset($q->is_page_for_custom_post_type) && $q->is_page_for_custom_post_type;
521+
return isset($q->{self::QUERY_VAR_IS_PFCPT}) && $q->{self::QUERY_VAR_IS_PFCPT};
520522
}
521523

522524
/**
@@ -526,14 +528,14 @@ public function is_query_page_for_custom_post_type(?WP_Query $query = null): boo
526528
*/
527529
public function set_home_template_hierarchy(array $templates): array
528530
{
529-
if (!isset($GLOBALS['wp_query']->is_page_for_custom_post_type)) {
531+
if (!isset($GLOBALS['wp_query']->{self::QUERY_VAR_IS_PFCPT})) {
530532
return $templates;
531533
}
532-
if (!\is_string($GLOBALS['wp_query']->is_page_for_custom_post_type)) {
534+
if (!\is_string($GLOBALS['wp_query']->{self::QUERY_VAR_IS_PFCPT})) {
533535
return $templates;
534536
}
535537
return \array_merge([
536-
"home-{$GLOBALS['wp_query']->is_page_for_custom_post_type}",
538+
"home-{$GLOBALS['wp_query']->{self::QUERY_VAR_IS_PFCPT}}",
537539
], $templates);
538540
}
539541

@@ -560,7 +562,7 @@ public function set_page_for_custom_post_type_query(WP_Query $query): void
560562
// Set conditionals
561563
foreach (\array_keys($page_ids) as $post_type) {
562564
$query->{$this->get_conditional_name($post_type)} = false;
563-
$query->is_page_for_custom_post_type = false;
565+
$query->{self::QUERY_VAR_IS_PFCPT} = false;
564566
}
565567

566568
if (!\in_array($current_page_id, $page_ids, true)) {
@@ -576,7 +578,7 @@ public function set_page_for_custom_post_type_query(WP_Query $query): void
576578
$query->is_home = true;
577579
$query->{$this->get_conditional_name($post_type)} = true;
578580
$query->set('post_type', $post_type);
579-
$query->is_page_for_custom_post_type = $post_type;
581+
$query->{self::QUERY_VAR_IS_PFCPT} = $post_type;
580582

581583
\add_filter('home_template_hierarchy', [$this, 'set_home_template_hierarchy']);
582584
\add_filter('frontpage_template_hierarchy', '__return_empty_array');
@@ -589,7 +591,7 @@ public function set_page_for_custom_post_type_query(WP_Query $query): void
589591
*/
590592
public function on_template_redirect(): void
591593
{
592-
if (!$this->is_page_for_custom_post_type()) {
594+
if (!$this->{self::QUERY_VAR_IS_PFCPT}()) {
593595
return;
594596
}
595597

@@ -651,7 +653,7 @@ public function is_page_for_custom_post_type(?string $post_type = null): bool
651653
return false;
652654
}
653655

654-
$current_post_type = $GLOBALS['wp_query']->is_page_for_custom_post_type ?? null;
656+
$current_post_type = $GLOBALS['wp_query']->{self::QUERY_VAR_IS_PFCPT} ?? null;
655657
if ($post_type === null) {
656658
return (bool) $current_post_type;
657659
}

0 commit comments

Comments
 (0)