author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
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 |
|
18 | 17 |
* via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::set_is_enabled(). |
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 |
/** |
18 | 53 |
* Flags that XML-RPC is enabled |
54 |
* |
|
55 |
* @var bool |
|
56 |
*/ |
|
57 |
private $is_enabled; |
|
58 |
||
59 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* Registers all of the XMLRPC methods that XMLRPC server understands. |
0 | 61 |
* |
62 |
* Sets up server and method property. Passes XMLRPC |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* 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
|
64 |
* or replace XML-RPC methods. |
0 | 65 |
* |
66 |
* @since 1.5.0 |
|
67 |
*/ |
|
5 | 68 |
public function __construct() { |
0 | 69 |
$this->methods = array( |
16 | 70 |
// WordPress API. |
9 | 71 |
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', |
72 |
'wp.newPost' => 'this:wp_newPost', |
|
73 |
'wp.editPost' => 'this:wp_editPost', |
|
74 |
'wp.deletePost' => 'this:wp_deletePost', |
|
75 |
'wp.getPost' => 'this:wp_getPost', |
|
76 |
'wp.getPosts' => 'this:wp_getPosts', |
|
77 |
'wp.newTerm' => 'this:wp_newTerm', |
|
78 |
'wp.editTerm' => 'this:wp_editTerm', |
|
79 |
'wp.deleteTerm' => 'this:wp_deleteTerm', |
|
80 |
'wp.getTerm' => 'this:wp_getTerm', |
|
81 |
'wp.getTerms' => 'this:wp_getTerms', |
|
82 |
'wp.getTaxonomy' => 'this:wp_getTaxonomy', |
|
83 |
'wp.getTaxonomies' => 'this:wp_getTaxonomies', |
|
84 |
'wp.getUser' => 'this:wp_getUser', |
|
85 |
'wp.getUsers' => 'this:wp_getUsers', |
|
86 |
'wp.getProfile' => 'this:wp_getProfile', |
|
87 |
'wp.editProfile' => 'this:wp_editProfile', |
|
88 |
'wp.getPage' => 'this:wp_getPage', |
|
89 |
'wp.getPages' => 'this:wp_getPages', |
|
90 |
'wp.newPage' => 'this:wp_newPage', |
|
91 |
'wp.deletePage' => 'this:wp_deletePage', |
|
92 |
'wp.editPage' => 'this:wp_editPage', |
|
93 |
'wp.getPageList' => 'this:wp_getPageList', |
|
94 |
'wp.getAuthors' => 'this:wp_getAuthors', |
|
16 | 95 |
'wp.getCategories' => 'this:mw_getCategories', // Alias. |
9 | 96 |
'wp.getTags' => 'this:wp_getTags', |
97 |
'wp.newCategory' => 'this:wp_newCategory', |
|
98 |
'wp.deleteCategory' => 'this:wp_deleteCategory', |
|
99 |
'wp.suggestCategories' => 'this:wp_suggestCategories', |
|
16 | 100 |
'wp.uploadFile' => 'this:mw_newMediaObject', // Alias. |
101 |
'wp.deleteFile' => 'this:wp_deletePost', // Alias. |
|
9 | 102 |
'wp.getCommentCount' => 'this:wp_getCommentCount', |
103 |
'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
|
104 |
'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
|
105 |
'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
|
106 |
'wp.getOptions' => 'this:wp_getOptions', |
|
107 |
'wp.setOptions' => 'this:wp_setOptions', |
|
108 |
'wp.getComment' => 'this:wp_getComment', |
|
109 |
'wp.getComments' => 'this:wp_getComments', |
|
110 |
'wp.deleteComment' => 'this:wp_deleteComment', |
|
111 |
'wp.editComment' => 'this:wp_editComment', |
|
112 |
'wp.newComment' => 'this:wp_newComment', |
|
113 |
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', |
|
114 |
'wp.getMediaItem' => 'this:wp_getMediaItem', |
|
115 |
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', |
|
116 |
'wp.getPostFormats' => 'this:wp_getPostFormats', |
|
117 |
'wp.getPostType' => 'this:wp_getPostType', |
|
118 |
'wp.getPostTypes' => 'this:wp_getPostTypes', |
|
119 |
'wp.getRevisions' => 'this:wp_getRevisions', |
|
120 |
'wp.restoreRevision' => 'this:wp_restoreRevision', |
|
0 | 121 |
|
16 | 122 |
// Blogger API. |
9 | 123 |
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
124 |
'blogger.getUserInfo' => 'this:blogger_getUserInfo', |
|
125 |
'blogger.getPost' => 'this:blogger_getPost', |
|
126 |
'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', |
|
127 |
'blogger.newPost' => 'this:blogger_newPost', |
|
128 |
'blogger.editPost' => 'this:blogger_editPost', |
|
129 |
'blogger.deletePost' => 'this:blogger_deletePost', |
|
0 | 130 |
|
16 | 131 |
// MetaWeblog API (with MT extensions to structs). |
9 | 132 |
'metaWeblog.newPost' => 'this:mw_newPost', |
133 |
'metaWeblog.editPost' => 'this:mw_editPost', |
|
134 |
'metaWeblog.getPost' => 'this:mw_getPost', |
|
135 |
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', |
|
136 |
'metaWeblog.getCategories' => 'this:mw_getCategories', |
|
137 |
'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', |
|
0 | 138 |
|
16 | 139 |
// MetaWeblog API aliases for Blogger API. |
140 |
// See http://www.xmlrpc.com/stories/storyReader$2460 |
|
9 | 141 |
'metaWeblog.deletePost' => 'this:blogger_deletePost', |
142 |
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|
0 | 143 |
|
16 | 144 |
// MovableType API. |
9 | 145 |
'mt.getCategoryList' => 'this:mt_getCategoryList', |
146 |
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', |
|
147 |
'mt.getPostCategories' => 'this:mt_getPostCategories', |
|
148 |
'mt.setPostCategories' => 'this:mt_setPostCategories', |
|
149 |
'mt.supportedMethods' => 'this:mt_supportedMethods', |
|
150 |
'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', |
|
151 |
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', |
|
152 |
'mt.publishPost' => 'this:mt_publishPost', |
|
0 | 153 |
|
16 | 154 |
// Pingback. |
9 | 155 |
'pingback.ping' => 'this:pingback_ping', |
0 | 156 |
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', |
157 |
||
9 | 158 |
'demo.sayHello' => 'this:sayHello', |
159 |
'demo.addTwoNumbers' => 'this:addTwoNumbers', |
|
0 | 160 |
); |
161 |
||
162 |
$this->initialise_blog_option_info(); |
|
5 | 163 |
|
164 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* Filters the methods exposed by the XML-RPC server. |
5 | 166 |
* |
167 |
* This filter can be used to add new methods, and remove built-in methods. |
|
168 |
* |
|
169 |
* @since 1.5.0 |
|
170 |
* |
|
16 | 171 |
* @param string[] $methods An array of XML-RPC methods, keyed by their methodName. |
5 | 172 |
*/ |
173 |
$this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
|
18 | 174 |
|
175 |
$this->set_is_enabled(); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Set wp_xmlrpc_server::$is_enabled property. |
|
180 |
* |
|
181 |
* Determine whether the xmlrpc server is enabled on this WordPress install |
|
182 |
* and set the is_enabled property accordingly. |
|
183 |
* |
|
184 |
* @since 5.7.3 |
|
185 |
*/ |
|
186 |
private function set_is_enabled() { |
|
187 |
/* |
|
188 |
* Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
|
189 |
* option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
|
190 |
*/ |
|
191 |
$is_enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
|
192 |
if ( false === $is_enabled ) { |
|
193 |
$is_enabled = apply_filters( 'option_enable_xmlrpc', true ); |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Filters whether XML-RPC methods requiring authentication are enabled. |
|
198 |
* |
|
199 |
* Contrary to the way it's named, this filter does not control whether XML-RPC is *fully* |
|
200 |
* enabled, rather, it only controls whether XML-RPC methods requiring authentication - such |
|
201 |
* as for publishing purposes - are enabled. |
|
202 |
* |
|
203 |
* Further, the filter does not control whether pingbacks or other custom endpoints that don't |
|
204 |
* require authentication are enabled. This behavior is expected, and due to how parity was matched |
|
205 |
* with the `enable_xmlrpc` UI option the filter replaced when it was introduced in 3.5. |
|
206 |
* |
|
207 |
* To disable XML-RPC methods that require authentication, use: |
|
208 |
* |
|
209 |
* add_filter( 'xmlrpc_enabled', '__return_false' ); |
|
210 |
* |
|
211 |
* For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
|
212 |
* and {@see 'xmlrpc_element_limit'} hooks. |
|
213 |
* |
|
214 |
* @since 3.5.0 |
|
215 |
* |
|
216 |
* @param bool $is_enabled Whether XML-RPC is enabled. Default true. |
|
217 |
*/ |
|
218 |
$this->is_enabled = apply_filters( 'xmlrpc_enabled', $is_enabled ); |
|
0 | 219 |
} |
220 |
||
5 | 221 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* Make private/protected methods readable for backward compatibility. |
5 | 223 |
* |
224 |
* @since 4.0.0 |
|
225 |
* |
|
16 | 226 |
* @param string $name Method to call. |
227 |
* @param array $arguments Arguments to pass when calling. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
* @return array|IXR_Error|false Return value of the callback, false otherwise. |
5 | 229 |
*/ |
230 |
public function __call( $name, $arguments ) { |
|
231 |
if ( '_multisite_getUsersBlogs' === $name ) { |
|
16 | 232 |
return $this->_multisite_getUsersBlogs( ...$arguments ); |
5 | 233 |
} |
234 |
return false; |
|
235 |
} |
|
236 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* Serves the XML-RPC request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
*/ |
5 | 242 |
public function serve_request() { |
9 | 243 |
$this->IXR_Server( $this->methods ); |
0 | 244 |
} |
245 |
||
246 |
/** |
|
247 |
* Test XMLRPC API by saying, "Hello!" to client. |
|
248 |
* |
|
249 |
* @since 1.5.0 |
|
250 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @return string Hello string response. |
0 | 252 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
public function sayHello() { |
0 | 254 |
return 'Hello!'; |
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Test XMLRPC API by adding two numbers for client. |
|
259 |
* |
|
260 |
* @since 1.5.0 |
|
261 |
* |
|
16 | 262 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @type int $number1 A number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
* @type int $number2 A second number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @return int Sum of the two given numbers. |
0 | 269 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
public function addTwoNumbers( $args ) { |
0 | 271 |
$number1 = $args[0]; |
272 |
$number2 = $args[1]; |
|
273 |
return $number1 + $number2; |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Log user in. |
|
278 |
* |
|
279 |
* @since 2.8.0 |
|
280 |
* |
|
281 |
* @param string $username User's username. |
|
282 |
* @param string $password User's password. |
|
18 | 283 |
* @return WP_User|false WP_User object if authentication passed, false otherwise |
0 | 284 |
*/ |
5 | 285 |
public function login( $username, $password ) { |
18 | 286 |
if ( ! $this->is_enabled ) { |
0 | 287 |
$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
288 |
return false; |
|
289 |
} |
|
290 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
if ( $this->auth_failed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
$user = new WP_Error( 'login_prevented' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
$user = wp_authenticate( $username, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
if ( is_wp_error( $user ) ) { |
0 | 298 |
$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) ); |
5 | 299 |
|
16 | 300 |
// 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
|
301 |
$this->auth_failed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
|
5 | 303 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* Filters the XML-RPC user login error message. |
5 | 305 |
* |
306 |
* @since 3.5.0 |
|
307 |
* |
|
18 | 308 |
* @param IXR_Error $error The XML-RPC error message. |
309 |
* @param WP_Error $user WP_Error object. |
|
5 | 310 |
*/ |
0 | 311 |
$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user ); |
312 |
return false; |
|
313 |
} |
|
314 |
||
315 |
wp_set_current_user( $user->ID ); |
|
316 |
return $user; |
|
317 |
} |
|
318 |
||
319 |
/** |
|
320 |
* Check user's credentials. Deprecated. |
|
321 |
* |
|
322 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* @deprecated 2.8.0 Use wp_xmlrpc_server::login() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* @see wp_xmlrpc_server::login() |
0 | 325 |
* |
326 |
* @param string $username User's username. |
|
327 |
* @param string $password User's password. |
|
328 |
* @return bool Whether authentication passed. |
|
329 |
*/ |
|
5 | 330 |
public function login_pass_ok( $username, $password ) { |
0 | 331 |
return (bool) $this->login( $username, $password ); |
332 |
} |
|
333 |
||
334 |
/** |
|
335 |
* Escape string or array of strings for database. |
|
336 |
* |
|
337 |
* @since 1.5.2 |
|
338 |
* |
|
339 |
* @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
|
340 |
* @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
|
341 |
* when array is passed. |
0 | 342 |
*/ |
5 | 343 |
public function escape( &$data ) { |
9 | 344 |
if ( ! is_array( $data ) ) { |
0 | 345 |
return wp_slash( $data ); |
9 | 346 |
} |
0 | 347 |
|
348 |
foreach ( $data as &$v ) { |
|
9 | 349 |
if ( is_array( $v ) ) { |
0 | 350 |
$this->escape( $v ); |
9 | 351 |
} elseif ( ! is_object( $v ) ) { |
0 | 352 |
$v = wp_slash( $v ); |
9 | 353 |
} |
0 | 354 |
} |
355 |
} |
|
356 |
||
357 |
/** |
|
18 | 358 |
* Send error response to client. |
359 |
* |
|
360 |
* Send an XML error response to the client. If the endpoint is enabled |
|
361 |
* an HTTP 200 response is always sent per the XML-RPC specification. |
|
362 |
* |
|
363 |
* @since 5.7.3 |
|
364 |
* |
|
365 |
* @param IXR_Error|string $error Error code or an error object. |
|
366 |
* @param false $message Error message. Optional. |
|
367 |
*/ |
|
368 |
public function error( $error, $message = false ) { |
|
369 |
// Accepts either an error object or an error code and message |
|
370 |
if ( $message && ! is_object( $error ) ) { |
|
371 |
$error = new IXR_Error( $error, $message ); |
|
372 |
} |
|
373 |
||
374 |
if ( ! $this->is_enabled ) { |
|
375 |
status_header( $error->code ); |
|
376 |
} |
|
377 |
||
378 |
$this->output( $error->getXml() ); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
0 | 382 |
* Retrieve custom fields for post. |
383 |
* |
|
384 |
* @since 2.5.0 |
|
385 |
* |
|
386 |
* @param int $post_id Post ID. |
|
387 |
* @return array Custom fields, if exist. |
|
388 |
*/ |
|
9 | 389 |
public function get_custom_fields( $post_id ) { |
0 | 390 |
$post_id = (int) $post_id; |
391 |
||
392 |
$custom_fields = array(); |
|
393 |
||
9 | 394 |
foreach ( (array) has_meta( $post_id ) as $meta ) { |
0 | 395 |
// Don't expose protected fields. |
9 | 396 |
if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) { |
0 | 397 |
continue; |
9 | 398 |
} |
0 | 399 |
|
400 |
$custom_fields[] = array( |
|
9 | 401 |
'id' => $meta['meta_id'], |
402 |
'key' => $meta['meta_key'], |
|
403 |
'value' => $meta['meta_value'], |
|
0 | 404 |
); |
405 |
} |
|
406 |
||
407 |
return $custom_fields; |
|
408 |
} |
|
409 |
||
410 |
/** |
|
411 |
* Set custom fields for post. |
|
412 |
* |
|
413 |
* @since 2.5.0 |
|
414 |
* |
|
16 | 415 |
* @param int $post_id Post ID. |
416 |
* @param array $fields Custom fields. |
|
0 | 417 |
*/ |
9 | 418 |
public function set_custom_fields( $post_id, $fields ) { |
0 | 419 |
$post_id = (int) $post_id; |
420 |
||
421 |
foreach ( (array) $fields as $meta ) { |
|
9 | 422 |
if ( isset( $meta['id'] ) ) { |
0 | 423 |
$meta['id'] = (int) $meta['id']; |
9 | 424 |
$pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
if ( ! $pmeta || $pmeta->post_id != $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
continue; |
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 |
|
9 | 430 |
if ( isset( $meta['key'] ) ) { |
0 | 431 |
$meta['key'] = wp_unslash( $meta['key'] ); |
9 | 432 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
0 | 433 |
continue; |
9 | 434 |
} |
0 | 435 |
$meta['value'] = wp_unslash( $meta['value'] ); |
9 | 436 |
if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) { |
0 | 437 |
update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
9 | 438 |
} |
0 | 439 |
} elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
440 |
delete_metadata_by_mid( 'post', $meta['id'] ); |
|
441 |
} |
|
442 |
} elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { |
|
443 |
add_post_meta( $post_id, $meta['key'], $meta['value'] ); |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* Retrieve custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* @return array Array of custom fields, if they exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
public function get_term_custom_fields( $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
$custom_fields = array(); |
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 |
foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
continue; |
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 |
$custom_fields[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
'id' => $meta['meta_id'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
'key' => $meta['meta_key'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
'value' => $meta['meta_value'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
return $custom_fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* Set custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* |
16 | 482 |
* @param int $term_id Term ID. |
483 |
* @param array $fields Custom fields. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
public function set_term_custom_fields( $term_id, $fields ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
foreach ( (array) $fields as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
if ( isset( $meta['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
$meta['id'] = (int) $meta['id']; |
9 | 491 |
$pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
if ( isset( $meta['key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
$meta['key'] = wp_unslash( $meta['key'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$meta['value'] = wp_unslash( $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
} elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
delete_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
} elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
/** |
0 | 511 |
* Set up blog options property. |
512 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* Passes property through {@see 'xmlrpc_blog_options'} filter. |
0 | 514 |
* |
515 |
* @since 2.6.0 |
|
516 |
*/ |
|
5 | 517 |
public function initialise_blog_option_info() { |
0 | 518 |
$this->blog_options = array( |
16 | 519 |
// Read-only options. |
9 | 520 |
'software_name' => array( |
521 |
'desc' => __( 'Software Name' ), |
|
522 |
'readonly' => true, |
|
523 |
'value' => 'WordPress', |
|
0 | 524 |
), |
9 | 525 |
'software_version' => array( |
526 |
'desc' => __( 'Software Version' ), |
|
527 |
'readonly' => true, |
|
528 |
'value' => get_bloginfo( 'version' ), |
|
0 | 529 |
), |
9 | 530 |
'blog_url' => array( |
531 |
'desc' => __( 'WordPress Address (URL)' ), |
|
532 |
'readonly' => true, |
|
533 |
'option' => 'siteurl', |
|
0 | 534 |
), |
9 | 535 |
'home_url' => array( |
536 |
'desc' => __( 'Site Address (URL)' ), |
|
537 |
'readonly' => true, |
|
538 |
'option' => 'home', |
|
0 | 539 |
), |
9 | 540 |
'login_url' => array( |
541 |
'desc' => __( 'Login Address (URL)' ), |
|
542 |
'readonly' => true, |
|
543 |
'value' => wp_login_url(), |
|
0 | 544 |
), |
9 | 545 |
'admin_url' => array( |
546 |
'desc' => __( 'The URL to the admin area' ), |
|
547 |
'readonly' => true, |
|
548 |
'value' => get_admin_url(), |
|
0 | 549 |
), |
550 |
'image_default_link_type' => array( |
|
9 | 551 |
'desc' => __( 'Image default link type' ), |
552 |
'readonly' => true, |
|
553 |
'option' => 'image_default_link_type', |
|
0 | 554 |
), |
9 | 555 |
'image_default_size' => array( |
556 |
'desc' => __( 'Image default size' ), |
|
557 |
'readonly' => true, |
|
558 |
'option' => 'image_default_size', |
|
0 | 559 |
), |
9 | 560 |
'image_default_align' => array( |
561 |
'desc' => __( 'Image default align' ), |
|
562 |
'readonly' => true, |
|
563 |
'option' => 'image_default_align', |
|
0 | 564 |
), |
9 | 565 |
'template' => array( |
566 |
'desc' => __( 'Template' ), |
|
567 |
'readonly' => true, |
|
568 |
'option' => 'template', |
|
0 | 569 |
), |
9 | 570 |
'stylesheet' => array( |
571 |
'desc' => __( 'Stylesheet' ), |
|
572 |
'readonly' => true, |
|
573 |
'option' => 'stylesheet', |
|
0 | 574 |
), |
9 | 575 |
'post_thumbnail' => array( |
576 |
'desc' => __( 'Post Thumbnail' ), |
|
577 |
'readonly' => true, |
|
578 |
'value' => current_theme_supports( 'post-thumbnails' ), |
|
0 | 579 |
), |
580 |
||
16 | 581 |
// Updatable options. |
9 | 582 |
'time_zone' => array( |
583 |
'desc' => __( 'Time Zone' ), |
|
584 |
'readonly' => false, |
|
585 |
'option' => 'gmt_offset', |
|
0 | 586 |
), |
9 | 587 |
'blog_title' => array( |
588 |
'desc' => __( 'Site Title' ), |
|
589 |
'readonly' => false, |
|
590 |
'option' => 'blogname', |
|
0 | 591 |
), |
9 | 592 |
'blog_tagline' => array( |
593 |
'desc' => __( 'Site Tagline' ), |
|
594 |
'readonly' => false, |
|
595 |
'option' => 'blogdescription', |
|
0 | 596 |
), |
9 | 597 |
'date_format' => array( |
598 |
'desc' => __( 'Date Format' ), |
|
599 |
'readonly' => false, |
|
600 |
'option' => 'date_format', |
|
0 | 601 |
), |
9 | 602 |
'time_format' => array( |
603 |
'desc' => __( 'Time Format' ), |
|
604 |
'readonly' => false, |
|
605 |
'option' => 'time_format', |
|
0 | 606 |
), |
9 | 607 |
'users_can_register' => array( |
608 |
'desc' => __( 'Allow new users to sign up' ), |
|
609 |
'readonly' => false, |
|
610 |
'option' => 'users_can_register', |
|
0 | 611 |
), |
9 | 612 |
'thumbnail_size_w' => array( |
613 |
'desc' => __( 'Thumbnail Width' ), |
|
614 |
'readonly' => false, |
|
615 |
'option' => 'thumbnail_size_w', |
|
0 | 616 |
), |
9 | 617 |
'thumbnail_size_h' => array( |
618 |
'desc' => __( 'Thumbnail Height' ), |
|
619 |
'readonly' => false, |
|
620 |
'option' => 'thumbnail_size_h', |
|
0 | 621 |
), |
9 | 622 |
'thumbnail_crop' => array( |
623 |
'desc' => __( 'Crop thumbnail to exact dimensions' ), |
|
624 |
'readonly' => false, |
|
625 |
'option' => 'thumbnail_crop', |
|
0 | 626 |
), |
9 | 627 |
'medium_size_w' => array( |
628 |
'desc' => __( 'Medium size image width' ), |
|
629 |
'readonly' => false, |
|
630 |
'option' => 'medium_size_w', |
|
0 | 631 |
), |
9 | 632 |
'medium_size_h' => array( |
633 |
'desc' => __( 'Medium size image height' ), |
|
634 |
'readonly' => false, |
|
635 |
'option' => 'medium_size_h', |
|
0 | 636 |
), |
9 | 637 |
'medium_large_size_w' => array( |
638 |
'desc' => __( 'Medium-Large size image width' ), |
|
639 |
'readonly' => false, |
|
640 |
'option' => 'medium_large_size_w', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
), |
9 | 642 |
'medium_large_size_h' => array( |
643 |
'desc' => __( 'Medium-Large size image height' ), |
|
644 |
'readonly' => false, |
|
645 |
'option' => 'medium_large_size_h', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
), |
9 | 647 |
'large_size_w' => array( |
648 |
'desc' => __( 'Large size image width' ), |
|
649 |
'readonly' => false, |
|
650 |
'option' => 'large_size_w', |
|
0 | 651 |
), |
9 | 652 |
'large_size_h' => array( |
653 |
'desc' => __( 'Large size image height' ), |
|
654 |
'readonly' => false, |
|
655 |
'option' => 'large_size_h', |
|
0 | 656 |
), |
9 | 657 |
'default_comment_status' => array( |
16 | 658 |
'desc' => __( 'Allow people to submit comments on new posts.' ), |
9 | 659 |
'readonly' => false, |
660 |
'option' => 'default_comment_status', |
|
0 | 661 |
), |
9 | 662 |
'default_ping_status' => array( |
16 | 663 |
'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new posts.' ), |
9 | 664 |
'readonly' => false, |
665 |
'option' => 'default_ping_status', |
|
666 |
), |
|
0 | 667 |
); |
668 |
||
5 | 669 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
* Filters the XML-RPC blog options property. |
5 | 671 |
* |
672 |
* @since 2.6.0 |
|
673 |
* |
|
674 |
* @param array $blog_options An array of XML-RPC blog options. |
|
675 |
*/ |
|
0 | 676 |
$this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); |
677 |
} |
|
678 |
||
679 |
/** |
|
680 |
* Retrieve the blogs of the user. |
|
681 |
* |
|
682 |
* @since 2.6.0 |
|
683 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
* } |
5 | 690 |
* @return array|IXR_Error Array contains: |
0 | 691 |
* - 'isAdmin' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* - 'isPrimary' - whether the blog is the user's primary blog |
0 | 693 |
* - 'url' |
694 |
* - 'blogid' |
|
695 |
* - 'blogName' |
|
696 |
* - 'xmlrpc' - url of xmlrpc endpoint |
|
697 |
*/ |
|
5 | 698 |
public function wp_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
if ( ! $this->minimum_args( $args, 2 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
|
16 | 703 |
// If this isn't on WPMU then just use blogger_getUsersBlogs(). |
9 | 704 |
if ( ! is_multisite() ) { |
0 | 705 |
array_unshift( $args, 1 ); |
706 |
return $this->blogger_getUsersBlogs( $args ); |
|
707 |
} |
|
708 |
||
709 |
$this->escape( $args ); |
|
710 |
||
711 |
$username = $args[0]; |
|
712 |
$password = $args[1]; |
|
713 |
||
16 | 714 |
$user = $this->login( $username, $password ); |
715 |
if ( ! $user ) { |
|
0 | 716 |
return $this->error; |
9 | 717 |
} |
0 | 718 |
|
5 | 719 |
/** |
720 |
* Fires after the XML-RPC user has been authenticated but before the rest of |
|
721 |
* the method logic begins. |
|
722 |
* |
|
723 |
* All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
|
724 |
* equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
|
725 |
* |
|
726 |
* @since 2.5.0 |
|
18 | 727 |
* @since 5.7.0 Added the `$args` and `$server` parameters. |
5 | 728 |
* |
18 | 729 |
* @param string $name The method name. |
730 |
* @param array|string $args The escaped arguments passed to the method. |
|
731 |
* @param wp_xmlrpc_server $server The XML-RPC server instance. |
|
5 | 732 |
*/ |
18 | 733 |
do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this ); |
0 | 734 |
|
9 | 735 |
$blogs = (array) get_blogs_of_user( $user->ID ); |
736 |
$struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
$primary_blog_id = 0; |
9 | 738 |
$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
|
739 |
if ( $active_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
$primary_blog_id = (int) $active_blog->blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
} |
0 | 742 |
|
743 |
foreach ( $blogs as $blog ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
// Don't include blogs that aren't hosted at this site. |
16 | 745 |
if ( get_current_network_id() != $blog->site_id ) { |
0 | 746 |
continue; |
9 | 747 |
} |
0 | 748 |
|
749 |
$blog_id = $blog->userblog_id; |
|
750 |
||
751 |
switch_to_blog( $blog_id ); |
|
752 |
||
9 | 753 |
$is_admin = current_user_can( 'manage_options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
$is_primary = ( (int) $blog_id === $primary_blog_id ); |
0 | 755 |
|
756 |
$struct[] = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
'isAdmin' => $is_admin, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
'isPrimary' => $is_primary, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
'blogid' => (string) $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
'blogName' => get_option( 'blogname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
0 | 763 |
); |
764 |
||
765 |
restore_current_blog(); |
|
766 |
} |
|
767 |
||
768 |
return $struct; |
|
769 |
} |
|
770 |
||
771 |
/** |
|
772 |
* Checks if the method received at least the minimum number of arguments. |
|
773 |
* |
|
774 |
* @since 3.4.0 |
|
775 |
* |
|
16 | 776 |
* @param array $args An array of arguments to check. |
777 |
* @param int $count Minimum number of arguments. |
|
778 |
* @return bool True if `$args` contains at least `$count` arguments, false otherwise. |
|
0 | 779 |
*/ |
780 |
protected function minimum_args( $args, $count ) { |
|
16 | 781 |
if ( ! is_array( $args ) || count( $args ) < $count ) { |
0 | 782 |
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) ); |
783 |
return false; |
|
784 |
} |
|
785 |
||
786 |
return true; |
|
787 |
} |
|
788 |
||
789 |
/** |
|
790 |
* Prepares taxonomy data for return in an XML-RPC object. |
|
791 |
* |
|
18 | 792 |
* @param WP_Taxonomy $taxonomy The unprepared taxonomy data. |
793 |
* @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
|
794 |
* @return array The prepared taxonomy data. |
0 | 795 |
*/ |
796 |
protected function _prepare_taxonomy( $taxonomy, $fields ) { |
|
797 |
$_taxonomy = array( |
|
9 | 798 |
'name' => $taxonomy->name, |
799 |
'label' => $taxonomy->label, |
|
0 | 800 |
'hierarchical' => (bool) $taxonomy->hierarchical, |
9 | 801 |
'public' => (bool) $taxonomy->public, |
802 |
'show_ui' => (bool) $taxonomy->show_ui, |
|
803 |
'_builtin' => (bool) $taxonomy->_builtin, |
|
0 | 804 |
); |
805 |
||
16 | 806 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 807 |
$_taxonomy['labels'] = (array) $taxonomy->labels; |
9 | 808 |
} |
809 |
||
16 | 810 |
if ( in_array( 'cap', $fields, true ) ) { |
0 | 811 |
$_taxonomy['cap'] = (array) $taxonomy->cap; |
9 | 812 |
} |
813 |
||
16 | 814 |
if ( in_array( 'menu', $fields, true ) ) { |
18 | 815 |
$_taxonomy['show_in_menu'] = (bool) $taxonomy->show_in_menu; |
9 | 816 |
} |
817 |
||
16 | 818 |
if ( in_array( 'object_type', $fields, true ) ) { |
0 | 819 |
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
9 | 820 |
} |
0 | 821 |
|
5 | 822 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* Filters XML-RPC-prepared data for the given taxonomy. |
5 | 824 |
* |
825 |
* @since 3.4.0 |
|
826 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @param array $_taxonomy An array of taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @param WP_Taxonomy $taxonomy Taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* @param array $fields The subset of taxonomy fields to return. |
5 | 830 |
*/ |
0 | 831 |
return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
832 |
} |
|
833 |
||
834 |
/** |
|
835 |
* Prepares term data for return in an XML-RPC object. |
|
836 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* @param array|object $term The unprepared term data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* @return array The prepared term data. |
0 | 839 |
*/ |
840 |
protected function _prepare_term( $term ) { |
|
841 |
$_term = $term; |
|
9 | 842 |
if ( ! is_array( $_term ) ) { |
0 | 843 |
$_term = get_object_vars( $_term ); |
9 | 844 |
} |
0 | 845 |
|
846 |
// For integers which may be larger than XML-RPC supports ensure we return strings. |
|
18 | 847 |
$_term['term_id'] = (string) $_term['term_id']; |
848 |
$_term['term_group'] = (string) $_term['term_group']; |
|
849 |
$_term['term_taxonomy_id'] = (string) $_term['term_taxonomy_id']; |
|
850 |
$_term['parent'] = (string) $_term['parent']; |
|
0 | 851 |
|
852 |
// Count we are happy to return as an integer because people really shouldn't use terms that much. |
|
18 | 853 |
$_term['count'] = (int) $_term['count']; |
0 | 854 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
// Get term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
$_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
|
857 |
|
5 | 858 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* Filters XML-RPC-prepared data for the given term. |
5 | 860 |
* |
861 |
* @since 3.4.0 |
|
862 |
* |
|
863 |
* @param array $_term An array of term data. |
|
864 |
* @param array|object $term Term object or array. |
|
865 |
*/ |
|
0 | 866 |
return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
867 |
} |
|
868 |
||
869 |
/** |
|
870 |
* Convert a WordPress date string to an IXR_Date object. |
|
871 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
* @param string $date Date string to convert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
* @return IXR_Date IXR_Date object. |
0 | 874 |
*/ |
875 |
protected function _convert_date( $date ) { |
|
16 | 876 |
if ( '0000-00-00 00:00:00' === $date ) { |
0 | 877 |
return new IXR_Date( '00000000T00:00:00Z' ); |
878 |
} |
|
879 |
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); |
|
880 |
} |
|
881 |
||
882 |
/** |
|
883 |
* Convert a WordPress GMT date string to an IXR_Date object. |
|
884 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
* @param string $date_gmt WordPress GMT date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* @param string $date Date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* @return IXR_Date IXR_Date object. |
0 | 888 |
*/ |
889 |
protected function _convert_date_gmt( $date_gmt, $date ) { |
|
16 | 890 |
if ( '0000-00-00 00:00:00' !== $date && '0000-00-00 00:00:00' === $date_gmt ) { |
0 | 891 |
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) ); |
892 |
} |
|
893 |
return $this->_convert_date( $date_gmt ); |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* Prepares post data for return in an XML-RPC object. |
|
898 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* @param array $post The unprepared post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* @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
|
901 |
* @return array The prepared post data. |
0 | 902 |
*/ |
903 |
protected function _prepare_post( $post, $fields ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
// Holds the data for this post. built up based on $fields. |
18 | 905 |
$_post = array( 'post_id' => (string) $post['ID'] ); |
0 | 906 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
// Prepare common post fields. |
0 | 908 |
$post_fields = array( |
909 |
'post_title' => $post['post_title'], |
|
910 |
'post_date' => $this->_convert_date( $post['post_date'] ), |
|
911 |
'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
|
912 |
'post_modified' => $this->_convert_date( $post['post_modified'] ), |
|
913 |
'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ), |
|
914 |
'post_status' => $post['post_status'], |
|
915 |
'post_type' => $post['post_type'], |
|
916 |
'post_name' => $post['post_name'], |
|
917 |
'post_author' => $post['post_author'], |
|
918 |
'post_password' => $post['post_password'], |
|
919 |
'post_excerpt' => $post['post_excerpt'], |
|
920 |
'post_content' => $post['post_content'], |
|
18 | 921 |
'post_parent' => (string) $post['post_parent'], |
0 | 922 |
'post_mime_type' => $post['post_mime_type'], |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
'link' => get_permalink( $post['ID'] ), |
0 | 924 |
'guid' => $post['guid'], |
18 | 925 |
'menu_order' => (int) $post['menu_order'], |
0 | 926 |
'comment_status' => $post['comment_status'], |
927 |
'ping_status' => $post['ping_status'], |
|
16 | 928 |
'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ), |
0 | 929 |
); |
930 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
// Thumbnail. |
0 | 932 |
$post_fields['post_thumbnail'] = array(); |
9 | 933 |
$thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
0 | 934 |
if ( $thumbnail_id ) { |
9 | 935 |
$thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail'; |
0 | 936 |
$post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
937 |
} |
|
938 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
// Consider future posts as published. |
16 | 940 |
if ( 'future' === $post_fields['post_status'] ) { |
0 | 941 |
$post_fields['post_status'] = 'publish'; |
9 | 942 |
} |
0 | 943 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
// Fill in blank post format. |
0 | 945 |
$post_fields['post_format'] = get_post_format( $post['ID'] ); |
9 | 946 |
if ( empty( $post_fields['post_format'] ) ) { |
0 | 947 |
$post_fields['post_format'] = 'standard'; |
9 | 948 |
} |
0 | 949 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
// Merge requested $post_fields fields into $_post. |
16 | 951 |
if ( in_array( 'post', $fields, true ) ) { |
0 | 952 |
$_post = array_merge( $_post, $post_fields ); |
953 |
} else { |
|
954 |
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
|
9 | 955 |
$_post = array_merge( $_post, $requested_fields ); |
0 | 956 |
} |
957 |
||
16 | 958 |
$all_taxonomy_fields = in_array( 'taxonomies', $fields, true ); |
959 |
||
960 |
if ( $all_taxonomy_fields || in_array( 'terms', $fields, true ) ) { |
|
0 | 961 |
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' ); |
9 | 962 |
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies ); |
963 |
$_post['terms'] = array(); |
|
0 | 964 |
foreach ( $terms as $term ) { |
965 |
$_post['terms'][] = $this->_prepare_term( $term ); |
|
966 |
} |
|
967 |
} |
|
968 |
||
16 | 969 |
if ( in_array( 'custom_fields', $fields, true ) ) { |
0 | 970 |
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] ); |
9 | 971 |
} |
0 | 972 |
|
16 | 973 |
if ( in_array( 'enclosure', $fields, true ) ) { |
0 | 974 |
$_post['enclosure'] = array(); |
9 | 975 |
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' ); |
0 | 976 |
if ( ! empty( $enclosures ) ) { |
9 | 977 |
$encdata = explode( "\n", $enclosures[0] ); |
978 |
$_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
0 | 979 |
$_post['enclosure']['length'] = (int) trim( $encdata[1] ); |
9 | 980 |
$_post['enclosure']['type'] = trim( $encdata[2] ); |
0 | 981 |
} |
982 |
} |
|
983 |
||
5 | 984 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* Filters XML-RPC-prepared date for the given post. |
5 | 986 |
* |
987 |
* @since 3.4.0 |
|
988 |
* |
|
989 |
* @param array $_post An array of modified post data. |
|
990 |
* @param array $post An array of post data. |
|
991 |
* @param array $fields An array of post fields. |
|
992 |
*/ |
|
0 | 993 |
return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields ); |
994 |
} |
|
995 |
||
996 |
/** |
|
997 |
* Prepares post data for return in an XML-RPC object. |
|
998 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* @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
|
1001 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* @param WP_Post_Type $post_type Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
* @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
|
1004 |
* @return array The prepared post type data. |
0 | 1005 |
*/ |
1006 |
protected function _prepare_post_type( $post_type, $fields ) { |
|
1007 |
$_post_type = array( |
|
9 | 1008 |
'name' => $post_type->name, |
1009 |
'label' => $post_type->label, |
|
0 | 1010 |
'hierarchical' => (bool) $post_type->hierarchical, |
9 | 1011 |
'public' => (bool) $post_type->public, |
1012 |
'show_ui' => (bool) $post_type->show_ui, |
|
1013 |
'_builtin' => (bool) $post_type->_builtin, |
|
1014 |
'has_archive' => (bool) $post_type->has_archive, |
|
1015 |
'supports' => get_all_post_type_supports( $post_type->name ), |
|
0 | 1016 |
); |
1017 |
||
16 | 1018 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 1019 |
$_post_type['labels'] = (array) $post_type->labels; |
1020 |
} |
|
1021 |
||
16 | 1022 |
if ( in_array( 'cap', $fields, true ) ) { |
9 | 1023 |
$_post_type['cap'] = (array) $post_type->cap; |
0 | 1024 |
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; |
1025 |
} |
|
1026 |
||
16 | 1027 |
if ( in_array( 'menu', $fields, true ) ) { |
0 | 1028 |
$_post_type['menu_position'] = (int) $post_type->menu_position; |
9 | 1029 |
$_post_type['menu_icon'] = $post_type->menu_icon; |
1030 |
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; |
|
1031 |
} |
|
1032 |
||
16 | 1033 |
if ( in_array( 'taxonomies', $fields, true ) ) { |
0 | 1034 |
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
9 | 1035 |
} |
0 | 1036 |
|
5 | 1037 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
* Filters XML-RPC-prepared date for the given post type. |
5 | 1039 |
* |
1040 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 1042 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
* @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
|
1044 |
* @param WP_Post_Type $post_type Post type object. |
5 | 1045 |
*/ |
0 | 1046 |
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
1047 |
} |
|
1048 |
||
1049 |
/** |
|
1050 |
* Prepares media item data for return in an XML-RPC object. |
|
1051 |
* |
|
18 | 1052 |
* @param WP_Post $media_item The unprepared media item data. |
1053 |
* @param string $thumbnail_size The image size to use for the thumbnail URL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* @return array The prepared media item data. |
0 | 1055 |
*/ |
1056 |
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
|
1057 |
$_media_item = array( |
|
18 | 1058 |
'attachment_id' => (string) $media_item->ID, |
0 | 1059 |
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
1060 |
'parent' => $media_item->post_parent, |
|
1061 |
'link' => wp_get_attachment_url( $media_item->ID ), |
|
1062 |
'title' => $media_item->post_title, |
|
1063 |
'caption' => $media_item->post_excerpt, |
|
1064 |
'description' => $media_item->post_content, |
|
1065 |
'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
9 | 1066 |
'type' => $media_item->post_mime_type, |
0 | 1067 |
); |
1068 |
||
1069 |
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
|
9 | 1070 |
if ( $thumbnail_src ) { |
0 | 1071 |
$_media_item['thumbnail'] = $thumbnail_src[0]; |
9 | 1072 |
} else { |
0 | 1073 |
$_media_item['thumbnail'] = $_media_item['link']; |
9 | 1074 |
} |
0 | 1075 |
|
5 | 1076 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
* Filters XML-RPC-prepared data for the given media item. |
5 | 1078 |
* |
1079 |
* @since 3.4.0 |
|
1080 |
* |
|
18 | 1081 |
* @param array $_media_item An array of media item data. |
1082 |
* @param WP_Post $media_item Media item object. |
|
1083 |
* @param string $thumbnail_size Image size. |
|
5 | 1084 |
*/ |
0 | 1085 |
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1086 |
} |
|
1087 |
||
1088 |
/** |
|
1089 |
* Prepares page data for return in an XML-RPC object. |
|
1090 |
* |
|
18 | 1091 |
* @param WP_Post $page The unprepared page data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
* @return array The prepared page data. |
0 | 1093 |
*/ |
1094 |
protected function _prepare_page( $page ) { |
|
1095 |
// Get all of the page content and link. |
|
1096 |
$full_page = get_extended( $page->post_content ); |
|
9 | 1097 |
$link = get_permalink( $page->ID ); |
0 | 1098 |
|
1099 |
// Get info the page parent if there is one. |
|
9 | 1100 |
$parent_title = ''; |
0 | 1101 |
if ( ! empty( $page->post_parent ) ) { |
9 | 1102 |
$parent = get_post( $page->post_parent ); |
0 | 1103 |
$parent_title = $parent->post_title; |
1104 |
} |
|
1105 |
||
1106 |
// Determine comment and ping settings. |
|
1107 |
$allow_comments = comments_open( $page->ID ) ? 1 : 0; |
|
9 | 1108 |
$allow_pings = pings_open( $page->ID ) ? 1 : 0; |
0 | 1109 |
|
1110 |
// Format page date. |
|
9 | 1111 |
$page_date = $this->_convert_date( $page->post_date ); |
0 | 1112 |
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); |
1113 |
||
1114 |
// Pull the categories info together. |
|
1115 |
$categories = array(); |
|
5 | 1116 |
if ( is_object_in_taxonomy( 'page', 'category' ) ) { |
1117 |
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { |
|
1118 |
$categories[] = get_cat_name( $cat_id ); |
|
1119 |
} |
|
0 | 1120 |
} |
1121 |
||
1122 |
// Get the author info. |
|
1123 |
$author = get_userdata( $page->post_author ); |
|
1124 |
||
1125 |
$page_template = get_page_template_slug( $page->ID ); |
|
9 | 1126 |
if ( empty( $page_template ) ) { |
0 | 1127 |
$page_template = 'default'; |
9 | 1128 |
} |
0 | 1129 |
|
1130 |
$_page = array( |
|
1131 |
'dateCreated' => $page_date, |
|
1132 |
'userid' => $page->post_author, |
|
1133 |
'page_id' => $page->ID, |
|
1134 |
'page_status' => $page->post_status, |
|
1135 |
'description' => $full_page['main'], |
|
1136 |
'title' => $page->post_title, |
|
1137 |
'link' => $link, |
|
1138 |
'permaLink' => $link, |
|
1139 |
'categories' => $categories, |
|
1140 |
'excerpt' => $page->post_excerpt, |
|
1141 |
'text_more' => $full_page['extended'], |
|
1142 |
'mt_allow_comments' => $allow_comments, |
|
1143 |
'mt_allow_pings' => $allow_pings, |
|
1144 |
'wp_slug' => $page->post_name, |
|
1145 |
'wp_password' => $page->post_password, |
|
1146 |
'wp_author' => $author->display_name, |
|
1147 |
'wp_page_parent_id' => $page->post_parent, |
|
1148 |
'wp_page_parent_title' => $parent_title, |
|
1149 |
'wp_page_order' => $page->menu_order, |
|
1150 |
'wp_author_id' => (string) $author->ID, |
|
1151 |
'wp_author_display_name' => $author->display_name, |
|
1152 |
'date_created_gmt' => $page_date_gmt, |
|
1153 |
'custom_fields' => $this->get_custom_fields( $page->ID ), |
|
9 | 1154 |
'wp_page_template' => $page_template, |
0 | 1155 |
); |
1156 |
||
5 | 1157 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
* Filters XML-RPC-prepared data for the given page. |
5 | 1159 |
* |
1160 |
* @since 3.4.0 |
|
1161 |
* |
|
1162 |
* @param array $_page An array of page data. |
|
1163 |
* @param WP_Post $page Page object. |
|
1164 |
*/ |
|
0 | 1165 |
return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); |
1166 |
} |
|
1167 |
||
1168 |
/** |
|
1169 |
* Prepares comment data for return in an XML-RPC object. |
|
1170 |
* |
|
18 | 1171 |
* @param WP_Comment $comment The unprepared comment data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @return array The prepared comment data. |
0 | 1173 |
*/ |
1174 |
protected function _prepare_comment( $comment ) { |
|
1175 |
// Format page date. |
|
1176 |
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
|
1177 |
||
5 | 1178 |
if ( '0' == $comment->comment_approved ) { |
0 | 1179 |
$comment_status = 'hold'; |
16 | 1180 |
} elseif ( 'spam' === $comment->comment_approved ) { |
0 | 1181 |
$comment_status = 'spam'; |
5 | 1182 |
} elseif ( '1' == $comment->comment_approved ) { |
0 | 1183 |
$comment_status = 'approve'; |
5 | 1184 |
} else { |
0 | 1185 |
$comment_status = $comment->comment_approved; |
5 | 1186 |
} |
0 | 1187 |
$_comment = array( |
1188 |
'date_created_gmt' => $comment_date_gmt, |
|
1189 |
'user_id' => $comment->user_id, |
|
1190 |
'comment_id' => $comment->comment_ID, |
|
1191 |
'parent' => $comment->comment_parent, |
|
1192 |
'status' => $comment_status, |
|
1193 |
'content' => $comment->comment_content, |
|
9 | 1194 |
'link' => get_comment_link( $comment ), |
0 | 1195 |
'post_id' => $comment->comment_post_ID, |
9 | 1196 |
'post_title' => get_the_title( $comment->comment_post_ID ), |
0 | 1197 |
'author' => $comment->comment_author, |
1198 |
'author_url' => $comment->comment_author_url, |
|
1199 |
'author_email' => $comment->comment_author_email, |
|
1200 |
'author_ip' => $comment->comment_author_IP, |
|
1201 |
'type' => $comment->comment_type, |
|
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 comment. |
5 | 1206 |
* |
1207 |
* @since 3.4.0 |
|
1208 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
* @param array $_comment An array of prepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
* @param WP_Comment $comment Comment object. |
5 | 1211 |
*/ |
0 | 1212 |
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1213 |
} |
|
1214 |
||
1215 |
/** |
|
1216 |
* Prepares user data for return in an XML-RPC object. |
|
1217 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* @param WP_User $user The unprepared user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
* @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
|
1220 |
* @return array The prepared user data. |
0 | 1221 |
*/ |
1222 |
protected function _prepare_user( $user, $fields ) { |
|
18 | 1223 |
$_user = array( 'user_id' => (string) $user->ID ); |
0 | 1224 |
|
1225 |
$user_fields = array( |
|
9 | 1226 |
'username' => $user->user_login, |
1227 |
'first_name' => $user->user_firstname, |
|
1228 |
'last_name' => $user->user_lastname, |
|
1229 |
'registered' => $this->_convert_date( $user->user_registered ), |
|
1230 |
'bio' => $user->user_description, |
|
1231 |
'email' => $user->user_email, |
|
1232 |
'nickname' => $user->nickname, |
|
1233 |
'nicename' => $user->user_nicename, |
|
1234 |
'url' => $user->user_url, |
|
1235 |
'display_name' => $user->display_name, |
|
1236 |
'roles' => $user->roles, |
|
0 | 1237 |
); |
1238 |
||
16 | 1239 |
if ( in_array( 'all', $fields, true ) ) { |
0 | 1240 |
$_user = array_merge( $_user, $user_fields ); |
1241 |
} else { |
|
16 | 1242 |
if ( in_array( 'basic', $fields, true ) ) { |
0 | 1243 |
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); |
9 | 1244 |
$fields = array_merge( $fields, $basic_fields ); |
0 | 1245 |
} |
1246 |
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); |
|
9 | 1247 |
$_user = array_merge( $_user, $requested_fields ); |
0 | 1248 |
} |
1249 |
||
5 | 1250 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* Filters XML-RPC-prepared data for the given user. |
5 | 1252 |
* |
1253 |
* @since 3.5.0 |
|
1254 |
* |
|
1255 |
* @param array $_user An array of user data. |
|
1256 |
* @param WP_User $user User object. |
|
1257 |
* @param array $fields An array of user fields. |
|
1258 |
*/ |
|
0 | 1259 |
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); |
1260 |
} |
|
1261 |
||
1262 |
/** |
|
1263 |
* Create a new post for any registered post type. |
|
1264 |
* |
|
1265 |
* @since 3.4.0 |
|
1266 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
* @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
|
1268 |
* |
16 | 1269 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
* 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
|
1271 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
* @type array $content_struct { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
* 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
|
1277 |
* additional post fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* @type string $post_type Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
* @type string $post_status Post status. Default 'draft' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* @type string $post_title Post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* @type int $post_author Post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* @type string $post_excerpt Post excerpt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* @type string $post_content Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* @type string $post_date_gmt Post date in GMT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* @type string $post_date Post date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
* @type string $post_password Post password (20-character limit). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
* @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
|
1289 |
* @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
|
1290 |
* @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
|
1291 |
* `$post_status` is 'private'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
* @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
|
1293 |
* @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
|
1294 |
* @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
|
1295 |
* of term IDs as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
* @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
|
1297 |
* of term names as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
* @type array $enclosure { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
* 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
|
1300 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
* @type string $url URL for the feed enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
* @type int $length Size in bytes of the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
* @type string $type Mime-type for the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
0 | 1308 |
*/ |
5 | 1309 |
public function wp_newPost( $args ) { |
9 | 1310 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1311 |
return $this->error; |
9 | 1312 |
} |
0 | 1313 |
|
1314 |
$this->escape( $args ); |
|
1315 |
||
1316 |
$username = $args[1]; |
|
1317 |
$password = $args[2]; |
|
1318 |
$content_struct = $args[3]; |
|
1319 |
||
16 | 1320 |
$user = $this->login( $username, $password ); |
1321 |
if ( ! $user ) { |
|
0 | 1322 |
return $this->error; |
9 | 1323 |
} |
0 | 1324 |
|
16 | 1325 |
// Convert the date field back to IXR form. |
5 | 1326 |
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
1327 |
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1328 |
} |
|
1329 |
||
16 | 1330 |
/* |
1331 |
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1332 |
* since _insert_post() will ignore the non-GMT date if the GMT date is set. |
|
1333 |
*/ |
|
5 | 1334 |
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
16 | 1335 |
if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
5 | 1336 |
unset( $content_struct['post_date_gmt'] ); |
1337 |
} else { |
|
1338 |
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1339 |
} |
|
1340 |
} |
|
1341 |
||
1342 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 1343 |
do_action( 'xmlrpc_call', 'wp.newPost', $args, $this ); |
0 | 1344 |
|
1345 |
unset( $content_struct['ID'] ); |
|
1346 |
||
1347 |
return $this->_insert_post( $user, $content_struct ); |
|
1348 |
} |
|
1349 |
||
1350 |
/** |
|
1351 |
* Helper method for filtering out elements from an array. |
|
1352 |
* |
|
1353 |
* @since 3.4.0 |
|
1354 |
* |
|
1355 |
* @param int $count Number to compare to one. |
|
18 | 1356 |
* @return bool True if the number is greater than one, false otherwise. |
0 | 1357 |
*/ |
1358 |
private function _is_greater_than_one( $count ) { |
|
1359 |
return $count > 1; |
|
1360 |
} |
|
1361 |
||
1362 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
* Encapsulate the logic for sticking a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
* 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
|
1365 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
* @param array $post_data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
* @param bool $update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
* @return void|IXR_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
private function _toggle_sticky( $post_data, $update = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
$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
|
1374 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
// Private and password-protected posts cannot be stickied. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
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
|
1377 |
// 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
|
1378 |
if ( ! empty( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
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
|
1380 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
if ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
} |
9 | 1385 |
} elseif ( isset( $post_data['sticky'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
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
|
1387 |
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
|
1388 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
$sticky = wp_validate_boolean( $post_data['sticky'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
if ( $sticky ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
stick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
* Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
0 | 1401 |
* |
1402 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
* @param WP_User $user The post author if post_author isn't set in $content_struct. |
5 | 1407 |
* @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
|
1408 |
* @return IXR_Error|string |
0 | 1409 |
*/ |
1410 |
protected function _insert_post( $user, $content_struct ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
'post_status' => 'draft', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
'post_type' => 'post', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
'post_author' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
'post_password' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
'post_excerpt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
'post_content' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
'post_title' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
'post_date' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
'post_date_gmt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
'post_format' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
'post_name' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
'post_thumbnail' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
'post_parent' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
'ping_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
'comment_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
'custom_fields' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
'terms_names' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
'terms' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
'sticky' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
'enclosure' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
'ID' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
0 | 1436 |
|
1437 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
|
9 | 1438 |
if ( ! $post_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1440 |
} |
0 | 1441 |
|
1442 |
$update = ! empty( $post_data['ID'] ); |
|
1443 |
||
1444 |
if ( $update ) { |
|
9 | 1445 |
if ( ! get_post( $post_data['ID'] ) ) { |
0 | 1446 |
return new IXR_Error( 401, __( 'Invalid post ID.' ) ); |
9 | 1447 |
} |
1448 |
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) { |
|
0 | 1449 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1450 |
} |
16 | 1451 |
if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) { |
0 | 1452 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 1453 |
} |
0 | 1454 |
} else { |
9 | 1455 |
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 1456 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
9 | 1457 |
} |
0 | 1458 |
} |
1459 |
||
1460 |
switch ( $post_data['post_status'] ) { |
|
1461 |
case 'draft': |
|
1462 |
case 'pending': |
|
1463 |
break; |
|
1464 |
case 'private': |
|
9 | 1465 |
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
|
1466 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
9 | 1467 |
} |
0 | 1468 |
break; |
1469 |
case 'publish': |
|
1470 |
case 'future': |
|
9 | 1471 |
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
|
1472 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
9 | 1473 |
} |
0 | 1474 |
break; |
1475 |
default: |
|
9 | 1476 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) { |
0 | 1477 |
$post_data['post_status'] = 'draft'; |
9 | 1478 |
} |
1479 |
break; |
|
1480 |
} |
|
1481 |
||
1482 |
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
|
1483 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
9 | 1484 |
} |
0 | 1485 |
|
1486 |
$post_data['post_author'] = absint( $post_data['post_author'] ); |
|
1487 |
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
|
9 | 1488 |
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
|
1489 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 1490 |
} |
0 | 1491 |
|
1492 |
$author = get_userdata( $post_data['post_author'] ); |
|
1493 |
||
9 | 1494 |
if ( ! $author ) { |
0 | 1495 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 1496 |
} |
0 | 1497 |
} else { |
1498 |
$post_data['post_author'] = $user->ID; |
|
1499 |
} |
|
1500 |
||
16 | 1501 |
if ( isset( $post_data['comment_status'] ) && 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { |
0 | 1502 |
unset( $post_data['comment_status'] ); |
9 | 1503 |
} |
1504 |
||
16 | 1505 |
if ( isset( $post_data['ping_status'] ) && 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { |
0 | 1506 |
unset( $post_data['ping_status'] ); |
9 | 1507 |
} |
0 | 1508 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
// Do some timestamp voodoo. |
0 | 1510 |
if ( ! empty( $post_data['post_date_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 1512 |
$dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1513 |
} elseif ( ! empty( $post_data['post_date'] ) ) { |
|
1514 |
$dateCreated = $post_data['post_date']->getIso(); |
|
1515 |
} |
|
1516 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
// 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
|
1518 |
$post_data['edit_date'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
|
0 | 1520 |
if ( ! empty( $dateCreated ) ) { |
16 | 1521 |
$post_data['post_date'] = iso8601_to_datetime( $dateCreated ); |
1522 |
$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
|
1523 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
$post_data['edit_date'] = true; |
0 | 1526 |
} |
1527 |
||
9 | 1528 |
if ( ! isset( $post_data['ID'] ) ) { |
0 | 1529 |
$post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
9 | 1530 |
} |
0 | 1531 |
$post_ID = $post_data['ID']; |
1532 |
||
16 | 1533 |
if ( 'post' === $post_data['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
$error = $this->_toggle_sticky( $post_data, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
return $error; |
0 | 1537 |
} |
1538 |
} |
|
1539 |
||
1540 |
if ( isset( $post_data['post_thumbnail'] ) ) { |
|
16 | 1541 |
// Empty value deletes, non-empty value adds/updates. |
9 | 1542 |
if ( ! $post_data['post_thumbnail'] ) { |
0 | 1543 |
delete_post_thumbnail( $post_ID ); |
9 | 1544 |
} elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) { |
0 | 1545 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 1546 |
} |
0 | 1547 |
set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
1548 |
unset( $content_struct['post_thumbnail'] ); |
|
1549 |
} |
|
1550 |
||
9 | 1551 |
if ( isset( $post_data['custom_fields'] ) ) { |
0 | 1552 |
$this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
9 | 1553 |
} |
0 | 1554 |
|
1555 |
if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
|
1556 |
$post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
|
1557 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
// Accumulate term IDs from terms and terms_names. |
0 | 1559 |
$terms = array(); |
1560 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
// First validate the terms specified by ID. |
0 | 1562 |
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1563 |
$taxonomies = array_keys( $post_data['terms'] ); |
|
1564 |
||
16 | 1565 |
// Validating term IDs. |
0 | 1566 |
foreach ( $taxonomies as $taxonomy ) { |
9 | 1567 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1568 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1569 |
} |
1570 |
||
1571 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1572 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1573 |
} |
1574 |
||
1575 |
$term_ids = $post_data['terms'][ $taxonomy ]; |
|
5 | 1576 |
$terms[ $taxonomy ] = array(); |
0 | 1577 |
foreach ( $term_ids as $term_id ) { |
1578 |
$term = get_term_by( 'id', $term_id, $taxonomy ); |
|
1579 |
||
9 | 1580 |
if ( ! $term ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
9 | 1582 |
} |
1583 |
||
1584 |
$terms[ $taxonomy ][] = (int) $term_id; |
|
0 | 1585 |
} |
1586 |
} |
|
1587 |
} |
|
1588 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
// Now validate terms specified by name. |
0 | 1590 |
if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1591 |
$taxonomies = array_keys( $post_data['terms_names'] ); |
|
1592 |
||
1593 |
foreach ( $taxonomies as $taxonomy ) { |
|
9 | 1594 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1595 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1596 |
} |
1597 |
||
1598 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1599 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1600 |
} |
0 | 1601 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1603 |
* 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
|
1604 |
* in the hierarchy share the same name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
*/ |
0 | 1606 |
$ambiguous_terms = array(); |
1607 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
9 | 1608 |
$tax_term_names = get_terms( |
1609 |
array( |
|
16 | 1610 |
'taxonomy' => $taxonomy, |
9 | 1611 |
'fields' => 'names', |
1612 |
'hide_empty' => false, |
|
1613 |
) |
|
1614 |
); |
|
0 | 1615 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
// Count the number of terms with the same name. |
0 | 1617 |
$tax_term_names_count = array_count_values( $tax_term_names ); |
1618 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1619 |
// Filter out non-ambiguous term names. |
9 | 1620 |
$ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) ); |
0 | 1621 |
|
1622 |
$ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
|
1623 |
} |
|
1624 |
||
9 | 1625 |
$term_names = $post_data['terms_names'][ $taxonomy ]; |
0 | 1626 |
foreach ( $term_names as $term_name ) { |
16 | 1627 |
if ( in_array( $term_name, $ambiguous_terms, true ) ) { |
0 | 1628 |
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
9 | 1629 |
} |
0 | 1630 |
|
1631 |
$term = get_term_by( 'name', $term_name, $taxonomy ); |
|
1632 |
||
1633 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
// Term doesn't exist, so check that the user is allowed to create new terms. |
9 | 1635 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->edit_terms ) ) { |
0 | 1636 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
9 | 1637 |
} |
0 | 1638 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
// Create the new term. |
0 | 1640 |
$term_info = wp_insert_term( $term_name, $taxonomy ); |
9 | 1641 |
if ( is_wp_error( $term_info ) ) { |
0 | 1642 |
return new IXR_Error( 500, $term_info->get_error_message() ); |
9 | 1643 |
} |
1644 |
||
1645 |
$terms[ $taxonomy ][] = (int) $term_info['term_id']; |
|
0 | 1646 |
} else { |
9 | 1647 |
$terms[ $taxonomy ][] = (int) $term->term_id; |
0 | 1648 |
} |
1649 |
} |
|
1650 |
} |
|
1651 |
} |
|
1652 |
||
1653 |
$post_data['tax_input'] = $terms; |
|
1654 |
unset( $post_data['terms'], $post_data['terms_names'] ); |
|
1655 |
} |
|
1656 |
||
1657 |
if ( isset( $post_data['post_format'] ) ) { |
|
1658 |
$format = set_post_format( $post_ID, $post_data['post_format'] ); |
|
1659 |
||
9 | 1660 |
if ( is_wp_error( $format ) ) { |
0 | 1661 |
return new IXR_Error( 500, $format->get_error_message() ); |
9 | 1662 |
} |
0 | 1663 |
|
1664 |
unset( $post_data['post_format'] ); |
|
1665 |
} |
|
1666 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
// Handle enclosures. |
0 | 1668 |
$enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; |
1669 |
$this->add_enclosure_if_new( $post_ID, $enclosure ); |
|
1670 |
||
1671 |
$this->attach_uploads( $post_ID, $post_data['post_content'] ); |
|
1672 |
||
5 | 1673 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
* Filters post data array to be inserted via XML-RPC. |
5 | 1675 |
* |
1676 |
* @since 3.4.0 |
|
1677 |
* |
|
1678 |
* @param array $post_data Parsed array of post data. |
|
1679 |
* @param array $content_struct Post data array. |
|
1680 |
*/ |
|
0 | 1681 |
$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); |
1682 |
||
1683 |
$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); |
|
9 | 1684 |
if ( is_wp_error( $post_ID ) ) { |
0 | 1685 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
9 | 1686 |
} |
1687 |
||
1688 |
if ( ! $post_ID ) { |
|
16 | 1689 |
if ( $update ) { |
1690 |
return new IXR_Error( 401, __( 'Sorry, the post could not be updated.' ) ); |
|
1691 |
} else { |
|
1692 |
return new IXR_Error( 401, __( 'Sorry, the post could not be created.' ) ); |
|
1693 |
} |
|
9 | 1694 |
} |
0 | 1695 |
|
18 | 1696 |
return (string) $post_ID; |
0 | 1697 |
} |
1698 |
||
1699 |
/** |
|
1700 |
* Edit a post for any registered post type. |
|
1701 |
* |
|
1702 |
* The $content_struct parameter only needs to contain fields that |
|
1703 |
* should be changed. All other fields will retain their existing values. |
|
1704 |
* |
|
1705 |
* @since 3.4.0 |
|
1706 |
* |
|
16 | 1707 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
* @type array $content_struct Extra content arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
* @return true|IXR_Error True on success, IXR_Error on failure. |
0 | 1717 |
*/ |
5 | 1718 |
public function wp_editPost( $args ) { |
9 | 1719 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 1720 |
return $this->error; |
9 | 1721 |
} |
0 | 1722 |
|
1723 |
$this->escape( $args ); |
|
1724 |
||
1725 |
$username = $args[1]; |
|
1726 |
$password = $args[2]; |
|
1727 |
$post_id = (int) $args[3]; |
|
1728 |
$content_struct = $args[4]; |
|
1729 |
||
16 | 1730 |
$user = $this->login( $username, $password ); |
1731 |
if ( ! $user ) { |
|
0 | 1732 |
return $this->error; |
9 | 1733 |
} |
0 | 1734 |
|
5 | 1735 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1736 |
do_action( 'xmlrpc_call', 'wp.editPost', $args, $this ); |
0 | 1737 |
|
1738 |
$post = get_post( $post_id, ARRAY_A ); |
|
1739 |
||
9 | 1740 |
if ( empty( $post['ID'] ) ) { |
0 | 1741 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1742 |
} |
0 | 1743 |
|
1744 |
if ( isset( $content_struct['if_not_modified_since'] ) ) { |
|
1745 |
// If the post has been modified since the date provided, return an error. |
|
1746 |
if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { |
|
1747 |
return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); |
|
1748 |
} |
|
1749 |
} |
|
1750 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
// Convert the date field back to IXR form. |
0 | 1752 |
$post['post_date'] = $this->_convert_date( $post['post_date'] ); |
1753 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
* 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
|
1756 |
* 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
|
1757 |
*/ |
16 | 1758 |
if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
0 | 1759 |
unset( $post['post_date_gmt'] ); |
9 | 1760 |
} else { |
0 | 1761 |
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); |
9 | 1762 |
} |
0 | 1763 |
|
16 | 1764 |
/* |
1765 |
* If the API client did not provide 'post_date', then we must not perpetuate the value that |
|
1766 |
* was stored in the database, or it will appear to be an intentional edit. Conveying it here |
|
1767 |
* as if it was coming from the API client will cause an otherwise zeroed out 'post_date_gmt' |
|
1768 |
* to get set with the value that was originally stored in the database when the draft was created. |
|
1769 |
*/ |
|
1770 |
if ( ! isset( $content_struct['post_date'] ) ) { |
|
1771 |
unset( $post['post_date'] ); |
|
1772 |
} |
|
1773 |
||
0 | 1774 |
$this->escape( $post ); |
1775 |
$merged_content_struct = array_merge( $post, $content_struct ); |
|
1776 |
||
1777 |
$retval = $this->_insert_post( $user, $merged_content_struct ); |
|
9 | 1778 |
if ( $retval instanceof IXR_Error ) { |
0 | 1779 |
return $retval; |
9 | 1780 |
} |
0 | 1781 |
|
1782 |
return true; |
|
1783 |
} |
|
1784 |
||
1785 |
/** |
|
1786 |
* Delete a post for any registered post type. |
|
1787 |
* |
|
1788 |
* @since 3.4.0 |
|
1789 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
* @see wp_delete_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
* |
16 | 1792 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 1801 |
*/ |
5 | 1802 |
public function wp_deletePost( $args ) { |
9 | 1803 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1804 |
return $this->error; |
9 | 1805 |
} |
0 | 1806 |
|
1807 |
$this->escape( $args ); |
|
1808 |
||
9 | 1809 |
$username = $args[1]; |
1810 |
$password = $args[2]; |
|
1811 |
$post_id = (int) $args[3]; |
|
1812 |
||
16 | 1813 |
$user = $this->login( $username, $password ); |
1814 |
if ( ! $user ) { |
|
0 | 1815 |
return $this->error; |
9 | 1816 |
} |
0 | 1817 |
|
5 | 1818 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1819 |
do_action( 'xmlrpc_call', 'wp.deletePost', $args, $this ); |
0 | 1820 |
|
1821 |
$post = get_post( $post_id, ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
if ( empty( $post['ID'] ) ) { |
0 | 1823 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
0 | 1827 |
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
|
1828 |
} |
0 | 1829 |
|
1830 |
$result = wp_delete_post( $post_id ); |
|
1831 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1832 |
if ( ! $result ) { |
16 | 1833 |
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
|
1834 |
} |
0 | 1835 |
|
1836 |
return true; |
|
1837 |
} |
|
1838 |
||
1839 |
/** |
|
1840 |
* Retrieve a post. |
|
1841 |
* |
|
1842 |
* @since 3.4.0 |
|
1843 |
* |
|
1844 |
* The optional $fields parameter specifies what fields will be included |
|
1845 |
* in the response array. This should be a list of field names. 'post_id' will |
|
1846 |
* always be included in the response regardless of the value of $fields. |
|
1847 |
* |
|
1848 |
* Instead of, or in addition to, individual field names, conceptual group |
|
1849 |
* names can be used to specify multiple fields. The available conceptual |
|
1850 |
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields', |
|
1851 |
* and 'enclosure'. |
|
1852 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
* @see get_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
* @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
|
1863 |
* } |
5 | 1864 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 1865 |
* - 'post_id' |
1866 |
* - 'post_title' |
|
1867 |
* - 'post_date' |
|
1868 |
* - 'post_date_gmt' |
|
1869 |
* - 'post_modified' |
|
1870 |
* - 'post_modified_gmt' |
|
1871 |
* - 'post_status' |
|
1872 |
* - 'post_type' |
|
1873 |
* - 'post_name' |
|
1874 |
* - 'post_author' |
|
1875 |
* - 'post_password' |
|
1876 |
* - 'post_excerpt' |
|
1877 |
* - 'post_content' |
|
1878 |
* - 'link' |
|
1879 |
* - 'comment_status' |
|
1880 |
* - 'ping_status' |
|
1881 |
* - 'sticky' |
|
1882 |
* - 'custom_fields' |
|
1883 |
* - 'terms' |
|
1884 |
* - 'categories' |
|
1885 |
* - 'tags' |
|
1886 |
* - 'enclosure' |
|
1887 |
*/ |
|
5 | 1888 |
public function wp_getPost( $args ) { |
9 | 1889 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1890 |
return $this->error; |
9 | 1891 |
} |
0 | 1892 |
|
1893 |
$this->escape( $args ); |
|
1894 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1895 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
$post_id = (int) $args[3]; |
0 | 1898 |
|
5 | 1899 |
if ( isset( $args[4] ) ) { |
0 | 1900 |
$fields = $args[4]; |
5 | 1901 |
} else { |
1902 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
* Filters the list of post query fields used by the given XML-RPC method. |
5 | 1904 |
* |
1905 |
* @since 3.4.0 |
|
1906 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
* @param array $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'. |
5 | 1908 |
* @param string $method Method name. |
1909 |
*/ |
|
0 | 1910 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
5 | 1911 |
} |
0 | 1912 |
|
16 | 1913 |
$user = $this->login( $username, $password ); |
1914 |
if ( ! $user ) { |
|
0 | 1915 |
return $this->error; |
9 | 1916 |
} |
0 | 1917 |
|
5 | 1918 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1919 |
do_action( 'xmlrpc_call', 'wp.getPost', $args, $this ); |
0 | 1920 |
|
1921 |
$post = get_post( $post_id, ARRAY_A ); |
|
1922 |
||
9 | 1923 |
if ( empty( $post['ID'] ) ) { |
0 | 1924 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1925 |
} |
1926 |
||
1927 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1928 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1929 |
} |
0 | 1930 |
|
1931 |
return $this->_prepare_post( $post, $fields ); |
|
1932 |
} |
|
1933 |
||
1934 |
/** |
|
1935 |
* Retrieve posts. |
|
1936 |
* |
|
1937 |
* @since 3.4.0 |
|
1938 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
* @see wp_get_recent_posts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
* @see wp_getPost() for more on `$fields` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1941 |
* @see get_posts() for more on `$filter` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1943 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1944 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1945 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1946 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1948 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1949 |
* @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
|
1950 |
* 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1951 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
* @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
|
1953 |
* } |
5 | 1954 |
* @return array|IXR_Error Array contains a collection of posts. |
0 | 1955 |
*/ |
5 | 1956 |
public function wp_getPosts( $args ) { |
9 | 1957 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 1958 |
return $this->error; |
9 | 1959 |
} |
0 | 1960 |
|
1961 |
$this->escape( $args ); |
|
1962 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 1966 |
|
5 | 1967 |
if ( isset( $args[4] ) ) { |
0 | 1968 |
$fields = $args[4]; |
5 | 1969 |
} else { |
1970 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1971 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
5 | 1972 |
} |
0 | 1973 |
|
16 | 1974 |
$user = $this->login( $username, $password ); |
1975 |
if ( ! $user ) { |
|
0 | 1976 |
return $this->error; |
9 | 1977 |
} |
0 | 1978 |
|
5 | 1979 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1980 |
do_action( 'xmlrpc_call', 'wp.getPosts', $args, $this ); |
0 | 1981 |
|
1982 |
$query = array(); |
|
1983 |
||
1984 |
if ( isset( $filter['post_type'] ) ) { |
|
1985 |
$post_type = get_post_type_object( $filter['post_type'] ); |
|
9 | 1986 |
if ( ! ( (bool) $post_type ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1988 |
} |
0 | 1989 |
} else { |
1990 |
$post_type = get_post_type_object( 'post' ); |
|
1991 |
} |
|
1992 |
||
9 | 1993 |
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
|
1994 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 1995 |
} |
0 | 1996 |
|
1997 |
$query['post_type'] = $post_type->name; |
|
1998 |
||
9 | 1999 |
if ( isset( $filter['post_status'] ) ) { |
0 | 2000 |
$query['post_status'] = $filter['post_status']; |
9 | 2001 |
} |
2002 |
||
2003 |
if ( isset( $filter['number'] ) ) { |
|
0 | 2004 |
$query['numberposts'] = absint( $filter['number'] ); |
9 | 2005 |
} |
2006 |
||
2007 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2008 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2009 |
} |
0 | 2010 |
|
2011 |
if ( isset( $filter['orderby'] ) ) { |
|
2012 |
$query['orderby'] = $filter['orderby']; |
|
2013 |
||
9 | 2014 |
if ( isset( $filter['order'] ) ) { |
0 | 2015 |
$query['order'] = $filter['order']; |
9 | 2016 |
} |
0 | 2017 |
} |
2018 |
||
2019 |
if ( isset( $filter['s'] ) ) { |
|
2020 |
$query['s'] = $filter['s']; |
|
2021 |
} |
|
2022 |
||
2023 |
$posts_list = wp_get_recent_posts( $query ); |
|
2024 |
||
9 | 2025 |
if ( ! $posts_list ) { |
0 | 2026 |
return array(); |
9 | 2027 |
} |
0 | 2028 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
// Holds all the posts data. |
0 | 2030 |
$struct = array(); |
2031 |
||
2032 |
foreach ( $posts_list as $post ) { |
|
9 | 2033 |
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) { |
0 | 2034 |
continue; |
9 | 2035 |
} |
0 | 2036 |
|
2037 |
$struct[] = $this->_prepare_post( $post, $fields ); |
|
2038 |
} |
|
2039 |
||
2040 |
return $struct; |
|
2041 |
} |
|
2042 |
||
2043 |
/** |
|
2044 |
* Create a new term. |
|
2045 |
* |
|
2046 |
* @since 3.4.0 |
|
2047 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* @see wp_insert_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
* @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
|
2057 |
* the term 'name' and 'taxonomy'. Optional accepted values include |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
* 'parent', 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
* @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
0 | 2061 |
*/ |
5 | 2062 |
public function wp_newTerm( $args ) { |
9 | 2063 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2064 |
return $this->error; |
9 | 2065 |
} |
0 | 2066 |
|
2067 |
$this->escape( $args ); |
|
2068 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
$content_struct = $args[3]; |
0 | 2072 |
|
16 | 2073 |
$user = $this->login( $username, $password ); |
2074 |
if ( ! $user ) { |
|
0 | 2075 |
return $this->error; |
9 | 2076 |
} |
0 | 2077 |
|
5 | 2078 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2079 |
do_action( 'xmlrpc_call', 'wp.newTerm', $args, $this ); |
0 | 2080 |
|
9 | 2081 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2083 |
} |
0 | 2084 |
|
2085 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2086 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
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
|
2089 |
} |
0 | 2090 |
|
2091 |
$taxonomy = (array) $taxonomy; |
|
2092 |
||
16 | 2093 |
// Hold the data of the term. |
0 | 2094 |
$term_data = array(); |
2095 |
||
2096 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
9 | 2097 |
if ( empty( $term_data['name'] ) ) { |
0 | 2098 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2099 |
} |
0 | 2100 |
|
2101 |
if ( isset( $content_struct['parent'] ) ) { |
|
9 | 2102 |
if ( ! $taxonomy['hierarchical'] ) { |
0 | 2103 |
return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
9 | 2104 |
} |
0 | 2105 |
|
2106 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2107 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2108 |
||
2109 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2110 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2111 |
} |
2112 |
||
2113 |
if ( ! $parent_term ) { |
|
0 | 2114 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2115 |
} |
0 | 2116 |
|
2117 |
$term_data['parent'] = $content_struct['parent']; |
|
2118 |
} |
|
2119 |
||
9 | 2120 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2121 |
$term_data['description'] = $content_struct['description']; |
9 | 2122 |
} |
2123 |
||
2124 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2125 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2126 |
} |
2127 |
||
2128 |
$term = wp_insert_term( $term_data['name'], $taxonomy['name'], $term_data ); |
|
2129 |
||
2130 |
if ( is_wp_error( $term ) ) { |
|
0 | 2131 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2132 |
} |
2133 |
||
2134 |
if ( ! $term ) { |
|
16 | 2135 |
return new IXR_Error( 500, __( 'Sorry, the term could not be created.' ) ); |
9 | 2136 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2137 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2138 |
// Add term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2139 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
$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
|
2141 |
} |
0 | 2142 |
|
18 | 2143 |
return (string) $term['term_id']; |
0 | 2144 |
} |
2145 |
||
2146 |
/** |
|
2147 |
* Edit a term. |
|
2148 |
* |
|
2149 |
* @since 3.4.0 |
|
2150 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2151 |
* @see wp_update_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2153 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2154 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2155 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2156 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2158 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
* @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
|
2161 |
* term ''taxonomy'. Optional accepted values include 'name', 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2162 |
* 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2163 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2164 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2165 |
*/ |
5 | 2166 |
public function wp_editTerm( $args ) { |
9 | 2167 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2168 |
return $this->error; |
9 | 2169 |
} |
0 | 2170 |
|
2171 |
$this->escape( $args ); |
|
2172 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
$term_id = (int) $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
$content_struct = $args[4]; |
0 | 2177 |
|
16 | 2178 |
$user = $this->login( $username, $password ); |
2179 |
if ( ! $user ) { |
|
0 | 2180 |
return $this->error; |
9 | 2181 |
} |
0 | 2182 |
|
5 | 2183 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2184 |
do_action( 'xmlrpc_call', 'wp.editTerm', $args, $this ); |
0 | 2185 |
|
9 | 2186 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2187 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2188 |
} |
0 | 2189 |
|
2190 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2191 |
||
2192 |
$taxonomy = (array) $taxonomy; |
|
2193 |
||
16 | 2194 |
// Hold the data of the term. |
0 | 2195 |
$term_data = array(); |
2196 |
||
9 | 2197 |
$term = get_term( $term_id, $content_struct['taxonomy'] ); |
2198 |
||
2199 |
if ( is_wp_error( $term ) ) { |
|
0 | 2200 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2201 |
} |
2202 |
||
2203 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2205 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
if ( ! current_user_can( 'edit_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
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
|
2209 |
} |
0 | 2210 |
|
2211 |
if ( isset( $content_struct['name'] ) ) { |
|
2212 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
2213 |
||
9 | 2214 |
if ( empty( $term_data['name'] ) ) { |
0 | 2215 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2216 |
} |
0 | 2217 |
} |
2218 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
if ( ! empty( $content_struct['parent'] ) ) { |
9 | 2220 |
if ( ! $taxonomy['hierarchical'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
9 | 2222 |
} |
0 | 2223 |
|
2224 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2225 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2226 |
||
2227 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2228 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2229 |
} |
2230 |
||
2231 |
if ( ! $parent_term ) { |
|
0 | 2232 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2233 |
} |
0 | 2234 |
|
2235 |
$term_data['parent'] = $content_struct['parent']; |
|
2236 |
} |
|
2237 |
||
9 | 2238 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2239 |
$term_data['description'] = $content_struct['description']; |
9 | 2240 |
} |
2241 |
||
2242 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2243 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2244 |
} |
2245 |
||
2246 |
$term = wp_update_term( $term_id, $taxonomy['name'], $term_data ); |
|
2247 |
||
2248 |
if ( is_wp_error( $term ) ) { |
|
0 | 2249 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2250 |
} |
2251 |
||
2252 |
if ( ! $term ) { |
|
0 | 2253 |
return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
9 | 2254 |
} |
0 | 2255 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2256 |
// Update term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2257 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2258 |
$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
|
2259 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2260 |
|
0 | 2261 |
return true; |
2262 |
} |
|
2263 |
||
2264 |
/** |
|
2265 |
* Delete a term. |
|
2266 |
* |
|
2267 |
* @since 3.4.0 |
|
2268 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @see wp_delete_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
* |
16 | 2271 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2273 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
* @type string $taxnomy_name Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2279 |
* } |
18 | 2280 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2281 |
*/ |
5 | 2282 |
public function wp_deleteTerm( $args ) { |
9 | 2283 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2284 |
return $this->error; |
9 | 2285 |
} |
0 | 2286 |
|
2287 |
$this->escape( $args ); |
|
2288 |
||
9 | 2289 |
$username = $args[1]; |
2290 |
$password = $args[2]; |
|
2291 |
$taxonomy = $args[3]; |
|
2292 |
$term_id = (int) $args[4]; |
|
2293 |
||
16 | 2294 |
$user = $this->login( $username, $password ); |
2295 |
if ( ! $user ) { |
|
0 | 2296 |
return $this->error; |
9 | 2297 |
} |
0 | 2298 |
|
5 | 2299 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2300 |
do_action( 'xmlrpc_call', 'wp.deleteTerm', $args, $this ); |
0 | 2301 |
|
9 | 2302 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2303 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2304 |
} |
0 | 2305 |
|
2306 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
9 | 2307 |
$term = get_term( $term_id, $taxonomy->name ); |
2308 |
||
2309 |
if ( is_wp_error( $term ) ) { |
|
0 | 2310 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2311 |
} |
2312 |
||
2313 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2315 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2316 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
if ( ! current_user_can( 'delete_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
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
|
2319 |
} |
0 | 2320 |
|
2321 |
$result = wp_delete_term( $term_id, $taxonomy->name ); |
|
2322 |
||
9 | 2323 |
if ( is_wp_error( $result ) ) { |
0 | 2324 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2325 |
} |
2326 |
||
2327 |
if ( ! $result ) { |
|
0 | 2328 |
return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
9 | 2329 |
} |
0 | 2330 |
|
2331 |
return $result; |
|
2332 |
} |
|
2333 |
||
2334 |
/** |
|
2335 |
* Retrieve a term. |
|
2336 |
* |
|
2337 |
* @since 3.4.0 |
|
2338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
* @see get_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
* |
16 | 2341 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2347 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2348 |
* @type string $term_id Term ID. |
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 |
* @return array|IXR_Error IXR_Error on failure, array on success, containing: |
0 | 2351 |
* - 'term_id' |
2352 |
* - 'name' |
|
2353 |
* - 'slug' |
|
2354 |
* - 'term_group' |
|
2355 |
* - 'term_taxonomy_id' |
|
2356 |
* - 'taxonomy' |
|
2357 |
* - 'description' |
|
2358 |
* - 'parent' |
|
2359 |
* - 'count' |
|
2360 |
*/ |
|
5 | 2361 |
public function wp_getTerm( $args ) { |
9 | 2362 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2363 |
return $this->error; |
9 | 2364 |
} |
0 | 2365 |
|
2366 |
$this->escape( $args ); |
|
2367 |
||
9 | 2368 |
$username = $args[1]; |
2369 |
$password = $args[2]; |
|
2370 |
$taxonomy = $args[3]; |
|
2371 |
$term_id = (int) $args[4]; |
|
2372 |
||
16 | 2373 |
$user = $this->login( $username, $password ); |
2374 |
if ( ! $user ) { |
|
0 | 2375 |
return $this->error; |
9 | 2376 |
} |
0 | 2377 |
|
5 | 2378 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2379 |
do_action( 'xmlrpc_call', 'wp.getTerm', $args, $this ); |
0 | 2380 |
|
9 | 2381 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2382 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2383 |
} |
0 | 2384 |
|
2385 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2386 |
||
9 | 2387 |
$term = get_term( $term_id, $taxonomy->name, ARRAY_A ); |
2388 |
||
2389 |
if ( is_wp_error( $term ) ) { |
|
0 | 2390 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2391 |
} |
2392 |
||
2393 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2394 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2395 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2396 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
if ( ! current_user_can( 'assign_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2398 |
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
|
2399 |
} |
0 | 2400 |
|
2401 |
return $this->_prepare_term( $term ); |
|
2402 |
} |
|
2403 |
||
2404 |
/** |
|
2405 |
* Retrieve all terms for a taxonomy. |
|
2406 |
* |
|
2407 |
* @since 3.4.0 |
|
2408 |
* |
|
2409 |
* The optional $filter parameter modifies the query used to retrieve terms. |
|
2410 |
* Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
|
2411 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2412 |
* @see get_terms() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
* |
16 | 2414 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2420 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2421 |
* @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
|
2422 |
* '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
|
2423 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
* @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
0 | 2425 |
*/ |
5 | 2426 |
public function wp_getTerms( $args ) { |
9 | 2427 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2428 |
return $this->error; |
9 | 2429 |
} |
0 | 2430 |
|
2431 |
$this->escape( $args ); |
|
2432 |
||
9 | 2433 |
$username = $args[1]; |
2434 |
$password = $args[2]; |
|
2435 |
$taxonomy = $args[3]; |
|
2436 |
$filter = isset( $args[4] ) ? $args[4] : array(); |
|
2437 |
||
16 | 2438 |
$user = $this->login( $username, $password ); |
2439 |
if ( ! $user ) { |
|
0 | 2440 |
return $this->error; |
9 | 2441 |
} |
0 | 2442 |
|
5 | 2443 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2444 |
do_action( 'xmlrpc_call', 'wp.getTerms', $args, $this ); |
0 | 2445 |
|
9 | 2446 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2448 |
} |
0 | 2449 |
|
2450 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2451 |
||
9 | 2452 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2454 |
} |
0 | 2455 |
|
16 | 2456 |
$query = array( 'taxonomy' => $taxonomy->name ); |
0 | 2457 |
|
9 | 2458 |
if ( isset( $filter['number'] ) ) { |
0 | 2459 |
$query['number'] = absint( $filter['number'] ); |
9 | 2460 |
} |
2461 |
||
2462 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2463 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2464 |
} |
0 | 2465 |
|
2466 |
if ( isset( $filter['orderby'] ) ) { |
|
2467 |
$query['orderby'] = $filter['orderby']; |
|
2468 |
||
9 | 2469 |
if ( isset( $filter['order'] ) ) { |
0 | 2470 |
$query['order'] = $filter['order']; |
9 | 2471 |
} |
2472 |
} |
|
2473 |
||
2474 |
if ( isset( $filter['hide_empty'] ) ) { |
|
0 | 2475 |
$query['hide_empty'] = $filter['hide_empty']; |
9 | 2476 |
} else { |
0 | 2477 |
$query['get'] = 'all'; |
9 | 2478 |
} |
2479 |
||
2480 |
if ( isset( $filter['search'] ) ) { |
|
0 | 2481 |
$query['search'] = $filter['search']; |
9 | 2482 |
} |
0 | 2483 |
|
16 | 2484 |
$terms = get_terms( $query ); |
0 | 2485 |
|
9 | 2486 |
if ( is_wp_error( $terms ) ) { |
0 | 2487 |
return new IXR_Error( 500, $terms->get_error_message() ); |
9 | 2488 |
} |
0 | 2489 |
|
2490 |
$struct = array(); |
|
2491 |
||
2492 |
foreach ( $terms as $term ) { |
|
2493 |
$struct[] = $this->_prepare_term( $term ); |
|
2494 |
} |
|
2495 |
||
2496 |
return $struct; |
|
2497 |
} |
|
2498 |
||
2499 |
/** |
|
2500 |
* Retrieve a taxonomy. |
|
2501 |
* |
|
2502 |
* @since 3.4.0 |
|
2503 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2504 |
* @see get_taxonomy() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2505 |
* |
16 | 2506 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2507 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2508 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2509 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2510 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2513 |
* @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
|
2514 |
* Accepts 'labels', 'cap', 'menu', and 'object_type'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2515 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2516 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2517 |
* @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
0 | 2518 |
*/ |
5 | 2519 |
public function wp_getTaxonomy( $args ) { |
9 | 2520 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2521 |
return $this->error; |
9 | 2522 |
} |
0 | 2523 |
|
2524 |
$this->escape( $args ); |
|
2525 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
$taxonomy = $args[3]; |
0 | 2529 |
|
5 | 2530 |
if ( isset( $args[4] ) ) { |
0 | 2531 |
$fields = $args[4]; |
5 | 2532 |
} else { |
2533 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
* Filters the taxonomy query fields used by the given XML-RPC method. |
5 | 2535 |
* |
2536 |
* @since 3.4.0 |
|
2537 |
* |
|
2538 |
* @param array $fields An array of taxonomy fields to retrieve. |
|
2539 |
* @param string $method The method name. |
|
2540 |
*/ |
|
0 | 2541 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
5 | 2542 |
} |
0 | 2543 |
|
16 | 2544 |
$user = $this->login( $username, $password ); |
2545 |
if ( ! $user ) { |
|
0 | 2546 |
return $this->error; |
9 | 2547 |
} |
0 | 2548 |
|
5 | 2549 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2550 |
do_action( 'xmlrpc_call', 'wp.getTaxonomy', $args, $this ); |
0 | 2551 |
|
9 | 2552 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2553 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2554 |
} |
0 | 2555 |
|
2556 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2557 |
||
9 | 2558 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2559 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2560 |
} |
0 | 2561 |
|
2562 |
return $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2563 |
} |
|
2564 |
||
2565 |
/** |
|
2566 |
* Retrieve all taxonomies. |
|
2567 |
* |
|
2568 |
* @since 3.4.0 |
|
2569 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2570 |
* @see get_taxonomies() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
* |
16 | 2572 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2573 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2575 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2576 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2577 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2578 |
* @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
|
2579 |
* @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
|
2580 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2581 |
* @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
|
2582 |
* by `$fields`, or an IXR_Error instance on failure. |
0 | 2583 |
*/ |
5 | 2584 |
public function wp_getTaxonomies( $args ) { |
9 | 2585 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2586 |
return $this->error; |
9 | 2587 |
} |
0 | 2588 |
|
2589 |
$this->escape( $args ); |
|
2590 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2592 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2593 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 2594 |
|
5 | 2595 |
if ( isset( $args[4] ) ) { |
0 | 2596 |
$fields = $args[4]; |
5 | 2597 |
} else { |
2598 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2599 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
5 | 2600 |
} |
0 | 2601 |
|
16 | 2602 |
$user = $this->login( $username, $password ); |
2603 |
if ( ! $user ) { |
|
0 | 2604 |
return $this->error; |
9 | 2605 |
} |
0 | 2606 |
|
5 | 2607 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2608 |
do_action( 'xmlrpc_call', 'wp.getTaxonomies', $args, $this ); |
0 | 2609 |
|
2610 |
$taxonomies = get_taxonomies( $filter, 'objects' ); |
|
2611 |
||
16 | 2612 |
// Holds all the taxonomy data. |
0 | 2613 |
$struct = array(); |
2614 |
||
2615 |
foreach ( $taxonomies as $taxonomy ) { |
|
16 | 2616 |
// Capability check for post types. |
9 | 2617 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
0 | 2618 |
continue; |
9 | 2619 |
} |
0 | 2620 |
|
2621 |
$struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2622 |
} |
|
2623 |
||
2624 |
return $struct; |
|
2625 |
} |
|
2626 |
||
2627 |
/** |
|
2628 |
* Retrieve a user. |
|
2629 |
* |
|
2630 |
* The optional $fields parameter specifies what fields will be included |
|
2631 |
* in the response array. This should be a list of field names. 'user_id' will |
|
2632 |
* always be included in the response regardless of the value of $fields. |
|
2633 |
* |
|
2634 |
* Instead of, or in addition to, individual field names, conceptual group |
|
2635 |
* names can be used to specify multiple fields. The available conceptual |
|
2636 |
* groups are 'basic' and 'all'. |
|
2637 |
* |
|
2638 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2639 |
* |
16 | 2640 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2641 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2642 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2643 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2645 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
* @type int $user_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
* } |
5 | 2649 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 2650 |
* - 'user_id' |
2651 |
* - 'username' |
|
2652 |
* - 'first_name' |
|
2653 |
* - 'last_name' |
|
2654 |
* - 'registered' |
|
2655 |
* - 'bio' |
|
2656 |
* - 'email' |
|
2657 |
* - 'nickname' |
|
2658 |
* - 'nicename' |
|
2659 |
* - 'url' |
|
2660 |
* - 'display_name' |
|
2661 |
* - 'roles' |
|
2662 |
*/ |
|
5 | 2663 |
public function wp_getUser( $args ) { |
9 | 2664 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2665 |
return $this->error; |
9 | 2666 |
} |
0 | 2667 |
|
2668 |
$this->escape( $args ); |
|
2669 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2670 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2672 |
$user_id = (int) $args[3]; |
0 | 2673 |
|
5 | 2674 |
if ( isset( $args[4] ) ) { |
0 | 2675 |
$fields = $args[4]; |
5 | 2676 |
} else { |
2677 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2678 |
* Filters the default user query fields used by the given XML-RPC method. |
5 | 2679 |
* |
2680 |
* @since 3.5.0 |
|
2681 |
* |
|
2682 |
* @param array $fields User query fields for given method. Default 'all'. |
|
2683 |
* @param string $method The method name. |
|
2684 |
*/ |
|
0 | 2685 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
5 | 2686 |
} |
0 | 2687 |
|
16 | 2688 |
$user = $this->login( $username, $password ); |
2689 |
if ( ! $user ) { |
|
0 | 2690 |
return $this->error; |
9 | 2691 |
} |
0 | 2692 |
|
5 | 2693 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2694 |
do_action( 'xmlrpc_call', 'wp.getUser', $args, $this ); |
0 | 2695 |
|
9 | 2696 |
if ( ! current_user_can( 'edit_user', $user_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2697 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
9 | 2698 |
} |
0 | 2699 |
|
2700 |
$user_data = get_userdata( $user_id ); |
|
2701 |
||
9 | 2702 |
if ( ! $user_data ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
return new IXR_Error( 404, __( 'Invalid user ID.' ) ); |
9 | 2704 |
} |
0 | 2705 |
|
2706 |
return $this->_prepare_user( $user_data, $fields ); |
|
2707 |
} |
|
2708 |
||
2709 |
/** |
|
2710 |
* Retrieve users. |
|
2711 |
* |
|
2712 |
* The optional $filter parameter modifies the query used to retrieve users. |
|
2713 |
* Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', |
|
2714 |
* 'who', 'orderby', and 'order'. |
|
2715 |
* |
|
2716 |
* The optional $fields parameter specifies what fields will be included |
|
2717 |
* in the response array. |
|
2718 |
* |
|
2719 |
* @uses get_users() |
|
2720 |
* @see wp_getUser() for more on $fields and return values |
|
2721 |
* |
|
16 | 2722 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2723 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2724 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2725 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2726 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2727 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2729 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
* } |
5 | 2731 |
* @return array|IXR_Error users data |
0 | 2732 |
*/ |
5 | 2733 |
public function wp_getUsers( $args ) { |
9 | 2734 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2735 |
return $this->error; |
9 | 2736 |
} |
0 | 2737 |
|
2738 |
$this->escape( $args ); |
|
2739 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2740 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2741 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2742 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 2743 |
|
5 | 2744 |
if ( isset( $args[4] ) ) { |
0 | 2745 |
$fields = $args[4]; |
5 | 2746 |
} else { |
2747 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2748 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
5 | 2749 |
} |
0 | 2750 |
|
16 | 2751 |
$user = $this->login( $username, $password ); |
2752 |
if ( ! $user ) { |
|
0 | 2753 |
return $this->error; |
9 | 2754 |
} |
0 | 2755 |
|
5 | 2756 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2757 |
do_action( 'xmlrpc_call', 'wp.getUsers', $args, $this ); |
0 | 2758 |
|
9 | 2759 |
if ( ! current_user_can( 'list_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2760 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
9 | 2761 |
} |
0 | 2762 |
|
2763 |
$query = array( 'fields' => 'all_with_meta' ); |
|
2764 |
||
2765 |
$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50; |
|
2766 |
$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0; |
|
2767 |
||
2768 |
if ( isset( $filter['orderby'] ) ) { |
|
2769 |
$query['orderby'] = $filter['orderby']; |
|
2770 |
||
9 | 2771 |
if ( isset( $filter['order'] ) ) { |
0 | 2772 |
$query['order'] = $filter['order']; |
9 | 2773 |
} |
0 | 2774 |
} |
2775 |
||
2776 |
if ( isset( $filter['role'] ) ) { |
|
9 | 2777 |
if ( get_role( $filter['role'] ) === null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
return new IXR_Error( 403, __( 'Invalid role.' ) ); |
9 | 2779 |
} |
0 | 2780 |
|
2781 |
$query['role'] = $filter['role']; |
|
2782 |
} |
|
2783 |
||
2784 |
if ( isset( $filter['who'] ) ) { |
|
2785 |
$query['who'] = $filter['who']; |
|
2786 |
} |
|
2787 |
||
2788 |
$users = get_users( $query ); |
|
2789 |
||
2790 |
$_users = array(); |
|
2791 |
foreach ( $users as $user_data ) { |
|
9 | 2792 |
if ( current_user_can( 'edit_user', $user_data->ID ) ) { |
0 | 2793 |
$_users[] = $this->_prepare_user( $user_data, $fields ); |
9 | 2794 |
} |
0 | 2795 |
} |
2796 |
return $_users; |
|
2797 |
} |
|
2798 |
||
2799 |
/** |
|
2800 |
* Retrieve information about the requesting user. |
|
2801 |
* |
|
2802 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
* |
16 | 2804 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2806 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2809 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
* } |
5 | 2812 |
* @return array|IXR_Error (@see wp_getUser) |
0 | 2813 |
*/ |
5 | 2814 |
public function wp_getProfile( $args ) { |
9 | 2815 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2816 |
return $this->error; |
9 | 2817 |
} |
0 | 2818 |
|
2819 |
$this->escape( $args ); |
|
2820 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
$password = $args[2]; |
0 | 2823 |
|
5 | 2824 |
if ( isset( $args[3] ) ) { |
0 | 2825 |
$fields = $args[3]; |
5 | 2826 |
} else { |
2827 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2828 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
5 | 2829 |
} |
0 | 2830 |
|
16 | 2831 |
$user = $this->login( $username, $password ); |
2832 |
if ( ! $user ) { |
|
0 | 2833 |
return $this->error; |
9 | 2834 |
} |
0 | 2835 |
|
5 | 2836 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2837 |
do_action( 'xmlrpc_call', 'wp.getProfile', $args, $this ); |
0 | 2838 |
|
9 | 2839 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2841 |
} |
0 | 2842 |
|
2843 |
$user_data = get_userdata( $user->ID ); |
|
2844 |
||
2845 |
return $this->_prepare_user( $user_data, $fields ); |
|
2846 |
} |
|
2847 |
||
2848 |
/** |
|
2849 |
* Edit user's profile. |
|
2850 |
* |
|
2851 |
* @uses wp_update_user() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* |
16 | 2853 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2856 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
* @type array $content_struct It can optionally contain: |
0 | 2860 |
* - 'first_name' |
2861 |
* - 'last_name' |
|
2862 |
* - 'website' |
|
2863 |
* - 'display_name' |
|
2864 |
* - 'nickname' |
|
2865 |
* - 'nicename' |
|
2866 |
* - 'bio' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2867 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
* @return true|IXR_Error True, on success. |
0 | 2869 |
*/ |
5 | 2870 |
public function wp_editProfile( $args ) { |
9 | 2871 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2872 |
return $this->error; |
9 | 2873 |
} |
0 | 2874 |
|
2875 |
$this->escape( $args ); |
|
2876 |
||
2877 |
$username = $args[1]; |
|
2878 |
$password = $args[2]; |
|
2879 |
$content_struct = $args[3]; |
|
2880 |
||
16 | 2881 |
$user = $this->login( $username, $password ); |
2882 |
if ( ! $user ) { |
|
0 | 2883 |
return $this->error; |
9 | 2884 |
} |
0 | 2885 |
|
5 | 2886 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2887 |
do_action( 'xmlrpc_call', 'wp.editProfile', $args, $this ); |
0 | 2888 |
|
9 | 2889 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2890 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2891 |
} |
0 | 2892 |
|
16 | 2893 |
// Holds data of the user. |
9 | 2894 |
$user_data = array(); |
0 | 2895 |
$user_data['ID'] = $user->ID; |
2896 |
||
16 | 2897 |
// Only set the user details if they were given. |
9 | 2898 |
if ( isset( $content_struct['first_name'] ) ) { |
0 | 2899 |
$user_data['first_name'] = $content_struct['first_name']; |
9 | 2900 |
} |
2901 |
||
2902 |
if ( isset( $content_struct['last_name'] ) ) { |
|
0 | 2903 |
$user_data['last_name'] = $content_struct['last_name']; |
9 | 2904 |
} |
2905 |
||
2906 |
if ( isset( $content_struct['url'] ) ) { |
|
0 | 2907 |
$user_data['user_url'] = $content_struct['url']; |
9 | 2908 |
} |
2909 |
||
2910 |
if ( isset( $content_struct['display_name'] ) ) { |
|
0 | 2911 |
$user_data['display_name'] = $content_struct['display_name']; |
9 | 2912 |
} |
2913 |
||
2914 |
if ( isset( $content_struct['nickname'] ) ) { |
|
0 | 2915 |
$user_data['nickname'] = $content_struct['nickname']; |
9 | 2916 |
} |
2917 |
||
2918 |
if ( isset( $content_struct['nicename'] ) ) { |
|
0 | 2919 |
$user_data['user_nicename'] = $content_struct['nicename']; |
9 | 2920 |
} |
2921 |
||
2922 |
if ( isset( $content_struct['bio'] ) ) { |
|
0 | 2923 |
$user_data['description'] = $content_struct['bio']; |
9 | 2924 |
} |
0 | 2925 |
|
2926 |
$result = wp_update_user( $user_data ); |
|
2927 |
||
9 | 2928 |
if ( is_wp_error( $result ) ) { |
0 | 2929 |
return new IXR_Error( 500, $result->get_error_message() ); |
9 | 2930 |
} |
2931 |
||
2932 |
if ( ! $result ) { |
|
16 | 2933 |
return new IXR_Error( 500, __( 'Sorry, the user could not be updated.' ) ); |
9 | 2934 |
} |
0 | 2935 |
|
2936 |
return true; |
|
2937 |
} |
|
2938 |
||
2939 |
/** |
|
2940 |
* Retrieve page. |
|
2941 |
* |
|
2942 |
* @since 2.2.0 |
|
2943 |
* |
|
16 | 2944 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2945 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2946 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
* @type int $page_id |
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 |
* } |
5 | 2952 |
* @return array|IXR_Error |
0 | 2953 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2954 |
public function wp_getPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2955 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2959 |
$password = $args[3]; |
0 | 2960 |
|
16 | 2961 |
$user = $this->login( $username, $password ); |
2962 |
if ( ! $user ) { |
|
0 | 2963 |
return $this->error; |
2964 |
} |
|
2965 |
||
9 | 2966 |
$page = get_post( $page_id ); |
2967 |
if ( ! $page ) { |
|
0 | 2968 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 2969 |
} |
2970 |
||
2971 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 2973 |
} |
0 | 2974 |
|
5 | 2975 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2976 |
do_action( 'xmlrpc_call', 'wp.getPage', $args, $this ); |
0 | 2977 |
|
2978 |
// If we found the page then format the data. |
|
16 | 2979 |
if ( $page->ID && ( 'page' === $page->post_type ) ) { |
0 | 2980 |
return $this->_prepare_page( $page ); |
9 | 2981 |
} else { |
16 | 2982 |
// If the page doesn't exist, indicate that. |
5 | 2983 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2984 |
} |
2985 |
} |
|
2986 |
||
2987 |
/** |
|
2988 |
* Retrieve Pages. |
|
2989 |
* |
|
2990 |
* @since 2.2.0 |
|
2991 |
* |
|
16 | 2992 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2993 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
* @type int $num_pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
* } |
5 | 3000 |
* @return array|IXR_Error |
0 | 3001 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
public function wp_getPages( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
$password = $args[2]; |
9 | 3007 |
$num_pages = isset( $args[3] ) ? (int) $args[3] : 10; |
3008 |
||
16 | 3009 |
$user = $this->login( $username, $password ); |
3010 |
if ( ! $user ) { |
|
0 | 3011 |
return $this->error; |
9 | 3012 |
} |
3013 |
||
3014 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3016 |
} |
0 | 3017 |
|
5 | 3018 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3019 |
do_action( 'xmlrpc_call', 'wp.getPages', $args, $this ); |
0 | 3020 |
|
9 | 3021 |
$pages = get_posts( |
3022 |
array( |
|
3023 |
'post_type' => 'page', |
|
3024 |
'post_status' => 'any', |
|
3025 |
'numberposts' => $num_pages, |
|
3026 |
) |
|
3027 |
); |
|
3028 |
$num_pages = count( $pages ); |
|
0 | 3029 |
|
3030 |
// If we have pages, put together their info. |
|
3031 |
if ( $num_pages >= 1 ) { |
|
3032 |
$pages_struct = array(); |
|
3033 |
||
9 | 3034 |
foreach ( $pages as $page ) { |
3035 |
if ( current_user_can( 'edit_page', $page->ID ) ) { |
|
0 | 3036 |
$pages_struct[] = $this->_prepare_page( $page ); |
9 | 3037 |
} |
0 | 3038 |
} |
3039 |
||
5 | 3040 |
return $pages_struct; |
0 | 3041 |
} |
5 | 3042 |
|
3043 |
return array(); |
|
0 | 3044 |
} |
3045 |
||
3046 |
/** |
|
3047 |
* Create new page. |
|
3048 |
* |
|
3049 |
* @since 2.2.0 |
|
3050 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3051 |
* @see wp_xmlrpc_server::mw_newPost() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
* |
16 | 3053 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3056 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3057 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3058 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3059 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3060 |
* } |
5 | 3061 |
* @return int|IXR_Error |
0 | 3062 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3063 |
public function wp_newPage( $args ) { |
16 | 3064 |
// 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
|
3065 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
$password = $this->escape( $args[2] ); |
0 | 3067 |
|
16 | 3068 |
$user = $this->login( $username, $password ); |
3069 |
if ( ! $user ) { |
|
0 | 3070 |
return $this->error; |
9 | 3071 |
} |
0 | 3072 |
|
5 | 3073 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3074 |
do_action( 'xmlrpc_call', 'wp.newPage', $args, $this ); |
0 | 3075 |
|
3076 |
// Mark this as content for a page. |
|
9 | 3077 |
$args[3]['post_type'] = 'page'; |
0 | 3078 |
|
16 | 3079 |
// Let mw_newPost() do all of the heavy lifting. |
5 | 3080 |
return $this->mw_newPost( $args ); |
0 | 3081 |
} |
3082 |
||
3083 |
/** |
|
3084 |
* Delete page. |
|
3085 |
* |
|
3086 |
* @since 2.2.0 |
|
3087 |
* |
|
16 | 3088 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3089 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3092 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3095 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3096 |
* @return true|IXR_Error True, if success. |
0 | 3097 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3098 |
public function wp_deletePage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3101 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3102 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
$page_id = (int) $args[3]; |
0 | 3104 |
|
16 | 3105 |
$user = $this->login( $username, $password ); |
3106 |
if ( ! $user ) { |
|
0 | 3107 |
return $this->error; |
9 | 3108 |
} |
0 | 3109 |
|
5 | 3110 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3111 |
do_action( 'xmlrpc_call', 'wp.deletePage', $args, $this ); |
0 | 3112 |
|
16 | 3113 |
// Get the current page based on the 'page_id' and |
0 | 3114 |
// make sure it is a page and not a post. |
9 | 3115 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3116 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3117 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3118 |
} |
0 | 3119 |
|
3120 |
// Make sure the user can delete pages. |
|
9 | 3121 |
if ( ! current_user_can( 'delete_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) ); |
9 | 3123 |
} |
0 | 3124 |
|
3125 |
// Attempt to delete the page. |
|
9 | 3126 |
$result = wp_delete_post( $page_id ); |
3127 |
if ( ! $result ) { |
|
5 | 3128 |
return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
9 | 3129 |
} |
5 | 3130 |
|
3131 |
/** |
|
3132 |
* Fires after a page has been successfully deleted via XML-RPC. |
|
3133 |
* |
|
3134 |
* @since 3.4.0 |
|
3135 |
* |
|
3136 |
* @param int $page_id ID of the deleted page. |
|
3137 |
* @param array $args An array of arguments to delete the page. |
|
3138 |
*/ |
|
16 | 3139 |
do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3140 |
|
5 | 3141 |
return true; |
0 | 3142 |
} |
3143 |
||
3144 |
/** |
|
3145 |
* Edit page. |
|
3146 |
* |
|
3147 |
* @since 2.2.0 |
|
3148 |
* |
|
16 | 3149 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3150 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3158 |
* } |
5 | 3159 |
* @return array|IXR_Error |
0 | 3160 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3161 |
public function wp_editPage( $args ) { |
16 | 3162 |
// Items will be escaped in mw_editPost(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3163 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3164 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3167 |
$publish = $args[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3169 |
$escaped_username = $this->escape( $username ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3170 |
$escaped_password = $this->escape( $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3171 |
|
16 | 3172 |
$user = $this->login( $escaped_username, $escaped_password ); |
3173 |
if ( ! $user ) { |
|
0 | 3174 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3175 |
} |
0 | 3176 |
|
5 | 3177 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3178 |
do_action( 'xmlrpc_call', 'wp.editPage', $args, $this ); |
0 | 3179 |
|
3180 |
// Get the page data and make sure it is a page. |
|
9 | 3181 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3182 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3183 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3184 |
} |
0 | 3185 |
|
3186 |
// Make sure the user is allowed to edit pages. |
|
9 | 3187 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 3189 |
} |
0 | 3190 |
|
3191 |
// Mark this as content for a page. |
|
3192 |
$content['post_type'] = 'page'; |
|
3193 |
||
16 | 3194 |
// Arrange args in the way mw_editPost() understands. |
0 | 3195 |
$args = array( |
3196 |
$page_id, |
|
3197 |
$username, |
|
3198 |
$password, |
|
3199 |
$content, |
|
9 | 3200 |
$publish, |
0 | 3201 |
); |
3202 |
||
16 | 3203 |
// Let mw_editPost() do all of the heavy lifting. |
5 | 3204 |
return $this->mw_editPost( $args ); |
0 | 3205 |
} |
3206 |
||
3207 |
/** |
|
3208 |
* Retrieve page list. |
|
3209 |
* |
|
3210 |
* @since 2.2.0 |
|
3211 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
* |
16 | 3214 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3216 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3218 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3219 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
* } |
5 | 3221 |
* @return array|IXR_Error |
0 | 3222 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3223 |
public function wp_getPageList( $args ) { |
0 | 3224 |
global $wpdb; |
3225 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3226 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3227 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3228 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3229 |
$password = $args[2]; |
0 | 3230 |
|
16 | 3231 |
$user = $this->login( $username, $password ); |
3232 |
if ( ! $user ) { |
|
0 | 3233 |
return $this->error; |
9 | 3234 |
} |
3235 |
||
3236 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3237 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3238 |
} |
0 | 3239 |
|
5 | 3240 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3241 |
do_action( 'xmlrpc_call', 'wp.getPageList', $args, $this ); |
0 | 3242 |
|
16 | 3243 |
// Get list of page IDs and titles. |
9 | 3244 |
$page_list = $wpdb->get_results( |
3245 |
" |
|
0 | 3246 |
SELECT ID page_id, |
3247 |
post_title page_title, |
|
3248 |
post_parent page_parent_id, |
|
3249 |
post_date_gmt, |
|
3250 |
post_date, |
|
3251 |
post_status |
|
3252 |
FROM {$wpdb->posts} |
|
3253 |
WHERE post_type = 'page' |
|
3254 |
ORDER BY ID |
|
9 | 3255 |
" |
3256 |
); |
|
0 | 3257 |
|
3258 |
// The date needs to be formatted properly. |
|
9 | 3259 |
$num_pages = count( $page_list ); |
0 | 3260 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
9 | 3261 |
$page_list[ $i ]->dateCreated = $this->_convert_date( $page_list[ $i ]->post_date ); |
3262 |
$page_list[ $i ]->date_created_gmt = $this->_convert_date_gmt( $page_list[ $i ]->post_date_gmt, $page_list[ $i ]->post_date ); |
|
3263 |
||
3264 |
unset( $page_list[ $i ]->post_date_gmt ); |
|
3265 |
unset( $page_list[ $i ]->post_date ); |
|
3266 |
unset( $page_list[ $i ]->post_status ); |
|
0 | 3267 |
} |
3268 |
||
5 | 3269 |
return $page_list; |
0 | 3270 |
} |
3271 |
||
3272 |
/** |
|
3273 |
* Retrieve authors list. |
|
3274 |
* |
|
3275 |
* @since 2.2.0 |
|
3276 |
* |
|
16 | 3277 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3281 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3282 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3283 |
* } |
5 | 3284 |
* @return array|IXR_Error |
0 | 3285 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
public function wp_getAuthors( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
$password = $args[2]; |
0 | 3291 |
|
16 | 3292 |
$user = $this->login( $username, $password ); |
3293 |
if ( ! $user ) { |
|
0 | 3294 |
return $this->error; |
9 | 3295 |
} |
3296 |
||
3297 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 3299 |
} |
5 | 3300 |
|
3301 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 3302 |
do_action( 'xmlrpc_call', 'wp.getAuthors', $args, $this ); |
0 | 3303 |
|
3304 |
$authors = array(); |
|
9 | 3305 |
foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
0 | 3306 |
$authors[] = array( |
9 | 3307 |
'user_id' => $user->ID, |
3308 |
'user_login' => $user->user_login, |
|
3309 |
'display_name' => $user->display_name, |
|
0 | 3310 |
); |
3311 |
} |
|
3312 |
||
3313 |
return $authors; |
|
3314 |
} |
|
3315 |
||
3316 |
/** |
|
3317 |
* Get list of all tags |
|
3318 |
* |
|
3319 |
* @since 2.7.0 |
|
3320 |
* |
|
16 | 3321 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3323 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3326 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
* } |
5 | 3328 |
* @return array|IXR_Error |
0 | 3329 |
*/ |
5 | 3330 |
public function wp_getTags( $args ) { |
0 | 3331 |
$this->escape( $args ); |
3332 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3334 |
$password = $args[2]; |
0 | 3335 |
|
16 | 3336 |
$user = $this->login( $username, $password ); |
3337 |
if ( ! $user ) { |
|
0 | 3338 |
return $this->error; |
9 | 3339 |
} |
3340 |
||
3341 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 3342 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
9 | 3343 |
} |
0 | 3344 |
|
5 | 3345 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3346 |
do_action( 'xmlrpc_call', 'wp.getKeywords', $args, $this ); |
0 | 3347 |
|
3348 |
$tags = array(); |
|
3349 |
||
16 | 3350 |
$all_tags = get_tags(); |
3351 |
if ( $all_tags ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
foreach ( (array) $all_tags as $tag ) { |
9 | 3353 |
$struct = array(); |
3354 |
$struct['tag_id'] = $tag->term_id; |
|
3355 |
$struct['name'] = $tag->name; |
|
3356 |
$struct['count'] = $tag->count; |
|
3357 |
$struct['slug'] = $tag->slug; |
|
3358 |
$struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
|
3359 |
$struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) ); |
|
0 | 3360 |
|
3361 |
$tags[] = $struct; |
|
3362 |
} |
|
3363 |
} |
|
3364 |
||
3365 |
return $tags; |
|
3366 |
} |
|
3367 |
||
3368 |
/** |
|
3369 |
* Create new category. |
|
3370 |
* |
|
3371 |
* @since 2.2.0 |
|
3372 |
* |
|
16 | 3373 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
* } |
5 | 3381 |
* @return int|IXR_Error Category ID. |
0 | 3382 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
public function wp_newCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
$category = $args[3]; |
0 | 3389 |
|
16 | 3390 |
$user = $this->login( $username, $password ); |
3391 |
if ( ! $user ) { |
|
0 | 3392 |
return $this->error; |
9 | 3393 |
} |
0 | 3394 |
|
5 | 3395 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3396 |
do_action( 'xmlrpc_call', 'wp.newCategory', $args, $this ); |
0 | 3397 |
|
3398 |
// 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
|
3399 |
if ( ! current_user_can( 'manage_categories' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
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
|
3401 |
} |
0 | 3402 |
|
16 | 3403 |
// If no slug was provided, make it empty |
3404 |
// so that WordPress will generate one. |
|
9 | 3405 |
if ( empty( $category['slug'] ) ) { |
0 | 3406 |
$category['slug'] = ''; |
9 | 3407 |
} |
0 | 3408 |
|
16 | 3409 |
// If no parent_id was provided, make it empty |
3410 |
// so that it will be a top-level page (no parent). |
|
9 | 3411 |
if ( ! isset( $category['parent_id'] ) ) { |
0 | 3412 |
$category['parent_id'] = ''; |
9 | 3413 |
} |
0 | 3414 |
|
16 | 3415 |
// If no description was provided, make it empty. |
9 | 3416 |
if ( empty( $category['description'] ) ) { |
3417 |
$category['description'] = ''; |
|
3418 |
} |
|
0 | 3419 |
|
3420 |
$new_category = array( |
|
9 | 3421 |
'cat_name' => $category['name'], |
3422 |
'category_nicename' => $category['slug'], |
|
3423 |
'category_parent' => $category['parent_id'], |
|
3424 |
'category_description' => $category['description'], |
|
0 | 3425 |
); |
3426 |
||
9 | 3427 |
$cat_id = wp_insert_category( $new_category, true ); |
0 | 3428 |
if ( is_wp_error( $cat_id ) ) { |
16 | 3429 |
if ( 'term_exists' === $cat_id->get_error_code() ) { |
0 | 3430 |
return (int) $cat_id->get_error_data(); |
9 | 3431 |
} else { |
16 | 3432 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
9 | 3433 |
} |
0 | 3434 |
} elseif ( ! $cat_id ) { |
16 | 3435 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
0 | 3436 |
} |
3437 |
||
5 | 3438 |
/** |
3439 |
* Fires after a new category has been successfully created via XML-RPC. |
|
3440 |
* |
|
3441 |
* @since 3.4.0 |
|
3442 |
* |
|
3443 |
* @param int $cat_id ID of the new category. |
|
3444 |
* @param array $args An array of new category arguments. |
|
3445 |
*/ |
|
16 | 3446 |
do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3447 |
|
3448 |
return $cat_id; |
|
3449 |
} |
|
3450 |
||
3451 |
/** |
|
3452 |
* Remove category. |
|
3453 |
* |
|
3454 |
* @since 2.5.0 |
|
3455 |
* |
|
16 | 3456 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3457 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3458 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3459 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3460 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3461 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
* @type int $category_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3463 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3464 |
* @return bool|IXR_Error See wp_delete_term() for return info. |
0 | 3465 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
public function wp_deleteCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3469 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3470 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
$category_id = (int) $args[3]; |
0 | 3472 |
|
16 | 3473 |
$user = $this->login( $username, $password ); |
3474 |
if ( ! $user ) { |
|
0 | 3475 |
return $this->error; |
9 | 3476 |
} |
0 | 3477 |
|
5 | 3478 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3479 |
do_action( 'xmlrpc_call', 'wp.deleteCategory', $args, $this ); |
0 | 3480 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3481 |
if ( ! current_user_can( 'delete_term', $category_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3482 |
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
|
3483 |
} |
0 | 3484 |
|
3485 |
$status = wp_delete_term( $category_id, 'category' ); |
|
3486 |
||
5 | 3487 |
if ( true == $status ) { |
3488 |
/** |
|
3489 |
* Fires after a category has been successfully deleted via XML-RPC. |
|
3490 |
* |
|
3491 |
* @since 3.4.0 |
|
3492 |
* |
|
3493 |
* @param int $category_id ID of the deleted category. |
|
3494 |
* @param array $args An array of arguments to delete the category. |
|
3495 |
*/ |
|
16 | 3496 |
do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3497 |
} |
0 | 3498 |
|
3499 |
return $status; |
|
3500 |
} |
|
3501 |
||
3502 |
/** |
|
3503 |
* Retrieve category list. |
|
3504 |
* |
|
3505 |
* @since 2.2.0 |
|
3506 |
* |
|
16 | 3507 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3508 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3511 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
* @type int $max_results |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
* } |
5 | 3516 |
* @return array|IXR_Error |
0 | 3517 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
public function wp_suggestCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
$category = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
$max_results = (int) $args[4]; |
0 | 3525 |
|
16 | 3526 |
$user = $this->login( $username, $password ); |
3527 |
if ( ! $user ) { |
|
0 | 3528 |
return $this->error; |
9 | 3529 |
} |
3530 |
||
3531 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
5 | 3532 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 3533 |
} |
5 | 3534 |
|
3535 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 3536 |
do_action( 'xmlrpc_call', 'wp.suggestCategories', $args, $this ); |
0 | 3537 |
|
3538 |
$category_suggestions = array(); |
|
9 | 3539 |
$args = array( |
3540 |
'get' => 'all', |
|
3541 |
'number' => $max_results, |
|
3542 |
'name__like' => $category, |
|
3543 |
); |
|
3544 |
foreach ( (array) get_categories( $args ) as $cat ) { |
|
0 | 3545 |
$category_suggestions[] = array( |
9 | 3546 |
'category_id' => $cat->term_id, |
3547 |
'category_name' => $cat->name, |
|
0 | 3548 |
); |
3549 |
} |
|
3550 |
||
5 | 3551 |
return $category_suggestions; |
0 | 3552 |
} |
3553 |
||
3554 |
/** |
|
3555 |
* Retrieve comment. |
|
3556 |
* |
|
3557 |
* @since 2.7.0 |
|
3558 |
* |
|
16 | 3559 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3560 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3565 |
* @type int $comment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
* } |
5 | 3567 |
* @return array|IXR_Error |
0 | 3568 |
*/ |
9 | 3569 |
public function wp_getComment( $args ) { |
3570 |
$this->escape( $args ); |
|
3571 |
||
3572 |
$username = $args[1]; |
|
3573 |
$password = $args[2]; |
|
3574 |
$comment_id = (int) $args[3]; |
|
0 | 3575 |
|
16 | 3576 |
$user = $this->login( $username, $password ); |
3577 |
if ( ! $user ) { |
|
0 | 3578 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
} |
0 | 3580 |
|
5 | 3581 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3582 |
do_action( 'xmlrpc_call', 'wp.getComment', $args, $this ); |
0 | 3583 |
|
16 | 3584 |
$comment = get_comment( $comment_id ); |
3585 |
if ( ! $comment ) { |
|
0 | 3586 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
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
|
3591 |
} |
0 | 3592 |
|
3593 |
return $this->_prepare_comment( $comment ); |
|
3594 |
} |
|
3595 |
||
3596 |
/** |
|
3597 |
* Retrieve comments. |
|
3598 |
* |
|
5 | 3599 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 3600 |
* array as last argument. |
3601 |
* |
|
3602 |
* Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
|
3603 |
* |
|
3604 |
* The defaults are as follows: |
|
3605 |
* - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
|
3606 |
* - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
|
3607 |
* - '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
|
3608 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 3609 |
* |
3610 |
* @since 2.7.0 |
|
3611 |
* |
|
16 | 3612 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3613 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3616 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3617 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3618 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3619 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
* @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents |
0 | 3621 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3622 |
public function wp_getComments( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3624 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
$password = $args[2]; |
9 | 3627 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
|
16 | 3629 |
$user = $this->login( $username, $password ); |
3630 |
if ( ! $user ) { |
|
0 | 3631 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
} |
0 | 3633 |
|
5 | 3634 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3635 |
do_action( 'xmlrpc_call', 'wp.getComments', $args, $this ); |
0 | 3636 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
if ( isset( $struct['status'] ) ) { |
0 | 3638 |
$status = $struct['status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
} else { |
0 | 3640 |
$status = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3641 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3642 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3643 |
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
} |
0 | 3646 |
|
3647 |
$post_id = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
if ( isset( $struct['post_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
$post_id = absint( $struct['post_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
$post_type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
if ( isset( $struct['post_type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
$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
|
3655 |
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
|
3656 |
return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3658 |
$post_type = $struct['post_type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
} |
0 | 3660 |
|
3661 |
$offset = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
if ( isset( $struct['offset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
$offset = absint( $struct['offset'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
} |
0 | 3665 |
|
3666 |
$number = 10; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3667 |
if ( isset( $struct['number'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3668 |
$number = absint( $struct['number'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
|
9 | 3671 |
$comments = get_comments( |
3672 |
array( |
|
3673 |
'status' => $status, |
|
3674 |
'post_id' => $post_id, |
|
3675 |
'offset' => $offset, |
|
3676 |
'number' => $number, |
|
3677 |
'post_type' => $post_type, |
|
3678 |
) |
|
3679 |
); |
|
0 | 3680 |
|
3681 |
$comments_struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3682 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3683 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3684 |
$comments_struct[] = $this->_prepare_comment( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3685 |
} |
0 | 3686 |
} |
3687 |
||
3688 |
return $comments_struct; |
|
3689 |
} |
|
3690 |
||
3691 |
/** |
|
3692 |
* Delete a comment. |
|
3693 |
* |
|
16 | 3694 |
* 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
|
3695 |
* See wp_delete_comment() for more information on this behavior. |
0 | 3696 |
* |
3697 |
* @since 2.7.0 |
|
3698 |
* |
|
16 | 3699 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3700 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3704 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3705 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3707 |
* @return bool|IXR_Error See wp_delete_comment(). |
0 | 3708 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
public function wp_deleteComment( $args ) { |
9 | 3710 |
$this->escape( $args ); |
3711 |
||
3712 |
$username = $args[1]; |
|
3713 |
$password = $args[2]; |
|
3714 |
$comment_ID = (int) $args[3]; |
|
0 | 3715 |
|
16 | 3716 |
$user = $this->login( $username, $password ); |
3717 |
if ( ! $user ) { |
|
0 | 3718 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
} |
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 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3722 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
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
|
3727 |
} |
0 | 3728 |
|
5 | 3729 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3730 |
do_action( 'xmlrpc_call', 'wp.deleteComment', $args, $this ); |
0 | 3731 |
|
3732 |
$status = wp_delete_comment( $comment_ID ); |
|
3733 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
if ( $status ) { |
5 | 3735 |
/** |
3736 |
* Fires after a comment has been successfully deleted via XML-RPC. |
|
3737 |
* |
|
3738 |
* @since 3.4.0 |
|
3739 |
* |
|
3740 |
* @param int $comment_ID ID of the deleted comment. |
|
3741 |
* @param array $args An array of arguments to delete the comment. |
|
3742 |
*/ |
|
16 | 3743 |
do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3744 |
} |
0 | 3745 |
|
3746 |
return $status; |
|
3747 |
} |
|
3748 |
||
3749 |
/** |
|
3750 |
* Edit comment. |
|
3751 |
* |
|
5 | 3752 |
* Besides the common blog_id (unused), username, and password arguments, it takes a |
0 | 3753 |
* comment_id integer and a content_struct array as last argument. |
3754 |
* |
|
3755 |
* The allowed keys in the content_struct array are: |
|
3756 |
* - 'author' |
|
3757 |
* - 'author_url' |
|
3758 |
* - 'author_email' |
|
3759 |
* - 'content' |
|
3760 |
* - 'date_created_gmt' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
* - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details |
0 | 3762 |
* |
3763 |
* @since 2.7.0 |
|
3764 |
* |
|
16 | 3765 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3773 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
* @return true|IXR_Error True, on success. |
0 | 3775 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
public function wp_editComment( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3777 |
$this->escape( $args ); |
0 | 3778 |
|
9 | 3779 |
$username = $args[1]; |
3780 |
$password = $args[2]; |
|
3781 |
$comment_ID = (int) $args[3]; |
|
0 | 3782 |
$content_struct = $args[4]; |
3783 |
||
16 | 3784 |
$user = $this->login( $username, $password ); |
3785 |
if ( ! $user ) { |
|
0 | 3786 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3787 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3788 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3789 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3790 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3791 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3792 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
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
|
3795 |
} |
0 | 3796 |
|
5 | 3797 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3798 |
do_action( 'xmlrpc_call', 'wp.editComment', $args, $this ); |
9 | 3799 |
$comment = array( |
3800 |
'comment_ID' => $comment_ID, |
|
3801 |
); |
|
3802 |
||
3803 |
if ( isset( $content_struct['status'] ) ) { |
|
0 | 3804 |
$statuses = get_comment_statuses(); |
9 | 3805 |
$statuses = array_keys( $statuses ); |
3806 |
||
16 | 3807 |
if ( ! in_array( $content_struct['status'], $statuses, true ) ) { |
0 | 3808 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
9 | 3809 |
} |
3810 |
||
3811 |
$comment['comment_approved'] = $content_struct['status']; |
|
0 | 3812 |
} |
3813 |
||
16 | 3814 |
// Do some timestamp voodoo. |
9 | 3815 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 3816 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
9 | 3817 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
16 | 3818 |
$comment['comment_date'] = get_date_from_gmt( $dateCreated ); |
3819 |
$comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
9 | 3820 |
} |
3821 |
||
3822 |
if ( isset( $content_struct['content'] ) ) { |
|
3823 |
$comment['comment_content'] = $content_struct['content']; |
|
3824 |
} |
|
3825 |
||
3826 |
if ( isset( $content_struct['author'] ) ) { |
|
3827 |
$comment['comment_author'] = $content_struct['author']; |
|
3828 |
} |
|
3829 |
||
3830 |
if ( isset( $content_struct['author_url'] ) ) { |
|
3831 |
$comment['comment_author_url'] = $content_struct['author_url']; |
|
3832 |
} |
|
3833 |
||
3834 |
if ( isset( $content_struct['author_email'] ) ) { |
|
3835 |
$comment['comment_author_email'] = $content_struct['author_email']; |
|
3836 |
} |
|
3837 |
||
16 | 3838 |
$result = wp_update_comment( $comment, true ); |
9 | 3839 |
if ( is_wp_error( $result ) ) { |
3840 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
3841 |
} |
|
3842 |
||
3843 |
if ( ! $result ) { |
|
16 | 3844 |
return new IXR_Error( 500, __( 'Sorry, the comment could not be updated.' ) ); |
9 | 3845 |
} |
0 | 3846 |
|
5 | 3847 |
/** |
3848 |
* Fires after a comment has been successfully updated via XML-RPC. |
|
3849 |
* |
|
3850 |
* @since 3.4.0 |
|
3851 |
* |
|
3852 |
* @param int $comment_ID ID of the updated comment. |
|
3853 |
* @param array $args An array of arguments to update the comment. |
|
3854 |
*/ |
|
16 | 3855 |
do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3856 |
|
3857 |
return true; |
|
3858 |
} |
|
3859 |
||
3860 |
/** |
|
3861 |
* Create new comment. |
|
3862 |
* |
|
3863 |
* @since 2.7.0 |
|
3864 |
* |
|
16 | 3865 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3870 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3871 |
* @type string|int $post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3872 |
* @type array $content_struct |
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 |
* @return int|IXR_Error See wp_new_comment(). |
0 | 3875 |
*/ |
9 | 3876 |
public function wp_newComment( $args ) { |
3877 |
$this->escape( $args ); |
|
0 | 3878 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
$post = $args[3]; |
0 | 3882 |
$content_struct = $args[4]; |
3883 |
||
5 | 3884 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
* Filters whether to allow anonymous comments over XML-RPC. |
5 | 3886 |
* |
3887 |
* @since 2.7.0 |
|
3888 |
* |
|
3889 |
* @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3890 |
* Default false. |
|
3891 |
*/ |
|
3892 |
$allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
|
0 | 3893 |
|
9 | 3894 |
$user = $this->login( $username, $password ); |
3895 |
||
3896 |
if ( ! $user ) { |
|
0 | 3897 |
$logged_in = false; |
9 | 3898 |
if ( $allow_anon && get_option( 'comment_registration' ) ) { |
16 | 3899 |
return new IXR_Error( 403, __( 'Sorry, you must be logged in to comment.' ) ); |
5 | 3900 |
} elseif ( ! $allow_anon ) { |
0 | 3901 |
return $this->error; |
5 | 3902 |
} |
0 | 3903 |
} else { |
3904 |
$logged_in = true; |
|
3905 |
} |
|
3906 |
||
9 | 3907 |
if ( is_numeric( $post ) ) { |
3908 |
$post_id = absint( $post ); |
|
3909 |
} else { |
|
3910 |
$post_id = url_to_postid( $post ); |
|
3911 |
} |
|
0 | 3912 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
if ( ! $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
if ( ! get_post( $post_id ) ) { |
0 | 3918 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
if ( ! comments_open( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
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
|
3923 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
|
18 | 3925 |
if ( |
3926 |
'publish' === get_post_status( $post_id ) && |
|
3927 |
! current_user_can( 'edit_post', $post_id ) && |
|
3928 |
post_password_required( $post_id ) |
|
3929 |
) { |
|
3930 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
|
3931 |
} |
|
3932 |
||
3933 |
if ( |
|
3934 |
'private' === get_post_status( $post_id ) && |
|
3935 |
! current_user_can( 'read_post', $post_id ) |
|
3936 |
) { |
|
3937 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
$comment = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
'comment_post_ID' => $post_id, |
18 | 3942 |
'comment_content' => trim( $content_struct['content'] ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
); |
0 | 3944 |
|
3945 |
if ( $logged_in ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
$display_name = $user->display_name; |
9 | 3947 |
$user_email = $user->user_email; |
3948 |
$user_url = $user->user_url; |
|
3949 |
||
3950 |
$comment['comment_author'] = $this->escape( $display_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
$comment['comment_author_email'] = $this->escape( $user_email ); |
9 | 3952 |
$comment['comment_author_url'] = $this->escape( $user_url ); |
3953 |
$comment['user_ID'] = $user->ID; |
|
0 | 3954 |
} else { |
3955 |
$comment['comment_author'] = ''; |
|
9 | 3956 |
if ( isset( $content_struct['author'] ) ) { |
0 | 3957 |
$comment['comment_author'] = $content_struct['author']; |
9 | 3958 |
} |
0 | 3959 |
|
3960 |
$comment['comment_author_email'] = ''; |
|
9 | 3961 |
if ( isset( $content_struct['author_email'] ) ) { |
0 | 3962 |
$comment['comment_author_email'] = $content_struct['author_email']; |
9 | 3963 |
} |
0 | 3964 |
|
3965 |
$comment['comment_author_url'] = ''; |
|
9 | 3966 |
if ( isset( $content_struct['author_url'] ) ) { |
0 | 3967 |
$comment['comment_author_url'] = $content_struct['author_url']; |
9 | 3968 |
} |
0 | 3969 |
|
3970 |
$comment['user_ID'] = 0; |
|
3971 |
||
9 | 3972 |
if ( get_option( 'require_name_email' ) ) { |
18 | 3973 |
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
|
3974 |
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
9 | 3975 |
} elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
9 | 3977 |
} |
0 | 3978 |
} |
3979 |
} |
|
3980 |
||
9 | 3981 |
$comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
0 | 3982 |
|
18 | 3983 |
/** This filter is documented in wp-includes/comment.php */ |
3984 |
$allow_empty = apply_filters( 'allow_empty_comment', false, $comment ); |
|
3985 |
||
3986 |
if ( ! $allow_empty && '' === $comment['comment_content'] ) { |
|
3987 |
return new IXR_Error( 403, __( 'Comment is required.' ) ); |
|
3988 |
} |
|
3989 |
||
5 | 3990 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3991 |
do_action( 'xmlrpc_call', 'wp.newComment', $args, $this ); |
0 | 3992 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
$comment_ID = wp_new_comment( $comment, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
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
|
3996 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
if ( ! $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
return new IXR_Error( 403, __( 'Something went wrong.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
} |
0 | 4001 |
|
5 | 4002 |
/** |
4003 |
* Fires after a new comment has been successfully created via XML-RPC. |
|
4004 |
* |
|
4005 |
* @since 3.4.0 |
|
4006 |
* |
|
4007 |
* @param int $comment_ID ID of the new comment. |
|
4008 |
* @param array $args An array of new comment arguments. |
|
4009 |
*/ |
|
16 | 4010 |
do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 4011 |
|
4012 |
return $comment_ID; |
|
4013 |
} |
|
4014 |
||
4015 |
/** |
|
4016 |
* Retrieve all of the comment status. |
|
4017 |
* |
|
4018 |
* @since 2.7.0 |
|
4019 |
* |
|
16 | 4020 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4021 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4022 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4023 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4024 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4025 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4026 |
* } |
5 | 4027 |
* @return array|IXR_Error |
0 | 4028 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4029 |
public function wp_getCommentStatusList( $args ) { |
0 | 4030 |
$this->escape( $args ); |
4031 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4032 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4033 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4034 |
|
16 | 4035 |
$user = $this->login( $username, $password ); |
4036 |
if ( ! $user ) { |
|
0 | 4037 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4038 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4039 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4040 |
if ( ! current_user_can( 'publish_posts' ) ) { |
9 | 4041 |
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
|
4042 |
} |
0 | 4043 |
|
5 | 4044 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4045 |
do_action( 'xmlrpc_call', 'wp.getCommentStatusList', $args, $this ); |
0 | 4046 |
|
4047 |
return get_comment_statuses(); |
|
4048 |
} |
|
4049 |
||
4050 |
/** |
|
4051 |
* Retrieve comment count. |
|
4052 |
* |
|
4053 |
* @since 2.5.0 |
|
4054 |
* |
|
16 | 4055 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4058 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4059 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4060 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4061 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4062 |
* } |
5 | 4063 |
* @return array|IXR_Error |
0 | 4064 |
*/ |
5 | 4065 |
public function wp_getCommentCount( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4066 |
$this->escape( $args ); |
0 | 4067 |
|
9 | 4068 |
$username = $args[1]; |
4069 |
$password = $args[2]; |
|
4070 |
$post_id = (int) $args[3]; |
|
0 | 4071 |
|
16 | 4072 |
$user = $this->login( $username, $password ); |
4073 |
if ( ! $user ) { |
|
0 | 4074 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
} |
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 |
$post = get_post( $post_id, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4078 |
if ( empty( $post['ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4079 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4080 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4081 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4082 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 4083 |
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
|
4084 |
} |
0 | 4085 |
|
5 | 4086 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4087 |
do_action( 'xmlrpc_call', 'wp.getCommentCount', $args, $this ); |
0 | 4088 |
|
4089 |
$count = wp_count_comments( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4090 |
|
0 | 4091 |
return array( |
9 | 4092 |
'approved' => $count->approved, |
0 | 4093 |
'awaiting_moderation' => $count->moderated, |
9 | 4094 |
'spam' => $count->spam, |
4095 |
'total_comments' => $count->total_comments, |
|
0 | 4096 |
); |
4097 |
} |
|
4098 |
||
4099 |
/** |
|
4100 |
* Retrieve post statuses. |
|
4101 |
* |
|
4102 |
* @since 2.5.0 |
|
4103 |
* |
|
16 | 4104 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4105 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4106 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4107 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4108 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4109 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4110 |
* } |
5 | 4111 |
* @return array|IXR_Error |
0 | 4112 |
*/ |
5 | 4113 |
public function wp_getPostStatusList( $args ) { |
0 | 4114 |
$this->escape( $args ); |
4115 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4116 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4117 |
$password = $args[2]; |
0 | 4118 |
|
16 | 4119 |
$user = $this->login( $username, $password ); |
4120 |
if ( ! $user ) { |
|
0 | 4121 |
return $this->error; |
9 | 4122 |
} |
4123 |
||
4124 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4125 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4126 |
} |
|
0 | 4127 |
|
5 | 4128 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4129 |
do_action( 'xmlrpc_call', 'wp.getPostStatusList', $args, $this ); |
0 | 4130 |
|
4131 |
return get_post_statuses(); |
|
4132 |
} |
|
4133 |
||
4134 |
/** |
|
4135 |
* Retrieve page statuses. |
|
4136 |
* |
|
4137 |
* @since 2.5.0 |
|
4138 |
* |
|
16 | 4139 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4141 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4142 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4143 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4144 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
* } |
5 | 4146 |
* @return array|IXR_Error |
0 | 4147 |
*/ |
5 | 4148 |
public function wp_getPageStatusList( $args ) { |
0 | 4149 |
$this->escape( $args ); |
4150 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
$password = $args[2]; |
0 | 4153 |
|
16 | 4154 |
$user = $this->login( $username, $password ); |
4155 |
if ( ! $user ) { |
|
0 | 4156 |
return $this->error; |
9 | 4157 |
} |
4158 |
||
4159 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4160 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4161 |
} |
|
0 | 4162 |
|
5 | 4163 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4164 |
do_action( 'xmlrpc_call', 'wp.getPageStatusList', $args, $this ); |
0 | 4165 |
|
4166 |
return get_page_statuses(); |
|
4167 |
} |
|
4168 |
||
4169 |
/** |
|
4170 |
* Retrieve page templates. |
|
4171 |
* |
|
4172 |
* @since 2.6.0 |
|
4173 |
* |
|
16 | 4174 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4175 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4176 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4177 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4178 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4179 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4180 |
* } |
5 | 4181 |
* @return array|IXR_Error |
0 | 4182 |
*/ |
5 | 4183 |
public function wp_getPageTemplates( $args ) { |
0 | 4184 |
$this->escape( $args ); |
4185 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4186 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4187 |
$password = $args[2]; |
0 | 4188 |
|
16 | 4189 |
$user = $this->login( $username, $password ); |
4190 |
if ( ! $user ) { |
|
0 | 4191 |
return $this->error; |
9 | 4192 |
} |
4193 |
||
4194 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4195 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4196 |
} |
|
4197 |
||
4198 |
$templates = get_page_templates(); |
|
0 | 4199 |
$templates['Default'] = 'default'; |
4200 |
||
4201 |
return $templates; |
|
4202 |
} |
|
4203 |
||
4204 |
/** |
|
4205 |
* Retrieve blog options. |
|
4206 |
* |
|
4207 |
* @since 2.6.0 |
|
4208 |
* |
|
16 | 4209 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
* } |
5 | 4217 |
* @return array|IXR_Error |
0 | 4218 |
*/ |
5 | 4219 |
public function wp_getOptions( $args ) { |
0 | 4220 |
$this->escape( $args ); |
4221 |
||
9 | 4222 |
$username = $args[1]; |
4223 |
$password = $args[2]; |
|
4224 |
$options = isset( $args[3] ) ? (array) $args[3] : array(); |
|
4225 |
||
16 | 4226 |
$user = $this->login( $username, $password ); |
4227 |
if ( ! $user ) { |
|
0 | 4228 |
return $this->error; |
9 | 4229 |
} |
0 | 4230 |
|
16 | 4231 |
// If no specific options where asked for, return all of them. |
9 | 4232 |
if ( count( $options ) == 0 ) { |
4233 |
$options = array_keys( $this->blog_options ); |
|
4234 |
} |
|
4235 |
||
4236 |
return $this->_getOptions( $options ); |
|
0 | 4237 |
} |
4238 |
||
4239 |
/** |
|
4240 |
* Retrieve blog options value from list. |
|
4241 |
* |
|
4242 |
* @since 2.6.0 |
|
4243 |
* |
|
4244 |
* @param array $options Options to retrieve. |
|
4245 |
* @return array |
|
4246 |
*/ |
|
9 | 4247 |
public function _getOptions( $options ) { |
4248 |
$data = array(); |
|
0 | 4249 |
$can_manage = current_user_can( 'manage_options' ); |
4250 |
foreach ( $options as $option ) { |
|
4251 |
if ( array_key_exists( $option, $this->blog_options ) ) { |
|
9 | 4252 |
$data[ $option ] = $this->blog_options[ $option ]; |
16 | 4253 |
// Is the value static or dynamic? |
9 | 4254 |
if ( isset( $data[ $option ]['option'] ) ) { |
4255 |
$data[ $option ]['value'] = get_option( $data[ $option ]['option'] ); |
|
4256 |
unset( $data[ $option ]['option'] ); |
|
0 | 4257 |
} |
4258 |
||
9 | 4259 |
if ( ! $can_manage ) { |
4260 |
$data[ $option ]['readonly'] = true; |
|
4261 |
} |
|
0 | 4262 |
} |
4263 |
} |
|
4264 |
||
4265 |
return $data; |
|
4266 |
} |
|
4267 |
||
4268 |
/** |
|
4269 |
* Update blog options. |
|
4270 |
* |
|
4271 |
* @since 2.6.0 |
|
4272 |
* |
|
16 | 4273 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4274 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4275 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4276 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4277 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4278 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4279 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4280 |
* } |
5 | 4281 |
* @return array|IXR_Error |
0 | 4282 |
*/ |
5 | 4283 |
public function wp_setOptions( $args ) { |
0 | 4284 |
$this->escape( $args ); |
4285 |
||
9 | 4286 |
$username = $args[1]; |
4287 |
$password = $args[2]; |
|
4288 |
$options = (array) $args[3]; |
|
4289 |
||
16 | 4290 |
$user = $this->login( $username, $password ); |
4291 |
if ( ! $user ) { |
|
0 | 4292 |
return $this->error; |
9 | 4293 |
} |
4294 |
||
4295 |
if ( ! current_user_can( 'manage_options' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4296 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) ); |
9 | 4297 |
} |
0 | 4298 |
|
5 | 4299 |
$option_names = array(); |
0 | 4300 |
foreach ( $options as $o_name => $o_value ) { |
4301 |
$option_names[] = $o_name; |
|
9 | 4302 |
if ( ! array_key_exists( $o_name, $this->blog_options ) ) { |
0 | 4303 |
continue; |
9 | 4304 |
} |
4305 |
||
16 | 4306 |
if ( true == $this->blog_options[ $o_name ]['readonly'] ) { |
0 | 4307 |
continue; |
9 | 4308 |
} |
4309 |
||
4310 |
update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) ); |
|
0 | 4311 |
} |
4312 |
||
16 | 4313 |
// Now return the updated values. |
9 | 4314 |
return $this->_getOptions( $option_names ); |
0 | 4315 |
} |
4316 |
||
4317 |
/** |
|
4318 |
* Retrieve a media item by ID |
|
4319 |
* |
|
4320 |
* @since 3.1.0 |
|
4321 |
* |
|
16 | 4322 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4323 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4324 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4325 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4326 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4327 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4328 |
* @type int $attachment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4329 |
* } |
5 | 4330 |
* @return array|IXR_Error Associative array contains: |
0 | 4331 |
* - 'date_created_gmt' |
4332 |
* - 'parent' |
|
4333 |
* - 'link' |
|
4334 |
* - 'thumbnail' |
|
4335 |
* - 'title' |
|
4336 |
* - 'caption' |
|
4337 |
* - 'description' |
|
4338 |
* - 'metadata' |
|
4339 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4340 |
public function wp_getMediaItem( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4341 |
$this->escape( $args ); |
0 | 4342 |
|
9 | 4343 |
$username = $args[1]; |
4344 |
$password = $args[2]; |
|
4345 |
$attachment_id = (int) $args[3]; |
|
4346 |
||
16 | 4347 |
$user = $this->login( $username, $password ); |
4348 |
if ( ! $user ) { |
|
0 | 4349 |
return $this->error; |
9 | 4350 |
} |
4351 |
||
4352 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4353 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4354 |
} |
0 | 4355 |
|
5 | 4356 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4357 |
do_action( 'xmlrpc_call', 'wp.getMediaItem', $args, $this ); |
0 | 4358 |
|
16 | 4359 |
$attachment = get_post( $attachment_id ); |
18 | 4360 |
if ( ! $attachment || 'attachment' !== $attachment->post_type ) { |
0 | 4361 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 4362 |
} |
0 | 4363 |
|
4364 |
return $this->_prepare_media_item( $attachment ); |
|
4365 |
} |
|
4366 |
||
4367 |
/** |
|
4368 |
* Retrieves a collection of media library items (or attachments) |
|
4369 |
* |
|
5 | 4370 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 4371 |
* array as last argument. |
4372 |
* |
|
4373 |
* Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
|
4374 |
* |
|
4375 |
* The defaults are as follows: |
|
4376 |
* - '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
|
4377 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 4378 |
* - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
4379 |
* - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
|
4380 |
* |
|
4381 |
* @since 3.1.0 |
|
4382 |
* |
|
16 | 4383 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4385 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4386 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4387 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4389 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4390 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4391 |
* @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents |
0 | 4392 |
*/ |
9 | 4393 |
public function wp_getMediaLibrary( $args ) { |
4394 |
$this->escape( $args ); |
|
4395 |
||
4396 |
$username = $args[1]; |
|
4397 |
$password = $args[2]; |
|
4398 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
|
4399 |
||
16 | 4400 |
$user = $this->login( $username, $password ); |
4401 |
if ( ! $user ) { |
|
0 | 4402 |
return $this->error; |
9 | 4403 |
} |
4404 |
||
4405 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4406 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4407 |
} |
0 | 4408 |
|
5 | 4409 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4410 |
do_action( 'xmlrpc_call', 'wp.getMediaLibrary', $args, $this ); |
0 | 4411 |
|
9 | 4412 |
$parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4413 |
$mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
|
4414 |
$offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
|
4415 |
$number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
|
4416 |
||
4417 |
$attachments = get_posts( |
|
4418 |
array( |
|
4419 |
'post_type' => 'attachment', |
|
4420 |
'post_parent' => $parent_id, |
|
4421 |
'offset' => $offset, |
|
4422 |
'numberposts' => $number, |
|
4423 |
'post_mime_type' => $mime_type, |
|
4424 |
) |
|
4425 |
); |
|
0 | 4426 |
|
4427 |
$attachments_struct = array(); |
|
4428 |
||
9 | 4429 |
foreach ( $attachments as $attachment ) { |
0 | 4430 |
$attachments_struct[] = $this->_prepare_media_item( $attachment ); |
9 | 4431 |
} |
0 | 4432 |
|
4433 |
return $attachments_struct; |
|
4434 |
} |
|
4435 |
||
4436 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4437 |
* 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
|
4438 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4439 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4440 |
* |
16 | 4441 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4442 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4443 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4444 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4445 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4446 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4447 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
* @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
|
4449 |
*/ |
5 | 4450 |
public function wp_getPostFormats( $args ) { |
0 | 4451 |
$this->escape( $args ); |
4452 |
||
4453 |
$username = $args[1]; |
|
4454 |
$password = $args[2]; |
|
4455 |
||
16 | 4456 |
$user = $this->login( $username, $password ); |
4457 |
if ( ! $user ) { |
|
0 | 4458 |
return $this->error; |
9 | 4459 |
} |
4460 |
||
4461 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4462 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4463 |
} |
|
0 | 4464 |
|
5 | 4465 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4466 |
do_action( 'xmlrpc_call', 'wp.getPostFormats', $args, $this ); |
0 | 4467 |
|
4468 |
$formats = get_post_format_strings(); |
|
4469 |
||
16 | 4470 |
// Find out if they want a list of currently supports formats. |
0 | 4471 |
if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4472 |
if ( $args[3]['show-supported'] ) { |
|
4473 |
if ( current_theme_supports( 'post-formats' ) ) { |
|
4474 |
$supported = get_theme_support( 'post-formats' ); |
|
4475 |
||
9 | 4476 |
$data = array(); |
4477 |
$data['all'] = $formats; |
|
0 | 4478 |
$data['supported'] = $supported[0]; |
4479 |
||
4480 |
$formats = $data; |
|
4481 |
} |
|
4482 |
} |
|
4483 |
} |
|
4484 |
||
4485 |
return $formats; |
|
4486 |
} |
|
4487 |
||
4488 |
/** |
|
4489 |
* Retrieves a post type |
|
4490 |
* |
|
4491 |
* @since 3.4.0 |
|
4492 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4493 |
* @see get_post_type_object() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4494 |
* |
16 | 4495 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4496 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4497 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4500 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4501 |
* @type string $post_type_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4502 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
* } |
5 | 4504 |
* @return array|IXR_Error Array contains: |
0 | 4505 |
* - 'labels' |
4506 |
* - 'description' |
|
4507 |
* - 'capability_type' |
|
4508 |
* - 'cap' |
|
4509 |
* - 'map_meta_cap' |
|
4510 |
* - 'hierarchical' |
|
4511 |
* - 'menu_position' |
|
4512 |
* - 'taxonomies' |
|
4513 |
* - 'supports' |
|
4514 |
*/ |
|
5 | 4515 |
public function wp_getPostType( $args ) { |
9 | 4516 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4517 |
return $this->error; |
9 | 4518 |
} |
0 | 4519 |
|
4520 |
$this->escape( $args ); |
|
4521 |
||
4522 |
$username = $args[1]; |
|
4523 |
$password = $args[2]; |
|
4524 |
$post_type_name = $args[3]; |
|
4525 |
||
5 | 4526 |
if ( isset( $args[4] ) ) { |
0 | 4527 |
$fields = $args[4]; |
5 | 4528 |
} else { |
4529 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
* Filters the default query fields used by the given XML-RPC method. |
5 | 4531 |
* |
4532 |
* @since 3.4.0 |
|
4533 |
* |
|
4534 |
* @param array $fields An array of post type query fields for the given method. |
|
4535 |
* @param string $method The method name. |
|
4536 |
*/ |
|
0 | 4537 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
5 | 4538 |
} |
0 | 4539 |
|
16 | 4540 |
$user = $this->login( $username, $password ); |
4541 |
if ( ! $user ) { |
|
0 | 4542 |
return $this->error; |
9 | 4543 |
} |
0 | 4544 |
|
5 | 4545 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4546 |
do_action( 'xmlrpc_call', 'wp.getPostType', $args, $this ); |
0 | 4547 |
|
9 | 4548 |
if ( ! post_type_exists( $post_type_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4549 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 4550 |
} |
0 | 4551 |
|
4552 |
$post_type = get_post_type_object( $post_type_name ); |
|
4553 |
||
9 | 4554 |
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
|
4555 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 4556 |
} |
0 | 4557 |
|
4558 |
return $this->_prepare_post_type( $post_type, $fields ); |
|
4559 |
} |
|
4560 |
||
4561 |
/** |
|
4562 |
* Retrieves a post types |
|
4563 |
* |
|
4564 |
* @since 3.4.0 |
|
4565 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4566 |
* @see get_post_types() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4567 |
* |
16 | 4568 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4569 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4570 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4571 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4575 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
* } |
5 | 4577 |
* @return array|IXR_Error |
0 | 4578 |
*/ |
5 | 4579 |
public function wp_getPostTypes( $args ) { |
9 | 4580 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4581 |
return $this->error; |
9 | 4582 |
} |
0 | 4583 |
|
4584 |
$this->escape( $args ); |
|
4585 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 4589 |
|
5 | 4590 |
if ( isset( $args[4] ) ) { |
0 | 4591 |
$fields = $args[4]; |
5 | 4592 |
} else { |
4593 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 4594 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
5 | 4595 |
} |
0 | 4596 |
|
16 | 4597 |
$user = $this->login( $username, $password ); |
4598 |
if ( ! $user ) { |
|
0 | 4599 |
return $this->error; |
9 | 4600 |
} |
0 | 4601 |
|
5 | 4602 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4603 |
do_action( 'xmlrpc_call', 'wp.getPostTypes', $args, $this ); |
0 | 4604 |
|
4605 |
$post_types = get_post_types( $filter, 'objects' ); |
|
4606 |
||
4607 |
$struct = array(); |
|
4608 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4609 |
foreach ( $post_types as $post_type ) { |
9 | 4610 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 4611 |
continue; |
9 | 4612 |
} |
4613 |
||
4614 |
$struct[ $post_type->name ] = $this->_prepare_post_type( $post_type, $fields ); |
|
0 | 4615 |
} |
4616 |
||
4617 |
return $struct; |
|
4618 |
} |
|
4619 |
||
4620 |
/** |
|
4621 |
* Retrieve revisions for a specific post. |
|
4622 |
* |
|
4623 |
* @since 3.5.0 |
|
4624 |
* |
|
4625 |
* The optional $fields parameter specifies what fields will be included |
|
4626 |
* in the response array. |
|
4627 |
* |
|
4628 |
* @uses wp_get_post_revisions() |
|
4629 |
* @see wp_getPost() for more on $fields |
|
4630 |
* |
|
16 | 4631 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4632 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4633 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4634 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4635 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4636 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4637 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4638 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4639 |
* } |
5 | 4640 |
* @return array|IXR_Error contains a collection of posts. |
0 | 4641 |
*/ |
5 | 4642 |
public function wp_getRevisions( $args ) { |
9 | 4643 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4644 |
return $this->error; |
9 | 4645 |
} |
0 | 4646 |
|
4647 |
$this->escape( $args ); |
|
4648 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4649 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4650 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4651 |
$post_id = (int) $args[3]; |
0 | 4652 |
|
5 | 4653 |
if ( isset( $args[4] ) ) { |
0 | 4654 |
$fields = $args[4]; |
5 | 4655 |
} else { |
4656 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4657 |
* Filters the default revision query fields used by the given XML-RPC method. |
5 | 4658 |
* |
4659 |
* @since 3.5.0 |
|
4660 |
* |
|
4661 |
* @param array $field An array of revision query fields. |
|
4662 |
* @param string $method The method name. |
|
4663 |
*/ |
|
0 | 4664 |
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
5 | 4665 |
} |
0 | 4666 |
|
16 | 4667 |
$user = $this->login( $username, $password ); |
4668 |
if ( ! $user ) { |
|
0 | 4669 |
return $this->error; |
9 | 4670 |
} |
0 | 4671 |
|
5 | 4672 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4673 |
do_action( 'xmlrpc_call', 'wp.getRevisions', $args, $this ); |
0 | 4674 |
|
16 | 4675 |
$post = get_post( $post_id ); |
4676 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4677 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4678 |
} |
4679 |
||
4680 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
0 | 4681 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4682 |
} |
0 | 4683 |
|
4684 |
// Check if revisions are enabled. |
|
9 | 4685 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4686 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4687 |
} |
0 | 4688 |
|
4689 |
$revisions = wp_get_post_revisions( $post_id ); |
|
4690 |
||
9 | 4691 |
if ( ! $revisions ) { |
0 | 4692 |
return array(); |
9 | 4693 |
} |
0 | 4694 |
|
4695 |
$struct = array(); |
|
4696 |
||
4697 |
foreach ( $revisions as $revision ) { |
|
9 | 4698 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
0 | 4699 |
continue; |
9 | 4700 |
} |
0 | 4701 |
|
16 | 4702 |
// Skip autosaves. |
9 | 4703 |
if ( wp_is_post_autosave( $revision ) ) { |
0 | 4704 |
continue; |
9 | 4705 |
} |
0 | 4706 |
|
4707 |
$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); |
|
4708 |
} |
|
4709 |
||
4710 |
return $struct; |
|
4711 |
} |
|
4712 |
||
4713 |
/** |
|
4714 |
* Restore a post revision |
|
4715 |
* |
|
4716 |
* @since 3.5.0 |
|
4717 |
* |
|
4718 |
* @uses wp_restore_post_revision() |
|
4719 |
* |
|
16 | 4720 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4721 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4722 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4723 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4724 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4725 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4726 |
* @type int $revision_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4727 |
* } |
5 | 4728 |
* @return bool|IXR_Error false if there was an error restoring, true if success. |
0 | 4729 |
*/ |
5 | 4730 |
public function wp_restoreRevision( $args ) { |
9 | 4731 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4732 |
return $this->error; |
9 | 4733 |
} |
0 | 4734 |
|
4735 |
$this->escape( $args ); |
|
4736 |
||
4737 |
$username = $args[1]; |
|
4738 |
$password = $args[2]; |
|
4739 |
$revision_id = (int) $args[3]; |
|
4740 |
||
16 | 4741 |
$user = $this->login( $username, $password ); |
4742 |
if ( ! $user ) { |
|
0 | 4743 |
return $this->error; |
9 | 4744 |
} |
0 | 4745 |
|
5 | 4746 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4747 |
do_action( 'xmlrpc_call', 'wp.restoreRevision', $args, $this ); |
0 | 4748 |
|
16 | 4749 |
$revision = wp_get_post_revision( $revision_id ); |
4750 |
if ( ! $revision ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4751 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4752 |
} |
4753 |
||
4754 |
if ( wp_is_post_autosave( $revision ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4755 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4756 |
} |
4757 |
||
16 | 4758 |
$post = get_post( $revision->post_parent ); |
4759 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4760 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4761 |
} |
4762 |
||
4763 |
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
|
4764 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4765 |
} |
0 | 4766 |
|
4767 |
// Check if revisions are disabled. |
|
9 | 4768 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4769 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4770 |
} |
0 | 4771 |
|
4772 |
$post = wp_restore_post_revision( $revision_id ); |
|
4773 |
||
4774 |
return (bool) $post; |
|
4775 |
} |
|
4776 |
||
16 | 4777 |
/* |
4778 |
* Blogger API functions. |
|
4779 |
* Specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
|
0 | 4780 |
*/ |
4781 |
||
4782 |
/** |
|
4783 |
* Retrieve blogs that user owns. |
|
4784 |
* |
|
4785 |
* Will make more sense once we support multiple blogs. |
|
4786 |
* |
|
4787 |
* @since 1.5.0 |
|
4788 |
* |
|
16 | 4789 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4790 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4791 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4792 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4793 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4794 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4795 |
* } |
5 | 4796 |
* @return array|IXR_Error |
0 | 4797 |
*/ |
9 | 4798 |
public function blogger_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4800 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4801 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4802 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4803 |
if ( is_multisite() ) { |
9 | 4804 |
return $this->_multisite_getUsersBlogs( $args ); |
4805 |
} |
|
4806 |
||
4807 |
$this->escape( $args ); |
|
0 | 4808 |
|
4809 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4810 |
$password = $args[2]; |
0 | 4811 |
|
16 | 4812 |
$user = $this->login( $username, $password ); |
4813 |
if ( ! $user ) { |
|
0 | 4814 |
return $this->error; |
9 | 4815 |
} |
0 | 4816 |
|
5 | 4817 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4818 |
do_action( 'xmlrpc_call', 'blogger.getUsersBlogs', $args, $this ); |
0 | 4819 |
|
9 | 4820 |
$is_admin = current_user_can( 'manage_options' ); |
0 | 4821 |
|
4822 |
$struct = array( |
|
4823 |
'isAdmin' => $is_admin, |
|
9 | 4824 |
'url' => get_option( 'home' ) . '/', |
0 | 4825 |
'blogid' => '1', |
9 | 4826 |
'blogName' => get_option( 'blogname' ), |
0 | 4827 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
4828 |
); |
|
4829 |
||
9 | 4830 |
return array( $struct ); |
0 | 4831 |
} |
4832 |
||
4833 |
/** |
|
4834 |
* Private function for retrieving a users blogs for multisite setups |
|
4835 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4836 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4837 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4838 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4839 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4841 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4843 |
* } |
5 | 4844 |
* @return array|IXR_Error |
0 | 4845 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4846 |
protected function _multisite_getUsersBlogs( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4847 |
$current_blog = get_site(); |
0 | 4848 |
|
4849 |
$domain = $current_blog->domain; |
|
9 | 4850 |
$path = $current_blog->path . 'xmlrpc.php'; |
0 | 4851 |
|
4852 |
$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) ); |
|
9 | 4853 |
$rpc->query( 'wp.getUsersBlogs', $args[1], $args[2] ); |
0 | 4854 |
$blogs = $rpc->getResponse(); |
4855 |
||
9 | 4856 |
if ( isset( $blogs['faultCode'] ) ) { |
4857 |
return new IXR_Error( $blogs['faultCode'], $blogs['faultString'] ); |
|
4858 |
} |
|
0 | 4859 |
|
4860 |
if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { |
|
4861 |
return $blogs; |
|
4862 |
} else { |
|
4863 |
foreach ( (array) $blogs as $blog ) { |
|
9 | 4864 |
if ( strpos( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { |
4865 |
return array( $blog ); |
|
4866 |
} |
|
0 | 4867 |
} |
4868 |
return array(); |
|
4869 |
} |
|
4870 |
} |
|
4871 |
||
4872 |
/** |
|
4873 |
* Retrieve user's data. |
|
4874 |
* |
|
4875 |
* Gives your client some info about you, so you don't have to. |
|
4876 |
* |
|
4877 |
* @since 1.5.0 |
|
4878 |
* |
|
16 | 4879 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4880 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4881 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4882 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4883 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4884 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4885 |
* } |
5 | 4886 |
* @return array|IXR_Error |
0 | 4887 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4888 |
public function blogger_getUserInfo( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4889 |
$this->escape( $args ); |
0 | 4890 |
|
4891 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4892 |
$password = $args[2]; |
0 | 4893 |
|
16 | 4894 |
$user = $this->login( $username, $password ); |
4895 |
if ( ! $user ) { |
|
0 | 4896 |
return $this->error; |
9 | 4897 |
} |
4898 |
||
4899 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4900 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
9 | 4901 |
} |
0 | 4902 |
|
5 | 4903 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4904 |
do_action( 'xmlrpc_call', 'blogger.getUserInfo', $args, $this ); |
0 | 4905 |
|
4906 |
$struct = array( |
|
4907 |
'nickname' => $user->nickname, |
|
4908 |
'userid' => $user->ID, |
|
4909 |
'url' => $user->user_url, |
|
4910 |
'lastname' => $user->last_name, |
|
9 | 4911 |
'firstname' => $user->first_name, |
0 | 4912 |
); |
4913 |
||
4914 |
return $struct; |
|
4915 |
} |
|
4916 |
||
4917 |
/** |
|
4918 |
* Retrieve post. |
|
4919 |
* |
|
4920 |
* @since 1.5.0 |
|
4921 |
* |
|
16 | 4922 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4923 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4924 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4925 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4926 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4927 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4928 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4929 |
* } |
5 | 4930 |
* @return array|IXR_Error |
0 | 4931 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4932 |
public function blogger_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4933 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4934 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4935 |
$post_ID = (int) $args[1]; |
0 | 4936 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4937 |
$password = $args[3]; |
0 | 4938 |
|
16 | 4939 |
$user = $this->login( $username, $password ); |
4940 |
if ( ! $user ) { |
|
0 | 4941 |
return $this->error; |
9 | 4942 |
} |
4943 |
||
4944 |
$post_data = get_post( $post_ID, ARRAY_A ); |
|
4945 |
if ( ! $post_data ) { |
|
0 | 4946 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4947 |
} |
4948 |
||
4949 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4950 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4951 |
} |
0 | 4952 |
|
5 | 4953 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4954 |
do_action( 'xmlrpc_call', 'blogger.getPost', $args, $this ); |
0 | 4955 |
|
9 | 4956 |
$categories = implode( ',', wp_get_post_categories( $post_ID ) ); |
4957 |
||
4958 |
$content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
|
4959 |
$content .= '<category>' . $categories . '</category>'; |
|
4960 |
$content .= wp_unslash( $post_data['post_content'] ); |
|
0 | 4961 |
|
4962 |
$struct = array( |
|
9 | 4963 |
'userid' => $post_data['post_author'], |
0 | 4964 |
'dateCreated' => $this->_convert_date( $post_data['post_date'] ), |
4965 |
'content' => $content, |
|
9 | 4966 |
'postid' => (string) $post_data['ID'], |
0 | 4967 |
); |
4968 |
||
4969 |
return $struct; |
|
4970 |
} |
|
4971 |
||
4972 |
/** |
|
4973 |
* Retrieve list of recent posts. |
|
4974 |
* |
|
4975 |
* @since 1.5.0 |
|
4976 |
* |
|
16 | 4977 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4978 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4979 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4980 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4981 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4982 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4983 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4984 |
* @type int $numberposts (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4985 |
* } |
5 | 4986 |
* @return array|IXR_Error |
0 | 4987 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4988 |
public function blogger_getRecentPosts( $args ) { |
0 | 4989 |
|
9 | 4990 |
$this->escape( $args ); |
0 | 4991 |
|
16 | 4992 |
// $args[0] = appkey - ignored. |
0 | 4993 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4994 |
$password = $args[3]; |
9 | 4995 |
if ( isset( $args[4] ) ) { |
0 | 4996 |
$query = array( 'numberposts' => absint( $args[4] ) ); |
9 | 4997 |
} else { |
0 | 4998 |
$query = array(); |
9 | 4999 |
} |
5000 |
||
16 | 5001 |
$user = $this->login( $username, $password ); |
5002 |
if ( ! $user ) { |
|
0 | 5003 |
return $this->error; |
9 | 5004 |
} |
5005 |
||
5006 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5007 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 5008 |
} |
0 | 5009 |
|
5 | 5010 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5011 |
do_action( 'xmlrpc_call', 'blogger.getRecentPosts', $args, $this ); |
0 | 5012 |
|
5013 |
$posts_list = wp_get_recent_posts( $query ); |
|
5014 |
||
9 | 5015 |
if ( ! $posts_list ) { |
5016 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 5017 |
return $this->error; |
5018 |
} |
|
5019 |
||
5 | 5020 |
$recent_posts = array(); |
9 | 5021 |
foreach ( $posts_list as $entry ) { |
5022 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 5023 |
continue; |
9 | 5024 |
} |
0 | 5025 |
|
5026 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
9 | 5027 |
$categories = implode( ',', wp_get_post_categories( $entry['ID'] ) ); |
5028 |
||
5029 |
$content = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>'; |
|
5030 |
$content .= '<category>' . $categories . '</category>'; |
|
5031 |
$content .= wp_unslash( $entry['post_content'] ); |
|
0 | 5032 |
|
5 | 5033 |
$recent_posts[] = array( |
9 | 5034 |
'userid' => $entry['post_author'], |
0 | 5035 |
'dateCreated' => $post_date, |
9 | 5036 |
'content' => $content, |
5037 |
'postid' => (string) $entry['ID'], |
|
0 | 5038 |
); |
5039 |
} |
|
5040 |
||
5041 |
return $recent_posts; |
|
5042 |
} |
|
5043 |
||
5044 |
/** |
|
5045 |
* Deprecated. |
|
5046 |
* |
|
5047 |
* @since 1.5.0 |
|
5048 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5049 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5050 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5051 |
* @return IXR_Error Error object. |
0 | 5052 |
*/ |
9 | 5053 |
public function blogger_getTemplate( $args ) { |
16 | 5054 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 5055 |
} |
5056 |
||
5057 |
/** |
|
5058 |
* Deprecated. |
|
5059 |
* |
|
5060 |
* @since 1.5.0 |
|
5061 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5063 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5064 |
* @return IXR_Error Error object. |
0 | 5065 |
*/ |
9 | 5066 |
public function blogger_setTemplate( $args ) { |
16 | 5067 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 5068 |
} |
5069 |
||
5070 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5071 |
* Creates new post. |
0 | 5072 |
* |
5073 |
* @since 1.5.0 |
|
5074 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5075 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5076 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5077 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5078 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5079 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5080 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5081 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5082 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5083 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5084 |
* } |
5 | 5085 |
* @return int|IXR_Error |
0 | 5086 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5087 |
public function blogger_newPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5088 |
$this->escape( $args ); |
0 | 5089 |
|
5090 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5091 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5092 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5093 |
$publish = $args[5]; |
0 | 5094 |
|
16 | 5095 |
$user = $this->login( $username, $password ); |
5096 |
if ( ! $user ) { |
|
0 | 5097 |
return $this->error; |
9 | 5098 |
} |
0 | 5099 |
|
5 | 5100 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5101 |
do_action( 'xmlrpc_call', 'blogger.newPost', $args, $this ); |
0 | 5102 |
|
9 | 5103 |
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
5104 |
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
|
5105 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
|
5106 |
} |
|
5107 |
||
5108 |
$post_status = ( $publish ) ? 'publish' : 'draft'; |
|
0 | 5109 |
|
5110 |
$post_author = $user->ID; |
|
5111 |
||
9 | 5112 |
$post_title = xmlrpc_getposttitle( $content ); |
5113 |
$post_category = xmlrpc_getpostcategory( $content ); |
|
5114 |
$post_content = xmlrpc_removepostdata( $content ); |
|
5115 |
||
5116 |
$post_date = current_time( 'mysql' ); |
|
5117 |
$post_date_gmt = current_time( 'mysql', 1 ); |
|
5118 |
||
5119 |
$post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' ); |
|
5120 |
||
5121 |
$post_ID = wp_insert_post( $post_data ); |
|
5122 |
if ( is_wp_error( $post_ID ) ) { |
|
5123 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
5124 |
} |
|
5125 |
||
5126 |
if ( ! $post_ID ) { |
|
16 | 5127 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5128 |
} |
0 | 5129 |
|
5130 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5131 |
||
5 | 5132 |
/** |
5133 |
* Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
5134 |
* |
|
5135 |
* @since 3.4.0 |
|
5136 |
* |
|
5137 |
* @param int $post_ID ID of the new post. |
|
5138 |
* @param array $args An array of new post arguments. |
|
5139 |
*/ |
|
16 | 5140 |
do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5141 |
|
5142 |
return $post_ID; |
|
5143 |
} |
|
5144 |
||
5145 |
/** |
|
5146 |
* Edit a post. |
|
5147 |
* |
|
5148 |
* @since 1.5.0 |
|
5149 |
* |
|
16 | 5150 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5151 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5153 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5154 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5155 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5156 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5157 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5158 |
* @type bool $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5159 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5160 |
* @return true|IXR_Error true when done. |
0 | 5161 |
*/ |
5 | 5162 |
public function blogger_editPost( $args ) { |
0 | 5163 |
|
9 | 5164 |
$this->escape( $args ); |
0 | 5165 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5166 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5167 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5168 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5169 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5170 |
$publish = $args[5]; |
5 | 5171 |
|
16 | 5172 |
$user = $this->login( $username, $password ); |
5173 |
if ( ! $user ) { |
|
0 | 5174 |
return $this->error; |
5 | 5175 |
} |
5176 |
||
5177 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 5178 |
do_action( 'xmlrpc_call', 'blogger.editPost', $args, $this ); |
5 | 5179 |
|
5180 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
5181 |
||
16 | 5182 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5 | 5183 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5184 |
} |
|
0 | 5185 |
|
9 | 5186 |
$this->escape( $actual_post ); |
0 | 5187 |
|
5 | 5188 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
9 | 5189 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5 | 5190 |
} |
16 | 5191 |
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
|
5192 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5193 |
} |
5194 |
||
9 | 5195 |
$postdata = array(); |
5196 |
$postdata['ID'] = $actual_post['ID']; |
|
5197 |
$postdata['post_content'] = xmlrpc_removepostdata( $content ); |
|
5198 |
$postdata['post_title'] = xmlrpc_getposttitle( $content ); |
|
5 | 5199 |
$postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
9 | 5200 |
$postdata['post_status'] = $actual_post['post_status']; |
5201 |
$postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
5202 |
$postdata['post_status'] = $publish ? 'publish' : 'draft'; |
|
5 | 5203 |
|
5204 |
$result = wp_update_post( $postdata ); |
|
5205 |
||
5206 |
if ( ! $result ) { |
|
16 | 5207 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
5 | 5208 |
} |
5209 |
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
|
5210 |
||
5211 |
/** |
|
5212 |
* Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
5213 |
* |
|
5214 |
* @since 3.4.0 |
|
5215 |
* |
|
5216 |
* @param int $post_ID ID of the updated post. |
|
5217 |
* @param array $args An array of arguments for the post to edit. |
|
5218 |
*/ |
|
16 | 5219 |
do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5220 |
|
5221 |
return true; |
|
5222 |
} |
|
5223 |
||
5224 |
/** |
|
5225 |
* Remove a post. |
|
5226 |
* |
|
5227 |
* @since 1.5.0 |
|
5228 |
* |
|
16 | 5229 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5230 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5231 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5232 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5233 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5234 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5235 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5236 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5237 |
* @return true|IXR_Error True when post is deleted. |
0 | 5238 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5239 |
public function blogger_deletePost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5240 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5242 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5243 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5244 |
$password = $args[3]; |
0 | 5245 |
|
16 | 5246 |
$user = $this->login( $username, $password ); |
5247 |
if ( ! $user ) { |
|
0 | 5248 |
return $this->error; |
9 | 5249 |
} |
0 | 5250 |
|
5 | 5251 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5252 |
do_action( 'xmlrpc_call', 'blogger.deletePost', $args, $this ); |
0 | 5253 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5254 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5255 |
|
16 | 5256 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5257 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5258 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5259 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5260 |
if ( ! current_user_can( 'delete_post', $post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5261 |
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
|
5262 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5264 |
$result = wp_delete_post( $post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5266 |
if ( ! $result ) { |
16 | 5267 |
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
|
5268 |
} |
0 | 5269 |
|
5 | 5270 |
/** |
5271 |
* Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
|
5272 |
* |
|
5273 |
* @since 3.4.0 |
|
5274 |
* |
|
5275 |
* @param int $post_ID ID of the deleted post. |
|
5276 |
* @param array $args An array of arguments to delete the post. |
|
5277 |
*/ |
|
16 | 5278 |
do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5279 |
|
5280 |
return true; |
|
5281 |
} |
|
5282 |
||
16 | 5283 |
/* |
5284 |
* MetaWeblog API functions. |
|
5285 |
* Specs on wherever Dave Winer wants them to be. |
|
0 | 5286 |
*/ |
5287 |
||
5288 |
/** |
|
5289 |
* Create a new post. |
|
5290 |
* |
|
5291 |
* The 'content_struct' argument must contain: |
|
5292 |
* - title |
|
5293 |
* - description |
|
5294 |
* - mt_excerpt |
|
5295 |
* - mt_text_more |
|
5296 |
* - mt_keywords |
|
5297 |
* - mt_tb_ping_urls |
|
5298 |
* - categories |
|
5299 |
* |
|
5300 |
* Also, it can optionally contain: |
|
5301 |
* - wp_slug |
|
5302 |
* - wp_password |
|
5303 |
* - wp_page_parent_id |
|
5304 |
* - wp_page_order |
|
5305 |
* - wp_author_id |
|
5306 |
* - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' |
|
5307 |
* - mt_allow_comments - can be 'open' or 'closed' |
|
5308 |
* - mt_allow_pings - can be 'open' or 'closed' |
|
5309 |
* - date_created_gmt |
|
5310 |
* - dateCreated |
|
5311 |
* - wp_post_thumbnail |
|
5312 |
* |
|
5313 |
* @since 1.5.0 |
|
5314 |
* |
|
16 | 5315 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5316 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5317 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5318 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5319 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5320 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5321 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5322 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5323 |
* } |
5 | 5324 |
* @return int|IXR_Error |
0 | 5325 |
*/ |
9 | 5326 |
public function mw_newPost( $args ) { |
5327 |
$this->escape( $args ); |
|
0 | 5328 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5329 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5330 |
$password = $args[2]; |
0 | 5331 |
$content_struct = $args[3]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5332 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
0 | 5333 |
|
16 | 5334 |
$user = $this->login( $username, $password ); |
5335 |
if ( ! $user ) { |
|
0 | 5336 |
return $this->error; |
9 | 5337 |
} |
0 | 5338 |
|
5 | 5339 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5340 |
do_action( 'xmlrpc_call', 'metaWeblog.newPost', $args, $this ); |
0 | 5341 |
|
5342 |
$page_template = ''; |
|
9 | 5343 |
if ( ! empty( $content_struct['post_type'] ) ) { |
16 | 5344 |
if ( 'page' === $content_struct['post_type'] ) { |
9 | 5345 |
if ( $publish ) { |
5346 |
$cap = 'publish_pages'; |
|
16 | 5347 |
} elseif ( isset( $content_struct['page_status'] ) && 'publish' === $content_struct['page_status'] ) { |
9 | 5348 |
$cap = 'publish_pages'; |
5349 |
} else { |
|
0 | 5350 |
$cap = 'edit_pages'; |
9 | 5351 |
} |
0 | 5352 |
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' ); |
9 | 5353 |
$post_type = 'page'; |
5354 |
if ( ! empty( $content_struct['wp_page_template'] ) ) { |
|
0 | 5355 |
$page_template = $content_struct['wp_page_template']; |
9 | 5356 |
} |
16 | 5357 |
} elseif ( 'post' === $content_struct['post_type'] ) { |
9 | 5358 |
if ( $publish ) { |
5359 |
$cap = 'publish_posts'; |
|
16 | 5360 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5361 |
$cap = 'publish_posts'; |
5362 |
} else { |
|
0 | 5363 |
$cap = 'edit_posts'; |
9 | 5364 |
} |
0 | 5365 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5366 |
$post_type = 'post'; |
0 | 5367 |
} else { |
16 | 5368 |
// No other 'post_type' values are allowed here. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5369 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5370 |
} |
5371 |
} else { |
|
9 | 5372 |
if ( $publish ) { |
5373 |
$cap = 'publish_posts'; |
|
16 | 5374 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5375 |
$cap = 'publish_posts'; |
5376 |
} else { |
|
0 | 5377 |
$cap = 'edit_posts'; |
9 | 5378 |
} |
0 | 5379 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5380 |
$post_type = 'post'; |
5381 |
} |
|
5382 |
||
5383 |
if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) { |
|
0 | 5384 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) ); |
9 | 5385 |
} |
5386 |
if ( ! current_user_can( $cap ) ) { |
|
0 | 5387 |
return new IXR_Error( 401, $error_message ); |
9 | 5388 |
} |
0 | 5389 |
|
16 | 5390 |
// Check for a valid post format if one was given. |
0 | 5391 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5392 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5393 |
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
|
5394 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5395 |
} |
5396 |
} |
|
5397 |
||
16 | 5398 |
// Let WordPress generate the 'post_name' (slug) unless |
0 | 5399 |
// one has been provided. |
9 | 5400 |
$post_name = ''; |
5401 |
if ( isset( $content_struct['wp_slug'] ) ) { |
|
0 | 5402 |
$post_name = $content_struct['wp_slug']; |
9 | 5403 |
} |
0 | 5404 |
|
5405 |
// Only use a password if one was given. |
|
9 | 5406 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5407 |
$post_password = $content_struct['wp_password']; |
9 | 5408 |
} else { |
5409 |
$post_password = ''; |
|
5410 |
} |
|
0 | 5411 |
|
16 | 5412 |
// Only set a post parent if one was given. |
9 | 5413 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5414 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5415 |
} else { |
5416 |
$post_parent = 0; |
|
5417 |
} |
|
0 | 5418 |
|
16 | 5419 |
// Only set the 'menu_order' if it was given. |
9 | 5420 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5421 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5422 |
} else { |
5423 |
$menu_order = 0; |
|
5424 |
} |
|
0 | 5425 |
|
5426 |
$post_author = $user->ID; |
|
5427 |
||
5428 |
// If an author id was provided then use it instead. |
|
5429 |
if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
|
5430 |
switch ( $post_type ) { |
|
9 | 5431 |
case 'post': |
5432 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5433 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 5434 |
} |
0 | 5435 |
break; |
9 | 5436 |
case 'page': |
5437 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5438 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
9 | 5439 |
} |
0 | 5440 |
break; |
5441 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5442 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5443 |
} |
5444 |
$author = get_userdata( $content_struct['wp_author_id'] ); |
|
9 | 5445 |
if ( ! $author ) { |
0 | 5446 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 5447 |
} |
0 | 5448 |
$post_author = $content_struct['wp_author_id']; |
5449 |
} |
|
5450 |
||
9 | 5451 |
$post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; |
0 | 5452 |
$post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null; |
5453 |
||
5454 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5455 |
||
9 | 5456 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5457 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5458 |
case 'draft': |
5459 |
case 'pending': |
|
5460 |
case 'private': |
|
5461 |
case 'publish': |
|
9 | 5462 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5463 |
break; |
5464 |
default: |
|
5465 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5466 |
break; |
|
5467 |
} |
|
5468 |
} |
|
5469 |
||
9 | 5470 |
$post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : null; |
5471 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5472 |
||
5473 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5474 |
||
5475 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
|
5476 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5477 |
switch ( $content_struct['mt_allow_comments'] ) { |
5478 |
case 'closed': |
|
5479 |
$comment_status = 'closed'; |
|
5480 |
break; |
|
5481 |
case 'open': |
|
5482 |
$comment_status = 'open'; |
|
5483 |
break; |
|
5484 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5485 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5486 |
break; |
5487 |
} |
|
5488 |
} else { |
|
5489 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5490 |
case 0: |
|
5491 |
case 2: |
|
5492 |
$comment_status = 'closed'; |
|
5493 |
break; |
|
5494 |
case 1: |
|
5495 |
$comment_status = 'open'; |
|
5496 |
break; |
|
5497 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5498 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5499 |
break; |
5500 |
} |
|
5501 |
} |
|
5502 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5503 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5504 |
} |
5505 |
||
9 | 5506 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5507 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5508 |
switch ( $content_struct['mt_allow_pings'] ) { |
5509 |
case 'closed': |
|
5510 |
$ping_status = 'closed'; |
|
5511 |
break; |
|
5512 |
case 'open': |
|
5513 |
$ping_status = 'open'; |
|
5514 |
break; |
|
5515 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5516 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5517 |
break; |
5518 |
} |
|
5519 |
} else { |
|
5520 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
|
5521 |
case 0: |
|
5522 |
$ping_status = 'closed'; |
|
5523 |
break; |
|
5524 |
case 1: |
|
5525 |
$ping_status = 'open'; |
|
5526 |
break; |
|
5527 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5528 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5529 |
break; |
5530 |
} |
|
5531 |
} |
|
5532 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5533 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5534 |
} |
5535 |
||
9 | 5536 |
if ( $post_more ) { |
0 | 5537 |
$post_content = $post_content . '<!--more-->' . $post_more; |
9 | 5538 |
} |
0 | 5539 |
|
5540 |
$to_ping = null; |
|
5541 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5542 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5543 |
if ( is_array( $to_ping ) ) { |
5544 |
$to_ping = implode( ' ', $to_ping ); |
|
5545 |
} |
|
0 | 5546 |
} |
5547 |
||
16 | 5548 |
// Do some timestamp voodoo. |
9 | 5549 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 5550 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5551 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5552 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5553 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5554 |
} |
5555 |
||
5556 |
if ( ! empty( $dateCreated ) ) { |
|
16 | 5557 |
$post_date = iso8601_to_datetime( $dateCreated ); |
5558 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
0 | 5559 |
} else { |
9 | 5560 |
$post_date = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5561 |
$post_date_gmt = ''; |
0 | 5562 |
} |
5563 |
||
5564 |
$post_category = array(); |
|
5565 |
if ( isset( $content_struct['categories'] ) ) { |
|
5566 |
$catnames = $content_struct['categories']; |
|
5567 |
||
9 | 5568 |
if ( is_array( $catnames ) ) { |
5569 |
foreach ( $catnames as $cat ) { |
|
5570 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5571 |
} |
5572 |
} |
|
5573 |
} |
|
5574 |
||
9 | 5575 |
$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 | 5576 |
|
16 | 5577 |
$post_ID = get_default_post_to_edit( $post_type, true )->ID; |
5578 |
$postdata['ID'] = $post_ID; |
|
5579 |
||
5580 |
// Only posts can be sticky. |
|
5581 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 5582 |
$data = $postdata; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5583 |
$data['sticky'] = $content_struct['sticky']; |
9 | 5584 |
$error = $this->_toggle_sticky( $data ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5585 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5586 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5587 |
} |
0 | 5588 |
} |
5589 |
||
9 | 5590 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5591 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5592 |
} |
|
5593 |
||
5594 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
5595 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
|
0 | 5596 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5597 |
} |
0 | 5598 |
|
5599 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5600 |
} |
|
5601 |
||
16 | 5602 |
// Handle enclosures. |
9 | 5603 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5604 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5605 |
|
5606 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5607 |
||
5608 |
// Handle post formats if assigned, value is validated earlier |
|
16 | 5609 |
// in this function. |
9 | 5610 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 5611 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 5612 |
} |
0 | 5613 |
|
5614 |
$post_ID = wp_insert_post( $postdata, true ); |
|
9 | 5615 |
if ( is_wp_error( $post_ID ) ) { |
5616 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
5617 |
} |
|
5618 |
||
5619 |
if ( ! $post_ID ) { |
|
16 | 5620 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5621 |
} |
0 | 5622 |
|
5 | 5623 |
/** |
5624 |
* Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
5625 |
* |
|
5626 |
* @since 3.4.0 |
|
5627 |
* |
|
5628 |
* @param int $post_ID ID of the new post. |
|
5629 |
* @param array $args An array of arguments to create the new post. |
|
5630 |
*/ |
|
16 | 5631 |
do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5632 |
|
18 | 5633 |
return (string) $post_ID; |
0 | 5634 |
} |
5635 |
||
5 | 5636 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5637 |
* 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
|
5638 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5639 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5640 |
* |
18 | 5641 |
* @param int $post_ID Post ID. |
5642 |
* @param array $enclosure Enclosure data. |
|
5 | 5643 |
*/ |
5644 |
public function add_enclosure_if_new( $post_ID, $enclosure ) { |
|
0 | 5645 |
if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
16 | 5646 |
$encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
5647 |
$found = false; |
|
5648 |
$enclosures = get_post_meta( $post_ID, 'enclosure' ); |
|
5649 |
if ( $enclosures ) { |
|
0 | 5650 |
foreach ( $enclosures as $enc ) { |
5651 |
// This method used to omit the trailing new line. #23219 |
|
5652 |
if ( rtrim( $enc, "\n" ) == rtrim( $encstring, "\n" ) ) { |
|
5653 |
$found = true; |
|
5654 |
break; |
|
5655 |
} |
|
5656 |
} |
|
5657 |
} |
|
9 | 5658 |
if ( ! $found ) { |
0 | 5659 |
add_post_meta( $post_ID, 'enclosure', $encstring ); |
9 | 5660 |
} |
0 | 5661 |
} |
5662 |
} |
|
5663 |
||
5664 |
/** |
|
5665 |
* Attach upload to a post. |
|
5666 |
* |
|
5667 |
* @since 2.1.0 |
|
5668 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5669 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5670 |
* |
16 | 5671 |
* @param int $post_ID Post ID. |
0 | 5672 |
* @param string $post_content Post Content for attachment. |
5673 |
*/ |
|
5 | 5674 |
public function attach_uploads( $post_ID, $post_content ) { |
0 | 5675 |
global $wpdb; |
5676 |
||
16 | 5677 |
// Find any unattached files. |
0 | 5678 |
$attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); |
5679 |
if ( is_array( $attachments ) ) { |
|
5680 |
foreach ( $attachments as $file ) { |
|
9 | 5681 |
if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { |
5682 |
$wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); |
|
5683 |
} |
|
0 | 5684 |
} |
5685 |
} |
|
5686 |
} |
|
5687 |
||
5688 |
/** |
|
5689 |
* Edit a post. |
|
5690 |
* |
|
5691 |
* @since 1.5.0 |
|
5692 |
* |
|
16 | 5693 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5694 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5695 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5696 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5697 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5698 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5699 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5700 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5701 |
* } |
18 | 5702 |
* @return true|IXR_Error True on success. |
0 | 5703 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5704 |
public function mw_editPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5705 |
$this->escape( $args ); |
0 | 5706 |
|
5707 |
$post_ID = (int) $args[0]; |
|
5708 |
$username = $args[1]; |
|
5709 |
$password = $args[2]; |
|
5710 |
$content_struct = $args[3]; |
|
5711 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
|
5712 |
||
16 | 5713 |
$user = $this->login( $username, $password ); |
5714 |
if ( ! $user ) { |
|
0 | 5715 |
return $this->error; |
9 | 5716 |
} |
0 | 5717 |
|
5 | 5718 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5719 |
do_action( 'xmlrpc_call', 'metaWeblog.editPost', $args, $this ); |
0 | 5720 |
|
5721 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5722 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5723 |
/* |
16 | 5724 |
* 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
|
5725 |
* 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
|
5726 |
*/ |
9 | 5727 |
if ( ! $postdata || empty( $postdata['ID'] ) ) { |
0 | 5728 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5729 |
} |
5730 |
||
5731 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5732 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5733 |
} |
0 | 5734 |
|
5735 |
// Use wp.editPost to edit post types other than post and page. |
|
16 | 5736 |
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
|
5737 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
9 | 5738 |
} |
0 | 5739 |
|
5740 |
// Thwart attempt to change the post type. |
|
9 | 5741 |
if ( ! empty( $content_struct['post_type'] ) && ( $content_struct['post_type'] != $postdata['post_type'] ) ) { |
0 | 5742 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 5743 |
} |
0 | 5744 |
|
16 | 5745 |
// Check for a valid post format if one was given. |
0 | 5746 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5747 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5748 |
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
|
5749 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5750 |
} |
5751 |
} |
|
5752 |
||
9 | 5753 |
$this->escape( $postdata ); |
5754 |
||
5755 |
$ID = $postdata['ID']; |
|
5756 |
$post_content = $postdata['post_content']; |
|
5757 |
$post_title = $postdata['post_title']; |
|
5758 |
$post_excerpt = $postdata['post_excerpt']; |
|
5759 |
$post_password = $postdata['post_password']; |
|
5760 |
$post_parent = $postdata['post_parent']; |
|
5761 |
$post_type = $postdata['post_type']; |
|
5762 |
$menu_order = $postdata['menu_order']; |
|
5763 |
$ping_status = $postdata['ping_status']; |
|
5764 |
$comment_status = $postdata['comment_status']; |
|
0 | 5765 |
|
5766 |
// Let WordPress manage slug if none was provided. |
|
5767 |
$post_name = $postdata['post_name']; |
|
9 | 5768 |
if ( isset( $content_struct['wp_slug'] ) ) { |
0 | 5769 |
$post_name = $content_struct['wp_slug']; |
9 | 5770 |
} |
0 | 5771 |
|
5772 |
// Only use a password if one was given. |
|
9 | 5773 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5774 |
$post_password = $content_struct['wp_password']; |
9 | 5775 |
} |
0 | 5776 |
|
5777 |
// Only set a post parent if one was given. |
|
9 | 5778 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5779 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5780 |
} |
0 | 5781 |
|
16 | 5782 |
// Only set the 'menu_order' if it was given. |
9 | 5783 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5784 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5785 |
} |
0 | 5786 |
|
5 | 5787 |
$page_template = null; |
16 | 5788 |
if ( ! empty( $content_struct['wp_page_template'] ) && 'page' === $post_type ) { |
0 | 5789 |
$page_template = $content_struct['wp_page_template']; |
9 | 5790 |
} |
0 | 5791 |
|
5792 |
$post_author = $postdata['post_author']; |
|
5793 |
||
16 | 5794 |
// If an author id was provided then use it instead. |
5 | 5795 |
if ( isset( $content_struct['wp_author_id'] ) ) { |
5796 |
// Check permissions if attempting to switch author to or from another user. |
|
5797 |
if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) { |
|
5798 |
switch ( $post_type ) { |
|
5799 |
case 'post': |
|
5800 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5801 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the post author as this user.' ) ); |
5 | 5802 |
} |
5803 |
break; |
|
5804 |
case 'page': |
|
5805 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5806 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the page author as this user.' ) ); |
5 | 5807 |
} |
5808 |
break; |
|
5809 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5810 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
5 | 5811 |
} |
5812 |
$post_author = $content_struct['wp_author_id']; |
|
0 | 5813 |
} |
5814 |
} |
|
5815 |
||
9 | 5816 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
5817 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5818 |
switch ( $content_struct['mt_allow_comments'] ) { |
5819 |
case 'closed': |
|
5820 |
$comment_status = 'closed'; |
|
5821 |
break; |
|
5822 |
case 'open': |
|
5823 |
$comment_status = 'open'; |
|
5824 |
break; |
|
5825 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5826 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5827 |
break; |
5828 |
} |
|
5829 |
} else { |
|
5830 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5831 |
case 0: |
|
5832 |
case 2: |
|
5833 |
$comment_status = 'closed'; |
|
5834 |
break; |
|
5835 |
case 1: |
|
5836 |
$comment_status = 'open'; |
|
5837 |
break; |
|
5838 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5839 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5840 |
break; |
5841 |
} |
|
5842 |
} |
|
5843 |
} |
|
5844 |
||
9 | 5845 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5846 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5847 |
switch ( $content_struct['mt_allow_pings'] ) { |
5848 |
case 'closed': |
|
5849 |
$ping_status = 'closed'; |
|
5850 |
break; |
|
5851 |
case 'open': |
|
5852 |
$ping_status = 'open'; |
|
5853 |
break; |
|
5854 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5855 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5856 |
break; |
5857 |
} |
|
5858 |
} else { |
|
9 | 5859 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
0 | 5860 |
case 0: |
5861 |
$ping_status = 'closed'; |
|
5862 |
break; |
|
5863 |
case 1: |
|
5864 |
$ping_status = 'open'; |
|
5865 |
break; |
|
5866 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5867 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5868 |
break; |
5869 |
} |
|
5870 |
} |
|
5871 |
} |
|
5872 |
||
9 | 5873 |
if ( isset( $content_struct['title'] ) ) { |
5874 |
$post_title = $content_struct['title']; |
|
5875 |
} |
|
5876 |
||
5877 |
if ( isset( $content_struct['description'] ) ) { |
|
0 | 5878 |
$post_content = $content_struct['description']; |
9 | 5879 |
} |
0 | 5880 |
|
5881 |
$post_category = array(); |
|
5882 |
if ( isset( $content_struct['categories'] ) ) { |
|
5883 |
$catnames = $content_struct['categories']; |
|
9 | 5884 |
if ( is_array( $catnames ) ) { |
5885 |
foreach ( $catnames as $cat ) { |
|
5886 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5887 |
} |
5888 |
} |
|
5889 |
} |
|
5890 |
||
9 | 5891 |
if ( isset( $content_struct['mt_excerpt'] ) ) { |
5892 |
$post_excerpt = $content_struct['mt_excerpt']; |
|
5893 |
} |
|
0 | 5894 |
|
5895 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5896 |
||
5897 |
$post_status = $publish ? 'publish' : 'draft'; |
|
9 | 5898 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5899 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5900 |
case 'draft': |
5901 |
case 'pending': |
|
5902 |
case 'private': |
|
5903 |
case 'publish': |
|
9 | 5904 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5905 |
break; |
5906 |
default: |
|
5907 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5908 |
break; |
|
5909 |
} |
|
5910 |
} |
|
5911 |
||
5912 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5913 |
||
16 | 5914 |
if ( 'publish' === $post_status || 'private' === $post_status ) { |
5915 |
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
|
5916 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) ); |
5 | 5917 |
} elseif ( ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5918 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5919 |
} |
0 | 5920 |
} |
5921 |
||
9 | 5922 |
if ( $post_more ) { |
5923 |
$post_content = $post_content . '<!--more-->' . $post_more; |
|
5924 |
} |
|
0 | 5925 |
|
5926 |
$to_ping = null; |
|
5927 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5928 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5929 |
if ( is_array( $to_ping ) ) { |
5930 |
$to_ping = implode( ' ', $to_ping ); |
|
5931 |
} |
|
0 | 5932 |
} |
5933 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5934 |
// Do some timestamp voodoo. |
9 | 5935 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5936 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5937 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5938 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5939 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5940 |
} |
0 | 5941 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5942 |
// 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
|
5943 |
$edit_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5944 |
|
9 | 5945 |
if ( ! empty( $dateCreated ) ) { |
16 | 5946 |
$post_date = iso8601_to_datetime( $dateCreated ); |
5947 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5949 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5950 |
$edit_date = true; |
0 | 5951 |
} else { |
5952 |
$post_date = $postdata['post_date']; |
|
5953 |
$post_date_gmt = $postdata['post_date_gmt']; |
|
5954 |
} |
|
5955 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5956 |
// We've got all the data -- post it. |
9 | 5957 |
$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' ); |
5958 |
||
5959 |
$result = wp_update_post( $newpost, true ); |
|
5960 |
if ( is_wp_error( $result ) ) { |
|
5961 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
5962 |
} |
|
5963 |
||
5964 |
if ( ! $result ) { |
|
16 | 5965 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
5966 |
} |
|
5967 |
||
5968 |
// Only posts can be sticky. |
|
5969 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 5970 |
$data = $newpost; |
5971 |
$data['sticky'] = $content_struct['sticky']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5972 |
$data['post_type'] = 'post'; |
9 | 5973 |
$error = $this->_toggle_sticky( $data, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5974 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5975 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5976 |
} |
0 | 5977 |
} |
5978 |
||
9 | 5979 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5980 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5981 |
} |
|
5982 |
||
5983 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5984 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5985 |
// Empty value deletes, non-empty value adds/updates. |
0 | 5986 |
if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
5987 |
delete_post_thumbnail( $post_ID ); |
|
5988 |
} else { |
|
9 | 5989 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
0 | 5990 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5991 |
} |
0 | 5992 |
} |
5993 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5994 |
} |
|
5995 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5996 |
// Handle enclosures. |
9 | 5997 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5998 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5999 |
|
6000 |
$this->attach_uploads( $ID, $post_content ); |
|
6001 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6002 |
// Handle post formats if assigned, validation is handled earlier in this function. |
9 | 6003 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 6004 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 6005 |
} |
0 | 6006 |
|
5 | 6007 |
/** |
6008 |
* Fires after a post has been successfully updated via the XML-RPC MovableType API. |
|
6009 |
* |
|
6010 |
* @since 3.4.0 |
|
6011 |
* |
|
6012 |
* @param int $post_ID ID of the updated post. |
|
6013 |
* @param array $args An array of arguments to update the post. |
|
6014 |
*/ |
|
16 | 6015 |
do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 6016 |
|
6017 |
return true; |
|
6018 |
} |
|
6019 |
||
6020 |
/** |
|
6021 |
* Retrieve post. |
|
6022 |
* |
|
6023 |
* @since 1.5.0 |
|
6024 |
* |
|
16 | 6025 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6026 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6027 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6028 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6029 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6030 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6031 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6032 |
* } |
5 | 6033 |
* @return array|IXR_Error |
0 | 6034 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6035 |
public function mw_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6036 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6037 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6038 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6039 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6040 |
$password = $args[2]; |
0 | 6041 |
|
16 | 6042 |
$user = $this->login( $username, $password ); |
6043 |
if ( ! $user ) { |
|
0 | 6044 |
return $this->error; |
9 | 6045 |
} |
6046 |
||
6047 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
6048 |
if ( ! $postdata ) { |
|
0 | 6049 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6050 |
} |
6051 |
||
6052 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6053 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6054 |
} |
0 | 6055 |
|
5 | 6056 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6057 |
do_action( 'xmlrpc_call', 'metaWeblog.getPost', $args, $this ); |
0 | 6058 |
|
16 | 6059 |
if ( '' !== $postdata['post_date'] ) { |
9 | 6060 |
$post_date = $this->_convert_date( $postdata['post_date'] ); |
6061 |
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
|
6062 |
$post_modified = $this->_convert_date( $postdata['post_modified'] ); |
|
0 | 6063 |
$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); |
6064 |
||
6065 |
$categories = array(); |
|
9 | 6066 |
$catids = wp_get_post_categories( $post_ID ); |
6067 |
foreach ( $catids as $catid ) { |
|
6068 |
$categories[] = get_cat_name( $catid ); |
|
6069 |
} |
|
0 | 6070 |
|
6071 |
$tagnames = array(); |
|
9 | 6072 |
$tags = wp_get_post_tags( $post_ID ); |
6073 |
if ( ! empty( $tags ) ) { |
|
6074 |
foreach ( $tags as $tag ) { |
|
0 | 6075 |
$tagnames[] = $tag->name; |
9 | 6076 |
} |
0 | 6077 |
$tagnames = implode( ', ', $tagnames ); |
6078 |
} else { |
|
6079 |
$tagnames = ''; |
|
6080 |
} |
|
6081 |
||
9 | 6082 |
$post = get_extended( $postdata['post_content'] ); |
6083 |
$link = get_permalink( $postdata['ID'] ); |
|
0 | 6084 |
|
6085 |
// Get the author info. |
|
9 | 6086 |
$author = get_userdata( $postdata['post_author'] ); |
6087 |
||
16 | 6088 |
$allow_comments = ( 'open' === $postdata['comment_status'] ) ? 1 : 0; |
6089 |
$allow_pings = ( 'open' === $postdata['ping_status'] ) ? 1 : 0; |
|
6090 |
||
6091 |
// Consider future posts as published. |
|
6092 |
if ( 'future' === $postdata['post_status'] ) { |
|
0 | 6093 |
$postdata['post_status'] = 'publish'; |
9 | 6094 |
} |
0 | 6095 |
|
16 | 6096 |
// Get post format. |
0 | 6097 |
$post_format = get_post_format( $post_ID ); |
9 | 6098 |
if ( empty( $post_format ) ) { |
0 | 6099 |
$post_format = 'standard'; |
9 | 6100 |
} |
0 | 6101 |
|
6102 |
$sticky = false; |
|
9 | 6103 |
if ( is_sticky( $post_ID ) ) { |
0 | 6104 |
$sticky = true; |
9 | 6105 |
} |
0 | 6106 |
|
6107 |
$enclosure = array(); |
|
9 | 6108 |
foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) { |
16 | 6109 |
if ( 'enclosure' === $key ) { |
0 | 6110 |
foreach ( (array) $val as $enc ) { |
9 | 6111 |
$encdata = explode( "\n", $enc ); |
6112 |
$enclosure['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
6113 |
$enclosure['length'] = (int) trim( $encdata[1] ); |
|
6114 |
$enclosure['type'] = trim( $encdata[2] ); |
|
0 | 6115 |
break 2; |
6116 |
} |
|
6117 |
} |
|
6118 |
} |
|
6119 |
||
6120 |
$resp = array( |
|
9 | 6121 |
'dateCreated' => $post_date, |
6122 |
'userid' => $postdata['post_author'], |
|
6123 |
'postid' => $postdata['ID'], |
|
6124 |
'description' => $post['main'], |
|
6125 |
'title' => $postdata['post_title'], |
|
6126 |
'link' => $link, |
|
6127 |
'permaLink' => $link, |
|
16 | 6128 |
// Commented out because no other tool seems to use this. |
6129 |
// 'content' => $entry['post_content'], |
|
9 | 6130 |
'categories' => $categories, |
6131 |
'mt_excerpt' => $postdata['post_excerpt'], |
|
6132 |
'mt_text_more' => $post['extended'], |
|
6133 |
'wp_more_text' => $post['more_text'], |
|
6134 |
'mt_allow_comments' => $allow_comments, |
|
6135 |
'mt_allow_pings' => $allow_pings, |
|
6136 |
'mt_keywords' => $tagnames, |
|
6137 |
'wp_slug' => $postdata['post_name'], |
|
6138 |
'wp_password' => $postdata['post_password'], |
|
6139 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6140 |
'wp_author_display_name' => $author->display_name, |
9 | 6141 |
'date_created_gmt' => $post_date_gmt, |
6142 |
'post_status' => $postdata['post_status'], |
|
6143 |
'custom_fields' => $this->get_custom_fields( $post_ID ), |
|
6144 |
'wp_post_format' => $post_format, |
|
6145 |
'sticky' => $sticky, |
|
6146 |
'date_modified' => $post_modified, |
|
6147 |
'date_modified_gmt' => $post_modified_gmt, |
|
0 | 6148 |
); |
6149 |
||
9 | 6150 |
if ( ! empty( $enclosure ) ) { |
6151 |
$resp['enclosure'] = $enclosure; |
|
6152 |
} |
|
0 | 6153 |
|
6154 |
$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] ); |
|
6155 |
||
6156 |
return $resp; |
|
6157 |
} else { |
|
9 | 6158 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
0 | 6159 |
} |
6160 |
} |
|
6161 |
||
6162 |
/** |
|
6163 |
* Retrieve list of recent posts. |
|
6164 |
* |
|
6165 |
* @since 1.5.0 |
|
6166 |
* |
|
16 | 6167 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6168 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6170 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6171 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6172 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6173 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6174 |
* } |
5 | 6175 |
* @return array|IXR_Error |
0 | 6176 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6177 |
public function mw_getRecentPosts( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6178 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6179 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6180 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6181 |
$password = $args[2]; |
9 | 6182 |
if ( isset( $args[3] ) ) { |
0 | 6183 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6184 |
} else { |
0 | 6185 |
$query = array(); |
9 | 6186 |
} |
6187 |
||
16 | 6188 |
$user = $this->login( $username, $password ); |
6189 |
if ( ! $user ) { |
|
0 | 6190 |
return $this->error; |
9 | 6191 |
} |
6192 |
||
6193 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6194 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 6195 |
} |
0 | 6196 |
|
5 | 6197 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6198 |
do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts', $args, $this ); |
0 | 6199 |
|
6200 |
$posts_list = wp_get_recent_posts( $query ); |
|
6201 |
||
9 | 6202 |
if ( ! $posts_list ) { |
0 | 6203 |
return array(); |
9 | 6204 |
} |
0 | 6205 |
|
5 | 6206 |
$recent_posts = array(); |
9 | 6207 |
foreach ( $posts_list as $entry ) { |
6208 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6209 |
continue; |
9 | 6210 |
} |
6211 |
||
6212 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
6213 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
6214 |
$post_modified = $this->_convert_date( $entry['post_modified'] ); |
|
0 | 6215 |
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] ); |
6216 |
||
6217 |
$categories = array(); |
|
9 | 6218 |
$catids = wp_get_post_categories( $entry['ID'] ); |
6219 |
foreach ( $catids as $catid ) { |
|
6220 |
$categories[] = get_cat_name( $catid ); |
|
6221 |
} |
|
0 | 6222 |
|
6223 |
$tagnames = array(); |
|
9 | 6224 |
$tags = wp_get_post_tags( $entry['ID'] ); |
6225 |
if ( ! empty( $tags ) ) { |
|
0 | 6226 |
foreach ( $tags as $tag ) { |
6227 |
$tagnames[] = $tag->name; |
|
6228 |
} |
|
6229 |
$tagnames = implode( ', ', $tagnames ); |
|
6230 |
} else { |
|
6231 |
$tagnames = ''; |
|
6232 |
} |
|
6233 |
||
9 | 6234 |
$post = get_extended( $entry['post_content'] ); |
6235 |
$link = get_permalink( $entry['ID'] ); |
|
0 | 6236 |
|
6237 |
// Get the post author info. |
|
9 | 6238 |
$author = get_userdata( $entry['post_author'] ); |
6239 |
||
16 | 6240 |
$allow_comments = ( 'open' === $entry['comment_status'] ) ? 1 : 0; |
6241 |
$allow_pings = ( 'open' === $entry['ping_status'] ) ? 1 : 0; |
|
6242 |
||
6243 |
// Consider future posts as published. |
|
6244 |
if ( 'future' === $entry['post_status'] ) { |
|
0 | 6245 |
$entry['post_status'] = 'publish'; |
9 | 6246 |
} |
0 | 6247 |
|
16 | 6248 |
// Get post format. |
0 | 6249 |
$post_format = get_post_format( $entry['ID'] ); |
9 | 6250 |
if ( empty( $post_format ) ) { |
0 | 6251 |
$post_format = 'standard'; |
9 | 6252 |
} |
0 | 6253 |
|
5 | 6254 |
$recent_posts[] = array( |
9 | 6255 |
'dateCreated' => $post_date, |
6256 |
'userid' => $entry['post_author'], |
|
6257 |
'postid' => (string) $entry['ID'], |
|
6258 |
'description' => $post['main'], |
|
6259 |
'title' => $entry['post_title'], |
|
6260 |
'link' => $link, |
|
6261 |
'permaLink' => $link, |
|
16 | 6262 |
// Commented out because no other tool seems to use this. |
0 | 6263 |
// 'content' => $entry['post_content'], |
9 | 6264 |
'categories' => $categories, |
6265 |
'mt_excerpt' => $entry['post_excerpt'], |
|
6266 |
'mt_text_more' => $post['extended'], |
|
6267 |
'wp_more_text' => $post['more_text'], |
|
6268 |
'mt_allow_comments' => $allow_comments, |
|
6269 |
'mt_allow_pings' => $allow_pings, |
|
6270 |
'mt_keywords' => $tagnames, |
|
6271 |
'wp_slug' => $entry['post_name'], |
|
6272 |
'wp_password' => $entry['post_password'], |
|
6273 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6274 |
'wp_author_display_name' => $author->display_name, |
9 | 6275 |
'date_created_gmt' => $post_date_gmt, |
6276 |
'post_status' => $entry['post_status'], |
|
6277 |
'custom_fields' => $this->get_custom_fields( $entry['ID'] ), |
|
6278 |
'wp_post_format' => $post_format, |
|
6279 |
'date_modified' => $post_modified, |
|
6280 |
'date_modified_gmt' => $post_modified_gmt, |
|
16 | 6281 |
'sticky' => ( 'post' === $entry['post_type'] && is_sticky( $entry['ID'] ) ), |
9 | 6282 |
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ), |
0 | 6283 |
); |
6284 |
} |
|
6285 |
||
6286 |
return $recent_posts; |
|
6287 |
} |
|
6288 |
||
6289 |
/** |
|
6290 |
* Retrieve the list of categories on a given blog. |
|
6291 |
* |
|
6292 |
* @since 1.5.0 |
|
6293 |
* |
|
16 | 6294 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6295 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6296 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6297 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6298 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6299 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6300 |
* } |
5 | 6301 |
* @return array|IXR_Error |
0 | 6302 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6303 |
public function mw_getCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6304 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6305 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6306 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6307 |
$password = $args[2]; |
0 | 6308 |
|
16 | 6309 |
$user = $this->login( $username, $password ); |
6310 |
if ( ! $user ) { |
|
0 | 6311 |
return $this->error; |
9 | 6312 |
} |
6313 |
||
6314 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6315 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6316 |
} |
0 | 6317 |
|
5 | 6318 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6319 |
do_action( 'xmlrpc_call', 'metaWeblog.getCategories', $args, $this ); |
0 | 6320 |
|
6321 |
$categories_struct = array(); |
|
6322 |
||
16 | 6323 |
$cats = get_categories( array( 'get' => 'all' ) ); |
6324 |
if ( $cats ) { |
|
0 | 6325 |
foreach ( $cats as $cat ) { |
9 | 6326 |
$struct = array(); |
6327 |
$struct['categoryId'] = $cat->term_id; |
|
6328 |
$struct['parentId'] = $cat->parent; |
|
6329 |
$struct['description'] = $cat->name; |
|
0 | 6330 |
$struct['categoryDescription'] = $cat->description; |
9 | 6331 |
$struct['categoryName'] = $cat->name; |
6332 |
$struct['htmlUrl'] = esc_html( get_category_link( $cat->term_id ) ); |
|
6333 |
$struct['rssUrl'] = esc_html( get_category_feed_link( $cat->term_id, 'rss2' ) ); |
|
0 | 6334 |
|
6335 |
$categories_struct[] = $struct; |
|
6336 |
} |
|
6337 |
} |
|
6338 |
||
6339 |
return $categories_struct; |
|
6340 |
} |
|
6341 |
||
6342 |
/** |
|
6343 |
* Uploads a file, following your settings. |
|
6344 |
* |
|
6345 |
* Adapted from a patch by Johann Richard. |
|
6346 |
* |
|
6347 |
* @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/ |
|
6348 |
* |
|
6349 |
* @since 1.5.0 |
|
6350 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6351 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6352 |
* |
16 | 6353 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6354 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6355 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6356 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6357 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6358 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6359 |
* @type array $data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6360 |
* } |
5 | 6361 |
* @return array|IXR_Error |
0 | 6362 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6363 |
public function mw_newMediaObject( $args ) { |
0 | 6364 |
global $wpdb; |
6365 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6366 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6367 |
$password = $this->escape( $args[2] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6368 |
$data = $args[3]; |
0 | 6369 |
|
6370 |
$name = sanitize_file_name( $data['name'] ); |
|
6371 |
$type = $data['type']; |
|
6372 |
$bits = $data['bits']; |
|
6373 |
||
16 | 6374 |
$user = $this->login( $username, $password ); |
6375 |
if ( ! $user ) { |
|
0 | 6376 |
return $this->error; |
9 | 6377 |
} |
0 | 6378 |
|
5 | 6379 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6380 |
do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject', $args, $this ); |
0 | 6381 |
|
9 | 6382 |
if ( ! current_user_can( 'upload_files' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6383 |
$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
|
6384 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6385 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6386 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6387 |
if ( is_multisite() && upload_is_user_over_quota( false ) ) { |
9 | 6388 |
$this->error = new IXR_Error( |
6389 |
401, |
|
6390 |
sprintf( |
|
16 | 6391 |
/* translators: %s: Allowed space allocation. */ |
9 | 6392 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
6393 |
size_format( get_space_allowed() * MB_IN_BYTES ) |
|
6394 |
) |
|
6395 |
); |
|
0 | 6396 |
return $this->error; |
6397 |
} |
|
6398 |
||
5 | 6399 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6400 |
* Filters whether to preempt the XML-RPC media upload. |
5 | 6401 |
* |
6402 |
* Passing a truthy value will effectively short-circuit the media upload, |
|
6403 |
* returning that value as a 500 error instead. |
|
6404 |
* |
|
6405 |
* @since 2.1.0 |
|
6406 |
* |
|
6407 |
* @param bool $error Whether to pre-empt the media upload. Default false. |
|
6408 |
*/ |
|
16 | 6409 |
$upload_err = apply_filters( 'pre_upload_error', false ); |
6410 |
if ( $upload_err ) { |
|
5 | 6411 |
return new IXR_Error( 500, $upload_err ); |
6412 |
} |
|
0 | 6413 |
|
9 | 6414 |
$upload = wp_upload_bits( $name, null, $bits ); |
6415 |
if ( ! empty( $upload['error'] ) ) { |
|
16 | 6416 |
/* translators: 1: File name, 2: Error message. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6417 |
$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
|
6418 |
return new IXR_Error( 500, $errorString ); |
0 | 6419 |
} |
16 | 6420 |
// Construct the attachment array. |
0 | 6421 |
$post_id = 0; |
6422 |
if ( ! empty( $data['post_id'] ) ) { |
|
6423 |
$post_id = (int) $data['post_id']; |
|
6424 |
||
9 | 6425 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6426 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6427 |
} |
0 | 6428 |
} |
6429 |
$attachment = array( |
|
9 | 6430 |
'post_title' => $name, |
6431 |
'post_content' => '', |
|
6432 |
'post_type' => 'attachment', |
|
6433 |
'post_parent' => $post_id, |
|
0 | 6434 |
'post_mime_type' => $type, |
9 | 6435 |
'guid' => $upload['url'], |
0 | 6436 |
); |
6437 |
||
16 | 6438 |
// Save the data. |
9 | 6439 |
$id = wp_insert_attachment( $attachment, $upload['file'], $post_id ); |
0 | 6440 |
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
6441 |
||
5 | 6442 |
/** |
6443 |
* Fires after a new attachment has been added via the XML-RPC MovableType API. |
|
6444 |
* |
|
6445 |
* @since 3.4.0 |
|
6446 |
* |
|
6447 |
* @param int $id ID of the new attachment. |
|
6448 |
* @param array $args An array of arguments to add the attachment. |
|
6449 |
*/ |
|
16 | 6450 |
do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 6451 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6452 |
$struct = $this->_prepare_media_item( get_post( $id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6453 |
|
16 | 6454 |
// Deprecated values. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6455 |
$struct['id'] = $struct['attachment_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6456 |
$struct['file'] = $struct['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6457 |
$struct['url'] = $struct['link']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6458 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6459 |
return $struct; |
0 | 6460 |
} |
6461 |
||
16 | 6462 |
/* |
6463 |
* MovableType API functions. |
|
6464 |
* Specs on http://www.movabletype.org/docs/mtmanual_programmatic.html |
|
0 | 6465 |
*/ |
6466 |
||
6467 |
/** |
|
6468 |
* Retrieve the post titles of recent posts. |
|
6469 |
* |
|
6470 |
* @since 1.5.0 |
|
6471 |
* |
|
16 | 6472 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6473 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6474 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6475 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6476 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6477 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6478 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6479 |
* } |
5 | 6480 |
* @return array|IXR_Error |
0 | 6481 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6482 |
public function mt_getRecentPostTitles( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6483 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6484 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6485 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6486 |
$password = $args[2]; |
9 | 6487 |
if ( isset( $args[3] ) ) { |
0 | 6488 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6489 |
} else { |
0 | 6490 |
$query = array(); |
9 | 6491 |
} |
6492 |
||
16 | 6493 |
$user = $this->login( $username, $password ); |
6494 |
if ( ! $user ) { |
|
0 | 6495 |
return $this->error; |
9 | 6496 |
} |
0 | 6497 |
|
5 | 6498 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6499 |
do_action( 'xmlrpc_call', 'mt.getRecentPostTitles', $args, $this ); |
0 | 6500 |
|
6501 |
$posts_list = wp_get_recent_posts( $query ); |
|
6502 |
||
9 | 6503 |
if ( ! $posts_list ) { |
6504 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 6505 |
return $this->error; |
6506 |
} |
|
6507 |
||
5 | 6508 |
$recent_posts = array(); |
0 | 6509 |
|
9 | 6510 |
foreach ( $posts_list as $entry ) { |
6511 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6512 |
continue; |
9 | 6513 |
} |
6514 |
||
6515 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
0 | 6516 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
6517 |
||
5 | 6518 |
$recent_posts[] = array( |
9 | 6519 |
'dateCreated' => $post_date, |
6520 |
'userid' => $entry['post_author'], |
|
6521 |
'postid' => (string) $entry['ID'], |
|
6522 |
'title' => $entry['post_title'], |
|
6523 |
'post_status' => $entry['post_status'], |
|
6524 |
'date_created_gmt' => $post_date_gmt, |
|
0 | 6525 |
); |
6526 |
} |
|
6527 |
||
6528 |
return $recent_posts; |
|
6529 |
} |
|
6530 |
||
6531 |
/** |
|
6532 |
* Retrieve list of all categories on blog. |
|
6533 |
* |
|
6534 |
* @since 1.5.0 |
|
6535 |
* |
|
16 | 6536 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6537 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6538 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6539 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6540 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6541 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6542 |
* } |
5 | 6543 |
* @return array|IXR_Error |
0 | 6544 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6545 |
public function mt_getCategoryList( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6546 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6548 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6549 |
$password = $args[2]; |
0 | 6550 |
|
16 | 6551 |
$user = $this->login( $username, $password ); |
6552 |
if ( ! $user ) { |
|
0 | 6553 |
return $this->error; |
9 | 6554 |
} |
6555 |
||
6556 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6557 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6558 |
} |
0 | 6559 |
|
5 | 6560 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6561 |
do_action( 'xmlrpc_call', 'mt.getCategoryList', $args, $this ); |
0 | 6562 |
|
6563 |
$categories_struct = array(); |
|
6564 |
||
16 | 6565 |
$cats = get_categories( |
9 | 6566 |
array( |
6567 |
'hide_empty' => 0, |
|
6568 |
'hierarchical' => 0, |
|
6569 |
) |
|
16 | 6570 |
); |
6571 |
if ( $cats ) { |
|
0 | 6572 |
foreach ( $cats as $cat ) { |
9 | 6573 |
$struct = array(); |
6574 |
$struct['categoryId'] = $cat->term_id; |
|
0 | 6575 |
$struct['categoryName'] = $cat->name; |
6576 |
||
6577 |
$categories_struct[] = $struct; |
|
6578 |
} |
|
6579 |
} |
|
6580 |
||
6581 |
return $categories_struct; |
|
6582 |
} |
|
6583 |
||
6584 |
/** |
|
6585 |
* Retrieve post categories. |
|
6586 |
* |
|
6587 |
* @since 1.5.0 |
|
6588 |
* |
|
16 | 6589 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6590 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6592 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6593 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6594 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6595 |
* } |
5 | 6596 |
* @return array|IXR_Error |
0 | 6597 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6598 |
public function mt_getPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6599 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6600 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6601 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6602 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6603 |
$password = $args[2]; |
0 | 6604 |
|
16 | 6605 |
$user = $this->login( $username, $password ); |
6606 |
if ( ! $user ) { |
|
0 | 6607 |
return $this->error; |
9 | 6608 |
} |
6609 |
||
6610 |
if ( ! get_post( $post_ID ) ) { |
|
0 | 6611 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6612 |
} |
6613 |
||
6614 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6615 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6616 |
} |
0 | 6617 |
|
5 | 6618 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6619 |
do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this ); |
0 | 6620 |
|
6621 |
$categories = array(); |
|
18 | 6622 |
$catids = wp_get_post_categories( (int) $post_ID ); |
16 | 6623 |
// First listed category will be the primary category. |
0 | 6624 |
$isPrimary = true; |
6625 |
foreach ( $catids as $catid ) { |
|
6626 |
$categories[] = array( |
|
9 | 6627 |
'categoryName' => get_cat_name( $catid ), |
6628 |
'categoryId' => (string) $catid, |
|
6629 |
'isPrimary' => $isPrimary, |
|
0 | 6630 |
); |
9 | 6631 |
$isPrimary = false; |
0 | 6632 |
} |
6633 |
||
6634 |
return $categories; |
|
6635 |
} |
|
6636 |
||
6637 |
/** |
|
6638 |
* Sets categories for a post. |
|
6639 |
* |
|
6640 |
* @since 1.5.0 |
|
6641 |
* |
|
16 | 6642 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6643 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6644 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6645 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6646 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6647 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6648 |
* @type array $categories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6649 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6650 |
* @return true|IXR_Error True on success. |
0 | 6651 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6652 |
public function mt_setPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6653 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6654 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6655 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6656 |
$username = $args[1]; |
0 | 6657 |
$password = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6658 |
$categories = $args[3]; |
0 | 6659 |
|
16 | 6660 |
$user = $this->login( $username, $password ); |
6661 |
if ( ! $user ) { |
|
0 | 6662 |
return $this->error; |
9 | 6663 |
} |
0 | 6664 |
|
5 | 6665 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6666 |
do_action( 'xmlrpc_call', 'mt.setPostCategories', $args, $this ); |
0 | 6667 |
|
9 | 6668 |
if ( ! get_post( $post_ID ) ) { |
0 | 6669 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6670 |
} |
6671 |
||
6672 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6673 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
|
6674 |
} |
|
0 | 6675 |
|
6676 |
$catids = array(); |
|
6677 |
foreach ( $categories as $cat ) { |
|
6678 |
$catids[] = $cat['categoryId']; |
|
6679 |
} |
|
6680 |
||
9 | 6681 |
wp_set_post_categories( $post_ID, $catids ); |
0 | 6682 |
|
6683 |
return true; |
|
6684 |
} |
|
6685 |
||
6686 |
/** |
|
6687 |
* Retrieve an array of methods supported by this server. |
|
6688 |
* |
|
6689 |
* @since 1.5.0 |
|
6690 |
* |
|
6691 |
* @return array |
|
6692 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6693 |
public function mt_supportedMethods() { |
5 | 6694 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6695 |
do_action( 'xmlrpc_call', 'mt.supportedMethods', array(), $this ); |
0 | 6696 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6697 |
return array_keys( $this->methods ); |
0 | 6698 |
} |
6699 |
||
6700 |
/** |
|
6701 |
* Retrieve an empty array because we don't support per-post text filters. |
|
6702 |
* |
|
6703 |
* @since 1.5.0 |
|
6704 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6705 |
public function mt_supportedTextFilters() { |
5 | 6706 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6707 |
do_action( 'xmlrpc_call', 'mt.supportedTextFilters', array(), $this ); |
5 | 6708 |
|
6709 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6710 |
* Filters the MoveableType text filters list for XML-RPC. |
5 | 6711 |
* |
6712 |
* @since 2.2.0 |
|
6713 |
* |
|
6714 |
* @param array $filters An array of text filters. |
|
6715 |
*/ |
|
6716 |
return apply_filters( 'xmlrpc_text_filters', array() ); |
|
0 | 6717 |
} |
6718 |
||
6719 |
/** |
|
6720 |
* Retrieve trackbacks sent to a given post. |
|
6721 |
* |
|
6722 |
* @since 1.5.0 |
|
6723 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6724 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6725 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6726 |
* @param int $post_ID |
5 | 6727 |
* @return array|IXR_Error |
0 | 6728 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6729 |
public function mt_getTrackbackPings( $post_ID ) { |
0 | 6730 |
global $wpdb; |
6731 |
||
5 | 6732 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6733 |
do_action( 'xmlrpc_call', 'mt.getTrackbackPings', $post_ID, $this ); |
0 | 6734 |
|
9 | 6735 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
6736 |
||
6737 |
if ( ! $actual_post ) { |
|
6738 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
6739 |
} |
|
6740 |
||
6741 |
$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 ) ); |
|
6742 |
||
6743 |
if ( ! $comments ) { |
|
0 | 6744 |
return array(); |
9 | 6745 |
} |
0 | 6746 |
|
6747 |
$trackback_pings = array(); |
|
6748 |
foreach ( $comments as $comment ) { |
|
16 | 6749 |
if ( 'trackback' === $comment->comment_type ) { |
9 | 6750 |
$content = $comment->comment_content; |
6751 |
$title = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) ); |
|
0 | 6752 |
$trackback_pings[] = array( |
6753 |
'pingTitle' => $title, |
|
6754 |
'pingURL' => $comment->comment_author_url, |
|
9 | 6755 |
'pingIP' => $comment->comment_author_IP, |
0 | 6756 |
); |
6757 |
} |
|
6758 |
} |
|
6759 |
||
6760 |
return $trackback_pings; |
|
6761 |
} |
|
6762 |
||
6763 |
/** |
|
6764 |
* Sets a post's publish status to 'publish'. |
|
6765 |
* |
|
6766 |
* @since 1.5.0 |
|
6767 |
* |
|
16 | 6768 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6769 |
* Method arguments. Note: arguments must be ordered as documented. |
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 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6772 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6773 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6774 |
* } |
5 | 6775 |
* @return int|IXR_Error |
0 | 6776 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6777 |
public function mt_publishPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6778 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6779 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6780 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6781 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6782 |
$password = $args[2]; |
0 | 6783 |
|
16 | 6784 |
$user = $this->login( $username, $password ); |
6785 |
if ( ! $user ) { |
|
0 | 6786 |
return $this->error; |
9 | 6787 |
} |
0 | 6788 |
|
5 | 6789 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6790 |
do_action( 'xmlrpc_call', 'mt.publishPost', $args, $this ); |
0 | 6791 |
|
9 | 6792 |
$postdata = get_post( $post_ID, ARRAY_A ); |
6793 |
if ( ! $postdata ) { |
|
0 | 6794 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6795 |
} |
6796 |
||
6797 |
if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6798 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
|
6799 |
} |
|
0 | 6800 |
|
6801 |
$postdata['post_status'] = 'publish'; |
|
6802 |
||
16 | 6803 |
// Retain old categories. |
6804 |
$postdata['post_category'] = wp_get_post_categories( $post_ID ); |
|
9 | 6805 |
$this->escape( $postdata ); |
0 | 6806 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6807 |
return wp_update_post( $postdata ); |
0 | 6808 |
} |
6809 |
||
16 | 6810 |
/* |
6811 |
* Pingback functions. |
|
6812 |
* Specs on www.hixie.ch/specs/pingback/pingback |
|
0 | 6813 |
*/ |
6814 |
||
6815 |
/** |
|
6816 |
* Retrieves a pingback and registers it. |
|
6817 |
* |
|
6818 |
* @since 1.5.0 |
|
6819 |
* |
|
16 | 6820 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6821 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6822 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6823 |
* @type string $pagelinkedfrom |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6824 |
* @type string $pagelinkedto |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6825 |
* } |
5 | 6826 |
* @return string|IXR_Error |
0 | 6827 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6828 |
public function pingback_ping( $args ) { |
0 | 6829 |
global $wpdb; |
6830 |
||
5 | 6831 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6832 |
do_action( 'xmlrpc_call', 'pingback.ping', $args, $this ); |
0 | 6833 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6834 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6835 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6836 |
$pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
9 | 6837 |
$pagelinkedto = str_replace( '&', '&', $args[1] ); |
6838 |
$pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
|
0 | 6839 |
|
5 | 6840 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6841 |
* Filters the pingback source URI. |
5 | 6842 |
* |
6843 |
* @since 3.6.0 |
|
6844 |
* |
|
6845 |
* @param string $pagelinkedfrom URI of the page linked from. |
|
6846 |
* @param string $pagelinkedto URI of the page linked to. |
|
6847 |
*/ |
|
0 | 6848 |
$pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5 | 6849 |
|
9 | 6850 |
if ( ! $pagelinkedfrom ) { |
0 | 6851 |
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
9 | 6852 |
} |
0 | 6853 |
|
16 | 6854 |
// Check if the page linked to is on our site. |
9 | 6855 |
$pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) ); |
6856 |
if ( ! $pos1 ) { |
|
0 | 6857 |
return $this->pingback_error( 0, __( 'Is there no link to us?' ) ); |
9 | 6858 |
} |
0 | 6859 |
|
16 | 6860 |
/* |
6861 |
* Let's find which post is linked to. |
|
6862 |
* FIXME: Does url_to_postid() cover all these cases already? |
|
6863 |
* If so, then let's use it and drop the old code. |
|
6864 |
*/ |
|
9 | 6865 |
$urltest = parse_url( $pagelinkedto ); |
16 | 6866 |
$post_ID = url_to_postid( $pagelinkedto ); |
6867 |
if ( $post_ID ) { |
|
5 | 6868 |
// $way |
9 | 6869 |
} elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) { |
16 | 6870 |
// The path defines the post_ID (archives/p/XXXX). |
9 | 6871 |
$blah = explode( '/', $match[0] ); |
0 | 6872 |
$post_ID = (int) $blah[1]; |
9 | 6873 |
} elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) { |
16 | 6874 |
// The query string defines the post_ID (?p=XXXX). |
9 | 6875 |
$blah = explode( '=', $match[0] ); |
0 | 6876 |
$post_ID = (int) $blah[1]; |
9 | 6877 |
} elseif ( isset( $urltest['fragment'] ) ) { |
16 | 6878 |
// An #anchor is there, it's either... |
18 | 6879 |
if ( (int) $urltest['fragment'] ) { |
16 | 6880 |
// ...an integer #XXXX (simplest case), |
0 | 6881 |
$post_ID = (int) $urltest['fragment']; |
9 | 6882 |
} elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
16 | 6883 |
// ...a post ID in the form 'post-###', |
9 | 6884 |
$post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
6885 |
} elseif ( is_string( $urltest['fragment'] ) ) { |
|
16 | 6886 |
// ...or a string #title, a little more complicated. |
6887 |
$title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] ); |
|
6888 |
$sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
|
6889 |
$post_ID = $wpdb->get_var( $sql ); |
|
6890 |
if ( ! $post_ID ) { |
|
6891 |
// Returning unknown error '0' is better than die()'ing. |
|
9 | 6892 |
return $this->pingback_error( 0, '' ); |
0 | 6893 |
} |
6894 |
} |
|
6895 |
} else { |
|
16 | 6896 |
// TODO: Attempt to extract a post ID from the given URL. |
9 | 6897 |
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 | 6898 |
} |
6899 |
$post_ID = (int) $post_ID; |
|
6900 |
||
9 | 6901 |
$post = get_post( $post_ID ); |
6902 |
||
16 | 6903 |
if ( ! $post ) { // Post not found. |
9 | 6904 |
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.' ) ); |
6905 |
} |
|
6906 |
||
16 | 6907 |
if ( url_to_postid( $pagelinkedfrom ) == $post_ID ) { |
0 | 6908 |
return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); |
9 | 6909 |
} |
0 | 6910 |
|
16 | 6911 |
// Check if pings are on. |
9 | 6912 |
if ( ! pings_open( $post ) ) { |
6913 |
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.' ) ); |
|
6914 |
} |
|
0 | 6915 |
|
16 | 6916 |
// Let's check that the remote site didn't already pingback this entry. |
9 | 6917 |
if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom ) ) ) { |
0 | 6918 |
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
9 | 6919 |
} |
0 | 6920 |
|
16 | 6921 |
// Very stupid, but gives time to the 'from' server to publish! |
9 | 6922 |
sleep( 1 ); |
0 | 6923 |
|
5 | 6924 |
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
6925 |
||
6926 |
/** This filter is documented in wp-includes/class-http.php */ |
|
16 | 6927 |
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $pagelinkedfrom ); |
6928 |
||
6929 |
// Let's check the remote site. |
|
0 | 6930 |
$http_api_args = array( |
9 | 6931 |
'timeout' => 10, |
6932 |
'redirection' => 0, |
|
0 | 6933 |
'limit_response_size' => 153600, // 150 KB |
9 | 6934 |
'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
6935 |
'headers' => array( |
|
5 | 6936 |
'X-Pingback-Forwarded-For' => $remote_ip, |
6937 |
), |
|
0 | 6938 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6939 |
|
16 | 6940 |
$request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
6941 |
$remote_source = wp_remote_retrieve_body( $request ); |
|
6942 |
$remote_source_original = $remote_source; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6943 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6944 |
if ( ! $remote_source ) { |
5 | 6945 |
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
|
6946 |
} |
5 | 6947 |
|
6948 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6949 |
* Filters the pingback remote source. |
5 | 6950 |
* |
6951 |
* @since 2.5.0 |
|
6952 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6953 |
* @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
|
6954 |
* @param string $pagelinkedto URL of the page linked to. |
5 | 6955 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6956 |
$remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
0 | 6957 |
|
6958 |
// Work around bug in strip_tags(): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6959 |
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6960 |
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
9 | 6961 |
$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
|
6962 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6963 |
preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6964 |
$title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6965 |
if ( empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6966 |
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
|
6967 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6968 |
|
16 | 6969 |
// Remove all script and style tags including their content. |
6970 |
$remote_source = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $remote_source ); |
|
6971 |
// Just keep the tag we need. |
|
6972 |
$remote_source = strip_tags( $remote_source, '<a>' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6973 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6974 |
$p = explode( "\n\n", $remote_source ); |
0 | 6975 |
|
9 | 6976 |
$preg_target = preg_quote( $pagelinkedto, '|' ); |
0 | 6977 |
|
6978 |
foreach ( $p as $para ) { |
|
16 | 6979 |
if ( strpos( $para, $pagelinkedto ) !== false ) { // It exists, but is it a link? |
9 | 6980 |
preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context ); |
0 | 6981 |
|
16 | 6982 |
// If the URL isn't in a link context, keep looking. |
9 | 6983 |
if ( empty( $context ) ) { |
0 | 6984 |
continue; |
9 | 6985 |
} |
0 | 6986 |
|
16 | 6987 |
// We're going to use this fake tag to mark the context in a bit. |
6988 |
// The marker is needed in case the link text appears more than once in the paragraph. |
|
9 | 6989 |
$excerpt = preg_replace( '|\</?wpcontext\>|', '', $para ); |
0 | 6990 |
|
6991 |
// prevent really long link text |
|
9 | 6992 |
if ( strlen( $context[1] ) > 100 ) { |
6993 |
$context[1] = substr( $context[1], 0, 100 ) . '…'; |
|
6994 |
} |
|
6995 |
||
16 | 6996 |
$marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // Set up our marker. |
6997 |
$excerpt = str_replace( $context[0], $marker, $excerpt ); // Swap out the link for our marker. |
|
6998 |
$excerpt = strip_tags( $excerpt, '<wpcontext>' ); // Strip all tags but our context marker. |
|
9 | 6999 |
$excerpt = trim( $excerpt ); |
7000 |
$preg_marker = preg_quote( $marker, '|' ); |
|
7001 |
$excerpt = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt ); |
|
16 | 7002 |
$excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper. |
0 | 7003 |
break; |
7004 |
} |
|
7005 |
} |
|
7006 |
||
16 | 7007 |
if ( empty( $context ) ) { // Link to target not found. |
0 | 7008 |
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 | 7009 |
} |
7010 |
||
7011 |
$pagelinkedfrom = str_replace( '&', '&', $pagelinkedfrom ); |
|
7012 |
||
7013 |
$context = '[…] ' . esc_html( $excerpt ) . ' […]'; |
|
0 | 7014 |
$pagelinkedfrom = $this->escape( $pagelinkedfrom ); |
7015 |
||
9 | 7016 |
$comment_post_ID = (int) $post_ID; |
7017 |
$comment_author = $title; |
|
0 | 7018 |
$comment_author_email = ''; |
9 | 7019 |
$this->escape( $comment_author ); |
0 | 7020 |
$comment_author_url = $pagelinkedfrom; |
9 | 7021 |
$comment_content = $context; |
7022 |
$this->escape( $comment_content ); |
|
0 | 7023 |
$comment_type = 'pingback'; |
7024 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7025 |
$commentdata = compact( |
9 | 7026 |
'comment_post_ID', |
7027 |
'comment_author', |
|
7028 |
'comment_author_url', |
|
7029 |
'comment_author_email', |
|
7030 |
'comment_content', |
|
7031 |
'comment_type', |
|
7032 |
'remote_source', |
|
7033 |
'remote_source_original' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7034 |
); |
0 | 7035 |
|
9 | 7036 |
$comment_ID = wp_new_comment( $commentdata ); |
5 | 7037 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7038 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7039 |
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
|
7040 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7041 |
|
5 | 7042 |
/** |
7043 |
* Fires after a post pingback has been sent. |
|
7044 |
* |
|
7045 |
* @since 0.71 |
|
7046 |
* |
|
7047 |
* @param int $comment_ID Comment ID. |
|
7048 |
*/ |
|
7049 |
do_action( 'pingback_post', $comment_ID ); |
|
0 | 7050 |
|
16 | 7051 |
/* 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
|
7052 |
return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
0 | 7053 |
} |
7054 |
||
7055 |
/** |
|
7056 |
* Retrieve array of URLs that pingbacked the given URL. |
|
7057 |
* |
|
7058 |
* Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
|
7059 |
* |
|
7060 |
* @since 1.5.0 |
|
7061 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7062 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7063 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7064 |
* @param string $url |
5 | 7065 |
* @return array|IXR_Error |
0 | 7066 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7067 |
public function pingback_extensions_getPingbacks( $url ) { |
0 | 7068 |
global $wpdb; |
7069 |
||
5 | 7070 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 7071 |
do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks', $url, $this ); |
0 | 7072 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7073 |
$url = $this->escape( $url ); |
0 | 7074 |
|
9 | 7075 |
$post_ID = url_to_postid( $url ); |
7076 |
if ( ! $post_ID ) { |
|
16 | 7077 |
// We aren't sure that the resource is available and/or pingback enabled. |
9 | 7078 |
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.' ) ); |
7079 |
} |
|
7080 |
||
7081 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
7082 |
||
7083 |
if ( ! $actual_post ) { |
|
16 | 7084 |
// No such post = resource not found. |
9 | 7085 |
return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) ); |
7086 |
} |
|
7087 |
||
7088 |
$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 ) ); |
|
7089 |
||
7090 |
if ( ! $comments ) { |
|
0 | 7091 |
return array(); |
9 | 7092 |
} |
0 | 7093 |
|
7094 |
$pingbacks = array(); |
|
7095 |
foreach ( $comments as $comment ) { |
|
16 | 7096 |
if ( 'pingback' === $comment->comment_type ) { |
0 | 7097 |
$pingbacks[] = $comment->comment_author_url; |
9 | 7098 |
} |
0 | 7099 |
} |
7100 |
||
7101 |
return $pingbacks; |
|
7102 |
} |
|
7103 |
||
5 | 7104 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7105 |
* 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
|
7106 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7107 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7108 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7109 |
* @param int $code Error code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7110 |
* @param string $message Error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7111 |
* @return IXR_Error Error object. |
5 | 7112 |
*/ |
0 | 7113 |
protected function pingback_error( $code, $message ) { |
5 | 7114 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7115 |
* Filters the XML-RPC pingback error return. |
5 | 7116 |
* |
7117 |
* @since 3.5.1 |
|
7118 |
* |
|
7119 |
* @param IXR_Error $error An IXR_Error object containing the error code and message. |
|
7120 |
*/ |
|
0 | 7121 |
return apply_filters( 'xmlrpc_pingback_error', new IXR_Error( $code, $message ) ); |
7122 |
} |
|
7123 |
} |