bbp_form_slug_conflict_check( string $slug, string $default )

Used to check if a Forums slug conflicts with an existing known slug.

Description

Parameters

$slug

(Required)

$default

(Required)

Source

File: bp-forums/admin/settings.php

function bbp_form_slug_conflict_check( $slug, $default ) {

	// Only set the slugs once ver page load
	static $the_core_slugs = array();

	// Get the form value
	$this_slug = bbp_get_form_option( $slug, $default, true );

	if ( empty( $the_core_slugs ) ) {

		// Slugs to check
		$core_slugs = apply_filters( 'bbp_slug_conflict_check', array(

			/** WordPress Core ****************************************************/

			// Core Post Types
			'post_base'       => array( 'name' => __( 'Posts',         'buddyboss' ), 'default' => 'post',          'context' => 'WordPress' ),
			'page_base'       => array( 'name' => __( 'Pages',         'buddyboss' ), 'default' => 'page',          'context' => 'WordPress' ),
			'revision_base'   => array( 'name' => __( 'Revisions',     'buddyboss' ), 'default' => 'revision',      'context' => 'WordPress' ),
			'attachment_base' => array( 'name' => __( 'Attachments',   'buddyboss' ), 'default' => 'attachment',    'context' => 'WordPress' ),
			'nav_menu_base'   => array( 'name' => __( 'Menus',         'buddyboss' ), 'default' => 'nav_menu_item', 'context' => 'WordPress' ),

			// Post Tags
			'tag_base'        => array( 'name' => __( 'Tag base',      'buddyboss' ), 'default' => 'tag',           'context' => 'WordPress' ),

			// Post Categories
			'category_base'   => array( 'name' => __( 'Category base', 'buddyboss' ), 'default' => 'category',      'context' => 'WordPress' ),

			/** Forums Core ******************************************************/

			// Forum archive slug
			'_bbp_root_slug'          => array( 'name' => __( 'Forums base', 'buddyboss' ), 'default' => 'forums', 'context' => 'Forums' ),

			// Topic archive slug
			'_bbp_topic_archive_slug' => array( 'name' => __( 'Discussions base', 'buddyboss' ), 'default' => 'discussions', 'context' => 'Forums' ),

			// Forum slug
			'_bbp_forum_slug'         => array( 'name' => __( 'Forum slug',  'buddyboss' ), 'default' => 'forum',  'context' => 'Forums' ),

			// Topic slug
			'_bbp_topic_slug'         => array( 'name' => __( 'Discussion slug',  'buddyboss' ), 'default' => 'discussion',  'context' => 'Forums' ),

			// Reply slug
			'_bbp_reply_slug'         => array( 'name' => __( 'Reply slug',  'buddyboss' ), 'default' => 'reply',  'context' => 'Forums' ),

			// User profile slug
			'_bbp_user_slug'          => array( 'name' => __( 'User base',   'buddyboss' ), 'default' => 'users',  'context' => 'Forums' ),

			// View slug
			'_bbp_view_slug'          => array( 'name' => __( 'View base',   'buddyboss' ), 'default' => 'view',   'context' => 'Forums' ),

			// Topic tag slug
			'_bbp_topic_tag_slug'     => array( 'name' => __( 'Discussion tag slug', 'buddyboss' ), 'default' => 'discussion-tag', 'context' => 'Forums' ),
		) );

		/** BuddyBoss Core *******************************************************/

		if ( defined( 'BP_VERSION' ) ) {
			$bp = buddypress();

			// Loop through root slugs and check for conflict
			if ( !empty( $bp->pages ) ) {
				foreach ( $bp->pages as $page => $page_data ) {
					$page_base    = $page . '_base';
					$page_title   = sprintf( __( '%s page', 'buddyboss' ), $page_data->title );
					$core_slugs[$page_base] = array( 'name' => $page_title, 'default' => $page_data->slug, 'context' => 'BuddyPress' );
				}
			}
		}

		// Set the static
		$the_core_slugs = apply_filters( 'bbp_slug_conflict', $core_slugs );
	}

	// Loop through slugs to check
	foreach ( $the_core_slugs as $key => $value ) {

		// Get the slug
		$slug_check = bbp_get_form_option( $key, $value['default'], true );

		// Compare
		if ( ( $slug !== $key ) && ( $slug_check === $this_slug ) ) : ?>

			<span class="attention"><?php printf( esc_html__( 'Possible %1$s conflict: %2$s', 'buddyboss' ), $value['context'], '<strong>' . $value['name'] . '</strong>' ); ?></span>

		<?php endif;
	}
}

Changelog

Changelog
Version Description
bbPress (r3306) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.