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

Studio: Add config constants to mu-plugins #766

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

katinthehatsite
Copy link
Contributor

@katinthehatsite katinthehatsite commented Jan 3, 2025

Related issues

Closes https://github.com/Automattic/dotcom-forge/issues/10148

Proposed Changes

This PR adds polyfill to mu-plugins for database constants in case they are not defined in the wp-config.php file when it is being imported. This ensures that the database constants are defined at all times.

Testing Instructions

  • Pull the changes from this branch
  • Download a backup from this site: https://mc.a8c.com/rewind/debugger.php?site=138657400
  • Navigate to Import/Export tab in Studio
  • Drop this backup to import it into a site
  • Observe that the import succeeds and the site starts successfully
  • Navigate to wp-admin/plugins.php?plugin_status=mustuse and confirm that the 0-wp-config-constants-polyfill.php plugin is present there

Alternatively, you can export a Studio site, edit wp-config.php file and remove the constants such as DB_HOST etc. from that file. You can then attempt to import it and confirm that the import succeeds and that the site starts successfully.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@wojtekn
Copy link
Contributor

wojtekn commented Jan 3, 2025

@katinthehatsite the code change looks clear, and it fixes the issue for such sites.

`<?php
// Define database constants if not already defined. It fixes the error
// for imported sites that don't have those defined e.g. WP Cloud and
// include plugins which try to access those directly e.g. Mailpoet
Copy link
Contributor

Choose a reason for hiding this comment

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

I updated the comment to clearly state what is the purpose of the polyfill.

@wojtekn wojtekn merged commit 2a676e9 into trunk Jan 3, 2025
6 checks passed
@wojtekn wojtekn deleted the add/mu-plugin-polyfills-for-undefined-constants branch January 3, 2025 09:07
@ivan-ottinger
Copy link
Contributor

I have reviewed and tested this PR as well and it is working as expected. The mu plugin is getting added and makes sure the missing constants are defined. 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants