Add additional admin notice on plugin activation in OOP
-
I am using plugin boilerplate to create a plugin and would like to add a message on plugin activation, instead of or under the ‘Plugin activated’ notice.
I’ve tried every solution here, but nothing worked.
I have
register_activation_hook( __FILE__, 'activate_plugin' ); function activate_plugin() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-activator.php'; Plugin_Activator::activate(); }
I tried to implement this solution like this
register_activation_hook( __FILE__, 'activate_plugin' ); function activate_plugin() { require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-activator.php'; Plugin_Activator::activate(); add_action( 'load-plugins.php', function() { add_filter( 'gettext', Plugin_Activator::change_plugin_text(), 99, 3 ); } ); }
In my class-plugin-activator.php file in Plugin_Activator class I have public static function activate() method that works (things get written in the db), and I created
public static function change_plugin_text( $translated_text, $untranslated_text, $domain ) { $old = array( 'Plugin <strong>activated</strong>.', 'Selected plugins <strong>activated</strong>.', ); $new = '<div class="notice notice-success is-dismissible"><p>' . __( 'This is my custom notice.' ) . '</p></div>'; if ( in_array( $untranslated_text, $old, true ) ) { $translated_text = $new; remove_filter( current_filter(), __FUNCTION__, 99 ); } return $translated_text; }
But this is not working. So what am I doing wrong?
How can I add admin notice in OOP way when activating a plugin?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Add additional admin notice on plugin activation in OOP’ is closed to new replies.