diff --git a/classes/Models/Model.php b/classes/Models/Model.php index de5f85d..17883a7 100644 --- a/classes/Models/Model.php +++ b/classes/Models/Model.php @@ -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 ) ) ); } @@ -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 ); } @@ -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() ); } diff --git a/classes/Models/User.php b/classes/Models/User.php index cd16c9d..84f52c5 100644 --- a/classes/Models/User.php +++ b/classes/Models/User.php @@ -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 ); } /** @@ -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() ); }