Skip to content

Commit 6d0abd4

Browse files
Merge pull request #2 from WP4Laravel/feature/martijn.g-blade-templates-in-ACF
Make Blade template available in ACF
2 parents af95212 + 338d506 commit 6d0abd4

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WP4Laravel WordPress plugin
2+
3+
This plugin makes WordPress and the `wp4laravel` theme work together with `wp4laravel/wp4laravel`.
4+
5+
## Installation
6+
7+
`composer require wp4laravel/wp4laravel-plugin`
8+
9+
## Functionality
10+
11+
### Blade template loading
12+
13+
When you have Blade templates in `resources/views` you can show them as templates in the WordPress edit screen.
14+
15+
Create a folder with the same name as the post type in `resources/views` and add a Blade template to it. `default.blade.php` will be used when you select WordPress default template.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wp4laravel/wp4laravel-plugin",
3-
"description": "Wordpress MU plugin for the WP4Laravel concept",
3+
"description": "Wordpress plugin for the WP4Laravel concept",
44
"type": "wordpress-plugin",
55
"license": "MIT",
66
"authors": [
@@ -9,6 +9,6 @@
99
"email": "development@in10.nl"
1010
}
1111
],
12-
"minimum-stability": "dev",
12+
"minimum-stability": "stable",
1313
"require": {}
1414
}

src/config/template.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
<?php
22

3-
add_action('registered_post_type', function () {
4-
foreach (get_post_types(['public'=>true], 'names') as $type) {
5-
add_filter("theme_{$type}_templates", 'filter_templates');
6-
}
7-
});
3+
add_filter('theme_templates', 'add_blade_templates', 10, 4);
84

9-
function filter_templates($templates)
10-
{
5+
function add_blade_templates(array $templates, WP_Theme $theme, WP_Post|null $post, string $post_type) {
116
if (!defined('WP_TEMPLATE_DIR')) {
127
return $templates;
138
}
149

15-
if (!$type = get_post_type()) {
10+
if (!is_post_type_viewable($post_type)) {
1611
return $templates;
1712
}
1813

19-
20-
$path = WP_TEMPLATE_DIR.$type;
14+
$path = WP_TEMPLATE_DIR.$post_type;
2115

2216
if (!is_dir($path)) {
2317
return $templates;
2418
}
2519

2620
$filtered = array_filter(scandir($path), function ($item) {
27-
return $item == '.' || $item == '..' || strpos($item, ".blade.php") === false ? false : true;
21+
return $item == '.' || $item == '..' || $item == 'default.blade.php' || strpos($item, ".blade.php") === false ? false : true;
2822
});
2923

3024
$list = array_map(function ($item) {
@@ -33,3 +27,4 @@ function filter_templates($templates)
3327

3428
return array_merge($templates, array_combine($list, $list));
3529
}
30+

0 commit comments

Comments
 (0)