true]);
$public = get_taxonomies([
'_builtin' => false,
'public' => true,
]);
$private = get_taxonomies([
'_builtin' => false,
'public' => false,
]);
$registered_taxonomies = array_merge($core, $public, $private);
wp_localize_script(
'st-taxonomies',
'taxopress_tax_data',
[
'confirm' => esc_html__(
'Are you sure you want to delete this? Deleting will NOT remove created content.',
'simple-tags'
),
'no_associated_type' => esc_html__('Please select at least one post type.', 'simple-tags'),
'existing_taxonomies' => $registered_taxonomies,
'integer_error' => esc_html__('Taxonomy slug cannot be numbers only.', 'simple-tags'),
]
);
}
}
public static function set_screen($status, $option, $value)
{
return $value;
}
/** Singleton instance */
public static function get_instance()
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Add WP admin menu for Tags
*
* @return void
* @author Olatechpro
*/
public function admin_menu()
{
$hook = add_submenu_page(
self::MENU_SLUG,
esc_html__('Taxonomies', 'simple-tags'),
esc_html__('Taxonomies', 'simple-tags'),
'simple_tags',
'st_taxonomies',
[
$this,
'page_manage_taxonomies',
]
);
if (taxopress_is_screen_main_page()) {
add_action("load-$hook", [$this, 'screen_option']);
}
}
/**
* Screen options
*/
public function screen_option()
{
$option = 'per_page';
$args = [
'label' => esc_html__('Number of items per page', 'simple-tags'),
'default' => 20,
'option' => 'st_taxonomies_per_page'
];
add_screen_option($option, $args);
$this->terms_table = new Taxonomy_List();
}
/**
* Method for build the page HTML manage tags
*
* @return void
* @author Olatechpro
*/
public function page_manage_taxonomies()
{
// Default order
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading non-state-modifying GET parameter for default value
if (!isset($_GET['order'])) {
$_GET['order'] = 'name-asc';
}
settings_errors(__CLASS__);
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading non-state-modifying GET parameter for page display
if (!isset($_GET['add'])) {
//all tax
?>
' . esc_html__(
'Search results for “%s”',
'simple-tags'
) . '', esc_html($search));
}
?>
terms_table->prepare_items();
?>
true,
),
'objects'
);
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading non-state-modifying GET parameter for filter display
$selected_post_type = isset($_GET['taxopress_taxonomy_post_type'])
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
? sanitize_key(wp_unslash($_GET['taxopress_taxonomy_post_type']))
: 'all';
?>
taxopress_manage_taxonomies();
echo '
';
}
} ?>
esc_html__('Invalid nonce. Request is not authorized.', 'simple-tags')), 403);
}
$taxonomy_object = get_taxonomy($taxonomy);
if (
!current_user_can('simple_tags')
|| !$taxonomy_object
|| empty($taxonomy_object->cap->assign_terms)
|| !current_user_can($taxonomy_object->cap->assign_terms)
) {
wp_send_json_error(array('message' => esc_html__('You do not have permission to view terms in this taxonomy.', 'simple-tags')), 403);
}
$args = array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'number' => $per_page,
'offset' => ($page - 1) * $per_page,
'search' => $search_term,
'orderby' => 'name',
'order' => 'ASC',
);
$terms = get_terms($args);
if (is_wp_error($terms)) {
wp_send_json_error(array('message' => esc_html__('Unable to retrieve terms for this taxonomy.', 'simple-tags')), 400);
}
$count_args = $args;
unset($count_args['number'], $count_args['offset']);
$total_terms = wp_count_terms($count_args);
if (is_wp_error($total_terms)) {
$total_terms = 0;
}
$context = isset($_GET['context']) ? sanitize_text_field(wp_unslash($_GET['context'])) : '';
$show_slug = (
'mass_edit' === $context
&& (int) SimpleTags_Plugin::get_option_value('enable_mass-edit_terms_slug') === 1
);
$results = array();
foreach ($terms as $term) {
$text = $term->name;
if ($show_slug) {
$text = sprintf('%s (%s)', $term->name, $term->slug);
}
$results[] = array(
'id' => $term->slug,
'text' => $text,
);
}
wp_send_json(array(
'items' => $results,
'more' => ($page * $per_page < $total_terms),
));
}
/**
* Create our settings page output.
*
* @internal
*/
public function taxopress_manage_taxonomies()
{
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new';
$tab_class = 'taxopress-' . $tab;
$current = null;
?>
$request_tax], 'objects');
if (isset($external_taxonomy) > 0) {
$current = taxopress_convert_external_taxonomy(
$external_taxonomy[$request_tax],
$request_tax
);
$external_edit = true;
$taxonomy_edit = true;
}
}
if ($request_tax === 'media_tag') {
$external_edit = false;
}
}
if ($taxonomy_edit) {
$wordpress_core_tax = array_keys(get_taxonomies(['_builtin' => true]));
$wordpress_core_tax[] = 'post_tag';
$wordpress_core_tax[] = 'category';
if (in_array($current['name'], $wordpress_core_tax)) {
$core_edit = true;
}
}
$ui = new taxopress_admin_ui();
?>