labels->singular_name) ? strtolower($post_type_data->labels->singular_name) : 'post';
$post_taxonomies = get_object_taxonomies(get_post_type());
//add taxonomy
$click_tags_taxonomy = '
';
//add method
$click_tags_methods = ['name' => esc_html__('Name', 'simple-tags'), 'count' => esc_html__('Counter', 'simple-tags'), 'random' => esc_html__('Random', 'simple-tags')];
$click_tags_method = '
';
//add order
$click_tags_orders = ['asc' => esc_html__('Ascending', 'simple-tags'), 'desc' => esc_html__('Descending', 'simple-tags')];
$click_tags_order = '
';
//add limit
$click_tags_limit = '
';
//add searchbox
$click_tags_search = '
';
//create tags search data
$click_tags_options = ''. $click_tags_search.' '.$click_tags_taxonomy.' '.$click_tags_method.' '.$click_tags_order.' '.$click_tags_limit.'
';
//metabox edit line
if (current_user_can('admin_simple_tags')) {
$click_term_edit = '
'. sprintf(
'%s',
add_query_arg(
[
'page' => 'st_suggestterms',
'add' => 'new_item',
'action' => 'edit',
'taxopress_suggestterms' => $click_terms['ID'],
],
admin_url('admin.php')
),
__('Edit this metabox', 'simple-tags')
)
.'
';
} else {
$click_term_edit = '';
}
wp_localize_script(
'st-helper-click-tags',
'stHelperClickTagsL10n',
array(
'show_txt' => esc_html__('Click to display tags', 'simple-tags'),
'arial_label' => esc_html__('suggested terms', 'simple-tags'),
'hide_txt' => sprintf(esc_html__('Click terms to add them to this %s', 'simple-tags'), $post_type_name),
'state' => 'show',
'search_icon' => STAGS_URL . '/assets/images/indicator.gif',
'search_box' => '',
'click_tags_options' => $click_tags_options,
'edit_metabox_link' => $click_term_edit,
)
);
// Helper for post type
wp_enqueue_script('st-helper-click-tags');
}
/**
* Register metabox
*
* @return void
* @author WebFactory Ltd
*/
public static function admin_head()
{
$click_terms = taxopress_current_post_suggest_terms('existing_terms');
if (!is_array($click_terms)) {
return;
}
add_meta_box(
'st-clicks-tags',
__('Show existing terms', 'simple-tags'),
array(
__CLASS__,
'metabox',
),
get_post_type(),
'advanced',
'core'
);
}
/**
* Put default HTML for people without JS
*
* @return void
* @author WebFactory Ltd
*/
public static function metabox()
{
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo SimpleTags_Admin::getDefaultContentBox();
}
/**
* Ajax Dispatcher
*
* @return void
* @author WebFactory Ltd
*/
public static function ajax_check()
{
if (isset($_GET['stags_action']) && 'click_tags' === $_GET['stags_action']) {
self::ajax_click_tags();
}
}
/**
* Display a span list for click tags
*
* @return void
* @author WebFactory Ltd
*/
public static function ajax_click_tags()
{
status_header(200); // Send good header HTTP
header('Content-Type: text/html; charset=' . get_bloginfo('charset'));
$taxonomy = isset($_GET['click_tags_taxonomy']) ? sanitize_text_field($_GET['click_tags_taxonomy']) : 'post_tag';
if (0 === (int) wp_count_terms($taxonomy, array( 'hide_empty' => false ))) { // No tags to suggest
echo '' . esc_html__('No terms in your WordPress database.', 'simple-tags') . '
';
exit();
}
// Prepare search
$search = (isset($_GET['q'])) ? trim(stripslashes(sanitize_text_field($_GET['q']))) : '';
$post_id = (isset($_GET['post_id'])) ? intval($_GET['post_id']) : 0;
if (isset($_GET['click_tags_method']) && !empty($_GET['click_tags_method'])) {
$order_click_tags = (sanitize_text_field($_GET['click_tags_method']) === 'random') ? sanitize_text_field($_GET['click_tags_method']) : sanitize_text_field($_GET['click_tags_method']).'-'.sanitize_text_field($_GET['click_tags_order']);
} else {
// Order tags before selection (count-asc/count-desc/name-asc/name-desc/random)
$order_click_tags = 'random';
}
switch ($order_click_tags) {
case 'count-asc':
$order_by = 'tt.count';
$order = 'ASC';
break;
case 'random':
$order_by = 'RAND()';
$order = '';
break;
case 'count-desc':
$order_by = 'tt.count';
$order = 'DESC';
break;
case 'name-desc':
$order_by = 't.name';
$order = 'DESC';
break;
default: // name-asc
$order_by = 't.name';
$order = 'ASC';
break;
}
$term_limit = isset($_GET['click_tags_limit']) ? (int)$_GET['click_tags_limit'] : 100;
if ($term_limit > 0) {
$limit = 'LIMIT 0, '.$term_limit;
} else {
$limit = '';
}
// Get all terms, or filter with search
$terms = SimpleTags_Admin::getTermsForAjax($taxonomy, $search, $order_by, $order, $limit);
if (empty($terms)) {
echo '' . esc_html__('No results from your WordPress database.', 'simple-tags') . '
';
exit();
}
// Get terms for current post
$post_terms = array();
if ($post_id > 0) {
$post_terms = wp_get_post_terms($post_id, $taxonomy, array( 'fields' => 'ids' ));
}
foreach ((array) $terms as $term) {
$class_current = in_array($term->term_id, $post_terms) ? 'used_term' : '';
echo '' . esc_html(stripslashes($term->name)) . '' . "\n";
}
echo '';
exit();
}
}