You code is almost certainly loading those files and adding the notice, but you’ve misunderstood how PHP works so they’re not happening when you expect them to happen.
You need to keep two things in mind with PHP:
- Admin notices and
require_onceare not persistent across multiple requests. If you want to load a file or display a notice you need to run that code for every request for which you want the notice to appear or the files to be loaded.
- Your plugin code will run for every page request in the browser, but the activation hook will only run once: when the plugin is activated.
So keep those in mind when you consider the sequence of activating a plugin through the UI:
- You visit
wp-admin/plugins.phpand click Activate on a plugin.
- You are taken to
/wp-admin/plugins.php?action=activate&plugin=plugin-name.php, where the plugin is activated.
- You are redirected back to to
activate() method is only going to run for step 2. This means that the framework you’re trying to load is only going to load during step 2, and your notice is only going to be during step 2.
So you need to do 2 things:
load_files()on every request. In the WP Plugin Boilerplate there is already a
load_dependencies()method of the
Plugin_Nameclass that seems to be intended for loading files.
- Run your
admin_noticeson every request. In the boilerplate the
define_admin_hooks()method of the
Plugin_Nameclass seems the appropriate place for this. In your
admin_noticesmethod you will need to implement logic to hide the notice if it’s been dismissed.