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' => __( 'Name', 'simple-tags' ), 'count' => __( 'Counter', 'simple-tags' ), 'random' => __( 'Random', 'simple-tags' )]; $click_tags_method = '

'; //add order $click_tags_orders = ['asc' => __( 'Ascending', 'simple-tags' ), 'desc' => __( '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.'
'; wp_localize_script( 'st-helper-click-tags', 'stHelperClickTagsL10n', array( 'show_txt' => __( 'Click to display tags', 'simple-tags' ), 'hide_txt' => sprintf( __( '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, ) ); // 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(true); 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() { 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']) ? $_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( $_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 = ($_GET['click_tags_method'] === 'random') ? $_GET['click_tags_method'] : $_GET['click_tags_method'].'-'.$_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']) ? $_GET['click_tags_limit'] : 100; $limit = 'LIMIT 0, '.$term_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, true ) ? 'used_term' : ''; echo '' . esc_html( stripslashes( $term->name ) ) . '' . "\n"; } echo '
'; exit(); } }