Skip to content

Commit e0423b4

Browse files
authored
docs: add installation steps for release (#48)
1 parent f55439d commit e0423b4

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

docs/2.getting-started.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,93 @@
11
# 2. Getting Started
22

3-
## Installation Options
3+
## Installation
44

5-
Currently, the Abilities API is available as a WordPress plugin. You can install it by cloning the repository into your `wp-content/plugins` directory.
5+
Until the Abilities API is merged into WordPress core, it must be installed before it can be used.
6+
7+
### As a plugin
8+
9+
The easiest way to try and use the Abilities API is to install it as a plugin by downloading the latest release from the [GitHub Releases page](https://github.com/WordPress/abilities-api/releases/latest).
10+
11+
#### With WP-CLI
612

713
```bash
8-
cd wp-content/plugins
9-
git clone https://github.com/WordPress/abilities-api
14+
wp plugin install https://github.com/WordPress/abilities-api/releases/latest/download/abilities-api.zip
15+
```
16+
17+
#### With WP-Env
18+
19+
```jsonc
20+
// .wp-env.json
21+
{
22+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
23+
// ... other config ...
24+
"plugins": [
25+
"WordPress/abilities-api",
26+
// ... other plugins ...
27+
],
28+
// ... more config ...
29+
}
30+
```
31+
32+
### As a dependency
33+
34+
Plugin authors and developers may wish to rely on the Abilities API as a dependency in their own projects, before it is merged into core. You can do that in one of the following ways.
35+
36+
#### As a Plugin Dependency (Recommended)
37+
38+
The best way to ensure the Abilities API is available for your plugins is to include it as one of your `Requires Plugins` in your [Plugin header](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/). For example:
39+
40+
```diff
41+
# my-plugin.php
42+
/*
43+
*
44+
* Plugin Name: My Plugin
45+
* Plugin URI: https://example.com/plugins/the-basics/
46+
* Description: Handle the basics with this plugin.
47+
* {all the other plugin header fields...}
48+
+ * Requires Plugins: abilities-api
49+
*/
50+
```
51+
52+
While this is enough to ensure the Abilities API is loaded before your plugin, if you need to ensure specific version requirements or provide users guidance on installing the plugin, you can use the methods described [later on](#checking-availability-with-code)
53+
54+
#### As a Composer dependency
55+
56+
```bash
57+
composer require wordpress/abilities-api
58+
```
59+
60+
### Checking availability with code
61+
62+
To ensure the Abilities API is loaded in your plugin:
63+
64+
```php
65+
if ( ! class_exists( 'WP_Ability' ) ) {
66+
// E.g. add an admin notice about the missing dependency.
67+
add_action( 'admin_notices', static function() {
68+
wp_admin_notice(
69+
// If it's a Composer dependency, you might want to suggest running `composer install` instead.
70+
esc_html__( 'This plugin requires the Abilities API to use. Please install and activate it.', 'my-plugin' ),
71+
'error'
72+
);
73+
} );
74+
return;
75+
}
76+
```
77+
78+
You can also check for specific versions of the Abilities API using the `WP_ABILITIES_API_VERSION` constant:
79+
80+
```php
81+
if ( ! defined( 'WP_ABILITIES_API_VERSION' ) || version_compare( WP_ABILITIES_API_VERSION, '0.1.0', '<' ) ) {
82+
// E.g. add an admin notice about the required version.
83+
add_action( 'admin_notices', static function() {
84+
wp_admin_notice(
85+
esc_html__( 'This plugin requires Abilities API version 0.1.0 or higher. Please update the plugin dependency.', 'my-plugin' ),
86+
'error'
87+
);
88+
} );
89+
return;
90+
}
1091
```
1192

1293
## Basic Usage Example

0 commit comments

Comments
 (0)