Repository navigation
Expand file tree
/
Copy pathwordpress-api.bat
More file actions
314 lines (271 loc) · 9.6 KB
/
Copy pathwordpress-api.bat
File metadata and controls
314 lines (271 loc) · 9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
@echo off
setlocal enabledelayedexpansion
:: API Key Forge - WordPress
:: =========================
color 06
cls
echo.
echo ╔═══════════════════════════════════════════════════╗
echo ║ API Key Forge - WordPress ║
echo ╠═══════════════════════════════════════════════════╣
echo ║ Application Passwords and REST API Access ║
echo ╚═══════════════════════════════════════════════════╝
echo.
echo What would you like to set up?
echo.
echo [1] Application Password (Recommended)
echo [2] JWT Authentication
echo [3] OAuth 2.0 Authentication
echo [4] WooCommerce API Keys
echo [5] WordPress.com API
echo.
set /p choice="Enter your choice (1-5): "
if "%choice%"=="1" goto :app_password
if "%choice%"=="2" goto :jwt_auth
if "%choice%"=="3" goto :oauth2
if "%choice%"=="4" goto :woocommerce
if "%choice%"=="5" goto :wpcom
goto :invalid
:app_password
cls
echo.
echo ══════════════════════════════════════════════════════
echo WordPress Application Passwords
echo ══════════════════════════════════════════════════════
echo.
echo The easiest way to authenticate with WordPress REST API.
echo.
set /p site_url="Enter your WordPress site URL: "
if not "!site_url!"=="" (
echo.
echo Opening your WordPress admin...
start !site_url!/wp-admin/profile.php#application-passwords-section
) else (
echo Please provide your site URL first!
pause
goto :app_password
)
echo.
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Scroll to "Application Passwords" section
echo 2. Enter a name (e.g., "API Key Forge")
echo 3. Click "Add New Application Password"
echo 4. COPY THE PASSWORD NOW! (spaces don't matter)
echo 5. You won't see it again!
echo.
set /p username="Enter your WordPress username: "
set /p app_pass="Paste the application password: "
if not "!app_pass!"=="" (
:: Remove spaces from password
set app_pass=!app_pass: =!
echo.
echo Your credentials:
echo Username: !username!
echo Password: !app_pass!
echo.
echo For Basic Auth, encode as:
echo !username!:!app_pass!
echo.
:: Base64 encode for Authorization header
powershell -command "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('!username!:!app_pass!'))" > temp_auth.txt
set /p auth_header=<temp_auth.txt
del temp_auth.txt
echo Authorization header:
echo Authorization: Basic !auth_header!
echo.
echo Testing API access...
curl -s -H "Authorization: Basic !auth_header!" !site_url!/wp-json/wp/v2/users/me
)
goto :end
:jwt_auth
cls
echo.
echo ══════════════════════════════════════════════════════
echo JWT Authentication Setup
echo ══════════════════════════════════════════════════════
echo.
echo Requires JWT Authentication plugin installation.
echo.
echo SETUP STEPS:
echo ------------
echo 1. Install JWT Authentication for WP REST API plugin
echo https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/
echo.
echo 2. Add to wp-config.php:
echo.
echo define('JWT_AUTH_SECRET_KEY', 'your-secret-key');
echo define('JWT_AUTH_CORS_ENABLE', true);
echo.
echo 3. Add to .htaccess:
echo.
echo RewriteEngine on
echo RewriteCond %%{HTTP:Authorization} ^(.*)
echo RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%%1]
echo.
set /p has_plugin="Have you installed the plugin? (y/n): "
if /i "%has_plugin%"=="y" (
echo.
echo 4. Get token by POST to:
echo /wp-json/jwt-auth/v1/token
echo.
echo Body: {
echo "username": "your-username",
echo "password": "your-password"
echo }
echo.
echo 5. Use token in headers:
echo Authorization: Bearer YOUR_JWT_TOKEN
)
goto :end
:oauth2
cls
echo.
echo ══════════════════════════════════════════════════════
echo WordPress OAuth 2.0 Setup
echo ══════════════════════════════════════════════════════
echo.
echo Requires OAuth Server plugin or WordPress.com.
echo.
echo Choose your OAuth provider:
echo [1] Self-hosted with OAuth Server plugin
echo [2] WordPress.com OAuth
echo.
set /p oauth_type="Choice: "
if "%oauth_type%"=="1" (
echo.
echo SELF-HOSTED SETUP:
echo ------------------
echo 1. Install WP OAuth Server plugin
echo https://wp-oauth.com/
echo.
echo 2. Create a new client in WP Admin → OAuth Server → Clients
echo.
echo 3. Set redirect URI:
echo http://localhost:3000/callback
echo.
echo 4. Note your Client ID and Client Secret
) else (
echo.
echo WORDPRESS.COM OAUTH:
echo -------------------
start https://developer.wordpress.com/apps/new/
echo 1. Create new application
echo 2. Set redirect URLs
echo 3. Copy Client ID and Client Secret
echo.
echo OAuth endpoints:
echo Authorize: https://public-api.wordpress.com/oauth2/authorize
echo Token: https://public-api.wordpress.com/oauth2/token
)
goto :end
:woocommerce
cls
echo.
echo ══════════════════════════════════════════════════════
echo WooCommerce REST API Keys
echo ══════════════════════════════════════════════════════
echo.
set /p site_url="Enter your WooCommerce site URL: "
if not "!site_url!"=="" (
echo.
echo Opening WooCommerce API settings...
start !site_url!/wp-admin/admin.php?page=wc-settings^&tab=advanced^§ion=keys
)
echo.
echo STEPS TO FOLLOW:
echo ----------------
echo 1. Go to WooCommerce → Settings → Advanced → REST API
echo 2. Click "Add key"
echo 3. Description: "API Key Forge"
echo 4. User: Select a user (usually admin)
echo 5. Permissions:
echo - Read (for reading data)
echo - Write (for creating/updating)
echo - Read/Write (full access)
echo 6. Click "Generate API key"
echo 7. Copy Consumer key and Consumer secret
echo.
set /p consumer_key="Consumer key: "
set /p consumer_secret="Consumer secret: "
if not "!consumer_key!"=="" (
echo.
echo Your WooCommerce credentials:
echo Consumer key: !consumer_key!
echo Consumer secret: !consumer_secret:~0,20!...
echo.
echo Example usage:
echo curl !site_url!/wp-json/wc/v3/products \
echo -u !consumer_key!:!consumer_secret!
)
goto :end
:wpcom
cls
echo.
echo ══════════════════════════════════════════════════════
echo WordPress.com API Setup
echo ══════════════════════════════════════════════════════
echo.
start https://developer.wordpress.com/apps/
echo STEPS FOR WORDPRESS.COM API:
echo ---------------------------
echo 1. Click "Create New Application"
echo 2. Fill in:
echo - Name: Your app name
echo - Description: What it does
echo - Website URL: Your site
echo - Redirect URLs: http://localhost:3000/callback
echo - Type: Web
echo 3. Create Application
echo 4. Copy Client ID and Client Secret
echo.
echo API Endpoints:
echo - REST API: https://public-api.wordpress.com/rest/v1.1/
echo - OAuth: https://public-api.wordpress.com/oauth2/
echo.
echo Popular endpoints:
echo - /sites/SITE_ID/posts (blog posts)
echo - /sites/SITE_ID/comments
echo - /sites/SITE_ID/stats
echo - /me (user info)
echo.
set /p create_app="Open app creation page? (y/n): "
if /i "%create_app%"=="y" start https://developer.wordpress.com/apps/new/
goto :end
:invalid
echo Invalid choice. Please run the script again.
pause
exit /b 1
:end
echo.
echo ══════════════════════════════════════════════════════
echo WordPress Setup Complete!
echo ══════════════════════════════════════════════════════
echo.
echo Quick Testing Commands:
echo.
echo List posts:
echo curl -X GET https://your-site.com/wp-json/wp/v2/posts
echo.
echo Get current user (authenticated):
echo curl -H "Authorization: Basic YOUR_BASE64_AUTH" \
echo https://your-site.com/wp-json/wp/v2/users/me
echo.
echo Security Tips:
echo - Use HTTPS always
echo - Limit permissions to what you need
echo - Rotate credentials regularly
echo - Use application passwords over main password
echo.
set /p save_env="Save credentials to .env file? (y/n): "
if /i "%save_env%"=="y" (
echo.
echo # WordPress API Credentials >> .env
echo WORDPRESS_URL=!site_url! >> .env
echo WORDPRESS_USERNAME=!username! >> .env
echo WORDPRESS_APP_PASSWORD=!app_pass! >> .env
echo.
echo Saved to .env file!
)
echo.
pause