Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

74
inc/functions/sort.php Normal file
View File

@ -0,0 +1,74 @@
<?php
/**
* Sort Helper Functions
*
* @package WP_Ultimo\Functions
* @since 2.0.11
*/
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* Sort arrays based on a particular column.
*
* @since 2.0.0
*
* @param array $a The first array.
* @param array $b The second array.
* @param string $column The column to compare.
* @return int
*/
function wu_sort_by_column($a, $b, $column = 'order') {
$a[$column] = isset($a[$column]) ? (int) $a[$column] : 50;
$b[$column] = isset($b[$column]) ? (int) $b[$column] : 50;
return $a[$column] - $b[$column];
} // end wu_sort_by_column;
/**
* Sorts the fields.
*
* @param array $a The first array containing a order key.
* @param array $b The second array containing a order key.
* @return int
*/
function wu_sort_by_order($a, $b) {
return wu_sort_by_column($a, $b, 'order');
} // end wu_sort_by_order;
/**
* Loops through the list items and adds a order key if none is set, based on the index.
*
* @since 2.0.7
*
* @param array $list The list of sortable elements.
* @param string $order_key The order key.
* @return array
*/
function wu_set_order_from_index($list, $order_key = 'order') {
$index = 1;
foreach ($list as &$item) {
if (isset($item[$order_key]) === false) {
$index = $index ? $index : 1; // phpcs:ignore
$item[$order_key] = $index * 10;
$index++;
} // end if;
} // end foreach;
return $list;
} // end wu_set_order_from_index;