diff --git a/includes/transformer/class-base.php b/includes/transformer/class-base.php index 5a9ad96..4f626a0 100644 --- a/includes/transformer/class-base.php +++ b/includes/transformer/class-base.php @@ -78,20 +78,39 @@ abstract class Base { // todo renmae to Base_tranformer /** * Retrieves a post meta field for the configured post. * - * @param string $key Optional. The meta key to retrieve. By default, - * returns data for all keys. Default empty. - * @param bool $single Optional. Whether to return a single value. - * This parameter has no effect if `$key` is not specified. - * Default false. + * @param string $key The meta key to retrieve. By default, + * returns data for all keys. + * @param bool $single Optional. Whether to return a single value. + * This parameter has no effect if `$key` is not specified. + * Default false. + * @param mixed $default_value Optional. if the key doesn't exists, it returns the default value. + * Default null. * @return mixed An array of values if `$single` is false. * The value of the meta field if `$single` is true. * False for an invalid `$post_id` (non-numeric, zero, or negative value). * An empty string if a valid but non-existing post ID is passed. */ - public function get_post_meta( string $key = '', $single = false, $default = null ) { - // todo test what if not present - // empty string or empty array, then return default - return \get_post_meta( $this->wp_post->ID, $key, $single ); + public function get_post_meta( $key, $single = false, $default_value = null ) { + if ( \metadata_exists( 'post', $this->wp_post->ID, $key ) ) { + return \get_post_meta( $this->wp_post->ID, $key, $single ); + } + return $default_value; + } + + /** + * Retrieves a post property field for the configured post. + * + * @param string $key The property key to retrieve. By default, + * returns data for all keys. + * @param mixed $default_value Optional. if the key doesn't exists, it returns the default value. + * Default null. + * @return mixed The value of the property. + */ + public function get_post_property( $key, $default_value = null ) { + if ( isset( $this->wp_post->$key ) ) { + return $this->wp_post->$key; + } + return $default_value; } /**