Example #1
0
/**
 * Populate properties array.
 *
 * @param  array|object $properties
 *
 * @return array
 */
function papi_populate_properties($properties)
{
    if (!is_array($properties) && !is_object($properties) || empty($properties)) {
        return [];
    }
    if (is_object($properties)) {
        return [$properties];
    }
    $results = [];
    // Get the box property (when you only put a array in the box method) if it exists.
    $properties = papi_get_box_property($properties);
    // Convert all non property objects to property objects.
    $properties = array_map(function ($property) {
        if (!is_object($property) && is_array($property) && !isset($property['tab'])) {
            return papi_get_property_options($property);
        }
        return $property;
    }, $properties);
    // Fix so the properties array will have the right order.
    $properties = array_reverse($properties);
    foreach ($properties as $property) {
        if (isset($property->tab) && $property->tab) {
            $results[] = $property;
            continue;
        }
        $results[] = $property;
    }
    if (empty($results) || isset($results[0]->tab) && $results[0]->tab) {
        return $results;
    }
    return papi_sort_order($results);
}
Example #2
0
		<?php 
    $boxes = $page_type->get_boxes();
    if (empty($boxes)) {
        echo sprintf('<p>%s</p>', esc_html__('No meta boxes exists.', 'papi'));
        return;
    }
    foreach ($boxes as $box) {
        $tab = isset($box[1]) && isset($box[1][0]) && isset($box[1][0]->tab) && $box[1][0]->tab;
        $top_right_text = __('Properties', 'papi');
        if ($tab) {
            $top_right_text = __('Tabs', 'papi');
        }
        if (!isset($box['title']) || empty($box['title'])) {
            continue;
        }
        $counter = count(papi_get_box_property($box[1]));
        ?>
			<div class="postbox papi-box papi-management-box">
				<div class="handlediv" title="Click to toggle">
					<br>
				</div>
				<h3 class="hndle">
					<span><?php 
        echo esc_html($box['title']);
        ?>
</span>
					<span class="papi-pull-right"><?php 
        echo esc_html($top_right_text . ': ') . strval($counter);
        ?>
</span>
				</h3>