Skip to content

Conversation

@herewithme
Copy link
Member

@herewithme herewithme commented Sep 4, 2024

Note

Streamlines Model and User meta get/update to use direct keys with ACF (or WP meta fallback), removing reliance on ACF fields mapping.

  • Models:
    • classes/Models/Model.php:
      • get_meta: use direct ACF get_field($key, $id, $format); fallback to get_post_meta() when ACF unavailable.
      • update_content_meta: use direct ACF update_field($key, $value, $id); fallback to update_post_meta() when ACF unavailable. Param $value loosened to mixed.
      • Removed use of get_fields() for ACF name↔key mapping in meta access.
    • classes/Models/User.php:
      • get_meta: use direct ACF get_field($key, $this->user, $format); fallback to get_user_meta() when ACF unavailable.
      • update_user_meta: use direct ACF update_field($key, $value, 'user_'.$id); fallback to update_user_meta().
      • Removed get_fields() mapping from meta get/update paths.

Written by Cursor Bugbot for commit cd0b2ff. This will update automatically on new commits. Configure here.

@herewithme
Copy link
Member Author

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
petitphp previously approved these changes Sep 17, 2024
Copy link
Member

@petitphp petitphp left a 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.

}

return get_field( $fields[ $key ], 'user_' . $this->get_id(), $format );
return get_field( $key, 'user_' . $this->get_id(), $format );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return get_field( $key, 'user_' . $this->get_id(), $format );
return get_field( $key, $this->user, $format );

@Rahe
Copy link
Member

Rahe commented Sep 17, 2024

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.

asadowski10
asadowski10 previously approved these changes Dec 20, 2024
@asadowski10 asadowski10 dismissed stale reviews from petitphp and themself via cd0b2ff December 11, 2025 14:45
@asadowski10 asadowski10 merged commit cd0b2ff into master Dec 11, 2025
1 of 2 checks passed
Copy link

@cursor cursor bot left a 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 );
Copy link

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.

Additional Locations (1)

Fix in Cursor Fix in Web

@asadowski10 asadowski10 deleted the feature/performances branch December 11, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants