Advertisement
Guest User

my-plugin.php

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: My Plugin
  4. Plugin URI: https://stackoverflow.com/q/48890836/9217760
  5. Description: Just a simple test plugin.
  6. Version: 20180221.1
  7. */
  8.  
  9. // Either of these worked for me.
  10. /*global $my_vars;
  11. $my_vars = '1';*/
  12. $GLOBALS['my_vars'] = '1';
  13.  
  14. // THIS IS REALLY JUST A TEST. =)
  15. function my_plugin_option( $name ) {
  16.     if ( 'my_vars' === $name ) {
  17.         return '1';
  18.     }
  19. }
  20.  
  21. // You'll need to turn on WP_DEBUG and WP_DEBUG_LOG; then see wp-content/debug.log
  22. // after plugin activation.
  23. register_activation_hook( __FILE__, 'my_plugin_activation' );
  24. function my_plugin_activation() {
  25.     global $my_vars;
  26.  
  27.     error_log( var_export( $my_vars, true ) );  // NULL if $my_vars wasn't defined with "global" or $GLOBALS
  28.     error_log( my_plugin_option( 'my_vars' ) ); // 1
  29.  
  30.     error_log( '"My Plugin" has been activated.' );
  31. }
  32.  
  33. // You'll need to turn on WP_DEBUG and WP_DEBUG_LOG; then see wp-content/debug.log
  34. // after plugin deactivation.
  35. register_deactivation_hook( __FILE__, 'my_plugin_deactivation' );
  36. function my_plugin_deactivation() {
  37.     error_log( '"My Plugin" has been deactivated.' );
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement