public get_terms_for_site ( integer $site_id ) : array | ||
$site_id | integer | Blog ID. |
return | array |
public function get_terms_for_site($site_id)
{
$out = [];
switch_to_blog($site_id);
$taxonomy_object = get_taxonomy($this->taxonomy_name);
if (!current_user_can($taxonomy_object->cap->edit_terms)) {
$terms = [];
} else {
$terms = get_terms($this->taxonomy_name, ['hide_empty' => FALSE]);
}
foreach ($terms as $term) {
if (is_taxonomy_hierarchical($this->taxonomy_name)) {
$ancestors = get_ancestors($term->term_id, $this->taxonomy_name);
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
$parent_term = get_term($ancestor, $this->taxonomy_name);
$term->name = $parent_term->name . '/' . $term->name;
}
}
}
$out[$term->term_taxonomy_id] = esc_html($term->name);
}
restore_current_blog();
uasort($out, 'strcasecmp');
return $out;
}
/** * @return bool */ public function print_table() { if (empty($this->related_sites)) { return FALSE; } print $this->presenter->get_nonce_field(); $this->print_style(); ?> <table class="mlp_term_selections"> <?php foreach ($this->related_sites as $site_id => $language) { $key = $this->presenter->get_key_base($site_id); $label_id = $this->get_label_id($key); $terms = $this->presenter->get_terms_for_site($site_id); ?> <tr> <th> <label for="<?php print $label_id; ?> "><?php print $language; ?> </label> </th> <td> <?php if (empty($terms)) { print $this->get_no_terms_found_message($site_id); } else { ?> <select name="<?php print $key; ?> " id="<?php print $label_id; ?> "> <option value="0" class="mlp_empty_option"><?php esc_html_e('No translation', 'multilingualpress'); ?> </option> <?php $this->print_term_options($site_id, $terms); ?> </select> <?php } ?> </td> </tr> <?php } ?> </table> <?php return TRUE; }