Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

PaymentGateway::get_plugin_filepublicWC 1.0

Get the corresponding plugin file of the payment gateway, without the .php extension.

This is useful for using the WP API to change the state of the plugin (activate or deactivate). We remove the .php extension since the WP API expects plugin files without it.

Метод класса: PaymentGateway{}

Хуков нет.

Возвращает

Строку. The plugin file corresponding to the payment gateway plugin. Does not include the .php extension. In case of failures, it will return an empty string.

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

$PaymentGateway = new PaymentGateway();
$PaymentGateway->get_plugin_file( $payment_gateway, $plugin_slug ): string;
$payment_gateway(WC_Payment_Gateway) (обязательный)
The payment gateway object.
$plugin_slug(строка)
The payment gateway plugin slug to use directly.
По умолчанию: ''

Код PaymentGateway::get_plugin_file() WC 10.5.0

public function get_plugin_file( WC_Payment_Gateway $payment_gateway, string $plugin_slug = '' ): string {
	// If the payment gateway object has a `plugin_file` property, use it.
	// This is useful for testing.
	if ( isset( $payment_gateway->plugin_file ) ) {
		$plugin_file = $payment_gateway->plugin_file;
		// Sanity check.
		if ( ! is_string( $plugin_file ) ) {
			return '';
		}
		// Remove the .php extension from the file path. The WP API expects it without it.
		return Utils::trim_php_file_extension( $plugin_file );
	}

	if ( empty( $plugin_slug ) ) {
		$plugin_slug = $this->get_plugin_slug( $payment_gateway );
	}

	// Bail if we couldn't determine the plugin slug.
	if ( empty( $plugin_slug ) ) {
		return '';
	}

	$plugin_file = PluginsHelper::get_plugin_path_from_slug( $plugin_slug );
	// Bail if we couldn't determine the plugin file.
	if ( ! is_string( $plugin_file ) || empty( $plugin_file ) ) {
		return '';
	}

	// Remove the .php extension from the file path. The WP API expects it without it.
	return Utils::trim_php_file_extension( $plugin_file );
}