From c640a25f78cc1f5d97fc3813044157a025b17b88 Mon Sep 17 00:00:00 2001 From: Shea Bunge Date: Thu, 5 May 2022 12:11:45 +1000 Subject: [PATCH] Use is_allowed_field instead of just checking isset() --- php/class-snippet.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 ); }