public function ap_load_new_tag_form() { if (!wp_verify_nonce($_REQUEST['args'], 'new_tag_form') && ap_user_can_create_tag()) { $result = array('status' => false, 'message' => __('Unable to load form, please try again.', 'ap')); } else { $result = array('status' => true, 'message' => __('Successfully loaded form.', 'ap'), 'html' => ap_tag_form()); } die(json_encode($result)); }
public function ap_suggest_tags() { $keyword = sanitize_text_field($_POST['q']); $tags = get_terms('question_tags', array('orderby' => 'count', 'order' => 'DESC', 'hide_empty' => false, 'search' => $keyword, 'number' => 8)); if ($tags) { $items = array(); foreach ($tags as $k => $t) { $items[$k]['id'] = $t->slug; $items[$k]['name'] = $t->name; $items[$k]['count'] = $t->count; $items[$k]['description'] = ap_truncate_chars($t->description, 80); } $result = array('status' => true, 'items' => $items, 'form' => '<div class="clearfix"></div><div class="ap-cntlabel"><a href="#" id="ap-load-new-tag-form" data-args="' . wp_create_nonce('new_tag_form') . '">' . __('Create new tag', 'ap') . '</a></div>'); } else { $form = ''; if (ap_user_can_create_tag()) { $form = '<div class="ap-esw warning">' . __('No tags found', 'ap') . '</div>' . ap_tag_form(); } $result = array('status' => false, 'message' => __('No related tags found', 'ap'), 'form' => $form); } die(json_encode($result)); }