Can’t activate plugin programmatically
-
Version: 3.0.2
Hi. I’m getting an error when trying to activate the plugin programmatically. I have a site builder tool that builds sites for me, including activating plugins. When I do:
activate_plugin('strong-testimonials/strong-testimonials.php');
I get this error:
Uncaught Error: Class 'Strong_Testimonials_Welcome' not found in /www/wp-content/plugins/strong-testimonials/strong-testimonials.php:162
I think it’s because the ST activation code has this:
new Strong_Testimonials_Welcome(); do_action( 'wpmtst_after_update_setup', $first_install );
However, that class is only
require_once
d ifis_admin()
is true:if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { ... require_once WPMTST_ADMIN . 'about/class-strong-testimonials-welcome.php'; ... }
Even if the class were included, the
wpmtst_after_update_setup
hook does a redirect:wp_safe_redirect( admin_url( 'index.php?page=wpmtst-getting-started' ) ); exit;
This will be equally problematic for a site built programmatically.
My request is, can you rethink your approach on this? It looks like your redirect is for the sake of showing a “Getting Started” page. It only does that if it’s the “first install” (the
wpmtst_db_version
value does not exist in the options table). How about also checking the options table for some value like ‘skip_welcome’, or ‘is_programmatic_activation’, or similar? This will help me out a lot because I build lots of sites programatically. Thanks!
- The topic ‘Can’t activate plugin programmatically’ is closed to new replies.