afragen / wp-dependency-installer

A lightweight class to add to WordPress plugins/themes to automatically install plugin dependencies.
MIT License
205 stars 32 forks source link

Required dependencies installation messages #71

Open davidessayan opened 9 months ago

davidessayan commented 9 months ago

Hello,

First, thank you for this interesting library ! I was just wondering if I did something wrong because when a plugin is required, the auto-installation process shows update messages in a funny way :

image

As you can see, update messages are showing before the "Screen options" button. Is there anything to do about that ?

Thank you !

afragen commented 9 months ago

That's strange. Are there any console errors?

davidessayan commented 9 months ago

Nothing in console unfortunately. Actually, notices are generated before the doctype :

image

This is the way I am running wpdi (from a custom plugin) :

include_once( __DIR__ . '/../vendor/autoload.php' );

$plugins = array( ... );

add_action('plugins_loaded', function() use ($plugins){
    $wpdi = WP_Dependency_Installer::instance( __DIR__ );
    $wpdi->register( $plugins )->run();
});
afragen commented 9 months ago

Can you try testing with a default theme?

davidessayan commented 9 months ago

Of course ! Please find my simple test below :

Context :

WP Version : 6.4.2 Theme : twentytwentyfour Plugins : No plugin / Fresh install

File : functions.php

add_action('init', function () {
    WP_Dependency_Installer::instance( __DIR__ )->run();
});

File : wp-dependencies.json

[
  {
    "name": "Query Monitor",
    "host": "wordpress",
    "slug": "query-monitor/query-monitor.php",
    "uri": "https://wordpress.org/plugins/query-monitor/",
    "required": true
  },
  {
    "name": "Git Updater",
    "host": "github",
    "slug": "git-updater/git-updater.php",
    "uri": "afragen/git-updater",
    "branch": "master",
    "optional": false,
    "token": null
  },
  {
    "name": "Yoast SEO",
    "host": "wordpress",
    "slug": "wordpress-seo/wp-seo.php",
    "uri": "https://fr.wordpress.org/plugins/wordpress-seo/",
    "required": true
  }
]

Result

Notices are showing before the doctype. This seems to happen when the installed plugin needs a translation update :

image

Final result when the document is fully loaded : image

afragen commented 9 months ago

I think you've discovered the issue.

I load the installation messages in the notice but I don't handle translation updates or their messages.

I'm open to PRs if you can figure it out.🙂

davidessayan commented 9 months ago

Ok :)

I guess I may have found a workaround. The problem is that WP_Upgrader_Skin is not silent.

So I had a look of what's happening here : /wp-admin/plugin-install.php

On this page, the installation process use WP_Ajax_Upgrader_Skin which seems to work in our context. With this skin, we no longer have translation messages printed by the Wordpress show_message() function.

Can you please have a look and tell me what do you think about this solution ?

https://github.com/davidessayan/wp-dependency-installer/commit/1fcca91e72a3c2eb06710dc31c1930614d1415b8