bobbingwide / oik-unloader

WordPress Must Use plugin to unload unnecessary plugins on demand
GNU General Public License v2.0
0 stars 0 forks source link

Create [active_plugins] shortcode / block #7

Open bobbingwide opened 2 years ago

bobbingwide commented 2 years ago

Using oik-loader and oik-unloader in cwiccer.com I was able to improve or worsen the performance of a post or page by reducing the number of activated plugins to those essential for delivering the post or page. Note:The logic isn't specific to single posts, but it's a lot easier to work on a single post than it is to work on an archive.

The admin interface for oik-unloader is better than the knocked up version for oik-loader but it could be improved significantly were it incorporated into the editor for individual posts and pages.

Requirement

Proposed solution

bobbingwide commented 2 years ago

References

CSS and JS tidy

bobbingwide commented 2 years ago

The [active_plugins] shortcode now displays something like this.

Combination

  1. bbboing/bbboing.php Unloaded
  2. oik-loader/oik-loader.php
  3. oik-unloader/oik-unloader.php
  4. oik/oik.php
  5. sb-post-edit-block/sb-post-edit-block.php
  6. oik-magnetic-poetry/oik-magnetic-poetry.php Loaded

This shows that bbboing was unloaded by oik-unloader and oik-magnetic-poetry was loaded by oik-loader

Note: For a subdirectory install the URL must include the subdirectory entry in C:\apache\htdocs\wp55/wp-content/mu-plugins/oik-unloader.1.csv

/wp55/2022/02/18/active_plugins/,,bbboing/bbboing.php

entry in C:\apache\htdocs\wp55/wp-content/mu-plugins/oik-loader-extras.csv


/wp55/2022/02/18/active_plugins/,0,oik-magnetic-poetry/oik-magnetic-poetry.php
bobbingwide commented 2 years ago

Additional requirements

bobbingwide commented 2 years ago

The first version of the table of plugins in the form is image

This shows:

bobbingwide commented 2 years ago

I'm finding it difficult to decide how to deal with the automatic plugin activation logic in oik-loader.

Proposed solution

bobbingwide commented 2 years ago

Having copied and cobbled class oik_unloader_admin to oik_loader_admin I now realise that when two forms are on the same admin page they need to have unique button names. When they're duplicated the action is performed against both forms. Which isn't what we want at all. Perhaps it would make sense to complete the shortcode logic then apply that to the admin page.

bobbingwide commented 2 years ago

I've added the logic to update the oik-loader-extras from the [active_plugins] shortcode. But since oik-unloader-mu runs after oik-loader-mu the changes are not being detected immediately.

Proposed solution

bobbingwide commented 2 years ago

Consider implementing an oik-loader-mu-reload hook after performing an update.

That worked with 2 lines of code; the do_action in oik_loader_admin::update() and the add_action in the oik-loader-mu plugin file. This only gets invoked when an update has been applied.

There's still the consideration of what to do when the [active_plugins] shortcode is used on a page which automatically generates oik-loader CSV records.

bobbingwide commented 2 years ago

The logic in the active_plugins shortcode should take into account the availability of the oik-loader-mu plugin. If it's not loaded then anything to do with oik-loader shouldn't be shown.

bobbingwide commented 2 years ago

With oik-loader-MU activated.

image

Without oik-loader-MU activated.

image

bobbingwide commented 2 years ago

So, how can we tell that the server response has improved? Well, we can introduce a timings field into the form that keeps the last 10 (or so ) timings and displays them under the form.

It shouldn't be necessary to show what's changed. The user has to have a bit of common sense in order to be able to use this stuff in the first place.

image

bobbingwide commented 2 years ago

Delivered as server side rendered

I implemented the logic to deliver the block as server side rendered.

image

There were two major problems

  1. None of the checkboxes were checked
  2. Clicking on Update activated plugins produced a "Leave site? Changes you made may not be saved" message.

On reload of the post after update

  1. None of the checkboxes were checked
  2. Clicking on Update activated plugins didn't appear to work.

Obviously some more thought needs to be put into this. First thing to do is to investigate 1.

bobbingwide commented 2 years ago
  1. None of the checkboxes were checked

I got this to work by re-enabling the lookup by post ID.

Currently, any entry in the oik-unloader CSV file that doesn't have an ID, but which needs one, must be manually updated. This is not yet possible in either the oik-unloader admin interface or the active_plugins shortcode / block.

bobbingwide commented 2 years ago

Clicking on Update activated plugins didn't appear to work.

It works for Unload but not for Load.

bobbingwide commented 2 years ago

At present changing the plugins to Load replaces the extras file with the latest URL; previous entries are lost.

bobbingwide commented 2 years ago

Note: If you unload the oik-unloader plugin then it disables the oik-unloader/active-plugins block. This confused me for a while on s.b/hm where I'd previously unloaded nearly every plugin on the home page. Also, you have to remember to enable the MU versions of oik-unloader and oik-loader as well.

bobbingwide commented 2 years ago

When oik-loader isn't active the active-plugins block crashes with oik_loader_map_id not found. OIK_Unloader_Active_Plugins_Shortcode::is_oik_loader_mu_loaded should also check for oik_loader_map_id

bobbingwide commented 2 years ago

When the server rendered block is displayed the checkboxes and Update activated plugins button should only be enabled when the user has the authority to update them. When the user's not logged in the button's not displayed but the checkboxes are still enabled.