sebkay / oop-wp
Fund package maintenance!
SebKay
Requires
- php: ^7.4|^8.0
- nesbot/carbon: ^2.57
Requires (Dev)
- php-stubs/wordpress-globals: ^0.2
- php-stubs/wordpress-stubs: ^5.9
- php-stubs/wordpress-tests-stubs: ^5.8
- spatie/ray: ^1.28
- squizlabs/php_codesniffer: ^3.6
README
A simple library of OOP style helper classes for WordPress theme and plugin development.
Most methods in this package are wrappers for already existing functionality like get_the_title()
or get_user_meta()
, but they give you a much cleaner (and more modern) way to do so!
Installation
It's recommended you install this package via Composer.
composer require sebkay/oop-wp
You'll need to include the Composer autoloader so you have access to the package. Add the following to the top of your functions.php
file:
require get_template_directory() . '/vendor/autoload.php';
Usage
Wherever you want to use one of the OOP implementations, you can do so like this:
use OOPWP\PostTypes\Post; $blog_post = new Post(get_the_ID()); $blog_post->title();
Dates with nesbot/carbon
All dates use the Carbon PHP library.
use OOPWP\PostTypes\Post; $blog_post = new Post(get_the_ID()); # date() is \Carbon\Carbon object $blog_post->date()->format('j F Y);
Available Classes
Posts
OOPWP\PostTypes\Post
Users
OOPWP\Users