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

add multisite support #102

Merged
merged 18 commits into from
Nov 4, 2024
Merged

add multisite support #102

merged 18 commits into from
Nov 4, 2024

Conversation

afragen
Copy link
Contributor

@afragen afragen commented Nov 2, 2024

Pull Request

What changed?

Added multisite support.

Why did it change?

Fixes #59

Did you fix any specific issues?

Multisite support.
Update to use site options.
Apparently there were also some spaces at the end of code lines that VSCode removed.

CERTIFICATION

By opening this pull request, I do agree to abide by
the CODE OF CONDUCT and be bound by the terms
of the Contribution Guidelines in effect on the date and time
of my contribution as proven by the
revision information in GitHub. I also agree that any previous contributions shall be deemed subject to the terms of the
version in effect on the date and time of this pull request, or any future revisions for pull requests I may submit.
Further, I certify that this work is my own, is original, does not violate the intellectual property of any other person
or entity, and I am not violating any license agreements or contracts I have with any person or entity. Finally, I agree
that this code may be licensed under any license deemed appropraite by AspirePress, including but not
limited to open source, closed source, proprietary or custom licenses, and that such license terms neither violate my
rights or my copyright to this code.

@afragen afragen marked this pull request as ready for review November 2, 2024 16:21
@afragen
Copy link
Contributor Author

afragen commented Nov 2, 2024

Network Admin
screenshot_594

Single Site Admin on Multisite
screenshot_596

@namithj
Copy link
Contributor

namithj commented Nov 2, 2024

Have you tested this in MU. This shouldn't be enough for MU support. We need an admin screen for Network Admin., take away the setting from normal admins as MU core and plugins needs to be updated as a whole and can't be updated individually. This needs a lot of thought before we embark on the path.

@namithj
Copy link
Contributor

namithj commented Nov 2, 2024

Also the settings should use network options instead of the regular options if we do this.

@afragen afragen marked this pull request as draft November 2, 2024 16:34
@namithj
Copy link
Contributor

namithj commented Nov 2, 2024

The URLs for reset button and the redirect url after the reset will need to be updated

@namithj
Copy link
Contributor

namithj commented Nov 2, 2024

While we are at it, let’s make that URL come from a new function now that there can be different values for it so that it can be unit tested.

@afragen
Copy link
Contributor Author

afragen commented Nov 2, 2024

Currently working on saving settings.

@afragen
Copy link
Contributor Author

afragen commented Nov 2, 2024

If I comment out the following saving settings works for both single and multisite.

add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );

If not commented out there doesn't seem to be any action from the Save Changes button. I tested this in a new installation with a clean copy of the plugin and no other plugins.

See #103, #43

@afragen
Copy link
Contributor Author

afragen commented Nov 3, 2024

Aside from the issues #43 and #103, this PR should be ready for review.

FWIW, I have similar code running in many plugins for multisite compatibility, including the WordPress Beta Tester plugin.

@afragen afragen marked this pull request as ready for review November 3, 2024 17:42
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks Andy!

Haven't tested yet so just some minor things and a few clarification requests.

includes/class-admin-settings.php Show resolved Hide resolved
Comment on lines +53 to +54
add_action( 'admin_init', array( $this, 'update_settings' ) );
add_action( 'network_admin_edit_aspireupdate-settings', array( $this, 'update_settings' ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Double-checking if this is necessary for this issue or if this fixes a different issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary for saving from multisite and provides a consistent manner of saving for both single and multisite.

Comment on lines 308 to 310
<?php submit_button( esc_html__( 'Save Changes', 'aspireupdate-settings' ), 'primary', 'submit', false ); ?>

<a href="<?php echo esc_url( $reset_url ); ?>" class="button button-secondary" >Reset</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same clarification request about if this is necessary for this issue or if it's aprt of another?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's necessary for sending a nonce with the submit button. I did change the link to use the submit_button() though it may not be technically necessary to do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me, thanks!

Comment on lines +535 to +538
<option
data-api-key-url="<?php echo esc_html( $group_option['api-key-url'] ?? '' ); ?>"
data-require-api-key="<?php echo esc_html( $group_option['require-api-key'] ?? 'false' ); ?>"
value="<?php echo esc_attr( $group_option['value'] ?? '' ); ?>"
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 What change am I not seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VSCode removed the extra space at the end of some of the lines automatically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly 😂

Comment on lines +549 to +552
type="text"
id="aspireupdate-settings-field-<?php echo esc_attr( $id ); ?>_other"
name="<?php echo esc_attr( $this->option_name ); ?>[<?php echo esc_attr( $id ); ?>_other]"
value="<?php echo esc_attr( $options[ $id . '_other' ] ?? '' ); ?>"
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 What change am I not seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, my VSCode settings removed the extra space at the end of the line automatically.

@@ -539,18 +569,18 @@ class="regular-text"
public function sanitize_settings( $input ) {
$sanitized_input = array();

$sanitized_input['enable'] = ( isset( $input['enable'] ) && $input['enable'] ) ? 1 : 0;
$sanitized_input['enable'] = ( ! empty( $input['enable'] ) && $input['enable'] ) ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change here for enable and later for enable_debug, and is this needed for multisite support?

Copy link
Contributor

@costdev costdev Nov 3, 2024

Choose a reason for hiding this comment

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

Also, the second condition shouldn't be necessary here if using ! empty()

What about just (int) ! empty( $input['enable'] )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These values are unset by default. With multisite the sanitize function runs twice, I assume once from the register_setting() callback. The second time this runs the input is 0 and therefore it is set, but it is also empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me test that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested and working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Further simplified, doesn't need ternary.

@afragen
Copy link
Contributor Author

afragen commented Nov 3, 2024

I have tested this in both single and multisite. It's working for me. Only caveat is the first setting to enable API rewrites must be set in order for any other settings to be set. This is unrelated to multisite.

@asirota asirota requested a review from namithj November 4, 2024 08:26
@namithj
Copy link
Contributor

namithj commented Nov 4, 2024

@costdev Is this good to go?

@costdev
Copy link
Contributor

costdev commented Nov 4, 2024

I haven't had a chance to test this on multisite, but since @afragen has tested it, I'm pretty confident that it'll work as expected.

Nevertheless, I can follow up to test it, possibly later today.

@namithj
Copy link
Contributor

namithj commented Nov 4, 2024

Once you test, approve it in and let the testers know in slack so that they can test this one. Its a tricky one to test.

@afragen
Copy link
Contributor Author

afragen commented Nov 4, 2024

Be sure to test it in a single site too.

@costdev
Copy link
Contributor

costdev commented Nov 4, 2024

@afragen Be sure to test it in a single site too.

Make me!

Ok, I will 😂

@costdev
Copy link
Contributor

costdev commented Nov 4, 2024

Test Report

Environment

  • WordPress: 6.6.2
  • PHP: 7.4.33
  • Server: Apache/2.4.57 (Ubuntu)
  • Database: mysqli (Server: 8.0.35-0ubuntu0.20.04.1 / Client: mysqlnd 7.4.33)
  • Browser: Chrome 129.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Four 1.2
  • MU Plugins: None activated
  • Plugins:
    • AspireUpdate 0.5
    • Test Reports 1.2.0

Actual Results

Single Site

  1. ✅ Settings appear under Dashboard > AspireUpdate.
  2. ✅ Settings can be saved and are retained upon page refresh.
  3. ✅ Settings are reset and are still reset upon page refresh.
  4. ✅ Plugins are installed from the dotorg API when rewriting is disabled.
  5. ✅ Plugins are installed from the AP API when rewriting is enabled.
  6. ✅ Themes are installed from the dotorg API when rewriting is disabled.
  7. ✅ Themes are installed from the AP API when rewriting is enabled.

Multisite

  1. ✅ Settings appear under Dashboard > AspireUpdate for Network Admin.
  2. ✅ Settings do not appear under Dashboard > AspireUpdate when viewing a single site's dashboard.
  3. ✅ Settings can be saved and are retained upon page refresh.
  4. ✅ Settings are reset and are still reset upon page refresh.
  5. ✅ Plugins are installed from the dotorg API when rewriting is disabled.
  6. ✅ Plugins are installed from the AP API when rewriting is enabled.
  7. ✅ Themes are installed from the dotorg API when rewriting is disabled.
  8. ✅ Themes are installed from the AP API when rewriting is enabled.

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks @afragen!

As expected, everything I tested works in Single Site and Multisite. ❤️

@costdev
Copy link
Contributor

costdev commented Nov 4, 2024

@asirota This one should be good to go in now.

@asirota asirota added the enhancement New feature or request label Nov 4, 2024
@asirota asirota added this to the Phase 1 milestone Nov 4, 2024
@asirota asirota merged commit 46cd8f1 into aspirepress:main Nov 4, 2024
2 checks passed
isset( $_GET['reset-success'] ) &&
( 'success' === $_GET['reset-success'] ) &&
isset( $_GET['reset-success-nonce'] ) &&
wp_verify_nonce( sanitize_key( $_GET['reset-success-nonce'] ), 'aspireupdate-reset-success-nonce' )
) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings have been reset to default.', 'AspireUpdate' ) . '</p></div>';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how the i18n and escaping got removed. Sorry.

Copy link
Member

Choose a reason for hiding this comment

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

I assume this made it into the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It didn't but I made another PR for it.

asirota pushed a commit that referenced this pull request Nov 4, 2024
Fixed typo in code deleted when addressing #102
asirota added a commit that referenced this pull request Nov 5, 2024
* Prevent Recursion on certain Host name patterns (#69)

---------

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* Playground ready updating into main (#71)

* Update blueprint.json

Switching to default theme of 2022 to support minimum WP Playground support for WordPress version as 5.9.9

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* Switching blueprint.json to 2022 theme

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>

---------

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* `Add New Plugin`: Remove 'Featured' and 'Favorites' tabs when API rewrite is enabled. (#80)

* Add class for overriding plugins screens.

* Remove unused tabs when API rewrite is enabled.

* `Add New Theme`: Remove 'Favorites' filter tab when API rewrite is enabled. (#82)

* Add class for overriding themes screens.

* Hide unsupported filters.

* Redirect unsupported filters to `theme-install.php`.

---------

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Co-authored-by: Alex Sirota <alex@newpathconsulting.com>

* Add PHPUnit. (#87)

* Add PHPUnit scaffolding.

* Add Composer files for dependencies and test script.

* Add `.gitignore`.

* Add sample test for `Admin_Settings::get_setting()`.

* Add PHP 8.3 to the test matrix.

* Add `.cache/*` to `.gitignore`.

* Limit testing to PHP 7.4 (minimum) and 8.3 (latest).

* `Plugins Screens`: Initialize in `Controller::__construct()`. (#89)

* `Workflows`: Fix PHP version and add more workflow triggers. (#92)

* Fix PHP version.

* Add `push` and `workflow_dispatch` workflow triggers.

* `Tests`: Ensure options are not set when tests run. (#95)

* Introduce a test constant.

* Don't initialize when the tests are running.

* Use a new object for testing `Admin_Settings::get_setting()`.

* Warning when debug-aspire-update.log doesnt exist (#109)

* `Tests`: Add default coverage settings. (#97)

* Improve I18N Issues Based on version 0.5 (#104)

* Fixes Settings not getting saved when rewrites were turned off (#108)

* Add French Translation (#105)

* I18n fr fr (#113)

* Translations loading fix112 (#114)

* Add French translations. 

* load any available translations with code in the plugin

* #110 (#116)

Fixes #110

* Add nonce verification and sanitize `$_REQUEST/$_GET` values. (#115)

Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>

* Added German Translation (#111)

* added German translation

* added gitignore for .DS_Store


Signed-off-by: Harikrishnan R <harikrishnanr994@gmail.com>

* Voltron has landed. (#117)

The Voltron has landed. See if you can find where.

* `Admin Settings`: Delete all settings when the plugin is uninstalled. (#118)

* `Admin Settings`: Add multisite-safe deletion of all settings.

* Delete all settings when the plugin is uninstalled.

* add multisite support (#102)

* accidentally deleted (#124)

Fixed typo in code deleted when addressing #102

* Add `.editorconfig`. (#123)

* create zip with each new tagged release (#121)

* create zip with each new tagged release

* update .gitattributes

---------

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>
Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Signed-off-by: Harikrishnan R <harikrishnanr994@gmail.com>
Co-authored-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Co-authored-by: Alex Lion <learnwithalex@gmail.com>
Co-authored-by: Sébastien SERRE <sebastien@thivinfo.com>
Co-authored-by: Harikrishnan R <harikrishnanr994@gmail.com>
Co-authored-by: Andy Fragen <andy@thefragens.com>
asirota added a commit that referenced this pull request Nov 5, 2024
* Prevent Recursion on certain Host name patterns (#69)

---------

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* Playground ready updating into main (#71)

* Update blueprint.json

Switching to default theme of 2022 to support minimum WP Playground support for WordPress version as 5.9.9

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* Switching blueprint.json to 2022 theme

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>

---------

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>

* `Add New Plugin`: Remove 'Featured' and 'Favorites' tabs when API rewrite is enabled. (#80)

* Add class for overriding plugins screens.

* Remove unused tabs when API rewrite is enabled.

* `Add New Theme`: Remove 'Favorites' filter tab when API rewrite is enabled. (#82)

* Add class for overriding themes screens.

* Hide unsupported filters.

* Redirect unsupported filters to `theme-install.php`.

---------

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Co-authored-by: Alex Sirota <alex@newpathconsulting.com>

* Add PHPUnit. (#87)

* Add PHPUnit scaffolding.

* Add Composer files for dependencies and test script.

* Add `.gitignore`.

* Add sample test for `Admin_Settings::get_setting()`.

* Add PHP 8.3 to the test matrix.

* Add `.cache/*` to `.gitignore`.

* Limit testing to PHP 7.4 (minimum) and 8.3 (latest).

* `Plugins Screens`: Initialize in `Controller::__construct()`. (#89)

* `Workflows`: Fix PHP version and add more workflow triggers. (#92)

* Fix PHP version.

* Add `push` and `workflow_dispatch` workflow triggers.

* `Tests`: Ensure options are not set when tests run. (#95)

* Introduce a test constant.

* Don't initialize when the tests are running.

* Use a new object for testing `Admin_Settings::get_setting()`.

* Warning when debug-aspire-update.log doesnt exist (#109)

* `Tests`: Add default coverage settings. (#97)

* Improve I18N Issues Based on version 0.5 (#104)

* Fixes Settings not getting saved when rewrites were turned off (#108)

* Add French Translation (#105)

* I18n fr fr (#113)

* Translations loading fix112 (#114)

* Add French translations. 

* load any available translations with code in the plugin

* #110 (#116)

Fixes #110

* Add nonce verification and sanitize `$_REQUEST/$_GET` values. (#115)

Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>

* Added German Translation (#111)

* added German translation

* added gitignore for .DS_Store


Signed-off-by: Harikrishnan R <harikrishnanr994@gmail.com>

* Voltron has landed. (#117)

The Voltron has landed. See if you can find where.

* `Admin Settings`: Delete all settings when the plugin is uninstalled. (#118)

* `Admin Settings`: Add multisite-safe deletion of all settings.

* Delete all settings when the plugin is uninstalled.

* add multisite support (#102)

* accidentally deleted (#124)

Fixed typo in code deleted when addressing #102

* Add `.editorconfig`. (#123)

* create zip with each new tagged release (#121)

* create zip with each new tagged release

* update .gitattributes

* Cleanup after `.editorconfig` was added to the repository. (#126)

* Add coding standard. (#127)

* Add Coding Standard.

* Add PHPCS cache directory.

* Coding Standards: Apply PHPCBF to codebase.

* Coding Standards: Add GitHub workflow.

---------

Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Co-authored-by: Alex Sirota <alex@newpathconsulting.com>

---------

Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>
Signed-off-by: Alex Sirota <alex@newpathconsulting.com>
Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Signed-off-by: Harikrishnan R <harikrishnanr994@gmail.com>
Co-authored-by: Namith Jawahar <48271037+namithj@users.noreply.github.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Co-authored-by: Alex Lion <learnwithalex@gmail.com>
Co-authored-by: Sébastien SERRE <sebastien@thivinfo.com>
Co-authored-by: Harikrishnan R <harikrishnanr994@gmail.com>
Co-authored-by: Andy Fragen <andy@thefragens.com>
@afragen afragen deleted the multisite branch November 6, 2024 19:45
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
Status: Done
Development

Successfully merging this pull request may close these issues.

Multi site support
4 participants