Skip to content

Commit

Permalink
Use is_allowed_field instead of just checking isset()
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed May 5, 2022
1 parent f5f6628 commit c640a25
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions php/class-snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ];
Expand All @@ -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 );
}
Expand Down

0 comments on commit c640a25

Please sign in to comment.