Skip to content

Commit b06512f

Browse files
committed
Added examples
1 parent 0e2cbc3 commit b06512f

5 files changed

+105
-1
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* text=auto eol=lf
22

33
/tests export-ignore
4+
/examples export-ignore
45
/.github export-ignore
56
/.editorconfig export-ignore
67
/.gitattributes export-ignore

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ register_extended_field_group([
5151
]);
5252
```
5353

54-
[Visit the official documentation to read more about the field group settings.](https://www.advancedcustomfields.com/resources/register-fields-via-php#group-settings)
54+
Find more examples in the [examples directory](examples) or [visit the official ACF documentation](https://www.advancedcustomfields.com/resources/register-fields-via-php#group-settings) to read more about the field group settings.
5555

5656
## Fields
5757

examples/custom-post-type.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use WordPlate\Acf\Fields\Email;
4+
use WordPlate\Acf\Fields\Text;
5+
use WordPlate\Acf\Location;
6+
7+
register_extended_field_group([
8+
'title' => 'Employee',
9+
'fields' => [
10+
Text::make('Title')
11+
->instructions('Add the employee title.')
12+
->required(),
13+
Email::make('Email address', 'email')
14+
->instructions('Add the employee email address.')
15+
->required(),
16+
Text::make('Phone number', 'phone')
17+
->instructions('Add the employee phone number.'),
18+
],
19+
'location' => [
20+
Location::if('post_type', 'employee'),
21+
],
22+
]);

examples/option-page.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
// This example is registering a option page using ACF. Please see the
4+
// documentation for more information:
5+
// https://www.advancedcustomfields.com/resources/acf_add_options_page/
6+
7+
use WordPlate\Acf\Fields\Text;
8+
use WordPlate\Acf\Fields\Wysiwyg;
9+
use WordPlate\Acf\Location;
10+
11+
acf_add_options_page([
12+
'icon_url' => 'dashicons-star-filled',
13+
'menu_slug' => 'cookie',
14+
'page_title' => 'Cookie',
15+
'position' => 21,
16+
]);
17+
18+
register_extended_field_group([
19+
'title' => 'Cookie',
20+
'fields' => [
21+
Wysiwyg::make('Text', 'cookie_text')
22+
->instructions('Add the cookie disclaimer text.')
23+
->mediaUpload(false)
24+
->toolbar('link')
25+
->tabs('visual')
26+
->required(),
27+
Text::make('Label', 'cookie_label')
28+
->instructions('Add the button label.')
29+
->required(),
30+
],
31+
'location' => [
32+
Location::if('options_page', 'cookie'),
33+
],
34+
]);

examples/with-extended-cpts.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
// This example is using the Extended CPTs package to register custom post types
4+
// and taxanomies. Please see the repository for more information:
5+
// https://github.com/johnbillion/extended-cpts
6+
7+
use WordPlate\Acf\Fields\Wysiwyg;
8+
use WordPlate\Acf\Location;
9+
10+
register_extended_post_type('faq', [
11+
'menu_icon' => 'dashicons-format-chat',
12+
'has_archive' => false,
13+
'supports' => ['title', 'revisions'],
14+
'admin_cols' => [
15+
'category' => [
16+
'taxonomy' => 'topic',
17+
],
18+
],
19+
'taxonomies' => ['topic'],
20+
], [
21+
'singluar' => 'FAQ',
22+
'plural' => 'FAQ',
23+
'slug' => 'faq',
24+
]);
25+
26+
register_extended_taxonomy('topic', 'faq', [
27+
'hierarchical' => false,
28+
'meta_box' => 'radio',
29+
'required' => true,
30+
'hierarchical' => false,
31+
'show_in_rest' => true,
32+
]);
33+
34+
register_extended_field_group([
35+
'title' => 'FAQ',
36+
'fields' => [
37+
Wysiwyg::make('Answer')
38+
->instructions('Add the question answer.')
39+
->mediaUpload(false)
40+
->toolbar('faq')
41+
->tabs('visual')
42+
->required(),
43+
],
44+
'location' => [
45+
Location::if('post_type', 'faq'),
46+
],
47+
]);

0 commit comments

Comments
 (0)