Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. define ( 'MY_PLUGIN_VERSION', '2.0.0');
  2.  
  3. register_activation_hook(__FILE__, 'my_plugin_activation'));
  4. register_deactivation_hook(__FILE__, 'my_plugin_deactivation'));
  5. function my_plugin_activation() {
  6. // Initialize some stuff for my_plugin
  7. }
  8. function my_plugin_deactivation() {
  9. // Welp, I've been deactivated - are there some things I should clean up?
  10. }
  11.  
  12. function my_plugin_activation() {
  13. $version = get_option( 'my_plugin_version' );
  14.  
  15. if( version_compare($version, '2.0.0', '<')) {
  16. // Do some special things when we update to 2.0.0.
  17. }
  18.  
  19. update_option( 'my_plugin_version', MY_PLUGIN_VERSION );
  20. return MY_PLUGIN_VERSION;
  21. }
  22.  
  23. function my_plugin_is_current_version(){
  24. $version = get_option( 'my_plugin_version' );
  25. return version_compare($version, MY_PLUGIN_VERSION, '=') ? true : false;
  26. }
  27.  
  28. if ( !my_plugin_is_current_version() ) my_plugin_activation();
  29.  
  30. add_action('activated_plugin', 'my_plugin_activation_error');
  31. my_plugin_activation_error() {
  32. file_put_contents( plugin_dir_path(__FILE__) . '/error_activation.html', ob_get_contents());
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement