diff --git a/generators/app/templates/gulp/templatesFunctions.js b/generators/app/templates/gulp/templatesFunctions.js index 74d7dde5..2263a5ca 100644 --- a/generators/app/templates/gulp/templatesFunctions.js +++ b/generators/app/templates/gulp/templatesFunctions.js @@ -40,8 +40,14 @@ module.exports = function templateFunctions(data = {}) { } const classes = [name]; let el; - for (let i = 0; i < args.length; i += 1) { - el = args[i]; + let modifiers; + if(args[0] instanceof Array) { + modifiers = args[0]; + } else { + modifiers = args; + } + for (let i = 0; i < modifiers.length; i += 1) { + el = modifiers[i]; if (el && typeof el === 'string') { classes.push(`${name}--${el}`); } diff --git a/generators/wp/templates/chisel-starter-theme/Chisel/Extensions/ChiselTwig.php b/generators/wp/templates/chisel-starter-theme/Chisel/Extensions/ChiselTwig.php index e43ec7a5..659cfc2a 100644 --- a/generators/wp/templates/chisel-starter-theme/Chisel/Extensions/ChiselTwig.php +++ b/generators/wp/templates/chisel-starter-theme/Chisel/Extensions/ChiselTwig.php @@ -145,7 +145,9 @@ public function className( $name = '', $modifiers = null ) { if ( ! is_string( $name ) || empty( $name ) ) { return ''; } - $modifiers = array_slice( func_get_args(), 1 ); + if ( ! is_array( $modifiers ) ) { + $modifiers = array_slice( func_get_args(), 1 ); + } $classes = array( $name ); foreach ( $modifiers as $modifier ) { if ( is_string( $modifier ) && ! empty( $modifier ) ) { diff --git a/generators/wp/templates/chisel-starter-theme/Chisel/Post.php b/generators/wp/templates/chisel-starter-theme/Chisel/Post.php index 9b9cdcad..e9483e56 100644 --- a/generators/wp/templates/chisel-starter-theme/Chisel/Post.php +++ b/generators/wp/templates/chisel-starter-theme/Chisel/Post.php @@ -49,15 +49,19 @@ 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 ); } - return parent::get_field( $field_name ); + return $value ? $value : $default_value; } /** @@ -69,4 +73,29 @@ public function get_field( $field_name ) { public static function overrideTimberPostClass() { return '\Chisel\Post'; } + + /** + * @param string $field_name + * + * @return mixed + */ + private function _get_field( $field_name ) { + if ( $rd = $this->get_revised_data_from_method( 'get_field', $field_name ) ) { + return $rd; + } + $value = apply_filters( 'timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this ); + if ( $value === null ) { + $value = get_post_meta( $this->ID, $field_name ); + if ( is_array( $value ) && count( $value ) == 1 ) { + $value = $value[0]; + } + if ( is_array( $value ) && count( $value ) == 0 ) { + $value = null; + } + } + $value = apply_filters( 'timber_post_get_meta_field', $value, $this->ID, $field_name, $this ); + $value = $this->convert( $value, get_class( $this ) ); + + return $value; + } }