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_once
are 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.php
and 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
/wp-admin/plugins.php?activate=true
.
Your 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:
- Run
load_files()
on every request. In the WP Plugin Boilerplate there is already aload_dependencies()
method of thePlugin_Name
class that seems to be intended for loading files. - Run your
add_action()
foradmin_notices
on every request. In the boilerplate thedefine_admin_hooks()
method of thePlugin_Name
class seems the appropriate place for this. In youradmin_notices
method you will need to implement logic to hide the notice if it’s been dismissed.