webshr / core
Framework for WordPress projects.
Installs: 177
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/webshr/core
Requires
- php: >=8.1
- psr/container: ^2.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.12
- wp-coding-standards/wpcs: ^3.1
This package is not auto-updated.
Last update: 2025-11-12 11:17:29 UTC
README
A modern, modular framework for WordPress projects built with PHP 8.1+ and inspired by Laravel's architecture.
Overview
Webshr Core is a lightweight yet powerful framework designed specifically for WordPress development. It provides a clean, object-oriented approach to building WordPress themes and plugins with modern PHP features, dependency injection, and a modular architecture.
Features
- Modern PHP Architecture: Built with PHP 8.1+ using PSR-4 autoloading
- Modular System: Extensible module-based architecture for clean code organization
- Asset Management: Comprehensive asset handling with manifest support and bundling
- Dependency Injection: Service container for managing dependencies and bindings
- Encryption & Security: Built-in encryption utilities with multiple cipher support
- Configuration Management: Flexible configuration system with environment support
- Helper Functions: Rich set of utility functions for common WordPress tasks
- String Utilities: Comprehensive string manipulation helpers
- Filesystem Abstraction: Clean filesystem operations with proper error handling
Installation
composer require webshr/core
Quick Start
Basic Setup
<?php // functions.php or your theme's bootstrap file use Webshr\Core\Bootloader; // Initialize the framework $bootloader = Bootloader::get_instance(); $bootloader->boot();
Using the Application Container
use Webshr\Core\app; // Get the application instance $app = app(); // Resolve services from the container $encryption = app('encryption'); $assets = app('assets');
Core Components
Application Container
The Application class serves as the main service container and communication hub:
use Webshr\Core\Application; $app = new Application(); // Bind services $app->instance('my-service', new MyService()); // Resolve services $service = $app->make('my-service'); // Register singletons $app->singleton('database', Database::class);
Module System
Create modular functionality using the module system:
use Webshr\Core\Module; class MyModule extends Module { public function register(): void { // Register WordPress hooks, services, etc. add_action('init', [$this, 'init']); } public function boot(): void { // Boot logic after registration } public function can_register(): bool { return true; // Conditional registration } }
Asset Management
Handle assets with manifest support and bundling:
use Webshr\Core\asset; use Webshr\Core\bundle; // Get individual assets $css = asset('styles/main.css'); $js = asset('scripts/app.js'); // Get asset bundles $mainBundle = bundle('main'); // Enqueue CSS files $mainBundle->css(function($handle, $src) { wp_enqueue_style($handle, $src); }); // Enqueue JS files $mainBundle->js(function($handle, $src, $deps) { wp_enqueue_script($handle, $src, $deps); });
Encryption Utilities
Secure data with built-in encryption:
use Webshr\Core\encrypt; use Webshr\Core\decrypt; // Encrypt data $encrypted = encrypt('sensitive data'); // Decrypt data $decrypted = decrypt($encrypted); // String-specific encryption (no serialization) $encrypted = encrypt_string('plain text'); $decrypted = decrypt_string($encrypted);
String Utilities
Rich string manipulation helpers:
use Webshr\Core\Support\Str; // String operations Str::contains('Hello World', 'World'); // true Str::starts_with('Hello World', 'Hello'); // true Str::ends_with('Hello World', 'World'); // true // String extraction Str::before('user@example.com', '@'); // 'user' Str::after('user@example.com', '@'); // 'example.com' Str::between('Hello [World]', '[', ']'); // 'World' // Pattern matching Str::is('admin/*', 'admin/users'); // true
Configuration
Environment Configuration
The framework supports environment-based configuration:
// config/app.php return [ 'paths' => [ 'base' => get_template_directory(), 'config' => get_template_directory() . '/config', 'resources' => get_template_directory() . '/resources', 'storage' => get_template_directory() . '/storage', ], 'modules' => [ 'theme' => ThemeModule::class, 'assets' => AssetModule::class, ], 'cipher' => 'aes-256-cbc', 'key' => env('APP_KEY'), ];
Asset Configuration
Configure asset manifests and bundles:
// config/assets.php return [ 'default' => 'main', 'manifests' => [ 'main' => [ 'path' => get_template_directory() . '/dist', 'url' => get_template_directory_uri() . '/dist', 'assets' => get_template_directory() . '/dist/manifest.json', 'bundles' => get_template_directory() . '/dist/bundles.json', ], ], ];
Helper Functions
The framework provides numerous helper functions:
// Application helpers app(); // Get application instance bootloader(); // Get bootloader instance // Asset helpers asset('path/to/file.css'); bundle('main'); meta('path/to/file.json'); // Module helpers module('theme'); // Security helpers encrypt($data); decrypt($payload); hash($data); check($data, $hash); // WordPress helpers add_actions(['init', 'wp_enqueue_scripts'], $callback); add_filters(['the_content', 'the_title'], $callback); require_files('/path/to/directory');
Architecture
Directory Structure
src/
├── Application.php # Main application container
├── Bootloader.php # Application bootstrapper
├── Module.php # Base module class
├── Assets/ # Asset management system
│ ├── Manager.php # Asset manager
│ ├── Manifest.php # Asset manifest handler
│ ├── Bundle.php # Asset bundle handler
│ └── Asset/ # Asset types
├── Modules/ # Module system
│ ├── Manager.php # Module manager
│ └── Contracts/ # Module interfaces
├── Support/ # Support utilities
│ ├── Str.php # String utilities
│ └── Traits/ # Reusable traits
├── Utility/ # Utility classes
│ ├── Encryption.php # Encryption utilities
│ └── Hash.php # Hashing utilities
├── Config/ # Configuration management
├── Filesystem/ # Filesystem abstraction
└── Contracts/ # Framework interfaces
Key Design Patterns
- Service Container: Dependency injection and service resolution
- Module Pattern: Extensible, modular architecture
- Manager Pattern: Centralized management of resources
- Factory Pattern: Asset creation and instantiation
- Strategy Pattern: Pluggable encryption and hashing algorithms
Requirements
- PHP 8.1 or higher
- WordPress 5.0 or higher
- Composer for dependency management
Dependencies
psr/container: PSR-11 container interfacephpunit/phpunit: Testing framework (dev)squizlabs/php_codesniffer: Code quality (dev)wp-coding-standards/wpcs: WordPress coding standards (dev)
Development
Running Tests
composer test
Code Quality
composer lint composer lint:fix
Coverage
composer coverage
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the GPL-3.0-or-later License - see the LICENSE.md file for details.
Credits
- Author: Henrik Liebel (Webshore)
- Inspired by: Laravel Framework, Roots Acorn
- Website: webshore.eu
Support
For support and questions, please visit the project repository or contact mail@henrikliebel.com.