$rows
* @param callable|null $debugInfoWriter Receives debug text while rendering large option sets.
* @return string
*/
public function buildPostOptions(string $dest, array $rows, ?callable $debugInfoWriter = null): string {
$content = array();
$rowCounter = 0;
$currentPostType = '';
foreach ($rows as $row) {
$rowCounter++;
/** @var object{id: int|string, post_type: string, depth?: int} $row */
$id = is_scalar($row->id) ? (string)$row->id : '';
$titleId = is_numeric($id) ? (int)$id : 0;
$theTitle = get_the_title($titleId);
$thisval = $id . "|" . ABJ404_TYPE_POST;
if ($debugInfoWriter !== null) {
$debugInfoWriter('Before row: ' . $rowCounter . ', Title: ' . $theTitle .
', Post type: ' . $row->post_type);
}
if ($row->post_type != $currentPostType) {
if ($currentPostType != '') {
$content[] = "\n" . '' . "\n";
}
$postTypeLabel = $this->postTypeLabel((string)$row->post_type);
$content[] = "\n" . '' . "\n";
}
if ($debugInfoWriter !== null) {
$debugInfoWriter('Cleared after building redirect destination page list.');
}
return implode('', $content);
}
/**
* @param string $dest
* @param array $categories
* @param array $tags
* @param array> $customCategories
* @return string
*/
public function buildTaxonomyOptions(string $dest, array $categories, array $tags, array $customCategories): string {
$content = "";
$content .= "\n" . '' . "\n";
$content .= "\n" . '' . "\n";
foreach ($customCategories as $taxonomy => $catRow) {
$content .= "\n" . '' . "\n";
}
return $content;
}
/**
* @param string $id
* @param int $type
* @param string $label
* @param string $title
* @param string $dest
* @return string
*/
private function buildTaxonomyOption(string $id, int $type, string $label, string $title, string $dest): string {
$thisval = $id . "|" . $type;
$selected = ($thisval == $dest) ? " selected" : "";
return "\n";
}
private function postTypeLabel(string $postType): string {
if (function_exists('get_post_type_object')) {
$postTypeObject = get_post_type_object($postType);
if (is_object($postTypeObject) && property_exists($postTypeObject, 'labels') && is_object($postTypeObject->labels)) {
$labels = $postTypeObject->labels;
$label = $labels->singular_name ?? $labels->name ?? '';
if (is_scalar($label) && (string)$label !== '') {
return (string)$label;
}
}
}
return ucwords(str_replace(array('_', '-'), ' ', $postType));
}
}