acf_register_location_type()ACF 5.9.0

Registers a location type.

Hooks from the function

Returns

(ACF_Location|false).

Usage

acf_register_location_type( $class_name );
$class_name(string) (required)
The location class name.

Changelog

Since 5.9.0 Introduced.

acf_register_location_type() code ACF 6.8.8

function acf_register_location_type( $class_name ) {
	$store = acf_get_store( 'location-types' );

	// Check class exists.
	if ( ! class_exists( $class_name ) ) {
		/* translators: %s class name for a location that could not be found */
		$message = sprintf( __( 'Class "%s" does not exist.', 'acf' ), $class_name );
		_doing_it_wrong( __FUNCTION__, esc_html( $message ), '5.9.0' );
		return false;
	}

	// Create instance.
	$location_type = new $class_name();
	$name          = $location_type->name;

	// Check location type is unique.
	if ( $store->has( $name ) ) {
		/* translators: %s the name of the location type */
		$message = sprintf( __( 'Location type "%s" is already registered.', 'acf' ), $name );
		_doing_it_wrong( __FUNCTION__, esc_html( $message ), '5.9.0' );
		return false;
	}

	// Add to store.
	$store->set( $name, $location_type );

	/**
	 * Fires after a location type is registered.
	 *
	 * @date    8/4/20
	 * @since   5.9.0
	 *
	 * @param   string $name The location type name.
	 * @param   ACF_Location $location_type The location type instance.
	 */
	do_action( 'acf/registered_location_type', $name, $location_type );

	// Return location type instance.
	return $location_type;
}