From f18ee7e064eeb38445bd4eddd64f278a07bc1636 Mon Sep 17 00:00:00 2001 From: Brian DiChiara <122309362+bd-viget@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:20:05 -0500 Subject: [PATCH] [#919] Change Base Share URL for Referrals (#921) --- .../goodbids/src/classes/Network/Sites.php | 8 +++++- .../goodbids/src/classes/Users/Referrals.php | 28 +++++++++++++++++++ .../src/classes/Users/Referrals/Referrer.php | 2 +- .../classes/Users/Referrals/Shortcodes.php | 2 -- .../src/classes/Users/Referrals/Track.php | 4 +-- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/Network/Sites.php b/client-mu-plugins/goodbids/src/classes/Network/Sites.php index c79848702..4957a0388 100644 --- a/client-mu-plugins/goodbids/src/classes/Network/Sites.php +++ b/client-mu-plugins/goodbids/src/classes/Network/Sites.php @@ -47,6 +47,12 @@ class Sites { */ const AUCTIONS_OPTION = 'gb_auctions_page'; + /** + * @since 1.0.1 + * @var string + */ + const ALL_AUCTIONS_SLUG = 'explore-auctions'; + /** * @since 1.0.0 * @var string @@ -539,7 +545,7 @@ private function create_all_auctions_page(): void { add_action( 'goodbids_initialize_site', function (): void { - $auctions_slug = 'explore-auctions'; + $auctions_slug = self::ALL_AUCTIONS_SLUG; $existing = get_option( self::AUCTIONS_OPTION ); // Make sure it doesn't already exist. diff --git a/client-mu-plugins/goodbids/src/classes/Users/Referrals.php b/client-mu-plugins/goodbids/src/classes/Users/Referrals.php index e33f9b341..65cf1895b 100644 --- a/client-mu-plugins/goodbids/src/classes/Users/Referrals.php +++ b/client-mu-plugins/goodbids/src/classes/Users/Referrals.php @@ -9,6 +9,7 @@ namespace GoodBids\Users; use GoodBids\Core; +use GoodBids\Network\Sites; use GoodBids\Users\Referrals\Admin; use GoodBids\Users\Referrals\Generator; use GoodBids\Users\Referrals\Referral; @@ -430,4 +431,31 @@ public function get_top_referrers(): array { ARRAY_A ); } + + /** + * Get the base share URL + * + * @since 1.0.1 + * + * @return string + */ + public function get_base_share_url(): string { + return goodbids()->sites->main( + function () { + $share_page_id = get_option( Sites::AUCTIONS_OPTION ); + + if ( $share_page_id ) { + return get_permalink( $share_page_id ); + } + + $share_page = get_page_by_path( Sites::ALL_AUCTIONS_SLUG ); + + if ( $share_page ) { + return get_permalink( $share_page ); + } + + return site_url(); // Default to the main site Home page. + } + ); + } } diff --git a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Referrer.php b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Referrer.php index de329ce78..ca4bb3617 100644 --- a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Referrer.php +++ b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Referrer.php @@ -130,7 +130,7 @@ public function get_link(): string { } $code = strtoupper( $this->get_code() ); - $base = wp_registration_url(); + $base = goodbids()->referrals->get_base_share_url(); return add_query_arg( [ Track::REFERRAL_CODE_QUERY_ARG => $code ], $base ); } diff --git a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Shortcodes.php b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Shortcodes.php index 1c08e1204..d9b39886c 100644 --- a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Shortcodes.php +++ b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Shortcodes.php @@ -8,8 +8,6 @@ namespace GoodBids\Users\Referrals; -use GoodBids\Users\Referrals; - /** * Class for Referral Shortcodes * diff --git a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Track.php b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Track.php index 58690fa8b..7d6831038 100644 --- a/client-mu-plugins/goodbids/src/classes/Users/Referrals/Track.php +++ b/client-mu-plugins/goodbids/src/classes/Users/Referrals/Track.php @@ -74,8 +74,8 @@ function () { } } - // Remove referral code from URL. - wp_safe_redirect( remove_query_arg( self::REFERRAL_CODE_QUERY_ARG ) ); + // Redirect to default base share URL. + wp_safe_redirect( goodbids()->referrals->get_base_share_url() ); exit; }, 2