acf_register_location_type()
Registers a location type.
Хуки из функции
Возвращает
(ACF_Location|false).
Использование
acf_register_location_type( $class_name );
- $class_name(строка) (обязательный)
- The location class name.
Список изменений
| С версии 5.9.0 | Введена. |
Код acf_register_location_type() acf register location type ACF 6.4.2
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;
}