templates for self-hosting game jams (or any other kind of jam tbh)
1<?php
2
3/**
4 * Theme setup.
5 */
6
7namespace App;
8
9use Illuminate\Support\Facades\Vite;
10
11/**
12 * Inject styles into the block editor.
13 *
14 * @return array
15 */
16add_filter('block_editor_settings_all', function ($settings) {
17 $style = Vite::asset('resources/css/editor.scss');
18
19 $settings['styles'][] = [
20 'css' => "@import url('{$style}')",
21 ];
22
23 return $settings;
24});
25
26/**
27 * Inject scripts into the block editor.
28 *
29 * @return void
30 */
31add_filter('admin_head', function () {
32 if (! get_current_screen()?->is_block_editor()) {
33 return;
34 }
35
36 $dependencies = json_decode(Vite::content('editor.deps.json'));
37
38 foreach ($dependencies as $dependency) {
39 if (! wp_script_is($dependency)) {
40 wp_enqueue_script($dependency);
41 }
42 }
43
44 echo Vite::withEntryPoints([
45 'resources/js/editor.js',
46 ])->toHtml();
47});
48
49/**
50 * Use the generated theme.json file.
51 *
52 * @return string
53 */
54add_filter('theme_file_path', function ($path, $file) {
55 return $file === 'theme.json'
56 ? public_path('build/assets/theme.json')
57 : $path;
58}, 10, 2);
59
60/**
61 * Register the initial theme setup.
62 *
63 * @return void
64 */
65add_action('after_setup_theme', function () {
66 /**
67 * Disable full-site editing support.
68 *
69 * @link https://wptavern.com/gutenberg-10-5-embeds-pdfs-adds-verse-block-color-options-and-introduces-new-patterns
70 */
71 remove_theme_support('block-templates');
72
73 \register_post_type('game', [
74 'label' => 'Games',
75 'public' => true,
76 'show_in_rest' => true,
77 'supports' => [
78 'title',
79 'editor',
80 'custom-fields',
81 'revisions',
82 'trackbacks',
83 'comments',
84 'author',
85 'excerpt',
86 'thumbnail'
87 ],
88 'taxonomies' => [
89 'game_tag',
90 'game_platform'
91 ],
92 'register_meta_box_cb' => function () {
93 \add_meta_box(
94 'screenshots',
95 'Screenshots',
96 function () {
97 global $post;
98 wp_enqueue_media();
99 wp_enqueue_script('media-upload');
100 wp_enqueue_style( 'screenshot_css', Vite::asset('resources/css/screenshot.scss') );
101 // Add an nonce field so we can check for it later.
102 wp_nonce_field( 'screenshots_metabox', 'screenshots_metabox' );
103
104 $value = get_post_custom_values('_screenshots', $post->ID);
105
106 // Display the form, using the current value.
107 ?>
108 <label for="myplugin_new_field">
109 <?php _e( 'Screenshots', 'homemadejam' ); ?>
110 </label>
111 <div class="screenshots">
112 <div class="screenshot"><a href="#" id="open-gallery-screenshots">Add Screenshots</a></div>
113 <?php if ($value) : ?>
114 <?php foreach($value as $img) : ?>
115 <a href="#" class="gallery-img"><?php print_r($img); ?></a>
116 <?php endforeach; ?>
117 <?php endif; ?>
118 </div>
119 <input type="hidden" name="_screenshots" id="screenshots" value="<?php echo esc_attr($value); ?>" />
120 <?php
121 },
122 'game',
123 'normal',
124 'core'
125 );
126 \add_meta_box(
127 'downloads',
128 'Downloads',
129 function () {
130
131 },
132 'game',
133 'normal',
134 'core'
135 );
136 }
137 ]);
138
139 \register_post_type('joined', [
140 'public' => false,
141 'show_ui' => true,
142 'supports' => [
143 'title',
144 'custom-fields',
145 'thumbnail'
146 ]
147 ]);
148
149 \register_taxonomy('game_tag', ['game'], [
150 'labels' => [
151 'name' => 'Tags',
152 'singular_name' => 'Tag'
153 ],
154 'public' => true,
155 'show_in_rest' => true
156 ]);
157
158 \register_taxonomy('game_platform', ['game'], [
159 'labels' => [
160 'name' => 'Platforms',
161 'singular_name' => 'Platform'
162 ],
163 'hierarchical' => true,
164 'public' => true,
165 'show_in_rest' => true
166 ]);
167
168 if (!term_exists('windows', 'game_platform')) {
169 \wp_insert_term('windows', 'game_platform');
170 }
171
172 if (!term_exists('macos', 'game_platform')) {
173 \wp_insert_term('macos', 'game_platform');
174 }
175
176 if (!term_exists('linux', 'game_platform')) {
177 \wp_insert_term('linux', 'game_platform');
178 }
179
180 if (!term_exists('android', 'game_platform')) {
181 \wp_insert_term('android', 'game_platform');
182 }
183
184 if (!term_exists('web', 'game_platform')) {
185 \wp_insert_term('web', 'game_platform');
186 }
187
188 /**
189 * Register the navigation menus.
190 *
191 * @link https://developer.wordpress.org/reference/functions/register_nav_menus/
192 */
193 register_nav_menus([
194 'primary_navigation' => __('Primary Navigation', 'sage'),
195 ]);
196
197 /**
198 * Disable the default block patterns.
199 *
200 * @link https://developer.wordpress.org/block-editor/developers/themes/theme-support/#disabling-the-default-block-patterns
201 */
202 remove_theme_support('core-block-patterns');
203
204 /**
205 * Enable plugins to manage the document title.
206 *
207 * @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag
208 */
209 add_theme_support('title-tag');
210
211 /**
212 * Enable post thumbnail support.
213 *
214 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
215 */
216 add_theme_support('post-thumbnails');
217
218 /**
219 * Enable responsive embed support.
220 *
221 * @link https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#responsive-embedded-content
222 */
223 add_theme_support('responsive-embeds');
224
225 /**
226 * Enable HTML5 markup support.
227 *
228 * @link https://developer.wordpress.org/reference/functions/add_theme_support/#html5
229 */
230 add_theme_support('html5', [
231 'caption',
232 'comment-form',
233 'comment-list',
234 'gallery',
235 'search-form',
236 'script',
237 'style',
238 ]);
239
240 /**
241 * Enable selective refresh for widgets in customizer.
242 *
243 * @link https://developer.wordpress.org/reference/functions/add_theme_support/#customize-selective-refresh-widgets
244 */
245 add_theme_support('customize-selective-refresh-widgets');
246}, 20);
247
248/**
249 * Register the theme sidebars.
250 *
251 * @return void
252 */
253add_action('widgets_init', function () {
254 $config = [
255 'before_widget' => '<section class="widget %1$s %2$s">',
256 'after_widget' => '</section>',
257 'before_title' => '<h3>',
258 'after_title' => '</h3>',
259 ];
260
261 register_sidebar([
262 'name' => __('Primary', 'sage'),
263 'id' => 'sidebar-primary',
264 ] + $config);
265
266 register_sidebar([
267 'name' => __('Footer', 'sage'),
268 'id' => 'sidebar-footer',
269 ] + $config);
270});