AnsPress_Category::register_question_categories()

Description #

Register category taxonomy for question cpt.

Changelog #

VersionDescription
2.0Introduced.

Source #

File: addons/free/category.php

	public static function register_question_categories() {
		ap_add_default_options([
			'form_category_orderby'   => 'count',
			'categories_page_order'   => 'DESC',
			'categories_page_orderby' => 'count',
			'category_page_slug'      => 'category',
			'categories_per_page'     => 20,
			'categories_image_height' => 150,
		]);

		/**
		 * Labels for category taxonomy.
		 *
		 * @var array
		 */
		$categories_labels = array(
			'name' 				        => __( 'Question Categories', 'anspress-question-answer' ),
			'singular_name' 	    => __( 'Category', 'anspress-question-answer' ),
			'all_items' 		      => __( 'All Categories', 'anspress-question-answer' ),
			'add_new_item' 		    => __( 'Add New Category', 'anspress-question-answer' ),
			'edit_item' 		      => __( 'Edit Category', 'anspress-question-answer' ),
			'new_item' 			      => __( 'New Category', 'anspress-question-answer' ),
			'view_item' 		      => __( 'View Category', 'anspress-question-answer' ),
			'search_items' 		    => __( 'Search Category', 'anspress-question-answer' ),
			'not_found' 		      => __( 'Nothing Found', 'anspress-question-answer' ),
			'not_found_in_trash'  => __( 'Nothing found in Trash', 'anspress-question-answer' ),
			'parent_item_colon'   => '',
		);

		/**
		 * FILTER: ap_question_category_labels
		 * Filter ic called before registering question_category taxonomy
		 */
		$categories_labels = apply_filters( 'ap_question_category_labels',  $categories_labels );

		/**
		 * Arguments for category taxonomy
		 *
		 * @var array
		 * @since 2.0
		 */
		$category_args = array(
			'hierarchical'       => true,
			'labels'             => $categories_labels,
			'rewrite'            => false,
			'publicly_queryable' => true,
		);

		/**
		 * Filter is called before registering question_category taxonomy.
		 *
		 * @param array $category_args Category arguments.
		 */
		$category_args = apply_filters( 'ap_question_category_args',  $category_args );

		/**
		 * Now let WordPress know about our taxonomy
		 */
		register_taxonomy( 'question_category', [ 'question' ], $category_args );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment