Skip to content

Commit

Permalink
Allow Post::get_field method to accept default value returned when fi…
Browse files Browse the repository at this point in the history
…eld is empty.
  • Loading branch information
Jakub Szajna committed Jan 28, 2019
1 parent a94c445 commit 3f88ab3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions generators/wp/templates/chisel-starter-theme/Chisel/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,20 @@ protected function prepareFakePost( $fields ) {
* Overrides get_field function to use fake meta when provided.
*
* @param $field_name
* @param $default_value mixed Default value if field is empty
*
* @return mixed
*/
public function get_field( $field_name ) {
public function get_field( $field_name, $default_value = null ) {
$value = null;
if ( $this->fakeFields && isset( $this->fakeFields[ $field_name ] ) ) {
return $this->fakeFields[ $field_name ];
$value = $this->fakeFields[ $field_name ];
} else {
$value = $this->_get_field( $field_name );
$value = $this->convert( $value, get_class( $this ) );
}

return parent::get_field( $field_name );
return $value ? $value : $default_value;
}

/**
Expand Down

0 comments on commit 3f88ab3

Please sign in to comment.