{"id":28383834,"url":"https://github.com/cedaro/wp-plugin","last_synced_at":"2025-10-14T10:42:00.661Z","repository":{"id":54814256,"uuid":"46520373","full_name":"cedaro/wp-plugin","owner":"cedaro","description":"A library to help structure and bootstrap WordPress plugins.","archived":false,"fork":false,"pushed_at":"2025-10-01T00:21:06.000Z","size":62,"stargazers_count":42,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-01T02:37:12.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"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/cedaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-11-19T21:07:09.000Z","updated_at":"2025-07-02T23:18:50.000Z","dependencies_parsed_at":"2025-06-25T22:32:06.631Z","dependency_job_id":"dcd4c750-c829-422d-905d-711879d4130a","html_url":"https://github.com/cedaro/wp-plugin","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/cedaro/wp-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedaro%2Fwp-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedaro%2Fwp-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedaro%2Fwp-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedaro%2Fwp-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedaro","download_url":"https://codeload.github.com/cedaro/wp-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedaro%2Fwp-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018785,"owners_count":26086452,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-05-30T07:38:06.406Z","updated_at":"2025-10-14T10:42:00.643Z","avatar_url":"https://github.com/cedaro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Plugin Library\n\nAdds some structure to your WordPress plugins.\n\nRequires PHP 8.0+.\n\n## Installation\n\nTo use this library in your project, add it to `composer.json`:\n\n```sh\ncomposer require cedaro/wp-plugin\n```\n\n## Creating a Plugin\n\nA plugin is a simple object created to help bootstrap functionality by allowing you to easily retrieve plugin information, reference internal files and URLs, and register hooks.\n\n```php\n\u003c?php\n/**\n * Plugin Name: Structure\n */\n\nuse Cedaro\\WP\\Plugin\\PluginFactory;\n\nif ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {\n\trequire( __DIR__ . '/vendor/autoload.php' );\n}\n\n$structure = PluginFactory::create( 'structure' );\n```\n\n`$stucture` is an instance of `Plugin` and implements the `PluginInterface`, which provides a basic API to access information about the plugin.\n\n## Hook Providers\n\nRelated functionality can be encapsulated in a class called a \"hook provider\" that's registered when bootstrapping the plugin.\n\nHook providers allow you to encapsulate related functionality, maintain state without using globals, namespace methods without prefixing functions, limit access to internal methods, and make unit testing easier.\n\nFor an example, the `Cedaro\\WP\\Plugin\\Provider\\I18n` class is a default hook provider that automatically loads the text domain so the plugin can be translated.\n\nThe only requirement for a hook provider is that it should implement the `HookProviderInterface` by defining a method called `register_hooks()`.\n\nHook providers are registered with the main plugin instance by calling `Plugin::register_hooks()` like this:\n\n```php\n\u003c?php\n$structure\n\t-\u003eregister_hooks( new \\Cedaro\\WP\\Plugin\\Provider\\I18n() )\n\t-\u003eregister_hooks( new \\Structure\\PostType\\BookPostType() );\n```\n\nThe `BookPostType` provider might look something like this:\n\n```php\n\u003c?php\nnamespace Structure\\PostType;\n\nuse Cedaro\\WP\\Plugin\\AbstractHookProvider;\n\nclass BookPostType extends AbstractHookProvider {\n\tconst POST_TYPE = 'book';\n\n\tpublic function register_hooks() {\n\t\t$this-\u003eadd_action( 'init', 'register_post_type' );\n\t\t$this-\u003eadd_action( 'init', 'register_meta' );\n\t}\n\n\tprotected function register_post_type() {\n\t\tregister_post_type( static::POST_TYPE, $this-\u003eget_args() );\n\t}\n\n\tprotected function register_meta() {\n\t\tregister_meta( 'post', 'isbn', array(\n\t\t\t'type'              =\u003e 'string',\n\t\t\t'single'            =\u003e true,\n\t\t\t'sanitize_callback' =\u003e 'sanitize_text_field',\n\t\t\t'show_in_rest'      =\u003e true,\n\t\t) );\n\t}\n\n\tprotected function get_args() {\n\t\treturn array(\n\t\t\t'hierarchical'      =\u003e false,\n\t\t\t'public'            =\u003e true,\n\t\t\t'rest_base'         =\u003e 'books',\n\t\t\t'show_ui'           =\u003e true,\n\t\t\t'show_in_menu'      =\u003e true,\n\t\t\t'show_in_nav_menus' =\u003e false,\n\t\t\t'show_in_rest'      =\u003e true,\n\t\t);\n\t}\n}\n```\n\n## Protected Hook Callbacks\n\nIn WordPress, it's only possible to use public methods of a class as hook callbacks, but in the `BookPostType` hook provider above, the callbacks are protected methods of the class.\n\nLocking down the API like that is possible using the `HooksTrait` [developed by John P. Bloch](https://github.com/johnpbloch/wordpress-dev).\n\n## Plugin Awareness\n\nA hook provider may implement the `PluginAwareInterface` to automatically receive a reference to the plugin when its hooks are registered.\n\nFor instance, in this class the `enqueue_assets()` method references the internal `$plugin` property to retrieve the URL to a JavaScript file in the plugin.\n\n```php\n\u003c?php\nnamespace Structure\\Provider;\n\nuse Cedaro\\WP\\Plugin\\AbstractHookProvider;\n\nclass Assets extends AbstractHookProvider {\n\tpublic function register_hooks() {\n\t\t$this-\u003eadd_action( 'wp_enqueue_scripts', 'enqueue_assets' );\n\t}\n\n\tprotected function enqueue_assets() {\n\t\twp_enqueue_script(\n\t\t\t'structure',\n\t\t\t$this-\u003eplugin-\u003eget_url( 'assets/js/structure.js' )\n\t\t);\n\t}\n}\n```\n\nAnother example is the `I18n` provider mentioned earlier. It receives a reference to the plugin object so that it can use the plugin's base name and slug to load the text domain.\n\nClasses that extend `AbstractHookProvider` are automatically \"plugin aware.\"\n\n## License\n\nCopyright (c) 2017 Cedaro, LLC\n\nThis library is licensed under MIT.\n\nAttribution is appreciated, but not required.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedaro%2Fwp-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedaro%2Fwp-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedaro%2Fwp-plugin/lists"}