-
Notifications
You must be signed in to change notification settings - Fork 5
remove get fields, cleanup code #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Sur un projet de nombreux modèles + beaucoup de champs, je gagne 0,3 sec sur chaque génération de page, non négligeable. |
petitphp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On peut directement passer l'objet WP_User à get_field et ACF gère automatiquement, sinon OK.
J'ai vérifié, get_field renvoi bien une meta même si ce n'est pas un champ register, donc pas de gros impact à l'utiliser tout le temps si disponible.
classes/Models/User.php
Outdated
| } | ||
|
|
||
| return get_field( $fields[ $key ], 'user_' . $this->get_id(), $format ); | ||
| return get_field( $key, 'user_' . $this->get_id(), $format ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return get_field( $key, 'user_' . $this->get_id(), $format ); | |
| return get_field( $key, $this->user, $format ); |
|
Je crois que c'était fait comme ça parce que ACF gérait un peu mal les clés, mais ça me semble ^tre ok là avec la modification de Clément. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| // On ACF given key | ||
| $key = in_array( $key, $fields, true ) ? $key : $fields[ $key ]; | ||
|
|
||
| return \get_field( $key, $this->get_id(), $format ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Non-ACF meta keys return null with ACF 5.11+
The refactored get_meta() now always calls get_field() when ACF is installed, but ACF 5.11+ no longer falls back to get_post_meta() for non-ACF field keys (this was a security change). The old code explicitly checked if the key was in the ACF fields array and fell back to direct property access for non-ACF keys. The method's docstring states it works for "the ACF or the meta key" but the new implementation only works for ACF fields when ACF 5.11+ is active. This breaks get_all_data() which explicitly calls get_meta() with non-ACF meta keys at line 440.
Note
Streamlines Model and User meta get/update to use direct keys with ACF (or WP meta fallback), removing reliance on ACF fields mapping.
classes/Models/Model.php:get_meta: use direct ACFget_field($key, $id, $format); fallback toget_post_meta()when ACF unavailable.update_content_meta: use direct ACFupdate_field($key, $value, $id); fallback toupdate_post_meta()when ACF unavailable. Param$valueloosened tomixed.get_fields()for ACF name↔key mapping in meta access.classes/Models/User.php:get_meta: use direct ACFget_field($key, $this->user, $format); fallback toget_user_meta()when ACF unavailable.update_user_meta: use direct ACFupdate_field($key, $value, 'user_'.$id); fallback toupdate_user_meta().get_fields()mapping from meta get/update paths.Written by Cursor Bugbot for commit cd0b2ff. This will update automatically on new commits. Configure here.