-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.txt
More file actions
410 lines (336 loc) · 12 KB
/
README.txt
File metadata and controls
410 lines (336 loc) · 12 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
=== WPSnipHub ===
Contributors: @maxcgparis
Tags: hub, code snippets, scripts and styles management, dashboard customization, woocommerce.
Author: @maxcgparis
Author URI: https://maxgremez.com/
Plugin URI: https://github.com/MaxG-WebProjects/wp-sniphub
Version: 1.2.5
Stable tag: 1.2.5
Requires at least: 6.7
Tested up to: 6.9
Requires PHP: 8.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
A dev-oriented central and modular hub for code snippets and utility functions of WordPress sites
=== Documentation ===
== Description ==
**WPSnipHub** is a modular WordPress plugin designed to centralize reusable snippets and utility functions in a clean, maintainable, and scalable way.
Each feature is packaged as an independent module that can be enabled or disabled from a dedicated administration screen.
Main features include:
- WordPress admin dashboard customization (logo, colors, footer, avatars)
- Custom login page styling
- Front-end and back-end scripts and styles management
- Custom post types and taxonomies registration
- Reusable shortcodes
- Security hardening and WordPress cleanup
- Helper utility functions shared across modules
The plugin follows WordPress coding standards and best practices.
---
== Installation ==
You can install WP SnipHub by downloading the ZIP file from the latest GitHub release.
GitHub automatically provides a source archive for each release tag.
1. Upload the `wp-sniphub` directory to `/wp-content/plugins/`
2. Activate the plugin through the WordPress admin panel
3. Open **WPSnipHub** from the admin menu
4. Enable or disable modules as needed
5. Save your configuration
---
== Changelog ==
See the full changelog in the dedicated file: [CHANGELOG.md](<a href="https://github.com/MaxG-WebProjects/wp-sniphub/blob/main/CHANGELOG.md" alt="link to file CHANGELOG.md">CHANGELOG.md</a>) for the complete history of changes.
---
== Objectives ==
The goal is to ensure:
- A centralized interface for functions
- Simple activation/deactivation of modules
- Improved code hierarchy and readability
- Easy addition of extra code
- Simplified maintenance
- Compliance with WordPress best practices
---
== Plugin structure ==
wp-sniphub/
│
├── _docs.php # Internal documentation (not loaded)
├── CHANGELOG.md # Internal documentation (not loaded)
├── README.md # Internal documentation (not loaded)
├── README.txt # Internal documentation (not loaded)
├── LICENSE # Internal documentation (not loaded)
│
├── wp-sniphub.php
│
├── inc/
│ ├── setup.php
│ ├── security.php
│ ├── custom-login.php
│ ├── custom-admin.php
│ ├── custom-favicon.php
│ ├── hooks.php
│ ├── scripts.php
│ ├── styles.php
│ ├── performance.php
│ ├── cleanup.php
│ ├── custom-post-types.php
│ ├── taxonomies.php
│ ├── media-setup.php
│ ├── image-size.php
│ ├── shortcodes.php
│ ├── publications.php
│ ├── woocommerce.php
│ ├── gravity-forms.php
│ ├── greenshift.php
│ └── helpers.php
│
├── css/
│ ├── admin/
│ │ └── wpsh-admin.css
│ │
│ ├── custom-login/
│ │ └── login-styles.css
│ │
│ └── custom-admin-colors/
│ └── color-scheme.css
│
└── img/
├── icon.svg
├── gravatar-icon-290x290px.png
└── favicons/
├── favicon.ico
├── favicon.svg
├── favicon-16x16.png
├── favicon-32x32.png
├── favicon-96x96.png
├── apple-touch-icon.png
├── web-app-manifest-192x192.png
├── web-app-manifest-512x512.png
├── safari-pinned-tab.svg
└── site.webmanifest
---
== Order of execution (priorities) ==
┌──────────────────────────┬────────────┬───────────────────────────────────────────┐
│ Modules │ Priorities │ Roles │
├──────────────────────────┼────────────┼───────────────────────────────────────────┤
│ setup.php │ 5 │ Initialisation │
│ security.php │ 10 │ Security improvements │
│ custom-login.php │ 45 │ Customizing the login │
│ custom-admin.php │ 50 │ Admin customization │
│ custom-favicon.php │ 15 │ Customizing the favicon │
│ hooks.php │ 45 │ Custom hooks (actions/filters) │
│ scripts.php │ 40 │ Loading CSS/JS │
│ performance.php │ 45 │ Performance improvements │
│ cleanup.php │ 35 │ WordPress cleanup │
│ custom-post-types.php │ 30 │ Declaration of Custom Post Types │
│ taxonomies.php │ 20 │ Declaration of taxonomies │
│ media-setup.php │ 45 │ Added media types (svg, json) │
│ image-size.php │ 55 │ Adding image sizes │
│ shortcodes.php │ 25 │ Declaration of shortcodes │
│ publications.php │ 25 │ Adding features to articles │
│ woocommerce.php │ 25 │ Adding features to WooCommerce │
│ gravity-forms.php │ 45 │ Customizing the Gravity Forms plugin │
│ greenshift.php │ 35 │ Customizing the Greenshift plugin │
│ helpers.php │ 20 │ Utility functions │
│ ... │ .. │ ... │
│ ... │ .. │ ... │
│ ... │ .. │ ... │
└──────────────────────────┴────────────┴───────────────────────────────────────────┘
## Guidelines for WPSnipHub module creation
### Philosophy
A module is **clean, isolated, and maintainable code** that conforms to WordPress.org standards.
### 1. Objective of these guidelines
To ensure that each module:
- adheres to security and quality standards
- never conflicts with other plugins or themes
- passes Plugin Check without critical errors
- facilitates easy adoption
- evolves without technical debt
- can be disabled via WPSnipHub
- is compatible with WordPress.org. Even though **WPSnipHub** is not intended to be published on the official plugin repository
---
### 2. Minimum Module Structure
Each module must be a single PHP file located in:
/inc/nom-du-module.php
Recommended header:
```php
<?php
/**
* Module name
* Short module description
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
```
---
### 3. Prefix everything that is global
wpsh_
This prefix must be used consistently for:
┌─────────────────────┬─────────────────────────────┐
│ Type │ Correct example │
├─────────────────────┼─────────────────────────────┤
│ Fonction │ wpsh_register_post_types() │
│ Hook callback │ wpsh_enqueue_assets() │
│ Global variable │ $wpsh_options │
│ Constant │ WPSH_OPTION_NAME │
│ Class │ WPSH_Module_Example │
└─────────────────────┴─────────────────────────────┘
Plugin Check error cause:
```php
<?php
function enqueue_assets() {}
function my_custom_filter() {}
```
Solution :
```php
<?php
function wpsh_enqueue_assets() {}
function wpsh_custom_filter() {}
```
---
### 4. Hooks & filters
Plugin Check error cause:
```php
<?php
add_action( 'init', 'register_cpt' ); //Exemple pour CPT
```
Solution :
```php
<?php
add_action( 'init', 'wpsh_register_cpt' );
function wpsh_register_cpt() {
// ...
}
```
---
### 5. Use of anonymous functions (closures)
Anonymous functions are only permitted for:
- very simple filters
- direct return (__return_true, etc.)
To avoid:
```php
<?php
add_action( 'init', function() {
// complex logic
});
```
Recommended:
```php
<?php
add_action( 'init', 'wpsh_init_module' );
function wpsh_init_module() {
// clear and testable logic
}
```
---
### 6. Internationalization (i18n)
Always provide the text domain: wp-sniphub
Incorrect:
```php
<?php
__( 'My string' );
```
Solution:
```php
<?php
__( 'My string', 'wp-sniphub' );
esc_html__( 'My string', 'wp-sniphub' );
```
---
### 7. Output safety (required escaping)
General rule: All HTML output must be escaped.
┌─────────────────────┬────────────────┐
│ Context │ Function │
├─────────────────────┼────────────────┤
│ Text │ esc_html() │
│ HTML Attribut │ esc_attr() │
│ URL │ esc_url() │
│ Translated text │ esc_html__() │
└─────────────────────┴────────────────┘
Incorrect:
```php
<?php
_e( 'Largeur maximale', 'wp-sniphub' );
```
Solution:
```php
<?php
esc_html_e( 'Largeur maximale', 'wp-sniphub' );
```
---
### 8. Dates and times
Incorrect:
```php
<?php
date( 'Y' );
```
Solution:
```php
<?php
wp_date( 'Y' );
```
---
### 9. Best practices for third-party plugins
- Always use the WPSH prefix, even in third-party hooks.
- Never use the third-party plugin's text domain.
Incorrect:
```php
<?php
esc_html__( 'Error', 'gravityforms' ); //Exemple pour Gravity Forms
function who_change_error_message() {}
```
Solution:
```php
<?php
esc_html__( 'Error', 'wp-sniphub' );
function wpsh_change_gform_error_message() {}
```
---
### 10. Template module compliant
```php
<?php
/**
* Module name
*
* Short description of the module.
*
* @package WPSnipHub
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/* ==========================================================
Module Initialization
========================================================== */
/**
* Initialize the module.
*
* @return void
*/
function wpsh_nom_module_init() {
// Module Initialization
}
add_action( 'init', 'wpsh_nom_module_init' );
/* ==========================================================
Main functions
========================================================== */
/**
* Example of a utility function.
*
* @param string $value Valeur à traiter.
* @return string
*/
function wpsh_nom_module_example( $value ) {
return esc_html( $value );
}
/* ==========================================================
Hooks / Filters
========================================================== */
/**
* Example of a WordPress filter.
*
* @param string $content Contenu.
* @return string
*/
function wpsh_nom_module_filter_example( $content ) {
return $content;
}
add_filter( 'the_content', 'wpsh_nom_module_filter_example' );