Automattic\WooCommerce\Blocks\Domain

Bootstrap::deprecated_dependency()protectedWC 1.0

Throws a deprecation notice for a dependency without breaking requests.

{} Это метод класса: Bootstrap{}

Возвращает

null. Ничего.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->deprecated_dependency( $function, $version, $replacement, $trigger_error_version );
$function(строка) (обязательный)
Class or function being deprecated.
$version(строка) (обязательный)
Version in which it was deprecated.
$replacement(строка)
Replacement class or function, if applicable.
По умолчанию: ''
$trigger_error_version(строка)
Optional version to start surfacing this as a PHP error rather than a log.
По умолчанию: $version

Код Bootstrap::deprecated_dependency() WC 6.8.0

protected function deprecated_dependency( $function, $version, $replacement = '', $trigger_error_version = '' ) {
	if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
		return;
	}

	$trigger_error_version = $trigger_error_version ? $trigger_error_version : $version;
	$error_message         = $replacement ? sprintf(
		'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
		$function,
		$version,
		$replacement
	) : sprintf(
		'%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
		$function,
		$version
	);

	do_action( 'deprecated_function_run', $function, $replacement, $version );

	$log_error = false;

	// If headers have not been sent yet, log to avoid breaking the request.
	if ( ! headers_sent() ) {
		$log_error = true;
	}

	// If the $trigger_error_version was not yet reached, only log the error.
	if ( version_compare( $this->package->get_version(), $trigger_error_version, '<' ) ) {
		$log_error = true;
	}

	// Apply same filter as WP core.
	if ( ! apply_filters( 'deprecated_function_trigger_error', true ) ) {
		$log_error = true;
	}

	if ( $log_error ) {
		// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
		error_log( $error_message );
	} else {
		// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
		trigger_error( $error_message, E_USER_DEPRECATED );
	}
}