wpseek.com
A WordPress-centric search engine for devs and theme authors



_get_custom_object_labels › WordPress Function

Since3.0.0
Deprecatedn/a
_get_custom_object_labels ( $data_object, $nohier_vs_hier_defaults )
Access:
  • private
Parameters: (2)
  • (object) $data_object A custom-something object.
    Required: Yes
  • (array) $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
    Required: Yes
Returns:
  • (object) Object containing labels for the given custom-something object.
Defined at:
Codex:

Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object



Source

function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
	$data_object->labels = (array) $data_object->labels;

	if ( isset( $data_object->label ) && empty( $data_object->labels['name'] ) ) {
		$data_object->labels['name'] = $data_object->label;
	}

	if ( ! isset( $data_object->labels['singular_name'] ) && isset( $data_object->labels['name'] ) ) {
		$data_object->labels['singular_name'] = $data_object->labels['name'];
	}

	if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
		$data_object->labels['name_admin_bar'] =
			isset( $data_object->labels['singular_name'] )
			? $data_object->labels['singular_name']
			: $data_object->name;
	}

	if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
		$data_object->labels['menu_name'] = $data_object->labels['name'];
	}

	if ( ! isset( $data_object->labels['all_items'] ) && isset( $data_object->labels['menu_name'] ) ) {
		$data_object->labels['all_items'] = $data_object->labels['menu_name'];
	}

	if ( ! isset( $data_object->labels['archives'] ) && isset( $data_object->labels['all_items'] ) ) {
		$data_object->labels['archives'] = $data_object->labels['all_items'];
	}

	$defaults = array();
	foreach ( $nohier_vs_hier_defaults as $key => $value ) {
		$defaults[ $key ] = $data_object->hierarchical ? $value[1] : $value[0];
	}

	$labels              = array_merge( $defaults, $data_object->labels );
	$data_object->labels = (object) $data_object->labels;

	return (object) $labels;
}