_wp_connectors_resolve_ai_provider_logo_url()WP 7.0.0

Resolves an AI provider logo file path to a URL.

Converts an absolute file path to a plugin URL. The path must reside within the plugins or must-use plugins directory.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

non-empty-Строку|null. The URL to the logo file, or null if the path is invalid.

Использование

_wp_connectors_resolve_ai_provider_logo_url( $path ): ?string;
$path(строка) (обязательный)
Absolute path to the logo file.

Список изменений

С версии 7.0.0 Введена.

Код _wp_connectors_resolve_ai_provider_logo_url() WP 7.0.4

function _wp_connectors_resolve_ai_provider_logo_url( string $path ): ?string {
	if ( ! $path ) {
		return null;
	}

	$path = wp_normalize_path( $path );

	if ( ! file_exists( $path ) ) {
		return null;
	}

	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
	if ( str_starts_with( $path, $mu_plugin_dir . '/' ) ) {
		$logo_url = plugins_url( substr( $path, strlen( $mu_plugin_dir ) ), WPMU_PLUGIN_DIR . '/.' );
		return $logo_url ? $logo_url : null;
	}

	$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
	if ( str_starts_with( $path, $plugin_dir . '/' ) ) {
		$logo_url = plugins_url( substr( $path, strlen( $plugin_dir ) ) );
		return $logo_url ? $logo_url : null;
	}

	_doing_it_wrong(
		__FUNCTION__,
		__( 'Provider logo path must be located within the plugins or must-use plugins directory.' ),
		'7.0.0'
	);

	return null;
}