samrap / acf-fluent Goto Github PK
View Code? Open in Web Editor NEW✒️ A fluent interface for the Advanced Custom Fields WordPress plugin
License: MIT License
✒️ A fluent interface for the Advanced Custom Fields WordPress plugin
License: MIT License
The ability to define something like this...
Acf::macro('imageArray', function ($builder) {
return $builder
->expect('array')
->default([
'url' => 'default.jpg',
'alt' => 'Default Image',
]);
});
...and then call that "macro" from anywhere else in your code...
Acf::field('image')->imageArray()->get();
...might be a good way to shorten complex ACF queries especially when using the same expectation logic throughout templates.
The package does not currently provide a way to specify the format_value
argument in the get_field
and get_sub_field
functions.
WordPress provides sanitization functions that theme developers rely on. We should allow these functions in the whitelist and default to esc_html
. htmlspecialchars
and urlencode
will remain whitelisted.
See: https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data#Escaping:_Securing_Output
With the introduction of Group fields, my template is getting pretty heavy with values being inside of the group's array.
I was curious if you thought about any fluent, elegant way we could retrieve values, as well as process their shortcodes without assigning it to a variable and running do_shortcode()
on it?
At the moment, I have to do the following:
$header = Acf::field('header')->get();
return do_shortcode($header['subtitle']);
It'd be pretty nice to be able to retrieve a specific keys value from the array and process our escapes, shortcodes, and possibly even a default right from the ->get()
-go.
Something like Acf::field('header')->key('subtitle')->shortcodes()->get()
?
I'm sure it can be done in a much more sane syntax, the above is merely a pseudo-example.
Also, have you brainstormed on how we could have_rows(); the_row();
using acf-fluent? It'd be absolutely great if I can ditch ACF's functions all together. They are just... ugly. I ignore them in most cases using Blade directives with Sage 9, but I'd still much rather using acf-fluent for all of my ACF calls.
I'm sure you've thought about the above and it might just not be deemed sane-- but I thought I'd bring it up nonetheless.
Thanks a lot for acf-fluent. Using it with acf-builder is really great. 😃
The builder shortcodes method does not return a builder instance.
The Builder's fluent interface should always return $this
for every builder method. The shortcodes method was missing this and causing a runtime error. All tests should be updated to ensure $this
is returned.
The package creates new instances of the following objects on every call:
That means that 3 objects are created for every ACF call. Where appropriate, these classes should be cached and reused. The Builder acts as a container for the "queries", so it is not safe to cache this object. But the Runner and the behaviors should absolutely be instantiated no more than once.
A cache container should be created to store instances of each cacheable object to reduce the amount of resources used.
While ACF returns null
if a field is empty, it returns false
if a sub field is empty. Because of this, ACF Fluent does not properly return the default value if a sub field is empty.
I have installed acf-fluent by running the suggested command in my Wordpress website's theme directory:
composer require samrap/acf-fluent
I then included my composer dependencies by requiring the vendor/autoload.php
.
After doing the above and attempting to replicate the following example:
$heading = Acf::field('heading') ->default(get_the_title()) ->escape() ->get();
I receive the error:
Parse error: syntax error, unexpected 'default' (T_DEFAULT), expecting identifier (T_STRING) in {path_to_my_theme}/vendor/samrap/acf-fluent/src/Fluent/Builder.php on line 124
I don't think this should have an impact on the issue, but I am using Wordpress 4.7.3, the latest version of ACF Pro and the theme I am developing is based on the Roots Sage base theme (https://github.com/roots/sage).
Perhaps I am doing something wrong, but I have tried including acf-fluent a few different ways and seem to get the same error every time.
I look forward to using your interface in the future, and thanks in advance!
Improve readability and check coverage of tests across the package.
The Acf
namespace does not properly reflect the package. Consider renaming this to a more descriptive namespace, or simply using Samrap\Acf
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.