Skip to content

Commit 26db9ff

Browse files
authored
Merge pull request #1157 from PatelUtkarsh/feature/local-wp-env-setup
Add wp-env local development environment
2 parents 2786523 + 1fab9ba commit 26db9ff

File tree

7 files changed

+9516
-4906
lines changed

7 files changed

+9516
-4906
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ coverage/html/
4040
# ENV files
4141
.env
4242

43-
# wp-env
44-
.wp-env.json
43+
# wp-env personal overrides
44+
.wp-env.override.json
4545

4646
# IDE
4747
.vscode

.wp-env.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"core": "WordPress/WordPress#6.9.4",
3+
"phpVersion": "8.2",
4+
"plugins": ["."],
5+
"config": {
6+
"WP_DEBUG": true,
7+
"WP_DEBUG_LOG": true,
8+
"SCRIPT_DEBUG": true
9+
},
10+
"mappings": {
11+
"wp-content/mu-plugins": "./.wp-env/mu-plugins"
12+
},
13+
"lifecycleScripts": {
14+
"afterStart": "./.wp-env/scripts/fix-loopback.sh"
15+
},
16+
"env": {
17+
"tests": {
18+
"phpVersion": "8.2",
19+
"config": {
20+
"WP_DEBUG": true,
21+
"WP_DEBUG_LOG": true,
22+
"SCRIPT_DEBUG": true
23+
}
24+
}
25+
}
26+
}

.wp-env/mu-plugins/.gitkeep

Whitespace-only changes.

.wp-env/scripts/fix-loopback.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Fix loopback requests in wp-env Docker environment.
3+
#
4+
# WordPress in wp-env thinks its URL is localhost:8888, but inside the
5+
# container Apache only listens on port 80. This causes self-pinging
6+
# REST API requests (used by Cloudinary's sync daemon) to fail with
7+
# cURL error 7. Adding port 8888 to Apache resolves this.
8+
#
9+
# This script finds the wp-env WordPress container and configures Apache
10+
# to also listen on port 8888, enabling loopback requests to succeed.
11+
12+
# Find the wp-env wordpress container (exclude tests container).
13+
CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'wordpress-1$' | grep -v tests | head -1)
14+
15+
if [ -z "$CONTAINER" ]; then
16+
echo "Warning: Could not find wp-env WordPress container. Loopback fix skipped."
17+
exit 0
18+
fi
19+
20+
# Add Listen 8888 if not already present, then graceful restart Apache.
21+
docker exec "$CONTAINER" bash -c \
22+
"grep -q 'Listen 8888' /etc/apache2/ports.conf || (echo 'Listen 8888' >> /etc/apache2/ports.conf && apache2ctl graceful)" 2>/dev/null
23+
24+
if [ $? -eq 0 ]; then
25+
echo "Loopback fix applied: Apache now also listens on port 8888 inside the container."
26+
else
27+
echo "Warning: Failed to apply loopback fix."
28+
fi

README.md

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cloudinary's WordPress Plugin
22

3-
Cloudinary is a cloud service that offers a solution to a web application's entire image and video management pipeline.
3+
Cloudinary is a cloud service that offers a solution to a web application's entire image and video management pipeline.
44
With Cloudinary, all your images are automatically uploaded, normalized, optimized and backed-up in the cloud instead of being hosted on your servers.
55

66
With Cloudinary, you can stop messing around with image editors. Cloudinary can manipulate and transform your images online, on-the-fly, directly from your WordPress console. Enhance your images using every possible filter and effect you can think of. All manipulations are done in the cloud using super-powerful hardware, and all resulting images are cached, optimized (smushed and more) and delivered via a lightning fast content delivery network (CDN).
@@ -12,20 +12,18 @@ The plugin is publicly available at: [https://wordpress.org/plugins/cloudinary-i
1212

1313
This Git repository is the development repository, while there's a mirror public SVN repository of the actual released WordPress plugin version: [https://plugins.svn.wordpress.org/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/](https://plugins.svn.wordpress.org/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/)
1414

15-
1615
> **Deprecation Note**
17-
> The legacy WordPress Plugin version (v1.x) will be deprecated as of **February 1st, 2021**, after which support, updates and bug fixes for the legacy plugin will continue in limited fashion.
16+
> The legacy WordPress Plugin version (v1.x) will be deprecated as of **February 1st, 2021**, after which support, updates and bug fixes for the legacy plugin will continue in limited fashion.
1817
> The legacy plugin will be made obsolete on **August 1st, 2021** (end-of-life date), meaning, Version 1.x of the plugin will no longer function after that date.
19-
> We ask that you update to our latest WordPress Plugin v2.x before the August 1st deadline.
20-
18+
> We ask that you update to our latest WordPress Plugin v2.x before the August 1st deadline.
2119
2220
## Additional resources
2321

2422
Additional resources are available at:
2523

26-
* [Website](https://cloudinary.com)
27-
* [Documentation](https://cloudinary.com/documentation)
28-
* [Knowledge Base](https://support.cloudinary.com/hc/en-us)
24+
- [Website](https://cloudinary.com)
25+
- [Documentation](https://cloudinary.com/documentation)
26+
- [Knowledge Base](https://support.cloudinary.com/hc/en-us)
2927

3028
## Support
3129

@@ -37,6 +35,74 @@ Stay tuned for updates, tips and tutorials: [Blog](https://cloudinary.com/blog),
3735

3836
## Development
3937

38+
### Prerequisites
39+
40+
- [Node.js](https://nodejs.org/) v16+ (see `.nvmrc`)
41+
- [npm](https://www.npmjs.com/) v6.9+
42+
- [Composer](https://getcomposer.org/)
43+
- [Docker](https://www.docker.com/) (required for the WordPress local environment via `wp-env`)
44+
45+
### Local Development Setup
46+
47+
1. **Clone the repository:**
48+
49+
```bash
50+
git clone https://github.com/cloudinary/cloudinary_wordpress.git
51+
cd cloudinary_wordpress
52+
```
53+
54+
2. **Set the correct Node version** (if using [nvm](https://github.com/nvm-sh/nvm)):
55+
56+
```bash
57+
nvm install
58+
nvm use
59+
```
60+
61+
3. **Install dependencies:**
62+
63+
```bash
64+
npm install
65+
```
66+
67+
This will also run `composer install` automatically via the `postinstall` script, setting up PHP dependencies and linting tools.
68+
69+
4. **Start the local WordPress environment:**
70+
71+
Make sure Docker is running, then:
72+
73+
```bash
74+
npm run env:start
75+
```
76+
77+
This spins up a WordPress instance at [http://localhost:8888](http://localhost:8888) with the plugin activated and `WP_DEBUG` enabled. A loopback fix is applied automatically so REST API self-requests work inside the container.
78+
79+
5. **Build front-end assets:**
80+
81+
```bash
82+
npm run build # One-time production build
83+
npm run dev # Watch mode for development
84+
```
85+
86+
### Useful Commands
87+
88+
| Command | Description |
89+
| ---------------------- | ---------------------------------------- |
90+
| `npm run env:start` | Start the local WordPress environment |
91+
| `npm run env:stop` | Stop the local WordPress environment |
92+
| `npm run env:destroy` | Remove the local environment completely |
93+
| `npm run env:logs` | View container logs |
94+
| `npm run env:cli` | Run WP-CLI commands inside the container |
95+
| `npm run env:clean` | Reset the environment (removes all data) |
96+
| `npm run build` | Build front-end assets for production |
97+
| `npm run dev` | Build front-end assets in watch mode |
98+
| `npm run lint` | Run all linters (PHP, JS, CSS) |
99+
| `npm run lint:php` | Run PHP CodeSniffer |
100+
| `npm run lint:php:fix` | Auto-fix PHP linting issues |
101+
| `npm run lint:js` | Run ESLint on JavaScript files |
102+
| `npm run lint:js:fix` | Auto-fix JS linting issues |
103+
| `npm run lint:style` | Run stylelint on SCSS files |
104+
| `npm run i18n` | Generate translation files |
105+
40106
### Create a Plugin Release Package
41107

42108
Run `npm run package` to create the plugin release in the `/build` directory and package it as `cloudinary-image-management-and-manipulation-in-the-cloud-cdn.zip` in the root directory.

0 commit comments

Comments
 (0)