Automattic\WooCommerce\Internal\Admin\Settings\PaymentProviders
PaymentGateway::get_plugin_file
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.
Method of the class: PaymentGateway{}
No Hooks.
Returns
String
. 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.
Usage
$PaymentGateway = new PaymentGateway(); $PaymentGateway->get_plugin_file( $payment_gateway, $plugin_slug ): string;
- $payment_gateway(WC_Payment_Gateway) (required)
- The payment gateway object.
- $plugin_slug(string)
- The payment gateway plugin slug to use directly.
Default: ''
PaymentGateway::get_plugin_file() PaymentGateway::get plugin file code WC 9.9.3
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 ); }