| 1 |
<?php |
| 2 |
/** |
| 3 |
* Utility functions pertaining to augmenting WP GraphQL. |
| 4 |
* |
| 5 |
* @package FaustWP |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPE\FaustWP\GraphQL; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Returns list of conditional tags applicable to a headless frontend. |
| 16 |
* |
| 17 |
* Important note, the order of these tags must follow the order set in WordPress' template-loader.php file so we can |
| 18 |
* accurately get the list of templates to be located for a given URI. |
| 19 |
* |
| 20 |
* @return array { |
| 21 |
* list of conditional tags |
| 22 |
* |
| 23 |
* @type string $description Description of the template getter. This will be displayed in the GraphQL docs. |
| 24 |
* @type string $template_getter Core function in WordPress used to locate the templates if the conditional tag |
| 25 |
* returns true. |
| 26 |
* } |
| 27 |
* @see template-loader.php |
| 28 |
*/ |
| 29 |
function get_conditional_tags() { |
| 30 |
return array( |
| 31 |
'is_search' => array( |
| 32 |
'description' => __( 'Determines whether the query is for a search.', 'faustwp' ), |
| 33 |
'template_getter' => 'get_search_template', |
| 34 |
), |
| 35 |
'is_front_page' => array( |
| 36 |
'description' => __( 'Determines whether the query is for the front page of the site.', 'faustwp' ), |
| 37 |
'template_getter' => 'get_front_page_template', |
| 38 |
), |
| 39 |
'is_home' => array( |
| 40 |
'description' => __( 'Determines whether the query is for the blog homepage.', 'faustwp' ), |
| 41 |
'template_getter' => 'get_home_template', |
| 42 |
), |
| 43 |
'is_privacy_policy' => array( |
| 44 |
'description' => __( 'Determines whether the query is for the Privacy Policy page.', 'faustwp' ), |
| 45 |
'template_getter' => 'get_privacy_policy_template', |
| 46 |
), |
| 47 |
'is_post_type_archive' => array( |
| 48 |
'description' => __( 'Determines whether the query is for an existing post type archive page.', 'faustwp' ), |
| 49 |
'template_getter' => 'get_post_type_archive_template', |
| 50 |
), |
| 51 |
'is_tax' => array( |
| 52 |
'description' => __( 'Determines whether the query is for an existing custom taxonomy archive page.', 'faustwp' ), |
| 53 |
'template_getter' => 'get_taxonomy_template', |
| 54 |
), |
| 55 |
'is_attachment' => array( |
| 56 |
'description' => __( 'Determines whether the query is for an existing attachment page.', 'faustwp' ), |
| 57 |
'template_getter' => 'get_attachment_template', |
| 58 |
), |
| 59 |
'is_single' => array( |
| 60 |
'description' => __( 'Determines whether the query is for an existing single post.', 'faustwp' ), |
| 61 |
'template_getter' => 'get_single_template', |
| 62 |
), |
| 63 |
'is_page' => array( |
| 64 |
'description' => __( 'Determines whether the query is for an existing single page.', 'faustwp' ), |
| 65 |
'template_getter' => 'get_page_template', |
| 66 |
), |
| 67 |
'is_singular' => array( |
| 68 |
'description' => __( 'Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).', 'faustwp' ), |
| 69 |
'template_getter' => 'get_singular_template', |
| 70 |
), |
| 71 |
'is_category' => array( |
| 72 |
'description' => __( 'Determines whether the query is for an existing category archive page.', 'faustwp' ), |
| 73 |
'template_getter' => 'get_category_template', |
| 74 |
), |
| 75 |
'is_tag' => array( |
| 76 |
'description' => __( 'Determines whether the query is for an existing tag archive page.', 'faustwp' ), |
| 77 |
'template_getter' => 'get_tag_template', |
| 78 |
), |
| 79 |
'is_author' => array( |
| 80 |
'description' => __( 'Determines whether the query is for an existing author archive page.', 'faustwp' ), |
| 81 |
'template_getter' => 'get_author_template', |
| 82 |
), |
| 83 |
'is_date' => array( |
| 84 |
'description' => __( 'Determines whether the query is for an existing date archive.', 'faustwp' ), |
| 85 |
'template_getter' => 'get_date_template', |
| 86 |
), |
| 87 |
'is_archive' => array( |
| 88 |
'description' => __( 'Determines whether the query is for an existing archive page.', 'faustwp' ), |
| 89 |
'template_getter' => 'get_archive_template', |
| 90 |
), |
| 91 |
|
| 92 |
/* Conditional tags without template getters */ |
| 93 |
'is_day' => array( |
| 94 |
'description' => __( 'Determines whether the query is for an existing day archive.', 'faustwp' ), |
| 95 |
), |
| 96 |
'is_multi_author' => array( |
| 97 |
'description' => __( 'Determines whether this site has more than one author.', 'faustwp' ), |
| 98 |
), |
| 99 |
'is_month' => array( |
| 100 |
'description' => __( 'Determines whether the query is for an existing month archive.', 'faustwp' ), |
| 101 |
), |
| 102 |
'is_page_template' => array( |
| 103 |
'description' => __( 'Determines whether currently in a page template.', 'faustwp' ), |
| 104 |
), |
| 105 |
'is_preview' => array( |
| 106 |
'description' => __( 'Determines whether the query is for a post or page preview.', 'faustwp' ), |
| 107 |
), |
| 108 |
'is_sticky' => array( |
| 109 |
'description' => __( 'Determines whether a post is sticky.', 'faustwp' ), |
| 110 |
), |
| 111 |
'is_year' => array( |
| 112 |
'description' => __( 'Determines whether the query is for an existing year archive.', 'faustwp' ), |
| 113 |
), |
| 114 |
); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Returns list of template hierarchy types supported by the {$type}_template_hierarchy filters. |
| 119 |
* |
| 120 |
* @return string[] list of template hierarchy types |
| 121 |
*/ |
| 122 |
function template_hierarchy_types() { |
| 123 |
return array( |
| 124 |
'index', |
| 125 |
'404', |
| 126 |
'archive', |
| 127 |
'author', |
| 128 |
'category', |
| 129 |
'tag', |
| 130 |
'taxonomy', |
| 131 |
'date', |
| 132 |
'embed', |
| 133 |
'home', |
| 134 |
'frontpage', |
| 135 |
'privacypolicy', |
| 136 |
'page', |
| 137 |
'paged', |
| 138 |
'search', |
| 139 |
'single', |
| 140 |
'singular', |
| 141 |
'attachment', |
| 142 |
); |
| 143 |
} |
| 144 |
|