Skip to content

Commit

Permalink
[#919] Change Base Share URL for Referrals (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget authored Apr 20, 2024
1 parent dca496f commit f18ee7e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
8 changes: 7 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Users/Referrals.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace GoodBids\Users\Referrals;

use GoodBids\Users\Referrals;

/**
* Class for Referral Shortcodes
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f18ee7e

Please sign in to comment.