Skip to content

Commit 79ee2b9

Browse files
committed
Initial commit
0 parents  commit 79ee2b9

File tree

8 files changed

+289
-0
lines changed

8 files changed

+289
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.php]
15+
indent_size = 4
16+
17+
[*.blade.php]
18+
indent_size = 2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) Roots Software LLC
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Acorn Post Types
2+
3+
Simple post types and taxonomies using Extended CPTs for Acorn.
4+
5+
## Requirements
6+
7+
- [PHP](https://secure.php.net/manual/en/install.php) >= 8.1
8+
- [Acorn](https://github.com/roots/acorn) >= 4.0
9+
10+
## Installation
11+
12+
Install via Composer:
13+
14+
```bash
15+
composer require roots/acorn-post-types
16+
```
17+
18+
## Getting Started
19+
20+
Start by optionally publishing the post-types config:
21+
22+
```shell
23+
$ wp acorn vendor:publish --provider="Roots\AcornPostTypes\AcornPostTypesServiceProvider"
24+
```
25+
26+
## Usage
27+
28+
Post types and taxonomies can be configured in the published `config/post-types.php` file.
29+
30+
## Bug Reports
31+
32+
If you discover a bug in Acorn Post Types, please [open an issue](https://github.com/roots/acorn-post-types/issues).
33+
34+
## Contributing
35+
36+
Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.
37+
38+
## License
39+
40+
Acorn Post Types is provided under the [MIT License](LICENSE.md).

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "roots/acorn-post-types",
3+
"type": "package",
4+
"description": "Simple post types and taxonomies using Extended CPTs for Acorn.",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Roots",
9+
"email": "team@roots.io"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Roots\\AcornPostTypes\\": "src/"
15+
}
16+
},
17+
"require": {
18+
"php": ">=8.1",
19+
"johnbillion/extended-cpts": "^5.0"
20+
},
21+
"require-dev": {
22+
"laravel/pint": "^1.13",
23+
"roots/acorn": "^4.0"
24+
},
25+
"extra": {
26+
"acorn": {
27+
"providers": [
28+
"Roots\\AcornPostTypes\\AcornPostTypesServiceProvider"
29+
]
30+
}
31+
}
32+
}

config/post-types.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Post Types
8+
|--------------------------------------------------------------------------
9+
|
10+
| Post types to be registered with Extended CPTs
11+
| <https://github.com/johnbillion/extended-cpts>
12+
|
13+
*/
14+
15+
'post_types' => [
16+
'seed' => [
17+
'menu_icon' => 'dashicons-star-filled',
18+
'supports' => ['title', 'editor', 'author', 'revisions', 'thumbnail'],
19+
'show_in_rest' => true,
20+
'names' => [
21+
'singular' => 'Seed',
22+
'plural' => 'Seeds',
23+
'slug' => 'seeds',
24+
],
25+
],
26+
],
27+
28+
/*
29+
|--------------------------------------------------------------------------
30+
| Taxonomies
31+
|--------------------------------------------------------------------------
32+
|
33+
| Taxonomies to be registered with Extended CPTs library
34+
| <https://github.com/johnbillion/extended-cpts>
35+
|
36+
*/
37+
38+
'taxonomies' => [
39+
'seed_category' => [
40+
'post_types' => ['seed'],
41+
'meta_box' => 'radio',
42+
'names' => [
43+
'singular' => 'Category',
44+
'plural' => 'Categories',
45+
],
46+
],
47+
],
48+
];

src/AcornPostTypes.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace Roots\AcornPostTypes;
4+
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Collection;
7+
use Roots\Acorn\Application;
8+
9+
class AcornPostTypes
10+
{
11+
/**
12+
* The Application instance.
13+
*/
14+
protected Application $app;
15+
16+
/**
17+
* The post types configuration.
18+
*/
19+
protected Collection $config;
20+
21+
/**
22+
* Create a new Acorn Post Types instance.
23+
*
24+
* @return void
25+
*/
26+
public function __construct(Application $app)
27+
{
28+
$this->app = $app;
29+
$this->config = Collection::make($this->app->config->get('post-types'));
30+
31+
$this->registerPostTypes();
32+
$this->registerTaxonomies();
33+
}
34+
35+
/**
36+
* Make a new instance of Acorn Post Types.
37+
*/
38+
public static function make(Application $app): self
39+
{
40+
return new static($app);
41+
}
42+
43+
/**
44+
* Register post types.
45+
*/
46+
protected function registerPostTypes(): void
47+
{
48+
Collection::make($this->config->get('post_types', []))
49+
->each(function ($args, $post_type) {
50+
register_extended_post_type(
51+
$post_type,
52+
$args,
53+
Arr::pull($args, 'names')
54+
);
55+
});
56+
}
57+
58+
/**
59+
* Register taxonomies.
60+
*/
61+
protected function registerTaxonomies(): void
62+
{
63+
Collection::make($this->config->get('taxonomies', []))
64+
->each(function ($args, $taxonomy) {
65+
register_extended_taxonomy(
66+
$taxonomy,
67+
Arr::pull($args, 'post_types'),
68+
$args,
69+
Arr::pull($args, 'names')
70+
);
71+
});
72+
}
73+
74+
/**
75+
* Get registered post types from config.
76+
*/
77+
public function getPostTypes(): array
78+
{
79+
return $this->config->get('post_types', []);
80+
}
81+
82+
/**
83+
* Get registered taxonomies from config.
84+
*/
85+
public function getTaxonomies(): array
86+
{
87+
return $this->config->get('taxonomies', []);
88+
}
89+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Roots\AcornPostTypes;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class AcornPostTypesServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register any application services.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
$this->app->singleton('Roots\AcornPostTypes', fn () => AcornPostTypes::make($this->app));
17+
18+
$this->mergeConfigFrom(
19+
__DIR__.'/../config/post-types.php',
20+
'post-types'
21+
);
22+
}
23+
24+
/**
25+
* Bootstrap any application services.
26+
*
27+
* @return void
28+
*/
29+
public function boot()
30+
{
31+
$this->publishes([
32+
__DIR__.'/../config/post-types.php' => $this->app->configPath('post-types.php'),
33+
], 'config');
34+
35+
/**
36+
* Register post types and taxonomies on WordPress init.
37+
*/
38+
add_action('init', function (): void {
39+
$this->app->make('Roots\AcornPostTypes');
40+
}, 100);
41+
}
42+
}

0 commit comments

Comments
 (0)