Skip to content

Commit 2c2680e

Browse files
authored
Merge branch '5.4.2-dev' into ch7127-add-standard-subscription-data-to-orders
2 parents 774e2f6 + a4edbed commit 2c2680e

File tree

5 files changed

+88
-8
lines changed

5 files changed

+88
-8
lines changed

woocommerce/admin/abstract-sv-wc-plugin-admin-setup-wizard.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ protected function add_hooks() {
145145
*/
146146
public function add_admin_notices() {
147147

148-
$current_screen = get_current_screen();
149-
150-
if ( ( $current_screen && 'plugins' === $current_screen->id ) || $this->get_plugin()->is_plugin_settings() ) {
148+
if ( Framework\SV_WC_Helper::is_current_screen( 'plugins' ) || $this->get_plugin()->is_plugin_settings() ) {
151149

152150
if ( $this->is_complete() && $this->get_documentation_notice_message() ) {
153151
$notice_id = "wc_{$this->id}_docs";

woocommerce/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
2019.nn.nn - version 5.4.2-dev.1
44
* Tweak - Add a standard set of subscription details to orders payment data set by a gateway
5+
* Tweak - Add replacement helper methods to get the current screen in WordPress and check the screen ID
6+
* Misc - Change SV_WC_Payment_Gateway::is_configured() from protected to public
7+
* Misc - Add admin notice when a gateway is enabled but is not configured and is unable to take payments
58

69
2019.08.06 - version 5.4.1
710
* Misc - Add a configurable admin notice for plugins running deprecated WooCommerce versions

woocommerce/class-sv-wc-helper.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,41 @@ public static function f_x( $text, $context ) {
956956
/** Misc functions ****************************************************/
957957

958958

959+
/**
960+
* Gets the WordPress current screen.
961+
*
962+
* @see get_current_screen() replacement which is always available, unlike the WordPress core function
963+
*
964+
* @since 5.4.2-dev.1
965+
*
966+
* @return \WP_Screen|null
967+
*/
968+
public static function get_current_screen() {
969+
global $current_screen;
970+
971+
return $current_screen ?: null;
972+
}
973+
974+
975+
/**
976+
* Checks if the current screen matches a specified ID.
977+
*
978+
* This helps avoiding using the get_current_screen() function which is not always available,
979+
* or setting the substitute global $current_screen every time a check needs to be performed.
980+
*
981+
* @since 5.4.2-dev.1
982+
*
983+
* @param string $id id (or property) to compare
984+
* @param string $prop optional property to compare, defaults to screen id
985+
* @return bool
986+
*/
987+
public static function is_current_screen( $id, $prop = 'id' ) {
988+
global $current_screen;
989+
990+
return isset( $current_screen->$prop ) && $id === $current_screen->$prop;
991+
}
992+
993+
959994
/**
960995
* Convert a 2-character country code into its 3-character equivalent, or
961996
* vice-versa, e.g.

woocommerce/payment-gateway/class-sv-wc-payment-gateway-plugin.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ public function add_delayed_admin_notices() {
568568

569569
// add notices about enabled debug logging
570570
$this->add_debug_setting_notices();
571+
572+
// add notices about gateways not being configured
573+
$this->add_gateway_not_configured_notices();
571574
}
572575

573576

@@ -723,6 +726,25 @@ protected function add_debug_setting_notices() {
723726
}
724727

725728

729+
/**
730+
* Adds notices about gateways not being configured.
731+
*
732+
* @since 5.4.2-dev.1
733+
*/
734+
protected function add_gateway_not_configured_notices() {
735+
736+
foreach ( $this->get_gateways() as $gateway ) {
737+
738+
if ( $gateway->is_enabled() && ! $gateway->is_configured() && ! $gateway->inherit_settings() ) {
739+
740+
$this->get_admin_notice_handler()->add_admin_notice( $gateway->get_not_configured_error_message(), $gateway->get_id() . '-not-configured', [
741+
'notice_class' => 'error',
742+
] );
743+
}
744+
}
745+
}
746+
747+
726748
/** Integration methods ***************************************************/
727749

728750

@@ -822,7 +844,7 @@ public function subscriptions_maybe_edit_renewal_support_status( $html, $gateway
822844
*/
823845
public function subscriptions_add_renewal_support_status_inline_style() {
824846

825-
if ( SV_WC_Plugin_Compatibility::normalize_wc_screen_id() === get_current_screen()->id ) {
847+
if ( SV_WC_Helper::is_current_screen( SV_WC_Plugin_Compatibility::normalize_wc_screen_id() ) ) {
826848
wp_add_inline_style( 'woocommerce_admin_styles', '.sv-wc-payment-gateway-renewal-status-inactive{font-size:1.4em;display:block;text-indent:-9999px;position:relative;height:1em;width:1em;cursor:pointer}.sv-wc-payment-gateway-renewal-status-inactive:before{line-height:1;margin:0;position:absolute;width:100%;height:100%;content:"\e016";color:#ffba00;font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;text-indent:0;top:0;left:0;text-align:center}' );
827849
}
828850
}

woocommerce/payment-gateway/class-sv-wc-payment-gateway.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,13 +1539,14 @@ public function is_available() {
15391539

15401540

15411541
/**
1542-
* Returns true if the gateway is properly configured to perform transactions
1542+
* Determines whether the gateway is properly configured to perform transactions.
15431543
*
15441544
* @since 1.0.0
1545-
* @see SV_WC_Payment_Gateway::is_configured()
1546-
* @return boolean true if the gateway is properly configured
1545+
*
1546+
* @return bool
15471547
*/
1548-
protected function is_configured() {
1548+
public function is_configured() {
1549+
15491550
// override this to check for gateway-specific required settings (user names, passwords, secret keys, etc)
15501551
return true;
15511552
}
@@ -4151,6 +4152,27 @@ public function get_checkout_order_received_order_id() {
41514152
}
41524153

41534154

4155+
/**
4156+
* Returns the error message for display if the gateway is not configured.
4157+
*
4158+
* @since 5.4.2-dev.1
4159+
*
4160+
* @return string
4161+
*/
4162+
public function get_not_configured_error_message() {
4163+
4164+
return sprintf(
4165+
/* translators: %1$s - gateway name, %2$s - <a> tag, %3$s - </a> tag, %4$s - <a> tag, %5$s - </a> tag */
4166+
__( 'Heads up! %1$s is not fully configured and cannot accept payments. Please %2$sreview the documentation%3$s and configure the %4$sgateway settings%5$s.', 'woocommerce-plugin-framework' ),
4167+
$this->get_method_title(),
4168+
'<a href="' . $this->get_plugin()->get_documentation_url() . '" target="_blank">',
4169+
'</a>',
4170+
'<a href="' . $this->get_plugin()->get_settings_url( $this->get_id() ) . '">',
4171+
'</a>'
4172+
);
4173+
}
4174+
4175+
41544176
/** Deprecated Methods ********************************************************************************************/
41554177

41564178

0 commit comments

Comments
 (0)