A dev-oriented central and modular hub for code snippets and utility functions of WordPress sites
- Version: 1.2.5
- Stable version: 1.2.5
- Requires at least: 6.7
- Tested up to: 6.9
- Requires PHP: 8.0
This project is licensed under the GNU General Public License v2.0 or later.
- License: GPL-2.0-or-later
- License URI: https://www.gnu.org/licenses/gpl-2.0.html
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.
You can install WP SnipHub by downloading the ZIP file from the latest release. GitHub automatically provides a source archive for each release tag.
- Upload the
wp-sniphubdirectory to/wp-content/plugins/ - Activate the plugin through the WordPress admin panel
- Open WPSnipHub from the admin menu
- Enable or disable modules as needed
- Save your configuration
Note
Inspect the code snippets of each module before activating them to understand what functions they generate.
See the full changelog in the dedicated file: CHANGELOG.md for the complete history of changes.
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
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
┌──────────────────────────┬────────────┬───────────────────────────────────────────┐
│ 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 JS │
│ styles.php │ 40 │ Loading CSS │
│ 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 │
│ ... │ .. │ ... │
│ ... │ .. │ ... │
│ ... │ .. │ ... │
└──────────────────────────┴────────────┴───────────────────────────────────────────┘
A module is clean, isolated, and maintainable code that conforms to WordPress.org standards.
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
Each module must be a single PHP file located in:
/inc/module-name.php
Recommended header:
<?php
/**
* Module name
* Short module description
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}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
function enqueue_assets() {}
function my_custom_filter() {}Solution :
<?php
function wpsh_enqueue_assets() {}
function wpsh_custom_filter() {}Plugin Check error cause:
<?php
add_action( 'init', 'register_cpt' ); //Exemple pour CPTSolution :
<?php
add_action( 'init', 'wpsh_register_cpt' );
function wpsh_register_cpt() {
// ...
}Anonymous functions are only permitted for:
- very simple filters
- direct return (__return_true, etc.)
To avoid:
<?php
add_action( 'init', function() {
// complex logic
});Recommended:
<?php
add_action( 'init', 'wpsh_init_module' );
function wpsh_init_module() {
// clear and testable logic
}Always provide the text domain: wp-sniphub
Incorrect:
<?php
__( 'My string' );Solution:
<?php
__( 'My string', 'wp-sniphub' );
esc_html__( 'My string', 'wp-sniphub' );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
_e( 'Maximum width', 'wp-sniphub' );Solution:
<?php
esc_html_e( 'Maximum width', 'wp-sniphub' );Incorrect:
<?php
date( 'Y' );Solution:
<?php
wp_date( 'Y' );- Always use the WPSH prefix, even in third-party hooks.
- Never use the third-party plugin's text domain.
Incorrect:
<?php
esc_html__( 'Error', 'gravityforms' ); //Example for Gravity Forms
function who_change_error_message() {}Solution:
<?php
esc_html__( 'Error', 'wp-sniphub' );
function wpsh_change_gform_error_message() {}<?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_module_name_init() {
// Module Initialization
}
add_action( 'init', 'wpsh_module_name_init' );
/* ==========================================================
Main functions
========================================================== */
/**
* Example of a utility function.
*
* @param string $value Valeur à traiter.
* @return string
*/
function wpsh_module_name_example( $value ) {
return esc_html( $value );
}
/* ==========================================================
Hooks / Filters
========================================================== */
/**
* Example of a WordPress filter.
*
* @param string $content Contenu.
* @return string
*/
function wpsh_module_name_filter_example( $content ) {
return $content;
}
add_filter( 'the_content', 'wpsh_module_name_filter_example' );