_get_custom_object_labels

The timeline below displays how wordpress function _get_custom_object_labels has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Builds an object with custom-something object (post type, taxonomy) labels
 * out of a custom-something object
 *
 * @since 3.0.0
 * @access private
 *
 * @param object $data_object             A custom-something object.
 * @param array  $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
 * @return object Object containing labels for the given custom-something object.
 */
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;
}

WordPress Version: 6.1

/**
 * Builds an object with custom-something object (post type, taxonomy) labels
 * out of a custom-something object
 *
 * @since 3.0.0
 * @access private
 *
 * @param object $object                  A custom-something object.
 * @param array  $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
 * @return object Object containing labels for the given custom-something object.
 */
function _get_custom_object_labels($object, $nohier_vs_hier_defaults)
{
    $object->labels = (array) $object->labels;
    if (isset($object->label) && empty($object->labels['name'])) {
        $object->labels['name'] = $object->label;
    }
    if (!isset($object->labels['singular_name']) && isset($object->labels['name'])) {
        $object->labels['singular_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['name_admin_bar'])) {
        $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name;
    }
    if (!isset($object->labels['menu_name']) && isset($object->labels['name'])) {
        $object->labels['menu_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['all_items']) && isset($object->labels['menu_name'])) {
        $object->labels['all_items'] = $object->labels['menu_name'];
    }
    if (!isset($object->labels['archives']) && isset($object->labels['all_items'])) {
        $object->labels['archives'] = $object->labels['all_items'];
    }
    $defaults = array();
    foreach ($nohier_vs_hier_defaults as $key => $value) {
        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    }
    $labels = array_merge($defaults, $object->labels);
    $object->labels = (object) $object->labels;
    return (object) $labels;
}

WordPress Version: 4.4

/**
 * Build an object with custom-something object (post type, taxonomy) labels
 * out of a custom-something object
 *
 * @since 3.0.0
 * @access private
 *
 * @param object $object                  A custom-something object.
 * @param array  $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
 * @return object Object containing labels for the given custom-something object.
 */
function _get_custom_object_labels($object, $nohier_vs_hier_defaults)
{
    $object->labels = (array) $object->labels;
    if (isset($object->label) && empty($object->labels['name'])) {
        $object->labels['name'] = $object->label;
    }
    if (!isset($object->labels['singular_name']) && isset($object->labels['name'])) {
        $object->labels['singular_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['name_admin_bar'])) {
        $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name;
    }
    if (!isset($object->labels['menu_name']) && isset($object->labels['name'])) {
        $object->labels['menu_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['all_items']) && isset($object->labels['menu_name'])) {
        $object->labels['all_items'] = $object->labels['menu_name'];
    }
    if (!isset($object->labels['archives']) && isset($object->labels['all_items'])) {
        $object->labels['archives'] = $object->labels['all_items'];
    }
    $defaults = array();
    foreach ($nohier_vs_hier_defaults as $key => $value) {
        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    }
    $labels = array_merge($defaults, $object->labels);
    $object->labels = (object) $object->labels;
    return (object) $labels;
}

WordPress Version: 4.2

/**
 * Build an object with custom-something object (post type, taxonomy) labels
 * out of a custom-something object
 *
 * @since 3.0.0
 * @access private
 *
 * @param object $object                  A custom-something object.
 * @param array  $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
 */
function _get_custom_object_labels($object, $nohier_vs_hier_defaults)
{
    $object->labels = (array) $object->labels;
    if (isset($object->label) && empty($object->labels['name'])) {
        $object->labels['name'] = $object->label;
    }
    if (!isset($object->labels['singular_name']) && isset($object->labels['name'])) {
        $object->labels['singular_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['name_admin_bar'])) {
        $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name;
    }
    if (!isset($object->labels['menu_name']) && isset($object->labels['name'])) {
        $object->labels['menu_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['all_items']) && isset($object->labels['menu_name'])) {
        $object->labels['all_items'] = $object->labels['menu_name'];
    }
    $defaults = array();
    foreach ($nohier_vs_hier_defaults as $key => $value) {
        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    }
    $labels = array_merge($defaults, $object->labels);
    return (object) $labels;
}

WordPress Version: 4.0

/**
 * Build an object with custom-something object (post type, taxonomy) labels
 * out of a custom-something object
 *
 * @since 3.0.0
 * @access private
 *
 * @param object $object                  A custom-something object.
 * @param array  $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels.
 */
function _get_custom_object_labels($object, $nohier_vs_hier_defaults)
{
    $object->labels = (array) $object->labels;
    if (isset($object->label) && empty($object->labels['name'])) {
        $object->labels['name'] = $object->label;
    }
    if (!isset($object->labels['singular_name']) && isset($object->labels['name'])) {
        $object->labels['singular_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['name_admin_bar'])) {
        $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name;
    }
    if (!isset($object->labels['menu_name']) && isset($object->labels['name'])) {
        $object->labels['menu_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['all_items']) && isset($object->labels['menu_name'])) {
        $object->labels['all_items'] = $object->labels['menu_name'];
    }
    foreach ($nohier_vs_hier_defaults as $key => $value) {
        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    }
    $labels = array_merge($defaults, $object->labels);
    return (object) $labels;
}

WordPress Version: 3.7

/**
 * Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
 *
 * @access private
 * @since 3.0.0
 */
function _get_custom_object_labels($object, $nohier_vs_hier_defaults)
{
    $object->labels = (array) $object->labels;
    if (isset($object->label) && empty($object->labels['name'])) {
        $object->labels['name'] = $object->label;
    }
    if (!isset($object->labels['singular_name']) && isset($object->labels['name'])) {
        $object->labels['singular_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['name_admin_bar'])) {
        $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name;
    }
    if (!isset($object->labels['menu_name']) && isset($object->labels['name'])) {
        $object->labels['menu_name'] = $object->labels['name'];
    }
    if (!isset($object->labels['all_items']) && isset($object->labels['menu_name'])) {
        $object->labels['all_items'] = $object->labels['menu_name'];
    }
    foreach ($nohier_vs_hier_defaults as $key => $value) {
        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    }
    $labels = array_merge($defaults, $object->labels);
    return (object) $labels;
}