tsu_newsletter_block.php 839 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // Register Newsletter Custom Post Type
  3. require 'tsu_newsletter_custom_post.php';
  4. // Register Custom Block Category
  5. add_filter( 'block_categories_all', function($categories) {
  6. // Set Category Slug
  7. $new_slug = 'tsu-category';
  8. // Set Category Title
  9. $new_title = 'To się uda';
  10. $has_category = false;
  11. foreach($categories as $category) {
  12. if($category === [ 'slug' => $new_slug, 'title' => $new_title]) {
  13. $has_category = true;
  14. }
  15. }
  16. if(!$has_category) {
  17. $categories[] = array(
  18. 'slug' => $new_slug,
  19. 'title' => $new_title
  20. );
  21. };
  22. return $categories;
  23. });
  24. // Register Newsletter Custom Block
  25. add_action( 'init', 'add_newsletter_block' );
  26. function add_newsletter_block() {
  27. register_block_type( __DIR__ . '/build' );
  28. }