Skip to content
Open
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 );
}

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, '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 );

}

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