You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-17Lines changed: 58 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,21 +9,24 @@ Created by [Hieu Le](http://www.hieule.info)
9
9
10
10
MIT licensed.
11
11
12
-
Current version: 2.3.0
12
+
Current version: 2.4.0
13
13
14
14
15
15
## Features
16
+
16
17
* Full test suit built in supporting testing using your own Wordpress site.
17
-
* Support error logging to files with Monolog library.
18
+
*~~Support error logging to files with Monolog library.~~ Now, erros can be logged in a more felxible way via **error callbacks** (v 2.4.0)
18
19
* Support UTF-8 content.
19
20
* Closely implement the whole [XML-RPC WordPress API](http://codex.Wordpress.org/XML-RPC_WordPress_API).
20
21
* Detail exception will be thrown when errors occurs.
21
22
* (v2.2) Support proxy and http authentication.
22
23
* (v2.2.1) Allow value of `DateTime` class to be convert correctly to `datetime.iso8601` XML-RPC type,
24
+
* (v2.4.0) Support using custom User Agent string beside the default User Agent string.
25
+
* (v2.4.0) Support callbacks on **sending** and **error** events
23
26
24
27
## Installation
25
28
26
-
You will need [Composer](https://getcomposer.org/) installed on your machine to use this library. Verify that composer is installed by typing this command
29
+
~~You will need [Composer](https://getcomposer.org/) installed on your machine to use this library~~[Composer](https://getcomposer.org/) now is not required but recommended. Verify that composer is installed by typing this command
27
30
28
31
```bash
29
32
composer --version
@@ -32,6 +35,7 @@ composer --version
32
35
Choose one of the following methods to install **Wordpress XML-RPC PHP Client**
33
36
34
37
### Your project has used composer:
38
+
35
39
Add this dependency into your `composer.json` file
36
40
37
41
```json
@@ -41,34 +45,37 @@ Add this dependency into your `composer.json` file
41
45
After that, run `composer update` to install this package.
42
46
43
47
### Your project does not use composer:
44
-
Clone or download the archive of this package from [github](https://github.com/letrunghieu/Wordpress-xmlrpc-client/releases). Copy the package directory into a location of your project. Open the command line terminal and do these command
45
48
46
-
```bash
47
-
cd library/installed/dir
48
-
composer install
49
-
```
49
+
Clone or download the archive of this package from [github](https://github.com/letrunghieu/Wordpress-xmlrpc-client/releases). Include all files in the `src` directory into your project and start using **Wordpress XML-RPC Client**. You have to update the code of this library manually if using it without Composer.
50
50
51
-
After the installation progress finished, there will be a file called `autoload.php` created inside the `vendor` sub folder of the library. You should include this file to use **Wordpress XML-RPC PHP Client**.
51
+
Required PHP extension is `xmlrpc` extension. The `curl` extension is optional be recommended.
52
52
53
53
54
54
## Usage
55
55
56
-
All API call will be executed via an instance of the `WordpressClient` class. This is the way we initiate it:
56
+
All API call will be executed via an instance of the `WordpressClient` class. Since version 2.4.0, there is no mandatory parameters in the contructor. `endPoint`, `username`, and `password` can be updated anytime by calling `setCredentials` method. The last parameter in previous version contructor (which is an instance of `\Illuminate\Log\Writer` class) is deprecated and will be removed in the next major release. Below is an example of using this library:
57
57
58
58
```php
59
59
# Your Wordpress website is at: http://wp-website.com
60
60
$endpoint = "http://wp-website.com/xmlrpc.php";
61
61
62
-
# The logger instance
63
-
$wpLog = new \Illuminate\Log\Writer(new Monolog\Logger('wp-xmlrpc'));
64
-
65
-
# Save logs into file
66
-
$wpLog->useFiles('path-to-your-log-file');
62
+
# The Monolog logger instance
63
+
$wpLog = new Monolog\Logger('wp-xmlrpc');
67
64
68
65
# Create client instance
69
-
# The logger instance is optional
70
-
$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient($endpoint, 'username', 'password', $wpLog);
66
+
$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();
67
+
# Log error
68
+
$wpClient->onError(function($error, $event) use ($wpLog){
If you have used logging feture of previous version of this library, you should update your code to use the new way of loggin as above, the Monolog instance can be replaced by any kinds of logging tool that you have.
78
+
72
79
To use date time value, you must use an instance of `DateTime` class instead of a string.
73
80
74
81
There will be 2 types of exception may be thrown from this library:
@@ -78,7 +85,41 @@ There will be 2 types of exception may be thrown from this library:
78
85
79
86
For API reference, visit [Wordpress documentation](http://codex.Wordpress.org/XML-RPC_WordPress_API) or [Library API documentation](http://letrunghieu.github.io/wordpress-xmlrpc-client/api/index.html)
80
87
88
+
## User Agent (since 2.4.0)
89
+
90
+
The library use the default User Agent when contacting with Wordpress blogs. If you want to use onother one, pass your custom User Agent string into the `setUserAgent` method. If you passed a _falsy_ value (`null`, `false`, ...) the default one will be used (thank @WarrenMoore)
91
+
92
+
## Callbacks and events (since 2.4.0)
93
+
94
+
The library allow developers to listen on two events `Sending` and `Error`. You can add new closure as a callback for each events by calling `on<event>` method with the closure as parameter (see the `onError` example above).
95
+
96
+
### `onSending($event)`
97
+
98
+
This event is fired before each request is send to Wordpress blogs. `$event` is an array:
99
+
100
+
-`event`: the name of the event, here is `sending`
101
+
-`endpoint`: URL of the current endpoint
102
+
-`username`: current username
103
+
-`password`: current password
104
+
-`method`: current XML-RPC method
105
+
-`params`: parameters passed to the current method
106
+
-`request`: the body of the current request which will be sent
107
+
-`proxy`: current proxy config
108
+
-`auth`: current http auth config
109
+
110
+
### `onError($errorMessage, $event)`
111
+
112
+
This event is fired when the library run into errors, before any exception thrown. `$errorMessage` is a string. `$event` is an array:
113
+
114
+
-`event`: the name of the event, here is `sending`
115
+
-`endpoint`: URL of the current endpoint
116
+
-`request`: the body of the current request
117
+
-`proxy`: current proxy config
118
+
-`auth`: current http auth config
119
+
120
+
81
121
## Unit testing
122
+
82
123
By default, the project use recorded data as the default data for test suite. However, if you want to test with your own Wordpress installation, there are available options inside the `./tests/xmlrpc.yml` file:
83
124
84
125
*`endpoint`: the url of your Wordpress XML-RPC endpoint
0 commit comments