Skip to content

Commit

Permalink
Refactor handling for template parts and custom templates
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Mar 18, 2021
1 parent 3b97eff commit 255e734
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,22 +1052,19 @@ public function get_settings() {
* @return array
*/
public function get_custom_templates() {
$custom_templates = array();
if ( ! isset( $this->theme_json['customTemplates'] ) ) {
return array();
} else {
return array_reduce(
$this->theme_json['customTemplates'],
function( $accumulator, $item ) {
if ( isset( $item['name'] ) ) {
$name = $item['name'];
unset( $item['name'] );
$accumulator[ $name ] = $item;
}
return $accumulator;
},
array()
);
return $custom_templates;
}

foreach ( $this->theme_json['customTemplates'] as $item ) {
if ( isset( $item['name'] ) ) {
$custom_templates[ $item['name'] ] = array(
'title' => isset( $item['title'] ) ? $item['title'] : '',
);
}
}
return $custom_templates;
}

/**
Expand All @@ -1076,21 +1073,19 @@ function( $accumulator, $item ) {
* @return array
*/
public function get_template_parts() {
$template_parts = array();
if ( ! isset( $this->theme_json['templateParts'] ) ) {
return array();
return $template_parts;
}
return array_reduce(
$this->theme_json['templateParts'],
function( $accumulator, $item ) {
if ( isset( $item['name'] ) ) {
$name = $item['name'];
unset( $item['name'] );
$accumulator[ $name ] = $item;
}
return $accumulator;
},
array()
);

foreach ( $this->theme_json['templateParts'] as $item ) {
if ( isset( $item['name'] ) ) {
$template_parts[ $item['name'] ] = array(
'area' => isset( $item['area'] ) ? $item['area'] : '',
);
}
}
return $template_parts;
}

/**
Expand Down

0 comments on commit 255e734

Please sign in to comment.