Skip to content

Commit

Permalink
Improve home URL check.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Feb 15, 2024
1 parent 3b28a44 commit 52e5d37
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/HomeUrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function init() {
$option = \get_option( 'pronamic_pay_home_url', null );

if ( null === $option ) {
\update_option( 'pronamic_pay_home_url', \home_url() );
\update_option( 'pronamic_pay_home_url', \get_option( 'home' ) );
}

\register_setting(
Expand All @@ -54,7 +54,7 @@ public function init() {
'type' => 'string',
'description' => \__( 'Home URL setting to detect changes in the WordPress home URL.', 'pronamic_ideal' ),
'sanitize_callback' => 'sanitize_url',
'default' => \home_url(),
'default' => \get_option( 'home' ),
]
);
}
Expand All @@ -74,7 +74,10 @@ public function admin_notices() {
*
* @link https://github.com/pronamic/wp-pay-core/issues/121
*/
if ( \get_option( 'home' ) === \get_option( 'pronamic_pay_home_url' ) ) {
$home_url_a = \get_option( 'home' );
$home_url_b = \get_option( 'pronamic_pay_home_url' );

if ( $home_url_a === $home_url_b ) {
return;
}

Expand All @@ -91,8 +94,8 @@ public function admin_notices() {
\sprintf(
/* translators: 1: Pronamic Pay home URL option, 2: home URL */
__( 'We noticed the WordPress home URL has changed from "%1$s" to "%2$s". Please verify the payment gateway settings. For example, you might want to switch between live and test mode or need to update an URL at the gateway to continue receiving payment status updates. Also keep an eye on pending payments to discover possible configuration issues.', 'pronamic_ideal' ),
\get_option( 'pronamic_pay_home_url' ),
\get_option( 'home' )
$home_url_b,
$home_url_a
)
);

Expand Down Expand Up @@ -148,7 +151,7 @@ public function admin_init() {
\wp_die( \esc_html__( 'You don’t have permission to do this.', 'pronamic_ideal' ) );
}

$result = \update_option( 'pronamic_pay_home_url', \home_url() );
$result = \update_option( 'pronamic_pay_home_url', \get_option( 'home' ) );

if ( false === $result ) {
\wp_die( \esc_html__( 'Action failed. Please refresh the page and retry.', 'pronamic_ideal' ) );
Expand Down

0 comments on commit 52e5d37

Please sign in to comment.