<?php
/**
 * Custom taxonomy for topic in posts
 *
 * Author: Gian MR - http://www.gianmr.com
 *
 * @since 1.0.0
 * @package Majalahpro Core
 */

/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'majalah_core_create_post_tax' ) ) {
	/**
	 * Add new taxonomy in post
	 *
	 * @since 1.0.0
	 * @return void
	 */
	function majalah_core_create_post_tax() {
		/* Add new taxonomy, NOT hierarchical (like tags) */
		$labels = array(
			'name'                       => _x( 'Topics', 'taxonomy general name', 'majalahpro-core' ),
			'singular_name'              => _x( 'Topic', 'taxonomy singular name', 'majalahpro-core' ),
			'search_items'               => __( 'Search Topics', 'majalahpro-core' ),
			'popular_items'              => __( 'Popular Topics', 'majalahpro-core' ),
			'all_items'                  => __( 'All Topics', 'majalahpro-core' ),
			'parent_item'                => null,
			'parent_item_colon'          => null,
			'edit_item'                  => __( 'Edit Topic', 'majalahpro-core' ),
			'update_item'                => __( 'Update Topic', 'majalahpro-core' ),
			'add_new_item'               => __( 'Add New Topic', 'majalahpro-core' ),
			'new_item_name'              => __( 'New Topic Name', 'majalahpro-core' ),
			'separate_items_with_commas' => __( 'Separate topics with commas', 'majalahpro-core' ),
			'add_or_remove_items'        => __( 'Add or remove topics', 'majalahpro-core' ),
			'choose_from_most_used'      => __( 'Choose from the most used topics', 'majalahpro-core' ),
			'not_found'                  => __( 'No topics found.', 'majalahpro-core' ),
			'menu_name'                  => __( 'Topics', 'majalahpro-core' ),
		);

		$args = array(
			'hierarchical'          => false,
			'labels'                => $labels,
			'show_ui'               => true,
			'show_in_rest'          => true,
			'update_count_callback' => '_update_post_term_count',
			'query_var'             => true,
			'rewrite'               => array( 'slug' => 'topic' ),
		);
		register_taxonomy( 'newstopic', array( 'post' ), $args );

		unset( $args );
		unset( $labels );
	}
}
add_action( 'init', 'majalah_core_create_post_tax', 0 );
