author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* XML-RPC protocol support for WordPress |
|
4 |
* |
|
5 |
* @package WordPress |
|
5 | 6 |
* @subpackage Publishing |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
10 |
* WordPress XMLRPC server implementation. |
|
11 |
* |
|
12 |
* Implements compatibility for Blogger API, MetaWeblog API, MovableType, and |
|
13 |
* pingback. Additional WordPress API for managing comments, pages, posts, |
|
14 |
* options, etc. |
|
15 |
* |
|
16 |
* As of WordPress 3.5.0, XML-RPC is enabled by default. It can be disabled |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::login(). |
0 | 18 |
* |
19 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @see IXR_Server |
0 | 22 |
*/ |
23 |
class wp_xmlrpc_server extends IXR_Server { |
|
5 | 24 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* Methods. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* |
5 | 27 |
* @var array |
28 |
*/ |
|
29 |
public $methods; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
|
5 | 31 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* Blog options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* |
5 | 34 |
* @var array |
35 |
*/ |
|
36 |
public $blog_options; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
|
5 | 38 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* IXR_Error instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* |
5 | 41 |
* @var IXR_Error |
42 |
*/ |
|
43 |
public $error; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
|
0 | 45 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* Flags that the user authentication has failed in this instance of wp_xmlrpc_server. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
protected $auth_failed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* Registers all of the XMLRPC methods that XMLRPC server understands. |
0 | 54 |
* |
55 |
* Sets up server and method property. Passes XMLRPC |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* methods through the {@see 'xmlrpc_methods'} filter to allow plugins to extend |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* or replace XML-RPC methods. |
0 | 58 |
* |
59 |
* @since 1.5.0 |
|
60 |
*/ |
|
5 | 61 |
public function __construct() { |
0 | 62 |
$this->methods = array( |
16 | 63 |
// WordPress API. |
9 | 64 |
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', |
65 |
'wp.newPost' => 'this:wp_newPost', |
|
66 |
'wp.editPost' => 'this:wp_editPost', |
|
67 |
'wp.deletePost' => 'this:wp_deletePost', |
|
68 |
'wp.getPost' => 'this:wp_getPost', |
|
69 |
'wp.getPosts' => 'this:wp_getPosts', |
|
70 |
'wp.newTerm' => 'this:wp_newTerm', |
|
71 |
'wp.editTerm' => 'this:wp_editTerm', |
|
72 |
'wp.deleteTerm' => 'this:wp_deleteTerm', |
|
73 |
'wp.getTerm' => 'this:wp_getTerm', |
|
74 |
'wp.getTerms' => 'this:wp_getTerms', |
|
75 |
'wp.getTaxonomy' => 'this:wp_getTaxonomy', |
|
76 |
'wp.getTaxonomies' => 'this:wp_getTaxonomies', |
|
77 |
'wp.getUser' => 'this:wp_getUser', |
|
78 |
'wp.getUsers' => 'this:wp_getUsers', |
|
79 |
'wp.getProfile' => 'this:wp_getProfile', |
|
80 |
'wp.editProfile' => 'this:wp_editProfile', |
|
81 |
'wp.getPage' => 'this:wp_getPage', |
|
82 |
'wp.getPages' => 'this:wp_getPages', |
|
83 |
'wp.newPage' => 'this:wp_newPage', |
|
84 |
'wp.deletePage' => 'this:wp_deletePage', |
|
85 |
'wp.editPage' => 'this:wp_editPage', |
|
86 |
'wp.getPageList' => 'this:wp_getPageList', |
|
87 |
'wp.getAuthors' => 'this:wp_getAuthors', |
|
16 | 88 |
'wp.getCategories' => 'this:mw_getCategories', // Alias. |
9 | 89 |
'wp.getTags' => 'this:wp_getTags', |
90 |
'wp.newCategory' => 'this:wp_newCategory', |
|
91 |
'wp.deleteCategory' => 'this:wp_deleteCategory', |
|
92 |
'wp.suggestCategories' => 'this:wp_suggestCategories', |
|
16 | 93 |
'wp.uploadFile' => 'this:mw_newMediaObject', // Alias. |
94 |
'wp.deleteFile' => 'this:wp_deletePost', // Alias. |
|
9 | 95 |
'wp.getCommentCount' => 'this:wp_getCommentCount', |
96 |
'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
|
97 |
'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
|
98 |
'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
|
99 |
'wp.getOptions' => 'this:wp_getOptions', |
|
100 |
'wp.setOptions' => 'this:wp_setOptions', |
|
101 |
'wp.getComment' => 'this:wp_getComment', |
|
102 |
'wp.getComments' => 'this:wp_getComments', |
|
103 |
'wp.deleteComment' => 'this:wp_deleteComment', |
|
104 |
'wp.editComment' => 'this:wp_editComment', |
|
105 |
'wp.newComment' => 'this:wp_newComment', |
|
106 |
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', |
|
107 |
'wp.getMediaItem' => 'this:wp_getMediaItem', |
|
108 |
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', |
|
109 |
'wp.getPostFormats' => 'this:wp_getPostFormats', |
|
110 |
'wp.getPostType' => 'this:wp_getPostType', |
|
111 |
'wp.getPostTypes' => 'this:wp_getPostTypes', |
|
112 |
'wp.getRevisions' => 'this:wp_getRevisions', |
|
113 |
'wp.restoreRevision' => 'this:wp_restoreRevision', |
|
0 | 114 |
|
16 | 115 |
// Blogger API. |
9 | 116 |
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
117 |
'blogger.getUserInfo' => 'this:blogger_getUserInfo', |
|
118 |
'blogger.getPost' => 'this:blogger_getPost', |
|
119 |
'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', |
|
120 |
'blogger.newPost' => 'this:blogger_newPost', |
|
121 |
'blogger.editPost' => 'this:blogger_editPost', |
|
122 |
'blogger.deletePost' => 'this:blogger_deletePost', |
|
0 | 123 |
|
16 | 124 |
// MetaWeblog API (with MT extensions to structs). |
9 | 125 |
'metaWeblog.newPost' => 'this:mw_newPost', |
126 |
'metaWeblog.editPost' => 'this:mw_editPost', |
|
127 |
'metaWeblog.getPost' => 'this:mw_getPost', |
|
128 |
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', |
|
129 |
'metaWeblog.getCategories' => 'this:mw_getCategories', |
|
130 |
'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', |
|
0 | 131 |
|
16 | 132 |
// MetaWeblog API aliases for Blogger API. |
133 |
// See http://www.xmlrpc.com/stories/storyReader$2460 |
|
9 | 134 |
'metaWeblog.deletePost' => 'this:blogger_deletePost', |
135 |
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|
0 | 136 |
|
16 | 137 |
// MovableType API. |
9 | 138 |
'mt.getCategoryList' => 'this:mt_getCategoryList', |
139 |
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', |
|
140 |
'mt.getPostCategories' => 'this:mt_getPostCategories', |
|
141 |
'mt.setPostCategories' => 'this:mt_setPostCategories', |
|
142 |
'mt.supportedMethods' => 'this:mt_supportedMethods', |
|
143 |
'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', |
|
144 |
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', |
|
145 |
'mt.publishPost' => 'this:mt_publishPost', |
|
0 | 146 |
|
16 | 147 |
// Pingback. |
9 | 148 |
'pingback.ping' => 'this:pingback_ping', |
0 | 149 |
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', |
150 |
||
9 | 151 |
'demo.sayHello' => 'this:sayHello', |
152 |
'demo.addTwoNumbers' => 'this:addTwoNumbers', |
|
0 | 153 |
); |
154 |
||
155 |
$this->initialise_blog_option_info(); |
|
5 | 156 |
|
157 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* Filters the methods exposed by the XML-RPC server. |
5 | 159 |
* |
160 |
* This filter can be used to add new methods, and remove built-in methods. |
|
161 |
* |
|
162 |
* @since 1.5.0 |
|
163 |
* |
|
16 | 164 |
* @param string[] $methods An array of XML-RPC methods, keyed by their methodName. |
5 | 165 |
*/ |
166 |
$this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
|
0 | 167 |
} |
168 |
||
5 | 169 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* Make private/protected methods readable for backward compatibility. |
5 | 171 |
* |
172 |
* @since 4.0.0 |
|
173 |
* |
|
16 | 174 |
* @param string $name Method to call. |
175 |
* @param array $arguments Arguments to pass when calling. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* @return array|IXR_Error|false Return value of the callback, false otherwise. |
5 | 177 |
*/ |
178 |
public function __call( $name, $arguments ) { |
|
179 |
if ( '_multisite_getUsersBlogs' === $name ) { |
|
16 | 180 |
return $this->_multisite_getUsersBlogs( ...$arguments ); |
5 | 181 |
} |
182 |
return false; |
|
183 |
} |
|
184 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* Serves the XML-RPC request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
*/ |
5 | 190 |
public function serve_request() { |
9 | 191 |
$this->IXR_Server( $this->methods ); |
0 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Test XMLRPC API by saying, "Hello!" to client. |
|
196 |
* |
|
197 |
* @since 1.5.0 |
|
198 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* @return string Hello string response. |
0 | 200 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
public function sayHello() { |
0 | 202 |
return 'Hello!'; |
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Test XMLRPC API by adding two numbers for client. |
|
207 |
* |
|
208 |
* @since 1.5.0 |
|
209 |
* |
|
16 | 210 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* @type int $number1 A number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* @type int $number2 A second number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
* @return int Sum of the two given numbers. |
0 | 217 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
public function addTwoNumbers( $args ) { |
0 | 219 |
$number1 = $args[0]; |
220 |
$number2 = $args[1]; |
|
221 |
return $number1 + $number2; |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Log user in. |
|
226 |
* |
|
227 |
* @since 2.8.0 |
|
228 |
* |
|
229 |
* @param string $username User's username. |
|
230 |
* @param string $password User's password. |
|
5 | 231 |
* @return WP_User|bool WP_User object if authentication passed, false otherwise |
0 | 232 |
*/ |
5 | 233 |
public function login( $username, $password ) { |
234 |
/* |
|
235 |
* Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
|
236 |
* option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
|
237 |
*/ |
|
238 |
$enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
|
239 |
if ( false === $enabled ) { |
|
240 |
$enabled = apply_filters( 'option_enable_xmlrpc', true ); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* Filters whether XML-RPC methods requiring authentication are enabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* Contrary to the way it's named, this filter does not control whether XML-RPC is *fully* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* enabled, rather, it only controls whether XML-RPC methods requiring authentication - such |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* as for publishing purposes - are enabled. |
5 | 249 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* Further, the filter does not control whether pingbacks or other custom endpoints that don't |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* require authentication are enabled. This behavior is expected, and due to how parity was matched |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* with the `enable_xmlrpc` UI option the filter replaced when it was introduced in 3.5. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* To disable XML-RPC methods that require authentication, use: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* add_filter( 'xmlrpc_enabled', '__return_false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
* and {@see 'xmlrpc_element_limit'} hooks. |
5 | 260 |
* |
261 |
* @since 3.5.0 |
|
262 |
* |
|
263 |
* @param bool $enabled Whether XML-RPC is enabled. Default true. |
|
264 |
*/ |
|
0 | 265 |
$enabled = apply_filters( 'xmlrpc_enabled', $enabled ); |
266 |
||
267 |
if ( ! $enabled ) { |
|
268 |
$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
|
269 |
return false; |
|
270 |
} |
|
271 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
if ( $this->auth_failed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$user = new WP_Error( 'login_prevented' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$user = wp_authenticate( $username, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
if ( is_wp_error( $user ) ) { |
0 | 279 |
$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) ); |
5 | 280 |
|
16 | 281 |
// Flag that authentication has failed once on this wp_xmlrpc_server instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
$this->auth_failed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
|
5 | 284 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* Filters the XML-RPC user login error message. |
5 | 286 |
* |
287 |
* @since 3.5.0 |
|
288 |
* |
|
16 | 289 |
* @param string $error The XML-RPC error message. |
290 |
* @param WP_Error $user WP_Error object. |
|
5 | 291 |
*/ |
0 | 292 |
$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user ); |
293 |
return false; |
|
294 |
} |
|
295 |
||
296 |
wp_set_current_user( $user->ID ); |
|
297 |
return $user; |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* Check user's credentials. Deprecated. |
|
302 |
* |
|
303 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* @deprecated 2.8.0 Use wp_xmlrpc_server::login() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
* @see wp_xmlrpc_server::login() |
0 | 306 |
* |
307 |
* @param string $username User's username. |
|
308 |
* @param string $password User's password. |
|
309 |
* @return bool Whether authentication passed. |
|
310 |
*/ |
|
5 | 311 |
public function login_pass_ok( $username, $password ) { |
0 | 312 |
return (bool) $this->login( $username, $password ); |
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
* Escape string or array of strings for database. |
|
317 |
* |
|
318 |
* @since 1.5.2 |
|
319 |
* |
|
320 |
* @param string|array $data Escape single string or array of strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* @return string|void Returns with string is passed, alters by-reference |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* when array is passed. |
0 | 323 |
*/ |
5 | 324 |
public function escape( &$data ) { |
9 | 325 |
if ( ! is_array( $data ) ) { |
0 | 326 |
return wp_slash( $data ); |
9 | 327 |
} |
0 | 328 |
|
329 |
foreach ( $data as &$v ) { |
|
9 | 330 |
if ( is_array( $v ) ) { |
0 | 331 |
$this->escape( $v ); |
9 | 332 |
} elseif ( ! is_object( $v ) ) { |
0 | 333 |
$v = wp_slash( $v ); |
9 | 334 |
} |
0 | 335 |
} |
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Retrieve custom fields for post. |
|
340 |
* |
|
341 |
* @since 2.5.0 |
|
342 |
* |
|
343 |
* @param int $post_id Post ID. |
|
344 |
* @return array Custom fields, if exist. |
|
345 |
*/ |
|
9 | 346 |
public function get_custom_fields( $post_id ) { |
0 | 347 |
$post_id = (int) $post_id; |
348 |
||
349 |
$custom_fields = array(); |
|
350 |
||
9 | 351 |
foreach ( (array) has_meta( $post_id ) as $meta ) { |
0 | 352 |
// Don't expose protected fields. |
9 | 353 |
if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) { |
0 | 354 |
continue; |
9 | 355 |
} |
0 | 356 |
|
357 |
$custom_fields[] = array( |
|
9 | 358 |
'id' => $meta['meta_id'], |
359 |
'key' => $meta['meta_key'], |
|
360 |
'value' => $meta['meta_value'], |
|
0 | 361 |
); |
362 |
} |
|
363 |
||
364 |
return $custom_fields; |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Set custom fields for post. |
|
369 |
* |
|
370 |
* @since 2.5.0 |
|
371 |
* |
|
16 | 372 |
* @param int $post_id Post ID. |
373 |
* @param array $fields Custom fields. |
|
0 | 374 |
*/ |
9 | 375 |
public function set_custom_fields( $post_id, $fields ) { |
0 | 376 |
$post_id = (int) $post_id; |
377 |
||
378 |
foreach ( (array) $fields as $meta ) { |
|
9 | 379 |
if ( isset( $meta['id'] ) ) { |
0 | 380 |
$meta['id'] = (int) $meta['id']; |
9 | 381 |
$pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
if ( ! $pmeta || $pmeta->post_id != $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
|
9 | 387 |
if ( isset( $meta['key'] ) ) { |
0 | 388 |
$meta['key'] = wp_unslash( $meta['key'] ); |
9 | 389 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
0 | 390 |
continue; |
9 | 391 |
} |
0 | 392 |
$meta['value'] = wp_unslash( $meta['value'] ); |
9 | 393 |
if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) { |
0 | 394 |
update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
9 | 395 |
} |
0 | 396 |
} elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
397 |
delete_metadata_by_mid( 'post', $meta['id'] ); |
|
398 |
} |
|
399 |
} elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { |
|
400 |
add_post_meta( $post_id, $meta['key'], $meta['value'] ); |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* Retrieve custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* @return array Array of custom fields, if they exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
public function get_term_custom_fields( $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
$custom_fields = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
$custom_fields[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
'id' => $meta['meta_id'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
'key' => $meta['meta_key'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
'value' => $meta['meta_value'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
return $custom_fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
* Set custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* |
16 | 439 |
* @param int $term_id Term ID. |
440 |
* @param array $fields Custom fields. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
public function set_term_custom_fields( $term_id, $fields ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
foreach ( (array) $fields as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
if ( isset( $meta['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
$meta['id'] = (int) $meta['id']; |
9 | 448 |
$pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
if ( isset( $meta['key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
$meta['key'] = wp_unslash( $meta['key'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
$meta['value'] = wp_unslash( $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
} elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
delete_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
} elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
/** |
0 | 468 |
* Set up blog options property. |
469 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* Passes property through {@see 'xmlrpc_blog_options'} filter. |
0 | 471 |
* |
472 |
* @since 2.6.0 |
|
473 |
*/ |
|
5 | 474 |
public function initialise_blog_option_info() { |
0 | 475 |
$this->blog_options = array( |
16 | 476 |
// Read-only options. |
9 | 477 |
'software_name' => array( |
478 |
'desc' => __( 'Software Name' ), |
|
479 |
'readonly' => true, |
|
480 |
'value' => 'WordPress', |
|
0 | 481 |
), |
9 | 482 |
'software_version' => array( |
483 |
'desc' => __( 'Software Version' ), |
|
484 |
'readonly' => true, |
|
485 |
'value' => get_bloginfo( 'version' ), |
|
0 | 486 |
), |
9 | 487 |
'blog_url' => array( |
488 |
'desc' => __( 'WordPress Address (URL)' ), |
|
489 |
'readonly' => true, |
|
490 |
'option' => 'siteurl', |
|
0 | 491 |
), |
9 | 492 |
'home_url' => array( |
493 |
'desc' => __( 'Site Address (URL)' ), |
|
494 |
'readonly' => true, |
|
495 |
'option' => 'home', |
|
0 | 496 |
), |
9 | 497 |
'login_url' => array( |
498 |
'desc' => __( 'Login Address (URL)' ), |
|
499 |
'readonly' => true, |
|
500 |
'value' => wp_login_url(), |
|
0 | 501 |
), |
9 | 502 |
'admin_url' => array( |
503 |
'desc' => __( 'The URL to the admin area' ), |
|
504 |
'readonly' => true, |
|
505 |
'value' => get_admin_url(), |
|
0 | 506 |
), |
507 |
'image_default_link_type' => array( |
|
9 | 508 |
'desc' => __( 'Image default link type' ), |
509 |
'readonly' => true, |
|
510 |
'option' => 'image_default_link_type', |
|
0 | 511 |
), |
9 | 512 |
'image_default_size' => array( |
513 |
'desc' => __( 'Image default size' ), |
|
514 |
'readonly' => true, |
|
515 |
'option' => 'image_default_size', |
|
0 | 516 |
), |
9 | 517 |
'image_default_align' => array( |
518 |
'desc' => __( 'Image default align' ), |
|
519 |
'readonly' => true, |
|
520 |
'option' => 'image_default_align', |
|
0 | 521 |
), |
9 | 522 |
'template' => array( |
523 |
'desc' => __( 'Template' ), |
|
524 |
'readonly' => true, |
|
525 |
'option' => 'template', |
|
0 | 526 |
), |
9 | 527 |
'stylesheet' => array( |
528 |
'desc' => __( 'Stylesheet' ), |
|
529 |
'readonly' => true, |
|
530 |
'option' => 'stylesheet', |
|
0 | 531 |
), |
9 | 532 |
'post_thumbnail' => array( |
533 |
'desc' => __( 'Post Thumbnail' ), |
|
534 |
'readonly' => true, |
|
535 |
'value' => current_theme_supports( 'post-thumbnails' ), |
|
0 | 536 |
), |
537 |
||
16 | 538 |
// Updatable options. |
9 | 539 |
'time_zone' => array( |
540 |
'desc' => __( 'Time Zone' ), |
|
541 |
'readonly' => false, |
|
542 |
'option' => 'gmt_offset', |
|
0 | 543 |
), |
9 | 544 |
'blog_title' => array( |
545 |
'desc' => __( 'Site Title' ), |
|
546 |
'readonly' => false, |
|
547 |
'option' => 'blogname', |
|
0 | 548 |
), |
9 | 549 |
'blog_tagline' => array( |
550 |
'desc' => __( 'Site Tagline' ), |
|
551 |
'readonly' => false, |
|
552 |
'option' => 'blogdescription', |
|
0 | 553 |
), |
9 | 554 |
'date_format' => array( |
555 |
'desc' => __( 'Date Format' ), |
|
556 |
'readonly' => false, |
|
557 |
'option' => 'date_format', |
|
0 | 558 |
), |
9 | 559 |
'time_format' => array( |
560 |
'desc' => __( 'Time Format' ), |
|
561 |
'readonly' => false, |
|
562 |
'option' => 'time_format', |
|
0 | 563 |
), |
9 | 564 |
'users_can_register' => array( |
565 |
'desc' => __( 'Allow new users to sign up' ), |
|
566 |
'readonly' => false, |
|
567 |
'option' => 'users_can_register', |
|
0 | 568 |
), |
9 | 569 |
'thumbnail_size_w' => array( |
570 |
'desc' => __( 'Thumbnail Width' ), |
|
571 |
'readonly' => false, |
|
572 |
'option' => 'thumbnail_size_w', |
|
0 | 573 |
), |
9 | 574 |
'thumbnail_size_h' => array( |
575 |
'desc' => __( 'Thumbnail Height' ), |
|
576 |
'readonly' => false, |
|
577 |
'option' => 'thumbnail_size_h', |
|
0 | 578 |
), |
9 | 579 |
'thumbnail_crop' => array( |
580 |
'desc' => __( 'Crop thumbnail to exact dimensions' ), |
|
581 |
'readonly' => false, |
|
582 |
'option' => 'thumbnail_crop', |
|
0 | 583 |
), |
9 | 584 |
'medium_size_w' => array( |
585 |
'desc' => __( 'Medium size image width' ), |
|
586 |
'readonly' => false, |
|
587 |
'option' => 'medium_size_w', |
|
0 | 588 |
), |
9 | 589 |
'medium_size_h' => array( |
590 |
'desc' => __( 'Medium size image height' ), |
|
591 |
'readonly' => false, |
|
592 |
'option' => 'medium_size_h', |
|
0 | 593 |
), |
9 | 594 |
'medium_large_size_w' => array( |
595 |
'desc' => __( 'Medium-Large size image width' ), |
|
596 |
'readonly' => false, |
|
597 |
'option' => 'medium_large_size_w', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
), |
9 | 599 |
'medium_large_size_h' => array( |
600 |
'desc' => __( 'Medium-Large size image height' ), |
|
601 |
'readonly' => false, |
|
602 |
'option' => 'medium_large_size_h', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
), |
9 | 604 |
'large_size_w' => array( |
605 |
'desc' => __( 'Large size image width' ), |
|
606 |
'readonly' => false, |
|
607 |
'option' => 'large_size_w', |
|
0 | 608 |
), |
9 | 609 |
'large_size_h' => array( |
610 |
'desc' => __( 'Large size image height' ), |
|
611 |
'readonly' => false, |
|
612 |
'option' => 'large_size_h', |
|
0 | 613 |
), |
9 | 614 |
'default_comment_status' => array( |
16 | 615 |
'desc' => __( 'Allow people to submit comments on new posts.' ), |
9 | 616 |
'readonly' => false, |
617 |
'option' => 'default_comment_status', |
|
0 | 618 |
), |
9 | 619 |
'default_ping_status' => array( |
16 | 620 |
'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new posts.' ), |
9 | 621 |
'readonly' => false, |
622 |
'option' => 'default_ping_status', |
|
623 |
), |
|
0 | 624 |
); |
625 |
||
5 | 626 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* Filters the XML-RPC blog options property. |
5 | 628 |
* |
629 |
* @since 2.6.0 |
|
630 |
* |
|
631 |
* @param array $blog_options An array of XML-RPC blog options. |
|
632 |
*/ |
|
0 | 633 |
$this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); |
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
* Retrieve the blogs of the user. |
|
638 |
* |
|
639 |
* @since 2.6.0 |
|
640 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* } |
5 | 647 |
* @return array|IXR_Error Array contains: |
0 | 648 |
* - 'isAdmin' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* - 'isPrimary' - whether the blog is the user's primary blog |
0 | 650 |
* - 'url' |
651 |
* - 'blogid' |
|
652 |
* - 'blogName' |
|
653 |
* - 'xmlrpc' - url of xmlrpc endpoint |
|
654 |
*/ |
|
5 | 655 |
public function wp_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
if ( ! $this->minimum_args( $args, 2 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
|
16 | 660 |
// If this isn't on WPMU then just use blogger_getUsersBlogs(). |
9 | 661 |
if ( ! is_multisite() ) { |
0 | 662 |
array_unshift( $args, 1 ); |
663 |
return $this->blogger_getUsersBlogs( $args ); |
|
664 |
} |
|
665 |
||
666 |
$this->escape( $args ); |
|
667 |
||
668 |
$username = $args[0]; |
|
669 |
$password = $args[1]; |
|
670 |
||
16 | 671 |
$user = $this->login( $username, $password ); |
672 |
if ( ! $user ) { |
|
0 | 673 |
return $this->error; |
9 | 674 |
} |
0 | 675 |
|
5 | 676 |
/** |
677 |
* Fires after the XML-RPC user has been authenticated but before the rest of |
|
678 |
* the method logic begins. |
|
679 |
* |
|
680 |
* All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
|
681 |
* equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
|
682 |
* |
|
683 |
* @since 2.5.0 |
|
684 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
* @param string $name The method name. |
5 | 686 |
*/ |
0 | 687 |
do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
688 |
||
9 | 689 |
$blogs = (array) get_blogs_of_user( $user->ID ); |
690 |
$struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
$primary_blog_id = 0; |
9 | 692 |
$active_blog = get_active_blog_for_user( $user->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
if ( $active_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
$primary_blog_id = (int) $active_blog->blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
} |
0 | 696 |
|
697 |
foreach ( $blogs as $blog ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
// Don't include blogs that aren't hosted at this site. |
16 | 699 |
if ( get_current_network_id() != $blog->site_id ) { |
0 | 700 |
continue; |
9 | 701 |
} |
0 | 702 |
|
703 |
$blog_id = $blog->userblog_id; |
|
704 |
||
705 |
switch_to_blog( $blog_id ); |
|
706 |
||
9 | 707 |
$is_admin = current_user_can( 'manage_options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
$is_primary = ( (int) $blog_id === $primary_blog_id ); |
0 | 709 |
|
710 |
$struct[] = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
'isAdmin' => $is_admin, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
'isPrimary' => $is_primary, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
'blogid' => (string) $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
'blogName' => get_option( 'blogname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
0 | 717 |
); |
718 |
||
719 |
restore_current_blog(); |
|
720 |
} |
|
721 |
||
722 |
return $struct; |
|
723 |
} |
|
724 |
||
725 |
/** |
|
726 |
* Checks if the method received at least the minimum number of arguments. |
|
727 |
* |
|
728 |
* @since 3.4.0 |
|
729 |
* |
|
16 | 730 |
* @param array $args An array of arguments to check. |
731 |
* @param int $count Minimum number of arguments. |
|
732 |
* @return bool True if `$args` contains at least `$count` arguments, false otherwise. |
|
0 | 733 |
*/ |
734 |
protected function minimum_args( $args, $count ) { |
|
16 | 735 |
if ( ! is_array( $args ) || count( $args ) < $count ) { |
0 | 736 |
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) ); |
737 |
return false; |
|
738 |
} |
|
739 |
||
740 |
return true; |
|
741 |
} |
|
742 |
||
743 |
/** |
|
744 |
* Prepares taxonomy data for return in an XML-RPC object. |
|
745 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
* @param object $taxonomy The unprepared taxonomy data. |
16 | 747 |
* @param array $fields The subset of taxonomy fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
* @return array The prepared taxonomy data. |
0 | 749 |
*/ |
750 |
protected function _prepare_taxonomy( $taxonomy, $fields ) { |
|
751 |
$_taxonomy = array( |
|
9 | 752 |
'name' => $taxonomy->name, |
753 |
'label' => $taxonomy->label, |
|
0 | 754 |
'hierarchical' => (bool) $taxonomy->hierarchical, |
9 | 755 |
'public' => (bool) $taxonomy->public, |
756 |
'show_ui' => (bool) $taxonomy->show_ui, |
|
757 |
'_builtin' => (bool) $taxonomy->_builtin, |
|
0 | 758 |
); |
759 |
||
16 | 760 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 761 |
$_taxonomy['labels'] = (array) $taxonomy->labels; |
9 | 762 |
} |
763 |
||
16 | 764 |
if ( in_array( 'cap', $fields, true ) ) { |
0 | 765 |
$_taxonomy['cap'] = (array) $taxonomy->cap; |
9 | 766 |
} |
767 |
||
16 | 768 |
if ( in_array( 'menu', $fields, true ) ) { |
0 | 769 |
$_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu; |
9 | 770 |
} |
771 |
||
16 | 772 |
if ( in_array( 'object_type', $fields, true ) ) { |
0 | 773 |
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
9 | 774 |
} |
0 | 775 |
|
5 | 776 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
* Filters XML-RPC-prepared data for the given taxonomy. |
5 | 778 |
* |
779 |
* @since 3.4.0 |
|
780 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @param array $_taxonomy An array of taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
* @param WP_Taxonomy $taxonomy Taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
* @param array $fields The subset of taxonomy fields to return. |
5 | 784 |
*/ |
0 | 785 |
return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
786 |
} |
|
787 |
||
788 |
/** |
|
789 |
* Prepares term data for return in an XML-RPC object. |
|
790 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* @param array|object $term The unprepared term data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
* @return array The prepared term data. |
0 | 793 |
*/ |
794 |
protected function _prepare_term( $term ) { |
|
795 |
$_term = $term; |
|
9 | 796 |
if ( ! is_array( $_term ) ) { |
0 | 797 |
$_term = get_object_vars( $_term ); |
9 | 798 |
} |
0 | 799 |
|
800 |
// For integers which may be larger than XML-RPC supports ensure we return strings. |
|
9 | 801 |
$_term['term_id'] = strval( $_term['term_id'] ); |
802 |
$_term['term_group'] = strval( $_term['term_group'] ); |
|
0 | 803 |
$_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] ); |
9 | 804 |
$_term['parent'] = strval( $_term['parent'] ); |
0 | 805 |
|
806 |
// Count we are happy to return as an integer because people really shouldn't use terms that much. |
|
807 |
$_term['count'] = intval( $_term['count'] ); |
|
808 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
// Get term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
$_term['custom_fields'] = $this->get_term_custom_fields( $_term['term_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
|
5 | 812 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* Filters XML-RPC-prepared data for the given term. |
5 | 814 |
* |
815 |
* @since 3.4.0 |
|
816 |
* |
|
817 |
* @param array $_term An array of term data. |
|
818 |
* @param array|object $term Term object or array. |
|
819 |
*/ |
|
0 | 820 |
return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
821 |
} |
|
822 |
||
823 |
/** |
|
824 |
* Convert a WordPress date string to an IXR_Date object. |
|
825 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param string $date Date string to convert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @return IXR_Date IXR_Date object. |
0 | 828 |
*/ |
829 |
protected function _convert_date( $date ) { |
|
16 | 830 |
if ( '0000-00-00 00:00:00' === $date ) { |
0 | 831 |
return new IXR_Date( '00000000T00:00:00Z' ); |
832 |
} |
|
833 |
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); |
|
834 |
} |
|
835 |
||
836 |
/** |
|
837 |
* Convert a WordPress GMT date string to an IXR_Date object. |
|
838 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
* @param string $date_gmt WordPress GMT date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* @param string $date Date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
* @return IXR_Date IXR_Date object. |
0 | 842 |
*/ |
843 |
protected function _convert_date_gmt( $date_gmt, $date ) { |
|
16 | 844 |
if ( '0000-00-00 00:00:00' !== $date && '0000-00-00 00:00:00' === $date_gmt ) { |
0 | 845 |
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) ); |
846 |
} |
|
847 |
return $this->_convert_date( $date_gmt ); |
|
848 |
} |
|
849 |
||
850 |
/** |
|
851 |
* Prepares post data for return in an XML-RPC object. |
|
852 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* @param array $post The unprepared post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
* @param array $fields The subset of post type fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
* @return array The prepared post data. |
0 | 856 |
*/ |
857 |
protected function _prepare_post( $post, $fields ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
// Holds the data for this post. built up based on $fields. |
0 | 859 |
$_post = array( 'post_id' => strval( $post['ID'] ) ); |
860 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
// Prepare common post fields. |
0 | 862 |
$post_fields = array( |
863 |
'post_title' => $post['post_title'], |
|
864 |
'post_date' => $this->_convert_date( $post['post_date'] ), |
|
865 |
'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
|
866 |
'post_modified' => $this->_convert_date( $post['post_modified'] ), |
|
867 |
'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ), |
|
868 |
'post_status' => $post['post_status'], |
|
869 |
'post_type' => $post['post_type'], |
|
870 |
'post_name' => $post['post_name'], |
|
871 |
'post_author' => $post['post_author'], |
|
872 |
'post_password' => $post['post_password'], |
|
873 |
'post_excerpt' => $post['post_excerpt'], |
|
874 |
'post_content' => $post['post_content'], |
|
875 |
'post_parent' => strval( $post['post_parent'] ), |
|
876 |
'post_mime_type' => $post['post_mime_type'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
'link' => get_permalink( $post['ID'] ), |
0 | 878 |
'guid' => $post['guid'], |
879 |
'menu_order' => intval( $post['menu_order'] ), |
|
880 |
'comment_status' => $post['comment_status'], |
|
881 |
'ping_status' => $post['ping_status'], |
|
16 | 882 |
'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ), |
0 | 883 |
); |
884 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
// Thumbnail. |
0 | 886 |
$post_fields['post_thumbnail'] = array(); |
9 | 887 |
$thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
0 | 888 |
if ( $thumbnail_id ) { |
9 | 889 |
$thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail'; |
0 | 890 |
$post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
891 |
} |
|
892 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
// Consider future posts as published. |
16 | 894 |
if ( 'future' === $post_fields['post_status'] ) { |
0 | 895 |
$post_fields['post_status'] = 'publish'; |
9 | 896 |
} |
0 | 897 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
// Fill in blank post format. |
0 | 899 |
$post_fields['post_format'] = get_post_format( $post['ID'] ); |
9 | 900 |
if ( empty( $post_fields['post_format'] ) ) { |
0 | 901 |
$post_fields['post_format'] = 'standard'; |
9 | 902 |
} |
0 | 903 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
// Merge requested $post_fields fields into $_post. |
16 | 905 |
if ( in_array( 'post', $fields, true ) ) { |
0 | 906 |
$_post = array_merge( $_post, $post_fields ); |
907 |
} else { |
|
908 |
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
|
9 | 909 |
$_post = array_merge( $_post, $requested_fields ); |
0 | 910 |
} |
911 |
||
16 | 912 |
$all_taxonomy_fields = in_array( 'taxonomies', $fields, true ); |
913 |
||
914 |
if ( $all_taxonomy_fields || in_array( 'terms', $fields, true ) ) { |
|
0 | 915 |
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' ); |
9 | 916 |
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies ); |
917 |
$_post['terms'] = array(); |
|
0 | 918 |
foreach ( $terms as $term ) { |
919 |
$_post['terms'][] = $this->_prepare_term( $term ); |
|
920 |
} |
|
921 |
} |
|
922 |
||
16 | 923 |
if ( in_array( 'custom_fields', $fields, true ) ) { |
0 | 924 |
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] ); |
9 | 925 |
} |
0 | 926 |
|
16 | 927 |
if ( in_array( 'enclosure', $fields, true ) ) { |
0 | 928 |
$_post['enclosure'] = array(); |
9 | 929 |
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' ); |
0 | 930 |
if ( ! empty( $enclosures ) ) { |
9 | 931 |
$encdata = explode( "\n", $enclosures[0] ); |
932 |
$_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
0 | 933 |
$_post['enclosure']['length'] = (int) trim( $encdata[1] ); |
9 | 934 |
$_post['enclosure']['type'] = trim( $encdata[2] ); |
0 | 935 |
} |
936 |
} |
|
937 |
||
5 | 938 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* Filters XML-RPC-prepared date for the given post. |
5 | 940 |
* |
941 |
* @since 3.4.0 |
|
942 |
* |
|
943 |
* @param array $_post An array of modified post data. |
|
944 |
* @param array $post An array of post data. |
|
945 |
* @param array $fields An array of post fields. |
|
946 |
*/ |
|
0 | 947 |
return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields ); |
948 |
} |
|
949 |
||
950 |
/** |
|
951 |
* Prepares post data for return in an XML-RPC object. |
|
952 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* @param WP_Post_Type $post_type Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
* @param array $fields The subset of post fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
* @return array The prepared post type data. |
0 | 959 |
*/ |
960 |
protected function _prepare_post_type( $post_type, $fields ) { |
|
961 |
$_post_type = array( |
|
9 | 962 |
'name' => $post_type->name, |
963 |
'label' => $post_type->label, |
|
0 | 964 |
'hierarchical' => (bool) $post_type->hierarchical, |
9 | 965 |
'public' => (bool) $post_type->public, |
966 |
'show_ui' => (bool) $post_type->show_ui, |
|
967 |
'_builtin' => (bool) $post_type->_builtin, |
|
968 |
'has_archive' => (bool) $post_type->has_archive, |
|
969 |
'supports' => get_all_post_type_supports( $post_type->name ), |
|
0 | 970 |
); |
971 |
||
16 | 972 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 973 |
$_post_type['labels'] = (array) $post_type->labels; |
974 |
} |
|
975 |
||
16 | 976 |
if ( in_array( 'cap', $fields, true ) ) { |
9 | 977 |
$_post_type['cap'] = (array) $post_type->cap; |
0 | 978 |
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; |
979 |
} |
|
980 |
||
16 | 981 |
if ( in_array( 'menu', $fields, true ) ) { |
0 | 982 |
$_post_type['menu_position'] = (int) $post_type->menu_position; |
9 | 983 |
$_post_type['menu_icon'] = $post_type->menu_icon; |
984 |
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; |
|
985 |
} |
|
986 |
||
16 | 987 |
if ( in_array( 'taxonomies', $fields, true ) ) { |
0 | 988 |
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
9 | 989 |
} |
0 | 990 |
|
5 | 991 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
* Filters XML-RPC-prepared date for the given post type. |
5 | 993 |
* |
994 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 996 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @param array $_post_type An array of post type data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
* @param WP_Post_Type $post_type Post type object. |
5 | 999 |
*/ |
0 | 1000 |
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
1001 |
} |
|
1002 |
||
1003 |
/** |
|
1004 |
* Prepares media item data for return in an XML-RPC object. |
|
1005 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* @param object $media_item The unprepared media item data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* @param string $thumbnail_size The image size to use for the thumbnail URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
* @return array The prepared media item data. |
0 | 1009 |
*/ |
1010 |
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
|
1011 |
$_media_item = array( |
|
1012 |
'attachment_id' => strval( $media_item->ID ), |
|
1013 |
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
|
1014 |
'parent' => $media_item->post_parent, |
|
1015 |
'link' => wp_get_attachment_url( $media_item->ID ), |
|
1016 |
'title' => $media_item->post_title, |
|
1017 |
'caption' => $media_item->post_excerpt, |
|
1018 |
'description' => $media_item->post_content, |
|
1019 |
'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
9 | 1020 |
'type' => $media_item->post_mime_type, |
0 | 1021 |
); |
1022 |
||
1023 |
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
|
9 | 1024 |
if ( $thumbnail_src ) { |
0 | 1025 |
$_media_item['thumbnail'] = $thumbnail_src[0]; |
9 | 1026 |
} else { |
0 | 1027 |
$_media_item['thumbnail'] = $_media_item['link']; |
9 | 1028 |
} |
0 | 1029 |
|
5 | 1030 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* Filters XML-RPC-prepared data for the given media item. |
5 | 1032 |
* |
1033 |
* @since 3.4.0 |
|
1034 |
* |
|
1035 |
* @param array $_media_item An array of media item data. |
|
1036 |
* @param object $media_item Media item object. |
|
1037 |
* @param string $thumbnail_size Image size. |
|
1038 |
*/ |
|
0 | 1039 |
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1040 |
} |
|
1041 |
||
1042 |
/** |
|
1043 |
* Prepares page data for return in an XML-RPC object. |
|
1044 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* @param object $page The unprepared page data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* @return array The prepared page data. |
0 | 1047 |
*/ |
1048 |
protected function _prepare_page( $page ) { |
|
1049 |
// Get all of the page content and link. |
|
1050 |
$full_page = get_extended( $page->post_content ); |
|
9 | 1051 |
$link = get_permalink( $page->ID ); |
0 | 1052 |
|
1053 |
// Get info the page parent if there is one. |
|
9 | 1054 |
$parent_title = ''; |
0 | 1055 |
if ( ! empty( $page->post_parent ) ) { |
9 | 1056 |
$parent = get_post( $page->post_parent ); |
0 | 1057 |
$parent_title = $parent->post_title; |
1058 |
} |
|
1059 |
||
1060 |
// Determine comment and ping settings. |
|
1061 |
$allow_comments = comments_open( $page->ID ) ? 1 : 0; |
|
9 | 1062 |
$allow_pings = pings_open( $page->ID ) ? 1 : 0; |
0 | 1063 |
|
1064 |
// Format page date. |
|
9 | 1065 |
$page_date = $this->_convert_date( $page->post_date ); |
0 | 1066 |
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); |
1067 |
||
1068 |
// Pull the categories info together. |
|
1069 |
$categories = array(); |
|
5 | 1070 |
if ( is_object_in_taxonomy( 'page', 'category' ) ) { |
1071 |
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { |
|
1072 |
$categories[] = get_cat_name( $cat_id ); |
|
1073 |
} |
|
0 | 1074 |
} |
1075 |
||
1076 |
// Get the author info. |
|
1077 |
$author = get_userdata( $page->post_author ); |
|
1078 |
||
1079 |
$page_template = get_page_template_slug( $page->ID ); |
|
9 | 1080 |
if ( empty( $page_template ) ) { |
0 | 1081 |
$page_template = 'default'; |
9 | 1082 |
} |
0 | 1083 |
|
1084 |
$_page = array( |
|
1085 |
'dateCreated' => $page_date, |
|
1086 |
'userid' => $page->post_author, |
|
1087 |
'page_id' => $page->ID, |
|
1088 |
'page_status' => $page->post_status, |
|
1089 |
'description' => $full_page['main'], |
|
1090 |
'title' => $page->post_title, |
|
1091 |
'link' => $link, |
|
1092 |
'permaLink' => $link, |
|
1093 |
'categories' => $categories, |
|
1094 |
'excerpt' => $page->post_excerpt, |
|
1095 |
'text_more' => $full_page['extended'], |
|
1096 |
'mt_allow_comments' => $allow_comments, |
|
1097 |
'mt_allow_pings' => $allow_pings, |
|
1098 |
'wp_slug' => $page->post_name, |
|
1099 |
'wp_password' => $page->post_password, |
|
1100 |
'wp_author' => $author->display_name, |
|
1101 |
'wp_page_parent_id' => $page->post_parent, |
|
1102 |
'wp_page_parent_title' => $parent_title, |
|
1103 |
'wp_page_order' => $page->menu_order, |
|
1104 |
'wp_author_id' => (string) $author->ID, |
|
1105 |
'wp_author_display_name' => $author->display_name, |
|
1106 |
'date_created_gmt' => $page_date_gmt, |
|
1107 |
'custom_fields' => $this->get_custom_fields( $page->ID ), |
|
9 | 1108 |
'wp_page_template' => $page_template, |
0 | 1109 |
); |
1110 |
||
5 | 1111 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
* Filters XML-RPC-prepared data for the given page. |
5 | 1113 |
* |
1114 |
* @since 3.4.0 |
|
1115 |
* |
|
1116 |
* @param array $_page An array of page data. |
|
1117 |
* @param WP_Post $page Page object. |
|
1118 |
*/ |
|
0 | 1119 |
return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); |
1120 |
} |
|
1121 |
||
1122 |
/** |
|
1123 |
* Prepares comment data for return in an XML-RPC object. |
|
1124 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
* @param object $comment The unprepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
* @return array The prepared comment data. |
0 | 1127 |
*/ |
1128 |
protected function _prepare_comment( $comment ) { |
|
1129 |
// Format page date. |
|
1130 |
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
|
1131 |
||
5 | 1132 |
if ( '0' == $comment->comment_approved ) { |
0 | 1133 |
$comment_status = 'hold'; |
16 | 1134 |
} elseif ( 'spam' === $comment->comment_approved ) { |
0 | 1135 |
$comment_status = 'spam'; |
5 | 1136 |
} elseif ( '1' == $comment->comment_approved ) { |
0 | 1137 |
$comment_status = 'approve'; |
5 | 1138 |
} else { |
0 | 1139 |
$comment_status = $comment->comment_approved; |
5 | 1140 |
} |
0 | 1141 |
$_comment = array( |
1142 |
'date_created_gmt' => $comment_date_gmt, |
|
1143 |
'user_id' => $comment->user_id, |
|
1144 |
'comment_id' => $comment->comment_ID, |
|
1145 |
'parent' => $comment->comment_parent, |
|
1146 |
'status' => $comment_status, |
|
1147 |
'content' => $comment->comment_content, |
|
9 | 1148 |
'link' => get_comment_link( $comment ), |
0 | 1149 |
'post_id' => $comment->comment_post_ID, |
9 | 1150 |
'post_title' => get_the_title( $comment->comment_post_ID ), |
0 | 1151 |
'author' => $comment->comment_author, |
1152 |
'author_url' => $comment->comment_author_url, |
|
1153 |
'author_email' => $comment->comment_author_email, |
|
1154 |
'author_ip' => $comment->comment_author_IP, |
|
1155 |
'type' => $comment->comment_type, |
|
1156 |
); |
|
1157 |
||
5 | 1158 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
* Filters XML-RPC-prepared data for the given comment. |
5 | 1160 |
* |
1161 |
* @since 3.4.0 |
|
1162 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* @param array $_comment An array of prepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* @param WP_Comment $comment Comment object. |
5 | 1165 |
*/ |
0 | 1166 |
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1167 |
} |
|
1168 |
||
1169 |
/** |
|
1170 |
* Prepares user data for return in an XML-RPC object. |
|
1171 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @param WP_User $user The unprepared user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* @param array $fields The subset of user fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* @return array The prepared user data. |
0 | 1175 |
*/ |
1176 |
protected function _prepare_user( $user, $fields ) { |
|
1177 |
$_user = array( 'user_id' => strval( $user->ID ) ); |
|
1178 |
||
1179 |
$user_fields = array( |
|
9 | 1180 |
'username' => $user->user_login, |
1181 |
'first_name' => $user->user_firstname, |
|
1182 |
'last_name' => $user->user_lastname, |
|
1183 |
'registered' => $this->_convert_date( $user->user_registered ), |
|
1184 |
'bio' => $user->user_description, |
|
1185 |
'email' => $user->user_email, |
|
1186 |
'nickname' => $user->nickname, |
|
1187 |
'nicename' => $user->user_nicename, |
|
1188 |
'url' => $user->user_url, |
|
1189 |
'display_name' => $user->display_name, |
|
1190 |
'roles' => $user->roles, |
|
0 | 1191 |
); |
1192 |
||
16 | 1193 |
if ( in_array( 'all', $fields, true ) ) { |
0 | 1194 |
$_user = array_merge( $_user, $user_fields ); |
1195 |
} else { |
|
16 | 1196 |
if ( in_array( 'basic', $fields, true ) ) { |
0 | 1197 |
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); |
9 | 1198 |
$fields = array_merge( $fields, $basic_fields ); |
0 | 1199 |
} |
1200 |
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); |
|
9 | 1201 |
$_user = array_merge( $_user, $requested_fields ); |
0 | 1202 |
} |
1203 |
||
5 | 1204 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* Filters XML-RPC-prepared data for the given user. |
5 | 1206 |
* |
1207 |
* @since 3.5.0 |
|
1208 |
* |
|
1209 |
* @param array $_user An array of user data. |
|
1210 |
* @param WP_User $user User object. |
|
1211 |
* @param array $fields An array of user fields. |
|
1212 |
*/ |
|
0 | 1213 |
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); |
1214 |
} |
|
1215 |
||
1216 |
/** |
|
1217 |
* Create a new post for any registered post type. |
|
1218 |
* |
|
1219 |
* @since 3.4.0 |
|
1220 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
* @link https://en.wikipedia.org/wiki/RSS_enclosure for information on RSS enclosures. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* |
16 | 1223 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* Method arguments. Note: top-level arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
* @type array $content_struct { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
* Content struct for adding a new post. See wp_insert_post() for information on |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
* additional post fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
* @type string $post_type Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* @type string $post_status Post status. Default 'draft' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* @type string $post_title Post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @type int $post_author Post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* @type string $post_excerpt Post excerpt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
* @type string $post_content Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
* @type string $post_date_gmt Post date in GMT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
* @type string $post_date Post date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
* @type string $post_password Post password (20-character limit). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
* @type string $comment_status Post comment enabled status. Accepts 'open' or 'closed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
* @type string $ping_status Post ping status. Accepts 'open' or 'closed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
* @type bool $sticky Whether the post should be sticky. Automatically false if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
* `$post_status` is 'private'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
* @type int $post_thumbnail ID of an image to use as the post thumbnail/featured image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
* @type array $custom_fields Array of meta key/value pairs to add to the post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
* @type array $terms Associative array with taxonomy names as keys and arrays |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
* of term IDs as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
* @type array $terms_names Associative array with taxonomy names as keys and arrays |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* of term names as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* @type array $enclosure { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* Array of feed enclosure data to add to post meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* @type string $url URL for the feed enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* @type int $length Size in bytes of the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
* @type string $type Mime-type for the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
0 | 1262 |
*/ |
5 | 1263 |
public function wp_newPost( $args ) { |
9 | 1264 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1265 |
return $this->error; |
9 | 1266 |
} |
0 | 1267 |
|
1268 |
$this->escape( $args ); |
|
1269 |
||
1270 |
$username = $args[1]; |
|
1271 |
$password = $args[2]; |
|
1272 |
$content_struct = $args[3]; |
|
1273 |
||
16 | 1274 |
$user = $this->login( $username, $password ); |
1275 |
if ( ! $user ) { |
|
0 | 1276 |
return $this->error; |
9 | 1277 |
} |
0 | 1278 |
|
16 | 1279 |
// Convert the date field back to IXR form. |
5 | 1280 |
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
1281 |
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1282 |
} |
|
1283 |
||
16 | 1284 |
/* |
1285 |
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1286 |
* since _insert_post() will ignore the non-GMT date if the GMT date is set. |
|
1287 |
*/ |
|
5 | 1288 |
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
16 | 1289 |
if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
5 | 1290 |
unset( $content_struct['post_date_gmt'] ); |
1291 |
} else { |
|
1292 |
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1293 |
} |
|
1294 |
} |
|
1295 |
||
1296 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1297 |
do_action( 'xmlrpc_call', 'wp.newPost' ); |
1298 |
||
1299 |
unset( $content_struct['ID'] ); |
|
1300 |
||
1301 |
return $this->_insert_post( $user, $content_struct ); |
|
1302 |
} |
|
1303 |
||
1304 |
/** |
|
1305 |
* Helper method for filtering out elements from an array. |
|
1306 |
* |
|
1307 |
* @since 3.4.0 |
|
1308 |
* |
|
1309 |
* @param int $count Number to compare to one. |
|
1310 |
*/ |
|
1311 |
private function _is_greater_than_one( $count ) { |
|
1312 |
return $count > 1; |
|
1313 |
} |
|
1314 |
||
1315 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* Encapsulate the logic for sticking a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* and determining if the user has permission to do so |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
* @param array $post_data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
* @param bool $update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
* @return void|IXR_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
private function _toggle_sticky( $post_data, $update = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
// Private and password-protected posts cannot be stickied. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
// Error if the client tried to stick the post, otherwise, silently unstick. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
if ( ! empty( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
if ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
} |
9 | 1338 |
} elseif ( isset( $post_data['sticky'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
$sticky = wp_validate_boolean( $post_data['sticky'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
if ( $sticky ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
stick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
0 | 1354 |
* |
1355 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
* @param WP_User $user The post author if post_author isn't set in $content_struct. |
5 | 1360 |
* @param array|IXR_Error $content_struct Post data to insert. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
* @return IXR_Error|string |
0 | 1362 |
*/ |
1363 |
protected function _insert_post( $user, $content_struct ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
'post_status' => 'draft', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
'post_type' => 'post', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
'post_author' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
'post_password' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
'post_excerpt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
'post_content' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
'post_title' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
'post_date' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
'post_date_gmt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
'post_format' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
'post_name' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
'post_thumbnail' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
'post_parent' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
'ping_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
'comment_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
'custom_fields' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
'terms_names' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
'terms' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
'sticky' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
'enclosure' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
'ID' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
0 | 1389 |
|
1390 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
|
9 | 1391 |
if ( ! $post_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1393 |
} |
0 | 1394 |
|
1395 |
$update = ! empty( $post_data['ID'] ); |
|
1396 |
||
1397 |
if ( $update ) { |
|
9 | 1398 |
if ( ! get_post( $post_data['ID'] ) ) { |
0 | 1399 |
return new IXR_Error( 401, __( 'Invalid post ID.' ) ); |
9 | 1400 |
} |
1401 |
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) { |
|
0 | 1402 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1403 |
} |
16 | 1404 |
if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) { |
0 | 1405 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 1406 |
} |
0 | 1407 |
} else { |
9 | 1408 |
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 1409 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
9 | 1410 |
} |
0 | 1411 |
} |
1412 |
||
1413 |
switch ( $post_data['post_status'] ) { |
|
1414 |
case 'draft': |
|
1415 |
case 'pending': |
|
1416 |
break; |
|
1417 |
case 'private': |
|
9 | 1418 |
if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
9 | 1420 |
} |
0 | 1421 |
break; |
1422 |
case 'publish': |
|
1423 |
case 'future': |
|
9 | 1424 |
if ( ! current_user_can( $post_type->cap->publish_posts ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
9 | 1426 |
} |
0 | 1427 |
break; |
1428 |
default: |
|
9 | 1429 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) { |
0 | 1430 |
$post_data['post_status'] = 'draft'; |
9 | 1431 |
} |
1432 |
break; |
|
1433 |
} |
|
1434 |
||
1435 |
if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
9 | 1437 |
} |
0 | 1438 |
|
1439 |
$post_data['post_author'] = absint( $post_data['post_author'] ); |
|
1440 |
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
|
9 | 1441 |
if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 1443 |
} |
0 | 1444 |
|
1445 |
$author = get_userdata( $post_data['post_author'] ); |
|
1446 |
||
9 | 1447 |
if ( ! $author ) { |
0 | 1448 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 1449 |
} |
0 | 1450 |
} else { |
1451 |
$post_data['post_author'] = $user->ID; |
|
1452 |
} |
|
1453 |
||
16 | 1454 |
if ( isset( $post_data['comment_status'] ) && 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { |
0 | 1455 |
unset( $post_data['comment_status'] ); |
9 | 1456 |
} |
1457 |
||
16 | 1458 |
if ( isset( $post_data['ping_status'] ) && 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { |
0 | 1459 |
unset( $post_data['ping_status'] ); |
9 | 1460 |
} |
0 | 1461 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
// Do some timestamp voodoo. |
0 | 1463 |
if ( ! empty( $post_data['post_date_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 1465 |
$dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1466 |
} elseif ( ! empty( $post_data['post_date'] ) ) { |
|
1467 |
$dateCreated = $post_data['post_date']->getIso(); |
|
1468 |
} |
|
1469 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
// Default to not flagging the post date to be edited unless it's intentional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
$post_data['edit_date'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
|
0 | 1473 |
if ( ! empty( $dateCreated ) ) { |
16 | 1474 |
$post_data['post_date'] = iso8601_to_datetime( $dateCreated ); |
1475 |
$post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
$post_data['edit_date'] = true; |
0 | 1479 |
} |
1480 |
||
9 | 1481 |
if ( ! isset( $post_data['ID'] ) ) { |
0 | 1482 |
$post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
9 | 1483 |
} |
0 | 1484 |
$post_ID = $post_data['ID']; |
1485 |
||
16 | 1486 |
if ( 'post' === $post_data['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
$error = $this->_toggle_sticky( $post_data, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
return $error; |
0 | 1490 |
} |
1491 |
} |
|
1492 |
||
1493 |
if ( isset( $post_data['post_thumbnail'] ) ) { |
|
16 | 1494 |
// Empty value deletes, non-empty value adds/updates. |
9 | 1495 |
if ( ! $post_data['post_thumbnail'] ) { |
0 | 1496 |
delete_post_thumbnail( $post_ID ); |
9 | 1497 |
} elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) { |
0 | 1498 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 1499 |
} |
0 | 1500 |
set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
1501 |
unset( $content_struct['post_thumbnail'] ); |
|
1502 |
} |
|
1503 |
||
9 | 1504 |
if ( isset( $post_data['custom_fields'] ) ) { |
0 | 1505 |
$this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
9 | 1506 |
} |
0 | 1507 |
|
1508 |
if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
|
1509 |
$post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
|
1510 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
// Accumulate term IDs from terms and terms_names. |
0 | 1512 |
$terms = array(); |
1513 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
// First validate the terms specified by ID. |
0 | 1515 |
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1516 |
$taxonomies = array_keys( $post_data['terms'] ); |
|
1517 |
||
16 | 1518 |
// Validating term IDs. |
0 | 1519 |
foreach ( $taxonomies as $taxonomy ) { |
9 | 1520 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1521 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1522 |
} |
1523 |
||
1524 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1525 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1526 |
} |
1527 |
||
1528 |
$term_ids = $post_data['terms'][ $taxonomy ]; |
|
5 | 1529 |
$terms[ $taxonomy ] = array(); |
0 | 1530 |
foreach ( $term_ids as $term_id ) { |
1531 |
$term = get_term_by( 'id', $term_id, $taxonomy ); |
|
1532 |
||
9 | 1533 |
if ( ! $term ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
9 | 1535 |
} |
1536 |
||
1537 |
$terms[ $taxonomy ][] = (int) $term_id; |
|
0 | 1538 |
} |
1539 |
} |
|
1540 |
} |
|
1541 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1542 |
// Now validate terms specified by name. |
0 | 1543 |
if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1544 |
$taxonomies = array_keys( $post_data['terms_names'] ); |
|
1545 |
||
1546 |
foreach ( $taxonomies as $taxonomy ) { |
|
9 | 1547 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1548 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1549 |
} |
1550 |
||
1551 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1552 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1553 |
} |
0 | 1554 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
* For hierarchical taxonomies, we can't assign a term when multiple terms |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
* in the hierarchy share the same name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
*/ |
0 | 1559 |
$ambiguous_terms = array(); |
1560 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
9 | 1561 |
$tax_term_names = get_terms( |
1562 |
array( |
|
16 | 1563 |
'taxonomy' => $taxonomy, |
9 | 1564 |
'fields' => 'names', |
1565 |
'hide_empty' => false, |
|
1566 |
) |
|
1567 |
); |
|
0 | 1568 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
// Count the number of terms with the same name. |
0 | 1570 |
$tax_term_names_count = array_count_values( $tax_term_names ); |
1571 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
// Filter out non-ambiguous term names. |
9 | 1573 |
$ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) ); |
0 | 1574 |
|
1575 |
$ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
|
1576 |
} |
|
1577 |
||
9 | 1578 |
$term_names = $post_data['terms_names'][ $taxonomy ]; |
0 | 1579 |
foreach ( $term_names as $term_name ) { |
16 | 1580 |
if ( in_array( $term_name, $ambiguous_terms, true ) ) { |
0 | 1581 |
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
9 | 1582 |
} |
0 | 1583 |
|
1584 |
$term = get_term_by( 'name', $term_name, $taxonomy ); |
|
1585 |
||
1586 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
// Term doesn't exist, so check that the user is allowed to create new terms. |
9 | 1588 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->edit_terms ) ) { |
0 | 1589 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
9 | 1590 |
} |
0 | 1591 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
// Create the new term. |
0 | 1593 |
$term_info = wp_insert_term( $term_name, $taxonomy ); |
9 | 1594 |
if ( is_wp_error( $term_info ) ) { |
0 | 1595 |
return new IXR_Error( 500, $term_info->get_error_message() ); |
9 | 1596 |
} |
1597 |
||
1598 |
$terms[ $taxonomy ][] = (int) $term_info['term_id']; |
|
0 | 1599 |
} else { |
9 | 1600 |
$terms[ $taxonomy ][] = (int) $term->term_id; |
0 | 1601 |
} |
1602 |
} |
|
1603 |
} |
|
1604 |
} |
|
1605 |
||
1606 |
$post_data['tax_input'] = $terms; |
|
1607 |
unset( $post_data['terms'], $post_data['terms_names'] ); |
|
1608 |
} |
|
1609 |
||
1610 |
if ( isset( $post_data['post_format'] ) ) { |
|
1611 |
$format = set_post_format( $post_ID, $post_data['post_format'] ); |
|
1612 |
||
9 | 1613 |
if ( is_wp_error( $format ) ) { |
0 | 1614 |
return new IXR_Error( 500, $format->get_error_message() ); |
9 | 1615 |
} |
0 | 1616 |
|
1617 |
unset( $post_data['post_format'] ); |
|
1618 |
} |
|
1619 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
// Handle enclosures. |
0 | 1621 |
$enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; |
1622 |
$this->add_enclosure_if_new( $post_ID, $enclosure ); |
|
1623 |
||
1624 |
$this->attach_uploads( $post_ID, $post_data['post_content'] ); |
|
1625 |
||
5 | 1626 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
* Filters post data array to be inserted via XML-RPC. |
5 | 1628 |
* |
1629 |
* @since 3.4.0 |
|
1630 |
* |
|
1631 |
* @param array $post_data Parsed array of post data. |
|
1632 |
* @param array $content_struct Post data array. |
|
1633 |
*/ |
|
0 | 1634 |
$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); |
1635 |
||
1636 |
$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); |
|
9 | 1637 |
if ( is_wp_error( $post_ID ) ) { |
0 | 1638 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
9 | 1639 |
} |
1640 |
||
1641 |
if ( ! $post_ID ) { |
|
16 | 1642 |
if ( $update ) { |
1643 |
return new IXR_Error( 401, __( 'Sorry, the post could not be updated.' ) ); |
|
1644 |
} else { |
|
1645 |
return new IXR_Error( 401, __( 'Sorry, the post could not be created.' ) ); |
|
1646 |
} |
|
9 | 1647 |
} |
0 | 1648 |
|
1649 |
return strval( $post_ID ); |
|
1650 |
} |
|
1651 |
||
1652 |
/** |
|
1653 |
* Edit a post for any registered post type. |
|
1654 |
* |
|
1655 |
* The $content_struct parameter only needs to contain fields that |
|
1656 |
* should be changed. All other fields will retain their existing values. |
|
1657 |
* |
|
1658 |
* @since 3.4.0 |
|
1659 |
* |
|
16 | 1660 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
* @type array $content_struct Extra content arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
* @return true|IXR_Error True on success, IXR_Error on failure. |
0 | 1670 |
*/ |
5 | 1671 |
public function wp_editPost( $args ) { |
9 | 1672 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 1673 |
return $this->error; |
9 | 1674 |
} |
0 | 1675 |
|
1676 |
$this->escape( $args ); |
|
1677 |
||
1678 |
$username = $args[1]; |
|
1679 |
$password = $args[2]; |
|
1680 |
$post_id = (int) $args[3]; |
|
1681 |
$content_struct = $args[4]; |
|
1682 |
||
16 | 1683 |
$user = $this->login( $username, $password ); |
1684 |
if ( ! $user ) { |
|
0 | 1685 |
return $this->error; |
9 | 1686 |
} |
0 | 1687 |
|
5 | 1688 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1689 |
do_action( 'xmlrpc_call', 'wp.editPost' ); |
1690 |
||
1691 |
$post = get_post( $post_id, ARRAY_A ); |
|
1692 |
||
9 | 1693 |
if ( empty( $post['ID'] ) ) { |
0 | 1694 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1695 |
} |
0 | 1696 |
|
1697 |
if ( isset( $content_struct['if_not_modified_since'] ) ) { |
|
1698 |
// If the post has been modified since the date provided, return an error. |
|
1699 |
if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { |
|
1700 |
return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); |
|
1701 |
} |
|
1702 |
} |
|
1703 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1704 |
// Convert the date field back to IXR form. |
0 | 1705 |
$post['post_date'] = $this->_convert_date( $post['post_date'] ); |
1706 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1707 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
* since _insert_post() will ignore the non-GMT date if the GMT date is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
*/ |
16 | 1711 |
if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
0 | 1712 |
unset( $post['post_date_gmt'] ); |
9 | 1713 |
} else { |
0 | 1714 |
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); |
9 | 1715 |
} |
0 | 1716 |
|
16 | 1717 |
/* |
1718 |
* If the API client did not provide 'post_date', then we must not perpetuate the value that |
|
1719 |
* was stored in the database, or it will appear to be an intentional edit. Conveying it here |
|
1720 |
* as if it was coming from the API client will cause an otherwise zeroed out 'post_date_gmt' |
|
1721 |
* to get set with the value that was originally stored in the database when the draft was created. |
|
1722 |
*/ |
|
1723 |
if ( ! isset( $content_struct['post_date'] ) ) { |
|
1724 |
unset( $post['post_date'] ); |
|
1725 |
} |
|
1726 |
||
0 | 1727 |
$this->escape( $post ); |
1728 |
$merged_content_struct = array_merge( $post, $content_struct ); |
|
1729 |
||
1730 |
$retval = $this->_insert_post( $user, $merged_content_struct ); |
|
9 | 1731 |
if ( $retval instanceof IXR_Error ) { |
0 | 1732 |
return $retval; |
9 | 1733 |
} |
0 | 1734 |
|
1735 |
return true; |
|
1736 |
} |
|
1737 |
||
1738 |
/** |
|
1739 |
* Delete a post for any registered post type. |
|
1740 |
* |
|
1741 |
* @since 3.4.0 |
|
1742 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
* @see wp_delete_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* |
16 | 1745 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 1754 |
*/ |
5 | 1755 |
public function wp_deletePost( $args ) { |
9 | 1756 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1757 |
return $this->error; |
9 | 1758 |
} |
0 | 1759 |
|
1760 |
$this->escape( $args ); |
|
1761 |
||
9 | 1762 |
$username = $args[1]; |
1763 |
$password = $args[2]; |
|
1764 |
$post_id = (int) $args[3]; |
|
1765 |
||
16 | 1766 |
$user = $this->login( $username, $password ); |
1767 |
if ( ! $user ) { |
|
0 | 1768 |
return $this->error; |
9 | 1769 |
} |
0 | 1770 |
|
5 | 1771 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1772 |
do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1773 |
||
1774 |
$post = get_post( $post_id, ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
if ( empty( $post['ID'] ) ) { |
0 | 1776 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
0 | 1780 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this post.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
} |
0 | 1782 |
|
1783 |
$result = wp_delete_post( $post_id ); |
|
1784 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
if ( ! $result ) { |
16 | 1786 |
return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
} |
0 | 1788 |
|
1789 |
return true; |
|
1790 |
} |
|
1791 |
||
1792 |
/** |
|
1793 |
* Retrieve a post. |
|
1794 |
* |
|
1795 |
* @since 3.4.0 |
|
1796 |
* |
|
1797 |
* The optional $fields parameter specifies what fields will be included |
|
1798 |
* in the response array. This should be a list of field names. 'post_id' will |
|
1799 |
* always be included in the response regardless of the value of $fields. |
|
1800 |
* |
|
1801 |
* Instead of, or in addition to, individual field names, conceptual group |
|
1802 |
* names can be used to specify multiple fields. The available conceptual |
|
1803 |
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields', |
|
1804 |
* and 'enclosure'. |
|
1805 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
* @see get_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
* @type array $fields The subset of post type fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* } |
5 | 1817 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 1818 |
* - 'post_id' |
1819 |
* - 'post_title' |
|
1820 |
* - 'post_date' |
|
1821 |
* - 'post_date_gmt' |
|
1822 |
* - 'post_modified' |
|
1823 |
* - 'post_modified_gmt' |
|
1824 |
* - 'post_status' |
|
1825 |
* - 'post_type' |
|
1826 |
* - 'post_name' |
|
1827 |
* - 'post_author' |
|
1828 |
* - 'post_password' |
|
1829 |
* - 'post_excerpt' |
|
1830 |
* - 'post_content' |
|
1831 |
* - 'link' |
|
1832 |
* - 'comment_status' |
|
1833 |
* - 'ping_status' |
|
1834 |
* - 'sticky' |
|
1835 |
* - 'custom_fields' |
|
1836 |
* - 'terms' |
|
1837 |
* - 'categories' |
|
1838 |
* - 'tags' |
|
1839 |
* - 'enclosure' |
|
1840 |
*/ |
|
5 | 1841 |
public function wp_getPost( $args ) { |
9 | 1842 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1843 |
return $this->error; |
9 | 1844 |
} |
0 | 1845 |
|
1846 |
$this->escape( $args ); |
|
1847 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1849 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
$post_id = (int) $args[3]; |
0 | 1851 |
|
5 | 1852 |
if ( isset( $args[4] ) ) { |
0 | 1853 |
$fields = $args[4]; |
5 | 1854 |
} else { |
1855 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
* Filters the list of post query fields used by the given XML-RPC method. |
5 | 1857 |
* |
1858 |
* @since 3.4.0 |
|
1859 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
* @param array $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'. |
5 | 1861 |
* @param string $method Method name. |
1862 |
*/ |
|
0 | 1863 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
5 | 1864 |
} |
0 | 1865 |
|
16 | 1866 |
$user = $this->login( $username, $password ); |
1867 |
if ( ! $user ) { |
|
0 | 1868 |
return $this->error; |
9 | 1869 |
} |
0 | 1870 |
|
5 | 1871 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1872 |
do_action( 'xmlrpc_call', 'wp.getPost' ); |
1873 |
||
1874 |
$post = get_post( $post_id, ARRAY_A ); |
|
1875 |
||
9 | 1876 |
if ( empty( $post['ID'] ) ) { |
0 | 1877 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1878 |
} |
1879 |
||
1880 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1882 |
} |
0 | 1883 |
|
1884 |
return $this->_prepare_post( $post, $fields ); |
|
1885 |
} |
|
1886 |
||
1887 |
/** |
|
1888 |
* Retrieve posts. |
|
1889 |
* |
|
1890 |
* @since 3.4.0 |
|
1891 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1892 |
* @see wp_get_recent_posts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
* @see wp_getPost() for more on `$fields` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1894 |
* @see get_posts() for more on `$filter` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1895 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1898 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1899 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1900 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1901 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
* @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
* 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
* @type array $fields Optional. The subset of post type fields to return in the response array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
* } |
5 | 1907 |
* @return array|IXR_Error Array contains a collection of posts. |
0 | 1908 |
*/ |
5 | 1909 |
public function wp_getPosts( $args ) { |
9 | 1910 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 1911 |
return $this->error; |
9 | 1912 |
} |
0 | 1913 |
|
1914 |
$this->escape( $args ); |
|
1915 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 1919 |
|
5 | 1920 |
if ( isset( $args[4] ) ) { |
0 | 1921 |
$fields = $args[4]; |
5 | 1922 |
} else { |
1923 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1924 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
5 | 1925 |
} |
0 | 1926 |
|
16 | 1927 |
$user = $this->login( $username, $password ); |
1928 |
if ( ! $user ) { |
|
0 | 1929 |
return $this->error; |
9 | 1930 |
} |
0 | 1931 |
|
5 | 1932 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1933 |
do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1934 |
||
1935 |
$query = array(); |
|
1936 |
||
1937 |
if ( isset( $filter['post_type'] ) ) { |
|
1938 |
$post_type = get_post_type_object( $filter['post_type'] ); |
|
9 | 1939 |
if ( ! ( (bool) $post_type ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1941 |
} |
0 | 1942 |
} else { |
1943 |
$post_type = get_post_type_object( 'post' ); |
|
1944 |
} |
|
1945 |
||
9 | 1946 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 1948 |
} |
0 | 1949 |
|
1950 |
$query['post_type'] = $post_type->name; |
|
1951 |
||
9 | 1952 |
if ( isset( $filter['post_status'] ) ) { |
0 | 1953 |
$query['post_status'] = $filter['post_status']; |
9 | 1954 |
} |
1955 |
||
1956 |
if ( isset( $filter['number'] ) ) { |
|
0 | 1957 |
$query['numberposts'] = absint( $filter['number'] ); |
9 | 1958 |
} |
1959 |
||
1960 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 1961 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 1962 |
} |
0 | 1963 |
|
1964 |
if ( isset( $filter['orderby'] ) ) { |
|
1965 |
$query['orderby'] = $filter['orderby']; |
|
1966 |
||
9 | 1967 |
if ( isset( $filter['order'] ) ) { |
0 | 1968 |
$query['order'] = $filter['order']; |
9 | 1969 |
} |
0 | 1970 |
} |
1971 |
||
1972 |
if ( isset( $filter['s'] ) ) { |
|
1973 |
$query['s'] = $filter['s']; |
|
1974 |
} |
|
1975 |
||
1976 |
$posts_list = wp_get_recent_posts( $query ); |
|
1977 |
||
9 | 1978 |
if ( ! $posts_list ) { |
0 | 1979 |
return array(); |
9 | 1980 |
} |
0 | 1981 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
// Holds all the posts data. |
0 | 1983 |
$struct = array(); |
1984 |
||
1985 |
foreach ( $posts_list as $post ) { |
|
9 | 1986 |
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) { |
0 | 1987 |
continue; |
9 | 1988 |
} |
0 | 1989 |
|
1990 |
$struct[] = $this->_prepare_post( $post, $fields ); |
|
1991 |
} |
|
1992 |
||
1993 |
return $struct; |
|
1994 |
} |
|
1995 |
||
1996 |
/** |
|
1997 |
* Create a new term. |
|
1998 |
* |
|
1999 |
* @since 3.4.0 |
|
2000 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
* @see wp_insert_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2002 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2003 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2005 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2006 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2007 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
* @type array $content_struct Content struct for adding a new term. The struct must contain |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
* the term 'name' and 'taxonomy'. Optional accepted values include |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
* 'parent', 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
* @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
0 | 2014 |
*/ |
5 | 2015 |
public function wp_newTerm( $args ) { |
9 | 2016 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2017 |
return $this->error; |
9 | 2018 |
} |
0 | 2019 |
|
2020 |
$this->escape( $args ); |
|
2021 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
$content_struct = $args[3]; |
0 | 2025 |
|
16 | 2026 |
$user = $this->login( $username, $password ); |
2027 |
if ( ! $user ) { |
|
0 | 2028 |
return $this->error; |
9 | 2029 |
} |
0 | 2030 |
|
5 | 2031 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2032 |
do_action( 'xmlrpc_call', 'wp.newTerm' ); |
2033 |
||
9 | 2034 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2036 |
} |
0 | 2037 |
|
2038 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2039 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
} |
0 | 2043 |
|
2044 |
$taxonomy = (array) $taxonomy; |
|
2045 |
||
16 | 2046 |
// Hold the data of the term. |
0 | 2047 |
$term_data = array(); |
2048 |
||
2049 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
9 | 2050 |
if ( empty( $term_data['name'] ) ) { |
0 | 2051 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2052 |
} |
0 | 2053 |
|
2054 |
if ( isset( $content_struct['parent'] ) ) { |
|
9 | 2055 |
if ( ! $taxonomy['hierarchical'] ) { |
0 | 2056 |
return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
9 | 2057 |
} |
0 | 2058 |
|
2059 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2060 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2061 |
||
2062 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2063 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2064 |
} |
2065 |
||
2066 |
if ( ! $parent_term ) { |
|
0 | 2067 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2068 |
} |
0 | 2069 |
|
2070 |
$term_data['parent'] = $content_struct['parent']; |
|
2071 |
} |
|
2072 |
||
9 | 2073 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2074 |
$term_data['description'] = $content_struct['description']; |
9 | 2075 |
} |
2076 |
||
2077 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2078 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2079 |
} |
2080 |
||
2081 |
$term = wp_insert_term( $term_data['name'], $taxonomy['name'], $term_data ); |
|
2082 |
||
2083 |
if ( is_wp_error( $term ) ) { |
|
0 | 2084 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2085 |
} |
2086 |
||
2087 |
if ( ! $term ) { |
|
16 | 2088 |
return new IXR_Error( 500, __( 'Sorry, the term could not be created.' ) ); |
9 | 2089 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
// Add term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
$this->set_term_custom_fields( $term['term_id'], $content_struct['custom_fields'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
} |
0 | 2095 |
|
2096 |
return strval( $term['term_id'] ); |
|
2097 |
} |
|
2098 |
||
2099 |
/** |
|
2100 |
* Edit a term. |
|
2101 |
* |
|
2102 |
* @since 3.4.0 |
|
2103 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
* @see wp_update_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
* @type array $content_struct Content struct for editing a term. The struct must contain the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
* term ''taxonomy'. Optional accepted values include 'name', 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
* 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2116 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2117 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2118 |
*/ |
5 | 2119 |
public function wp_editTerm( $args ) { |
9 | 2120 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2121 |
return $this->error; |
9 | 2122 |
} |
0 | 2123 |
|
2124 |
$this->escape( $args ); |
|
2125 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2126 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2127 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2128 |
$term_id = (int) $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
$content_struct = $args[4]; |
0 | 2130 |
|
16 | 2131 |
$user = $this->login( $username, $password ); |
2132 |
if ( ! $user ) { |
|
0 | 2133 |
return $this->error; |
9 | 2134 |
} |
0 | 2135 |
|
5 | 2136 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2137 |
do_action( 'xmlrpc_call', 'wp.editTerm' ); |
2138 |
||
9 | 2139 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2141 |
} |
0 | 2142 |
|
2143 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2144 |
||
2145 |
$taxonomy = (array) $taxonomy; |
|
2146 |
||
16 | 2147 |
// Hold the data of the term. |
0 | 2148 |
$term_data = array(); |
2149 |
||
9 | 2150 |
$term = get_term( $term_id, $content_struct['taxonomy'] ); |
2151 |
||
2152 |
if ( is_wp_error( $term ) ) { |
|
0 | 2153 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2154 |
} |
2155 |
||
2156 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2158 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
if ( ! current_user_can( 'edit_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2161 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this term.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2162 |
} |
0 | 2163 |
|
2164 |
if ( isset( $content_struct['name'] ) ) { |
|
2165 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
2166 |
||
9 | 2167 |
if ( empty( $term_data['name'] ) ) { |
0 | 2168 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2169 |
} |
0 | 2170 |
} |
2171 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
if ( ! empty( $content_struct['parent'] ) ) { |
9 | 2173 |
if ( ! $taxonomy['hierarchical'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
9 | 2175 |
} |
0 | 2176 |
|
2177 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2178 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2179 |
||
2180 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2181 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2182 |
} |
2183 |
||
2184 |
if ( ! $parent_term ) { |
|
0 | 2185 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2186 |
} |
0 | 2187 |
|
2188 |
$term_data['parent'] = $content_struct['parent']; |
|
2189 |
} |
|
2190 |
||
9 | 2191 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2192 |
$term_data['description'] = $content_struct['description']; |
9 | 2193 |
} |
2194 |
||
2195 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2196 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2197 |
} |
2198 |
||
2199 |
$term = wp_update_term( $term_id, $taxonomy['name'], $term_data ); |
|
2200 |
||
2201 |
if ( is_wp_error( $term ) ) { |
|
0 | 2202 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2203 |
} |
2204 |
||
2205 |
if ( ! $term ) { |
|
0 | 2206 |
return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
9 | 2207 |
} |
0 | 2208 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
// Update term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
$this->set_term_custom_fields( $term_id, $content_struct['custom_fields'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2213 |
|
0 | 2214 |
return true; |
2215 |
} |
|
2216 |
||
2217 |
/** |
|
2218 |
* Delete a term. |
|
2219 |
* |
|
2220 |
* @since 3.4.0 |
|
2221 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* @see wp_delete_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
* |
16 | 2224 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2226 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2227 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2229 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
* @type string $taxnomy_name Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
* @return bool|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2234 |
*/ |
5 | 2235 |
public function wp_deleteTerm( $args ) { |
9 | 2236 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2237 |
return $this->error; |
9 | 2238 |
} |
0 | 2239 |
|
2240 |
$this->escape( $args ); |
|
2241 |
||
9 | 2242 |
$username = $args[1]; |
2243 |
$password = $args[2]; |
|
2244 |
$taxonomy = $args[3]; |
|
2245 |
$term_id = (int) $args[4]; |
|
2246 |
||
16 | 2247 |
$user = $this->login( $username, $password ); |
2248 |
if ( ! $user ) { |
|
0 | 2249 |
return $this->error; |
9 | 2250 |
} |
0 | 2251 |
|
5 | 2252 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2253 |
do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
2254 |
||
9 | 2255 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2257 |
} |
0 | 2258 |
|
2259 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
9 | 2260 |
$term = get_term( $term_id, $taxonomy->name ); |
2261 |
||
2262 |
if ( is_wp_error( $term ) ) { |
|
0 | 2263 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2264 |
} |
2265 |
||
2266 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2268 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
if ( ! current_user_can( 'delete_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this term.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
} |
0 | 2273 |
|
2274 |
$result = wp_delete_term( $term_id, $taxonomy->name ); |
|
2275 |
||
9 | 2276 |
if ( is_wp_error( $result ) ) { |
0 | 2277 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2278 |
} |
2279 |
||
2280 |
if ( ! $result ) { |
|
0 | 2281 |
return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
9 | 2282 |
} |
0 | 2283 |
|
2284 |
return $result; |
|
2285 |
} |
|
2286 |
||
2287 |
/** |
|
2288 |
* Retrieve a term. |
|
2289 |
* |
|
2290 |
* @since 3.4.0 |
|
2291 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2292 |
* @see get_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2293 |
* |
16 | 2294 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2295 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2296 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2297 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2298 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2299 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2300 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2301 |
* @type string $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2302 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2303 |
* @return array|IXR_Error IXR_Error on failure, array on success, containing: |
0 | 2304 |
* - 'term_id' |
2305 |
* - 'name' |
|
2306 |
* - 'slug' |
|
2307 |
* - 'term_group' |
|
2308 |
* - 'term_taxonomy_id' |
|
2309 |
* - 'taxonomy' |
|
2310 |
* - 'description' |
|
2311 |
* - 'parent' |
|
2312 |
* - 'count' |
|
2313 |
*/ |
|
5 | 2314 |
public function wp_getTerm( $args ) { |
9 | 2315 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2316 |
return $this->error; |
9 | 2317 |
} |
0 | 2318 |
|
2319 |
$this->escape( $args ); |
|
2320 |
||
9 | 2321 |
$username = $args[1]; |
2322 |
$password = $args[2]; |
|
2323 |
$taxonomy = $args[3]; |
|
2324 |
$term_id = (int) $args[4]; |
|
2325 |
||
16 | 2326 |
$user = $this->login( $username, $password ); |
2327 |
if ( ! $user ) { |
|
0 | 2328 |
return $this->error; |
9 | 2329 |
} |
0 | 2330 |
|
5 | 2331 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2332 |
do_action( 'xmlrpc_call', 'wp.getTerm' ); |
2333 |
||
9 | 2334 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2335 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2336 |
} |
0 | 2337 |
|
2338 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2339 |
||
9 | 2340 |
$term = get_term( $term_id, $taxonomy->name, ARRAY_A ); |
2341 |
||
2342 |
if ( is_wp_error( $term ) ) { |
|
0 | 2343 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2344 |
} |
2345 |
||
2346 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2347 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2348 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2349 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2350 |
if ( ! current_user_can( 'assign_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign this term.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2352 |
} |
0 | 2353 |
|
2354 |
return $this->_prepare_term( $term ); |
|
2355 |
} |
|
2356 |
||
2357 |
/** |
|
2358 |
* Retrieve all terms for a taxonomy. |
|
2359 |
* |
|
2360 |
* @since 3.4.0 |
|
2361 |
* |
|
2362 |
* The optional $filter parameter modifies the query used to retrieve terms. |
|
2363 |
* Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
|
2364 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
* @see get_terms() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
* |
16 | 2367 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2369 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2370 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2371 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2372 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
* @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'number', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
* 'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2377 |
* @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
0 | 2378 |
*/ |
5 | 2379 |
public function wp_getTerms( $args ) { |
9 | 2380 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2381 |
return $this->error; |
9 | 2382 |
} |
0 | 2383 |
|
2384 |
$this->escape( $args ); |
|
2385 |
||
9 | 2386 |
$username = $args[1]; |
2387 |
$password = $args[2]; |
|
2388 |
$taxonomy = $args[3]; |
|
2389 |
$filter = isset( $args[4] ) ? $args[4] : array(); |
|
2390 |
||
16 | 2391 |
$user = $this->login( $username, $password ); |
2392 |
if ( ! $user ) { |
|
0 | 2393 |
return $this->error; |
9 | 2394 |
} |
0 | 2395 |
|
5 | 2396 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2397 |
do_action( 'xmlrpc_call', 'wp.getTerms' ); |
2398 |
||
9 | 2399 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2401 |
} |
0 | 2402 |
|
2403 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2404 |
||
9 | 2405 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2406 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2407 |
} |
0 | 2408 |
|
16 | 2409 |
$query = array( 'taxonomy' => $taxonomy->name ); |
0 | 2410 |
|
9 | 2411 |
if ( isset( $filter['number'] ) ) { |
0 | 2412 |
$query['number'] = absint( $filter['number'] ); |
9 | 2413 |
} |
2414 |
||
2415 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2416 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2417 |
} |
0 | 2418 |
|
2419 |
if ( isset( $filter['orderby'] ) ) { |
|
2420 |
$query['orderby'] = $filter['orderby']; |
|
2421 |
||
9 | 2422 |
if ( isset( $filter['order'] ) ) { |
0 | 2423 |
$query['order'] = $filter['order']; |
9 | 2424 |
} |
2425 |
} |
|
2426 |
||
2427 |
if ( isset( $filter['hide_empty'] ) ) { |
|
0 | 2428 |
$query['hide_empty'] = $filter['hide_empty']; |
9 | 2429 |
} else { |
0 | 2430 |
$query['get'] = 'all'; |
9 | 2431 |
} |
2432 |
||
2433 |
if ( isset( $filter['search'] ) ) { |
|
0 | 2434 |
$query['search'] = $filter['search']; |
9 | 2435 |
} |
0 | 2436 |
|
16 | 2437 |
$terms = get_terms( $query ); |
0 | 2438 |
|
9 | 2439 |
if ( is_wp_error( $terms ) ) { |
0 | 2440 |
return new IXR_Error( 500, $terms->get_error_message() ); |
9 | 2441 |
} |
0 | 2442 |
|
2443 |
$struct = array(); |
|
2444 |
||
2445 |
foreach ( $terms as $term ) { |
|
2446 |
$struct[] = $this->_prepare_term( $term ); |
|
2447 |
} |
|
2448 |
||
2449 |
return $struct; |
|
2450 |
} |
|
2451 |
||
2452 |
/** |
|
2453 |
* Retrieve a taxonomy. |
|
2454 |
* |
|
2455 |
* @since 3.4.0 |
|
2456 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2457 |
* @see get_taxonomy() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2458 |
* |
16 | 2459 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2461 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2464 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
* @type array $fields Optional. Array of taxonomy fields to limit to in the return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
* Accepts 'labels', 'cap', 'menu', and 'object_type'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2468 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2470 |
* @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
0 | 2471 |
*/ |
5 | 2472 |
public function wp_getTaxonomy( $args ) { |
9 | 2473 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2474 |
return $this->error; |
9 | 2475 |
} |
0 | 2476 |
|
2477 |
$this->escape( $args ); |
|
2478 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2479 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2480 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
$taxonomy = $args[3]; |
0 | 2482 |
|
5 | 2483 |
if ( isset( $args[4] ) ) { |
0 | 2484 |
$fields = $args[4]; |
5 | 2485 |
} else { |
2486 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2487 |
* Filters the taxonomy query fields used by the given XML-RPC method. |
5 | 2488 |
* |
2489 |
* @since 3.4.0 |
|
2490 |
* |
|
2491 |
* @param array $fields An array of taxonomy fields to retrieve. |
|
2492 |
* @param string $method The method name. |
|
2493 |
*/ |
|
0 | 2494 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
5 | 2495 |
} |
0 | 2496 |
|
16 | 2497 |
$user = $this->login( $username, $password ); |
2498 |
if ( ! $user ) { |
|
0 | 2499 |
return $this->error; |
9 | 2500 |
} |
0 | 2501 |
|
5 | 2502 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2503 |
do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2504 |
||
9 | 2505 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2506 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2507 |
} |
0 | 2508 |
|
2509 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2510 |
||
9 | 2511 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2513 |
} |
0 | 2514 |
|
2515 |
return $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2516 |
} |
|
2517 |
||
2518 |
/** |
|
2519 |
* Retrieve all taxonomies. |
|
2520 |
* |
|
2521 |
* @since 3.4.0 |
|
2522 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2523 |
* @see get_taxonomies() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2524 |
* |
16 | 2525 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2530 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2531 |
* @type array $filter Optional. An array of arguments for retrieving taxonomies. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2532 |
* @type array $fields Optional. The subset of taxonomy fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
* @return array|IXR_Error An associative array of taxonomy data with returned fields determined |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2535 |
* by `$fields`, or an IXR_Error instance on failure. |
0 | 2536 |
*/ |
5 | 2537 |
public function wp_getTaxonomies( $args ) { |
9 | 2538 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2539 |
return $this->error; |
9 | 2540 |
} |
0 | 2541 |
|
2542 |
$this->escape( $args ); |
|
2543 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2544 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2545 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2546 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 2547 |
|
5 | 2548 |
if ( isset( $args[4] ) ) { |
0 | 2549 |
$fields = $args[4]; |
5 | 2550 |
} else { |
2551 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2552 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
5 | 2553 |
} |
0 | 2554 |
|
16 | 2555 |
$user = $this->login( $username, $password ); |
2556 |
if ( ! $user ) { |
|
0 | 2557 |
return $this->error; |
9 | 2558 |
} |
0 | 2559 |
|
5 | 2560 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2561 |
do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
2562 |
||
2563 |
$taxonomies = get_taxonomies( $filter, 'objects' ); |
|
2564 |
||
16 | 2565 |
// Holds all the taxonomy data. |
0 | 2566 |
$struct = array(); |
2567 |
||
2568 |
foreach ( $taxonomies as $taxonomy ) { |
|
16 | 2569 |
// Capability check for post types. |
9 | 2570 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
0 | 2571 |
continue; |
9 | 2572 |
} |
0 | 2573 |
|
2574 |
$struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2575 |
} |
|
2576 |
||
2577 |
return $struct; |
|
2578 |
} |
|
2579 |
||
2580 |
/** |
|
2581 |
* Retrieve a user. |
|
2582 |
* |
|
2583 |
* The optional $fields parameter specifies what fields will be included |
|
2584 |
* in the response array. This should be a list of field names. 'user_id' will |
|
2585 |
* always be included in the response regardless of the value of $fields. |
|
2586 |
* |
|
2587 |
* Instead of, or in addition to, individual field names, conceptual group |
|
2588 |
* names can be used to specify multiple fields. The available conceptual |
|
2589 |
* groups are 'basic' and 'all'. |
|
2590 |
* |
|
2591 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2592 |
* |
16 | 2593 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2594 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2597 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
* @type int $user_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2601 |
* } |
5 | 2602 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 2603 |
* - 'user_id' |
2604 |
* - 'username' |
|
2605 |
* - 'first_name' |
|
2606 |
* - 'last_name' |
|
2607 |
* - 'registered' |
|
2608 |
* - 'bio' |
|
2609 |
* - 'email' |
|
2610 |
* - 'nickname' |
|
2611 |
* - 'nicename' |
|
2612 |
* - 'url' |
|
2613 |
* - 'display_name' |
|
2614 |
* - 'roles' |
|
2615 |
*/ |
|
5 | 2616 |
public function wp_getUser( $args ) { |
9 | 2617 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2618 |
return $this->error; |
9 | 2619 |
} |
0 | 2620 |
|
2621 |
$this->escape( $args ); |
|
2622 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2623 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2624 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
$user_id = (int) $args[3]; |
0 | 2626 |
|
5 | 2627 |
if ( isset( $args[4] ) ) { |
0 | 2628 |
$fields = $args[4]; |
5 | 2629 |
} else { |
2630 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2631 |
* Filters the default user query fields used by the given XML-RPC method. |
5 | 2632 |
* |
2633 |
* @since 3.5.0 |
|
2634 |
* |
|
2635 |
* @param array $fields User query fields for given method. Default 'all'. |
|
2636 |
* @param string $method The method name. |
|
2637 |
*/ |
|
0 | 2638 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
5 | 2639 |
} |
0 | 2640 |
|
16 | 2641 |
$user = $this->login( $username, $password ); |
2642 |
if ( ! $user ) { |
|
0 | 2643 |
return $this->error; |
9 | 2644 |
} |
0 | 2645 |
|
5 | 2646 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2647 |
do_action( 'xmlrpc_call', 'wp.getUser' ); |
2648 |
||
9 | 2649 |
if ( ! current_user_can( 'edit_user', $user_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
9 | 2651 |
} |
0 | 2652 |
|
2653 |
$user_data = get_userdata( $user_id ); |
|
2654 |
||
9 | 2655 |
if ( ! $user_data ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2656 |
return new IXR_Error( 404, __( 'Invalid user ID.' ) ); |
9 | 2657 |
} |
0 | 2658 |
|
2659 |
return $this->_prepare_user( $user_data, $fields ); |
|
2660 |
} |
|
2661 |
||
2662 |
/** |
|
2663 |
* Retrieve users. |
|
2664 |
* |
|
2665 |
* The optional $filter parameter modifies the query used to retrieve users. |
|
2666 |
* Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', |
|
2667 |
* 'who', 'orderby', and 'order'. |
|
2668 |
* |
|
2669 |
* The optional $fields parameter specifies what fields will be included |
|
2670 |
* in the response array. |
|
2671 |
* |
|
2672 |
* @uses get_users() |
|
2673 |
* @see wp_getUser() for more on $fields and return values |
|
2674 |
* |
|
16 | 2675 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2678 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2680 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2681 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2683 |
* } |
5 | 2684 |
* @return array|IXR_Error users data |
0 | 2685 |
*/ |
5 | 2686 |
public function wp_getUsers( $args ) { |
9 | 2687 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2688 |
return $this->error; |
9 | 2689 |
} |
0 | 2690 |
|
2691 |
$this->escape( $args ); |
|
2692 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2693 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2694 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 2696 |
|
5 | 2697 |
if ( isset( $args[4] ) ) { |
0 | 2698 |
$fields = $args[4]; |
5 | 2699 |
} else { |
2700 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2701 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
5 | 2702 |
} |
0 | 2703 |
|
16 | 2704 |
$user = $this->login( $username, $password ); |
2705 |
if ( ! $user ) { |
|
0 | 2706 |
return $this->error; |
9 | 2707 |
} |
0 | 2708 |
|
5 | 2709 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2710 |
do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2711 |
||
9 | 2712 |
if ( ! current_user_can( 'list_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
9 | 2714 |
} |
0 | 2715 |
|
2716 |
$query = array( 'fields' => 'all_with_meta' ); |
|
2717 |
||
2718 |
$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50; |
|
2719 |
$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0; |
|
2720 |
||
2721 |
if ( isset( $filter['orderby'] ) ) { |
|
2722 |
$query['orderby'] = $filter['orderby']; |
|
2723 |
||
9 | 2724 |
if ( isset( $filter['order'] ) ) { |
0 | 2725 |
$query['order'] = $filter['order']; |
9 | 2726 |
} |
0 | 2727 |
} |
2728 |
||
2729 |
if ( isset( $filter['role'] ) ) { |
|
9 | 2730 |
if ( get_role( $filter['role'] ) === null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2731 |
return new IXR_Error( 403, __( 'Invalid role.' ) ); |
9 | 2732 |
} |
0 | 2733 |
|
2734 |
$query['role'] = $filter['role']; |
|
2735 |
} |
|
2736 |
||
2737 |
if ( isset( $filter['who'] ) ) { |
|
2738 |
$query['who'] = $filter['who']; |
|
2739 |
} |
|
2740 |
||
2741 |
$users = get_users( $query ); |
|
2742 |
||
2743 |
$_users = array(); |
|
2744 |
foreach ( $users as $user_data ) { |
|
9 | 2745 |
if ( current_user_can( 'edit_user', $user_data->ID ) ) { |
0 | 2746 |
$_users[] = $this->_prepare_user( $user_data, $fields ); |
9 | 2747 |
} |
0 | 2748 |
} |
2749 |
return $_users; |
|
2750 |
} |
|
2751 |
||
2752 |
/** |
|
2753 |
* Retrieve information about the requesting user. |
|
2754 |
* |
|
2755 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2756 |
* |
16 | 2757 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2758 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2759 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2760 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2761 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2762 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2763 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2764 |
* } |
5 | 2765 |
* @return array|IXR_Error (@see wp_getUser) |
0 | 2766 |
*/ |
5 | 2767 |
public function wp_getProfile( $args ) { |
9 | 2768 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2769 |
return $this->error; |
9 | 2770 |
} |
0 | 2771 |
|
2772 |
$this->escape( $args ); |
|
2773 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2775 |
$password = $args[2]; |
0 | 2776 |
|
5 | 2777 |
if ( isset( $args[3] ) ) { |
0 | 2778 |
$fields = $args[3]; |
5 | 2779 |
} else { |
2780 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2781 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
5 | 2782 |
} |
0 | 2783 |
|
16 | 2784 |
$user = $this->login( $username, $password ); |
2785 |
if ( ! $user ) { |
|
0 | 2786 |
return $this->error; |
9 | 2787 |
} |
0 | 2788 |
|
5 | 2789 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2790 |
do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2791 |
||
9 | 2792 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2793 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2794 |
} |
0 | 2795 |
|
2796 |
$user_data = get_userdata( $user->ID ); |
|
2797 |
||
2798 |
return $this->_prepare_user( $user_data, $fields ); |
|
2799 |
} |
|
2800 |
||
2801 |
/** |
|
2802 |
* Edit user's profile. |
|
2803 |
* |
|
2804 |
* @uses wp_update_user() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
* |
16 | 2806 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2809 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
* @type array $content_struct It can optionally contain: |
0 | 2813 |
* - 'first_name' |
2814 |
* - 'last_name' |
|
2815 |
* - 'website' |
|
2816 |
* - 'display_name' |
|
2817 |
* - 'nickname' |
|
2818 |
* - 'nicename' |
|
2819 |
* - 'bio' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
* @return true|IXR_Error True, on success. |
0 | 2822 |
*/ |
5 | 2823 |
public function wp_editProfile( $args ) { |
9 | 2824 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2825 |
return $this->error; |
9 | 2826 |
} |
0 | 2827 |
|
2828 |
$this->escape( $args ); |
|
2829 |
||
2830 |
$username = $args[1]; |
|
2831 |
$password = $args[2]; |
|
2832 |
$content_struct = $args[3]; |
|
2833 |
||
16 | 2834 |
$user = $this->login( $username, $password ); |
2835 |
if ( ! $user ) { |
|
0 | 2836 |
return $this->error; |
9 | 2837 |
} |
0 | 2838 |
|
5 | 2839 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2840 |
do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2841 |
||
9 | 2842 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2844 |
} |
0 | 2845 |
|
16 | 2846 |
// Holds data of the user. |
9 | 2847 |
$user_data = array(); |
0 | 2848 |
$user_data['ID'] = $user->ID; |
2849 |
||
16 | 2850 |
// Only set the user details if they were given. |
9 | 2851 |
if ( isset( $content_struct['first_name'] ) ) { |
0 | 2852 |
$user_data['first_name'] = $content_struct['first_name']; |
9 | 2853 |
} |
2854 |
||
2855 |
if ( isset( $content_struct['last_name'] ) ) { |
|
0 | 2856 |
$user_data['last_name'] = $content_struct['last_name']; |
9 | 2857 |
} |
2858 |
||
2859 |
if ( isset( $content_struct['url'] ) ) { |
|
0 | 2860 |
$user_data['user_url'] = $content_struct['url']; |
9 | 2861 |
} |
2862 |
||
2863 |
if ( isset( $content_struct['display_name'] ) ) { |
|
0 | 2864 |
$user_data['display_name'] = $content_struct['display_name']; |
9 | 2865 |
} |
2866 |
||
2867 |
if ( isset( $content_struct['nickname'] ) ) { |
|
0 | 2868 |
$user_data['nickname'] = $content_struct['nickname']; |
9 | 2869 |
} |
2870 |
||
2871 |
if ( isset( $content_struct['nicename'] ) ) { |
|
0 | 2872 |
$user_data['user_nicename'] = $content_struct['nicename']; |
9 | 2873 |
} |
2874 |
||
2875 |
if ( isset( $content_struct['bio'] ) ) { |
|
0 | 2876 |
$user_data['description'] = $content_struct['bio']; |
9 | 2877 |
} |
0 | 2878 |
|
2879 |
$result = wp_update_user( $user_data ); |
|
2880 |
||
9 | 2881 |
if ( is_wp_error( $result ) ) { |
0 | 2882 |
return new IXR_Error( 500, $result->get_error_message() ); |
9 | 2883 |
} |
2884 |
||
2885 |
if ( ! $result ) { |
|
16 | 2886 |
return new IXR_Error( 500, __( 'Sorry, the user could not be updated.' ) ); |
9 | 2887 |
} |
0 | 2888 |
|
2889 |
return true; |
|
2890 |
} |
|
2891 |
||
2892 |
/** |
|
2893 |
* Retrieve page. |
|
2894 |
* |
|
2895 |
* @since 2.2.0 |
|
2896 |
* |
|
16 | 2897 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2898 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2899 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2900 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2901 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2903 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2904 |
* } |
5 | 2905 |
* @return array|IXR_Error |
0 | 2906 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2907 |
public function wp_getPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2910 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
$password = $args[3]; |
0 | 2913 |
|
16 | 2914 |
$user = $this->login( $username, $password ); |
2915 |
if ( ! $user ) { |
|
0 | 2916 |
return $this->error; |
2917 |
} |
|
2918 |
||
9 | 2919 |
$page = get_post( $page_id ); |
2920 |
if ( ! $page ) { |
|
0 | 2921 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 2922 |
} |
2923 |
||
2924 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 2926 |
} |
0 | 2927 |
|
5 | 2928 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2929 |
do_action( 'xmlrpc_call', 'wp.getPage' ); |
|
0 | 2930 |
|
2931 |
// If we found the page then format the data. |
|
16 | 2932 |
if ( $page->ID && ( 'page' === $page->post_type ) ) { |
0 | 2933 |
return $this->_prepare_page( $page ); |
9 | 2934 |
} else { |
16 | 2935 |
// If the page doesn't exist, indicate that. |
5 | 2936 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2937 |
} |
2938 |
} |
|
2939 |
||
2940 |
/** |
|
2941 |
* Retrieve Pages. |
|
2942 |
* |
|
2943 |
* @since 2.2.0 |
|
2944 |
* |
|
16 | 2945 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2946 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2949 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2950 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2951 |
* @type int $num_pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2952 |
* } |
5 | 2953 |
* @return array|IXR_Error |
0 | 2954 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2955 |
public function wp_getPages( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2956 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2959 |
$password = $args[2]; |
9 | 2960 |
$num_pages = isset( $args[3] ) ? (int) $args[3] : 10; |
2961 |
||
16 | 2962 |
$user = $this->login( $username, $password ); |
2963 |
if ( ! $user ) { |
|
0 | 2964 |
return $this->error; |
9 | 2965 |
} |
2966 |
||
2967 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 2969 |
} |
0 | 2970 |
|
5 | 2971 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2972 |
do_action( 'xmlrpc_call', 'wp.getPages' ); |
|
0 | 2973 |
|
9 | 2974 |
$pages = get_posts( |
2975 |
array( |
|
2976 |
'post_type' => 'page', |
|
2977 |
'post_status' => 'any', |
|
2978 |
'numberposts' => $num_pages, |
|
2979 |
) |
|
2980 |
); |
|
2981 |
$num_pages = count( $pages ); |
|
0 | 2982 |
|
2983 |
// If we have pages, put together their info. |
|
2984 |
if ( $num_pages >= 1 ) { |
|
2985 |
$pages_struct = array(); |
|
2986 |
||
9 | 2987 |
foreach ( $pages as $page ) { |
2988 |
if ( current_user_can( 'edit_page', $page->ID ) ) { |
|
0 | 2989 |
$pages_struct[] = $this->_prepare_page( $page ); |
9 | 2990 |
} |
0 | 2991 |
} |
2992 |
||
5 | 2993 |
return $pages_struct; |
0 | 2994 |
} |
5 | 2995 |
|
2996 |
return array(); |
|
0 | 2997 |
} |
2998 |
||
2999 |
/** |
|
3000 |
* Create new page. |
|
3001 |
* |
|
3002 |
* @since 2.2.0 |
|
3003 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
* @see wp_xmlrpc_server::mw_newPost() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
* |
16 | 3006 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3012 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3013 |
* } |
5 | 3014 |
* @return int|IXR_Error |
0 | 3015 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
public function wp_newPage( $args ) { |
16 | 3017 |
// Items not escaped here will be escaped in wp_newPost(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
$password = $this->escape( $args[2] ); |
0 | 3020 |
|
16 | 3021 |
$user = $this->login( $username, $password ); |
3022 |
if ( ! $user ) { |
|
0 | 3023 |
return $this->error; |
9 | 3024 |
} |
0 | 3025 |
|
5 | 3026 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3027 |
do_action( 'xmlrpc_call', 'wp.newPage' ); |
|
0 | 3028 |
|
3029 |
// Mark this as content for a page. |
|
9 | 3030 |
$args[3]['post_type'] = 'page'; |
0 | 3031 |
|
16 | 3032 |
// Let mw_newPost() do all of the heavy lifting. |
5 | 3033 |
return $this->mw_newPost( $args ); |
0 | 3034 |
} |
3035 |
||
3036 |
/** |
|
3037 |
* Delete page. |
|
3038 |
* |
|
3039 |
* @since 2.2.0 |
|
3040 |
* |
|
16 | 3041 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3042 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3043 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3045 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3046 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3047 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3049 |
* @return true|IXR_Error True, if success. |
0 | 3050 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3051 |
public function wp_deletePage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3056 |
$page_id = (int) $args[3]; |
0 | 3057 |
|
16 | 3058 |
$user = $this->login( $username, $password ); |
3059 |
if ( ! $user ) { |
|
0 | 3060 |
return $this->error; |
9 | 3061 |
} |
0 | 3062 |
|
5 | 3063 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3064 |
do_action( 'xmlrpc_call', 'wp.deletePage' ); |
|
0 | 3065 |
|
16 | 3066 |
// Get the current page based on the 'page_id' and |
0 | 3067 |
// make sure it is a page and not a post. |
9 | 3068 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3069 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3070 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3071 |
} |
0 | 3072 |
|
3073 |
// Make sure the user can delete pages. |
|
9 | 3074 |
if ( ! current_user_can( 'delete_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) ); |
9 | 3076 |
} |
0 | 3077 |
|
3078 |
// Attempt to delete the page. |
|
9 | 3079 |
$result = wp_delete_post( $page_id ); |
3080 |
if ( ! $result ) { |
|
5 | 3081 |
return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
9 | 3082 |
} |
5 | 3083 |
|
3084 |
/** |
|
3085 |
* Fires after a page has been successfully deleted via XML-RPC. |
|
3086 |
* |
|
3087 |
* @since 3.4.0 |
|
3088 |
* |
|
3089 |
* @param int $page_id ID of the deleted page. |
|
3090 |
* @param array $args An array of arguments to delete the page. |
|
3091 |
*/ |
|
16 | 3092 |
do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3093 |
|
5 | 3094 |
return true; |
0 | 3095 |
} |
3096 |
||
3097 |
/** |
|
3098 |
* Edit page. |
|
3099 |
* |
|
3100 |
* @since 2.2.0 |
|
3101 |
* |
|
16 | 3102 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3106 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
* } |
5 | 3112 |
* @return array|IXR_Error |
0 | 3113 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
public function wp_editPage( $args ) { |
16 | 3115 |
// Items will be escaped in mw_editPost(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
$publish = $args[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
$escaped_username = $this->escape( $username ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
$escaped_password = $this->escape( $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
|
16 | 3125 |
$user = $this->login( $escaped_username, $escaped_password ); |
3126 |
if ( ! $user ) { |
|
0 | 3127 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
} |
0 | 3129 |
|
5 | 3130 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3131 |
do_action( 'xmlrpc_call', 'wp.editPage' ); |
|
0 | 3132 |
|
3133 |
// Get the page data and make sure it is a page. |
|
9 | 3134 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3135 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3136 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3137 |
} |
0 | 3138 |
|
3139 |
// Make sure the user is allowed to edit pages. |
|
9 | 3140 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 3142 |
} |
0 | 3143 |
|
3144 |
// Mark this as content for a page. |
|
3145 |
$content['post_type'] = 'page'; |
|
3146 |
||
16 | 3147 |
// Arrange args in the way mw_editPost() understands. |
0 | 3148 |
$args = array( |
3149 |
$page_id, |
|
3150 |
$username, |
|
3151 |
$password, |
|
3152 |
$content, |
|
9 | 3153 |
$publish, |
0 | 3154 |
); |
3155 |
||
16 | 3156 |
// Let mw_editPost() do all of the heavy lifting. |
5 | 3157 |
return $this->mw_editPost( $args ); |
0 | 3158 |
} |
3159 |
||
3160 |
/** |
|
3161 |
* Retrieve page list. |
|
3162 |
* |
|
3163 |
* @since 2.2.0 |
|
3164 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
* |
16 | 3167 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3170 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3171 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3172 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3173 |
* } |
5 | 3174 |
* @return array|IXR_Error |
0 | 3175 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3176 |
public function wp_getPageList( $args ) { |
0 | 3177 |
global $wpdb; |
3178 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3179 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3182 |
$password = $args[2]; |
0 | 3183 |
|
16 | 3184 |
$user = $this->login( $username, $password ); |
3185 |
if ( ! $user ) { |
|
0 | 3186 |
return $this->error; |
9 | 3187 |
} |
3188 |
||
3189 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3191 |
} |
0 | 3192 |
|
5 | 3193 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3194 |
do_action( 'xmlrpc_call', 'wp.getPageList' ); |
|
0 | 3195 |
|
16 | 3196 |
// Get list of page IDs and titles. |
9 | 3197 |
$page_list = $wpdb->get_results( |
3198 |
" |
|
0 | 3199 |
SELECT ID page_id, |
3200 |
post_title page_title, |
|
3201 |
post_parent page_parent_id, |
|
3202 |
post_date_gmt, |
|
3203 |
post_date, |
|
3204 |
post_status |
|
3205 |
FROM {$wpdb->posts} |
|
3206 |
WHERE post_type = 'page' |
|
3207 |
ORDER BY ID |
|
9 | 3208 |
" |
3209 |
); |
|
0 | 3210 |
|
3211 |
// The date needs to be formatted properly. |
|
9 | 3212 |
$num_pages = count( $page_list ); |
0 | 3213 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
9 | 3214 |
$page_list[ $i ]->dateCreated = $this->_convert_date( $page_list[ $i ]->post_date ); |
3215 |
$page_list[ $i ]->date_created_gmt = $this->_convert_date_gmt( $page_list[ $i ]->post_date_gmt, $page_list[ $i ]->post_date ); |
|
3216 |
||
3217 |
unset( $page_list[ $i ]->post_date_gmt ); |
|
3218 |
unset( $page_list[ $i ]->post_date ); |
|
3219 |
unset( $page_list[ $i ]->post_status ); |
|
0 | 3220 |
} |
3221 |
||
5 | 3222 |
return $page_list; |
0 | 3223 |
} |
3224 |
||
3225 |
/** |
|
3226 |
* Retrieve authors list. |
|
3227 |
* |
|
3228 |
* @since 2.2.0 |
|
3229 |
* |
|
16 | 3230 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3231 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3232 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3233 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3234 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3235 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3236 |
* } |
5 | 3237 |
* @return array|IXR_Error |
0 | 3238 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
public function wp_getAuthors( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
$password = $args[2]; |
0 | 3244 |
|
16 | 3245 |
$user = $this->login( $username, $password ); |
3246 |
if ( ! $user ) { |
|
0 | 3247 |
return $this->error; |
9 | 3248 |
} |
3249 |
||
3250 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 3252 |
} |
5 | 3253 |
|
3254 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3255 |
do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
|
0 | 3256 |
|
3257 |
$authors = array(); |
|
9 | 3258 |
foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
0 | 3259 |
$authors[] = array( |
9 | 3260 |
'user_id' => $user->ID, |
3261 |
'user_login' => $user->user_login, |
|
3262 |
'display_name' => $user->display_name, |
|
0 | 3263 |
); |
3264 |
} |
|
3265 |
||
3266 |
return $authors; |
|
3267 |
} |
|
3268 |
||
3269 |
/** |
|
3270 |
* Get list of all tags |
|
3271 |
* |
|
3272 |
* @since 2.7.0 |
|
3273 |
* |
|
16 | 3274 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
* } |
5 | 3281 |
* @return array|IXR_Error |
0 | 3282 |
*/ |
5 | 3283 |
public function wp_getTags( $args ) { |
0 | 3284 |
$this->escape( $args ); |
3285 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
$password = $args[2]; |
0 | 3288 |
|
16 | 3289 |
$user = $this->login( $username, $password ); |
3290 |
if ( ! $user ) { |
|
0 | 3291 |
return $this->error; |
9 | 3292 |
} |
3293 |
||
3294 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 3295 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
9 | 3296 |
} |
0 | 3297 |
|
5 | 3298 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 3299 |
do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
3300 |
||
3301 |
$tags = array(); |
|
3302 |
||
16 | 3303 |
$all_tags = get_tags(); |
3304 |
if ( $all_tags ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
foreach ( (array) $all_tags as $tag ) { |
9 | 3306 |
$struct = array(); |
3307 |
$struct['tag_id'] = $tag->term_id; |
|
3308 |
$struct['name'] = $tag->name; |
|
3309 |
$struct['count'] = $tag->count; |
|
3310 |
$struct['slug'] = $tag->slug; |
|
3311 |
$struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
|
3312 |
$struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) ); |
|
0 | 3313 |
|
3314 |
$tags[] = $struct; |
|
3315 |
} |
|
3316 |
} |
|
3317 |
||
3318 |
return $tags; |
|
3319 |
} |
|
3320 |
||
3321 |
/** |
|
3322 |
* Create new category. |
|
3323 |
* |
|
3324 |
* @since 2.2.0 |
|
3325 |
* |
|
16 | 3326 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
* } |
5 | 3334 |
* @return int|IXR_Error Category ID. |
0 | 3335 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3336 |
public function wp_newCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3337 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3340 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3341 |
$category = $args[3]; |
0 | 3342 |
|
16 | 3343 |
$user = $this->login( $username, $password ); |
3344 |
if ( ! $user ) { |
|
0 | 3345 |
return $this->error; |
9 | 3346 |
} |
0 | 3347 |
|
5 | 3348 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3349 |
do_action( 'xmlrpc_call', 'wp.newCategory' ); |
|
0 | 3350 |
|
3351 |
// Make sure the user is allowed to add a category. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
if ( ! current_user_can( 'manage_categories' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3353 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
} |
0 | 3355 |
|
16 | 3356 |
// If no slug was provided, make it empty |
3357 |
// so that WordPress will generate one. |
|
9 | 3358 |
if ( empty( $category['slug'] ) ) { |
0 | 3359 |
$category['slug'] = ''; |
9 | 3360 |
} |
0 | 3361 |
|
16 | 3362 |
// If no parent_id was provided, make it empty |
3363 |
// so that it will be a top-level page (no parent). |
|
9 | 3364 |
if ( ! isset( $category['parent_id'] ) ) { |
0 | 3365 |
$category['parent_id'] = ''; |
9 | 3366 |
} |
0 | 3367 |
|
16 | 3368 |
// If no description was provided, make it empty. |
9 | 3369 |
if ( empty( $category['description'] ) ) { |
3370 |
$category['description'] = ''; |
|
3371 |
} |
|
0 | 3372 |
|
3373 |
$new_category = array( |
|
9 | 3374 |
'cat_name' => $category['name'], |
3375 |
'category_nicename' => $category['slug'], |
|
3376 |
'category_parent' => $category['parent_id'], |
|
3377 |
'category_description' => $category['description'], |
|
0 | 3378 |
); |
3379 |
||
9 | 3380 |
$cat_id = wp_insert_category( $new_category, true ); |
0 | 3381 |
if ( is_wp_error( $cat_id ) ) { |
16 | 3382 |
if ( 'term_exists' === $cat_id->get_error_code() ) { |
0 | 3383 |
return (int) $cat_id->get_error_data(); |
9 | 3384 |
} else { |
16 | 3385 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
9 | 3386 |
} |
0 | 3387 |
} elseif ( ! $cat_id ) { |
16 | 3388 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
0 | 3389 |
} |
3390 |
||
5 | 3391 |
/** |
3392 |
* Fires after a new category has been successfully created via XML-RPC. |
|
3393 |
* |
|
3394 |
* @since 3.4.0 |
|
3395 |
* |
|
3396 |
* @param int $cat_id ID of the new category. |
|
3397 |
* @param array $args An array of new category arguments. |
|
3398 |
*/ |
|
16 | 3399 |
do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3400 |
|
3401 |
return $cat_id; |
|
3402 |
} |
|
3403 |
||
3404 |
/** |
|
3405 |
* Remove category. |
|
3406 |
* |
|
3407 |
* @since 2.5.0 |
|
3408 |
* |
|
16 | 3409 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
* @type int $category_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
* @return bool|IXR_Error See wp_delete_term() for return info. |
0 | 3418 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
public function wp_deleteCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
$category_id = (int) $args[3]; |
0 | 3425 |
|
16 | 3426 |
$user = $this->login( $username, $password ); |
3427 |
if ( ! $user ) { |
|
0 | 3428 |
return $this->error; |
9 | 3429 |
} |
0 | 3430 |
|
5 | 3431 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3432 |
do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
|
0 | 3433 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
if ( ! current_user_can( 'delete_term', $category_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this category.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3436 |
} |
0 | 3437 |
|
3438 |
$status = wp_delete_term( $category_id, 'category' ); |
|
3439 |
||
5 | 3440 |
if ( true == $status ) { |
3441 |
/** |
|
3442 |
* Fires after a category has been successfully deleted via XML-RPC. |
|
3443 |
* |
|
3444 |
* @since 3.4.0 |
|
3445 |
* |
|
3446 |
* @param int $category_id ID of the deleted category. |
|
3447 |
* @param array $args An array of arguments to delete the category. |
|
3448 |
*/ |
|
16 | 3449 |
do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3450 |
} |
0 | 3451 |
|
3452 |
return $status; |
|
3453 |
} |
|
3454 |
||
3455 |
/** |
|
3456 |
* Retrieve category list. |
|
3457 |
* |
|
3458 |
* @since 2.2.0 |
|
3459 |
* |
|
16 | 3460 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3461 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3463 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3464 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3465 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
* @type int $max_results |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
* } |
5 | 3469 |
* @return array|IXR_Error |
0 | 3470 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
public function wp_suggestCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3472 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3474 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3475 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3476 |
$category = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3477 |
$max_results = (int) $args[4]; |
0 | 3478 |
|
16 | 3479 |
$user = $this->login( $username, $password ); |
3480 |
if ( ! $user ) { |
|
0 | 3481 |
return $this->error; |
9 | 3482 |
} |
3483 |
||
3484 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
5 | 3485 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 3486 |
} |
5 | 3487 |
|
3488 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3489 |
do_action( 'xmlrpc_call', 'wp.suggestCategories' ); |
|
0 | 3490 |
|
3491 |
$category_suggestions = array(); |
|
9 | 3492 |
$args = array( |
3493 |
'get' => 'all', |
|
3494 |
'number' => $max_results, |
|
3495 |
'name__like' => $category, |
|
3496 |
); |
|
3497 |
foreach ( (array) get_categories( $args ) as $cat ) { |
|
0 | 3498 |
$category_suggestions[] = array( |
9 | 3499 |
'category_id' => $cat->term_id, |
3500 |
'category_name' => $cat->name, |
|
0 | 3501 |
); |
3502 |
} |
|
3503 |
||
5 | 3504 |
return $category_suggestions; |
0 | 3505 |
} |
3506 |
||
3507 |
/** |
|
3508 |
* Retrieve comment. |
|
3509 |
* |
|
3510 |
* @since 2.7.0 |
|
3511 |
* |
|
16 | 3512 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3516 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* @type int $comment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* } |
5 | 3520 |
* @return array|IXR_Error |
0 | 3521 |
*/ |
9 | 3522 |
public function wp_getComment( $args ) { |
3523 |
$this->escape( $args ); |
|
3524 |
||
3525 |
$username = $args[1]; |
|
3526 |
$password = $args[2]; |
|
3527 |
$comment_id = (int) $args[3]; |
|
0 | 3528 |
|
16 | 3529 |
$user = $this->login( $username, $password ); |
3530 |
if ( ! $user ) { |
|
0 | 3531 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3532 |
} |
0 | 3533 |
|
5 | 3534 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3535 |
do_action( 'xmlrpc_call', 'wp.getComment' ); |
|
0 | 3536 |
|
16 | 3537 |
$comment = get_comment( $comment_id ); |
3538 |
if ( ! $comment ) { |
|
0 | 3539 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
} |
0 | 3545 |
|
3546 |
return $this->_prepare_comment( $comment ); |
|
3547 |
} |
|
3548 |
||
3549 |
/** |
|
3550 |
* Retrieve comments. |
|
3551 |
* |
|
5 | 3552 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 3553 |
* array as last argument. |
3554 |
* |
|
3555 |
* Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
|
3556 |
* |
|
3557 |
* The defaults are as follows: |
|
3558 |
* - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
|
3559 |
* - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
|
3560 |
* - 'number' - Default is 10. Total number of media items to retrieve. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 3562 |
* |
3563 |
* @since 2.7.0 |
|
3564 |
* |
|
16 | 3565 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3567 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
* @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents |
0 | 3574 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
public function wp_getComments( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
$password = $args[2]; |
9 | 3580 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
|
16 | 3582 |
$user = $this->login( $username, $password ); |
3583 |
if ( ! $user ) { |
|
0 | 3584 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
} |
0 | 3586 |
|
5 | 3587 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3588 |
do_action( 'xmlrpc_call', 'wp.getComments' ); |
|
0 | 3589 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
if ( isset( $struct['status'] ) ) { |
0 | 3591 |
$status = $struct['status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
} else { |
0 | 3593 |
$status = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
} |
0 | 3599 |
|
3600 |
$post_id = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3601 |
if ( isset( $struct['post_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
$post_id = absint( $struct['post_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3603 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
$post_type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
if ( isset( $struct['post_type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3607 |
$post_type_object = get_post_type_object( $struct['post_type'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
if ( ! $post_type_object || ! post_type_supports( $post_type_object->name, 'comments' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
$post_type = $struct['post_type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
} |
0 | 3613 |
|
3614 |
$offset = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
if ( isset( $struct['offset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3616 |
$offset = absint( $struct['offset'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3617 |
} |
0 | 3618 |
|
3619 |
$number = 10; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
if ( isset( $struct['number'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
$number = absint( $struct['number'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3622 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
|
9 | 3624 |
$comments = get_comments( |
3625 |
array( |
|
3626 |
'status' => $status, |
|
3627 |
'post_id' => $post_id, |
|
3628 |
'offset' => $offset, |
|
3629 |
'number' => $number, |
|
3630 |
'post_type' => $post_type, |
|
3631 |
) |
|
3632 |
); |
|
0 | 3633 |
|
3634 |
$comments_struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
$comments_struct[] = $this->_prepare_comment( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
} |
0 | 3639 |
} |
3640 |
||
3641 |
return $comments_struct; |
|
3642 |
} |
|
3643 |
||
3644 |
/** |
|
3645 |
* Delete a comment. |
|
3646 |
* |
|
16 | 3647 |
* By default, the comment will be moved to the Trash instead of deleted. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
* See wp_delete_comment() for more information on this behavior. |
0 | 3649 |
* |
3650 |
* @since 2.7.0 |
|
3651 |
* |
|
16 | 3652 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3658 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
* @return bool|IXR_Error See wp_delete_comment(). |
0 | 3661 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
public function wp_deleteComment( $args ) { |
9 | 3663 |
$this->escape( $args ); |
3664 |
||
3665 |
$username = $args[1]; |
|
3666 |
$password = $args[2]; |
|
3667 |
$comment_ID = (int) $args[3]; |
|
0 | 3668 |
|
16 | 3669 |
$user = $this->login( $username, $password ); |
3670 |
if ( ! $user ) { |
|
0 | 3671 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3675 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to delete this comment.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
} |
0 | 3681 |
|
5 | 3682 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3683 |
do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
|
0 | 3684 |
|
3685 |
$status = wp_delete_comment( $comment_ID ); |
|
3686 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
if ( $status ) { |
5 | 3688 |
/** |
3689 |
* Fires after a comment has been successfully deleted via XML-RPC. |
|
3690 |
* |
|
3691 |
* @since 3.4.0 |
|
3692 |
* |
|
3693 |
* @param int $comment_ID ID of the deleted comment. |
|
3694 |
* @param array $args An array of arguments to delete the comment. |
|
3695 |
*/ |
|
16 | 3696 |
do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3697 |
} |
0 | 3698 |
|
3699 |
return $status; |
|
3700 |
} |
|
3701 |
||
3702 |
/** |
|
3703 |
* Edit comment. |
|
3704 |
* |
|
5 | 3705 |
* Besides the common blog_id (unused), username, and password arguments, it takes a |
0 | 3706 |
* comment_id integer and a content_struct array as last argument. |
3707 |
* |
|
3708 |
* The allowed keys in the content_struct array are: |
|
3709 |
* - 'author' |
|
3710 |
* - 'author_url' |
|
3711 |
* - 'author_email' |
|
3712 |
* - 'content' |
|
3713 |
* - 'date_created_gmt' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
* - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details |
0 | 3715 |
* |
3716 |
* @since 2.7.0 |
|
3717 |
* |
|
16 | 3718 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
* @return true|IXR_Error True, on success. |
0 | 3728 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
public function wp_editComment( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
$this->escape( $args ); |
0 | 3731 |
|
9 | 3732 |
$username = $args[1]; |
3733 |
$password = $args[2]; |
|
3734 |
$comment_ID = (int) $args[3]; |
|
0 | 3735 |
$content_struct = $args[4]; |
3736 |
||
16 | 3737 |
$user = $this->login( $username, $password ); |
3738 |
if ( ! $user ) { |
|
0 | 3739 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3743 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
} |
0 | 3749 |
|
5 | 3750 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3751 |
do_action( 'xmlrpc_call', 'wp.editComment' ); |
|
9 | 3752 |
$comment = array( |
3753 |
'comment_ID' => $comment_ID, |
|
3754 |
); |
|
3755 |
||
3756 |
if ( isset( $content_struct['status'] ) ) { |
|
0 | 3757 |
$statuses = get_comment_statuses(); |
9 | 3758 |
$statuses = array_keys( $statuses ); |
3759 |
||
16 | 3760 |
if ( ! in_array( $content_struct['status'], $statuses, true ) ) { |
0 | 3761 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
9 | 3762 |
} |
3763 |
||
3764 |
$comment['comment_approved'] = $content_struct['status']; |
|
0 | 3765 |
} |
3766 |
||
16 | 3767 |
// Do some timestamp voodoo. |
9 | 3768 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 3769 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
9 | 3770 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
16 | 3771 |
$comment['comment_date'] = get_date_from_gmt( $dateCreated ); |
3772 |
$comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
9 | 3773 |
} |
3774 |
||
3775 |
if ( isset( $content_struct['content'] ) ) { |
|
3776 |
$comment['comment_content'] = $content_struct['content']; |
|
3777 |
} |
|
3778 |
||
3779 |
if ( isset( $content_struct['author'] ) ) { |
|
3780 |
$comment['comment_author'] = $content_struct['author']; |
|
3781 |
} |
|
3782 |
||
3783 |
if ( isset( $content_struct['author_url'] ) ) { |
|
3784 |
$comment['comment_author_url'] = $content_struct['author_url']; |
|
3785 |
} |
|
3786 |
||
3787 |
if ( isset( $content_struct['author_email'] ) ) { |
|
3788 |
$comment['comment_author_email'] = $content_struct['author_email']; |
|
3789 |
} |
|
3790 |
||
16 | 3791 |
$result = wp_update_comment( $comment, true ); |
9 | 3792 |
if ( is_wp_error( $result ) ) { |
3793 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
3794 |
} |
|
3795 |
||
3796 |
if ( ! $result ) { |
|
16 | 3797 |
return new IXR_Error( 500, __( 'Sorry, the comment could not be updated.' ) ); |
9 | 3798 |
} |
0 | 3799 |
|
5 | 3800 |
/** |
3801 |
* Fires after a comment has been successfully updated via XML-RPC. |
|
3802 |
* |
|
3803 |
* @since 3.4.0 |
|
3804 |
* |
|
3805 |
* @param int $comment_ID ID of the updated comment. |
|
3806 |
* @param array $args An array of arguments to update the comment. |
|
3807 |
*/ |
|
16 | 3808 |
do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3809 |
|
3810 |
return true; |
|
3811 |
} |
|
3812 |
||
3813 |
/** |
|
3814 |
* Create new comment. |
|
3815 |
* |
|
3816 |
* @since 2.7.0 |
|
3817 |
* |
|
16 | 3818 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3819 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3820 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3821 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
* @type string|int $post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
* @return int|IXR_Error See wp_new_comment(). |
0 | 3828 |
*/ |
9 | 3829 |
public function wp_newComment( $args ) { |
3830 |
$this->escape( $args ); |
|
0 | 3831 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3833 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
$post = $args[3]; |
0 | 3835 |
$content_struct = $args[4]; |
3836 |
||
5 | 3837 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3838 |
* Filters whether to allow anonymous comments over XML-RPC. |
5 | 3839 |
* |
3840 |
* @since 2.7.0 |
|
3841 |
* |
|
3842 |
* @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3843 |
* Default false. |
|
3844 |
*/ |
|
3845 |
$allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
|
0 | 3846 |
|
9 | 3847 |
$user = $this->login( $username, $password ); |
3848 |
||
3849 |
if ( ! $user ) { |
|
0 | 3850 |
$logged_in = false; |
9 | 3851 |
if ( $allow_anon && get_option( 'comment_registration' ) ) { |
16 | 3852 |
return new IXR_Error( 403, __( 'Sorry, you must be logged in to comment.' ) ); |
5 | 3853 |
} elseif ( ! $allow_anon ) { |
0 | 3854 |
return $this->error; |
5 | 3855 |
} |
0 | 3856 |
} else { |
3857 |
$logged_in = true; |
|
3858 |
} |
|
3859 |
||
9 | 3860 |
if ( is_numeric( $post ) ) { |
3861 |
$post_id = absint( $post ); |
|
3862 |
} else { |
|
3863 |
$post_id = url_to_postid( $post ); |
|
3864 |
} |
|
0 | 3865 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
if ( ! $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3870 |
if ( ! get_post( $post_id ) ) { |
0 | 3871 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3872 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
if ( ! comments_open( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3876 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
if ( empty( $content_struct['content'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
return new IXR_Error( 403, __( 'Comment is required.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
$comment = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3883 |
'comment_post_ID' => $post_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
'comment_content' => $content_struct['content'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
); |
0 | 3886 |
|
3887 |
if ( $logged_in ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
$display_name = $user->display_name; |
9 | 3889 |
$user_email = $user->user_email; |
3890 |
$user_url = $user->user_url; |
|
3891 |
||
3892 |
$comment['comment_author'] = $this->escape( $display_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3893 |
$comment['comment_author_email'] = $this->escape( $user_email ); |
9 | 3894 |
$comment['comment_author_url'] = $this->escape( $user_url ); |
3895 |
$comment['user_ID'] = $user->ID; |
|
0 | 3896 |
} else { |
3897 |
$comment['comment_author'] = ''; |
|
9 | 3898 |
if ( isset( $content_struct['author'] ) ) { |
0 | 3899 |
$comment['comment_author'] = $content_struct['author']; |
9 | 3900 |
} |
0 | 3901 |
|
3902 |
$comment['comment_author_email'] = ''; |
|
9 | 3903 |
if ( isset( $content_struct['author_email'] ) ) { |
0 | 3904 |
$comment['comment_author_email'] = $content_struct['author_email']; |
9 | 3905 |
} |
0 | 3906 |
|
3907 |
$comment['comment_author_url'] = ''; |
|
9 | 3908 |
if ( isset( $content_struct['author_url'] ) ) { |
0 | 3909 |
$comment['comment_author_url'] = $content_struct['author_url']; |
9 | 3910 |
} |
0 | 3911 |
|
3912 |
$comment['user_ID'] = 0; |
|
3913 |
||
9 | 3914 |
if ( get_option( 'require_name_email' ) ) { |
16 | 3915 |
if ( strlen( $comment['comment_author_email'] < 6 ) || '' === $comment['comment_author'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
9 | 3917 |
} elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
9 | 3919 |
} |
0 | 3920 |
} |
3921 |
} |
|
3922 |
||
9 | 3923 |
$comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
0 | 3924 |
|
5 | 3925 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3926 |
do_action( 'xmlrpc_call', 'wp.newComment' ); |
|
0 | 3927 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
$comment_ID = wp_new_comment( $comment, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
return new IXR_Error( 403, $comment_ID->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
if ( ! $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3934 |
return new IXR_Error( 403, __( 'Something went wrong.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3935 |
} |
0 | 3936 |
|
5 | 3937 |
/** |
3938 |
* Fires after a new comment has been successfully created via XML-RPC. |
|
3939 |
* |
|
3940 |
* @since 3.4.0 |
|
3941 |
* |
|
3942 |
* @param int $comment_ID ID of the new comment. |
|
3943 |
* @param array $args An array of new comment arguments. |
|
3944 |
*/ |
|
16 | 3945 |
do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3946 |
|
3947 |
return $comment_ID; |
|
3948 |
} |
|
3949 |
||
3950 |
/** |
|
3951 |
* Retrieve all of the comment status. |
|
3952 |
* |
|
3953 |
* @since 2.7.0 |
|
3954 |
* |
|
16 | 3955 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
* } |
5 | 3962 |
* @return array|IXR_Error |
0 | 3963 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
public function wp_getCommentStatusList( $args ) { |
0 | 3965 |
$this->escape( $args ); |
3966 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
|
16 | 3970 |
$user = $this->login( $username, $password ); |
3971 |
if ( ! $user ) { |
|
0 | 3972 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
if ( ! current_user_can( 'publish_posts' ) ) { |
9 | 3976 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
} |
0 | 3978 |
|
5 | 3979 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3980 |
do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
|
0 | 3981 |
|
3982 |
return get_comment_statuses(); |
|
3983 |
} |
|
3984 |
||
3985 |
/** |
|
3986 |
* Retrieve comment count. |
|
3987 |
* |
|
3988 |
* @since 2.5.0 |
|
3989 |
* |
|
16 | 3990 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
* } |
5 | 3998 |
* @return array|IXR_Error |
0 | 3999 |
*/ |
5 | 4000 |
public function wp_getCommentCount( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4001 |
$this->escape( $args ); |
0 | 4002 |
|
9 | 4003 |
$username = $args[1]; |
4004 |
$password = $args[2]; |
|
4005 |
$post_id = (int) $args[3]; |
|
0 | 4006 |
|
16 | 4007 |
$user = $this->login( $username, $password ); |
4008 |
if ( ! $user ) { |
|
0 | 4009 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4012 |
$post = get_post( $post_id, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4013 |
if ( empty( $post['ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4014 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4015 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4016 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4017 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 4018 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details of this post.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4019 |
} |
0 | 4020 |
|
5 | 4021 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4022 |
do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
|
0 | 4023 |
|
4024 |
$count = wp_count_comments( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4025 |
|
0 | 4026 |
return array( |
9 | 4027 |
'approved' => $count->approved, |
0 | 4028 |
'awaiting_moderation' => $count->moderated, |
9 | 4029 |
'spam' => $count->spam, |
4030 |
'total_comments' => $count->total_comments, |
|
0 | 4031 |
); |
4032 |
} |
|
4033 |
||
4034 |
/** |
|
4035 |
* Retrieve post statuses. |
|
4036 |
* |
|
4037 |
* @since 2.5.0 |
|
4038 |
* |
|
16 | 4039 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4040 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4041 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4042 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4043 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4044 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4045 |
* } |
5 | 4046 |
* @return array|IXR_Error |
0 | 4047 |
*/ |
5 | 4048 |
public function wp_getPostStatusList( $args ) { |
0 | 4049 |
$this->escape( $args ); |
4050 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4051 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4052 |
$password = $args[2]; |
0 | 4053 |
|
16 | 4054 |
$user = $this->login( $username, $password ); |
4055 |
if ( ! $user ) { |
|
0 | 4056 |
return $this->error; |
9 | 4057 |
} |
4058 |
||
4059 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4060 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4061 |
} |
|
0 | 4062 |
|
5 | 4063 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4064 |
do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
|
0 | 4065 |
|
4066 |
return get_post_statuses(); |
|
4067 |
} |
|
4068 |
||
4069 |
/** |
|
4070 |
* Retrieve page statuses. |
|
4071 |
* |
|
4072 |
* @since 2.5.0 |
|
4073 |
* |
|
16 | 4074 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4076 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4077 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4078 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4079 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4080 |
* } |
5 | 4081 |
* @return array|IXR_Error |
0 | 4082 |
*/ |
5 | 4083 |
public function wp_getPageStatusList( $args ) { |
0 | 4084 |
$this->escape( $args ); |
4085 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4086 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4087 |
$password = $args[2]; |
0 | 4088 |
|
16 | 4089 |
$user = $this->login( $username, $password ); |
4090 |
if ( ! $user ) { |
|
0 | 4091 |
return $this->error; |
9 | 4092 |
} |
4093 |
||
4094 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4095 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4096 |
} |
|
0 | 4097 |
|
5 | 4098 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4099 |
do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
|
0 | 4100 |
|
4101 |
return get_page_statuses(); |
|
4102 |
} |
|
4103 |
||
4104 |
/** |
|
4105 |
* Retrieve page templates. |
|
4106 |
* |
|
4107 |
* @since 2.6.0 |
|
4108 |
* |
|
16 | 4109 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4110 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4111 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4112 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4113 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4114 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4115 |
* } |
5 | 4116 |
* @return array|IXR_Error |
0 | 4117 |
*/ |
5 | 4118 |
public function wp_getPageTemplates( $args ) { |
0 | 4119 |
$this->escape( $args ); |
4120 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4121 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4122 |
$password = $args[2]; |
0 | 4123 |
|
16 | 4124 |
$user = $this->login( $username, $password ); |
4125 |
if ( ! $user ) { |
|
0 | 4126 |
return $this->error; |
9 | 4127 |
} |
4128 |
||
4129 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4130 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4131 |
} |
|
4132 |
||
4133 |
$templates = get_page_templates(); |
|
0 | 4134 |
$templates['Default'] = 'default'; |
4135 |
||
4136 |
return $templates; |
|
4137 |
} |
|
4138 |
||
4139 |
/** |
|
4140 |
* Retrieve blog options. |
|
4141 |
* |
|
4142 |
* @since 2.6.0 |
|
4143 |
* |
|
16 | 4144 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4147 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4148 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4149 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4150 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
* } |
5 | 4152 |
* @return array|IXR_Error |
0 | 4153 |
*/ |
5 | 4154 |
public function wp_getOptions( $args ) { |
0 | 4155 |
$this->escape( $args ); |
4156 |
||
9 | 4157 |
$username = $args[1]; |
4158 |
$password = $args[2]; |
|
4159 |
$options = isset( $args[3] ) ? (array) $args[3] : array(); |
|
4160 |
||
16 | 4161 |
$user = $this->login( $username, $password ); |
4162 |
if ( ! $user ) { |
|
0 | 4163 |
return $this->error; |
9 | 4164 |
} |
0 | 4165 |
|
16 | 4166 |
// If no specific options where asked for, return all of them. |
9 | 4167 |
if ( count( $options ) == 0 ) { |
4168 |
$options = array_keys( $this->blog_options ); |
|
4169 |
} |
|
4170 |
||
4171 |
return $this->_getOptions( $options ); |
|
0 | 4172 |
} |
4173 |
||
4174 |
/** |
|
4175 |
* Retrieve blog options value from list. |
|
4176 |
* |
|
4177 |
* @since 2.6.0 |
|
4178 |
* |
|
4179 |
* @param array $options Options to retrieve. |
|
4180 |
* @return array |
|
4181 |
*/ |
|
9 | 4182 |
public function _getOptions( $options ) { |
4183 |
$data = array(); |
|
0 | 4184 |
$can_manage = current_user_can( 'manage_options' ); |
4185 |
foreach ( $options as $option ) { |
|
4186 |
if ( array_key_exists( $option, $this->blog_options ) ) { |
|
9 | 4187 |
$data[ $option ] = $this->blog_options[ $option ]; |
16 | 4188 |
// Is the value static or dynamic? |
9 | 4189 |
if ( isset( $data[ $option ]['option'] ) ) { |
4190 |
$data[ $option ]['value'] = get_option( $data[ $option ]['option'] ); |
|
4191 |
unset( $data[ $option ]['option'] ); |
|
0 | 4192 |
} |
4193 |
||
9 | 4194 |
if ( ! $can_manage ) { |
4195 |
$data[ $option ]['readonly'] = true; |
|
4196 |
} |
|
0 | 4197 |
} |
4198 |
} |
|
4199 |
||
4200 |
return $data; |
|
4201 |
} |
|
4202 |
||
4203 |
/** |
|
4204 |
* Update blog options. |
|
4205 |
* |
|
4206 |
* @since 2.6.0 |
|
4207 |
* |
|
16 | 4208 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4209 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
* } |
5 | 4216 |
* @return array|IXR_Error |
0 | 4217 |
*/ |
5 | 4218 |
public function wp_setOptions( $args ) { |
0 | 4219 |
$this->escape( $args ); |
4220 |
||
9 | 4221 |
$username = $args[1]; |
4222 |
$password = $args[2]; |
|
4223 |
$options = (array) $args[3]; |
|
4224 |
||
16 | 4225 |
$user = $this->login( $username, $password ); |
4226 |
if ( ! $user ) { |
|
0 | 4227 |
return $this->error; |
9 | 4228 |
} |
4229 |
||
4230 |
if ( ! current_user_can( 'manage_options' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4231 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) ); |
9 | 4232 |
} |
0 | 4233 |
|
5 | 4234 |
$option_names = array(); |
0 | 4235 |
foreach ( $options as $o_name => $o_value ) { |
4236 |
$option_names[] = $o_name; |
|
9 | 4237 |
if ( ! array_key_exists( $o_name, $this->blog_options ) ) { |
0 | 4238 |
continue; |
9 | 4239 |
} |
4240 |
||
16 | 4241 |
if ( true == $this->blog_options[ $o_name ]['readonly'] ) { |
0 | 4242 |
continue; |
9 | 4243 |
} |
4244 |
||
4245 |
update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) ); |
|
0 | 4246 |
} |
4247 |
||
16 | 4248 |
// Now return the updated values. |
9 | 4249 |
return $this->_getOptions( $option_names ); |
0 | 4250 |
} |
4251 |
||
4252 |
/** |
|
4253 |
* Retrieve a media item by ID |
|
4254 |
* |
|
4255 |
* @since 3.1.0 |
|
4256 |
* |
|
16 | 4257 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4258 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4259 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4260 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4261 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4262 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4263 |
* @type int $attachment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4264 |
* } |
5 | 4265 |
* @return array|IXR_Error Associative array contains: |
0 | 4266 |
* - 'date_created_gmt' |
4267 |
* - 'parent' |
|
4268 |
* - 'link' |
|
4269 |
* - 'thumbnail' |
|
4270 |
* - 'title' |
|
4271 |
* - 'caption' |
|
4272 |
* - 'description' |
|
4273 |
* - 'metadata' |
|
4274 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4275 |
public function wp_getMediaItem( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4276 |
$this->escape( $args ); |
0 | 4277 |
|
9 | 4278 |
$username = $args[1]; |
4279 |
$password = $args[2]; |
|
4280 |
$attachment_id = (int) $args[3]; |
|
4281 |
||
16 | 4282 |
$user = $this->login( $username, $password ); |
4283 |
if ( ! $user ) { |
|
0 | 4284 |
return $this->error; |
9 | 4285 |
} |
4286 |
||
4287 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4288 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4289 |
} |
0 | 4290 |
|
5 | 4291 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4292 |
do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
|
0 | 4293 |
|
16 | 4294 |
$attachment = get_post( $attachment_id ); |
4295 |
if ( ! $attachment ) { |
|
0 | 4296 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 4297 |
} |
0 | 4298 |
|
4299 |
return $this->_prepare_media_item( $attachment ); |
|
4300 |
} |
|
4301 |
||
4302 |
/** |
|
4303 |
* Retrieves a collection of media library items (or attachments) |
|
4304 |
* |
|
5 | 4305 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 4306 |
* array as last argument. |
4307 |
* |
|
4308 |
* Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
|
4309 |
* |
|
4310 |
* The defaults are as follows: |
|
4311 |
* - 'number' - Default is 5. Total number of media items to retrieve. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4312 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 4313 |
* - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
4314 |
* - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
|
4315 |
* |
|
4316 |
* @since 3.1.0 |
|
4317 |
* |
|
16 | 4318 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4319 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4320 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4321 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4322 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4323 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4324 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4325 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4326 |
* @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents |
0 | 4327 |
*/ |
9 | 4328 |
public function wp_getMediaLibrary( $args ) { |
4329 |
$this->escape( $args ); |
|
4330 |
||
4331 |
$username = $args[1]; |
|
4332 |
$password = $args[2]; |
|
4333 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
|
4334 |
||
16 | 4335 |
$user = $this->login( $username, $password ); |
4336 |
if ( ! $user ) { |
|
0 | 4337 |
return $this->error; |
9 | 4338 |
} |
4339 |
||
4340 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4341 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4342 |
} |
0 | 4343 |
|
5 | 4344 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4345 |
do_action( 'xmlrpc_call', 'wp.getMediaLibrary' ); |
|
0 | 4346 |
|
9 | 4347 |
$parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4348 |
$mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
|
4349 |
$offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
|
4350 |
$number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
|
4351 |
||
4352 |
$attachments = get_posts( |
|
4353 |
array( |
|
4354 |
'post_type' => 'attachment', |
|
4355 |
'post_parent' => $parent_id, |
|
4356 |
'offset' => $offset, |
|
4357 |
'numberposts' => $number, |
|
4358 |
'post_mime_type' => $mime_type, |
|
4359 |
) |
|
4360 |
); |
|
0 | 4361 |
|
4362 |
$attachments_struct = array(); |
|
4363 |
||
9 | 4364 |
foreach ( $attachments as $attachment ) { |
0 | 4365 |
$attachments_struct[] = $this->_prepare_media_item( $attachment ); |
9 | 4366 |
} |
0 | 4367 |
|
4368 |
return $attachments_struct; |
|
4369 |
} |
|
4370 |
||
4371 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4372 |
* Retrieves a list of post formats used by the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4373 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4374 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
* |
16 | 4376 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4377 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4379 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4380 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4382 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4383 |
* @return array|IXR_Error List of post formats, otherwise IXR_Error object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
*/ |
5 | 4385 |
public function wp_getPostFormats( $args ) { |
0 | 4386 |
$this->escape( $args ); |
4387 |
||
4388 |
$username = $args[1]; |
|
4389 |
$password = $args[2]; |
|
4390 |
||
16 | 4391 |
$user = $this->login( $username, $password ); |
4392 |
if ( ! $user ) { |
|
0 | 4393 |
return $this->error; |
9 | 4394 |
} |
4395 |
||
4396 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4397 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4398 |
} |
|
0 | 4399 |
|
5 | 4400 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4401 |
do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
4402 |
||
4403 |
$formats = get_post_format_strings(); |
|
4404 |
||
16 | 4405 |
// Find out if they want a list of currently supports formats. |
0 | 4406 |
if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4407 |
if ( $args[3]['show-supported'] ) { |
|
4408 |
if ( current_theme_supports( 'post-formats' ) ) { |
|
4409 |
$supported = get_theme_support( 'post-formats' ); |
|
4410 |
||
9 | 4411 |
$data = array(); |
4412 |
$data['all'] = $formats; |
|
0 | 4413 |
$data['supported'] = $supported[0]; |
4414 |
||
4415 |
$formats = $data; |
|
4416 |
} |
|
4417 |
} |
|
4418 |
} |
|
4419 |
||
4420 |
return $formats; |
|
4421 |
} |
|
4422 |
||
4423 |
/** |
|
4424 |
* Retrieves a post type |
|
4425 |
* |
|
4426 |
* @since 3.4.0 |
|
4427 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4428 |
* @see get_post_type_object() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4429 |
* |
16 | 4430 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4431 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4432 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4433 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4434 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4435 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4436 |
* @type string $post_type_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4437 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4438 |
* } |
5 | 4439 |
* @return array|IXR_Error Array contains: |
0 | 4440 |
* - 'labels' |
4441 |
* - 'description' |
|
4442 |
* - 'capability_type' |
|
4443 |
* - 'cap' |
|
4444 |
* - 'map_meta_cap' |
|
4445 |
* - 'hierarchical' |
|
4446 |
* - 'menu_position' |
|
4447 |
* - 'taxonomies' |
|
4448 |
* - 'supports' |
|
4449 |
*/ |
|
5 | 4450 |
public function wp_getPostType( $args ) { |
9 | 4451 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4452 |
return $this->error; |
9 | 4453 |
} |
0 | 4454 |
|
4455 |
$this->escape( $args ); |
|
4456 |
||
4457 |
$username = $args[1]; |
|
4458 |
$password = $args[2]; |
|
4459 |
$post_type_name = $args[3]; |
|
4460 |
||
5 | 4461 |
if ( isset( $args[4] ) ) { |
0 | 4462 |
$fields = $args[4]; |
5 | 4463 |
} else { |
4464 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4465 |
* Filters the default query fields used by the given XML-RPC method. |
5 | 4466 |
* |
4467 |
* @since 3.4.0 |
|
4468 |
* |
|
4469 |
* @param array $fields An array of post type query fields for the given method. |
|
4470 |
* @param string $method The method name. |
|
4471 |
*/ |
|
0 | 4472 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
5 | 4473 |
} |
0 | 4474 |
|
16 | 4475 |
$user = $this->login( $username, $password ); |
4476 |
if ( ! $user ) { |
|
0 | 4477 |
return $this->error; |
9 | 4478 |
} |
0 | 4479 |
|
5 | 4480 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4481 |
do_action( 'xmlrpc_call', 'wp.getPostType' ); |
4482 |
||
9 | 4483 |
if ( ! post_type_exists( $post_type_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4484 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 4485 |
} |
0 | 4486 |
|
4487 |
$post_type = get_post_type_object( $post_type_name ); |
|
4488 |
||
9 | 4489 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4490 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 4491 |
} |
0 | 4492 |
|
4493 |
return $this->_prepare_post_type( $post_type, $fields ); |
|
4494 |
} |
|
4495 |
||
4496 |
/** |
|
4497 |
* Retrieves a post types |
|
4498 |
* |
|
4499 |
* @since 3.4.0 |
|
4500 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4501 |
* @see get_post_types() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4502 |
* |
16 | 4503 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4506 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4508 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4509 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4510 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4511 |
* } |
5 | 4512 |
* @return array|IXR_Error |
0 | 4513 |
*/ |
5 | 4514 |
public function wp_getPostTypes( $args ) { |
9 | 4515 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4516 |
return $this->error; |
9 | 4517 |
} |
0 | 4518 |
|
4519 |
$this->escape( $args ); |
|
4520 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4521 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4522 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4523 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 4524 |
|
5 | 4525 |
if ( isset( $args[4] ) ) { |
0 | 4526 |
$fields = $args[4]; |
5 | 4527 |
} else { |
4528 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 4529 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
5 | 4530 |
} |
0 | 4531 |
|
16 | 4532 |
$user = $this->login( $username, $password ); |
4533 |
if ( ! $user ) { |
|
0 | 4534 |
return $this->error; |
9 | 4535 |
} |
0 | 4536 |
|
5 | 4537 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4538 |
do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
4539 |
||
4540 |
$post_types = get_post_types( $filter, 'objects' ); |
|
4541 |
||
4542 |
$struct = array(); |
|
4543 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4544 |
foreach ( $post_types as $post_type ) { |
9 | 4545 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 4546 |
continue; |
9 | 4547 |
} |
4548 |
||
4549 |
$struct[ $post_type->name ] = $this->_prepare_post_type( $post_type, $fields ); |
|
0 | 4550 |
} |
4551 |
||
4552 |
return $struct; |
|
4553 |
} |
|
4554 |
||
4555 |
/** |
|
4556 |
* Retrieve revisions for a specific post. |
|
4557 |
* |
|
4558 |
* @since 3.5.0 |
|
4559 |
* |
|
4560 |
* The optional $fields parameter specifies what fields will be included |
|
4561 |
* in the response array. |
|
4562 |
* |
|
4563 |
* @uses wp_get_post_revisions() |
|
4564 |
* @see wp_getPost() for more on $fields |
|
4565 |
* |
|
16 | 4566 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4567 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4568 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4569 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4570 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4571 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
* } |
5 | 4575 |
* @return array|IXR_Error contains a collection of posts. |
0 | 4576 |
*/ |
5 | 4577 |
public function wp_getRevisions( $args ) { |
9 | 4578 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4579 |
return $this->error; |
9 | 4580 |
} |
0 | 4581 |
|
4582 |
$this->escape( $args ); |
|
4583 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4584 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4585 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
$post_id = (int) $args[3]; |
0 | 4587 |
|
5 | 4588 |
if ( isset( $args[4] ) ) { |
0 | 4589 |
$fields = $args[4]; |
5 | 4590 |
} else { |
4591 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
* Filters the default revision query fields used by the given XML-RPC method. |
5 | 4593 |
* |
4594 |
* @since 3.5.0 |
|
4595 |
* |
|
4596 |
* @param array $field An array of revision query fields. |
|
4597 |
* @param string $method The method name. |
|
4598 |
*/ |
|
0 | 4599 |
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
5 | 4600 |
} |
0 | 4601 |
|
16 | 4602 |
$user = $this->login( $username, $password ); |
4603 |
if ( ! $user ) { |
|
0 | 4604 |
return $this->error; |
9 | 4605 |
} |
0 | 4606 |
|
5 | 4607 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4608 |
do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
4609 |
||
16 | 4610 |
$post = get_post( $post_id ); |
4611 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4612 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4613 |
} |
4614 |
||
4615 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
0 | 4616 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4617 |
} |
0 | 4618 |
|
4619 |
// Check if revisions are enabled. |
|
9 | 4620 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4621 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4622 |
} |
0 | 4623 |
|
4624 |
$revisions = wp_get_post_revisions( $post_id ); |
|
4625 |
||
9 | 4626 |
if ( ! $revisions ) { |
0 | 4627 |
return array(); |
9 | 4628 |
} |
0 | 4629 |
|
4630 |
$struct = array(); |
|
4631 |
||
4632 |
foreach ( $revisions as $revision ) { |
|
9 | 4633 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
0 | 4634 |
continue; |
9 | 4635 |
} |
0 | 4636 |
|
16 | 4637 |
// Skip autosaves. |
9 | 4638 |
if ( wp_is_post_autosave( $revision ) ) { |
0 | 4639 |
continue; |
9 | 4640 |
} |
0 | 4641 |
|
4642 |
$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); |
|
4643 |
} |
|
4644 |
||
4645 |
return $struct; |
|
4646 |
} |
|
4647 |
||
4648 |
/** |
|
4649 |
* Restore a post revision |
|
4650 |
* |
|
4651 |
* @since 3.5.0 |
|
4652 |
* |
|
4653 |
* @uses wp_restore_post_revision() |
|
4654 |
* |
|
16 | 4655 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4656 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4657 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4658 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4659 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4660 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4661 |
* @type int $revision_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4662 |
* } |
5 | 4663 |
* @return bool|IXR_Error false if there was an error restoring, true if success. |
0 | 4664 |
*/ |
5 | 4665 |
public function wp_restoreRevision( $args ) { |
9 | 4666 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4667 |
return $this->error; |
9 | 4668 |
} |
0 | 4669 |
|
4670 |
$this->escape( $args ); |
|
4671 |
||
4672 |
$username = $args[1]; |
|
4673 |
$password = $args[2]; |
|
4674 |
$revision_id = (int) $args[3]; |
|
4675 |
||
16 | 4676 |
$user = $this->login( $username, $password ); |
4677 |
if ( ! $user ) { |
|
0 | 4678 |
return $this->error; |
9 | 4679 |
} |
0 | 4680 |
|
5 | 4681 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4682 |
do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
4683 |
||
16 | 4684 |
$revision = wp_get_post_revision( $revision_id ); |
4685 |
if ( ! $revision ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4686 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4687 |
} |
4688 |
||
4689 |
if ( wp_is_post_autosave( $revision ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4690 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4691 |
} |
4692 |
||
16 | 4693 |
$post = get_post( $revision->post_parent ); |
4694 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4695 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4696 |
} |
4697 |
||
4698 |
if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4699 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4700 |
} |
0 | 4701 |
|
4702 |
// Check if revisions are disabled. |
|
9 | 4703 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4704 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4705 |
} |
0 | 4706 |
|
4707 |
$post = wp_restore_post_revision( $revision_id ); |
|
4708 |
||
4709 |
return (bool) $post; |
|
4710 |
} |
|
4711 |
||
16 | 4712 |
/* |
4713 |
* Blogger API functions. |
|
4714 |
* Specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
|
0 | 4715 |
*/ |
4716 |
||
4717 |
/** |
|
4718 |
* Retrieve blogs that user owns. |
|
4719 |
* |
|
4720 |
* Will make more sense once we support multiple blogs. |
|
4721 |
* |
|
4722 |
* @since 1.5.0 |
|
4723 |
* |
|
16 | 4724 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4725 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4726 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4727 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4728 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4729 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4730 |
* } |
5 | 4731 |
* @return array|IXR_Error |
0 | 4732 |
*/ |
9 | 4733 |
public function blogger_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4734 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4735 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4736 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4737 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4738 |
if ( is_multisite() ) { |
9 | 4739 |
return $this->_multisite_getUsersBlogs( $args ); |
4740 |
} |
|
4741 |
||
4742 |
$this->escape( $args ); |
|
0 | 4743 |
|
4744 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4745 |
$password = $args[2]; |
0 | 4746 |
|
16 | 4747 |
$user = $this->login( $username, $password ); |
4748 |
if ( ! $user ) { |
|
0 | 4749 |
return $this->error; |
9 | 4750 |
} |
0 | 4751 |
|
5 | 4752 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4753 |
do_action( 'xmlrpc_call', 'blogger.getUsersBlogs' ); |
|
0 | 4754 |
|
9 | 4755 |
$is_admin = current_user_can( 'manage_options' ); |
0 | 4756 |
|
4757 |
$struct = array( |
|
4758 |
'isAdmin' => $is_admin, |
|
9 | 4759 |
'url' => get_option( 'home' ) . '/', |
0 | 4760 |
'blogid' => '1', |
9 | 4761 |
'blogName' => get_option( 'blogname' ), |
0 | 4762 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
4763 |
); |
|
4764 |
||
9 | 4765 |
return array( $struct ); |
0 | 4766 |
} |
4767 |
||
4768 |
/** |
|
4769 |
* Private function for retrieving a users blogs for multisite setups |
|
4770 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4771 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4772 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4773 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4774 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4775 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4776 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4777 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4778 |
* } |
5 | 4779 |
* @return array|IXR_Error |
0 | 4780 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4781 |
protected function _multisite_getUsersBlogs( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4782 |
$current_blog = get_site(); |
0 | 4783 |
|
4784 |
$domain = $current_blog->domain; |
|
9 | 4785 |
$path = $current_blog->path . 'xmlrpc.php'; |
0 | 4786 |
|
4787 |
$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) ); |
|
9 | 4788 |
$rpc->query( 'wp.getUsersBlogs', $args[1], $args[2] ); |
0 | 4789 |
$blogs = $rpc->getResponse(); |
4790 |
||
9 | 4791 |
if ( isset( $blogs['faultCode'] ) ) { |
4792 |
return new IXR_Error( $blogs['faultCode'], $blogs['faultString'] ); |
|
4793 |
} |
|
0 | 4794 |
|
4795 |
if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { |
|
4796 |
return $blogs; |
|
4797 |
} else { |
|
4798 |
foreach ( (array) $blogs as $blog ) { |
|
9 | 4799 |
if ( strpos( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { |
4800 |
return array( $blog ); |
|
4801 |
} |
|
0 | 4802 |
} |
4803 |
return array(); |
|
4804 |
} |
|
4805 |
} |
|
4806 |
||
4807 |
/** |
|
4808 |
* Retrieve user's data. |
|
4809 |
* |
|
4810 |
* Gives your client some info about you, so you don't have to. |
|
4811 |
* |
|
4812 |
* @since 1.5.0 |
|
4813 |
* |
|
16 | 4814 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4815 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4817 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4818 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4819 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4820 |
* } |
5 | 4821 |
* @return array|IXR_Error |
0 | 4822 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4823 |
public function blogger_getUserInfo( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4824 |
$this->escape( $args ); |
0 | 4825 |
|
4826 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4827 |
$password = $args[2]; |
0 | 4828 |
|
16 | 4829 |
$user = $this->login( $username, $password ); |
4830 |
if ( ! $user ) { |
|
0 | 4831 |
return $this->error; |
9 | 4832 |
} |
4833 |
||
4834 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4835 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
9 | 4836 |
} |
0 | 4837 |
|
5 | 4838 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4839 |
do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
|
0 | 4840 |
|
4841 |
$struct = array( |
|
4842 |
'nickname' => $user->nickname, |
|
4843 |
'userid' => $user->ID, |
|
4844 |
'url' => $user->user_url, |
|
4845 |
'lastname' => $user->last_name, |
|
9 | 4846 |
'firstname' => $user->first_name, |
0 | 4847 |
); |
4848 |
||
4849 |
return $struct; |
|
4850 |
} |
|
4851 |
||
4852 |
/** |
|
4853 |
* Retrieve post. |
|
4854 |
* |
|
4855 |
* @since 1.5.0 |
|
4856 |
* |
|
16 | 4857 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4858 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4859 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4860 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4861 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4862 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4863 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4864 |
* } |
5 | 4865 |
* @return array|IXR_Error |
0 | 4866 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4867 |
public function blogger_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4868 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4870 |
$post_ID = (int) $args[1]; |
0 | 4871 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4872 |
$password = $args[3]; |
0 | 4873 |
|
16 | 4874 |
$user = $this->login( $username, $password ); |
4875 |
if ( ! $user ) { |
|
0 | 4876 |
return $this->error; |
9 | 4877 |
} |
4878 |
||
4879 |
$post_data = get_post( $post_ID, ARRAY_A ); |
|
4880 |
if ( ! $post_data ) { |
|
0 | 4881 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4882 |
} |
4883 |
||
4884 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4885 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4886 |
} |
0 | 4887 |
|
5 | 4888 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4889 |
do_action( 'xmlrpc_call', 'blogger.getPost' ); |
|
0 | 4890 |
|
9 | 4891 |
$categories = implode( ',', wp_get_post_categories( $post_ID ) ); |
4892 |
||
4893 |
$content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
|
4894 |
$content .= '<category>' . $categories . '</category>'; |
|
4895 |
$content .= wp_unslash( $post_data['post_content'] ); |
|
0 | 4896 |
|
4897 |
$struct = array( |
|
9 | 4898 |
'userid' => $post_data['post_author'], |
0 | 4899 |
'dateCreated' => $this->_convert_date( $post_data['post_date'] ), |
4900 |
'content' => $content, |
|
9 | 4901 |
'postid' => (string) $post_data['ID'], |
0 | 4902 |
); |
4903 |
||
4904 |
return $struct; |
|
4905 |
} |
|
4906 |
||
4907 |
/** |
|
4908 |
* Retrieve list of recent posts. |
|
4909 |
* |
|
4910 |
* @since 1.5.0 |
|
4911 |
* |
|
16 | 4912 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4913 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4914 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4915 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4916 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4917 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4918 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4919 |
* @type int $numberposts (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4920 |
* } |
5 | 4921 |
* @return array|IXR_Error |
0 | 4922 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4923 |
public function blogger_getRecentPosts( $args ) { |
0 | 4924 |
|
9 | 4925 |
$this->escape( $args ); |
0 | 4926 |
|
16 | 4927 |
// $args[0] = appkey - ignored. |
0 | 4928 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4929 |
$password = $args[3]; |
9 | 4930 |
if ( isset( $args[4] ) ) { |
0 | 4931 |
$query = array( 'numberposts' => absint( $args[4] ) ); |
9 | 4932 |
} else { |
0 | 4933 |
$query = array(); |
9 | 4934 |
} |
4935 |
||
16 | 4936 |
$user = $this->login( $username, $password ); |
4937 |
if ( ! $user ) { |
|
0 | 4938 |
return $this->error; |
9 | 4939 |
} |
4940 |
||
4941 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4942 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4943 |
} |
0 | 4944 |
|
5 | 4945 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4946 |
do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
|
0 | 4947 |
|
4948 |
$posts_list = wp_get_recent_posts( $query ); |
|
4949 |
||
9 | 4950 |
if ( ! $posts_list ) { |
4951 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 4952 |
return $this->error; |
4953 |
} |
|
4954 |
||
5 | 4955 |
$recent_posts = array(); |
9 | 4956 |
foreach ( $posts_list as $entry ) { |
4957 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 4958 |
continue; |
9 | 4959 |
} |
0 | 4960 |
|
4961 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
9 | 4962 |
$categories = implode( ',', wp_get_post_categories( $entry['ID'] ) ); |
4963 |
||
4964 |
$content = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>'; |
|
4965 |
$content .= '<category>' . $categories . '</category>'; |
|
4966 |
$content .= wp_unslash( $entry['post_content'] ); |
|
0 | 4967 |
|
5 | 4968 |
$recent_posts[] = array( |
9 | 4969 |
'userid' => $entry['post_author'], |
0 | 4970 |
'dateCreated' => $post_date, |
9 | 4971 |
'content' => $content, |
4972 |
'postid' => (string) $entry['ID'], |
|
0 | 4973 |
); |
4974 |
} |
|
4975 |
||
4976 |
return $recent_posts; |
|
4977 |
} |
|
4978 |
||
4979 |
/** |
|
4980 |
* Deprecated. |
|
4981 |
* |
|
4982 |
* @since 1.5.0 |
|
4983 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4984 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4985 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4986 |
* @return IXR_Error Error object. |
0 | 4987 |
*/ |
9 | 4988 |
public function blogger_getTemplate( $args ) { |
16 | 4989 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 4990 |
} |
4991 |
||
4992 |
/** |
|
4993 |
* Deprecated. |
|
4994 |
* |
|
4995 |
* @since 1.5.0 |
|
4996 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4997 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4998 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4999 |
* @return IXR_Error Error object. |
0 | 5000 |
*/ |
9 | 5001 |
public function blogger_setTemplate( $args ) { |
16 | 5002 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 5003 |
} |
5004 |
||
5005 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5006 |
* Creates new post. |
0 | 5007 |
* |
5008 |
* @since 1.5.0 |
|
5009 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5010 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5011 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5012 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5013 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5014 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5015 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5016 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5017 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5018 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5019 |
* } |
5 | 5020 |
* @return int|IXR_Error |
0 | 5021 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5022 |
public function blogger_newPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5023 |
$this->escape( $args ); |
0 | 5024 |
|
5025 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5026 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5027 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5028 |
$publish = $args[5]; |
0 | 5029 |
|
16 | 5030 |
$user = $this->login( $username, $password ); |
5031 |
if ( ! $user ) { |
|
0 | 5032 |
return $this->error; |
9 | 5033 |
} |
0 | 5034 |
|
5 | 5035 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5036 |
do_action( 'xmlrpc_call', 'blogger.newPost' ); |
|
0 | 5037 |
|
9 | 5038 |
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
5039 |
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
|
5040 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
|
5041 |
} |
|
5042 |
||
5043 |
$post_status = ( $publish ) ? 'publish' : 'draft'; |
|
0 | 5044 |
|
5045 |
$post_author = $user->ID; |
|
5046 |
||
9 | 5047 |
$post_title = xmlrpc_getposttitle( $content ); |
5048 |
$post_category = xmlrpc_getpostcategory( $content ); |
|
5049 |
$post_content = xmlrpc_removepostdata( $content ); |
|
5050 |
||
5051 |
$post_date = current_time( 'mysql' ); |
|
5052 |
$post_date_gmt = current_time( 'mysql', 1 ); |
|
5053 |
||
5054 |
$post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' ); |
|
5055 |
||
5056 |
$post_ID = wp_insert_post( $post_data ); |
|
5057 |
if ( is_wp_error( $post_ID ) ) { |
|
5058 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
5059 |
} |
|
5060 |
||
5061 |
if ( ! $post_ID ) { |
|
16 | 5062 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5063 |
} |
0 | 5064 |
|
5065 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5066 |
||
5 | 5067 |
/** |
5068 |
* Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
5069 |
* |
|
5070 |
* @since 3.4.0 |
|
5071 |
* |
|
5072 |
* @param int $post_ID ID of the new post. |
|
5073 |
* @param array $args An array of new post arguments. |
|
5074 |
*/ |
|
16 | 5075 |
do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5076 |
|
5077 |
return $post_ID; |
|
5078 |
} |
|
5079 |
||
5080 |
/** |
|
5081 |
* Edit a post. |
|
5082 |
* |
|
5083 |
* @since 1.5.0 |
|
5084 |
* |
|
16 | 5085 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5086 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5087 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5088 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5089 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5090 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5091 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5092 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5093 |
* @type bool $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5094 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5095 |
* @return true|IXR_Error true when done. |
0 | 5096 |
*/ |
5 | 5097 |
public function blogger_editPost( $args ) { |
0 | 5098 |
|
9 | 5099 |
$this->escape( $args ); |
0 | 5100 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5101 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5102 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5103 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5104 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5105 |
$publish = $args[5]; |
5 | 5106 |
|
16 | 5107 |
$user = $this->login( $username, $password ); |
5108 |
if ( ! $user ) { |
|
0 | 5109 |
return $this->error; |
5 | 5110 |
} |
5111 |
||
5112 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5113 |
do_action( 'xmlrpc_call', 'blogger.editPost' ); |
|
5114 |
||
5115 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
5116 |
||
16 | 5117 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5 | 5118 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5119 |
} |
|
0 | 5120 |
|
9 | 5121 |
$this->escape( $actual_post ); |
0 | 5122 |
|
5 | 5123 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
9 | 5124 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5 | 5125 |
} |
16 | 5126 |
if ( 'publish' === $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5127 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5128 |
} |
5129 |
||
9 | 5130 |
$postdata = array(); |
5131 |
$postdata['ID'] = $actual_post['ID']; |
|
5132 |
$postdata['post_content'] = xmlrpc_removepostdata( $content ); |
|
5133 |
$postdata['post_title'] = xmlrpc_getposttitle( $content ); |
|
5 | 5134 |
$postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
9 | 5135 |
$postdata['post_status'] = $actual_post['post_status']; |
5136 |
$postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
5137 |
$postdata['post_status'] = $publish ? 'publish' : 'draft'; |
|
5 | 5138 |
|
5139 |
$result = wp_update_post( $postdata ); |
|
5140 |
||
5141 |
if ( ! $result ) { |
|
16 | 5142 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
5 | 5143 |
} |
5144 |
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
|
5145 |
||
5146 |
/** |
|
5147 |
* Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
5148 |
* |
|
5149 |
* @since 3.4.0 |
|
5150 |
* |
|
5151 |
* @param int $post_ID ID of the updated post. |
|
5152 |
* @param array $args An array of arguments for the post to edit. |
|
5153 |
*/ |
|
16 | 5154 |
do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5155 |
|
5156 |
return true; |
|
5157 |
} |
|
5158 |
||
5159 |
/** |
|
5160 |
* Remove a post. |
|
5161 |
* |
|
5162 |
* @since 1.5.0 |
|
5163 |
* |
|
16 | 5164 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5165 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5166 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5167 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5168 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5169 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5170 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5171 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5172 |
* @return true|IXR_Error True when post is deleted. |
0 | 5173 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5174 |
public function blogger_deletePost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5175 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5177 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5178 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5179 |
$password = $args[3]; |
0 | 5180 |
|
16 | 5181 |
$user = $this->login( $username, $password ); |
5182 |
if ( ! $user ) { |
|
0 | 5183 |
return $this->error; |
9 | 5184 |
} |
0 | 5185 |
|
5 | 5186 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5187 |
do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
|
0 | 5188 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5189 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5190 |
|
16 | 5191 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5192 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5193 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5195 |
if ( ! current_user_can( 'delete_post', $post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5196 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5198 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5199 |
$result = wp_delete_post( $post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5200 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5201 |
if ( ! $result ) { |
16 | 5202 |
return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5203 |
} |
0 | 5204 |
|
5 | 5205 |
/** |
5206 |
* Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
|
5207 |
* |
|
5208 |
* @since 3.4.0 |
|
5209 |
* |
|
5210 |
* @param int $post_ID ID of the deleted post. |
|
5211 |
* @param array $args An array of arguments to delete the post. |
|
5212 |
*/ |
|
16 | 5213 |
do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5214 |
|
5215 |
return true; |
|
5216 |
} |
|
5217 |
||
16 | 5218 |
/* |
5219 |
* MetaWeblog API functions. |
|
5220 |
* Specs on wherever Dave Winer wants them to be. |
|
0 | 5221 |
*/ |
5222 |
||
5223 |
/** |
|
5224 |
* Create a new post. |
|
5225 |
* |
|
5226 |
* The 'content_struct' argument must contain: |
|
5227 |
* - title |
|
5228 |
* - description |
|
5229 |
* - mt_excerpt |
|
5230 |
* - mt_text_more |
|
5231 |
* - mt_keywords |
|
5232 |
* - mt_tb_ping_urls |
|
5233 |
* - categories |
|
5234 |
* |
|
5235 |
* Also, it can optionally contain: |
|
5236 |
* - wp_slug |
|
5237 |
* - wp_password |
|
5238 |
* - wp_page_parent_id |
|
5239 |
* - wp_page_order |
|
5240 |
* - wp_author_id |
|
5241 |
* - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' |
|
5242 |
* - mt_allow_comments - can be 'open' or 'closed' |
|
5243 |
* - mt_allow_pings - can be 'open' or 'closed' |
|
5244 |
* - date_created_gmt |
|
5245 |
* - dateCreated |
|
5246 |
* - wp_post_thumbnail |
|
5247 |
* |
|
5248 |
* @since 1.5.0 |
|
5249 |
* |
|
16 | 5250 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5251 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5252 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5253 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5254 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5255 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5256 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5257 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5258 |
* } |
5 | 5259 |
* @return int|IXR_Error |
0 | 5260 |
*/ |
9 | 5261 |
public function mw_newPost( $args ) { |
5262 |
$this->escape( $args ); |
|
0 | 5263 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5264 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5265 |
$password = $args[2]; |
0 | 5266 |
$content_struct = $args[3]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5267 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
0 | 5268 |
|
16 | 5269 |
$user = $this->login( $username, $password ); |
5270 |
if ( ! $user ) { |
|
0 | 5271 |
return $this->error; |
9 | 5272 |
} |
0 | 5273 |
|
5 | 5274 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5275 |
do_action( 'xmlrpc_call', 'metaWeblog.newPost' ); |
|
0 | 5276 |
|
5277 |
$page_template = ''; |
|
9 | 5278 |
if ( ! empty( $content_struct['post_type'] ) ) { |
16 | 5279 |
if ( 'page' === $content_struct['post_type'] ) { |
9 | 5280 |
if ( $publish ) { |
5281 |
$cap = 'publish_pages'; |
|
16 | 5282 |
} elseif ( isset( $content_struct['page_status'] ) && 'publish' === $content_struct['page_status'] ) { |
9 | 5283 |
$cap = 'publish_pages'; |
5284 |
} else { |
|
0 | 5285 |
$cap = 'edit_pages'; |
9 | 5286 |
} |
0 | 5287 |
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' ); |
9 | 5288 |
$post_type = 'page'; |
5289 |
if ( ! empty( $content_struct['wp_page_template'] ) ) { |
|
0 | 5290 |
$page_template = $content_struct['wp_page_template']; |
9 | 5291 |
} |
16 | 5292 |
} elseif ( 'post' === $content_struct['post_type'] ) { |
9 | 5293 |
if ( $publish ) { |
5294 |
$cap = 'publish_posts'; |
|
16 | 5295 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5296 |
$cap = 'publish_posts'; |
5297 |
} else { |
|
0 | 5298 |
$cap = 'edit_posts'; |
9 | 5299 |
} |
0 | 5300 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5301 |
$post_type = 'post'; |
0 | 5302 |
} else { |
16 | 5303 |
// No other 'post_type' values are allowed here. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5304 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5305 |
} |
5306 |
} else { |
|
9 | 5307 |
if ( $publish ) { |
5308 |
$cap = 'publish_posts'; |
|
16 | 5309 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5310 |
$cap = 'publish_posts'; |
5311 |
} else { |
|
0 | 5312 |
$cap = 'edit_posts'; |
9 | 5313 |
} |
0 | 5314 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5315 |
$post_type = 'post'; |
5316 |
} |
|
5317 |
||
5318 |
if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) { |
|
0 | 5319 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) ); |
9 | 5320 |
} |
5321 |
if ( ! current_user_can( $cap ) ) { |
|
0 | 5322 |
return new IXR_Error( 401, $error_message ); |
9 | 5323 |
} |
0 | 5324 |
|
16 | 5325 |
// Check for a valid post format if one was given. |
0 | 5326 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5327 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5328 |
if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5329 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5330 |
} |
5331 |
} |
|
5332 |
||
16 | 5333 |
// Let WordPress generate the 'post_name' (slug) unless |
0 | 5334 |
// one has been provided. |
9 | 5335 |
$post_name = ''; |
5336 |
if ( isset( $content_struct['wp_slug'] ) ) { |
|
0 | 5337 |
$post_name = $content_struct['wp_slug']; |
9 | 5338 |
} |
0 | 5339 |
|
5340 |
// Only use a password if one was given. |
|
9 | 5341 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5342 |
$post_password = $content_struct['wp_password']; |
9 | 5343 |
} else { |
5344 |
$post_password = ''; |
|
5345 |
} |
|
0 | 5346 |
|
16 | 5347 |
// Only set a post parent if one was given. |
9 | 5348 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5349 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5350 |
} else { |
5351 |
$post_parent = 0; |
|
5352 |
} |
|
0 | 5353 |
|
16 | 5354 |
// Only set the 'menu_order' if it was given. |
9 | 5355 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5356 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5357 |
} else { |
5358 |
$menu_order = 0; |
|
5359 |
} |
|
0 | 5360 |
|
5361 |
$post_author = $user->ID; |
|
5362 |
||
5363 |
// If an author id was provided then use it instead. |
|
5364 |
if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
|
5365 |
switch ( $post_type ) { |
|
9 | 5366 |
case 'post': |
5367 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5368 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 5369 |
} |
0 | 5370 |
break; |
9 | 5371 |
case 'page': |
5372 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5373 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
9 | 5374 |
} |
0 | 5375 |
break; |
5376 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5377 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5378 |
} |
5379 |
$author = get_userdata( $content_struct['wp_author_id'] ); |
|
9 | 5380 |
if ( ! $author ) { |
0 | 5381 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 5382 |
} |
0 | 5383 |
$post_author = $content_struct['wp_author_id']; |
5384 |
} |
|
5385 |
||
9 | 5386 |
$post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; |
0 | 5387 |
$post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null; |
5388 |
||
5389 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5390 |
||
9 | 5391 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5392 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5393 |
case 'draft': |
5394 |
case 'pending': |
|
5395 |
case 'private': |
|
5396 |
case 'publish': |
|
9 | 5397 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5398 |
break; |
5399 |
default: |
|
5400 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5401 |
break; |
|
5402 |
} |
|
5403 |
} |
|
5404 |
||
9 | 5405 |
$post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : null; |
5406 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5407 |
||
5408 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5409 |
||
5410 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
|
5411 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5412 |
switch ( $content_struct['mt_allow_comments'] ) { |
5413 |
case 'closed': |
|
5414 |
$comment_status = 'closed'; |
|
5415 |
break; |
|
5416 |
case 'open': |
|
5417 |
$comment_status = 'open'; |
|
5418 |
break; |
|
5419 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5420 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5421 |
break; |
5422 |
} |
|
5423 |
} else { |
|
5424 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5425 |
case 0: |
|
5426 |
case 2: |
|
5427 |
$comment_status = 'closed'; |
|
5428 |
break; |
|
5429 |
case 1: |
|
5430 |
$comment_status = 'open'; |
|
5431 |
break; |
|
5432 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5433 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5434 |
break; |
5435 |
} |
|
5436 |
} |
|
5437 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5438 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5439 |
} |
5440 |
||
9 | 5441 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5442 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5443 |
switch ( $content_struct['mt_allow_pings'] ) { |
5444 |
case 'closed': |
|
5445 |
$ping_status = 'closed'; |
|
5446 |
break; |
|
5447 |
case 'open': |
|
5448 |
$ping_status = 'open'; |
|
5449 |
break; |
|
5450 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5451 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5452 |
break; |
5453 |
} |
|
5454 |
} else { |
|
5455 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
|
5456 |
case 0: |
|
5457 |
$ping_status = 'closed'; |
|
5458 |
break; |
|
5459 |
case 1: |
|
5460 |
$ping_status = 'open'; |
|
5461 |
break; |
|
5462 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5463 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5464 |
break; |
5465 |
} |
|
5466 |
} |
|
5467 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5468 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5469 |
} |
5470 |
||
9 | 5471 |
if ( $post_more ) { |
0 | 5472 |
$post_content = $post_content . '<!--more-->' . $post_more; |
9 | 5473 |
} |
0 | 5474 |
|
5475 |
$to_ping = null; |
|
5476 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5477 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5478 |
if ( is_array( $to_ping ) ) { |
5479 |
$to_ping = implode( ' ', $to_ping ); |
|
5480 |
} |
|
0 | 5481 |
} |
5482 |
||
16 | 5483 |
// Do some timestamp voodoo. |
9 | 5484 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 5485 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5486 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5487 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5488 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5489 |
} |
5490 |
||
5491 |
if ( ! empty( $dateCreated ) ) { |
|
16 | 5492 |
$post_date = iso8601_to_datetime( $dateCreated ); |
5493 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
0 | 5494 |
} else { |
9 | 5495 |
$post_date = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5496 |
$post_date_gmt = ''; |
0 | 5497 |
} |
5498 |
||
5499 |
$post_category = array(); |
|
5500 |
if ( isset( $content_struct['categories'] ) ) { |
|
5501 |
$catnames = $content_struct['categories']; |
|
5502 |
||
9 | 5503 |
if ( is_array( $catnames ) ) { |
5504 |
foreach ( $catnames as $cat ) { |
|
5505 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5506 |
} |
5507 |
} |
|
5508 |
} |
|
5509 |
||
9 | 5510 |
$postdata = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template' ); |
0 | 5511 |
|
16 | 5512 |
$post_ID = get_default_post_to_edit( $post_type, true )->ID; |
5513 |
$postdata['ID'] = $post_ID; |
|
5514 |
||
5515 |
// Only posts can be sticky. |
|
5516 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 5517 |
$data = $postdata; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5518 |
$data['sticky'] = $content_struct['sticky']; |
9 | 5519 |
$error = $this->_toggle_sticky( $data ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5520 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5521 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5522 |
} |
0 | 5523 |
} |
5524 |
||
9 | 5525 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5526 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5527 |
} |
|
5528 |
||
5529 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
5530 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
|
0 | 5531 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5532 |
} |
0 | 5533 |
|
5534 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5535 |
} |
|
5536 |
||
16 | 5537 |
// Handle enclosures. |
9 | 5538 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5539 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5540 |
|
5541 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5542 |
||
5543 |
// Handle post formats if assigned, value is validated earlier |
|
16 | 5544 |
// in this function. |
9 | 5545 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 5546 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 5547 |
} |
0 | 5548 |
|
5549 |
$post_ID = wp_insert_post( $postdata, true ); |
|
9 | 5550 |
if ( is_wp_error( $post_ID ) ) { |
5551 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
5552 |
} |
|
5553 |
||
5554 |
if ( ! $post_ID ) { |
|
16 | 5555 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5556 |
} |
0 | 5557 |
|
5 | 5558 |
/** |
5559 |
* Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
5560 |
* |
|
5561 |
* @since 3.4.0 |
|
5562 |
* |
|
5563 |
* @param int $post_ID ID of the new post. |
|
5564 |
* @param array $args An array of arguments to create the new post. |
|
5565 |
*/ |
|
16 | 5566 |
do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5567 |
|
9 | 5568 |
return strval( $post_ID ); |
0 | 5569 |
} |
5570 |
||
5 | 5571 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5572 |
* Adds an enclosure to a post if it's new. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5573 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5574 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5575 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5576 |
* @param integer $post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5577 |
* @param array $enclosure Enclosure data. |
5 | 5578 |
*/ |
5579 |
public function add_enclosure_if_new( $post_ID, $enclosure ) { |
|
0 | 5580 |
if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
16 | 5581 |
$encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
5582 |
$found = false; |
|
5583 |
$enclosures = get_post_meta( $post_ID, 'enclosure' ); |
|
5584 |
if ( $enclosures ) { |
|
0 | 5585 |
foreach ( $enclosures as $enc ) { |
5586 |
// This method used to omit the trailing new line. #23219 |
|
5587 |
if ( rtrim( $enc, "\n" ) == rtrim( $encstring, "\n" ) ) { |
|
5588 |
$found = true; |
|
5589 |
break; |
|
5590 |
} |
|
5591 |
} |
|
5592 |
} |
|
9 | 5593 |
if ( ! $found ) { |
0 | 5594 |
add_post_meta( $post_ID, 'enclosure', $encstring ); |
9 | 5595 |
} |
0 | 5596 |
} |
5597 |
} |
|
5598 |
||
5599 |
/** |
|
5600 |
* Attach upload to a post. |
|
5601 |
* |
|
5602 |
* @since 2.1.0 |
|
5603 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5604 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5605 |
* |
16 | 5606 |
* @param int $post_ID Post ID. |
0 | 5607 |
* @param string $post_content Post Content for attachment. |
5608 |
*/ |
|
5 | 5609 |
public function attach_uploads( $post_ID, $post_content ) { |
0 | 5610 |
global $wpdb; |
5611 |
||
16 | 5612 |
// Find any unattached files. |
0 | 5613 |
$attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); |
5614 |
if ( is_array( $attachments ) ) { |
|
5615 |
foreach ( $attachments as $file ) { |
|
9 | 5616 |
if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { |
5617 |
$wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); |
|
5618 |
} |
|
0 | 5619 |
} |
5620 |
} |
|
5621 |
} |
|
5622 |
||
5623 |
/** |
|
5624 |
* Edit a post. |
|
5625 |
* |
|
5626 |
* @since 1.5.0 |
|
5627 |
* |
|
16 | 5628 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5629 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5630 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5631 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5632 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5633 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5634 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5635 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5636 |
* } |
5 | 5637 |
* @return bool|IXR_Error True on success. |
0 | 5638 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5639 |
public function mw_editPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5640 |
$this->escape( $args ); |
0 | 5641 |
|
5642 |
$post_ID = (int) $args[0]; |
|
5643 |
$username = $args[1]; |
|
5644 |
$password = $args[2]; |
|
5645 |
$content_struct = $args[3]; |
|
5646 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
|
5647 |
||
16 | 5648 |
$user = $this->login( $username, $password ); |
5649 |
if ( ! $user ) { |
|
0 | 5650 |
return $this->error; |
9 | 5651 |
} |
0 | 5652 |
|
5 | 5653 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5654 |
do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
|
0 | 5655 |
|
5656 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5657 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5658 |
/* |
16 | 5659 |
* If there is no post data for the give post ID, stop now and return an error. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5660 |
* Otherwise a new post will be created (which was the old behavior). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5661 |
*/ |
9 | 5662 |
if ( ! $postdata || empty( $postdata['ID'] ) ) { |
0 | 5663 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5664 |
} |
5665 |
||
5666 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5667 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5668 |
} |
0 | 5669 |
|
5670 |
// Use wp.editPost to edit post types other than post and page. |
|
16 | 5671 |
if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5672 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
9 | 5673 |
} |
0 | 5674 |
|
5675 |
// Thwart attempt to change the post type. |
|
9 | 5676 |
if ( ! empty( $content_struct['post_type'] ) && ( $content_struct['post_type'] != $postdata['post_type'] ) ) { |
0 | 5677 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 5678 |
} |
0 | 5679 |
|
16 | 5680 |
// Check for a valid post format if one was given. |
0 | 5681 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5682 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5683 |
if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5684 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5685 |
} |
5686 |
} |
|
5687 |
||
9 | 5688 |
$this->escape( $postdata ); |
5689 |
||
5690 |
$ID = $postdata['ID']; |
|
5691 |
$post_content = $postdata['post_content']; |
|
5692 |
$post_title = $postdata['post_title']; |
|
5693 |
$post_excerpt = $postdata['post_excerpt']; |
|
5694 |
$post_password = $postdata['post_password']; |
|
5695 |
$post_parent = $postdata['post_parent']; |
|
5696 |
$post_type = $postdata['post_type']; |
|
5697 |
$menu_order = $postdata['menu_order']; |
|
5698 |
$ping_status = $postdata['ping_status']; |
|
5699 |
$comment_status = $postdata['comment_status']; |
|
0 | 5700 |
|
5701 |
// Let WordPress manage slug if none was provided. |
|
5702 |
$post_name = $postdata['post_name']; |
|
9 | 5703 |
if ( isset( $content_struct['wp_slug'] ) ) { |
0 | 5704 |
$post_name = $content_struct['wp_slug']; |
9 | 5705 |
} |
0 | 5706 |
|
5707 |
// Only use a password if one was given. |
|
9 | 5708 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5709 |
$post_password = $content_struct['wp_password']; |
9 | 5710 |
} |
0 | 5711 |
|
5712 |
// Only set a post parent if one was given. |
|
9 | 5713 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5714 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5715 |
} |
0 | 5716 |
|
16 | 5717 |
// Only set the 'menu_order' if it was given. |
9 | 5718 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5719 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5720 |
} |
0 | 5721 |
|
5 | 5722 |
$page_template = null; |
16 | 5723 |
if ( ! empty( $content_struct['wp_page_template'] ) && 'page' === $post_type ) { |
0 | 5724 |
$page_template = $content_struct['wp_page_template']; |
9 | 5725 |
} |
0 | 5726 |
|
5727 |
$post_author = $postdata['post_author']; |
|
5728 |
||
16 | 5729 |
// If an author id was provided then use it instead. |
5 | 5730 |
if ( isset( $content_struct['wp_author_id'] ) ) { |
5731 |
// Check permissions if attempting to switch author to or from another user. |
|
5732 |
if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) { |
|
5733 |
switch ( $post_type ) { |
|
5734 |
case 'post': |
|
5735 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5736 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the post author as this user.' ) ); |
5 | 5737 |
} |
5738 |
break; |
|
5739 |
case 'page': |
|
5740 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5741 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the page author as this user.' ) ); |
5 | 5742 |
} |
5743 |
break; |
|
5744 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5745 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
5 | 5746 |
} |
5747 |
$post_author = $content_struct['wp_author_id']; |
|
0 | 5748 |
} |
5749 |
} |
|
5750 |
||
9 | 5751 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
5752 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5753 |
switch ( $content_struct['mt_allow_comments'] ) { |
5754 |
case 'closed': |
|
5755 |
$comment_status = 'closed'; |
|
5756 |
break; |
|
5757 |
case 'open': |
|
5758 |
$comment_status = 'open'; |
|
5759 |
break; |
|
5760 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5761 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5762 |
break; |
5763 |
} |
|
5764 |
} else { |
|
5765 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5766 |
case 0: |
|
5767 |
case 2: |
|
5768 |
$comment_status = 'closed'; |
|
5769 |
break; |
|
5770 |
case 1: |
|
5771 |
$comment_status = 'open'; |
|
5772 |
break; |
|
5773 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5774 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5775 |
break; |
5776 |
} |
|
5777 |
} |
|
5778 |
} |
|
5779 |
||
9 | 5780 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5781 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5782 |
switch ( $content_struct['mt_allow_pings'] ) { |
5783 |
case 'closed': |
|
5784 |
$ping_status = 'closed'; |
|
5785 |
break; |
|
5786 |
case 'open': |
|
5787 |
$ping_status = 'open'; |
|
5788 |
break; |
|
5789 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5790 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5791 |
break; |
5792 |
} |
|
5793 |
} else { |
|
9 | 5794 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
0 | 5795 |
case 0: |
5796 |
$ping_status = 'closed'; |
|
5797 |
break; |
|
5798 |
case 1: |
|
5799 |
$ping_status = 'open'; |
|
5800 |
break; |
|
5801 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5802 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5803 |
break; |
5804 |
} |
|
5805 |
} |
|
5806 |
} |
|
5807 |
||
9 | 5808 |
if ( isset( $content_struct['title'] ) ) { |
5809 |
$post_title = $content_struct['title']; |
|
5810 |
} |
|
5811 |
||
5812 |
if ( isset( $content_struct['description'] ) ) { |
|
0 | 5813 |
$post_content = $content_struct['description']; |
9 | 5814 |
} |
0 | 5815 |
|
5816 |
$post_category = array(); |
|
5817 |
if ( isset( $content_struct['categories'] ) ) { |
|
5818 |
$catnames = $content_struct['categories']; |
|
9 | 5819 |
if ( is_array( $catnames ) ) { |
5820 |
foreach ( $catnames as $cat ) { |
|
5821 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5822 |
} |
5823 |
} |
|
5824 |
} |
|
5825 |
||
9 | 5826 |
if ( isset( $content_struct['mt_excerpt'] ) ) { |
5827 |
$post_excerpt = $content_struct['mt_excerpt']; |
|
5828 |
} |
|
0 | 5829 |
|
5830 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5831 |
||
5832 |
$post_status = $publish ? 'publish' : 'draft'; |
|
9 | 5833 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5834 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5835 |
case 'draft': |
5836 |
case 'pending': |
|
5837 |
case 'private': |
|
5838 |
case 'publish': |
|
9 | 5839 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5840 |
break; |
5841 |
default: |
|
5842 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5843 |
break; |
|
5844 |
} |
|
5845 |
} |
|
5846 |
||
5847 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5848 |
||
16 | 5849 |
if ( 'publish' === $post_status || 'private' === $post_status ) { |
5850 |
if ( 'page' === $post_type && ! current_user_can( 'publish_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5851 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) ); |
5 | 5852 |
} elseif ( ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5853 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5854 |
} |
0 | 5855 |
} |
5856 |
||
9 | 5857 |
if ( $post_more ) { |
5858 |
$post_content = $post_content . '<!--more-->' . $post_more; |
|
5859 |
} |
|
0 | 5860 |
|
5861 |
$to_ping = null; |
|
5862 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5863 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5864 |
if ( is_array( $to_ping ) ) { |
5865 |
$to_ping = implode( ' ', $to_ping ); |
|
5866 |
} |
|
0 | 5867 |
} |
5868 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5869 |
// Do some timestamp voodoo. |
9 | 5870 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5871 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5872 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5873 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5874 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5875 |
} |
0 | 5876 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5877 |
// Default to not flagging the post date to be edited unless it's intentional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5878 |
$edit_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5879 |
|
9 | 5880 |
if ( ! empty( $dateCreated ) ) { |
16 | 5881 |
$post_date = iso8601_to_datetime( $dateCreated ); |
5882 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5883 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5884 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5885 |
$edit_date = true; |
0 | 5886 |
} else { |
5887 |
$post_date = $postdata['post_date']; |
|
5888 |
$post_date_gmt = $postdata['post_date_gmt']; |
|
5889 |
} |
|
5890 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5891 |
// We've got all the data -- post it. |
9 | 5892 |
$newpost = compact( 'ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template' ); |
5893 |
||
5894 |
$result = wp_update_post( $newpost, true ); |
|
5895 |
if ( is_wp_error( $result ) ) { |
|
5896 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
5897 |
} |
|
5898 |
||
5899 |
if ( ! $result ) { |
|
16 | 5900 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
5901 |
} |
|
5902 |
||
5903 |
// Only posts can be sticky. |
|
5904 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 5905 |
$data = $newpost; |
5906 |
$data['sticky'] = $content_struct['sticky']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5907 |
$data['post_type'] = 'post'; |
9 | 5908 |
$error = $this->_toggle_sticky( $data, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5909 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5910 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5911 |
} |
0 | 5912 |
} |
5913 |
||
9 | 5914 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5915 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5916 |
} |
|
5917 |
||
5918 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5919 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5920 |
// Empty value deletes, non-empty value adds/updates. |
0 | 5921 |
if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
5922 |
delete_post_thumbnail( $post_ID ); |
|
5923 |
} else { |
|
9 | 5924 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
0 | 5925 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5926 |
} |
0 | 5927 |
} |
5928 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5929 |
} |
|
5930 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5931 |
// Handle enclosures. |
9 | 5932 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5933 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5934 |
|
5935 |
$this->attach_uploads( $ID, $post_content ); |
|
5936 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5937 |
// Handle post formats if assigned, validation is handled earlier in this function. |
9 | 5938 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 5939 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 5940 |
} |
0 | 5941 |
|
5 | 5942 |
/** |
5943 |
* Fires after a post has been successfully updated via the XML-RPC MovableType API. |
|
5944 |
* |
|
5945 |
* @since 3.4.0 |
|
5946 |
* |
|
5947 |
* @param int $post_ID ID of the updated post. |
|
5948 |
* @param array $args An array of arguments to update the post. |
|
5949 |
*/ |
|
16 | 5950 |
do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5951 |
|
5952 |
return true; |
|
5953 |
} |
|
5954 |
||
5955 |
/** |
|
5956 |
* Retrieve post. |
|
5957 |
* |
|
5958 |
* @since 1.5.0 |
|
5959 |
* |
|
16 | 5960 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5961 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5962 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5963 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5964 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5965 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5966 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5967 |
* } |
5 | 5968 |
* @return array|IXR_Error |
0 | 5969 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5970 |
public function mw_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5971 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5973 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5974 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5975 |
$password = $args[2]; |
0 | 5976 |
|
16 | 5977 |
$user = $this->login( $username, $password ); |
5978 |
if ( ! $user ) { |
|
0 | 5979 |
return $this->error; |
9 | 5980 |
} |
5981 |
||
5982 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5983 |
if ( ! $postdata ) { |
|
0 | 5984 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5985 |
} |
5986 |
||
5987 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5988 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5989 |
} |
0 | 5990 |
|
5 | 5991 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5992 |
do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
|
0 | 5993 |
|
16 | 5994 |
if ( '' !== $postdata['post_date'] ) { |
9 | 5995 |
$post_date = $this->_convert_date( $postdata['post_date'] ); |
5996 |
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
|
5997 |
$post_modified = $this->_convert_date( $postdata['post_modified'] ); |
|
0 | 5998 |
$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); |
5999 |
||
6000 |
$categories = array(); |
|
9 | 6001 |
$catids = wp_get_post_categories( $post_ID ); |
6002 |
foreach ( $catids as $catid ) { |
|
6003 |
$categories[] = get_cat_name( $catid ); |
|
6004 |
} |
|
0 | 6005 |
|
6006 |
$tagnames = array(); |
|
9 | 6007 |
$tags = wp_get_post_tags( $post_ID ); |
6008 |
if ( ! empty( $tags ) ) { |
|
6009 |
foreach ( $tags as $tag ) { |
|
0 | 6010 |
$tagnames[] = $tag->name; |
9 | 6011 |
} |
0 | 6012 |
$tagnames = implode( ', ', $tagnames ); |
6013 |
} else { |
|
6014 |
$tagnames = ''; |
|
6015 |
} |
|
6016 |
||
9 | 6017 |
$post = get_extended( $postdata['post_content'] ); |
6018 |
$link = get_permalink( $postdata['ID'] ); |
|
0 | 6019 |
|
6020 |
// Get the author info. |
|
9 | 6021 |
$author = get_userdata( $postdata['post_author'] ); |
6022 |
||
16 | 6023 |
$allow_comments = ( 'open' === $postdata['comment_status'] ) ? 1 : 0; |
6024 |
$allow_pings = ( 'open' === $postdata['ping_status'] ) ? 1 : 0; |
|
6025 |
||
6026 |
// Consider future posts as published. |
|
6027 |
if ( 'future' === $postdata['post_status'] ) { |
|
0 | 6028 |
$postdata['post_status'] = 'publish'; |
9 | 6029 |
} |
0 | 6030 |
|
16 | 6031 |
// Get post format. |
0 | 6032 |
$post_format = get_post_format( $post_ID ); |
9 | 6033 |
if ( empty( $post_format ) ) { |
0 | 6034 |
$post_format = 'standard'; |
9 | 6035 |
} |
0 | 6036 |
|
6037 |
$sticky = false; |
|
9 | 6038 |
if ( is_sticky( $post_ID ) ) { |
0 | 6039 |
$sticky = true; |
9 | 6040 |
} |
0 | 6041 |
|
6042 |
$enclosure = array(); |
|
9 | 6043 |
foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) { |
16 | 6044 |
if ( 'enclosure' === $key ) { |
0 | 6045 |
foreach ( (array) $val as $enc ) { |
9 | 6046 |
$encdata = explode( "\n", $enc ); |
6047 |
$enclosure['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
6048 |
$enclosure['length'] = (int) trim( $encdata[1] ); |
|
6049 |
$enclosure['type'] = trim( $encdata[2] ); |
|
0 | 6050 |
break 2; |
6051 |
} |
|
6052 |
} |
|
6053 |
} |
|
6054 |
||
6055 |
$resp = array( |
|
9 | 6056 |
'dateCreated' => $post_date, |
6057 |
'userid' => $postdata['post_author'], |
|
6058 |
'postid' => $postdata['ID'], |
|
6059 |
'description' => $post['main'], |
|
6060 |
'title' => $postdata['post_title'], |
|
6061 |
'link' => $link, |
|
6062 |
'permaLink' => $link, |
|
16 | 6063 |
// Commented out because no other tool seems to use this. |
6064 |
// 'content' => $entry['post_content'], |
|
9 | 6065 |
'categories' => $categories, |
6066 |
'mt_excerpt' => $postdata['post_excerpt'], |
|
6067 |
'mt_text_more' => $post['extended'], |
|
6068 |
'wp_more_text' => $post['more_text'], |
|
6069 |
'mt_allow_comments' => $allow_comments, |
|
6070 |
'mt_allow_pings' => $allow_pings, |
|
6071 |
'mt_keywords' => $tagnames, |
|
6072 |
'wp_slug' => $postdata['post_name'], |
|
6073 |
'wp_password' => $postdata['post_password'], |
|
6074 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6075 |
'wp_author_display_name' => $author->display_name, |
9 | 6076 |
'date_created_gmt' => $post_date_gmt, |
6077 |
'post_status' => $postdata['post_status'], |
|
6078 |
'custom_fields' => $this->get_custom_fields( $post_ID ), |
|
6079 |
'wp_post_format' => $post_format, |
|
6080 |
'sticky' => $sticky, |
|
6081 |
'date_modified' => $post_modified, |
|
6082 |
'date_modified_gmt' => $post_modified_gmt, |
|
0 | 6083 |
); |
6084 |
||
9 | 6085 |
if ( ! empty( $enclosure ) ) { |
6086 |
$resp['enclosure'] = $enclosure; |
|
6087 |
} |
|
0 | 6088 |
|
6089 |
$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] ); |
|
6090 |
||
6091 |
return $resp; |
|
6092 |
} else { |
|
9 | 6093 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
0 | 6094 |
} |
6095 |
} |
|
6096 |
||
6097 |
/** |
|
6098 |
* Retrieve list of recent posts. |
|
6099 |
* |
|
6100 |
* @since 1.5.0 |
|
6101 |
* |
|
16 | 6102 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6103 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6104 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6105 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6106 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6107 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6108 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6109 |
* } |
5 | 6110 |
* @return array|IXR_Error |
0 | 6111 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6112 |
public function mw_getRecentPosts( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6113 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6115 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6116 |
$password = $args[2]; |
9 | 6117 |
if ( isset( $args[3] ) ) { |
0 | 6118 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6119 |
} else { |
0 | 6120 |
$query = array(); |
9 | 6121 |
} |
6122 |
||
16 | 6123 |
$user = $this->login( $username, $password ); |
6124 |
if ( ! $user ) { |
|
0 | 6125 |
return $this->error; |
9 | 6126 |
} |
6127 |
||
6128 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6129 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 6130 |
} |
0 | 6131 |
|
5 | 6132 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6133 |
do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
|
0 | 6134 |
|
6135 |
$posts_list = wp_get_recent_posts( $query ); |
|
6136 |
||
9 | 6137 |
if ( ! $posts_list ) { |
0 | 6138 |
return array(); |
9 | 6139 |
} |
0 | 6140 |
|
5 | 6141 |
$recent_posts = array(); |
9 | 6142 |
foreach ( $posts_list as $entry ) { |
6143 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6144 |
continue; |
9 | 6145 |
} |
6146 |
||
6147 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
6148 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
6149 |
$post_modified = $this->_convert_date( $entry['post_modified'] ); |
|
0 | 6150 |
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] ); |
6151 |
||
6152 |
$categories = array(); |
|
9 | 6153 |
$catids = wp_get_post_categories( $entry['ID'] ); |
6154 |
foreach ( $catids as $catid ) { |
|
6155 |
$categories[] = get_cat_name( $catid ); |
|
6156 |
} |
|
0 | 6157 |
|
6158 |
$tagnames = array(); |
|
9 | 6159 |
$tags = wp_get_post_tags( $entry['ID'] ); |
6160 |
if ( ! empty( $tags ) ) { |
|
0 | 6161 |
foreach ( $tags as $tag ) { |
6162 |
$tagnames[] = $tag->name; |
|
6163 |
} |
|
6164 |
$tagnames = implode( ', ', $tagnames ); |
|
6165 |
} else { |
|
6166 |
$tagnames = ''; |
|
6167 |
} |
|
6168 |
||
9 | 6169 |
$post = get_extended( $entry['post_content'] ); |
6170 |
$link = get_permalink( $entry['ID'] ); |
|
0 | 6171 |
|
6172 |
// Get the post author info. |
|
9 | 6173 |
$author = get_userdata( $entry['post_author'] ); |
6174 |
||
16 | 6175 |
$allow_comments = ( 'open' === $entry['comment_status'] ) ? 1 : 0; |
6176 |
$allow_pings = ( 'open' === $entry['ping_status'] ) ? 1 : 0; |
|
6177 |
||
6178 |
// Consider future posts as published. |
|
6179 |
if ( 'future' === $entry['post_status'] ) { |
|
0 | 6180 |
$entry['post_status'] = 'publish'; |
9 | 6181 |
} |
0 | 6182 |
|
16 | 6183 |
// Get post format. |
0 | 6184 |
$post_format = get_post_format( $entry['ID'] ); |
9 | 6185 |
if ( empty( $post_format ) ) { |
0 | 6186 |
$post_format = 'standard'; |
9 | 6187 |
} |
0 | 6188 |
|
5 | 6189 |
$recent_posts[] = array( |
9 | 6190 |
'dateCreated' => $post_date, |
6191 |
'userid' => $entry['post_author'], |
|
6192 |
'postid' => (string) $entry['ID'], |
|
6193 |
'description' => $post['main'], |
|
6194 |
'title' => $entry['post_title'], |
|
6195 |
'link' => $link, |
|
6196 |
'permaLink' => $link, |
|
16 | 6197 |
// Commented out because no other tool seems to use this. |
0 | 6198 |
// 'content' => $entry['post_content'], |
9 | 6199 |
'categories' => $categories, |
6200 |
'mt_excerpt' => $entry['post_excerpt'], |
|
6201 |
'mt_text_more' => $post['extended'], |
|
6202 |
'wp_more_text' => $post['more_text'], |
|
6203 |
'mt_allow_comments' => $allow_comments, |
|
6204 |
'mt_allow_pings' => $allow_pings, |
|
6205 |
'mt_keywords' => $tagnames, |
|
6206 |
'wp_slug' => $entry['post_name'], |
|
6207 |
'wp_password' => $entry['post_password'], |
|
6208 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6209 |
'wp_author_display_name' => $author->display_name, |
9 | 6210 |
'date_created_gmt' => $post_date_gmt, |
6211 |
'post_status' => $entry['post_status'], |
|
6212 |
'custom_fields' => $this->get_custom_fields( $entry['ID'] ), |
|
6213 |
'wp_post_format' => $post_format, |
|
6214 |
'date_modified' => $post_modified, |
|
6215 |
'date_modified_gmt' => $post_modified_gmt, |
|
16 | 6216 |
'sticky' => ( 'post' === $entry['post_type'] && is_sticky( $entry['ID'] ) ), |
9 | 6217 |
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ), |
0 | 6218 |
); |
6219 |
} |
|
6220 |
||
6221 |
return $recent_posts; |
|
6222 |
} |
|
6223 |
||
6224 |
/** |
|
6225 |
* Retrieve the list of categories on a given blog. |
|
6226 |
* |
|
6227 |
* @since 1.5.0 |
|
6228 |
* |
|
16 | 6229 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6230 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6231 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6232 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6233 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6234 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6235 |
* } |
5 | 6236 |
* @return array|IXR_Error |
0 | 6237 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6238 |
public function mw_getCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6239 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6240 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6241 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6242 |
$password = $args[2]; |
0 | 6243 |
|
16 | 6244 |
$user = $this->login( $username, $password ); |
6245 |
if ( ! $user ) { |
|
0 | 6246 |
return $this->error; |
9 | 6247 |
} |
6248 |
||
6249 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6250 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6251 |
} |
0 | 6252 |
|
5 | 6253 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6254 |
do_action( 'xmlrpc_call', 'metaWeblog.getCategories' ); |
|
0 | 6255 |
|
6256 |
$categories_struct = array(); |
|
6257 |
||
16 | 6258 |
$cats = get_categories( array( 'get' => 'all' ) ); |
6259 |
if ( $cats ) { |
|
0 | 6260 |
foreach ( $cats as $cat ) { |
9 | 6261 |
$struct = array(); |
6262 |
$struct['categoryId'] = $cat->term_id; |
|
6263 |
$struct['parentId'] = $cat->parent; |
|
6264 |
$struct['description'] = $cat->name; |
|
0 | 6265 |
$struct['categoryDescription'] = $cat->description; |
9 | 6266 |
$struct['categoryName'] = $cat->name; |
6267 |
$struct['htmlUrl'] = esc_html( get_category_link( $cat->term_id ) ); |
|
6268 |
$struct['rssUrl'] = esc_html( get_category_feed_link( $cat->term_id, 'rss2' ) ); |
|
0 | 6269 |
|
6270 |
$categories_struct[] = $struct; |
|
6271 |
} |
|
6272 |
} |
|
6273 |
||
6274 |
return $categories_struct; |
|
6275 |
} |
|
6276 |
||
6277 |
/** |
|
6278 |
* Uploads a file, following your settings. |
|
6279 |
* |
|
6280 |
* Adapted from a patch by Johann Richard. |
|
6281 |
* |
|
6282 |
* @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/ |
|
6283 |
* |
|
6284 |
* @since 1.5.0 |
|
6285 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6286 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6287 |
* |
16 | 6288 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6289 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6290 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6291 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6292 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6293 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6294 |
* @type array $data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6295 |
* } |
5 | 6296 |
* @return array|IXR_Error |
0 | 6297 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6298 |
public function mw_newMediaObject( $args ) { |
0 | 6299 |
global $wpdb; |
6300 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6301 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6302 |
$password = $this->escape( $args[2] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6303 |
$data = $args[3]; |
0 | 6304 |
|
6305 |
$name = sanitize_file_name( $data['name'] ); |
|
6306 |
$type = $data['type']; |
|
6307 |
$bits = $data['bits']; |
|
6308 |
||
16 | 6309 |
$user = $this->login( $username, $password ); |
6310 |
if ( ! $user ) { |
|
0 | 6311 |
return $this->error; |
9 | 6312 |
} |
0 | 6313 |
|
5 | 6314 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6315 |
do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' ); |
|
0 | 6316 |
|
9 | 6317 |
if ( ! current_user_can( 'upload_files' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6318 |
$this->error = new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6319 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6320 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6321 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6322 |
if ( is_multisite() && upload_is_user_over_quota( false ) ) { |
9 | 6323 |
$this->error = new IXR_Error( |
6324 |
401, |
|
6325 |
sprintf( |
|
16 | 6326 |
/* translators: %s: Allowed space allocation. */ |
9 | 6327 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
6328 |
size_format( get_space_allowed() * MB_IN_BYTES ) |
|
6329 |
) |
|
6330 |
); |
|
0 | 6331 |
return $this->error; |
6332 |
} |
|
6333 |
||
5 | 6334 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6335 |
* Filters whether to preempt the XML-RPC media upload. |
5 | 6336 |
* |
6337 |
* Passing a truthy value will effectively short-circuit the media upload, |
|
6338 |
* returning that value as a 500 error instead. |
|
6339 |
* |
|
6340 |
* @since 2.1.0 |
|
6341 |
* |
|
6342 |
* @param bool $error Whether to pre-empt the media upload. Default false. |
|
6343 |
*/ |
|
16 | 6344 |
$upload_err = apply_filters( 'pre_upload_error', false ); |
6345 |
if ( $upload_err ) { |
|
5 | 6346 |
return new IXR_Error( 500, $upload_err ); |
6347 |
} |
|
0 | 6348 |
|
9 | 6349 |
$upload = wp_upload_bits( $name, null, $bits ); |
6350 |
if ( ! empty( $upload['error'] ) ) { |
|
16 | 6351 |
/* translators: 1: File name, 2: Error message. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6352 |
$errorString = sprintf( __( 'Could not write file %1$s (%2$s).' ), $name, $upload['error'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6353 |
return new IXR_Error( 500, $errorString ); |
0 | 6354 |
} |
16 | 6355 |
// Construct the attachment array. |
0 | 6356 |
$post_id = 0; |
6357 |
if ( ! empty( $data['post_id'] ) ) { |
|
6358 |
$post_id = (int) $data['post_id']; |
|
6359 |
||
9 | 6360 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6361 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6362 |
} |
0 | 6363 |
} |
6364 |
$attachment = array( |
|
9 | 6365 |
'post_title' => $name, |
6366 |
'post_content' => '', |
|
6367 |
'post_type' => 'attachment', |
|
6368 |
'post_parent' => $post_id, |
|
0 | 6369 |
'post_mime_type' => $type, |
9 | 6370 |
'guid' => $upload['url'], |
0 | 6371 |
); |
6372 |
||
16 | 6373 |
// Save the data. |
9 | 6374 |
$id = wp_insert_attachment( $attachment, $upload['file'], $post_id ); |
0 | 6375 |
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
6376 |
||
5 | 6377 |
/** |
6378 |
* Fires after a new attachment has been added via the XML-RPC MovableType API. |
|
6379 |
* |
|
6380 |
* @since 3.4.0 |
|
6381 |
* |
|
6382 |
* @param int $id ID of the new attachment. |
|
6383 |
* @param array $args An array of arguments to add the attachment. |
|
6384 |
*/ |
|
16 | 6385 |
do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 6386 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6387 |
$struct = $this->_prepare_media_item( get_post( $id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6388 |
|
16 | 6389 |
// Deprecated values. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6390 |
$struct['id'] = $struct['attachment_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6391 |
$struct['file'] = $struct['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6392 |
$struct['url'] = $struct['link']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6393 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6394 |
return $struct; |
0 | 6395 |
} |
6396 |
||
16 | 6397 |
/* |
6398 |
* MovableType API functions. |
|
6399 |
* Specs on http://www.movabletype.org/docs/mtmanual_programmatic.html |
|
0 | 6400 |
*/ |
6401 |
||
6402 |
/** |
|
6403 |
* Retrieve the post titles of recent posts. |
|
6404 |
* |
|
6405 |
* @since 1.5.0 |
|
6406 |
* |
|
16 | 6407 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6408 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6409 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6410 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6411 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6412 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6413 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6414 |
* } |
5 | 6415 |
* @return array|IXR_Error |
0 | 6416 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6417 |
public function mt_getRecentPostTitles( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6418 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6420 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6421 |
$password = $args[2]; |
9 | 6422 |
if ( isset( $args[3] ) ) { |
0 | 6423 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6424 |
} else { |
0 | 6425 |
$query = array(); |
9 | 6426 |
} |
6427 |
||
16 | 6428 |
$user = $this->login( $username, $password ); |
6429 |
if ( ! $user ) { |
|
0 | 6430 |
return $this->error; |
9 | 6431 |
} |
0 | 6432 |
|
5 | 6433 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6434 |
do_action( 'xmlrpc_call', 'mt.getRecentPostTitles' ); |
|
0 | 6435 |
|
6436 |
$posts_list = wp_get_recent_posts( $query ); |
|
6437 |
||
9 | 6438 |
if ( ! $posts_list ) { |
6439 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 6440 |
return $this->error; |
6441 |
} |
|
6442 |
||
5 | 6443 |
$recent_posts = array(); |
0 | 6444 |
|
9 | 6445 |
foreach ( $posts_list as $entry ) { |
6446 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6447 |
continue; |
9 | 6448 |
} |
6449 |
||
6450 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
0 | 6451 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
6452 |
||
5 | 6453 |
$recent_posts[] = array( |
9 | 6454 |
'dateCreated' => $post_date, |
6455 |
'userid' => $entry['post_author'], |
|
6456 |
'postid' => (string) $entry['ID'], |
|
6457 |
'title' => $entry['post_title'], |
|
6458 |
'post_status' => $entry['post_status'], |
|
6459 |
'date_created_gmt' => $post_date_gmt, |
|
0 | 6460 |
); |
6461 |
} |
|
6462 |
||
6463 |
return $recent_posts; |
|
6464 |
} |
|
6465 |
||
6466 |
/** |
|
6467 |
* Retrieve list of all categories on blog. |
|
6468 |
* |
|
6469 |
* @since 1.5.0 |
|
6470 |
* |
|
16 | 6471 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6472 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6473 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6474 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6475 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6476 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6477 |
* } |
5 | 6478 |
* @return array|IXR_Error |
0 | 6479 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6480 |
public function mt_getCategoryList( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6481 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6482 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6483 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6484 |
$password = $args[2]; |
0 | 6485 |
|
16 | 6486 |
$user = $this->login( $username, $password ); |
6487 |
if ( ! $user ) { |
|
0 | 6488 |
return $this->error; |
9 | 6489 |
} |
6490 |
||
6491 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6492 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6493 |
} |
0 | 6494 |
|
5 | 6495 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6496 |
do_action( 'xmlrpc_call', 'mt.getCategoryList' ); |
|
0 | 6497 |
|
6498 |
$categories_struct = array(); |
|
6499 |
||
16 | 6500 |
$cats = get_categories( |
9 | 6501 |
array( |
6502 |
'hide_empty' => 0, |
|
6503 |
'hierarchical' => 0, |
|
6504 |
) |
|
16 | 6505 |
); |
6506 |
if ( $cats ) { |
|
0 | 6507 |
foreach ( $cats as $cat ) { |
9 | 6508 |
$struct = array(); |
6509 |
$struct['categoryId'] = $cat->term_id; |
|
0 | 6510 |
$struct['categoryName'] = $cat->name; |
6511 |
||
6512 |
$categories_struct[] = $struct; |
|
6513 |
} |
|
6514 |
} |
|
6515 |
||
6516 |
return $categories_struct; |
|
6517 |
} |
|
6518 |
||
6519 |
/** |
|
6520 |
* Retrieve post categories. |
|
6521 |
* |
|
6522 |
* @since 1.5.0 |
|
6523 |
* |
|
16 | 6524 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6525 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6527 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6528 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6529 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6530 |
* } |
5 | 6531 |
* @return array|IXR_Error |
0 | 6532 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6533 |
public function mt_getPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6534 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6535 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6536 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6537 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6538 |
$password = $args[2]; |
0 | 6539 |
|
16 | 6540 |
$user = $this->login( $username, $password ); |
6541 |
if ( ! $user ) { |
|
0 | 6542 |
return $this->error; |
9 | 6543 |
} |
6544 |
||
6545 |
if ( ! get_post( $post_ID ) ) { |
|
0 | 6546 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6547 |
} |
6548 |
||
6549 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6550 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6551 |
} |
0 | 6552 |
|
5 | 6553 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6554 |
do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
|
0 | 6555 |
|
6556 |
$categories = array(); |
|
9 | 6557 |
$catids = wp_get_post_categories( intval( $post_ID ) ); |
16 | 6558 |
// First listed category will be the primary category. |
0 | 6559 |
$isPrimary = true; |
6560 |
foreach ( $catids as $catid ) { |
|
6561 |
$categories[] = array( |
|
9 | 6562 |
'categoryName' => get_cat_name( $catid ), |
6563 |
'categoryId' => (string) $catid, |
|
6564 |
'isPrimary' => $isPrimary, |
|
0 | 6565 |
); |
9 | 6566 |
$isPrimary = false; |
0 | 6567 |
} |
6568 |
||
6569 |
return $categories; |
|
6570 |
} |
|
6571 |
||
6572 |
/** |
|
6573 |
* Sets categories for a post. |
|
6574 |
* |
|
6575 |
* @since 1.5.0 |
|
6576 |
* |
|
16 | 6577 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6578 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6579 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6580 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6581 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6582 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6583 |
* @type array $categories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6584 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6585 |
* @return true|IXR_Error True on success. |
0 | 6586 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6587 |
public function mt_setPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6588 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6590 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6591 |
$username = $args[1]; |
0 | 6592 |
$password = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6593 |
$categories = $args[3]; |
0 | 6594 |
|
16 | 6595 |
$user = $this->login( $username, $password ); |
6596 |
if ( ! $user ) { |
|
0 | 6597 |
return $this->error; |
9 | 6598 |
} |
0 | 6599 |
|
5 | 6600 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6601 |
do_action( 'xmlrpc_call', 'mt.setPostCategories' ); |
|
0 | 6602 |
|
9 | 6603 |
if ( ! get_post( $post_ID ) ) { |
0 | 6604 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6605 |
} |
6606 |
||
6607 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6608 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
|
6609 |
} |
|
0 | 6610 |
|
6611 |
$catids = array(); |
|
6612 |
foreach ( $categories as $cat ) { |
|
6613 |
$catids[] = $cat['categoryId']; |
|
6614 |
} |
|
6615 |
||
9 | 6616 |
wp_set_post_categories( $post_ID, $catids ); |
0 | 6617 |
|
6618 |
return true; |
|
6619 |
} |
|
6620 |
||
6621 |
/** |
|
6622 |
* Retrieve an array of methods supported by this server. |
|
6623 |
* |
|
6624 |
* @since 1.5.0 |
|
6625 |
* |
|
6626 |
* @return array |
|
6627 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6628 |
public function mt_supportedMethods() { |
5 | 6629 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6630 |
do_action( 'xmlrpc_call', 'mt.supportedMethods' ); |
|
0 | 6631 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6632 |
return array_keys( $this->methods ); |
0 | 6633 |
} |
6634 |
||
6635 |
/** |
|
6636 |
* Retrieve an empty array because we don't support per-post text filters. |
|
6637 |
* |
|
6638 |
* @since 1.5.0 |
|
6639 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6640 |
public function mt_supportedTextFilters() { |
5 | 6641 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6642 |
do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
|
6643 |
||
6644 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6645 |
* Filters the MoveableType text filters list for XML-RPC. |
5 | 6646 |
* |
6647 |
* @since 2.2.0 |
|
6648 |
* |
|
6649 |
* @param array $filters An array of text filters. |
|
6650 |
*/ |
|
6651 |
return apply_filters( 'xmlrpc_text_filters', array() ); |
|
0 | 6652 |
} |
6653 |
||
6654 |
/** |
|
6655 |
* Retrieve trackbacks sent to a given post. |
|
6656 |
* |
|
6657 |
* @since 1.5.0 |
|
6658 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6659 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6660 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6661 |
* @param int $post_ID |
5 | 6662 |
* @return array|IXR_Error |
0 | 6663 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6664 |
public function mt_getTrackbackPings( $post_ID ) { |
0 | 6665 |
global $wpdb; |
6666 |
||
5 | 6667 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6668 |
do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); |
|
0 | 6669 |
|
9 | 6670 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
6671 |
||
6672 |
if ( ! $actual_post ) { |
|
6673 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
6674 |
} |
|
6675 |
||
6676 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) ); |
|
6677 |
||
6678 |
if ( ! $comments ) { |
|
0 | 6679 |
return array(); |
9 | 6680 |
} |
0 | 6681 |
|
6682 |
$trackback_pings = array(); |
|
6683 |
foreach ( $comments as $comment ) { |
|
16 | 6684 |
if ( 'trackback' === $comment->comment_type ) { |
9 | 6685 |
$content = $comment->comment_content; |
6686 |
$title = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) ); |
|
0 | 6687 |
$trackback_pings[] = array( |
6688 |
'pingTitle' => $title, |
|
6689 |
'pingURL' => $comment->comment_author_url, |
|
9 | 6690 |
'pingIP' => $comment->comment_author_IP, |
0 | 6691 |
); |
6692 |
} |
|
6693 |
} |
|
6694 |
||
6695 |
return $trackback_pings; |
|
6696 |
} |
|
6697 |
||
6698 |
/** |
|
6699 |
* Sets a post's publish status to 'publish'. |
|
6700 |
* |
|
6701 |
* @since 1.5.0 |
|
6702 |
* |
|
16 | 6703 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6704 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6705 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6706 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6707 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6708 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6709 |
* } |
5 | 6710 |
* @return int|IXR_Error |
0 | 6711 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6712 |
public function mt_publishPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6713 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6714 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6715 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6716 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6717 |
$password = $args[2]; |
0 | 6718 |
|
16 | 6719 |
$user = $this->login( $username, $password ); |
6720 |
if ( ! $user ) { |
|
0 | 6721 |
return $this->error; |
9 | 6722 |
} |
0 | 6723 |
|
5 | 6724 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6725 |
do_action( 'xmlrpc_call', 'mt.publishPost' ); |
|
0 | 6726 |
|
9 | 6727 |
$postdata = get_post( $post_ID, ARRAY_A ); |
6728 |
if ( ! $postdata ) { |
|
0 | 6729 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6730 |
} |
6731 |
||
6732 |
if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6733 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
|
6734 |
} |
|
0 | 6735 |
|
6736 |
$postdata['post_status'] = 'publish'; |
|
6737 |
||
16 | 6738 |
// Retain old categories. |
6739 |
$postdata['post_category'] = wp_get_post_categories( $post_ID ); |
|
9 | 6740 |
$this->escape( $postdata ); |
0 | 6741 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6742 |
return wp_update_post( $postdata ); |
0 | 6743 |
} |
6744 |
||
16 | 6745 |
/* |
6746 |
* Pingback functions. |
|
6747 |
* Specs on www.hixie.ch/specs/pingback/pingback |
|
0 | 6748 |
*/ |
6749 |
||
6750 |
/** |
|
6751 |
* Retrieves a pingback and registers it. |
|
6752 |
* |
|
6753 |
* @since 1.5.0 |
|
6754 |
* |
|
16 | 6755 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6756 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6757 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6758 |
* @type string $pagelinkedfrom |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6759 |
* @type string $pagelinkedto |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6760 |
* } |
5 | 6761 |
* @return string|IXR_Error |
0 | 6762 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6763 |
public function pingback_ping( $args ) { |
0 | 6764 |
global $wpdb; |
6765 |
||
5 | 6766 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6767 |
do_action( 'xmlrpc_call', 'pingback.ping' ); |
|
0 | 6768 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6769 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6770 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6771 |
$pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
9 | 6772 |
$pagelinkedto = str_replace( '&', '&', $args[1] ); |
6773 |
$pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
|
0 | 6774 |
|
5 | 6775 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6776 |
* Filters the pingback source URI. |
5 | 6777 |
* |
6778 |
* @since 3.6.0 |
|
6779 |
* |
|
6780 |
* @param string $pagelinkedfrom URI of the page linked from. |
|
6781 |
* @param string $pagelinkedto URI of the page linked to. |
|
6782 |
*/ |
|
0 | 6783 |
$pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5 | 6784 |
|
9 | 6785 |
if ( ! $pagelinkedfrom ) { |
0 | 6786 |
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
9 | 6787 |
} |
0 | 6788 |
|
16 | 6789 |
// Check if the page linked to is on our site. |
9 | 6790 |
$pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) ); |
6791 |
if ( ! $pos1 ) { |
|
0 | 6792 |
return $this->pingback_error( 0, __( 'Is there no link to us?' ) ); |
9 | 6793 |
} |
0 | 6794 |
|
16 | 6795 |
/* |
6796 |
* Let's find which post is linked to. |
|
6797 |
* FIXME: Does url_to_postid() cover all these cases already? |
|
6798 |
* If so, then let's use it and drop the old code. |
|
6799 |
*/ |
|
9 | 6800 |
$urltest = parse_url( $pagelinkedto ); |
16 | 6801 |
$post_ID = url_to_postid( $pagelinkedto ); |
6802 |
if ( $post_ID ) { |
|
5 | 6803 |
// $way |
9 | 6804 |
} elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) { |
16 | 6805 |
// The path defines the post_ID (archives/p/XXXX). |
9 | 6806 |
$blah = explode( '/', $match[0] ); |
0 | 6807 |
$post_ID = (int) $blah[1]; |
9 | 6808 |
} elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) { |
16 | 6809 |
// The query string defines the post_ID (?p=XXXX). |
9 | 6810 |
$blah = explode( '=', $match[0] ); |
0 | 6811 |
$post_ID = (int) $blah[1]; |
9 | 6812 |
} elseif ( isset( $urltest['fragment'] ) ) { |
16 | 6813 |
// An #anchor is there, it's either... |
9 | 6814 |
if ( intval( $urltest['fragment'] ) ) { |
16 | 6815 |
// ...an integer #XXXX (simplest case), |
0 | 6816 |
$post_ID = (int) $urltest['fragment']; |
9 | 6817 |
} elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
16 | 6818 |
// ...a post ID in the form 'post-###', |
9 | 6819 |
$post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
6820 |
} elseif ( is_string( $urltest['fragment'] ) ) { |
|
16 | 6821 |
// ...or a string #title, a little more complicated. |
6822 |
$title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] ); |
|
6823 |
$sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
|
6824 |
$post_ID = $wpdb->get_var( $sql ); |
|
6825 |
if ( ! $post_ID ) { |
|
6826 |
// Returning unknown error '0' is better than die()'ing. |
|
9 | 6827 |
return $this->pingback_error( 0, '' ); |
0 | 6828 |
} |
6829 |
} |
|
6830 |
} else { |
|
16 | 6831 |
// TODO: Attempt to extract a post ID from the given URL. |
9 | 6832 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
0 | 6833 |
} |
6834 |
$post_ID = (int) $post_ID; |
|
6835 |
||
9 | 6836 |
$post = get_post( $post_ID ); |
6837 |
||
16 | 6838 |
if ( ! $post ) { // Post not found. |
9 | 6839 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
6840 |
} |
|
6841 |
||
16 | 6842 |
if ( url_to_postid( $pagelinkedfrom ) == $post_ID ) { |
0 | 6843 |
return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); |
9 | 6844 |
} |
0 | 6845 |
|
16 | 6846 |
// Check if pings are on. |
9 | 6847 |
if ( ! pings_open( $post ) ) { |
6848 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
|
6849 |
} |
|
0 | 6850 |
|
16 | 6851 |
// Let's check that the remote site didn't already pingback this entry. |
9 | 6852 |
if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom ) ) ) { |
0 | 6853 |
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
9 | 6854 |
} |
0 | 6855 |
|
16 | 6856 |
// Very stupid, but gives time to the 'from' server to publish! |
9 | 6857 |
sleep( 1 ); |
0 | 6858 |
|
5 | 6859 |
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
6860 |
||
6861 |
/** This filter is documented in wp-includes/class-http.php */ |
|
16 | 6862 |
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $pagelinkedfrom ); |
6863 |
||
6864 |
// Let's check the remote site. |
|
0 | 6865 |
$http_api_args = array( |
9 | 6866 |
'timeout' => 10, |
6867 |
'redirection' => 0, |
|
0 | 6868 |
'limit_response_size' => 153600, // 150 KB |
9 | 6869 |
'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
6870 |
'headers' => array( |
|
5 | 6871 |
'X-Pingback-Forwarded-For' => $remote_ip, |
6872 |
), |
|
0 | 6873 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6874 |
|
16 | 6875 |
$request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
6876 |
$remote_source = wp_remote_retrieve_body( $request ); |
|
6877 |
$remote_source_original = $remote_source; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6878 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6879 |
if ( ! $remote_source ) { |
5 | 6880 |
return $this->pingback_error( 16, __( 'The source URL does not exist.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6881 |
} |
5 | 6882 |
|
6883 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6884 |
* Filters the pingback remote source. |
5 | 6885 |
* |
6886 |
* @since 2.5.0 |
|
6887 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6888 |
* @param string $remote_source Response source for the page linked from. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6889 |
* @param string $pagelinkedto URL of the page linked to. |
5 | 6890 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6891 |
$remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
0 | 6892 |
|
6893 |
// Work around bug in strip_tags(): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6894 |
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6895 |
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
9 | 6896 |
$remote_source = preg_replace( '/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/', "\n\n", $remote_source ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6897 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6898 |
preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6899 |
$title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6900 |
if ( empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6901 |
return $this->pingback_error( 32, __( 'We cannot find a title on that page.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6902 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6903 |
|
16 | 6904 |
// Remove all script and style tags including their content. |
6905 |
$remote_source = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $remote_source ); |
|
6906 |
// Just keep the tag we need. |
|
6907 |
$remote_source = strip_tags( $remote_source, '<a>' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6908 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6909 |
$p = explode( "\n\n", $remote_source ); |
0 | 6910 |
|
9 | 6911 |
$preg_target = preg_quote( $pagelinkedto, '|' ); |
0 | 6912 |
|
6913 |
foreach ( $p as $para ) { |
|
16 | 6914 |
if ( strpos( $para, $pagelinkedto ) !== false ) { // It exists, but is it a link? |
9 | 6915 |
preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context ); |
0 | 6916 |
|
16 | 6917 |
// If the URL isn't in a link context, keep looking. |
9 | 6918 |
if ( empty( $context ) ) { |
0 | 6919 |
continue; |
9 | 6920 |
} |
0 | 6921 |
|
16 | 6922 |
// We're going to use this fake tag to mark the context in a bit. |
6923 |
// The marker is needed in case the link text appears more than once in the paragraph. |
|
9 | 6924 |
$excerpt = preg_replace( '|\</?wpcontext\>|', '', $para ); |
0 | 6925 |
|
6926 |
// prevent really long link text |
|
9 | 6927 |
if ( strlen( $context[1] ) > 100 ) { |
6928 |
$context[1] = substr( $context[1], 0, 100 ) . '…'; |
|
6929 |
} |
|
6930 |
||
16 | 6931 |
$marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // Set up our marker. |
6932 |
$excerpt = str_replace( $context[0], $marker, $excerpt ); // Swap out the link for our marker. |
|
6933 |
$excerpt = strip_tags( $excerpt, '<wpcontext>' ); // Strip all tags but our context marker. |
|
9 | 6934 |
$excerpt = trim( $excerpt ); |
6935 |
$preg_marker = preg_quote( $marker, '|' ); |
|
6936 |
$excerpt = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt ); |
|
16 | 6937 |
$excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper. |
0 | 6938 |
break; |
6939 |
} |
|
6940 |
} |
|
6941 |
||
16 | 6942 |
if ( empty( $context ) ) { // Link to target not found. |
0 | 6943 |
return $this->pingback_error( 17, __( 'The source URL does not contain a link to the target URL, and so cannot be used as a source.' ) ); |
9 | 6944 |
} |
6945 |
||
6946 |
$pagelinkedfrom = str_replace( '&', '&', $pagelinkedfrom ); |
|
6947 |
||
6948 |
$context = '[…] ' . esc_html( $excerpt ) . ' […]'; |
|
0 | 6949 |
$pagelinkedfrom = $this->escape( $pagelinkedfrom ); |
6950 |
||
9 | 6951 |
$comment_post_ID = (int) $post_ID; |
6952 |
$comment_author = $title; |
|
0 | 6953 |
$comment_author_email = ''; |
9 | 6954 |
$this->escape( $comment_author ); |
0 | 6955 |
$comment_author_url = $pagelinkedfrom; |
9 | 6956 |
$comment_content = $context; |
6957 |
$this->escape( $comment_content ); |
|
0 | 6958 |
$comment_type = 'pingback'; |
6959 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6960 |
$commentdata = compact( |
9 | 6961 |
'comment_post_ID', |
6962 |
'comment_author', |
|
6963 |
'comment_author_url', |
|
6964 |
'comment_author_email', |
|
6965 |
'comment_content', |
|
6966 |
'comment_type', |
|
6967 |
'remote_source', |
|
6968 |
'remote_source_original' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6969 |
); |
0 | 6970 |
|
9 | 6971 |
$comment_ID = wp_new_comment( $commentdata ); |
5 | 6972 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6973 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6974 |
return $this->pingback_error( 0, $comment_ID->get_error_message() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6975 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6976 |
|
5 | 6977 |
/** |
6978 |
* Fires after a post pingback has been sent. |
|
6979 |
* |
|
6980 |
* @since 0.71 |
|
6981 |
* |
|
6982 |
* @param int $comment_ID Comment ID. |
|
6983 |
*/ |
|
6984 |
do_action( 'pingback_post', $comment_ID ); |
|
0 | 6985 |
|
16 | 6986 |
/* translators: 1: URL of the page linked from, 2: URL of the page linked to. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6987 |
return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
0 | 6988 |
} |
6989 |
||
6990 |
/** |
|
6991 |
* Retrieve array of URLs that pingbacked the given URL. |
|
6992 |
* |
|
6993 |
* Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
|
6994 |
* |
|
6995 |
* @since 1.5.0 |
|
6996 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6997 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6998 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6999 |
* @param string $url |
5 | 7000 |
* @return array|IXR_Error |
0 | 7001 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7002 |
public function pingback_extensions_getPingbacks( $url ) { |
0 | 7003 |
global $wpdb; |
7004 |
||
5 | 7005 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
7006 |
do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
|
0 | 7007 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7008 |
$url = $this->escape( $url ); |
0 | 7009 |
|
9 | 7010 |
$post_ID = url_to_postid( $url ); |
7011 |
if ( ! $post_ID ) { |
|
16 | 7012 |
// We aren't sure that the resource is available and/or pingback enabled. |
9 | 7013 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
7014 |
} |
|
7015 |
||
7016 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
7017 |
||
7018 |
if ( ! $actual_post ) { |
|
16 | 7019 |
// No such post = resource not found. |
9 | 7020 |
return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) ); |
7021 |
} |
|
7022 |
||
7023 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) ); |
|
7024 |
||
7025 |
if ( ! $comments ) { |
|
0 | 7026 |
return array(); |
9 | 7027 |
} |
0 | 7028 |
|
7029 |
$pingbacks = array(); |
|
7030 |
foreach ( $comments as $comment ) { |
|
16 | 7031 |
if ( 'pingback' === $comment->comment_type ) { |
0 | 7032 |
$pingbacks[] = $comment->comment_author_url; |
9 | 7033 |
} |
0 | 7034 |
} |
7035 |
||
7036 |
return $pingbacks; |
|
7037 |
} |
|
7038 |
||
5 | 7039 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7040 |
* Sends a pingback error based on the given error code and message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7041 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7042 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7043 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7044 |
* @param int $code Error code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7045 |
* @param string $message Error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7046 |
* @return IXR_Error Error object. |
5 | 7047 |
*/ |
0 | 7048 |
protected function pingback_error( $code, $message ) { |
5 | 7049 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7050 |
* Filters the XML-RPC pingback error return. |
5 | 7051 |
* |
7052 |
* @since 3.5.1 |
|
7053 |
* |
|
7054 |
* @param IXR_Error $error An IXR_Error object containing the error code and message. |
|
7055 |
*/ |
|
0 | 7056 |
return apply_filters( 'xmlrpc_pingback_error', new IXR_Error( $code, $message ) ); |
7057 |
} |
|
7058 |
} |