plugins – Why is my activator class adding the files/running the actions I add?
Question
I am using the WP Plugin Boilerplate to develop a plugin, but when I activate the plugin, the require files and actions I put inside the activate()
function are not working. I have tested the class and method by using die('Plugin error')
and it should this message so I am not sure as to why the the other statements aren’t working. There is also no PHP error being thrown.
class Wp_Portfolio_Pro_Activator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
// Require Kirki and setting for plugin build on framework.
self::load_files();
add_action( 'admin_notices', array( __CLASS__, 'admin_notice' ) );
}
public static function admin_notice() {
$message="<div class="notice notice-success"><p>";
$message .= sprintf( __( 'Hello %s!', 'my-plugin' ), '<strong>' . get_current_user_name() . '</strong>' );
$message .= '</p><p>';
$message .= __( 'Thank you for downloading WP Portfolio Pro. Edit the setting from the customizer.', 'wp-portfolio-pro' );
$message .= '</p>';
$message .= '<a href="' . esc_url( admin_url( 'customize.php?customize_changeset_uuid=' . get_theme_mods_changeset_post_id() ) ) . '"><button>Go to settings</button></a></div>';
echo $message;
printf( '<div class="notice notice-success is-dismissible">%1$s</div>', $message );
}
public static function load_files() {
// Require Kirki and setting for plugin build on framework.
require_once plugin_dir_path( __FILE__ ) . 'includes/kirki/kirki.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/wp-portfolio-pro-kirki.php';
}
}
This is the code in the main file that calls the class and runs the activate method:
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-wp-portfolio-pro-activator.php
*/
function activate_wp_portfolio_pro() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-portfolio-pro-activator.php';
Wp_Portfolio_Pro_Activator::activate();
}
register_activation_hook( __FILE__, 'activate_wp_portfolio_pro' );
0
3 weeks
2023-02-27T15:22:30-05:00
2023-02-27T15:22:30-05:00 0 Answers
0 views
0
Leave an answer