{"id":15546801,"url":"https://github.com/bernskiold/Block-Plugin-Support","last_synced_at":"2025-08-05T18:31:28.671Z","repository":{"id":62493417,"uuid":"258546484","full_name":"bernskioldmedia/Block-Plugin-Support","owner":"bernskioldmedia","description":"A reusable way of adding block support to a WordPress plugin.","archived":false,"fork":false,"pushed_at":"2022-05-03T09:51:36.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T08:03:43.008Z","etag":null,"topics":["trait","wordpress","wordpress-gutenberg","wordpress-helpers","wordpress-plugin-library"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bernskioldmedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-24T15:10:26.000Z","updated_at":"2022-05-03T09:49:58.000Z","dependencies_parsed_at":"2022-11-02T11:17:27.043Z","dependency_job_id":null,"html_url":"https://github.com/bernskioldmedia/Block-Plugin-Support","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bernskioldmedia%2FBlock-Plugin-Support","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bernskioldmedia%2FBlock-Plugin-Support/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bernskioldmedia%2FBlock-Plugin-Support/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bernskioldmedia%2FBlock-Plugin-Support/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bernskioldmedia","download_url":"https://codeload.github.com/bernskioldmedia/Block-Plugin-Support/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220753127,"owners_count":16697311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["trait","wordpress","wordpress-gutenberg","wordpress-helpers","wordpress-plugin-library"],"created_at":"2024-10-02T13:04:48.674Z","updated_at":"2025-08-05T18:31:28.296Z","avatar_url":"https://github.com/bernskioldmedia.png","language":"PHP","readme":"**THIS REPOSITORY WILL GO INTO READ-ONLY MODE**\n\nWe have integrated this composer package into our wp-plugin-base instead of keeping it separate.\n\n# Block Plugin Support\n\nWe find ourselves increasingly creating a bunch of plugins that add one or more blocks to the block editor.\n\nThis requires a few functions to load and register. And since we use the same scaffold almost any time, it makes sense to split out the block part into a library.\n\nThe library consists of a simple trait for making the plugin support blocks and two abstract classes for a base server-side rendered block.\n\n## Getting started\n\nAll you need to do is include the `Has_Blocks` trait in the plugin class as long as you are using the latest version of our plugin base, which recognizes this trait automatically.\n\nBlocks are assumed to be placed in a `blocks` subfolder, and they are being built to `dist/blocks`.\n\n**This trait relies on an autoloader being used in the plugin!**\n\n```\nuse BernskioldMedia\\WP\\Block_Plugin_Support\\Traits\\Has_Blocks;\n\nclass My_Plugin {\n\n    use Has_Blocks;\n\n}\n```\n\n### Defining a custom block prefix\nThe trait will default to using the 'bm' prefix for blocks. Blocks are named with a prefix to scope them to the project they are a part of. This also influences how the script and style handles are registered ($prefix-block-$block_name).\n\nYour project probably requires its custom prefix. You can set it on the main plugin class like so:\n\n```\nuse BernskioldMedia\\WP\\Block_Plugin_Support\\Traits\\Has_Blocks;\n\nclass My_Plugin {\n\n    use Has_Blocks;\n    \n    // Set my custom block prefix.\n    protected static string $block_prefix = 'my-prefix';\n\n}\n```\n\n## Required Folder Structure\n\nThe trait assumes the following folder structure:\n\n`blocks/` is the location of all blocks with one folder per block. The `index.js` file in each block folder is the entrypoint for the build script.\n\n`dist/blocks` is the location of built JavaScript blocks with the same filename as the main folder name.\n\n`languages/` is the location of the translation files. The handle and domain are both set to `{$block_prefix}-{$block_name}`.\n\n## Required Methods\n\nThe trait relies on two methods to be implemented.\n\n- `get_url()` should return the URL to the plugin directory.\n- `get_path()` should return the path to the plugin directory.\n- `get_textdomain()` should return the string plugin textdomain.\n\n## Hooks \u0026 Filters\n\nWe strive to make all code easily customizable with plenty of filters and hooks as needed. You never know when or why you might need that simple one-off customization.\n\nSince this is a composer package, filters are housed inside of the \"package namespace\" and do not inherit the consumer plugin's own naming structure.\n\n## Filters\n\n`bm_block_support_{$BLOCKNAME}_wrapper_args`. Available for any dynamic block that extends `Block` and is reliant on `Block::$name` being set in the consuming dynamic block class.\nAllows you to customize the args sent to `get_block_wrapper_attributes`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbernskiold%2FBlock-Plugin-Support","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbernskiold%2FBlock-Plugin-Support","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbernskiold%2FBlock-Plugin-Support/lists"}