Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. If you look at the top of setup.php you’ll see
  2.  
  3. <?php
  4.  
  5. namespace App;
  6.  
  7. ?>
  8.  
  9. This means that setup.php is in the App namespace. Whenever you pass callbacks to add_action or add_filter or whatever you must include the namespace. You can write the whole thing out, but in this context the easiest way is to use the __NAMESPACE__ magic constant. So something like this:
  10.  
  11. <?php
  12.  
  13. if( function_exists('acf_register_block_type') ) {
  14. add_action('acf/init', __NAMESPACE__.'\\register_acf_block_types');
  15. }
  16.  
  17. ?>
  18. If you don’t anticipate needing to un-hook that action later, you can do what many of us do and pass an anonymous function as a callback instead:
  19.  
  20. <?php
  21.  
  22. if( function_exists('acf_register_block_type') ) {
  23. add_action('acf/init', function() {
  24.  
  25. // register a testimonial block.
  26. acf_register_block_type(array(
  27. 'name' => 'testimonial',
  28. 'title' => __('Testimonial'),
  29. 'description' => __('A custom testimonial block.'),
  30. 'render_template' => 'app/Blocks/Testimonial/testimonial.php',
  31. 'category' => 'formatting',
  32. 'icon' => 'admin-comments',
  33. 'keywords' => array( 'testimonial', 'quote' ),
  34. ));
  35. });
  36. }
  37.  
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement