Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2. // mu-plugins/theme-features.php
  3. require_once( FEATURES_DIR . '/myfeature.php' );
  4.  
  5.  
  6. // mu-plugins/theme-features/myfeature.php
  7. function features_myfeature_init() {
  8. if ( current_theme_supports( 'myfeature' ) ) {
  9. add_action( 'some_hook', 'features_myfeature' );
  10. }
  11. }
  12.  
  13. add_action( 'wp_loaded', 'features_myfeature_init' );
  14.  
  15. function features_myfeature() {
  16. $defaults = [ 'type' => 'foobar'];
  17. $options = (array) get_theme_support( 'myfeature' );
  18. $options = wp_parse_args( $options, $defaults);
  19.  
  20. // do stuff
  21. echo ($options['type']); // qwerty
  22. }
  23.  
  24.  
  25.  
  26. // theme/functions.php
  27. function mytheme_setup() {
  28. add_theme_support( 'myfeature', ['type' => 'qwerty'] );
  29. }
  30.  
  31. add_action( 'after_setup_theme', 'mytheme_setup' );
  32. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement