Skip to content

Commit 1243a4c

Browse files
committed
Fix undefined property warning in Item::__call magic method
Add property_exists() checks before accessing dynamic properties in get, has, and add methods. Return empty string instead of null for non-existent properties.
1 parent 3849c03 commit 1243a4c

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

includes/entity/class-item.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ public function __call( $method, $params ) {
115115
$var = strtolower( substr( $method, 4 ) );
116116

117117
if ( strncasecmp( $method, 'get', 3 ) === 0 ) {
118-
return $this->$var;
118+
return property_exists( $this, $var ) ? $this->$var : '';
119119
}
120120

121121
if ( strncasecmp( $method, 'has', 3 ) === 0 ) {
122-
return ! empty( $this->$var );
122+
return property_exists( $this, $var ) && ! empty( $this->$var );
123123
}
124124

125125
if ( strncasecmp( $method, 'set', 3 ) === 0 ) {
126126
$this->$var = current( $params );
127127
}
128128

129129
if ( strncasecmp( $method, 'add', 3 ) === 0 ) {
130-
if ( ! $this->$var ) {
130+
if ( ! property_exists( $this, $var ) || ! $this->$var ) {
131131
call_user_func( array( $this, 'set_' . $var ), current( $params ) );
132132
return true;
133133
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Project and support maintained on github at [pfefferle/wordpress-webmention](htt
103103

104104
### 5.6.0
105105

106+
* Fix undefined property warning in `Item::__call` magic method when accessing non-existent properties like `category`.
106107
* Search Avatar Store if enabled for match before trying meta field. Disable updating meta field when side loading allowing for more flexibility.
107108
* Fix editor plugin error on custom post types without `custom-fields` support.
108109
* Add video/audio URL extraction as content fallback for webmentions without text content.

0 commit comments

Comments
 (0)