diff --git a/php/class-snippet.php b/php/class-snippet.php index f01129aa..92511cc7 100644 --- a/php/class-snippet.php +++ b/php/class-snippet.php @@ -73,7 +73,7 @@ public function __construct( $fields = null ) { } /** - * Set all of the snippet fields from an array or object. + * Set all snippet fields from an array or object. * Invalid fields will be ignored * * @param array|object $fields List of fields @@ -149,8 +149,12 @@ public function __get( $field ) { return call_user_func( array( $this, 'get_' . $field ) ); } - if ( ! isset( $this->fields[ $field ] ) ) { - throw new Exception( sprintf( 'Snippet field %s does not exist', esc_html( $field ) ) ); + if ( ! $this->is_allowed_field( $field ) ) { + if ( WP_DEBUG ) { + trigger_error( 'Trying to access invalid property on Snippets class: ' . esc_html( $field ), E_WARNING ); + } + + return null; } return $this->fields[ $field ]; @@ -166,7 +170,6 @@ public function __set( $field, $value ) { $field = $this->validate_field_name( $field ); if ( ! $this->is_allowed_field( $field ) ) { - if ( WP_DEBUG ) { trigger_error( 'Trying to set invalid property on Snippets class: ' . esc_html( $field ), E_WARNING ); }