Skip to content

Commit af93632

Browse files
committed
Update README.md for 2.0
1 parent fa752d8 commit af93632

File tree

1 file changed

+35
-126
lines changed

1 file changed

+35
-126
lines changed

README.md

Lines changed: 35 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,56 @@
1-
![Test PHP](https://github.com/SebKay/oop-wp/workflows/Test%20PHP/badge.svg)
2-
31
# OOP WP
4-
A simple library of OOP style helpers for WordPress theme and plugin development.
52

6-
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.
3+
[![Test PHP](https://github.com/SebKay/oop-wp/actions/workflows/php.yml/badge.svg)](https://github.com/SebKay/oop-wp/actions/workflows/php.yml)
4+
5+
A simple library of OOP style helper classes for WordPress theme and plugin development.
76

8-
Most of the methods are wrappers for already existing functions like `get_the_title()`
7+
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!
8+
9+
## Installation
910

10-
## How to install
1111
It's recommended you install this package via [Composer](https://getcomposer.org/).
1212

1313
```bash
1414
composer require sebkay/oop-wp
1515
```
1616

17-
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:
17+
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:
1818

1919
```php
2020
require get_template_directory() . '/vendor/autoload.php';
2121
```
2222

23-
## How to use
24-
Wherever you want to use one of the OOP implementations, you can do like this:
23+
## Usage
24+
25+
Wherever you want to use one of the OOP implementations, you can do so like this:
2526

2627
```php
27-
$blog_post = new OOPWP\Posts\Post(get_the_ID());
28+
use OOPWP\PostTypes\Post;
29+
30+
$blog_post = new Post(get_the_ID());
2831

2932
$blog_post->title();
3033
```
3134

32-
## Available Methods
33-
### OOPWP\Posts\Post
34-
<table>
35-
<tr>
36-
<th>
37-
Methods
38-
</th>
39-
<th></th>
40-
</tr>
41-
<tr>
42-
<td><code>->id()</code></td>
43-
<td>Outputs whatever ID is passed to the constructor.</td>
44-
</tr>
45-
<tr>
46-
<td><code>->url()</code></td>
47-
<td>Wrapper for <code>get_permalink()</code>.</td>
48-
</tr>
49-
<tr>
50-
<td><code>->slug()</code></td>
51-
<td>Returns <code>->post_name</code> from the <code>WP_Post</code> object.</td>
52-
</tr>
53-
<tr>
54-
<td><code>->status()</code></td>
55-
<td>Wrapper for <code>get_post_status()</code>.</td>
56-
</tr>
57-
<tr>
58-
<td><code>->format()</code></td>
59-
<td>Wrapper for <code>get_post_format()</code>.</td>
60-
</tr>
61-
<tr>
62-
<td><code>->title()</code></td>
63-
<td>Wrapper for <code>get_the_title()</code>.</td>
64-
</tr>
65-
<tr>
66-
<td><code>->excerpt()</code></td>
67-
<td>Wrapper for <code>get_the_excerpt()</code>.</td>
68-
</tr>
69-
<tr>
70-
<td><code>->publishDate()</code></td>
71-
<td>Wrapper for <code>get_the_date()</code>.</td>
72-
</tr>
73-
<tr>
74-
<td><code>->modifiedDate()</code></td>
75-
<td>Wrapper for <code>get_the_modified_time()</code>.</td>
76-
</tr>
77-
<tr>
78-
<td><code>->content()</code></td>
79-
<td>Returns <code>->post_content</code> from the <code>WP_Post</code> object and applies <code>the_content</code> filter.</td>
80-
</tr>
81-
<tr>
82-
<td><code>->parent()</code></td>
83-
<td>Returns a new <code>Post</code> object using <code>->post_parent</code> from the <code>WP_Post</code> object.</td>
84-
</tr>
85-
</table>
86-
87-
### OOPWP\User
88-
<table>
89-
<tr>
90-
<th>
91-
Methods
92-
</th>
93-
<th></th>
94-
</tr>
95-
<tr>
96-
<td><code>->id()</code></td>
97-
<td>Outputs whatever ID is passed to the constructor.</td>
98-
</tr>
99-
<tr>
100-
<td><code>->meta()</code></td>
101-
<td>Get custom meta field.</td>
102-
</tr>
103-
<tr>
104-
<td><code>->firstName()</code></td>
105-
<td>First name meta field.</td>
106-
</tr>
107-
<tr>
108-
<td><code>->lastName()</code></td>
109-
<td>Last name meta field.</td>
110-
</tr>
111-
<tr>
112-
<td><code>->fullName()</code></td>
113-
<td>Combination of <code>->firstName()</code> and <code>->lastName()</code>.</td>
114-
</tr>
115-
<tr>
116-
<td><code>->nickname()</code></td>
117-
<td>Nickname meta field.</td>
118-
</tr>
119-
<tr>
120-
<td><code>->description()</code></td>
121-
<td>Biographical info meta field with <code>the_content</code> filter applied.</td>
122-
</tr>
123-
<tr>
124-
<td><code>->username()</code></td>
125-
<td><code>user_login</code> field from <code>WP_User</code> object.</td>
126-
</tr>
127-
<tr>
128-
<td><code>->nicename()</code></td>
129-
<td>A URL friendly version of <code>->username()</code>.<br><code>user_nicename</code> property from <code>WP_User->data</code> object.</td>
130-
</tr>
131-
<tr>
132-
<td><code>->displayName()</code></td>
133-
<td><code>display_name</code> property from <code>WP_User->data</code> object.</td>
134-
</tr>
135-
<tr>
136-
<td><code>->email()</code></td>
137-
<td><code>user_email</code> property from <code>WP_User->data</code> object.</td>
138-
</tr>
139-
<tr>
140-
<td><code>->url()</code></td>
141-
<td><code>user_url</code> property from <code>WP_User->data</code> object.</td>
142-
</tr>
143-
<tr>
144-
<td><code>->registredDate()</code></td>
145-
<td><code>user_registered</code> property from <code>WP_User->data</code> object.</td>
146-
</tr>
147-
</table>
35+
### Dates with `nesbot/carbon`
36+
37+
All dates use the [Carbon](https://github.com/briannesbitt/Carbon) PHP library.
38+
39+
```php
40+
use OOPWP\PostTypes\Post;
41+
42+
$blog_post = new Post(get_the_ID());
43+
44+
# date() is \Carbon\Carbon object
45+
$blog_post->date()->format('j F Y);
46+
```
47+
48+
## Available Classes
49+
50+
### Posts
51+
52+
- `OOPWP\PostTypes\Post`
53+
54+
### Users
55+
56+
- `OOPWP\Users`

0 commit comments

Comments
 (0)