Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the full domain name #214

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/class-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function admin_enqueue_scripts( $hook ) {
[
'ajax_url' => network_admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'aspireupdate-ajax' ),
'domain' => Utilities::get_top_level_domain(),
'domain' => Utilities::get_site_domain(),
'line_ending' => PHP_EOL,
'unexpected_error' => esc_html__( 'Unexpected Error', 'aspireupdate' ),
]
Expand Down
13 changes: 5 additions & 8 deletions includes/class-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
* The Class for Admin Settings Page and functions to access Settings Values.
*/
class Utilities {

/**
* Get the top level domain name from the site URL.
* Get the domain name from the site URL.
*
* @return string the top level domain name.
* @return string the domain name.
costdev marked this conversation as resolved.
Show resolved Hide resolved
*/
public static function get_top_level_domain() {
$site_url = get_site_url();
$domain_name = wp_parse_url( $site_url, PHP_URL_HOST );
$domain_parts = explode( '.', $domain_name );
return sanitize_text_field( implode( '.', array_slice( $domain_parts, -2 ) ) );
public static function get_site_domain() {
$site_url = get_site_url();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In multisite, plugins can only be installed on the network level. Therefore, the URL for the API should be the main site's URL.

With a multisite setup of:

When on Second site, get_site_url() will return https://my-other-site.com.

Use network_site_url() instead, as it will return https://my-site.com.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with above

return wp_parse_url( $site_url, PHP_URL_HOST );
}

/**
Expand Down