Skip to content

Commit c4d3c17

Browse files
committed
Chore: Configure the composer package for publishing
1 parent 2da7f46 commit c4d3c17

File tree

6 files changed

+112
-37
lines changed

6 files changed

+112
-37
lines changed

.gitattributes

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Automatically normalize line endings.
2+
* text=auto
3+
4+
# Files and directories to exclude from the generated archive (export-ignore).
5+
# These will be omitted from GitHub/Packagist ZIP archives to keep packages small.
6+
7+
# Tests and test fixtures
8+
/tests/ export-ignore
9+
/tests/** export-ignore
10+
11+
# PHP unit / static analysis configs.
12+
/phpcs.xml.dist export-ignore
13+
/phpstan.neon.dist export-ignore
14+
/phpunit.xml.dist export-ignore
15+
16+
# Continuous Integration configs.
17+
/.github/ export-ignore
18+
/.github/** export-ignore
19+
20+
# Node and build artifacts.
21+
node_modules/ export-ignore
22+
node_modules/** export-ignore
23+
package.json export-ignore
24+
package-lock.json export-ignore
25+
26+
# Composer/vendor and dev tooling.
27+
/vendor/ export-ignore
28+
/vendor/** export-ignore
29+
/composer.lock export-ignore
30+
31+
# Don't include the dotfiles for distribution.
32+
/.editorconfig export-ignore
33+
/.gitattributes export-ignore
34+
.gitignore export-ignore
35+
.gitkeep export-ignore
36+
/.nvmrc export-ignore
37+
/.prettierignore export-ignore
38+
/.prettierrc.js export-ignore
39+
/.wp-env.json export-ignore
40+
41+
# Mark docs as documentation for GitHub Linguist.
42+
/docs/** linguist-documentation
43+
/CONTRIBUTING.md linguist-documentation
44+
/LICENSE.md linguist-documentation
45+
/README.md linguist-documentation

abilities-api.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,17 @@
2727
define( 'WP_ABILITIES_API_DIR', plugin_dir_path( __FILE__ ) );
2828

2929
/**
30-
* Version of the plugin.
30+
* Prefer Composer autoloader when available. If present, it will load
31+
* `includes/bootstrap.php` (registered in composer.json) which makes the
32+
* procedural functions and classes available. Otherwise fall back to the
33+
* local includes bootstrap to keep compatibility with non-Composer installs.
3134
*/
32-
define( 'WP_ABILITIES_API_VERSION', '0.1.0' );
35+
if ( file_exists( WP_ABILITIES_API_DIR . 'vendor/autoload.php' ) ) {
36+
require_once WP_ABILITIES_API_DIR . 'vendor/autoload.php';
37+
} else {
38+
require_once WP_ABILITIES_API_DIR . 'includes/bootstrap.php';
39+
}
3340

34-
/**
35-
* First the WP_Ability class that users can extend.
36-
*/
37-
require_once WP_ABILITIES_API_DIR . 'includes/abilities-api/class-wp-ability.php';
38-
39-
/**
40-
* Then the WP_Abilities_Registry class that manages the abilities.
41-
*/
42-
require_once WP_ABILITIES_API_DIR . 'includes/abilities-api/class-wp-abilities-registry.php';
43-
44-
/**
45-
* Then the public access functions that users can use to interact with the abilities.
46-
*/
47-
require_once WP_ABILITIES_API_DIR . 'includes/abilities-api.php';
48-
49-
/**
50-
* Initialize REST API controllers.
51-
*/
52-
require_once WP_ABILITIES_API_DIR . 'includes/rest-api/class-wp-rest-abilities-init.php';
41+
if ( function_exists( 'add_action' ) ) {
42+
add_action( 'rest_api_init', array( 'WP_REST_Abilities_Init', 'register_routes' ) );
43+
}

composer.json

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
{
22
"name": "wordpress/abilities-api",
3-
"description": "AI Abilities for WordPress",
3+
"description": "AI Abilities for WordPress.",
44
"license": "GPL-2.0-or-later",
55
"type": "wordpress-plugin",
6-
"version": "0.1.0",
76
"keywords": [
87
"ai",
8+
"api",
99
"llm",
1010
"abilities",
11-
"abilities-api",
1211
"wordpress"
1312
],
14-
"homepage": "https://github.com/WordPress/abilities-api/issues",
13+
"authors": [
14+
{
15+
"name": "WordPress AI Team",
16+
"homepage": "https://make.wordpress.org/ai/"
17+
}
18+
],
19+
"homepage": "https://github.com/WordPress/abilities-api",
1520
"support": {
16-
"issues": "https://github.com/WordPress/abilities-api/issues"
21+
"issues": "https://github.com/WordPress/abilities-api/issues",
22+
"source": "https://github.com/WordPress/abilities-api"
23+
},
24+
"minimum-stability": "dev",
25+
"prefer-stable": true,
26+
"autoload": {
27+
"files": [
28+
"includes/bootstrap.php"
29+
]
1730
},
1831
"config": {
19-
"sort-packages": true,
20-
"platform": {
21-
"php": "7.4"
22-
},
2332
"allow-plugins": {
2433
"dealerdirect/phpcodesniffer-composer-installer": true,
2534
"phpstan/extension-installer": true,
2635
"composer/installers": true
27-
}
36+
},
37+
"platform": {
38+
"php": "7.4"
39+
},
40+
"sort-packages": true
2841
},
29-
"minimum-stability": "dev",
30-
"prefer-stable": true,
3142
"repositories": [
3243
{
3344
"type": "composer",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/bootstrap.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Abilities API - Composer bootstrap
4+
*
5+
* This file is autoloaded by Composer when the package is installed via the
6+
* "files" autoload mechanism. It ensures the procedural functions defined in
7+
* `includes/abilities-api.php` are available without requiring namespaces.
8+
*
9+
* Keep this file simple and side-effect free except for requiring the functions
10+
* file.
11+
*/
12+
13+
// Load core classes if they are not already defined (for non-Composer installs or direct includes).
14+
if ( ! class_exists( 'WP_Ability' ) ) {
15+
require_once __DIR__ . '/abilities-api/class-wp-ability.php';
16+
}
17+
18+
if ( ! class_exists( 'WP_Abilities_Registry' ) ) {
19+
require_once __DIR__ . '/abilities-api/class-wp-abilities-registry.php';
20+
}
21+
22+
// Ensure procedural functions are available.
23+
if ( ! function_exists( 'wp_register_ability' ) ) {
24+
require_once __DIR__ . '/abilities-api.php';
25+
}
26+
27+
// Load REST API init class for plugin bootstrap.
28+
if ( ! class_exists( 'WP_REST_Abilities_Init' ) ) {
29+
require_once __DIR__ . '/rest-api/class-wp-rest-abilities-init.php';
30+
}

includes/rest-api/class-wp-rest-abilities-init.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@ public static function register_routes(): void {
3131
$list_controller->register_routes();
3232
}
3333
}
34-
35-
add_action( 'rest_api_init', array( 'WP_REST_Abilities_Init', 'register_routes' ) );

0 commit comments

Comments
 (0)