This repository was archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
137 lines (121 loc) · 3.43 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace App;
require_once __DIR__ . '/vendor/autoload.php';
use Illuminate\Support\Collection;
/**
* WPGraphQL Next interface.
*/
(new class() {
/** @var string */
public $url;
/** @var array */
public $type;
/** @var array */
public $fields;
/**
* Class constructor.
*/
public function __construct()
{
$this->url = get_home_url();
$this->type = [
'description' => __('Next JS specific data', 'sage-next'),
'type' => 'Next',
'resolve' => function ($post) {
return [
'url' => '/' . get_page_uri($post->ID),
'linkAs' => '/' . get_page_uri($post->ID),
'linkHref' => '/[slug]',
'content' => str_replace(
$this->getUrlVariants(),
'',
get_post($post->ID)->post_content
),
'media' => str_replace(
$this->getUrlVariants(),
'',
get_the_post_thumbnail_url($post->ID)
),
];
},
];
$this->fields = [
'url' => [
'type' => 'String',
'description' => __('URL', 'sage-next'),
],
'linkAs' => [
'type' => 'String',
'description' => __('Link component helper', 'sage-next'),
],
'linkHref' => [
'type' => 'String',
'description' => __('Link component helper', 'sage-next'),
],
'content' => [
'type' => 'String',
'description' => __('Filtered content', 'sage-next'),
],
'media' => [
'type' => 'String',
'description' => __('Featured media URL', 'sage-next')
],
];
}
/**
* Invocation
*/
public function __invoke(): void
{
remove_action('template_redirect', 'redirect_canonical');
add_action('graphql_register_types', function() {
register_graphql_type('Next', [
'description' => __( "Next framework specific fields", 'sage-next' ),
'fields' => $this->fields,
]);
register_graphql_field('Post', 'next', $this->type);
register_graphql_field('Page', 'next', $this->type);
});
}
/**
* Get URL variants
*
* @return array
*/
protected function getUrlVariants(): array
{
return [addslashes($this->url), $this->url];
}
})();
/**
* Theme setup.
*/
(new class() {
/**
* Class construct.
*/
public function __construct()
{
add_action('after_setup_theme', [$this, 'setup'], 20);
}
/**
* Setup theme
*
* @return void
*/
public function setup(): void
{
add_theme_support('title-tag');
register_nav_menus([
'primary' => __('Primary Navigation', 'sage-next'),
'footer' => __('Footer Navigation', 'sage-next'),
]);
add_theme_support('align-wide');
add_theme_support('responsive-embeds');
add_theme_support('editor-color-palette', [[
'name' => __('Primary', 'sage-next'),
'slug' => 'primary',
'color' => '#525ddc',
]]);
}
});