AnsPress_PostTypes::register_question_cpt()

Description #

Register question CPT.

Changelog #

VersionDescription
2.0.1Introduced.

Source #

File: includes/post-types.php

	public static function register_question_cpt() {
		add_rewrite_tag( '%question_id%', '([0-9]+)', 'post_type=question&p=' );
		add_rewrite_tag( '%question%', '([^/]+)' );

		// Question CPT labels.
		$labels = array(
			'name'               => _x( 'Questions', 'Post Type General Name', 'anspress-question-answer' ),
			'singular_name'      => _x( 'Question', 'Post Type Singular Name', 'anspress-question-answer' ),
			'menu_name'          => __( 'Questions', 'anspress-question-answer' ),
			'parent_item_colon'  => __( 'Parent question:', 'anspress-question-answer' ),
			'all_items'          => __( 'All questions', 'anspress-question-answer' ),
			'view_item'          => __( 'View question', 'anspress-question-answer' ),
			'add_new_item'       => __( 'Add new question', 'anspress-question-answer' ),
			'add_new'            => __( 'New question', 'anspress-question-answer' ),
			'edit_item'          => __( 'Edit question', 'anspress-question-answer' ),
			'update_item'        => __( 'Update question', 'anspress-question-answer' ),
			'search_items'       => __( 'Search questions', 'anspress-question-answer' ),
			'not_found'          => __( 'No question found', 'anspress-question-answer' ),
			'not_found_in_trash' => __( 'No questions found in trash', 'anspress-question-answer' ),
		);

		/**
		 * Override default question CPT labels.
		 *
		 * @param array $labels Default question labels.
		 */
		$labels = apply_filters( 'ap_question_cpt_labels', $labels );

		// Question CPT arguments.
		$args = array(
			'label'               => __( 'question', 'anspress-question-answer' ),
			'description'         => __( 'Question', 'anspress-question-answer' ),
			'labels'              => $labels,
			'supports'            => array(
				'title',
				'editor',
				'author',
				'comments',
				'excerpt',
				'trackbacks',
				'revisions',
				'custom-fields',
				'buddypress-activity',
			),
			'hierarchical'        => false,
			'public'              => true,
			'show_ui'             => true,
			'show_in_menu'        => false,
			'show_in_nav_menus'   => false,
			'show_in_admin_bar'   => true,
			'menu_icon'           => ANSPRESS_URL . 'assets/question.png',
			'can_export'          => true,
			'has_archive'         => true,
			'exclude_from_search' => true,
			'publicly_queryable'  => true,
			'capability_type'     => 'post',
			'rewrite'             => false,
			'query_var'           => 'question',
			'delete_with_user'    => true,
		);

		/**
		 * Filter default question CPT arguments.
		 *
		 * @param array $args CPT arguments.
		 */
		$args = apply_filters( 'ap_question_cpt_args', $args );

		// Call it before registering cpt.
		AnsPress_Rewrite::rewrite_rules();

		// Register CPT question.
		register_post_type( 'question', $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