From 1fe8c26b1d43bd8908507aa4c48be486eced3c2e Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 28 Jun 2023 19:38:19 +0200 Subject: [PATCH] ignore prefixed attributes --- includes/activity/class-base-object.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/includes/activity/class-base-object.php b/includes/activity/class-base-object.php index c8520ba..ee98411 100644 --- a/includes/activity/class-base-object.php +++ b/includes/activity/class-base-object.php @@ -462,6 +462,24 @@ class Base_Object { } } + /** + * Magic function, to transform the object to string. + * + * @return string The object id. + */ + public function __toString() { + return $this->to_string(); + } + + /** + * Function to transform the object to string. + * + * @return string The object id. + */ + public function to_string() { + return $this->get_id(); + } + /** * Generic getter. * @@ -575,6 +593,11 @@ class Base_Object { $vars = get_object_vars( $this ); foreach ( $vars as $key => $value ) { + // ignotre all _prefixed keys. + if ( '_' === substr( $key, 0, 1 ) ) { + continue; + } + // if value is empty, try to get it from a getter. if ( ! isset( $value ) ) { $value = call_user_func( array( $this, 'get_' . $key ) );