Skip to content

Commit 584e81b

Browse files
authored
Update README.md
1 parent 9669b00 commit 584e81b

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,83 @@
11
# OOP WP
22
A simple library of OOP style helpers for WordPress theme and plugin development.
33

4-
## What is this?
5-
OOP WP is a package that give you a load of handy classes and methods to use when building things in WordPress.
4+
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.
65

7-
It can give you well-formatted classes like User and Post which can then be extended into sub-classes in your own projects.
6+
Most of the methods are wrappers for already existing functions like `get_the_title()`
7+
8+
## How to install
9+
It's recommended you install this package via [Composer](https://getcomposer.org/).
10+
11+
```
12+
composer require sebkay/oop-wp
13+
```
14+
15+
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:
16+
17+
```
18+
require get_template_directory() . '/vendor/autoload.php';
19+
```
20+
21+
## How to use
22+
Wherever you want to use one of the OOP implementations, you can do like this:
23+
24+
```
25+
$blog_post = new OOPWP\Posts\Post(get_the_ID());
26+
27+
$blog_post->title();
28+
```
29+
30+
## Available Methods
31+
### Post
32+
<table>
33+
<tr>
34+
<th>
35+
Methods
36+
</th>
37+
<th></th>
38+
</tr>
39+
<tr>
40+
<td><code>->id()</code></td>
41+
<td>Outputs whatever ID is passed to the constructor.</td>
42+
</tr>
43+
<tr>
44+
<td><code>->url()</code></td>
45+
<td>Wrapper for <code>get_permalink()</code>.</td>
46+
</tr>
47+
<tr>
48+
<td><code>->slug()</code></td>
49+
<td>Returns <code>->post_name</code> from the <code>WP_Post</code> object.</td>
50+
</tr>
51+
<tr>
52+
<td><code>->status()</code></td>
53+
<td>Wrapper for <code>get_post_status()</code>.</td>
54+
</tr>
55+
<tr>
56+
<td><code>->format()</code></td>
57+
<td>Wrapper for <code>get_post_format()</code>.</td>
58+
</tr>
59+
<tr>
60+
<td><code>->title()</code></td>
61+
<td>Wrapper for <code>get_the_title()</code>.</td>
62+
</tr>
63+
<tr>
64+
<td><code>->excerpt()</code></td>
65+
<td>Wrapper for <code>get_the_excerpt()</code>.</td>
66+
</tr>
67+
<tr>
68+
<td><code>->publishDate()</code></td>
69+
<td>Wrapper for <code>get_the_date()</code>.</td>
70+
</tr>
71+
<tr>
72+
<td><code>->modifiedDate()</code></td>
73+
<td>Wrapper for <code>get_the_modified_time()</code>.</td>
74+
</tr>
75+
<tr>
76+
<td><code>->content()</code></td>
77+
<td>Returns <code>->post_content</code> from the <code>WP_Post</code> object and applies <code>the_content</code> filter.</td>
78+
</tr>
79+
<tr>
80+
<td><code>->parent()</code></td>
81+
<td>Returns a new <code>Post</code> object using <code>->post_parent</code> from the <code>WP_Post</code> object.</td>
82+
</tr>
83+
</table>

0 commit comments

Comments
 (0)