Skip to content

Commit 89e92b9

Browse files
committed
Prepare 12.0.0
1 parent 3b132d9 commit 89e92b9

File tree

6 files changed

+56
-38
lines changed

6 files changed

+56
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## Next
3+
## 12.0.0
44

55
- Updated minimum PHP version to 8.0
66
- Updated type hints and return types

README.md

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Require this package, with Composer, in the root directory of your project.
2626
composer require wordplate/acf
2727
```
2828

29-
Download the [Advanced Custom Fields Pro](https://www.advancedcustomfields.com/pro) plugin and put it in either the `plugins` or `mu-plugins` directory. Visit the WordPress dashboard and activate the plugin. Please note that you'll need the latest version of ACF in order to use all features in this package.
29+
Download the [Advanced Custom Fields Pro](https://www.advancedcustomfields.com/pro) plugin and put it in either the `plugins` or `mu-plugins` directory. Visit the WordPress dashboard and activate the plugin.
3030

3131
#### Installing ACF Pro with Composer (optional)
3232

@@ -66,7 +66,7 @@ add_action('acf/init', function() {
6666
Text::make('Title'),
6767
],
6868
'location' => [
69-
Location::if('post_type', 'page')
69+
Location::where('post_type', 'page')
7070
],
7171
]);
7272
});
@@ -91,8 +91,6 @@ Text::make('Title', 'heading')
9191
->required();
9292
```
9393

94-
Further down this page you'll find a list of available field types. Setting such as `wrapper`, `append` and `prepend` are supported on almost all fields but not listed in the documentation below. [Visit the official documentation](https://www.advancedcustomfields.com/resources/register-fields-via-php#field-settings) to read more about field settings.
95-
9694
### Basic Fields
9795

9896
**Email** - The [email field](https://www.advancedcustomfields.com/resources/text) creates a simple email input.
@@ -250,7 +248,7 @@ use WordPlate\Acf\Fields\TrueFalse;
250248
TrueFalse::make('Social Media', 'display-social-media')
251249
->instructions('Select whether to display social media links or not.')
252250
->defaultValue(false)
253-
->stylisedUi() // optinal on and off text labels
251+
->stylisedUi() // optional on and off text labels
254252
->required();
255253
```
256254

@@ -414,24 +412,25 @@ Accordion::make('Endpoint')
414412

415413
**Clone** - The [clone field](https://www.advancedcustomfields.com/resources/clone) allows you to select and display existing fields or groups. This field doesn't have a custom field class. Instead create a new file with your field and import it using `require` where you need it.
416414

417-
- `occupation.php`
415+
`occupation.php`
416+
417+
```php
418+
use WordPlate\Acf\Fields\Text;
418419

419-
```php
420-
use WordPlate\Acf\Fields\Text;
420+
return Text::make('Occupation')
421+
->instructions('Add the employees occupation.')
422+
->required();
423+
```
421424

422-
return Text::make('Occupation')
423-
->instructions('Add the employees occupation.')
424-
->required();
425-
```
426-
- `employee.php`
425+
`employee.php`
427426

428-
```php
429-
register_extended_field_group([
430-
'fields' => [
431-
require __DIR__.'/fields/occupation.php';
432-
]
433-
]);
434-
```
427+
```php
428+
register_extended_field_group([
429+
'fields' => [
430+
require __DIR__.'/fields/occupation.php';
431+
]
432+
]);
433+
```
435434

436435
**Flexible Content** - The [flexible content field](https://www.advancedcustomfields.com/resources/flexible-content) acts as a blank canvas to which you can add an unlimited number of layouts with full control over the order.
437436
```php
@@ -598,22 +597,22 @@ User::make('User')
598597
])
599598
->returnFormat('array'); // id, object or array (default)
600599

601-
// Available roles are administrator, author, subscriber, contributor and editor. Deafult is no filter.
600+
// Available roles are administrator, author, subscriber, contributor and editor. Default is no filter.
602601
```
603602

604603
## Location
605604

606-
The location class let you write [custom location rules](https://www.advancedcustomfields.com/resources/custom-location-rules) without the `name`, `operator` and `value` keys. If no `operator` is given it will use the `operator` as the `key`.
605+
The location class let you write [custom location rules](https://www.advancedcustomfields.com/resources/custom-location-rules) without the `name`, `operator` and `value` keys. If no `operator` is given it will use the `operator` as the `value`.
607606

608607
```php
609608
use WordPlate\Acf\Location;
610609

611-
Location::if('post_type', 'post')->and('post_type', '!=', 'post');
610+
Location::where('post_type', 'post')->and('post_type', '!=', 'post');
612611
```
613612

614613
## Conditional Logic
615614

616-
The conditional class help you write conditional logic [without knowing](https://media.giphy.com/media/SbtWGvMSmJIaV8faS8/source.gif) the fields `key` value.
615+
The conditional class help you write conditional logic [without knowing](https://media.giphy.com/media/SbtWGvMSmJIaV8faS8/source.gif) the field keys.
617616

618617
```php
619618
use WordPlate\Acf\ConditionalLogic;
@@ -628,17 +627,17 @@ Select::make('Type')
628627
]),
629628
File::make('Document', 'file')
630629
->conditionalLogic([
631-
ConditionalLogic::if('type')->equals('document')
630+
ConditionalLogic::where('type', '==', 'document') // available operators are ==, !=, >, < ==pattern, ==contains, ==empty, !=empty
632631
]),
633632
Url::make('Link', 'url')
634633
->conditionalLogic([
635-
ConditionalLogic::if('type')->equals('link')
634+
ConditionalLogic::where('type', '==', 'link')
636635
]),
637636
```
638637

639638
## Custom Configuration
640639

641-
If your application use third-party plugins which extend the default fields, you can extend the field classes in this package. Lets say you've want to add a configuration key to the select field. Create a new class which extends the base `WordPlate\Acf\Fields\Select` class:
640+
If you want to add custom settings to the fields, you can extend the field classes available in this library.
642641

643642
```php
644643
namespace App\Fields;
@@ -658,27 +657,46 @@ class Select extends Field
658657

659658
## Custom Fields
660659

661-
If your application use fields which isn't a default field in ACF, you may extend and create custom field classes. Lets say you've a field for Open Street Map. Create a new class which extends the base `WordPlate\Acf\Fields\Field` class:
660+
If you want to create custom field classes you may extend the [base field class](src/Fields/Field.php). You may also import [available setting traits](src/Fields/Settings) in order to add common methods such as `required()` and `intstructions()`.
662661

663662
```php
664663
namespace App\Fields;
665664

666665
use WordPlate\Acf\Fields\Field;
667-
use WordPlate\Acf\Fields\Attributes\Instructions;
668-
use WordPlate\Acf\Fields\Attributes\Required;
666+
use WordPlate\Acf\Fields\Settings\Instructions;
667+
use WordPlate\Acf\Fields\Settings\Required;
669668

670669
class OpenStreetMap extends Field
671670
{
672671
use Instructions;
673672
use Required;
674673

675674
protected $type = 'open_street_map';
675+
676+
public function latitude(float $latitude): static
677+
{
678+
$this->settings['latitude'] = $latitude;
679+
680+
return $this;
681+
}
682+
683+
public function longitude(float $longitude): static
684+
{
685+
$this->settings['longitude'] = $longitude;
686+
687+
return $this;
688+
}
689+
690+
public function zoom(float $zoom): static
691+
{
692+
$this->settings['zoom'] = $zoom;
693+
694+
return $this;
695+
}
676696
}
677697
```
678698

679-
Notice that we've imported traits which include the `required()` and `instructions()` methods. We've also added the `$type` property in order to let ACF know which field we're working with. You may now add any additional methods to this class which you will need such as `latitude()`, `longitude()`, `zoom()`, etc.
680-
681-
When you're ready you can import use it like any other field included in this package:
699+
When you're ready you can import use your field like any other field available in this library:
682700

683701
```php
684702
use App\Fields\OpenStreetMap;

examples/custom-post-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
->instructions('Add the employee phone number.'),
1818
],
1919
'location' => [
20-
Location::if('post_type', 'employee'),
20+
Location::where('post_type', 'employee'),
2121
],
2222
]);

examples/gutenberg-block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
->returnFormat('object')
2222
],
2323
'location' => [
24-
Location::if('block', 'acf/employee')
24+
Location::where('block', 'acf/employee')
2525
],
2626
]);

examples/option-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
->required(),
3030
],
3131
'location' => [
32-
Location::if('options_page', 'cookie'),
32+
Location::where('options_page', 'cookie'),
3333
],
3434
]);

examples/with-extended-cpts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
->required(),
4545
],
4646
'location' => [
47-
Location::if('post_type', 'faq'),
47+
Location::where('post_type', 'faq'),
4848
],
4949
]);

0 commit comments

Comments
 (0)