Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions classes/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ abstract class Model {
* @throws \Exception
*/
public function __construct( \WP_Post $post_obj ) {

if ( $post_obj->post_type !== $this->post_type ) {
throw new \InvalidArgumentException( sprintf( '%s post type does not match model post type %s', esc_html( $post_obj->post_type ), esc_html( $this->post_type ) ) );
}
Expand Down Expand Up @@ -137,17 +136,11 @@ public function get_meta( string $key, $format = true ) {
return false;
}

// Get all ACF fields
$fields = $this->get_fields();

// Check ACF
if ( ! function_exists( '\get_field' ) || ( ! in_array( $key, $fields, true ) && ! isset( $fields[ $key ] ) ) ) {
return $this->wp_object->{$key};
if ( ! function_exists( '\get_field' ) ) {
return get_post_meta( $this->get_id(), $key, true );
}

// 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

}

Expand Down Expand Up @@ -176,19 +169,16 @@ public function update_meta( string $key, $value = '' ) {
* Really update the value
*
* @param string $key
* @param string $value
* @param mixed $value
*
* @return bool|int
*/
protected function update_content_meta( string $key, $value = '' ) {
// Check ACF
if ( ! function_exists( '\update_field' ) ) {
return update_post_meta( $this->get_id(), $key, $value );
}

// Get the fields and use the ACF ones
$fields = $this->get_fields();
$key = isset( $fields[ $key ] ) ? $fields[ $key ] : $key;

return \update_field( $key, $value, $this->get_id() );
}

Expand Down
13 changes: 3 additions & 10 deletions classes/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,12 @@ public function get_meta( string $key, $format = true ) {
return false;
}

// Get all ACF fields
$fields = $this->get_fields();

// Check ACF
if ( ! isset( $fields[ $key ] ) || ! function_exists( 'get_field' ) ) {
return $this->user->{$key};
if ( ! function_exists( 'get_field' ) ) {
return get_user_meta( $this->get_id(), $key, true );
}

return get_field( $fields[ $key ], 'user_' . $this->get_id(), $format );
return get_field( $key, $this->user, $format );
}

/**
Expand Down Expand Up @@ -247,10 +244,6 @@ protected function update_user_meta( string $key, $value = '' ) {
return update_user_meta( $this->get_id(), $key, $value );
}

// Get the fields and use the ACF ones
$fields = $this->get_fields();
$key = $fields[ $key ] ?? $key;

return update_field( $key, $value, 'user_' . $this->get_id() );
}

Expand Down
Loading