tsu-financial-progress-block.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Plugin Name: Tsu Financial Progress Block
  4. * Description: Example block scaffolded with Create Block tool.
  5. * Requires at least: 6.1
  6. * Requires PHP: 7.0
  7. * Version: 0.1.0
  8. * Author: The WordPress Contributors
  9. * License: GPL-2.0-or-later
  10. * License URI: https://www.gnu.org/licenses/gpl-2.0.html
  11. * Text Domain: tsu-financial-progress-block
  12. *
  13. * @package create-block
  14. */
  15. if ( ! defined( 'ABSPATH' ) ) {
  16. exit; // Exit if accessed directly.
  17. }
  18. // Register Custom Block Category
  19. add_filter( 'block_categories_all', function($categories) {
  20. // Set Category Slug
  21. $new_slug = 'tsu-category';
  22. // Set Category Title
  23. $new_title = 'To się uda';
  24. $has_category = false;
  25. foreach($categories as $category) {
  26. if($category === [ 'slug' => $new_slug, 'title' => $new_title]) {
  27. $has_category = true;
  28. }
  29. }
  30. if(!$has_category) {
  31. $categories[] = array(
  32. 'slug' => $new_slug,
  33. 'title' => $new_title
  34. );
  35. };
  36. return $categories;
  37. });
  38. /**
  39. * Registers the block using the metadata loaded from the `block.json` file.
  40. * Behind the scenes, it registers also all assets so they can be enqueued
  41. * through the block editor in the corresponding context.
  42. *
  43. * @see https://developer.wordpress.org/reference/functions/register_block_type/
  44. */
  45. function tsu_financial_progress_block_tsu_financial_progress_block_block_init() {
  46. register_block_type( __DIR__ . '/build' );
  47. }
  48. add_action( 'init', 'tsu_financial_progress_block_tsu_financial_progress_block_block_init' );