equalizedigital / accessibility-checker

GNU General Public License v2.0
14 stars 8 forks source link

Activation and Deactivation callbacks compatible with WPVIP #257

Closed SteveJonesDev closed 2 months ago

SteveJonesDev commented 1 year ago

I've asked for clarification from WPVIP on this but haven't received it yet. This is what I got from ChatGPT.


WordPress VIP Activation and Deactivation Callbacks

WordPress VIP (often referred to as WP VIP) is a managed hosting platform for WordPress. It has specific rules and best practices for ensuring performance, security, and scalability for high-traffic websites.

Constraints on WP VIP:

On many WordPress installations, it's standard to use activation and deactivation hooks for setting up or cleaning processes. These are:

However, on WP VIP, these hooks don't typically fire because plugins are often set as "must-use" plugins (stored in the mu-plugins directory), which are auto-loaded.

Affected Patterns on WP VIP:

  1. Database Operations: Plugins creating or altering database tables upon activation won't work as intended. Ensure database operations are handled gracefully on runtime or via another mechanism.
  2. Option Initialization: Setting default options on activation won't function. Check for option existence during runtime and set if they don't exist.
  3. Scheduled Events: Events scheduled on activation need a different strategy. Check if events are scheduled at runtime and schedule if not.
  4. File Operations: Default directories or files created on activation need rethinking.
  5. Cleanup on Deactivation: Given deactivation hooks don't run, an alternative cleanup strategy is essential.

Recommendations:


amberhinds commented 1 year ago

I wonder if Gary knows the answer to this.

On Tue, Aug 29, 2023, 9:36 PM Steve Jones @.***> wrote:

I've asked for clarification from WPVIP on this but haven't received it yet. This is what I got from ChatGPT.

WordPress VIP Activation and Deactivation Callbacks

WordPress VIP (often referred to as WP VIP) is a managed hosting platform for WordPress. It has specific rules and best practices for ensuring performance, security, and scalability for high-traffic websites. Constraints on WP VIP:

On many WordPress installations, it's standard to use activation and deactivation hooks for setting up or cleaning processes. These are:

  • register_activation_hook()
  • register_deactivation_hook()

However, on WP VIP, these hooks don't typically fire because plugins are often set as "must-use" plugins (stored in the mu-plugins directory), which are auto-loaded. Affected Patterns on WP VIP:

  1. Database Operations: Plugins creating or altering database tables upon activation won't work as intended. Ensure database operations are handled gracefully on runtime or via another mechanism.
  2. Option Initialization: Setting default options on activation won't function. Check for option existence during runtime and set if they don't exist.
  3. Scheduled Events: Events scheduled on activation need a different strategy. Check if events are scheduled at runtime and schedule if not.
  4. File Operations: Default directories or files created on activation need rethinking.
  5. Cleanup on Deactivation: Given deactivation hooks don't run, an alternative cleanup strategy is essential.

Recommendations:

  • Utilize hooks like init or plugins_loaded to check and setup necessary components. Optimize to avoid performance hits.
  • Be cautious with is_plugin_active(). It might return misleading results for must-use plugins.
  • Consider an admin tool or WP-CLI command for cleanup instead of relying on deactivation.
  • Always consult the WordPress VIP documentation https://docs.wpvip.com/ and heed their code review feedback.

— Reply to this email directly, view it on GitHub https://github.com/equalizedigital/accessibility-checker/issues/257, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADELJMH6OSAXDCNKDVC5UEDXX2RJFANCNFSM6AAAAAA4D2FS6A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

SteveJonesDev commented 1 year ago

Good call @amberhinds. I'm pretty sure the explanation above is correct, but I'll see if Gary can confirm.

boonedev commented 1 year ago

Here's what I've found:

  1. VIP supports manually activating a plugin through the dashboard, but recommends against it
  2. Instead, they recommend activating the plugin by code using this VIP specific file:/client-mu-plugins/plugin-loader.php, ie:
/**
 * Activate the plugin located in `/plugins/plugin-name`.
 */
wpcom_vip_load_plugin( 'plugin-name' );

3) Activating by code using wpcom_vip_load_plugin() though doesn't fire the register_activation_hook(), which means edac_activation() and edacp_pro_activation() won't fire. see: https://docs.wpvip.com/how-tos/activate-plugins-through-code/#h-plugins-that-require-an-activation-hook

4) The docs seem to indicate there is a workaround, but aren't very clear what it is: https://docs.wpvip.com/how-tos/activate-plugins-through-code/#h-activating-plugins-through-code-in-a-theme-or-plugin.

I'm reading it as: 1) VIP users should not use /client-mu-plugins/plugin-loader to activate the plugin 2) Instead, activate the plugin thru the dashboard as normal 3) Then in edac_activation and edacp_pro_activation, if on VIP, run wpcom_vip_load_plugin() 4) I don't know what happens if the user decides to go with the /client-mu-plugins/plugin-loader

Also found: https://github.com/Yoast/wordpress-seo/issues/7702

I'm happy to take a stab at it, but I'm not certain this fixes like VIP wants.

@amberhinds @SteveJonesDev What do y'all think?

SteveJonesDev commented 1 year ago

I've asked for direct feedback from VIP twice. Let's put this on hold until we get an official answer.

SteveJonesDev commented 2 months ago

Issue moved to our internal system.