From af936329bf904f31cf0022535cb1dc13eae9fb66 Mon Sep 17 00:00:00 2001 From: Seb Kay Date: Tue, 20 Jul 2021 23:35:52 +0100 Subject: [PATCH] Update README.md for 2.0 --- README.md | 161 ++++++++++++------------------------------------------ 1 file changed, 35 insertions(+), 126 deletions(-) diff --git a/README.md b/README.md index 2ac5185..5156ee2 100644 --- a/README.md +++ b/README.md @@ -1,147 +1,56 @@ -![Test PHP](https://github.com/SebKay/oop-wp/workflows/Test%20PHP/badge.svg) - # OOP WP -A simple library of OOP style helpers for WordPress theme and plugin development. -It gives you well-formatted classes for things like posts for accessing items such as the title or publish date. It can easily be extended into sub-classes in your own projects. +[![Test PHP](https://github.com/SebKay/oop-wp/actions/workflows/php.yml/badge.svg)](https://github.com/SebKay/oop-wp/actions/workflows/php.yml) + +A simple library of OOP style helper classes for WordPress theme and plugin development. -Most of the methods are wrappers for already existing functions like `get_the_title()` +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 -## How to install It's recommended you install this package via [Composer](https://getcomposer.org/). ```bash composer require sebkay/oop-wp ``` -You'll then need to include the Composer autoloader so you have access to the package. Add the following at the top of your `functions.php` file: +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: ```php require get_template_directory() . '/vendor/autoload.php'; ``` -## How to use -Wherever you want to use one of the OOP implementations, you can do like this: +## Usage + +Wherever you want to use one of the OOP implementations, you can do so like this: ```php -$blog_post = new OOPWP\Posts\Post(get_the_ID()); +use OOPWP\PostTypes\Post; + +$blog_post = new Post(get_the_ID()); $blog_post->title(); ``` -## Available Methods -### OOPWP\Posts\Post - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Methods -
->id()Outputs whatever ID is passed to the constructor.
->url()Wrapper for get_permalink().
->slug()Returns ->post_name from the WP_Post object.
->status()Wrapper for get_post_status().
->format()Wrapper for get_post_format().
->title()Wrapper for get_the_title().
->excerpt()Wrapper for get_the_excerpt().
->publishDate()Wrapper for get_the_date().
->modifiedDate()Wrapper for get_the_modified_time().
->content()Returns ->post_content from the WP_Post object and applies the_content filter.
->parent()Returns a new Post object using ->post_parent from the WP_Post object.
- -### OOPWP\User - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Methods -
->id()Outputs whatever ID is passed to the constructor.
->meta()Get custom meta field.
->firstName()First name meta field.
->lastName()Last name meta field.
->fullName()Combination of ->firstName() and ->lastName().
->nickname()Nickname meta field.
->description()Biographical info meta field with the_content filter applied.
->username()user_login field from WP_User object.
->nicename()A URL friendly version of ->username().
user_nicename property from WP_User->data object.
->displayName()display_name property from WP_User->data object.
->email()user_email property from WP_User->data object.
->url()user_url property from WP_User->data object.
->registredDate()user_registered property from WP_User->data object.
+### Dates with `nesbot/carbon` + +All dates use the [Carbon](https://github.com/briannesbitt/Carbon) PHP library. + +```php +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`