Skip to content

Centralised Settings For Multisite#277

Open
mchirag2002 wants to merge 11 commits intodevelopfrom
feature/multisite-refactor
Open

Centralised Settings For Multisite#277
mchirag2002 wants to merge 11 commits intodevelopfrom
feature/multisite-refactor

Conversation

@mchirag2002
Copy link
Contributor

@mchirag2002 mchirag2002 commented Oct 3, 2025

Description

  • This PR refactors the settings page of the plugin for the multisite installations only.
  • It makes the following changes:
    • Creates a new settings page for Network Admins
    • Moved the Client ID and Client Secret to the network level and removed them from subsites
    • Added option for applying settings globally, which, if enabled, makes the site-level settings Read-Only.
    • If not, then these settings like Onetap, Onetap locations, Create New Users, and Whitelisted domains need to be configured from the individual sites.

ToDo before making this release

  • Before releasing this feature, we need to make a minor release which adds an admin notice that informs the users about this upcoming refactoring, so that the small subset of people who use different credentials on their sites, don't upgrade or find a workaround.
  • Once the release version is finalised, update the @since version comments in the codebase with the release version.

Demo video for the changes implemented

https://drive.google.com/file/d/1UVpIxZGK58cSi3I7myc67eyPuBmZVzcO/view?usp=sharing

Fixes

Make the plugin multisite compatible (#119)

@mchirag2002 mchirag2002 added the enhancement New feature or request label Oct 3, 2025
@mi5t4n mi5t4n self-requested a review November 3, 2025 07:27
@mi5t4n
Copy link
Member

mi5t4n commented Nov 3, 2025

Will take over reviewing this PR.

cc @mchirag2002 @joelabreo227

@mi5t4n
Copy link
Member

mi5t4n commented Nov 6, 2025

@mchirag2002 Could you add screenshot or a video recording on what has changes where the new settings are ?

Copilot AI review requested due to automatic review settings November 6, 2025 12:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds multisite network support for the Google Login plugin, allowing network administrators to configure OAuth credentials and settings globally across all sites in a WordPress multisite installation.

Key Changes:

  • Adds network-level settings management for multisite installations
  • Implements get_client_id() and get_client_secret() methods to retrieve credentials from network settings in multisite environments
  • Adds an "Apply Globally" option to enforce network settings across all subsites

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
src/Modules/Settings.php Core changes implementing network settings registration, rendering, and saving functionality with UI toggle logic
src/Container.php Updates GoogleClient instantiation to use the new getter methods instead of direct property access
readme.txt Documents multisite configuration in the setup instructions
README.md Adds multisite setup documentation explaining the network administrator workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'client_secret' => '',
];

$settings = $_POST['wp_google_login_network_settings'] ?? []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

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

While the phpcs:ignore comment indicates intentional access to unsanitized input, the array keys should be validated using wp_unslash() before processing. Consider wrapping $_POST['wp_google_login_network_settings'] with wp_unslash() to handle escaped input properly: $settings = isset( $_POST['wp_google_login_network_settings'] ) ? wp_unslash( $_POST['wp_google_login_network_settings'] ) : [];

Suggested change
$settings = $_POST['wp_google_login_network_settings'] ?? []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$settings = isset( $_POST['wp_google_login_network_settings'] ) ? wp_unslash( $_POST['wp_google_login_network_settings'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

Copilot uses AI. Check for mistakes.
@mchirag2002
Copy link
Contributor Author

@mchirag2002 Could you add screenshot or a video recording on what has changes where the new settings are ?

@mi5t4n Updated the PR description to add the requested video.

mi5t4n
mi5t4n previously approved these changes Nov 7, 2025
Copy link
Member

@mi5t4n mi5t4n left a comment

Choose a reason for hiding this comment

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

All looks good, but WP member setting must be set in the Settings -> General, otherwise just checking Create New User on Network side settings will not work.

* Register the settings, section and fields.
* Retrieves the Google OAuth Client ID, always from the network settings in multisite.
*
* @return string
Copy link
Member

Choose a reason for hiding this comment

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

Do add @since n.e.x.t and replace n.e.x.t with plugin version during release.

@mi5t4n mi5t4n self-requested a review November 7, 2025 11:53
mi5t4n

This comment was marked as duplicate.

@mi5t4n
Copy link
Member

mi5t4n commented Nov 17, 2025

@mchirag2002 Left some comments.

@mi5t4n
Copy link
Member

mi5t4n commented Nov 17, 2025

@mchirag2002 I was able to reproduce the issue again. It looks like we need to clear all the old settings in the multisite setup and create a completely fresh configuration.

Note

Remove all the settings from all the site options by searching through google name option.

Kazam_screencast_00000.mp4

@mchirag2002 mchirag2002 requested a review from mi5t4n November 19, 2025 11:55
Copy link
Member

@mi5t4n mi5t4n left a comment

Choose a reason for hiding this comment

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

We have same two text in the network settings and the membership link is not working in the network settings and in the invidividual site settings. https://prnt.sc/ao-MKoXXn_2B

public function apply_globally_field( $args = [] ): void {
$network_options = get_site_option( 'wp_google_login_network_settings', [] );
?>
<input type="checkbox" name="wp_google_login_network_settings[apply_globally]" id="apply-globally" value="1" <?php checked( ! empty( $network_options['apply_globally'] ) ); ?> />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<input type="checkbox" name="wp_google_login_network_settings[apply_globally]" id="apply-globally" value="1" <?php checked( ! empty( $network_options['apply_globally'] ) ); ?> />
<input
type="checkbox"
name="wp_google_login_network_settings[apply_globally]"
id="apply-globally"
value="1"
<?php checked( ! empty( $network_options['apply_globally'] ) ); ?>
/>

Comment on lines +594 to +600
<label style='display:block;margin-top:6px;'><input
type='checkbox'
name='wp_google_login_network_settings[one_tap_login]'
id="one-tap-login" <?php checked( $checked ); ?>
value='1'>
<?php esc_html_e( 'One Tap Login', 'login-with-google' ); ?>
</label>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<label style='display:block;margin-top:6px;'><input
type='checkbox'
name='wp_google_login_network_settings[one_tap_login]'
id="one-tap-login" <?php checked( $checked ); ?>
value='1'>
<?php esc_html_e( 'One Tap Login', 'login-with-google' ); ?>
</label>
<label style='display:block;margin-top:6px;'>
<input
type='checkbox'
name='wp_google_login_network_settings[one_tap_login]'
id="one-tap-login" <?php checked( $checked ); ?>
value='1'
/>
<?php esc_html_e( 'One Tap Login', 'login-with-google' ); ?>
</label>

Comment on lines +662 to +664
if ( $readonly ) {
echo 'disabled';
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( $readonly ) {
echo 'disabled';
}
echo ( $readonly ? 'disabled' : '' )

* @return void
*/
public function user_registration(): void {
public function user_registration( $args = [] ): void {
Copy link
Member

Choose a reason for hiding this comment

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

We need to add the version where $args parameter was introduced.

Comment on lines +529 to +532
<input type='checkbox'
name='wp_google_login_network_settings[registration_enabled]'
id="user-registration" <?php checked( $checked ); ?>
value='1'>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<input type='checkbox'
name='wp_google_login_network_settings[registration_enabled]'
id="user-registration" <?php checked( $checked ); ?>
value='1'>
<input
type='checkbox'
name='wp_google_login_network_settings[registration_enabled]'
id="user-registration" <?php checked( $checked ); ?>
value='1'
>

*
* @return void
*/
public function save_network_settings(): void {
Copy link
Member

Choose a reason for hiding this comment

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

Add @since n.e.x.t for newly added functions.

<h1><?php esc_html_e( 'Login with Google Network Settings', 'login-with-google' ); ?></h1>
<form method="post" action="edit.php?action=wp_google_login_network_settings">
<?php
wp_nonce_field( 'wp_google_login_network-options' );
Copy link
Member

Choose a reason for hiding this comment

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

Let's not use wp_google_login prefix as it indicates it's WP core specific. We have to use our own specific rtcamp_login_with_google_network-options. Apply similar thing to newly added nonce, settings, ids or input names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mi5t4n this convention of using wp_google_login is present across the codebase since the beginning, and although I completely agree with you to alter the prefix, I think for code consistency we can create a new task for code refactoring and tackle it over there.
Otherwise once this PR is merged, we will be having some filters/nonces with different prefix and others with different prefix.

Copy link
Member

Choose a reason for hiding this comment

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

@mchirag2002 Noted, let's do in another PR.

add_submenu_page(
'settings.php',
__( 'Login with Google Network Settings', 'login-with-google' ),
__( 'Login with Google', 'login-with-google' ),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
__( 'Login with Google', 'login-with-google' ),
_x( 'Login with Google', 'Page title', 'login-with-google' ),

@mchirag2002 mchirag2002 requested a review from mi5t4n November 25, 2025 10:13
Copy link
Member

@mi5t4n mi5t4n left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants