term_relationships.' AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN '.$wpdb->posts.' AS p ON p.ID = r.object_id'; $clauses['where'] .= ' AND p.post_type IN ('.implode(',', $post_types).')'; $clauses['orderby'] = 'GROUP BY t.term_id '.$clauses['orderby']; } } return $clauses; } /** * Init somes JS and CSS need for this feature * * @return void * @author Olatechpro */ public static function admin_enqueue_scripts() { // add JS for manage click tags if (isset($_GET['page']) && $_GET['page'] == 'st_terms') { wp_enqueue_style('st-taxonomies-css'); wp_enqueue_script( 'admin-tags' ); wp_enqueue_script('inline-edit-tax'); } } public function taxopress_terms_inline_save_term_callback() { global $wpdb; check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); $edit_taxonomy = sanitize_key( $_POST['edit_taxonomy'] ); $taxonomy = sanitize_key( $_POST['original_tax'] ); $tax = get_taxonomy( $taxonomy ); $edit_tax = get_taxonomy( $edit_taxonomy ); if ( ! $tax || !$edit_tax ) { wp_die( 0 ); } if ( ! isset( $_POST['tax_ID'] ) || ! (int) $_POST['tax_ID'] ) { wp_die( -1 ); } $id = (int) $_POST['tax_ID']; if ( ! current_user_can( 'edit_term', $id ) ) { wp_die( -1 ); } $tag = get_term( $id, $taxonomy ); $_POST['description'] = $tag->description; $updated = wp_update_term( $id, $taxonomy, $_POST ); if ( $updated && ! is_wp_error( $updated ) ) { $tag = get_term( $updated['term_id'], $taxonomy ); if ( ! $tag || is_wp_error( $tag ) ) { if ( is_wp_error( $tag ) && $tag->get_error_message() ) { wp_die( esc_html($tag->get_error_message()) ); } wp_die( esc_html__( 'Item not updated.' ) ); } else { if($tax !== $edit_tax){ $update_term = $wpdb->update( $wpdb->prefix . 'term_taxonomy', [ 'taxonomy' => $edit_taxonomy ], [ 'term_taxonomy_id' => $tag->term_id ], [ '%s' ], [ '%d' ] ); if($update_term){ clean_term_cache($tag->term_id); $tag = get_term( $tag->term_id ); } } } } else { if ( is_wp_error( $updated ) && $updated->get_error_message() ) { wp_die( esc_html($updated->get_error_message()) ); } wp_die( esc_html__( 'Item not updated.' ) ); } $wp_list_table = new Taxopress_Terms_List(); $wp_list_table->single_row($tag); wp_die(); } 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__('Terms', 'simple-tags'), esc_html__('Terms', 'simple-tags'), 'simple_tags', 'st_terms', [ $this, 'page_manage_terms', ] ); 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_terms_per_page' ]; add_screen_option($option, $args); $this->terms_table = new Taxopress_Terms_List(); } /** * Method for build the page HTML manage tags * * @return void * @author Olatechpro */ public function page_manage_terms() { // Default order if (!isset($_GET['order'])) { $_GET['order'] = 'name-asc'; } settings_errors(__CLASS__); ?>