Skip to content

Commit

Permalink
Template part 'area' term - reword confusing 'type' terminology (#29679)
Browse files Browse the repository at this point in the history
* reword confusing 'type' terminology

* rename get areas function

* rename hook string to be consistent
  • Loading branch information
Addison-Stavlo authored Mar 9, 2021
1 parent 654eb21 commit 390e2ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/full-site-editing/block-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function _gutenberg_add_template_part_area_info( $template_info ) {
}

if ( isset( $theme_data[ $template_info['slug'] ]['area'] ) ) {
$template_info['area'] = gutenberg_filter_template_part_area_type( $theme_data[ $template_info['slug'] ]['area'] );
$template_info['area'] = gutenberg_filter_template_part_area( $theme_data[ $template_info['slug'] ]['area'] );
} else {
$template_info['area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/full-site-editing/class-wp-rest-templates-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ protected function prepare_item_for_database( $request ) {

if ( 'wp_template_part' === $this->post_type ) {
if ( isset( $request['area'] ) ) {
$changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area_type( $request['area'] );
$changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area( $request['area'] );
} elseif ( null !== $template && ! $template->is_custom && $template->area ) {
$changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area_type( $template->area );
$changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area( $template->area );
} elseif ( ! $template->area ) {
$changes->tax_input['wp_template_part_area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/full-site-editing/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,41 +163,41 @@ function set_unique_slug_on_create_template_part( $post_id ) {
add_action( 'save_post_wp_template_part', 'set_unique_slug_on_create_template_part' );

/**
* Returns a filtered list of allowed area types for template parts.
* Returns a filtered list of allowed area values for template parts.
*
* @return array The supported template part area types.
* @return array The supported template part area values.
*/
function gutenberg_get_allowed_template_part_area_types() {
$default_area_types = array(
function gutenberg_get_allowed_template_part_areas() {
$default_area_values = array(
WP_TEMPLATE_PART_AREA_HEADER,
WP_TEMPLATE_PART_AREA_FOOTER,
WP_TEMPLATE_PART_AREA_SIDEBAR,
WP_TEMPLATE_PART_AREA_UNCATEGORIZED,
);

/**
* Filters the list of allowed template part area types.
* Filters the list of allowed template part area values.
*
* @param array $default_area_types An array of supported area types.
* @param array $default_area_values An array of supported area values.
*/
return apply_filters( 'default_wp_template_part_area_types', $default_area_types );
return apply_filters( 'default_wp_template_part_areas', $default_area_values );
}

/**
* Checks whether the input 'type' is a supported area type.
* Returns the input if supported, otherwise returns the 'other' type.
* Checks whether the input 'area' is a supported value.
* Returns the input if supported, otherwise returns the 'uncategorized' value.
*
* @param string $type Template part area name.
*
* @return string Input if supported, else 'other'.
* @return string Input if supported, else the uncategorized value.
*/
function gutenberg_filter_template_part_area_type( $type ) {
if ( in_array( $type, gutenberg_get_allowed_template_part_area_types(), true ) ) {
function gutenberg_filter_template_part_area( $type ) {
if ( in_array( $type, gutenberg_get_allowed_template_part_areas(), true ) ) {
return $type;
}

/* translators: %1$s: Template area type, %2$s: the uncategorized template area type. */
$warning_message = sprintf( __( '"%1$s" is not a supported wp_template_part_area type and has been added as "%2$s".', 'gutenberg' ), $type, WP_TEMPLATE_PART_AREA_UNCATEGORIZED );
/* translators: %1$s: Template area type, %2$s: the uncategorized template area value. */
$warning_message = sprintf( __( '"%1$s" is not a supported wp_template_part area value and has been added as "%2$s".', 'gutenberg' ), $type, WP_TEMPLATE_PART_AREA_UNCATEGORIZED );
trigger_error( $warning_message, E_USER_NOTICE );
return WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
}

0 comments on commit 390e2ac

Please sign in to comment.