Skip to content

Commit 8925f90

Browse files
racmanuelpriethor
andauthored
Add composer installation to docs/welcome (#99)
* Add composer installation to docs/welcome * docs: update SCF installation guide with Composer integration, benefits, and optional admin menu and update notification hiding docs: update SCF installation guide with Composer integration, benefits, and optional admin menu and update notification hiding * Update docs/welcome/installation.md let's not take for granted that readers are familiar with Composer Co-authored-by: Héctor <27339341+priethor@users.noreply.github.com> * Update docs/welcome/installation.md avoid potential conflicts between Composer and the built-in updater Co-authored-by: Héctor <27339341+priethor@users.noreply.github.com> --------- Co-authored-by: Héctor <27339341+priethor@users.noreply.github.com>
1 parent 4b1c987 commit 8925f90

File tree

1 file changed

+125
-4
lines changed

1 file changed

+125
-4
lines changed

docs/welcome/installation.md

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,132 @@ Before installing, ensure your site meets these requirements:
2626
2. Extract the plugin files
2727
3. Upload the plugin folder to `/wp-content/plugins/`
2828
4. Activate through the WordPress admin interface
29+
---
2930

30-
## Verification
31+
### Composer Installation
32+
33+
To install and manage Secure Custom Fields in your WordPress theme or plugin, it is recommended to use Composer.
34+
35+
This ensures that SCF is properly versioned, loaded automatically, and easy to update.
36+
37+
### Why integrate **Secure Custom Fields (SCF)** with Composer?
38+
39+
Integrating SCF using Composer offers several important advantages for the professional development of WordPress plugins and themes:
40+
41+
- **Centralized dependency management:**
42+
Composer allows you to declare, install, and update SCF easily along with other libraries needed in your project.
43+
44+
- **Version control:**
45+
You can lock a specific version of SCF in your `composer.json`, ensuring that all development and production environments use exactly the same version, avoiding unexpected errors.
46+
47+
- **Simplified deployment and automation (CI/CD):**
48+
Composer installs SCF automatically during deployment processes (`composer install`), eliminating the need to manually copy files.
49+
50+
- **Automatic autoloading:**
51+
Composer handles PHP class autoloading. Integrating SCF this way makes your code cleaner, safer, and PSR-4 compliant.
52+
53+
- **Reduced repository size:**
54+
By installing SCF as an external dependency, you avoid having redundant copies of the plugin in your project, keeping your repository lighter and easier to maintain.
55+
56+
- **License compliance:**
57+
Composer records the licenses of all dependencies used, which is very useful if you distribute your plugins or themes and need to meet legal or auditing requirements.
58+
59+
- **Facilitates project changes:**
60+
By managing SCF as a dependency, any theme or plugin can change its structure or installation system without affecting its functionality, ensuring greater flexibility and compatibility in development.
61+
62+
---
63+
64+
### How to Load and Use **Secure Custom Fields (SCF)** with Composer
65+
66+
Add the following configuration to your `composer.json` file:
67+
68+
```json
69+
{
70+
"repositories": [
71+
{
72+
"type": "composer",
73+
"url": "https://wpackagist.org"
74+
}
75+
],
76+
"extra": {
77+
"installer-paths": {
78+
"vendor/{$name}/": ["type:wordpress-plugin"]
79+
}
80+
},
81+
"require": {
82+
"wpackagist-plugin/secure-custom-fields": "^6.4"
83+
},
84+
"config": {
85+
"allow-plugins": {
86+
"composer/installers": true
87+
}
88+
}
89+
}
90+
```
91+
Once the configuration is set, run the following command in your terminal to install the dependencies:
92+
```shell
93+
composer install
94+
```
95+
or
96+
```shell
97+
composer i
98+
```
99+
---
100+
### Add the Composer Autoloader
101+
To ensure Composer dependencies are loaded correctly, add the following line in your plugin or theme:
102+
```php
103+
require_once plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php';
104+
```
105+
### Load Secure Custom Fields
106+
Now you need to manually load the Secure Custom Fields plugin and define its paths. Adjust the paths according to the structure of your plugin or theme:
107+
```php
108+
if (! class_exists('ACF')) {
109+
// Define the path and URL to the Secure Custom Fields plugin.
110+
define('MY_SCF_PATH', plugin_dir_path(dirname(__FILE__)) . 'vendor/secure-custom-fields/');
111+
define('MY_SCF_URL', plugin_dir_url(dirname(__FILE__)) . 'vendor/secure-custom-fields/');
112+
113+
// Include the plugin main file.
114+
require_once MY_SCF_PATH . 'secure-custom-fields.php';
115+
}
116+
```
117+
⚠️ **Note:** Replace MY_SCF_PATH and MY_SCF_URL with constants that match your plugin/theme structure if necessary.
118+
119+
### Done!
120+
You have successfully installed and integrated Secure Custom Fields via Composer. You can now use it as you would with a normal installation, but with all the benefits of Composer-based dependency management.
121+
122+
---
123+
124+
### Optional: Hide SCF Admin Menu and Updates
125+
126+
If you want to hide the **Secure Custom Fields (SCF)** admin menu from the WordPress dashboard and prevent the plugin's update notifications from appearing, you can use the following code:
127+
128+
```php
129+
// Hide the SCF admin menu item.
130+
add_filter( 'acf/settings/show_admin', '__return_false' );
131+
132+
// Hide the SCF Updates menu.
133+
add_filter( 'acf/settings/show_updates', '__return_false', 100 );
134+
```
135+
#### What does this do?
136+
137+
- **Hide Admin Menu:**
138+
The first filter disables the SCF menu in the WordPress admin area, preventing users from accessing SCF field groups or settings.
139+
140+
- **Hide Update Notifications:**
141+
The second filter disables the SCF update notices, so users won't see update prompts for the plugin inside the admin dashboard.
142+
143+
#### When should you use it?
144+
145+
- If you are bundling SCF inside your plugin or theme and want to **control all the custom fields yourself** without allowing clients or users to modify them.
146+
- If you want to **maintain full control** over SCF versions and updates to avoid compatibility issues caused by manual updates.
147+
148+
> **Note:** Hiding updates means you are responsible for manually updating SCF when necessary to keep your project secure and compatible, but it also helps avoid potential conflicts between Composer and the built-in updater.
149+
150+
151+
## Verify Your Installation
31152

32153
After installation:
33154

34-
1. Navigate to Custom Fields in your admin menu
35-
2. Verify you can access all plugin features
36-
3. Create a test field group to ensure functionality
155+
1. Navigate to **Secure Custom Fields** in your WordPress admin menu.
156+
2. Verify that you can access all **Secure Custom Fields** plugin features.
157+
3. Create a **test field group** to ensure that fields are saved and displayed correctly.

0 commit comments

Comments
 (0)