author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* XML-RPC protocol support for WordPress |
|
4 |
* |
|
5 |
* @package WordPress |
|
5 | 6 |
* @subpackage Publishing |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
10 |
* WordPress XMLRPC server implementation. |
|
11 |
* |
|
12 |
* Implements compatibility for Blogger API, MetaWeblog API, MovableType, and |
|
13 |
* pingback. Additional WordPress API for managing comments, pages, posts, |
|
14 |
* options, etc. |
|
15 |
* |
|
16 |
* As of WordPress 3.5.0, XML-RPC is enabled by default. It can be disabled |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::login(). |
0 | 18 |
* |
19 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @see IXR_Server |
0 | 22 |
*/ |
23 |
class wp_xmlrpc_server extends IXR_Server { |
|
5 | 24 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* Methods. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* |
5 | 27 |
* @var array |
28 |
*/ |
|
29 |
public $methods; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
|
5 | 31 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* Blog options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* |
5 | 34 |
* @var array |
35 |
*/ |
|
36 |
public $blog_options; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
|
5 | 38 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* IXR_Error instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* |
5 | 41 |
* @var IXR_Error |
42 |
*/ |
|
43 |
public $error; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
|
0 | 45 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* Flags that the user authentication has failed in this instance of wp_xmlrpc_server. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
protected $auth_failed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* Registers all of the XMLRPC methods that XMLRPC server understands. |
0 | 54 |
* |
55 |
* Sets up server and method property. Passes XMLRPC |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* methods through the {@see 'xmlrpc_methods'} filter to allow plugins to extend |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* or replace XML-RPC methods. |
0 | 58 |
* |
59 |
* @since 1.5.0 |
|
60 |
*/ |
|
5 | 61 |
public function __construct() { |
0 | 62 |
$this->methods = array( |
63 |
// WordPress API |
|
9 | 64 |
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', |
65 |
'wp.newPost' => 'this:wp_newPost', |
|
66 |
'wp.editPost' => 'this:wp_editPost', |
|
67 |
'wp.deletePost' => 'this:wp_deletePost', |
|
68 |
'wp.getPost' => 'this:wp_getPost', |
|
69 |
'wp.getPosts' => 'this:wp_getPosts', |
|
70 |
'wp.newTerm' => 'this:wp_newTerm', |
|
71 |
'wp.editTerm' => 'this:wp_editTerm', |
|
72 |
'wp.deleteTerm' => 'this:wp_deleteTerm', |
|
73 |
'wp.getTerm' => 'this:wp_getTerm', |
|
74 |
'wp.getTerms' => 'this:wp_getTerms', |
|
75 |
'wp.getTaxonomy' => 'this:wp_getTaxonomy', |
|
76 |
'wp.getTaxonomies' => 'this:wp_getTaxonomies', |
|
77 |
'wp.getUser' => 'this:wp_getUser', |
|
78 |
'wp.getUsers' => 'this:wp_getUsers', |
|
79 |
'wp.getProfile' => 'this:wp_getProfile', |
|
80 |
'wp.editProfile' => 'this:wp_editProfile', |
|
81 |
'wp.getPage' => 'this:wp_getPage', |
|
82 |
'wp.getPages' => 'this:wp_getPages', |
|
83 |
'wp.newPage' => 'this:wp_newPage', |
|
84 |
'wp.deletePage' => 'this:wp_deletePage', |
|
85 |
'wp.editPage' => 'this:wp_editPage', |
|
86 |
'wp.getPageList' => 'this:wp_getPageList', |
|
87 |
'wp.getAuthors' => 'this:wp_getAuthors', |
|
88 |
'wp.getCategories' => 'this:mw_getCategories', // Alias |
|
89 |
'wp.getTags' => 'this:wp_getTags', |
|
90 |
'wp.newCategory' => 'this:wp_newCategory', |
|
91 |
'wp.deleteCategory' => 'this:wp_deleteCategory', |
|
92 |
'wp.suggestCategories' => 'this:wp_suggestCategories', |
|
93 |
'wp.uploadFile' => 'this:mw_newMediaObject', // Alias |
|
94 |
'wp.deleteFile' => 'this:wp_deletePost', // Alias |
|
95 |
'wp.getCommentCount' => 'this:wp_getCommentCount', |
|
96 |
'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
|
97 |
'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
|
98 |
'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
|
99 |
'wp.getOptions' => 'this:wp_getOptions', |
|
100 |
'wp.setOptions' => 'this:wp_setOptions', |
|
101 |
'wp.getComment' => 'this:wp_getComment', |
|
102 |
'wp.getComments' => 'this:wp_getComments', |
|
103 |
'wp.deleteComment' => 'this:wp_deleteComment', |
|
104 |
'wp.editComment' => 'this:wp_editComment', |
|
105 |
'wp.newComment' => 'this:wp_newComment', |
|
106 |
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', |
|
107 |
'wp.getMediaItem' => 'this:wp_getMediaItem', |
|
108 |
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', |
|
109 |
'wp.getPostFormats' => 'this:wp_getPostFormats', |
|
110 |
'wp.getPostType' => 'this:wp_getPostType', |
|
111 |
'wp.getPostTypes' => 'this:wp_getPostTypes', |
|
112 |
'wp.getRevisions' => 'this:wp_getRevisions', |
|
113 |
'wp.restoreRevision' => 'this:wp_restoreRevision', |
|
0 | 114 |
|
115 |
// Blogger API |
|
9 | 116 |
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
117 |
'blogger.getUserInfo' => 'this:blogger_getUserInfo', |
|
118 |
'blogger.getPost' => 'this:blogger_getPost', |
|
119 |
'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', |
|
120 |
'blogger.newPost' => 'this:blogger_newPost', |
|
121 |
'blogger.editPost' => 'this:blogger_editPost', |
|
122 |
'blogger.deletePost' => 'this:blogger_deletePost', |
|
0 | 123 |
|
124 |
// MetaWeblog API (with MT extensions to structs) |
|
9 | 125 |
'metaWeblog.newPost' => 'this:mw_newPost', |
126 |
'metaWeblog.editPost' => 'this:mw_editPost', |
|
127 |
'metaWeblog.getPost' => 'this:mw_getPost', |
|
128 |
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', |
|
129 |
'metaWeblog.getCategories' => 'this:mw_getCategories', |
|
130 |
'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', |
|
0 | 131 |
|
132 |
// MetaWeblog API aliases for Blogger API |
|
133 |
// see http://www.xmlrpc.com/stories/storyReader$2460 |
|
9 | 134 |
'metaWeblog.deletePost' => 'this:blogger_deletePost', |
135 |
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|
0 | 136 |
|
137 |
// MovableType API |
|
9 | 138 |
'mt.getCategoryList' => 'this:mt_getCategoryList', |
139 |
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', |
|
140 |
'mt.getPostCategories' => 'this:mt_getPostCategories', |
|
141 |
'mt.setPostCategories' => 'this:mt_setPostCategories', |
|
142 |
'mt.supportedMethods' => 'this:mt_supportedMethods', |
|
143 |
'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', |
|
144 |
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', |
|
145 |
'mt.publishPost' => 'this:mt_publishPost', |
|
0 | 146 |
|
147 |
// PingBack |
|
9 | 148 |
'pingback.ping' => 'this:pingback_ping', |
0 | 149 |
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', |
150 |
||
9 | 151 |
'demo.sayHello' => 'this:sayHello', |
152 |
'demo.addTwoNumbers' => 'this:addTwoNumbers', |
|
0 | 153 |
); |
154 |
||
155 |
$this->initialise_blog_option_info(); |
|
5 | 156 |
|
157 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* Filters the methods exposed by the XML-RPC server. |
5 | 159 |
* |
160 |
* This filter can be used to add new methods, and remove built-in methods. |
|
161 |
* |
|
162 |
* @since 1.5.0 |
|
163 |
* |
|
164 |
* @param array $methods An array of XML-RPC methods. |
|
165 |
*/ |
|
166 |
$this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
|
0 | 167 |
} |
168 |
||
5 | 169 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* Make private/protected methods readable for backward compatibility. |
5 | 171 |
* |
172 |
* @since 4.0.0 |
|
173 |
* |
|
9 | 174 |
* @param string $name Method to call. |
5 | 175 |
* @param array $arguments Arguments to pass when calling. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* @return array|IXR_Error|false Return value of the callback, false otherwise. |
5 | 177 |
*/ |
178 |
public function __call( $name, $arguments ) { |
|
179 |
if ( '_multisite_getUsersBlogs' === $name ) { |
|
180 |
return call_user_func_array( array( $this, $name ), $arguments ); |
|
181 |
} |
|
182 |
return false; |
|
183 |
} |
|
184 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* Serves the XML-RPC request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
*/ |
5 | 190 |
public function serve_request() { |
9 | 191 |
$this->IXR_Server( $this->methods ); |
0 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Test XMLRPC API by saying, "Hello!" to client. |
|
196 |
* |
|
197 |
* @since 1.5.0 |
|
198 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* @return string Hello string response. |
0 | 200 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
public function sayHello() { |
0 | 202 |
return 'Hello!'; |
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Test XMLRPC API by adding two numbers for client. |
|
207 |
* |
|
208 |
* @since 1.5.0 |
|
209 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* @type int $number1 A number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* @type int $number2 A second number to add. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
* @return int Sum of the two given numbers. |
0 | 217 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
public function addTwoNumbers( $args ) { |
0 | 219 |
$number1 = $args[0]; |
220 |
$number2 = $args[1]; |
|
221 |
return $number1 + $number2; |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Log user in. |
|
226 |
* |
|
227 |
* @since 2.8.0 |
|
228 |
* |
|
229 |
* @param string $username User's username. |
|
230 |
* @param string $password User's password. |
|
5 | 231 |
* @return WP_User|bool WP_User object if authentication passed, false otherwise |
0 | 232 |
*/ |
5 | 233 |
public function login( $username, $password ) { |
234 |
/* |
|
235 |
* Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
|
236 |
* option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
|
237 |
*/ |
|
238 |
$enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
|
239 |
if ( false === $enabled ) { |
|
240 |
$enabled = apply_filters( 'option_enable_xmlrpc', true ); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* Filters whether XML-RPC methods requiring authentication are enabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* Contrary to the way it's named, this filter does not control whether XML-RPC is *fully* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* enabled, rather, it only controls whether XML-RPC methods requiring authentication - such |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* as for publishing purposes - are enabled. |
5 | 249 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* Further, the filter does not control whether pingbacks or other custom endpoints that don't |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* require authentication are enabled. This behavior is expected, and due to how parity was matched |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* with the `enable_xmlrpc` UI option the filter replaced when it was introduced in 3.5. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* To disable XML-RPC methods that require authentication, use: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* add_filter( 'xmlrpc_enabled', '__return_false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
* and {@see 'xmlrpc_element_limit'} hooks. |
5 | 260 |
* |
261 |
* @since 3.5.0 |
|
262 |
* |
|
263 |
* @param bool $enabled Whether XML-RPC is enabled. Default true. |
|
264 |
*/ |
|
0 | 265 |
$enabled = apply_filters( 'xmlrpc_enabled', $enabled ); |
266 |
||
267 |
if ( ! $enabled ) { |
|
268 |
$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
|
269 |
return false; |
|
270 |
} |
|
271 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
if ( $this->auth_failed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$user = new WP_Error( 'login_prevented' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$user = wp_authenticate( $username, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
if ( is_wp_error( $user ) ) { |
0 | 279 |
$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) ); |
5 | 280 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
// Flag that authentication has failed once on this wp_xmlrpc_server instance |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
$this->auth_failed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
|
5 | 284 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* Filters the XML-RPC user login error message. |
5 | 286 |
* |
287 |
* @since 3.5.0 |
|
288 |
* |
|
289 |
* @param string $error The XML-RPC error message. |
|
290 |
* @param WP_User $user WP_User object. |
|
291 |
*/ |
|
0 | 292 |
$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user ); |
293 |
return false; |
|
294 |
} |
|
295 |
||
296 |
wp_set_current_user( $user->ID ); |
|
297 |
return $user; |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* Check user's credentials. Deprecated. |
|
302 |
* |
|
303 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* @deprecated 2.8.0 Use wp_xmlrpc_server::login() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
* @see wp_xmlrpc_server::login() |
0 | 306 |
* |
307 |
* @param string $username User's username. |
|
308 |
* @param string $password User's password. |
|
309 |
* @return bool Whether authentication passed. |
|
310 |
*/ |
|
5 | 311 |
public function login_pass_ok( $username, $password ) { |
0 | 312 |
return (bool) $this->login( $username, $password ); |
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
* Escape string or array of strings for database. |
|
317 |
* |
|
318 |
* @since 1.5.2 |
|
319 |
* |
|
320 |
* @param string|array $data Escape single string or array of strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* @return string|void Returns with string is passed, alters by-reference |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* when array is passed. |
0 | 323 |
*/ |
5 | 324 |
public function escape( &$data ) { |
9 | 325 |
if ( ! is_array( $data ) ) { |
0 | 326 |
return wp_slash( $data ); |
9 | 327 |
} |
0 | 328 |
|
329 |
foreach ( $data as &$v ) { |
|
9 | 330 |
if ( is_array( $v ) ) { |
0 | 331 |
$this->escape( $v ); |
9 | 332 |
} elseif ( ! is_object( $v ) ) { |
0 | 333 |
$v = wp_slash( $v ); |
9 | 334 |
} |
0 | 335 |
} |
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Retrieve custom fields for post. |
|
340 |
* |
|
341 |
* @since 2.5.0 |
|
342 |
* |
|
343 |
* @param int $post_id Post ID. |
|
344 |
* @return array Custom fields, if exist. |
|
345 |
*/ |
|
9 | 346 |
public function get_custom_fields( $post_id ) { |
0 | 347 |
$post_id = (int) $post_id; |
348 |
||
349 |
$custom_fields = array(); |
|
350 |
||
9 | 351 |
foreach ( (array) has_meta( $post_id ) as $meta ) { |
0 | 352 |
// Don't expose protected fields. |
9 | 353 |
if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) { |
0 | 354 |
continue; |
9 | 355 |
} |
0 | 356 |
|
357 |
$custom_fields[] = array( |
|
9 | 358 |
'id' => $meta['meta_id'], |
359 |
'key' => $meta['meta_key'], |
|
360 |
'value' => $meta['meta_value'], |
|
0 | 361 |
); |
362 |
} |
|
363 |
||
364 |
return $custom_fields; |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Set custom fields for post. |
|
369 |
* |
|
370 |
* @since 2.5.0 |
|
371 |
* |
|
372 |
* @param int $post_id Post ID. |
|
373 |
* @param array $fields Custom fields. |
|
374 |
*/ |
|
9 | 375 |
public function set_custom_fields( $post_id, $fields ) { |
0 | 376 |
$post_id = (int) $post_id; |
377 |
||
378 |
foreach ( (array) $fields as $meta ) { |
|
9 | 379 |
if ( isset( $meta['id'] ) ) { |
0 | 380 |
$meta['id'] = (int) $meta['id']; |
9 | 381 |
$pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
if ( ! $pmeta || $pmeta->post_id != $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
|
9 | 387 |
if ( isset( $meta['key'] ) ) { |
0 | 388 |
$meta['key'] = wp_unslash( $meta['key'] ); |
9 | 389 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
0 | 390 |
continue; |
9 | 391 |
} |
0 | 392 |
$meta['value'] = wp_unslash( $meta['value'] ); |
9 | 393 |
if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) { |
0 | 394 |
update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
9 | 395 |
} |
0 | 396 |
} elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
397 |
delete_metadata_by_mid( 'post', $meta['id'] ); |
|
398 |
} |
|
399 |
} elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { |
|
400 |
add_post_meta( $post_id, $meta['key'], $meta['value'] ); |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* Retrieve custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* @return array Array of custom fields, if they exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
public function get_term_custom_fields( $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
$custom_fields = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
$custom_fields[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
'id' => $meta['meta_id'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
'key' => $meta['meta_key'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
'value' => $meta['meta_value'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
return $custom_fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
* Set custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
* @param array $fields Custom fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
public function set_term_custom_fields( $term_id, $fields ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
foreach ( (array) $fields as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
if ( isset( $meta['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
$meta['id'] = (int) $meta['id']; |
9 | 448 |
$pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
if ( isset( $meta['key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
$meta['key'] = wp_unslash( $meta['key'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
$meta['value'] = wp_unslash( $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
} elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
delete_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
} elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
/** |
0 | 468 |
* Set up blog options property. |
469 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* Passes property through {@see 'xmlrpc_blog_options'} filter. |
0 | 471 |
* |
472 |
* @since 2.6.0 |
|
473 |
*/ |
|
5 | 474 |
public function initialise_blog_option_info() { |
0 | 475 |
$this->blog_options = array( |
476 |
// Read only options |
|
9 | 477 |
'software_name' => array( |
478 |
'desc' => __( 'Software Name' ), |
|
479 |
'readonly' => true, |
|
480 |
'value' => 'WordPress', |
|
0 | 481 |
), |
9 | 482 |
'software_version' => array( |
483 |
'desc' => __( 'Software Version' ), |
|
484 |
'readonly' => true, |
|
485 |
'value' => get_bloginfo( 'version' ), |
|
0 | 486 |
), |
9 | 487 |
'blog_url' => array( |
488 |
'desc' => __( 'WordPress Address (URL)' ), |
|
489 |
'readonly' => true, |
|
490 |
'option' => 'siteurl', |
|
0 | 491 |
), |
9 | 492 |
'home_url' => array( |
493 |
'desc' => __( 'Site Address (URL)' ), |
|
494 |
'readonly' => true, |
|
495 |
'option' => 'home', |
|
0 | 496 |
), |
9 | 497 |
'login_url' => array( |
498 |
'desc' => __( 'Login Address (URL)' ), |
|
499 |
'readonly' => true, |
|
500 |
'value' => wp_login_url(), |
|
0 | 501 |
), |
9 | 502 |
'admin_url' => array( |
503 |
'desc' => __( 'The URL to the admin area' ), |
|
504 |
'readonly' => true, |
|
505 |
'value' => get_admin_url(), |
|
0 | 506 |
), |
507 |
'image_default_link_type' => array( |
|
9 | 508 |
'desc' => __( 'Image default link type' ), |
509 |
'readonly' => true, |
|
510 |
'option' => 'image_default_link_type', |
|
0 | 511 |
), |
9 | 512 |
'image_default_size' => array( |
513 |
'desc' => __( 'Image default size' ), |
|
514 |
'readonly' => true, |
|
515 |
'option' => 'image_default_size', |
|
0 | 516 |
), |
9 | 517 |
'image_default_align' => array( |
518 |
'desc' => __( 'Image default align' ), |
|
519 |
'readonly' => true, |
|
520 |
'option' => 'image_default_align', |
|
0 | 521 |
), |
9 | 522 |
'template' => array( |
523 |
'desc' => __( 'Template' ), |
|
524 |
'readonly' => true, |
|
525 |
'option' => 'template', |
|
0 | 526 |
), |
9 | 527 |
'stylesheet' => array( |
528 |
'desc' => __( 'Stylesheet' ), |
|
529 |
'readonly' => true, |
|
530 |
'option' => 'stylesheet', |
|
0 | 531 |
), |
9 | 532 |
'post_thumbnail' => array( |
533 |
'desc' => __( 'Post Thumbnail' ), |
|
534 |
'readonly' => true, |
|
535 |
'value' => current_theme_supports( 'post-thumbnails' ), |
|
0 | 536 |
), |
537 |
||
538 |
// Updatable options |
|
9 | 539 |
'time_zone' => array( |
540 |
'desc' => __( 'Time Zone' ), |
|
541 |
'readonly' => false, |
|
542 |
'option' => 'gmt_offset', |
|
0 | 543 |
), |
9 | 544 |
'blog_title' => array( |
545 |
'desc' => __( 'Site Title' ), |
|
546 |
'readonly' => false, |
|
547 |
'option' => 'blogname', |
|
0 | 548 |
), |
9 | 549 |
'blog_tagline' => array( |
550 |
'desc' => __( 'Site Tagline' ), |
|
551 |
'readonly' => false, |
|
552 |
'option' => 'blogdescription', |
|
0 | 553 |
), |
9 | 554 |
'date_format' => array( |
555 |
'desc' => __( 'Date Format' ), |
|
556 |
'readonly' => false, |
|
557 |
'option' => 'date_format', |
|
0 | 558 |
), |
9 | 559 |
'time_format' => array( |
560 |
'desc' => __( 'Time Format' ), |
|
561 |
'readonly' => false, |
|
562 |
'option' => 'time_format', |
|
0 | 563 |
), |
9 | 564 |
'users_can_register' => array( |
565 |
'desc' => __( 'Allow new users to sign up' ), |
|
566 |
'readonly' => false, |
|
567 |
'option' => 'users_can_register', |
|
0 | 568 |
), |
9 | 569 |
'thumbnail_size_w' => array( |
570 |
'desc' => __( 'Thumbnail Width' ), |
|
571 |
'readonly' => false, |
|
572 |
'option' => 'thumbnail_size_w', |
|
0 | 573 |
), |
9 | 574 |
'thumbnail_size_h' => array( |
575 |
'desc' => __( 'Thumbnail Height' ), |
|
576 |
'readonly' => false, |
|
577 |
'option' => 'thumbnail_size_h', |
|
0 | 578 |
), |
9 | 579 |
'thumbnail_crop' => array( |
580 |
'desc' => __( 'Crop thumbnail to exact dimensions' ), |
|
581 |
'readonly' => false, |
|
582 |
'option' => 'thumbnail_crop', |
|
0 | 583 |
), |
9 | 584 |
'medium_size_w' => array( |
585 |
'desc' => __( 'Medium size image width' ), |
|
586 |
'readonly' => false, |
|
587 |
'option' => 'medium_size_w', |
|
0 | 588 |
), |
9 | 589 |
'medium_size_h' => array( |
590 |
'desc' => __( 'Medium size image height' ), |
|
591 |
'readonly' => false, |
|
592 |
'option' => 'medium_size_h', |
|
0 | 593 |
), |
9 | 594 |
'medium_large_size_w' => array( |
595 |
'desc' => __( 'Medium-Large size image width' ), |
|
596 |
'readonly' => false, |
|
597 |
'option' => 'medium_large_size_w', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
), |
9 | 599 |
'medium_large_size_h' => array( |
600 |
'desc' => __( 'Medium-Large size image height' ), |
|
601 |
'readonly' => false, |
|
602 |
'option' => 'medium_large_size_h', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
), |
9 | 604 |
'large_size_w' => array( |
605 |
'desc' => __( 'Large size image width' ), |
|
606 |
'readonly' => false, |
|
607 |
'option' => 'large_size_w', |
|
0 | 608 |
), |
9 | 609 |
'large_size_h' => array( |
610 |
'desc' => __( 'Large size image height' ), |
|
611 |
'readonly' => false, |
|
612 |
'option' => 'large_size_h', |
|
0 | 613 |
), |
9 | 614 |
'default_comment_status' => array( |
615 |
'desc' => __( 'Allow people to post comments on new articles' ), |
|
616 |
'readonly' => false, |
|
617 |
'option' => 'default_comment_status', |
|
0 | 618 |
), |
9 | 619 |
'default_ping_status' => array( |
620 |
'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ), |
|
621 |
'readonly' => false, |
|
622 |
'option' => 'default_ping_status', |
|
623 |
), |
|
0 | 624 |
); |
625 |
||
5 | 626 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* Filters the XML-RPC blog options property. |
5 | 628 |
* |
629 |
* @since 2.6.0 |
|
630 |
* |
|
631 |
* @param array $blog_options An array of XML-RPC blog options. |
|
632 |
*/ |
|
0 | 633 |
$this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); |
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
* Retrieve the blogs of the user. |
|
638 |
* |
|
639 |
* @since 2.6.0 |
|
640 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* } |
5 | 647 |
* @return array|IXR_Error Array contains: |
0 | 648 |
* - 'isAdmin' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* - 'isPrimary' - whether the blog is the user's primary blog |
0 | 650 |
* - 'url' |
651 |
* - 'blogid' |
|
652 |
* - 'blogName' |
|
653 |
* - 'xmlrpc' - url of xmlrpc endpoint |
|
654 |
*/ |
|
5 | 655 |
public function wp_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
if ( ! $this->minimum_args( $args, 2 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
|
0 | 660 |
// If this isn't on WPMU then just use blogger_getUsersBlogs |
9 | 661 |
if ( ! is_multisite() ) { |
0 | 662 |
array_unshift( $args, 1 ); |
663 |
return $this->blogger_getUsersBlogs( $args ); |
|
664 |
} |
|
665 |
||
666 |
$this->escape( $args ); |
|
667 |
||
668 |
$username = $args[0]; |
|
669 |
$password = $args[1]; |
|
670 |
||
9 | 671 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 672 |
return $this->error; |
9 | 673 |
} |
0 | 674 |
|
5 | 675 |
/** |
676 |
* Fires after the XML-RPC user has been authenticated but before the rest of |
|
677 |
* the method logic begins. |
|
678 |
* |
|
679 |
* All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
|
680 |
* equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
|
681 |
* |
|
682 |
* @since 2.5.0 |
|
683 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* @param string $name The method name. |
5 | 685 |
*/ |
0 | 686 |
do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
687 |
||
9 | 688 |
$blogs = (array) get_blogs_of_user( $user->ID ); |
689 |
$struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
$primary_blog_id = 0; |
9 | 691 |
$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
|
692 |
if ( $active_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
$primary_blog_id = (int) $active_blog->blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
} |
0 | 695 |
|
696 |
foreach ( $blogs as $blog ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
// Don't include blogs that aren't hosted at this site. |
9 | 698 |
if ( $blog->site_id != get_current_network_id() ) { |
0 | 699 |
continue; |
9 | 700 |
} |
0 | 701 |
|
702 |
$blog_id = $blog->userblog_id; |
|
703 |
||
704 |
switch_to_blog( $blog_id ); |
|
705 |
||
9 | 706 |
$is_admin = current_user_can( 'manage_options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
$is_primary = ( (int) $blog_id === $primary_blog_id ); |
0 | 708 |
|
709 |
$struct[] = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
'isAdmin' => $is_admin, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
'isPrimary' => $is_primary, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
'blogid' => (string) $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
'blogName' => get_option( 'blogname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
0 | 716 |
); |
717 |
||
718 |
restore_current_blog(); |
|
719 |
} |
|
720 |
||
721 |
return $struct; |
|
722 |
} |
|
723 |
||
724 |
/** |
|
725 |
* Checks if the method received at least the minimum number of arguments. |
|
726 |
* |
|
727 |
* @since 3.4.0 |
|
728 |
* |
|
729 |
* @param string|array $args Sanitize single string or array of strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* @param int $count Minimum number of arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* @return bool if `$args` contains at least $count arguments. |
0 | 732 |
*/ |
733 |
protected function minimum_args( $args, $count ) { |
|
734 |
if ( count( $args ) < $count ) { |
|
735 |
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) ); |
|
736 |
return false; |
|
737 |
} |
|
738 |
||
739 |
return true; |
|
740 |
} |
|
741 |
||
742 |
/** |
|
743 |
* Prepares taxonomy data for return in an XML-RPC object. |
|
744 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
* @param object $taxonomy The unprepared taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
* @param array $fields The subset of taxonomy fields to return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
* @return array The prepared taxonomy data. |
0 | 748 |
*/ |
749 |
protected function _prepare_taxonomy( $taxonomy, $fields ) { |
|
750 |
$_taxonomy = array( |
|
9 | 751 |
'name' => $taxonomy->name, |
752 |
'label' => $taxonomy->label, |
|
0 | 753 |
'hierarchical' => (bool) $taxonomy->hierarchical, |
9 | 754 |
'public' => (bool) $taxonomy->public, |
755 |
'show_ui' => (bool) $taxonomy->show_ui, |
|
756 |
'_builtin' => (bool) $taxonomy->_builtin, |
|
0 | 757 |
); |
758 |
||
9 | 759 |
if ( in_array( 'labels', $fields ) ) { |
0 | 760 |
$_taxonomy['labels'] = (array) $taxonomy->labels; |
9 | 761 |
} |
762 |
||
763 |
if ( in_array( 'cap', $fields ) ) { |
|
0 | 764 |
$_taxonomy['cap'] = (array) $taxonomy->cap; |
9 | 765 |
} |
766 |
||
767 |
if ( in_array( 'menu', $fields ) ) { |
|
0 | 768 |
$_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu; |
9 | 769 |
} |
770 |
||
771 |
if ( in_array( 'object_type', $fields ) ) { |
|
0 | 772 |
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
9 | 773 |
} |
0 | 774 |
|
5 | 775 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
* Filters XML-RPC-prepared data for the given taxonomy. |
5 | 777 |
* |
778 |
* @since 3.4.0 |
|
779 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* @param array $_taxonomy An array of taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @param WP_Taxonomy $taxonomy Taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
* @param array $fields The subset of taxonomy fields to return. |
5 | 783 |
*/ |
0 | 784 |
return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
785 |
} |
|
786 |
||
787 |
/** |
|
788 |
* Prepares term data for return in an XML-RPC object. |
|
789 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* @param array|object $term The unprepared term data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* @return array The prepared term data. |
0 | 792 |
*/ |
793 |
protected function _prepare_term( $term ) { |
|
794 |
$_term = $term; |
|
9 | 795 |
if ( ! is_array( $_term ) ) { |
0 | 796 |
$_term = get_object_vars( $_term ); |
9 | 797 |
} |
0 | 798 |
|
799 |
// For integers which may be larger than XML-RPC supports ensure we return strings. |
|
9 | 800 |
$_term['term_id'] = strval( $_term['term_id'] ); |
801 |
$_term['term_group'] = strval( $_term['term_group'] ); |
|
0 | 802 |
$_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] ); |
9 | 803 |
$_term['parent'] = strval( $_term['parent'] ); |
0 | 804 |
|
805 |
// Count we are happy to return as an integer because people really shouldn't use terms that much. |
|
806 |
$_term['count'] = intval( $_term['count'] ); |
|
807 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
// Get term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
$_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
|
810 |
|
5 | 811 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* Filters XML-RPC-prepared data for the given term. |
5 | 813 |
* |
814 |
* @since 3.4.0 |
|
815 |
* |
|
816 |
* @param array $_term An array of term data. |
|
817 |
* @param array|object $term Term object or array. |
|
818 |
*/ |
|
0 | 819 |
return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
820 |
} |
|
821 |
||
822 |
/** |
|
823 |
* Convert a WordPress date string to an IXR_Date object. |
|
824 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* @param string $date Date string to convert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @return IXR_Date IXR_Date object. |
0 | 827 |
*/ |
828 |
protected function _convert_date( $date ) { |
|
829 |
if ( $date === '0000-00-00 00:00:00' ) { |
|
830 |
return new IXR_Date( '00000000T00:00:00Z' ); |
|
831 |
} |
|
832 |
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); |
|
833 |
} |
|
834 |
||
835 |
/** |
|
836 |
* Convert a WordPress GMT date string to an IXR_Date object. |
|
837 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* @param string $date_gmt WordPress GMT date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
* @param string $date Date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* @return IXR_Date IXR_Date object. |
0 | 841 |
*/ |
842 |
protected function _convert_date_gmt( $date_gmt, $date ) { |
|
843 |
if ( $date !== '0000-00-00 00:00:00' && $date_gmt === '0000-00-00 00:00:00' ) { |
|
844 |
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) ); |
|
845 |
} |
|
846 |
return $this->_convert_date( $date_gmt ); |
|
847 |
} |
|
848 |
||
849 |
/** |
|
850 |
* Prepares post data for return in an XML-RPC object. |
|
851 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
* @param array $post The unprepared post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* @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
|
854 |
* @return array The prepared post data. |
0 | 855 |
*/ |
856 |
protected function _prepare_post( $post, $fields ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
// Holds the data for this post. built up based on $fields. |
0 | 858 |
$_post = array( 'post_id' => strval( $post['ID'] ) ); |
859 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
// Prepare common post fields. |
0 | 861 |
$post_fields = array( |
862 |
'post_title' => $post['post_title'], |
|
863 |
'post_date' => $this->_convert_date( $post['post_date'] ), |
|
864 |
'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
|
865 |
'post_modified' => $this->_convert_date( $post['post_modified'] ), |
|
866 |
'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ), |
|
867 |
'post_status' => $post['post_status'], |
|
868 |
'post_type' => $post['post_type'], |
|
869 |
'post_name' => $post['post_name'], |
|
870 |
'post_author' => $post['post_author'], |
|
871 |
'post_password' => $post['post_password'], |
|
872 |
'post_excerpt' => $post['post_excerpt'], |
|
873 |
'post_content' => $post['post_content'], |
|
874 |
'post_parent' => strval( $post['post_parent'] ), |
|
875 |
'post_mime_type' => $post['post_mime_type'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
'link' => get_permalink( $post['ID'] ), |
0 | 877 |
'guid' => $post['guid'], |
878 |
'menu_order' => intval( $post['menu_order'] ), |
|
879 |
'comment_status' => $post['comment_status'], |
|
880 |
'ping_status' => $post['ping_status'], |
|
881 |
'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), |
|
882 |
); |
|
883 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
// Thumbnail. |
0 | 885 |
$post_fields['post_thumbnail'] = array(); |
9 | 886 |
$thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
0 | 887 |
if ( $thumbnail_id ) { |
9 | 888 |
$thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail'; |
0 | 889 |
$post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
890 |
} |
|
891 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
// Consider future posts as published. |
9 | 893 |
if ( $post_fields['post_status'] === 'future' ) { |
0 | 894 |
$post_fields['post_status'] = 'publish'; |
9 | 895 |
} |
0 | 896 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
// Fill in blank post format. |
0 | 898 |
$post_fields['post_format'] = get_post_format( $post['ID'] ); |
9 | 899 |
if ( empty( $post_fields['post_format'] ) ) { |
0 | 900 |
$post_fields['post_format'] = 'standard'; |
9 | 901 |
} |
0 | 902 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
// Merge requested $post_fields fields into $_post. |
0 | 904 |
if ( in_array( 'post', $fields ) ) { |
905 |
$_post = array_merge( $_post, $post_fields ); |
|
906 |
} else { |
|
907 |
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
|
9 | 908 |
$_post = array_merge( $_post, $requested_fields ); |
0 | 909 |
} |
910 |
||
911 |
$all_taxonomy_fields = in_array( 'taxonomies', $fields ); |
|
912 |
||
913 |
if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) { |
|
914 |
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' ); |
|
9 | 915 |
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies ); |
916 |
$_post['terms'] = array(); |
|
0 | 917 |
foreach ( $terms as $term ) { |
918 |
$_post['terms'][] = $this->_prepare_term( $term ); |
|
919 |
} |
|
920 |
} |
|
921 |
||
9 | 922 |
if ( in_array( 'custom_fields', $fields ) ) { |
0 | 923 |
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] ); |
9 | 924 |
} |
0 | 925 |
|
926 |
if ( in_array( 'enclosure', $fields ) ) { |
|
927 |
$_post['enclosure'] = array(); |
|
9 | 928 |
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' ); |
0 | 929 |
if ( ! empty( $enclosures ) ) { |
9 | 930 |
$encdata = explode( "\n", $enclosures[0] ); |
931 |
$_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
0 | 932 |
$_post['enclosure']['length'] = (int) trim( $encdata[1] ); |
9 | 933 |
$_post['enclosure']['type'] = trim( $encdata[2] ); |
0 | 934 |
} |
935 |
} |
|
936 |
||
5 | 937 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* Filters XML-RPC-prepared date for the given post. |
5 | 939 |
* |
940 |
* @since 3.4.0 |
|
941 |
* |
|
942 |
* @param array $_post An array of modified post data. |
|
943 |
* @param array $post An array of post data. |
|
944 |
* @param array $fields An array of post fields. |
|
945 |
*/ |
|
0 | 946 |
return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields ); |
947 |
} |
|
948 |
||
949 |
/** |
|
950 |
* Prepares post data for return in an XML-RPC object. |
|
951 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* @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
|
954 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* @param WP_Post_Type $post_type Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* @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
|
957 |
* @return array The prepared post type data. |
0 | 958 |
*/ |
959 |
protected function _prepare_post_type( $post_type, $fields ) { |
|
960 |
$_post_type = array( |
|
9 | 961 |
'name' => $post_type->name, |
962 |
'label' => $post_type->label, |
|
0 | 963 |
'hierarchical' => (bool) $post_type->hierarchical, |
9 | 964 |
'public' => (bool) $post_type->public, |
965 |
'show_ui' => (bool) $post_type->show_ui, |
|
966 |
'_builtin' => (bool) $post_type->_builtin, |
|
967 |
'has_archive' => (bool) $post_type->has_archive, |
|
968 |
'supports' => get_all_post_type_supports( $post_type->name ), |
|
0 | 969 |
); |
970 |
||
971 |
if ( in_array( 'labels', $fields ) ) { |
|
972 |
$_post_type['labels'] = (array) $post_type->labels; |
|
973 |
} |
|
974 |
||
975 |
if ( in_array( 'cap', $fields ) ) { |
|
9 | 976 |
$_post_type['cap'] = (array) $post_type->cap; |
0 | 977 |
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; |
978 |
} |
|
979 |
||
980 |
if ( in_array( 'menu', $fields ) ) { |
|
981 |
$_post_type['menu_position'] = (int) $post_type->menu_position; |
|
9 | 982 |
$_post_type['menu_icon'] = $post_type->menu_icon; |
983 |
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; |
|
984 |
} |
|
985 |
||
986 |
if ( in_array( 'taxonomies', $fields ) ) { |
|
0 | 987 |
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
9 | 988 |
} |
0 | 989 |
|
5 | 990 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
* Filters XML-RPC-prepared date for the given post type. |
5 | 992 |
* |
993 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 995 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* @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
|
997 |
* @param WP_Post_Type $post_type Post type object. |
5 | 998 |
*/ |
0 | 999 |
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
1000 |
} |
|
1001 |
||
1002 |
/** |
|
1003 |
* Prepares media item data for return in an XML-RPC object. |
|
1004 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
* @param object $media_item The unprepared media item data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* @param string $thumbnail_size The image size to use for the thumbnail URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* @return array The prepared media item data. |
0 | 1008 |
*/ |
1009 |
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
|
1010 |
$_media_item = array( |
|
1011 |
'attachment_id' => strval( $media_item->ID ), |
|
1012 |
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
|
1013 |
'parent' => $media_item->post_parent, |
|
1014 |
'link' => wp_get_attachment_url( $media_item->ID ), |
|
1015 |
'title' => $media_item->post_title, |
|
1016 |
'caption' => $media_item->post_excerpt, |
|
1017 |
'description' => $media_item->post_content, |
|
1018 |
'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
9 | 1019 |
'type' => $media_item->post_mime_type, |
0 | 1020 |
); |
1021 |
||
1022 |
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
|
9 | 1023 |
if ( $thumbnail_src ) { |
0 | 1024 |
$_media_item['thumbnail'] = $thumbnail_src[0]; |
9 | 1025 |
} else { |
0 | 1026 |
$_media_item['thumbnail'] = $_media_item['link']; |
9 | 1027 |
} |
0 | 1028 |
|
5 | 1029 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* Filters XML-RPC-prepared data for the given media item. |
5 | 1031 |
* |
1032 |
* @since 3.4.0 |
|
1033 |
* |
|
1034 |
* @param array $_media_item An array of media item data. |
|
1035 |
* @param object $media_item Media item object. |
|
1036 |
* @param string $thumbnail_size Image size. |
|
1037 |
*/ |
|
0 | 1038 |
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1039 |
} |
|
1040 |
||
1041 |
/** |
|
1042 |
* Prepares page data for return in an XML-RPC object. |
|
1043 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
* @param object $page The unprepared page data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* @return array The prepared page data. |
0 | 1046 |
*/ |
1047 |
protected function _prepare_page( $page ) { |
|
1048 |
// Get all of the page content and link. |
|
1049 |
$full_page = get_extended( $page->post_content ); |
|
9 | 1050 |
$link = get_permalink( $page->ID ); |
0 | 1051 |
|
1052 |
// Get info the page parent if there is one. |
|
9 | 1053 |
$parent_title = ''; |
0 | 1054 |
if ( ! empty( $page->post_parent ) ) { |
9 | 1055 |
$parent = get_post( $page->post_parent ); |
0 | 1056 |
$parent_title = $parent->post_title; |
1057 |
} |
|
1058 |
||
1059 |
// Determine comment and ping settings. |
|
1060 |
$allow_comments = comments_open( $page->ID ) ? 1 : 0; |
|
9 | 1061 |
$allow_pings = pings_open( $page->ID ) ? 1 : 0; |
0 | 1062 |
|
1063 |
// Format page date. |
|
9 | 1064 |
$page_date = $this->_convert_date( $page->post_date ); |
0 | 1065 |
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); |
1066 |
||
1067 |
// Pull the categories info together. |
|
1068 |
$categories = array(); |
|
5 | 1069 |
if ( is_object_in_taxonomy( 'page', 'category' ) ) { |
1070 |
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { |
|
1071 |
$categories[] = get_cat_name( $cat_id ); |
|
1072 |
} |
|
0 | 1073 |
} |
1074 |
||
1075 |
// Get the author info. |
|
1076 |
$author = get_userdata( $page->post_author ); |
|
1077 |
||
1078 |
$page_template = get_page_template_slug( $page->ID ); |
|
9 | 1079 |
if ( empty( $page_template ) ) { |
0 | 1080 |
$page_template = 'default'; |
9 | 1081 |
} |
0 | 1082 |
|
1083 |
$_page = array( |
|
1084 |
'dateCreated' => $page_date, |
|
1085 |
'userid' => $page->post_author, |
|
1086 |
'page_id' => $page->ID, |
|
1087 |
'page_status' => $page->post_status, |
|
1088 |
'description' => $full_page['main'], |
|
1089 |
'title' => $page->post_title, |
|
1090 |
'link' => $link, |
|
1091 |
'permaLink' => $link, |
|
1092 |
'categories' => $categories, |
|
1093 |
'excerpt' => $page->post_excerpt, |
|
1094 |
'text_more' => $full_page['extended'], |
|
1095 |
'mt_allow_comments' => $allow_comments, |
|
1096 |
'mt_allow_pings' => $allow_pings, |
|
1097 |
'wp_slug' => $page->post_name, |
|
1098 |
'wp_password' => $page->post_password, |
|
1099 |
'wp_author' => $author->display_name, |
|
1100 |
'wp_page_parent_id' => $page->post_parent, |
|
1101 |
'wp_page_parent_title' => $parent_title, |
|
1102 |
'wp_page_order' => $page->menu_order, |
|
1103 |
'wp_author_id' => (string) $author->ID, |
|
1104 |
'wp_author_display_name' => $author->display_name, |
|
1105 |
'date_created_gmt' => $page_date_gmt, |
|
1106 |
'custom_fields' => $this->get_custom_fields( $page->ID ), |
|
9 | 1107 |
'wp_page_template' => $page_template, |
0 | 1108 |
); |
1109 |
||
5 | 1110 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
* Filters XML-RPC-prepared data for the given page. |
5 | 1112 |
* |
1113 |
* @since 3.4.0 |
|
1114 |
* |
|
1115 |
* @param array $_page An array of page data. |
|
1116 |
* @param WP_Post $page Page object. |
|
1117 |
*/ |
|
0 | 1118 |
return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); |
1119 |
} |
|
1120 |
||
1121 |
/** |
|
1122 |
* Prepares comment data for return in an XML-RPC object. |
|
1123 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
* @param object $comment The unprepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
* @return array The prepared comment data. |
0 | 1126 |
*/ |
1127 |
protected function _prepare_comment( $comment ) { |
|
1128 |
// Format page date. |
|
1129 |
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
|
1130 |
||
5 | 1131 |
if ( '0' == $comment->comment_approved ) { |
0 | 1132 |
$comment_status = 'hold'; |
5 | 1133 |
} elseif ( 'spam' == $comment->comment_approved ) { |
0 | 1134 |
$comment_status = 'spam'; |
5 | 1135 |
} elseif ( '1' == $comment->comment_approved ) { |
0 | 1136 |
$comment_status = 'approve'; |
5 | 1137 |
} else { |
0 | 1138 |
$comment_status = $comment->comment_approved; |
5 | 1139 |
} |
0 | 1140 |
$_comment = array( |
1141 |
'date_created_gmt' => $comment_date_gmt, |
|
1142 |
'user_id' => $comment->user_id, |
|
1143 |
'comment_id' => $comment->comment_ID, |
|
1144 |
'parent' => $comment->comment_parent, |
|
1145 |
'status' => $comment_status, |
|
1146 |
'content' => $comment->comment_content, |
|
9 | 1147 |
'link' => get_comment_link( $comment ), |
0 | 1148 |
'post_id' => $comment->comment_post_ID, |
9 | 1149 |
'post_title' => get_the_title( $comment->comment_post_ID ), |
0 | 1150 |
'author' => $comment->comment_author, |
1151 |
'author_url' => $comment->comment_author_url, |
|
1152 |
'author_email' => $comment->comment_author_email, |
|
1153 |
'author_ip' => $comment->comment_author_IP, |
|
1154 |
'type' => $comment->comment_type, |
|
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 comment. |
5 | 1159 |
* |
1160 |
* @since 3.4.0 |
|
1161 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* @param array $_comment An array of prepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* @param WP_Comment $comment Comment object. |
5 | 1164 |
*/ |
0 | 1165 |
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1166 |
} |
|
1167 |
||
1168 |
/** |
|
1169 |
* Prepares user data for return in an XML-RPC object. |
|
1170 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* @param WP_User $user The unprepared user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @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
|
1173 |
* @return array The prepared user data. |
0 | 1174 |
*/ |
1175 |
protected function _prepare_user( $user, $fields ) { |
|
1176 |
$_user = array( 'user_id' => strval( $user->ID ) ); |
|
1177 |
||
1178 |
$user_fields = array( |
|
9 | 1179 |
'username' => $user->user_login, |
1180 |
'first_name' => $user->user_firstname, |
|
1181 |
'last_name' => $user->user_lastname, |
|
1182 |
'registered' => $this->_convert_date( $user->user_registered ), |
|
1183 |
'bio' => $user->user_description, |
|
1184 |
'email' => $user->user_email, |
|
1185 |
'nickname' => $user->nickname, |
|
1186 |
'nicename' => $user->user_nicename, |
|
1187 |
'url' => $user->user_url, |
|
1188 |
'display_name' => $user->display_name, |
|
1189 |
'roles' => $user->roles, |
|
0 | 1190 |
); |
1191 |
||
1192 |
if ( in_array( 'all', $fields ) ) { |
|
1193 |
$_user = array_merge( $_user, $user_fields ); |
|
1194 |
} else { |
|
1195 |
if ( in_array( 'basic', $fields ) ) { |
|
1196 |
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); |
|
9 | 1197 |
$fields = array_merge( $fields, $basic_fields ); |
0 | 1198 |
} |
1199 |
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); |
|
9 | 1200 |
$_user = array_merge( $_user, $requested_fields ); |
0 | 1201 |
} |
1202 |
||
5 | 1203 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
* Filters XML-RPC-prepared data for the given user. |
5 | 1205 |
* |
1206 |
* @since 3.5.0 |
|
1207 |
* |
|
1208 |
* @param array $_user An array of user data. |
|
1209 |
* @param WP_User $user User object. |
|
1210 |
* @param array $fields An array of user fields. |
|
1211 |
*/ |
|
0 | 1212 |
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); |
1213 |
} |
|
1214 |
||
1215 |
/** |
|
1216 |
* Create a new post for any registered post type. |
|
1217 |
* |
|
1218 |
* @since 3.4.0 |
|
1219 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
* @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
|
1221 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
* 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
|
1224 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* @type array $content_struct { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
* 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
|
1230 |
* additional post fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
* @type string $post_type Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
* @type string $post_status Post status. Default 'draft' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* @type string $post_title Post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* @type int $post_author Post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @type string $post_excerpt Post excerpt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* @type string $post_content Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
* @type string $post_date_gmt Post date in GMT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
* @type string $post_date Post date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
* @type string $post_password Post password (20-character limit). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
* @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
|
1242 |
* @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
|
1243 |
* @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
|
1244 |
* `$post_status` is 'private'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
* @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
|
1246 |
* @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
|
1247 |
* @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
|
1248 |
* of term IDs as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
* @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
|
1250 |
* of term names as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* @type array $enclosure { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* 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
|
1253 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* @type string $url URL for the feed enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* @type int $length Size in bytes of the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* @type string $type Mime-type for the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
0 | 1261 |
*/ |
5 | 1262 |
public function wp_newPost( $args ) { |
9 | 1263 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1264 |
return $this->error; |
9 | 1265 |
} |
0 | 1266 |
|
1267 |
$this->escape( $args ); |
|
1268 |
||
1269 |
$username = $args[1]; |
|
1270 |
$password = $args[2]; |
|
1271 |
$content_struct = $args[3]; |
|
1272 |
||
9 | 1273 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 1274 |
return $this->error; |
9 | 1275 |
} |
0 | 1276 |
|
5 | 1277 |
// convert the date field back to IXR form |
1278 |
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
|
1279 |
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1280 |
} |
|
1281 |
||
1282 |
// ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1283 |
// since _insert_post will ignore the non-GMT date if the GMT date is set |
|
1284 |
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
|
1285 |
if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { |
|
1286 |
unset( $content_struct['post_date_gmt'] ); |
|
1287 |
} else { |
|
1288 |
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1289 |
} |
|
1290 |
} |
|
1291 |
||
1292 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1293 |
do_action( 'xmlrpc_call', 'wp.newPost' ); |
1294 |
||
1295 |
unset( $content_struct['ID'] ); |
|
1296 |
||
1297 |
return $this->_insert_post( $user, $content_struct ); |
|
1298 |
} |
|
1299 |
||
1300 |
/** |
|
1301 |
* Helper method for filtering out elements from an array. |
|
1302 |
* |
|
1303 |
* @since 3.4.0 |
|
1304 |
* |
|
1305 |
* @param int $count Number to compare to one. |
|
1306 |
*/ |
|
1307 |
private function _is_greater_than_one( $count ) { |
|
1308 |
return $count > 1; |
|
1309 |
} |
|
1310 |
||
1311 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
* Encapsulate the logic for sticking a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
* 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
|
1314 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* @param array $post_data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* @param bool $update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* @return void|IXR_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
private function _toggle_sticky( $post_data, $update = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
$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
|
1323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
// Private and password-protected posts cannot be stickied. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
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
|
1326 |
// 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
|
1327 |
if ( ! empty( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
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
|
1329 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
if ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
} |
9 | 1334 |
} elseif ( isset( $post_data['sticky'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
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
|
1336 |
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
|
1337 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
$sticky = wp_validate_boolean( $post_data['sticky'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
if ( $sticky ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
stick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
* Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
0 | 1350 |
* |
1351 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
* @param WP_User $user The post author if post_author isn't set in $content_struct. |
5 | 1356 |
* @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
|
1357 |
* @return IXR_Error|string |
0 | 1358 |
*/ |
1359 |
protected function _insert_post( $user, $content_struct ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
'post_status' => 'draft', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
'post_type' => 'post', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
'post_author' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
'post_password' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
'post_excerpt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
'post_content' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
'post_title' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
'post_date' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
'post_date_gmt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
'post_format' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
'post_name' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
'post_thumbnail' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
'post_parent' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
'ping_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
'comment_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
'custom_fields' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
'terms_names' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
'terms' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
'sticky' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
'enclosure' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
'ID' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
0 | 1385 |
|
1386 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
|
9 | 1387 |
if ( ! $post_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1389 |
} |
0 | 1390 |
|
1391 |
$update = ! empty( $post_data['ID'] ); |
|
1392 |
||
1393 |
if ( $update ) { |
|
9 | 1394 |
if ( ! get_post( $post_data['ID'] ) ) { |
0 | 1395 |
return new IXR_Error( 401, __( 'Invalid post ID.' ) ); |
9 | 1396 |
} |
1397 |
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) { |
|
0 | 1398 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1399 |
} |
1400 |
if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) ) { |
|
0 | 1401 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 1402 |
} |
0 | 1403 |
} else { |
9 | 1404 |
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 1405 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
9 | 1406 |
} |
0 | 1407 |
} |
1408 |
||
1409 |
switch ( $post_data['post_status'] ) { |
|
1410 |
case 'draft': |
|
1411 |
case 'pending': |
|
1412 |
break; |
|
1413 |
case 'private': |
|
9 | 1414 |
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
|
1415 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
9 | 1416 |
} |
0 | 1417 |
break; |
1418 |
case 'publish': |
|
1419 |
case 'future': |
|
9 | 1420 |
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
|
1421 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
9 | 1422 |
} |
0 | 1423 |
break; |
1424 |
default: |
|
9 | 1425 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) { |
0 | 1426 |
$post_data['post_status'] = 'draft'; |
9 | 1427 |
} |
1428 |
break; |
|
1429 |
} |
|
1430 |
||
1431 |
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
|
1432 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
9 | 1433 |
} |
0 | 1434 |
|
1435 |
$post_data['post_author'] = absint( $post_data['post_author'] ); |
|
1436 |
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
|
9 | 1437 |
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
|
1438 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 1439 |
} |
0 | 1440 |
|
1441 |
$author = get_userdata( $post_data['post_author'] ); |
|
1442 |
||
9 | 1443 |
if ( ! $author ) { |
0 | 1444 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 1445 |
} |
0 | 1446 |
} else { |
1447 |
$post_data['post_author'] = $user->ID; |
|
1448 |
} |
|
1449 |
||
9 | 1450 |
if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) { |
0 | 1451 |
unset( $post_data['comment_status'] ); |
9 | 1452 |
} |
1453 |
||
1454 |
if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) { |
|
0 | 1455 |
unset( $post_data['ping_status'] ); |
9 | 1456 |
} |
0 | 1457 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
// Do some timestamp voodoo. |
0 | 1459 |
if ( ! empty( $post_data['post_date_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 1461 |
$dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1462 |
} elseif ( ! empty( $post_data['post_date'] ) ) { |
|
1463 |
$dateCreated = $post_data['post_date']->getIso(); |
|
1464 |
} |
|
1465 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
// 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
|
1467 |
$post_data['edit_date'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
|
0 | 1469 |
if ( ! empty( $dateCreated ) ) { |
9 | 1470 |
$post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
0 | 1471 |
$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
|
1472 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
$post_data['edit_date'] = true; |
0 | 1475 |
} |
1476 |
||
9 | 1477 |
if ( ! isset( $post_data['ID'] ) ) { |
0 | 1478 |
$post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
9 | 1479 |
} |
0 | 1480 |
$post_ID = $post_data['ID']; |
1481 |
||
1482 |
if ( $post_data['post_type'] == 'post' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
$error = $this->_toggle_sticky( $post_data, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
return $error; |
0 | 1486 |
} |
1487 |
} |
|
1488 |
||
1489 |
if ( isset( $post_data['post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
// empty value deletes, non-empty value adds/updates. |
9 | 1491 |
if ( ! $post_data['post_thumbnail'] ) { |
0 | 1492 |
delete_post_thumbnail( $post_ID ); |
9 | 1493 |
} elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) { |
0 | 1494 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 1495 |
} |
0 | 1496 |
set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
1497 |
unset( $content_struct['post_thumbnail'] ); |
|
1498 |
} |
|
1499 |
||
9 | 1500 |
if ( isset( $post_data['custom_fields'] ) ) { |
0 | 1501 |
$this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
9 | 1502 |
} |
0 | 1503 |
|
1504 |
if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
|
1505 |
$post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
|
1506 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
// Accumulate term IDs from terms and terms_names. |
0 | 1508 |
$terms = array(); |
1509 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
// First validate the terms specified by ID. |
0 | 1511 |
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1512 |
$taxonomies = array_keys( $post_data['terms'] ); |
|
1513 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
// Validating term ids. |
0 | 1515 |
foreach ( $taxonomies as $taxonomy ) { |
9 | 1516 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1517 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1518 |
} |
1519 |
||
1520 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1521 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1522 |
} |
1523 |
||
1524 |
$term_ids = $post_data['terms'][ $taxonomy ]; |
|
5 | 1525 |
$terms[ $taxonomy ] = array(); |
0 | 1526 |
foreach ( $term_ids as $term_id ) { |
1527 |
$term = get_term_by( 'id', $term_id, $taxonomy ); |
|
1528 |
||
9 | 1529 |
if ( ! $term ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
9 | 1531 |
} |
1532 |
||
1533 |
$terms[ $taxonomy ][] = (int) $term_id; |
|
0 | 1534 |
} |
1535 |
} |
|
1536 |
} |
|
1537 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
// Now validate terms specified by name. |
0 | 1539 |
if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1540 |
$taxonomies = array_keys( $post_data['terms_names'] ); |
|
1541 |
||
1542 |
foreach ( $taxonomies as $taxonomy ) { |
|
9 | 1543 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1544 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1545 |
} |
1546 |
||
1547 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1548 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1549 |
} |
0 | 1550 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1552 |
* 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
|
1553 |
* in the hierarchy share the same name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
*/ |
0 | 1555 |
$ambiguous_terms = array(); |
1556 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
9 | 1557 |
$tax_term_names = get_terms( |
1558 |
$taxonomy, |
|
1559 |
array( |
|
1560 |
'fields' => 'names', |
|
1561 |
'hide_empty' => false, |
|
1562 |
) |
|
1563 |
); |
|
0 | 1564 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
// Count the number of terms with the same name. |
0 | 1566 |
$tax_term_names_count = array_count_values( $tax_term_names ); |
1567 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
// Filter out non-ambiguous term names. |
9 | 1569 |
$ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) ); |
0 | 1570 |
|
1571 |
$ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
|
1572 |
} |
|
1573 |
||
9 | 1574 |
$term_names = $post_data['terms_names'][ $taxonomy ]; |
0 | 1575 |
foreach ( $term_names as $term_name ) { |
9 | 1576 |
if ( in_array( $term_name, $ambiguous_terms ) ) { |
0 | 1577 |
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
9 | 1578 |
} |
0 | 1579 |
|
1580 |
$term = get_term_by( 'name', $term_name, $taxonomy ); |
|
1581 |
||
1582 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
// Term doesn't exist, so check that the user is allowed to create new terms. |
9 | 1584 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->edit_terms ) ) { |
0 | 1585 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
9 | 1586 |
} |
0 | 1587 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
// Create the new term. |
0 | 1589 |
$term_info = wp_insert_term( $term_name, $taxonomy ); |
9 | 1590 |
if ( is_wp_error( $term_info ) ) { |
0 | 1591 |
return new IXR_Error( 500, $term_info->get_error_message() ); |
9 | 1592 |
} |
1593 |
||
1594 |
$terms[ $taxonomy ][] = (int) $term_info['term_id']; |
|
0 | 1595 |
} else { |
9 | 1596 |
$terms[ $taxonomy ][] = (int) $term->term_id; |
0 | 1597 |
} |
1598 |
} |
|
1599 |
} |
|
1600 |
} |
|
1601 |
||
1602 |
$post_data['tax_input'] = $terms; |
|
1603 |
unset( $post_data['terms'], $post_data['terms_names'] ); |
|
1604 |
} |
|
1605 |
||
1606 |
if ( isset( $post_data['post_format'] ) ) { |
|
1607 |
$format = set_post_format( $post_ID, $post_data['post_format'] ); |
|
1608 |
||
9 | 1609 |
if ( is_wp_error( $format ) ) { |
0 | 1610 |
return new IXR_Error( 500, $format->get_error_message() ); |
9 | 1611 |
} |
0 | 1612 |
|
1613 |
unset( $post_data['post_format'] ); |
|
1614 |
} |
|
1615 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
// Handle enclosures. |
0 | 1617 |
$enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; |
1618 |
$this->add_enclosure_if_new( $post_ID, $enclosure ); |
|
1619 |
||
1620 |
$this->attach_uploads( $post_ID, $post_data['post_content'] ); |
|
1621 |
||
5 | 1622 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1623 |
* Filters post data array to be inserted via XML-RPC. |
5 | 1624 |
* |
1625 |
* @since 3.4.0 |
|
1626 |
* |
|
1627 |
* @param array $post_data Parsed array of post data. |
|
1628 |
* @param array $content_struct Post data array. |
|
1629 |
*/ |
|
0 | 1630 |
$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); |
1631 |
||
1632 |
$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); |
|
9 | 1633 |
if ( is_wp_error( $post_ID ) ) { |
0 | 1634 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
9 | 1635 |
} |
1636 |
||
1637 |
if ( ! $post_ID ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
return new IXR_Error( 401, __( 'Sorry, your entry could not be posted.' ) ); |
9 | 1639 |
} |
0 | 1640 |
|
1641 |
return strval( $post_ID ); |
|
1642 |
} |
|
1643 |
||
1644 |
/** |
|
1645 |
* Edit a post for any registered post type. |
|
1646 |
* |
|
1647 |
* The $content_struct parameter only needs to contain fields that |
|
1648 |
* should be changed. All other fields will retain their existing values. |
|
1649 |
* |
|
1650 |
* @since 3.4.0 |
|
1651 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1655 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1656 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
* @type array $content_struct Extra content arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
* @return true|IXR_Error True on success, IXR_Error on failure. |
0 | 1662 |
*/ |
5 | 1663 |
public function wp_editPost( $args ) { |
9 | 1664 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 1665 |
return $this->error; |
9 | 1666 |
} |
0 | 1667 |
|
1668 |
$this->escape( $args ); |
|
1669 |
||
1670 |
$username = $args[1]; |
|
1671 |
$password = $args[2]; |
|
1672 |
$post_id = (int) $args[3]; |
|
1673 |
$content_struct = $args[4]; |
|
1674 |
||
9 | 1675 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 1676 |
return $this->error; |
9 | 1677 |
} |
0 | 1678 |
|
5 | 1679 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1680 |
do_action( 'xmlrpc_call', 'wp.editPost' ); |
1681 |
||
1682 |
$post = get_post( $post_id, ARRAY_A ); |
|
1683 |
||
9 | 1684 |
if ( empty( $post['ID'] ) ) { |
0 | 1685 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1686 |
} |
0 | 1687 |
|
1688 |
if ( isset( $content_struct['if_not_modified_since'] ) ) { |
|
1689 |
// If the post has been modified since the date provided, return an error. |
|
1690 |
if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { |
|
1691 |
return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); |
|
1692 |
} |
|
1693 |
} |
|
1694 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1695 |
// Convert the date field back to IXR form. |
0 | 1696 |
$post['post_date'] = $this->_convert_date( $post['post_date'] ); |
1697 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* 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
|
1700 |
* 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
|
1701 |
*/ |
9 | 1702 |
if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { |
0 | 1703 |
unset( $post['post_date_gmt'] ); |
9 | 1704 |
} else { |
0 | 1705 |
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); |
9 | 1706 |
} |
0 | 1707 |
|
1708 |
$this->escape( $post ); |
|
1709 |
$merged_content_struct = array_merge( $post, $content_struct ); |
|
1710 |
||
1711 |
$retval = $this->_insert_post( $user, $merged_content_struct ); |
|
9 | 1712 |
if ( $retval instanceof IXR_Error ) { |
0 | 1713 |
return $retval; |
9 | 1714 |
} |
0 | 1715 |
|
1716 |
return true; |
|
1717 |
} |
|
1718 |
||
1719 |
/** |
|
1720 |
* Delete a post for any registered post type. |
|
1721 |
* |
|
1722 |
* @since 3.4.0 |
|
1723 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
* @see wp_delete_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1725 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 1735 |
*/ |
5 | 1736 |
public function wp_deletePost( $args ) { |
9 | 1737 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1738 |
return $this->error; |
9 | 1739 |
} |
0 | 1740 |
|
1741 |
$this->escape( $args ); |
|
1742 |
||
9 | 1743 |
$username = $args[1]; |
1744 |
$password = $args[2]; |
|
1745 |
$post_id = (int) $args[3]; |
|
1746 |
||
1747 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 1748 |
return $this->error; |
9 | 1749 |
} |
0 | 1750 |
|
5 | 1751 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1752 |
do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1753 |
||
1754 |
$post = get_post( $post_id, ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
if ( empty( $post['ID'] ) ) { |
0 | 1756 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
0 | 1760 |
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
|
1761 |
} |
0 | 1762 |
|
1763 |
$result = wp_delete_post( $post_id ); |
|
1764 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
if ( ! $result ) { |
0 | 1766 |
return new IXR_Error( 500, __( 'The post cannot be deleted.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
} |
0 | 1768 |
|
1769 |
return true; |
|
1770 |
} |
|
1771 |
||
1772 |
/** |
|
1773 |
* Retrieve a post. |
|
1774 |
* |
|
1775 |
* @since 3.4.0 |
|
1776 |
* |
|
1777 |
* The optional $fields parameter specifies what fields will be included |
|
1778 |
* in the response array. This should be a list of field names. 'post_id' will |
|
1779 |
* always be included in the response regardless of the value of $fields. |
|
1780 |
* |
|
1781 |
* Instead of, or in addition to, individual field names, conceptual group |
|
1782 |
* names can be used to specify multiple fields. The available conceptual |
|
1783 |
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields', |
|
1784 |
* and 'enclosure'. |
|
1785 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
* @see get_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
* @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
|
1796 |
* } |
5 | 1797 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 1798 |
* - 'post_id' |
1799 |
* - 'post_title' |
|
1800 |
* - 'post_date' |
|
1801 |
* - 'post_date_gmt' |
|
1802 |
* - 'post_modified' |
|
1803 |
* - 'post_modified_gmt' |
|
1804 |
* - 'post_status' |
|
1805 |
* - 'post_type' |
|
1806 |
* - 'post_name' |
|
1807 |
* - 'post_author' |
|
1808 |
* - 'post_password' |
|
1809 |
* - 'post_excerpt' |
|
1810 |
* - 'post_content' |
|
1811 |
* - 'link' |
|
1812 |
* - 'comment_status' |
|
1813 |
* - 'ping_status' |
|
1814 |
* - 'sticky' |
|
1815 |
* - 'custom_fields' |
|
1816 |
* - 'terms' |
|
1817 |
* - 'categories' |
|
1818 |
* - 'tags' |
|
1819 |
* - 'enclosure' |
|
1820 |
*/ |
|
5 | 1821 |
public function wp_getPost( $args ) { |
9 | 1822 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1823 |
return $this->error; |
9 | 1824 |
} |
0 | 1825 |
|
1826 |
$this->escape( $args ); |
|
1827 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
$post_id = (int) $args[3]; |
0 | 1831 |
|
5 | 1832 |
if ( isset( $args[4] ) ) { |
0 | 1833 |
$fields = $args[4]; |
5 | 1834 |
} else { |
1835 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1836 |
* Filters the list of post query fields used by the given XML-RPC method. |
5 | 1837 |
* |
1838 |
* @since 3.4.0 |
|
1839 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1840 |
* @param array $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'. |
5 | 1841 |
* @param string $method Method name. |
1842 |
*/ |
|
0 | 1843 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
5 | 1844 |
} |
0 | 1845 |
|
9 | 1846 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 1847 |
return $this->error; |
9 | 1848 |
} |
0 | 1849 |
|
5 | 1850 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1851 |
do_action( 'xmlrpc_call', 'wp.getPost' ); |
1852 |
||
1853 |
$post = get_post( $post_id, ARRAY_A ); |
|
1854 |
||
9 | 1855 |
if ( empty( $post['ID'] ) ) { |
0 | 1856 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1857 |
} |
1858 |
||
1859 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1861 |
} |
0 | 1862 |
|
1863 |
return $this->_prepare_post( $post, $fields ); |
|
1864 |
} |
|
1865 |
||
1866 |
/** |
|
1867 |
* Retrieve posts. |
|
1868 |
* |
|
1869 |
* @since 3.4.0 |
|
1870 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1871 |
* @see wp_get_recent_posts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1872 |
* @see wp_getPost() for more on `$fields` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1873 |
* @see get_posts() for more on `$filter` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1874 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1878 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
* @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
|
1882 |
* 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1883 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
* @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
|
1885 |
* } |
5 | 1886 |
* @return array|IXR_Error Array contains a collection of posts. |
0 | 1887 |
*/ |
5 | 1888 |
public function wp_getPosts( $args ) { |
9 | 1889 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
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 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 1898 |
|
5 | 1899 |
if ( isset( $args[4] ) ) { |
0 | 1900 |
$fields = $args[4]; |
5 | 1901 |
} else { |
1902 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1903 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
5 | 1904 |
} |
0 | 1905 |
|
9 | 1906 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 1907 |
return $this->error; |
9 | 1908 |
} |
0 | 1909 |
|
5 | 1910 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1911 |
do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1912 |
||
1913 |
$query = array(); |
|
1914 |
||
1915 |
if ( isset( $filter['post_type'] ) ) { |
|
1916 |
$post_type = get_post_type_object( $filter['post_type'] ); |
|
9 | 1917 |
if ( ! ( (bool) $post_type ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1919 |
} |
0 | 1920 |
} else { |
1921 |
$post_type = get_post_type_object( 'post' ); |
|
1922 |
} |
|
1923 |
||
9 | 1924 |
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
|
1925 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 1926 |
} |
0 | 1927 |
|
1928 |
$query['post_type'] = $post_type->name; |
|
1929 |
||
9 | 1930 |
if ( isset( $filter['post_status'] ) ) { |
0 | 1931 |
$query['post_status'] = $filter['post_status']; |
9 | 1932 |
} |
1933 |
||
1934 |
if ( isset( $filter['number'] ) ) { |
|
0 | 1935 |
$query['numberposts'] = absint( $filter['number'] ); |
9 | 1936 |
} |
1937 |
||
1938 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 1939 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 1940 |
} |
0 | 1941 |
|
1942 |
if ( isset( $filter['orderby'] ) ) { |
|
1943 |
$query['orderby'] = $filter['orderby']; |
|
1944 |
||
9 | 1945 |
if ( isset( $filter['order'] ) ) { |
0 | 1946 |
$query['order'] = $filter['order']; |
9 | 1947 |
} |
0 | 1948 |
} |
1949 |
||
1950 |
if ( isset( $filter['s'] ) ) { |
|
1951 |
$query['s'] = $filter['s']; |
|
1952 |
} |
|
1953 |
||
1954 |
$posts_list = wp_get_recent_posts( $query ); |
|
1955 |
||
9 | 1956 |
if ( ! $posts_list ) { |
0 | 1957 |
return array(); |
9 | 1958 |
} |
0 | 1959 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1960 |
// Holds all the posts data. |
0 | 1961 |
$struct = array(); |
1962 |
||
1963 |
foreach ( $posts_list as $post ) { |
|
9 | 1964 |
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) { |
0 | 1965 |
continue; |
9 | 1966 |
} |
0 | 1967 |
|
1968 |
$struct[] = $this->_prepare_post( $post, $fields ); |
|
1969 |
} |
|
1970 |
||
1971 |
return $struct; |
|
1972 |
} |
|
1973 |
||
1974 |
/** |
|
1975 |
* Create a new term. |
|
1976 |
* |
|
1977 |
* @since 3.4.0 |
|
1978 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
* @see wp_insert_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
* @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
|
1988 |
* the term 'name' and 'taxonomy'. Optional accepted values include |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
* 'parent', 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
* @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
0 | 1992 |
*/ |
5 | 1993 |
public function wp_newTerm( $args ) { |
9 | 1994 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1995 |
return $this->error; |
9 | 1996 |
} |
0 | 1997 |
|
1998 |
$this->escape( $args ); |
|
1999 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2002 |
$content_struct = $args[3]; |
0 | 2003 |
|
9 | 2004 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2005 |
return $this->error; |
9 | 2006 |
} |
0 | 2007 |
|
5 | 2008 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2009 |
do_action( 'xmlrpc_call', 'wp.newTerm' ); |
2010 |
||
9 | 2011 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2013 |
} |
0 | 2014 |
|
2015 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2016 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2017 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
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
|
2019 |
} |
0 | 2020 |
|
2021 |
$taxonomy = (array) $taxonomy; |
|
2022 |
||
2023 |
// hold the data of the term |
|
2024 |
$term_data = array(); |
|
2025 |
||
2026 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
9 | 2027 |
if ( empty( $term_data['name'] ) ) { |
0 | 2028 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2029 |
} |
0 | 2030 |
|
2031 |
if ( isset( $content_struct['parent'] ) ) { |
|
9 | 2032 |
if ( ! $taxonomy['hierarchical'] ) { |
0 | 2033 |
return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
9 | 2034 |
} |
0 | 2035 |
|
2036 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2037 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2038 |
||
2039 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2040 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2041 |
} |
2042 |
||
2043 |
if ( ! $parent_term ) { |
|
0 | 2044 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2045 |
} |
0 | 2046 |
|
2047 |
$term_data['parent'] = $content_struct['parent']; |
|
2048 |
} |
|
2049 |
||
9 | 2050 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2051 |
$term_data['description'] = $content_struct['description']; |
9 | 2052 |
} |
2053 |
||
2054 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2055 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2056 |
} |
2057 |
||
2058 |
$term = wp_insert_term( $term_data['name'], $taxonomy['name'], $term_data ); |
|
2059 |
||
2060 |
if ( is_wp_error( $term ) ) { |
|
0 | 2061 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2062 |
} |
2063 |
||
2064 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) ); |
9 | 2066 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2067 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
// Add term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
$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
|
2071 |
} |
0 | 2072 |
|
2073 |
return strval( $term['term_id'] ); |
|
2074 |
} |
|
2075 |
||
2076 |
/** |
|
2077 |
* Edit a term. |
|
2078 |
* |
|
2079 |
* @since 3.4.0 |
|
2080 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
* @see wp_update_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
* @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
|
2091 |
* term ''taxonomy'. Optional accepted values include 'name', 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
* 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2095 |
*/ |
5 | 2096 |
public function wp_editTerm( $args ) { |
9 | 2097 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2098 |
return $this->error; |
9 | 2099 |
} |
0 | 2100 |
|
2101 |
$this->escape( $args ); |
|
2102 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
$term_id = (int) $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
$content_struct = $args[4]; |
0 | 2107 |
|
9 | 2108 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2109 |
return $this->error; |
9 | 2110 |
} |
0 | 2111 |
|
5 | 2112 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2113 |
do_action( 'xmlrpc_call', 'wp.editTerm' ); |
2114 |
||
9 | 2115 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2116 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2117 |
} |
0 | 2118 |
|
2119 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2120 |
||
2121 |
$taxonomy = (array) $taxonomy; |
|
2122 |
||
2123 |
// hold the data of the term |
|
2124 |
$term_data = array(); |
|
2125 |
||
9 | 2126 |
$term = get_term( $term_id, $content_struct['taxonomy'] ); |
2127 |
||
2128 |
if ( is_wp_error( $term ) ) { |
|
0 | 2129 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2130 |
} |
2131 |
||
2132 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2133 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2134 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
if ( ! current_user_can( 'edit_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2137 |
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
|
2138 |
} |
0 | 2139 |
|
2140 |
if ( isset( $content_struct['name'] ) ) { |
|
2141 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
2142 |
||
9 | 2143 |
if ( empty( $term_data['name'] ) ) { |
0 | 2144 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2145 |
} |
0 | 2146 |
} |
2147 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2148 |
if ( ! empty( $content_struct['parent'] ) ) { |
9 | 2149 |
if ( ! $taxonomy['hierarchical'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
9 | 2151 |
} |
0 | 2152 |
|
2153 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2154 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2155 |
||
2156 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2157 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2158 |
} |
2159 |
||
2160 |
if ( ! $parent_term ) { |
|
0 | 2161 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2162 |
} |
0 | 2163 |
|
2164 |
$term_data['parent'] = $content_struct['parent']; |
|
2165 |
} |
|
2166 |
||
9 | 2167 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2168 |
$term_data['description'] = $content_struct['description']; |
9 | 2169 |
} |
2170 |
||
2171 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2172 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2173 |
} |
2174 |
||
2175 |
$term = wp_update_term( $term_id, $taxonomy['name'], $term_data ); |
|
2176 |
||
2177 |
if ( is_wp_error( $term ) ) { |
|
0 | 2178 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2179 |
} |
2180 |
||
2181 |
if ( ! $term ) { |
|
0 | 2182 |
return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
9 | 2183 |
} |
0 | 2184 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2185 |
// Update term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2186 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2187 |
$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
|
2188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2189 |
|
0 | 2190 |
return true; |
2191 |
} |
|
2192 |
||
2193 |
/** |
|
2194 |
* Delete a term. |
|
2195 |
* |
|
2196 |
* @since 3.4.0 |
|
2197 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
* @see wp_delete_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2202 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2205 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
* @type string $taxnomy_name Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
* @return bool|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2210 |
*/ |
5 | 2211 |
public function wp_deleteTerm( $args ) { |
9 | 2212 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2213 |
return $this->error; |
9 | 2214 |
} |
0 | 2215 |
|
2216 |
$this->escape( $args ); |
|
2217 |
||
9 | 2218 |
$username = $args[1]; |
2219 |
$password = $args[2]; |
|
2220 |
$taxonomy = $args[3]; |
|
2221 |
$term_id = (int) $args[4]; |
|
2222 |
||
2223 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 2224 |
return $this->error; |
9 | 2225 |
} |
0 | 2226 |
|
5 | 2227 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2228 |
do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
2229 |
||
9 | 2230 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2232 |
} |
0 | 2233 |
|
2234 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
9 | 2235 |
$term = get_term( $term_id, $taxonomy->name ); |
2236 |
||
2237 |
if ( is_wp_error( $term ) ) { |
|
0 | 2238 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2239 |
} |
2240 |
||
2241 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2243 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
if ( ! current_user_can( 'delete_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
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
|
2247 |
} |
0 | 2248 |
|
2249 |
$result = wp_delete_term( $term_id, $taxonomy->name ); |
|
2250 |
||
9 | 2251 |
if ( is_wp_error( $result ) ) { |
0 | 2252 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2253 |
} |
2254 |
||
2255 |
if ( ! $result ) { |
|
0 | 2256 |
return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
9 | 2257 |
} |
0 | 2258 |
|
2259 |
return $result; |
|
2260 |
} |
|
2261 |
||
2262 |
/** |
|
2263 |
* Retrieve a term. |
|
2264 |
* |
|
2265 |
* @since 3.4.0 |
|
2266 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
* @see get_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2268 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2273 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
* @type string $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
* @return array|IXR_Error IXR_Error on failure, array on success, containing: |
0 | 2279 |
* - 'term_id' |
2280 |
* - 'name' |
|
2281 |
* - 'slug' |
|
2282 |
* - 'term_group' |
|
2283 |
* - 'term_taxonomy_id' |
|
2284 |
* - 'taxonomy' |
|
2285 |
* - 'description' |
|
2286 |
* - 'parent' |
|
2287 |
* - 'count' |
|
2288 |
*/ |
|
5 | 2289 |
public function wp_getTerm( $args ) { |
9 | 2290 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2291 |
return $this->error; |
9 | 2292 |
} |
0 | 2293 |
|
2294 |
$this->escape( $args ); |
|
2295 |
||
9 | 2296 |
$username = $args[1]; |
2297 |
$password = $args[2]; |
|
2298 |
$taxonomy = $args[3]; |
|
2299 |
$term_id = (int) $args[4]; |
|
2300 |
||
2301 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 2302 |
return $this->error; |
9 | 2303 |
} |
0 | 2304 |
|
5 | 2305 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2306 |
do_action( 'xmlrpc_call', 'wp.getTerm' ); |
2307 |
||
9 | 2308 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2309 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2310 |
} |
0 | 2311 |
|
2312 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2313 |
||
9 | 2314 |
$term = get_term( $term_id, $taxonomy->name, ARRAY_A ); |
2315 |
||
2316 |
if ( is_wp_error( $term ) ) { |
|
0 | 2317 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2318 |
} |
2319 |
||
2320 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2322 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
if ( ! current_user_can( 'assign_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
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
|
2326 |
} |
0 | 2327 |
|
2328 |
return $this->_prepare_term( $term ); |
|
2329 |
} |
|
2330 |
||
2331 |
/** |
|
2332 |
* Retrieve all terms for a taxonomy. |
|
2333 |
* |
|
2334 |
* @since 3.4.0 |
|
2335 |
* |
|
2336 |
* The optional $filter parameter modifies the query used to retrieve terms. |
|
2337 |
* Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
|
2338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
* @see get_terms() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
* @param array $args { |
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 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
|
2349 |
* '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
|
2350 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
* @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
0 | 2352 |
*/ |
5 | 2353 |
public function wp_getTerms( $args ) { |
9 | 2354 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2355 |
return $this->error; |
9 | 2356 |
} |
0 | 2357 |
|
2358 |
$this->escape( $args ); |
|
2359 |
||
9 | 2360 |
$username = $args[1]; |
2361 |
$password = $args[2]; |
|
2362 |
$taxonomy = $args[3]; |
|
2363 |
$filter = isset( $args[4] ) ? $args[4] : array(); |
|
2364 |
||
2365 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 2366 |
return $this->error; |
9 | 2367 |
} |
0 | 2368 |
|
5 | 2369 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2370 |
do_action( 'xmlrpc_call', 'wp.getTerms' ); |
2371 |
||
9 | 2372 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2374 |
} |
0 | 2375 |
|
2376 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2377 |
||
9 | 2378 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2379 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2380 |
} |
0 | 2381 |
|
2382 |
$query = array(); |
|
2383 |
||
9 | 2384 |
if ( isset( $filter['number'] ) ) { |
0 | 2385 |
$query['number'] = absint( $filter['number'] ); |
9 | 2386 |
} |
2387 |
||
2388 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2389 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2390 |
} |
0 | 2391 |
|
2392 |
if ( isset( $filter['orderby'] ) ) { |
|
2393 |
$query['orderby'] = $filter['orderby']; |
|
2394 |
||
9 | 2395 |
if ( isset( $filter['order'] ) ) { |
0 | 2396 |
$query['order'] = $filter['order']; |
9 | 2397 |
} |
2398 |
} |
|
2399 |
||
2400 |
if ( isset( $filter['hide_empty'] ) ) { |
|
0 | 2401 |
$query['hide_empty'] = $filter['hide_empty']; |
9 | 2402 |
} else { |
0 | 2403 |
$query['get'] = 'all'; |
9 | 2404 |
} |
2405 |
||
2406 |
if ( isset( $filter['search'] ) ) { |
|
0 | 2407 |
$query['search'] = $filter['search']; |
9 | 2408 |
} |
0 | 2409 |
|
2410 |
$terms = get_terms( $taxonomy->name, $query ); |
|
2411 |
||
9 | 2412 |
if ( is_wp_error( $terms ) ) { |
0 | 2413 |
return new IXR_Error( 500, $terms->get_error_message() ); |
9 | 2414 |
} |
0 | 2415 |
|
2416 |
$struct = array(); |
|
2417 |
||
2418 |
foreach ( $terms as $term ) { |
|
2419 |
$struct[] = $this->_prepare_term( $term ); |
|
2420 |
} |
|
2421 |
||
2422 |
return $struct; |
|
2423 |
} |
|
2424 |
||
2425 |
/** |
|
2426 |
* Retrieve a taxonomy. |
|
2427 |
* |
|
2428 |
* @since 3.4.0 |
|
2429 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2430 |
* @see get_taxonomy() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2431 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2432 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2433 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2434 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2435 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2436 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2437 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2438 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2439 |
* @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
|
2440 |
* Accepts 'labels', 'cap', 'menu', and 'object_type'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2441 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2442 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2443 |
* @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
0 | 2444 |
*/ |
5 | 2445 |
public function wp_getTaxonomy( $args ) { |
9 | 2446 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2447 |
return $this->error; |
9 | 2448 |
} |
0 | 2449 |
|
2450 |
$this->escape( $args ); |
|
2451 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2452 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
$taxonomy = $args[3]; |
0 | 2455 |
|
5 | 2456 |
if ( isset( $args[4] ) ) { |
0 | 2457 |
$fields = $args[4]; |
5 | 2458 |
} else { |
2459 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* Filters the taxonomy query fields used by the given XML-RPC method. |
5 | 2461 |
* |
2462 |
* @since 3.4.0 |
|
2463 |
* |
|
2464 |
* @param array $fields An array of taxonomy fields to retrieve. |
|
2465 |
* @param string $method The method name. |
|
2466 |
*/ |
|
0 | 2467 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
5 | 2468 |
} |
0 | 2469 |
|
9 | 2470 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2471 |
return $this->error; |
9 | 2472 |
} |
0 | 2473 |
|
5 | 2474 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2475 |
do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2476 |
||
9 | 2477 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2479 |
} |
0 | 2480 |
|
2481 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2482 |
||
9 | 2483 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2484 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2485 |
} |
0 | 2486 |
|
2487 |
return $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2488 |
} |
|
2489 |
||
2490 |
/** |
|
2491 |
* Retrieve all taxonomies. |
|
2492 |
* |
|
2493 |
* @since 3.4.0 |
|
2494 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2495 |
* @see get_taxonomies() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2498 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2500 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2501 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2502 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2503 |
* @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
|
2504 |
* @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
|
2505 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2506 |
* @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
|
2507 |
* by `$fields`, or an IXR_Error instance on failure. |
0 | 2508 |
*/ |
5 | 2509 |
public function wp_getTaxonomies( $args ) { |
9 | 2510 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2511 |
return $this->error; |
9 | 2512 |
} |
0 | 2513 |
|
2514 |
$this->escape( $args ); |
|
2515 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2516 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2517 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2518 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 2519 |
|
5 | 2520 |
if ( isset( $args[4] ) ) { |
0 | 2521 |
$fields = $args[4]; |
5 | 2522 |
} else { |
2523 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2524 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
5 | 2525 |
} |
0 | 2526 |
|
9 | 2527 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2528 |
return $this->error; |
9 | 2529 |
} |
0 | 2530 |
|
5 | 2531 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2532 |
do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
2533 |
||
2534 |
$taxonomies = get_taxonomies( $filter, 'objects' ); |
|
2535 |
||
2536 |
// holds all the taxonomy data |
|
2537 |
$struct = array(); |
|
2538 |
||
2539 |
foreach ( $taxonomies as $taxonomy ) { |
|
2540 |
// capability check for post_types |
|
9 | 2541 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
0 | 2542 |
continue; |
9 | 2543 |
} |
0 | 2544 |
|
2545 |
$struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2546 |
} |
|
2547 |
||
2548 |
return $struct; |
|
2549 |
} |
|
2550 |
||
2551 |
/** |
|
2552 |
* Retrieve a user. |
|
2553 |
* |
|
2554 |
* The optional $fields parameter specifies what fields will be included |
|
2555 |
* in the response array. This should be a list of field names. 'user_id' will |
|
2556 |
* always be included in the response regardless of the value of $fields. |
|
2557 |
* |
|
2558 |
* Instead of, or in addition to, individual field names, conceptual group |
|
2559 |
* names can be used to specify multiple fields. The available conceptual |
|
2560 |
* groups are 'basic' and 'all'. |
|
2561 |
* |
|
2562 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2563 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2564 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2567 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2568 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2569 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2570 |
* @type int $user_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2572 |
* } |
5 | 2573 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 2574 |
* - 'user_id' |
2575 |
* - 'username' |
|
2576 |
* - 'first_name' |
|
2577 |
* - 'last_name' |
|
2578 |
* - 'registered' |
|
2579 |
* - 'bio' |
|
2580 |
* - 'email' |
|
2581 |
* - 'nickname' |
|
2582 |
* - 'nicename' |
|
2583 |
* - 'url' |
|
2584 |
* - 'display_name' |
|
2585 |
* - 'roles' |
|
2586 |
*/ |
|
5 | 2587 |
public function wp_getUser( $args ) { |
9 | 2588 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2589 |
return $this->error; |
9 | 2590 |
} |
0 | 2591 |
|
2592 |
$this->escape( $args ); |
|
2593 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2594 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
$user_id = (int) $args[3]; |
0 | 2597 |
|
5 | 2598 |
if ( isset( $args[4] ) ) { |
0 | 2599 |
$fields = $args[4]; |
5 | 2600 |
} else { |
2601 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* Filters the default user query fields used by the given XML-RPC method. |
5 | 2603 |
* |
2604 |
* @since 3.5.0 |
|
2605 |
* |
|
2606 |
* @param array $fields User query fields for given method. Default 'all'. |
|
2607 |
* @param string $method The method name. |
|
2608 |
*/ |
|
0 | 2609 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
5 | 2610 |
} |
0 | 2611 |
|
9 | 2612 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2613 |
return $this->error; |
9 | 2614 |
} |
0 | 2615 |
|
5 | 2616 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2617 |
do_action( 'xmlrpc_call', 'wp.getUser' ); |
2618 |
||
9 | 2619 |
if ( ! current_user_can( 'edit_user', $user_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
9 | 2621 |
} |
0 | 2622 |
|
2623 |
$user_data = get_userdata( $user_id ); |
|
2624 |
||
9 | 2625 |
if ( ! $user_data ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2626 |
return new IXR_Error( 404, __( 'Invalid user ID.' ) ); |
9 | 2627 |
} |
0 | 2628 |
|
2629 |
return $this->_prepare_user( $user_data, $fields ); |
|
2630 |
} |
|
2631 |
||
2632 |
/** |
|
2633 |
* Retrieve users. |
|
2634 |
* |
|
2635 |
* The optional $filter parameter modifies the query used to retrieve users. |
|
2636 |
* Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', |
|
2637 |
* 'who', 'orderby', and 'order'. |
|
2638 |
* |
|
2639 |
* The optional $fields parameter specifies what fields will be included |
|
2640 |
* in the response array. |
|
2641 |
* |
|
2642 |
* @uses get_users() |
|
2643 |
* @see wp_getUser() for more on $fields and return values |
|
2644 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2645 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2651 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2652 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2653 |
* } |
5 | 2654 |
* @return array|IXR_Error users data |
0 | 2655 |
*/ |
5 | 2656 |
public function wp_getUsers( $args ) { |
9 | 2657 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2658 |
return $this->error; |
9 | 2659 |
} |
0 | 2660 |
|
2661 |
$this->escape( $args ); |
|
2662 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2663 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2664 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 2666 |
|
5 | 2667 |
if ( isset( $args[4] ) ) { |
0 | 2668 |
$fields = $args[4]; |
5 | 2669 |
} else { |
2670 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2671 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
5 | 2672 |
} |
0 | 2673 |
|
9 | 2674 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2675 |
return $this->error; |
9 | 2676 |
} |
0 | 2677 |
|
5 | 2678 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2679 |
do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2680 |
||
9 | 2681 |
if ( ! current_user_can( 'list_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2682 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
9 | 2683 |
} |
0 | 2684 |
|
2685 |
$query = array( 'fields' => 'all_with_meta' ); |
|
2686 |
||
2687 |
$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50; |
|
2688 |
$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0; |
|
2689 |
||
2690 |
if ( isset( $filter['orderby'] ) ) { |
|
2691 |
$query['orderby'] = $filter['orderby']; |
|
2692 |
||
9 | 2693 |
if ( isset( $filter['order'] ) ) { |
0 | 2694 |
$query['order'] = $filter['order']; |
9 | 2695 |
} |
0 | 2696 |
} |
2697 |
||
2698 |
if ( isset( $filter['role'] ) ) { |
|
9 | 2699 |
if ( get_role( $filter['role'] ) === null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
return new IXR_Error( 403, __( 'Invalid role.' ) ); |
9 | 2701 |
} |
0 | 2702 |
|
2703 |
$query['role'] = $filter['role']; |
|
2704 |
} |
|
2705 |
||
2706 |
if ( isset( $filter['who'] ) ) { |
|
2707 |
$query['who'] = $filter['who']; |
|
2708 |
} |
|
2709 |
||
2710 |
$users = get_users( $query ); |
|
2711 |
||
2712 |
$_users = array(); |
|
2713 |
foreach ( $users as $user_data ) { |
|
9 | 2714 |
if ( current_user_can( 'edit_user', $user_data->ID ) ) { |
0 | 2715 |
$_users[] = $this->_prepare_user( $user_data, $fields ); |
9 | 2716 |
} |
0 | 2717 |
} |
2718 |
return $_users; |
|
2719 |
} |
|
2720 |
||
2721 |
/** |
|
2722 |
* Retrieve information about the requesting user. |
|
2723 |
* |
|
2724 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2725 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2726 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2727 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2729 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2731 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2732 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2733 |
* } |
5 | 2734 |
* @return array|IXR_Error (@see wp_getUser) |
0 | 2735 |
*/ |
5 | 2736 |
public function wp_getProfile( $args ) { |
9 | 2737 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2738 |
return $this->error; |
9 | 2739 |
} |
0 | 2740 |
|
2741 |
$this->escape( $args ); |
|
2742 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2743 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2744 |
$password = $args[2]; |
0 | 2745 |
|
5 | 2746 |
if ( isset( $args[3] ) ) { |
0 | 2747 |
$fields = $args[3]; |
5 | 2748 |
} else { |
2749 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2750 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
5 | 2751 |
} |
0 | 2752 |
|
9 | 2753 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2754 |
return $this->error; |
9 | 2755 |
} |
0 | 2756 |
|
5 | 2757 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2758 |
do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2759 |
||
9 | 2760 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2761 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2762 |
} |
0 | 2763 |
|
2764 |
$user_data = get_userdata( $user->ID ); |
|
2765 |
||
2766 |
return $this->_prepare_user( $user_data, $fields ); |
|
2767 |
} |
|
2768 |
||
2769 |
/** |
|
2770 |
* Edit user's profile. |
|
2771 |
* |
|
2772 |
* @uses wp_update_user() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2773 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2775 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2776 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2777 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2779 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2780 |
* @type array $content_struct It can optionally contain: |
0 | 2781 |
* - 'first_name' |
2782 |
* - 'last_name' |
|
2783 |
* - 'website' |
|
2784 |
* - 'display_name' |
|
2785 |
* - 'nickname' |
|
2786 |
* - 'nicename' |
|
2787 |
* - 'bio' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2789 |
* @return true|IXR_Error True, on success. |
0 | 2790 |
*/ |
5 | 2791 |
public function wp_editProfile( $args ) { |
9 | 2792 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2793 |
return $this->error; |
9 | 2794 |
} |
0 | 2795 |
|
2796 |
$this->escape( $args ); |
|
2797 |
||
2798 |
$username = $args[1]; |
|
2799 |
$password = $args[2]; |
|
2800 |
$content_struct = $args[3]; |
|
2801 |
||
9 | 2802 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2803 |
return $this->error; |
9 | 2804 |
} |
0 | 2805 |
|
5 | 2806 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2807 |
do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2808 |
||
9 | 2809 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2811 |
} |
0 | 2812 |
|
2813 |
// holds data of the user |
|
9 | 2814 |
$user_data = array(); |
0 | 2815 |
$user_data['ID'] = $user->ID; |
2816 |
||
2817 |
// only set the user details if it was given |
|
9 | 2818 |
if ( isset( $content_struct['first_name'] ) ) { |
0 | 2819 |
$user_data['first_name'] = $content_struct['first_name']; |
9 | 2820 |
} |
2821 |
||
2822 |
if ( isset( $content_struct['last_name'] ) ) { |
|
0 | 2823 |
$user_data['last_name'] = $content_struct['last_name']; |
9 | 2824 |
} |
2825 |
||
2826 |
if ( isset( $content_struct['url'] ) ) { |
|
0 | 2827 |
$user_data['user_url'] = $content_struct['url']; |
9 | 2828 |
} |
2829 |
||
2830 |
if ( isset( $content_struct['display_name'] ) ) { |
|
0 | 2831 |
$user_data['display_name'] = $content_struct['display_name']; |
9 | 2832 |
} |
2833 |
||
2834 |
if ( isset( $content_struct['nickname'] ) ) { |
|
0 | 2835 |
$user_data['nickname'] = $content_struct['nickname']; |
9 | 2836 |
} |
2837 |
||
2838 |
if ( isset( $content_struct['nicename'] ) ) { |
|
0 | 2839 |
$user_data['user_nicename'] = $content_struct['nicename']; |
9 | 2840 |
} |
2841 |
||
2842 |
if ( isset( $content_struct['bio'] ) ) { |
|
0 | 2843 |
$user_data['description'] = $content_struct['bio']; |
9 | 2844 |
} |
0 | 2845 |
|
2846 |
$result = wp_update_user( $user_data ); |
|
2847 |
||
9 | 2848 |
if ( is_wp_error( $result ) ) { |
0 | 2849 |
return new IXR_Error( 500, $result->get_error_message() ); |
9 | 2850 |
} |
2851 |
||
2852 |
if ( ! $result ) { |
|
0 | 2853 |
return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) ); |
9 | 2854 |
} |
0 | 2855 |
|
2856 |
return true; |
|
2857 |
} |
|
2858 |
||
2859 |
/** |
|
2860 |
* Retrieve page. |
|
2861 |
* |
|
2862 |
* @since 2.2.0 |
|
2863 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2867 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2869 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
* } |
5 | 2872 |
* @return array|IXR_Error |
0 | 2873 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2874 |
public function wp_getPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2875 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2876 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2878 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2879 |
$password = $args[3]; |
0 | 2880 |
|
9 | 2881 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2882 |
return $this->error; |
2883 |
} |
|
2884 |
||
9 | 2885 |
$page = get_post( $page_id ); |
2886 |
if ( ! $page ) { |
|
0 | 2887 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 2888 |
} |
2889 |
||
2890 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2891 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 2892 |
} |
0 | 2893 |
|
5 | 2894 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2895 |
do_action( 'xmlrpc_call', 'wp.getPage' ); |
|
0 | 2896 |
|
2897 |
// If we found the page then format the data. |
|
9 | 2898 |
if ( $page->ID && ( $page->post_type == 'page' ) ) { |
0 | 2899 |
return $this->_prepare_page( $page ); |
9 | 2900 |
} else { |
2901 |
// If the page doesn't exist indicate that. |
|
5 | 2902 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2903 |
} |
2904 |
} |
|
2905 |
||
2906 |
/** |
|
2907 |
* Retrieve Pages. |
|
2908 |
* |
|
2909 |
* @since 2.2.0 |
|
2910 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2913 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
* @type int $num_pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2918 |
* } |
5 | 2919 |
* @return array|IXR_Error |
0 | 2920 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
public function wp_getPages( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
$password = $args[2]; |
9 | 2926 |
$num_pages = isset( $args[3] ) ? (int) $args[3] : 10; |
2927 |
||
2928 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 2929 |
return $this->error; |
9 | 2930 |
} |
2931 |
||
2932 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 2934 |
} |
0 | 2935 |
|
5 | 2936 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2937 |
do_action( 'xmlrpc_call', 'wp.getPages' ); |
|
0 | 2938 |
|
9 | 2939 |
$pages = get_posts( |
2940 |
array( |
|
2941 |
'post_type' => 'page', |
|
2942 |
'post_status' => 'any', |
|
2943 |
'numberposts' => $num_pages, |
|
2944 |
) |
|
2945 |
); |
|
2946 |
$num_pages = count( $pages ); |
|
0 | 2947 |
|
2948 |
// If we have pages, put together their info. |
|
2949 |
if ( $num_pages >= 1 ) { |
|
2950 |
$pages_struct = array(); |
|
2951 |
||
9 | 2952 |
foreach ( $pages as $page ) { |
2953 |
if ( current_user_can( 'edit_page', $page->ID ) ) { |
|
0 | 2954 |
$pages_struct[] = $this->_prepare_page( $page ); |
9 | 2955 |
} |
0 | 2956 |
} |
2957 |
||
5 | 2958 |
return $pages_struct; |
0 | 2959 |
} |
5 | 2960 |
|
2961 |
return array(); |
|
0 | 2962 |
} |
2963 |
||
2964 |
/** |
|
2965 |
* Create new page. |
|
2966 |
* |
|
2967 |
* @since 2.2.0 |
|
2968 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2969 |
* @see wp_xmlrpc_server::mw_newPost() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2970 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2974 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2975 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2977 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
* } |
5 | 2979 |
* @return int|IXR_Error |
0 | 2980 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
public function wp_newPage( $args ) { |
0 | 2982 |
// Items not escaped here will be escaped in newPost. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
$password = $this->escape( $args[2] ); |
0 | 2985 |
|
9 | 2986 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 2987 |
return $this->error; |
9 | 2988 |
} |
0 | 2989 |
|
5 | 2990 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2991 |
do_action( 'xmlrpc_call', 'wp.newPage' ); |
|
0 | 2992 |
|
2993 |
// Mark this as content for a page. |
|
9 | 2994 |
$args[3]['post_type'] = 'page'; |
0 | 2995 |
|
2996 |
// Let mw_newPost do all of the heavy lifting. |
|
5 | 2997 |
return $this->mw_newPost( $args ); |
0 | 2998 |
} |
2999 |
||
3000 |
/** |
|
3001 |
* Delete page. |
|
3002 |
* |
|
3003 |
* @since 2.2.0 |
|
3004 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3012 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3013 |
* @return true|IXR_Error True, if success. |
0 | 3014 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
public function wp_deletePage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3020 |
$page_id = (int) $args[3]; |
0 | 3021 |
|
9 | 3022 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3023 |
return $this->error; |
9 | 3024 |
} |
0 | 3025 |
|
5 | 3026 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3027 |
do_action( 'xmlrpc_call', 'wp.deletePage' ); |
|
0 | 3028 |
|
3029 |
// Get the current page based on the page_id and |
|
3030 |
// make sure it is a page and not a post. |
|
9 | 3031 |
$actual_page = get_post( $page_id, ARRAY_A ); |
3032 |
if ( ! $actual_page || ( $actual_page['post_type'] != 'page' ) ) { |
|
5 | 3033 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3034 |
} |
0 | 3035 |
|
3036 |
// Make sure the user can delete pages. |
|
9 | 3037 |
if ( ! current_user_can( 'delete_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) ); |
9 | 3039 |
} |
0 | 3040 |
|
3041 |
// Attempt to delete the page. |
|
9 | 3042 |
$result = wp_delete_post( $page_id ); |
3043 |
if ( ! $result ) { |
|
5 | 3044 |
return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
9 | 3045 |
} |
5 | 3046 |
|
3047 |
/** |
|
3048 |
* Fires after a page has been successfully deleted via XML-RPC. |
|
3049 |
* |
|
3050 |
* @since 3.4.0 |
|
3051 |
* |
|
3052 |
* @param int $page_id ID of the deleted page. |
|
3053 |
* @param array $args An array of arguments to delete the page. |
|
3054 |
*/ |
|
0 | 3055 |
do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); |
3056 |
||
5 | 3057 |
return true; |
0 | 3058 |
} |
3059 |
||
3060 |
/** |
|
3061 |
* Edit page. |
|
3062 |
* |
|
3063 |
* @since 2.2.0 |
|
3064 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3065 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
* } |
5 | 3075 |
* @return array|IXR_Error |
0 | 3076 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
public function wp_editPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3078 |
// Items will be escaped in mw_editPost. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3082 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
$publish = $args[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
$escaped_username = $this->escape( $username ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
$escaped_password = $this->escape( $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
|
9 | 3088 |
if ( ! $user = $this->login( $escaped_username, $escaped_password ) ) { |
0 | 3089 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
} |
0 | 3091 |
|
5 | 3092 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3093 |
do_action( 'xmlrpc_call', 'wp.editPage' ); |
|
0 | 3094 |
|
3095 |
// Get the page data and make sure it is a page. |
|
9 | 3096 |
$actual_page = get_post( $page_id, ARRAY_A ); |
3097 |
if ( ! $actual_page || ( $actual_page['post_type'] != 'page' ) ) { |
|
5 | 3098 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3099 |
} |
0 | 3100 |
|
3101 |
// Make sure the user is allowed to edit pages. |
|
9 | 3102 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 3104 |
} |
0 | 3105 |
|
3106 |
// Mark this as content for a page. |
|
3107 |
$content['post_type'] = 'page'; |
|
3108 |
||
3109 |
// Arrange args in the way mw_editPost understands. |
|
3110 |
$args = array( |
|
3111 |
$page_id, |
|
3112 |
$username, |
|
3113 |
$password, |
|
3114 |
$content, |
|
9 | 3115 |
$publish, |
0 | 3116 |
); |
3117 |
||
3118 |
// Let mw_editPost do all of the heavy lifting. |
|
5 | 3119 |
return $this->mw_editPost( $args ); |
0 | 3120 |
} |
3121 |
||
3122 |
/** |
|
3123 |
* Retrieve page list. |
|
3124 |
* |
|
3125 |
* @since 2.2.0 |
|
3126 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3133 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3134 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
* } |
5 | 3136 |
* @return array|IXR_Error |
0 | 3137 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
public function wp_getPageList( $args ) { |
0 | 3139 |
global $wpdb; |
3140 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
$password = $args[2]; |
0 | 3145 |
|
9 | 3146 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3147 |
return $this->error; |
9 | 3148 |
} |
3149 |
||
3150 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3152 |
} |
0 | 3153 |
|
5 | 3154 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3155 |
do_action( 'xmlrpc_call', 'wp.getPageList' ); |
|
0 | 3156 |
|
3157 |
// Get list of pages ids and titles |
|
9 | 3158 |
$page_list = $wpdb->get_results( |
3159 |
" |
|
0 | 3160 |
SELECT ID page_id, |
3161 |
post_title page_title, |
|
3162 |
post_parent page_parent_id, |
|
3163 |
post_date_gmt, |
|
3164 |
post_date, |
|
3165 |
post_status |
|
3166 |
FROM {$wpdb->posts} |
|
3167 |
WHERE post_type = 'page' |
|
3168 |
ORDER BY ID |
|
9 | 3169 |
" |
3170 |
); |
|
0 | 3171 |
|
3172 |
// The date needs to be formatted properly. |
|
9 | 3173 |
$num_pages = count( $page_list ); |
0 | 3174 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
9 | 3175 |
$page_list[ $i ]->dateCreated = $this->_convert_date( $page_list[ $i ]->post_date ); |
3176 |
$page_list[ $i ]->date_created_gmt = $this->_convert_date_gmt( $page_list[ $i ]->post_date_gmt, $page_list[ $i ]->post_date ); |
|
3177 |
||
3178 |
unset( $page_list[ $i ]->post_date_gmt ); |
|
3179 |
unset( $page_list[ $i ]->post_date ); |
|
3180 |
unset( $page_list[ $i ]->post_status ); |
|
0 | 3181 |
} |
3182 |
||
5 | 3183 |
return $page_list; |
0 | 3184 |
} |
3185 |
||
3186 |
/** |
|
3187 |
* Retrieve authors list. |
|
3188 |
* |
|
3189 |
* @since 2.2.0 |
|
3190 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
* } |
5 | 3198 |
* @return array|IXR_Error |
0 | 3199 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
public function wp_getAuthors( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
$password = $args[2]; |
0 | 3205 |
|
9 | 3206 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3207 |
return $this->error; |
9 | 3208 |
} |
3209 |
||
3210 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3211 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 3212 |
} |
5 | 3213 |
|
3214 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3215 |
do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
|
0 | 3216 |
|
3217 |
$authors = array(); |
|
9 | 3218 |
foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
0 | 3219 |
$authors[] = array( |
9 | 3220 |
'user_id' => $user->ID, |
3221 |
'user_login' => $user->user_login, |
|
3222 |
'display_name' => $user->display_name, |
|
0 | 3223 |
); |
3224 |
} |
|
3225 |
||
3226 |
return $authors; |
|
3227 |
} |
|
3228 |
||
3229 |
/** |
|
3230 |
* Get list of all tags |
|
3231 |
* |
|
3232 |
* @since 2.7.0 |
|
3233 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3234 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3235 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3236 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3237 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3238 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
* } |
5 | 3241 |
* @return array|IXR_Error |
0 | 3242 |
*/ |
5 | 3243 |
public function wp_getTags( $args ) { |
0 | 3244 |
$this->escape( $args ); |
3245 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
$password = $args[2]; |
0 | 3248 |
|
9 | 3249 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3250 |
return $this->error; |
9 | 3251 |
} |
3252 |
||
3253 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 3254 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
9 | 3255 |
} |
0 | 3256 |
|
5 | 3257 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 3258 |
do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
3259 |
||
3260 |
$tags = array(); |
|
3261 |
||
3262 |
if ( $all_tags = get_tags() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3263 |
foreach ( (array) $all_tags as $tag ) { |
9 | 3264 |
$struct = array(); |
3265 |
$struct['tag_id'] = $tag->term_id; |
|
3266 |
$struct['name'] = $tag->name; |
|
3267 |
$struct['count'] = $tag->count; |
|
3268 |
$struct['slug'] = $tag->slug; |
|
3269 |
$struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
|
3270 |
$struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) ); |
|
0 | 3271 |
|
3272 |
$tags[] = $struct; |
|
3273 |
} |
|
3274 |
} |
|
3275 |
||
3276 |
return $tags; |
|
3277 |
} |
|
3278 |
||
3279 |
/** |
|
3280 |
* Create new category. |
|
3281 |
* |
|
3282 |
* @since 2.2.0 |
|
3283 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3285 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3291 |
* } |
5 | 3292 |
* @return int|IXR_Error Category ID. |
0 | 3293 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
public function wp_newCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3299 |
$category = $args[3]; |
0 | 3300 |
|
9 | 3301 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3302 |
return $this->error; |
9 | 3303 |
} |
0 | 3304 |
|
5 | 3305 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3306 |
do_action( 'xmlrpc_call', 'wp.newCategory' ); |
|
0 | 3307 |
|
3308 |
// 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
|
3309 |
if ( ! current_user_can( 'manage_categories' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
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
|
3311 |
} |
0 | 3312 |
|
3313 |
// If no slug was provided make it empty so that |
|
3314 |
// WordPress will generate one. |
|
9 | 3315 |
if ( empty( $category['slug'] ) ) { |
0 | 3316 |
$category['slug'] = ''; |
9 | 3317 |
} |
0 | 3318 |
|
3319 |
// If no parent_id was provided make it empty |
|
3320 |
// so that it will be a top level page (no parent). |
|
9 | 3321 |
if ( ! isset( $category['parent_id'] ) ) { |
0 | 3322 |
$category['parent_id'] = ''; |
9 | 3323 |
} |
0 | 3324 |
|
3325 |
// If no description was provided make it empty. |
|
9 | 3326 |
if ( empty( $category['description'] ) ) { |
3327 |
$category['description'] = ''; |
|
3328 |
} |
|
0 | 3329 |
|
3330 |
$new_category = array( |
|
9 | 3331 |
'cat_name' => $category['name'], |
3332 |
'category_nicename' => $category['slug'], |
|
3333 |
'category_parent' => $category['parent_id'], |
|
3334 |
'category_description' => $category['description'], |
|
0 | 3335 |
); |
3336 |
||
9 | 3337 |
$cat_id = wp_insert_category( $new_category, true ); |
0 | 3338 |
if ( is_wp_error( $cat_id ) ) { |
9 | 3339 |
if ( 'term_exists' == $cat_id->get_error_code() ) { |
0 | 3340 |
return (int) $cat_id->get_error_data(); |
9 | 3341 |
} else { |
3342 |
return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) ); |
|
3343 |
} |
|
0 | 3344 |
} elseif ( ! $cat_id ) { |
9 | 3345 |
return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) ); |
0 | 3346 |
} |
3347 |
||
5 | 3348 |
/** |
3349 |
* Fires after a new category has been successfully created via XML-RPC. |
|
3350 |
* |
|
3351 |
* @since 3.4.0 |
|
3352 |
* |
|
3353 |
* @param int $cat_id ID of the new category. |
|
3354 |
* @param array $args An array of new category arguments. |
|
3355 |
*/ |
|
0 | 3356 |
do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); |
3357 |
||
3358 |
return $cat_id; |
|
3359 |
} |
|
3360 |
||
3361 |
/** |
|
3362 |
* Remove category. |
|
3363 |
* |
|
3364 |
* @since 2.5.0 |
|
3365 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3366 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3368 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3372 |
* @type int $category_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
* @return bool|IXR_Error See wp_delete_term() for return info. |
0 | 3375 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
public function wp_deleteCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
$category_id = (int) $args[3]; |
0 | 3382 |
|
9 | 3383 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3384 |
return $this->error; |
9 | 3385 |
} |
0 | 3386 |
|
5 | 3387 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3388 |
do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
|
0 | 3389 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
if ( ! current_user_can( 'delete_term', $category_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
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
|
3392 |
} |
0 | 3393 |
|
3394 |
$status = wp_delete_term( $category_id, 'category' ); |
|
3395 |
||
5 | 3396 |
if ( true == $status ) { |
3397 |
/** |
|
3398 |
* Fires after a category has been successfully deleted via XML-RPC. |
|
3399 |
* |
|
3400 |
* @since 3.4.0 |
|
3401 |
* |
|
3402 |
* @param int $category_id ID of the deleted category. |
|
3403 |
* @param array $args An array of arguments to delete the category. |
|
3404 |
*/ |
|
0 | 3405 |
do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); |
5 | 3406 |
} |
0 | 3407 |
|
3408 |
return $status; |
|
3409 |
} |
|
3410 |
||
3411 |
/** |
|
3412 |
* Retrieve category list. |
|
3413 |
* |
|
3414 |
* @since 2.2.0 |
|
3415 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3418 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3421 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
* @type int $max_results |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
* } |
5 | 3425 |
* @return array|IXR_Error |
0 | 3426 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
public function wp_suggestCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3429 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3430 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3431 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
$category = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
$max_results = (int) $args[4]; |
0 | 3434 |
|
9 | 3435 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3436 |
return $this->error; |
9 | 3437 |
} |
3438 |
||
3439 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
5 | 3440 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 3441 |
} |
5 | 3442 |
|
3443 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3444 |
do_action( 'xmlrpc_call', 'wp.suggestCategories' ); |
|
0 | 3445 |
|
3446 |
$category_suggestions = array(); |
|
9 | 3447 |
$args = array( |
3448 |
'get' => 'all', |
|
3449 |
'number' => $max_results, |
|
3450 |
'name__like' => $category, |
|
3451 |
); |
|
3452 |
foreach ( (array) get_categories( $args ) as $cat ) { |
|
0 | 3453 |
$category_suggestions[] = array( |
9 | 3454 |
'category_id' => $cat->term_id, |
3455 |
'category_name' => $cat->name, |
|
0 | 3456 |
); |
3457 |
} |
|
3458 |
||
5 | 3459 |
return $category_suggestions; |
0 | 3460 |
} |
3461 |
||
3462 |
/** |
|
3463 |
* Retrieve comment. |
|
3464 |
* |
|
3465 |
* @since 2.7.0 |
|
3466 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3470 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3472 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3473 |
* @type int $comment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3474 |
* } |
5 | 3475 |
* @return array|IXR_Error |
0 | 3476 |
*/ |
9 | 3477 |
public function wp_getComment( $args ) { |
3478 |
$this->escape( $args ); |
|
3479 |
||
3480 |
$username = $args[1]; |
|
3481 |
$password = $args[2]; |
|
3482 |
$comment_id = (int) $args[3]; |
|
0 | 3483 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3484 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3485 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3486 |
} |
0 | 3487 |
|
5 | 3488 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3489 |
do_action( 'xmlrpc_call', 'wp.getComment' ); |
|
0 | 3490 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3491 |
if ( ! $comment = get_comment( $comment_id ) ) { |
0 | 3492 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3493 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
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
|
3497 |
} |
0 | 3498 |
|
3499 |
return $this->_prepare_comment( $comment ); |
|
3500 |
} |
|
3501 |
||
3502 |
/** |
|
3503 |
* Retrieve comments. |
|
3504 |
* |
|
5 | 3505 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 3506 |
* array as last argument. |
3507 |
* |
|
3508 |
* Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
|
3509 |
* |
|
3510 |
* The defaults are as follows: |
|
3511 |
* - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
|
3512 |
* - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
|
3513 |
* - '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
|
3514 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 3515 |
* |
3516 |
* @since 2.7.0 |
|
3517 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* Method arguments. Note: arguments must be ordered as documented. |
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 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3525 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3526 |
* @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents |
0 | 3527 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
public function wp_getComments( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3529 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3530 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3531 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3532 |
$password = $args[2]; |
9 | 3533 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3534 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3535 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3536 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3537 |
} |
0 | 3538 |
|
5 | 3539 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3540 |
do_action( 'xmlrpc_call', 'wp.getComments' ); |
|
0 | 3541 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
if ( isset( $struct['status'] ) ) { |
0 | 3543 |
$status = $struct['status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
} else { |
0 | 3545 |
$status = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3550 |
} |
0 | 3551 |
|
3552 |
$post_id = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
if ( isset( $struct['post_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
$post_id = absint( $struct['post_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3556 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3557 |
$post_type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
if ( isset( $struct['post_type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3559 |
$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
|
3560 |
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
|
3561 |
return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
$post_type = $struct['post_type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
} |
0 | 3565 |
|
3566 |
$offset = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3567 |
if ( isset( $struct['offset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
$offset = absint( $struct['offset'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
} |
0 | 3570 |
|
3571 |
$number = 10; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
if ( isset( $struct['number'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
$number = absint( $struct['number'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
|
9 | 3576 |
$comments = get_comments( |
3577 |
array( |
|
3578 |
'status' => $status, |
|
3579 |
'post_id' => $post_id, |
|
3580 |
'offset' => $offset, |
|
3581 |
'number' => $number, |
|
3582 |
'post_type' => $post_type, |
|
3583 |
) |
|
3584 |
); |
|
0 | 3585 |
|
3586 |
$comments_struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
$comments_struct[] = $this->_prepare_comment( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
} |
0 | 3591 |
} |
3592 |
||
3593 |
return $comments_struct; |
|
3594 |
} |
|
3595 |
||
3596 |
/** |
|
3597 |
* Delete a comment. |
|
3598 |
* |
|
3599 |
* 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
|
3600 |
* See wp_delete_comment() for more information on this behavior. |
0 | 3601 |
* |
3602 |
* @since 2.7.0 |
|
3603 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3607 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
* @return bool|IXR_Error See wp_delete_comment(). |
0 | 3613 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
public function wp_deleteComment( $args ) { |
9 | 3615 |
$this->escape( $args ); |
3616 |
||
3617 |
$username = $args[1]; |
|
3618 |
$password = $args[2]; |
|
3619 |
$comment_ID = (int) $args[3]; |
|
0 | 3620 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3622 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3623 |
} |
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 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3626 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3629 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
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
|
3631 |
} |
0 | 3632 |
|
5 | 3633 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3634 |
do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
|
0 | 3635 |
|
3636 |
$status = wp_delete_comment( $comment_ID ); |
|
3637 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
if ( $status ) { |
5 | 3639 |
/** |
3640 |
* Fires after a comment has been successfully deleted via XML-RPC. |
|
3641 |
* |
|
3642 |
* @since 3.4.0 |
|
3643 |
* |
|
3644 |
* @param int $comment_ID ID of the deleted comment. |
|
3645 |
* @param array $args An array of arguments to delete the comment. |
|
3646 |
*/ |
|
0 | 3647 |
do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); |
5 | 3648 |
} |
0 | 3649 |
|
3650 |
return $status; |
|
3651 |
} |
|
3652 |
||
3653 |
/** |
|
3654 |
* Edit comment. |
|
3655 |
* |
|
5 | 3656 |
* Besides the common blog_id (unused), username, and password arguments, it takes a |
0 | 3657 |
* comment_id integer and a content_struct array as last argument. |
3658 |
* |
|
3659 |
* The allowed keys in the content_struct array are: |
|
3660 |
* - 'author' |
|
3661 |
* - 'author_url' |
|
3662 |
* - 'author_email' |
|
3663 |
* - 'content' |
|
3664 |
* - 'date_created_gmt' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
* - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details |
0 | 3666 |
* |
3667 |
* @since 2.7.0 |
|
3668 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
* @return true|IXR_Error True, on success. |
0 | 3679 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
public function wp_editComment( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3681 |
$this->escape( $args ); |
0 | 3682 |
|
9 | 3683 |
$username = $args[1]; |
3684 |
$password = $args[2]; |
|
3685 |
$comment_ID = (int) $args[3]; |
|
0 | 3686 |
$content_struct = $args[4]; |
3687 |
||
9 | 3688 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3689 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3693 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
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
|
3698 |
} |
0 | 3699 |
|
5 | 3700 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3701 |
do_action( 'xmlrpc_call', 'wp.editComment' ); |
|
9 | 3702 |
$comment = array( |
3703 |
'comment_ID' => $comment_ID, |
|
3704 |
); |
|
3705 |
||
3706 |
if ( isset( $content_struct['status'] ) ) { |
|
0 | 3707 |
$statuses = get_comment_statuses(); |
9 | 3708 |
$statuses = array_keys( $statuses ); |
3709 |
||
3710 |
if ( ! in_array( $content_struct['status'], $statuses ) ) { |
|
0 | 3711 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
9 | 3712 |
} |
3713 |
||
3714 |
$comment['comment_approved'] = $content_struct['status']; |
|
0 | 3715 |
} |
3716 |
||
3717 |
// Do some timestamp voodoo |
|
9 | 3718 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
0 | 3719 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force |
9 | 3720 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
3721 |
$comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
|
3722 |
$comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); |
|
3723 |
} |
|
3724 |
||
3725 |
if ( isset( $content_struct['content'] ) ) { |
|
3726 |
$comment['comment_content'] = $content_struct['content']; |
|
3727 |
} |
|
3728 |
||
3729 |
if ( isset( $content_struct['author'] ) ) { |
|
3730 |
$comment['comment_author'] = $content_struct['author']; |
|
3731 |
} |
|
3732 |
||
3733 |
if ( isset( $content_struct['author_url'] ) ) { |
|
3734 |
$comment['comment_author_url'] = $content_struct['author_url']; |
|
3735 |
} |
|
3736 |
||
3737 |
if ( isset( $content_struct['author_email'] ) ) { |
|
3738 |
$comment['comment_author_email'] = $content_struct['author_email']; |
|
3739 |
} |
|
3740 |
||
3741 |
$result = wp_update_comment( $comment ); |
|
3742 |
if ( is_wp_error( $result ) ) { |
|
3743 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
3744 |
} |
|
3745 |
||
3746 |
if ( ! $result ) { |
|
3747 |
return new IXR_Error( 500, __( 'Sorry, the comment could not be edited.' ) ); |
|
3748 |
} |
|
0 | 3749 |
|
5 | 3750 |
/** |
3751 |
* Fires after a comment has been successfully updated via XML-RPC. |
|
3752 |
* |
|
3753 |
* @since 3.4.0 |
|
3754 |
* |
|
3755 |
* @param int $comment_ID ID of the updated comment. |
|
3756 |
* @param array $args An array of arguments to update the comment. |
|
3757 |
*/ |
|
0 | 3758 |
do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); |
3759 |
||
3760 |
return true; |
|
3761 |
} |
|
3762 |
||
3763 |
/** |
|
3764 |
* Create new comment. |
|
3765 |
* |
|
3766 |
* @since 2.7.0 |
|
3767 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3773 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
* @type string|int $post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3775 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3777 |
* @return int|IXR_Error See wp_new_comment(). |
0 | 3778 |
*/ |
9 | 3779 |
public function wp_newComment( $args ) { |
3780 |
$this->escape( $args ); |
|
0 | 3781 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3782 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3783 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3784 |
$post = $args[3]; |
0 | 3785 |
$content_struct = $args[4]; |
3786 |
||
5 | 3787 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3788 |
* Filters whether to allow anonymous comments over XML-RPC. |
5 | 3789 |
* |
3790 |
* @since 2.7.0 |
|
3791 |
* |
|
3792 |
* @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3793 |
* Default false. |
|
3794 |
*/ |
|
3795 |
$allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
|
0 | 3796 |
|
9 | 3797 |
$user = $this->login( $username, $password ); |
3798 |
||
3799 |
if ( ! $user ) { |
|
0 | 3800 |
$logged_in = false; |
9 | 3801 |
if ( $allow_anon && get_option( 'comment_registration' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3802 |
return new IXR_Error( 403, __( 'You must be registered to comment.' ) ); |
5 | 3803 |
} elseif ( ! $allow_anon ) { |
0 | 3804 |
return $this->error; |
5 | 3805 |
} |
0 | 3806 |
} else { |
3807 |
$logged_in = true; |
|
3808 |
} |
|
3809 |
||
9 | 3810 |
if ( is_numeric( $post ) ) { |
3811 |
$post_id = absint( $post ); |
|
3812 |
} else { |
|
3813 |
$post_id = url_to_postid( $post ); |
|
3814 |
} |
|
0 | 3815 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
if ( ! $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3819 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3820 |
if ( ! get_post( $post_id ) ) { |
0 | 3821 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
if ( ! comments_open( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
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
|
3826 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
if ( empty( $content_struct['content'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
return new IXR_Error( 403, __( 'Comment is required.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3830 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3831 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
$comment = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3833 |
'comment_post_ID' => $post_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
'comment_content' => $content_struct['content'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3835 |
); |
0 | 3836 |
|
3837 |
if ( $logged_in ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3838 |
$display_name = $user->display_name; |
9 | 3839 |
$user_email = $user->user_email; |
3840 |
$user_url = $user->user_url; |
|
3841 |
||
3842 |
$comment['comment_author'] = $this->escape( $display_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3843 |
$comment['comment_author_email'] = $this->escape( $user_email ); |
9 | 3844 |
$comment['comment_author_url'] = $this->escape( $user_url ); |
3845 |
$comment['user_ID'] = $user->ID; |
|
0 | 3846 |
} else { |
3847 |
$comment['comment_author'] = ''; |
|
9 | 3848 |
if ( isset( $content_struct['author'] ) ) { |
0 | 3849 |
$comment['comment_author'] = $content_struct['author']; |
9 | 3850 |
} |
0 | 3851 |
|
3852 |
$comment['comment_author_email'] = ''; |
|
9 | 3853 |
if ( isset( $content_struct['author_email'] ) ) { |
0 | 3854 |
$comment['comment_author_email'] = $content_struct['author_email']; |
9 | 3855 |
} |
0 | 3856 |
|
3857 |
$comment['comment_author_url'] = ''; |
|
9 | 3858 |
if ( isset( $content_struct['author_url'] ) ) { |
0 | 3859 |
$comment['comment_author_url'] = $content_struct['author_url']; |
9 | 3860 |
} |
0 | 3861 |
|
3862 |
$comment['user_ID'] = 0; |
|
3863 |
||
9 | 3864 |
if ( get_option( 'require_name_email' ) ) { |
3865 |
if ( 6 > strlen( $comment['comment_author_email'] ) || '' == $comment['comment_author'] ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
9 | 3867 |
} elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
9 | 3869 |
} |
0 | 3870 |
} |
3871 |
} |
|
3872 |
||
9 | 3873 |
$comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
0 | 3874 |
|
5 | 3875 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3876 |
do_action( 'xmlrpc_call', 'wp.newComment' ); |
|
0 | 3877 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
$comment_ID = wp_new_comment( $comment, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
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
|
3881 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3883 |
if ( ! $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
return new IXR_Error( 403, __( 'Something went wrong.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
} |
0 | 3886 |
|
5 | 3887 |
/** |
3888 |
* Fires after a new comment has been successfully created via XML-RPC. |
|
3889 |
* |
|
3890 |
* @since 3.4.0 |
|
3891 |
* |
|
3892 |
* @param int $comment_ID ID of the new comment. |
|
3893 |
* @param array $args An array of new comment arguments. |
|
3894 |
*/ |
|
0 | 3895 |
do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); |
3896 |
||
3897 |
return $comment_ID; |
|
3898 |
} |
|
3899 |
||
3900 |
/** |
|
3901 |
* Retrieve all of the comment status. |
|
3902 |
* |
|
3903 |
* @since 2.7.0 |
|
3904 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
* } |
5 | 3912 |
* @return array|IXR_Error |
0 | 3913 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
public function wp_getCommentStatusList( $args ) { |
0 | 3915 |
$this->escape( $args ); |
3916 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
$password = $args[2]; |
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 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3921 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
} |
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 |
if ( ! current_user_can( 'publish_posts' ) ) { |
9 | 3925 |
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
|
3926 |
} |
0 | 3927 |
|
5 | 3928 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3929 |
do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
|
0 | 3930 |
|
3931 |
return get_comment_statuses(); |
|
3932 |
} |
|
3933 |
||
3934 |
/** |
|
3935 |
* Retrieve comment count. |
|
3936 |
* |
|
3937 |
* @since 2.5.0 |
|
3938 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3944 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
* } |
5 | 3947 |
* @return array|IXR_Error |
0 | 3948 |
*/ |
5 | 3949 |
public function wp_getCommentCount( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
$this->escape( $args ); |
0 | 3951 |
|
9 | 3952 |
$username = $args[1]; |
3953 |
$password = $args[2]; |
|
3954 |
$post_id = (int) $args[3]; |
|
0 | 3955 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3957 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
$post = get_post( $post_id, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
if ( empty( $post['ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 3966 |
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
|
3967 |
} |
0 | 3968 |
|
5 | 3969 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3970 |
do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
|
0 | 3971 |
|
3972 |
$count = wp_count_comments( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
|
0 | 3974 |
return array( |
9 | 3975 |
'approved' => $count->approved, |
0 | 3976 |
'awaiting_moderation' => $count->moderated, |
9 | 3977 |
'spam' => $count->spam, |
3978 |
'total_comments' => $count->total_comments, |
|
0 | 3979 |
); |
3980 |
} |
|
3981 |
||
3982 |
/** |
|
3983 |
* Retrieve post statuses. |
|
3984 |
* |
|
3985 |
* @since 2.5.0 |
|
3986 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
* } |
5 | 3994 |
* @return array|IXR_Error |
0 | 3995 |
*/ |
5 | 3996 |
public function wp_getPostStatusList( $args ) { |
0 | 3997 |
$this->escape( $args ); |
3998 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
$password = $args[2]; |
0 | 4001 |
|
9 | 4002 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4003 |
return $this->error; |
9 | 4004 |
} |
4005 |
||
4006 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4007 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4008 |
} |
|
0 | 4009 |
|
5 | 4010 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4011 |
do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
|
0 | 4012 |
|
4013 |
return get_post_statuses(); |
|
4014 |
} |
|
4015 |
||
4016 |
/** |
|
4017 |
* Retrieve page statuses. |
|
4018 |
* |
|
4019 |
* @since 2.5.0 |
|
4020 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4021 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4022 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4023 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4024 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4025 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4026 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4027 |
* } |
5 | 4028 |
* @return array|IXR_Error |
0 | 4029 |
*/ |
5 | 4030 |
public function wp_getPageStatusList( $args ) { |
0 | 4031 |
$this->escape( $args ); |
4032 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4033 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4034 |
$password = $args[2]; |
0 | 4035 |
|
9 | 4036 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4037 |
return $this->error; |
9 | 4038 |
} |
4039 |
||
4040 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4041 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4042 |
} |
|
0 | 4043 |
|
5 | 4044 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4045 |
do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
|
0 | 4046 |
|
4047 |
return get_page_statuses(); |
|
4048 |
} |
|
4049 |
||
4050 |
/** |
|
4051 |
* Retrieve page templates. |
|
4052 |
* |
|
4053 |
* @since 2.6.0 |
|
4054 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4055 |
* @param array $args { |
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 |
* } |
5 | 4062 |
* @return array|IXR_Error |
0 | 4063 |
*/ |
5 | 4064 |
public function wp_getPageTemplates( $args ) { |
0 | 4065 |
$this->escape( $args ); |
4066 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4067 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4068 |
$password = $args[2]; |
0 | 4069 |
|
9 | 4070 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4071 |
return $this->error; |
9 | 4072 |
} |
4073 |
||
4074 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4075 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4076 |
} |
|
4077 |
||
4078 |
$templates = get_page_templates(); |
|
0 | 4079 |
$templates['Default'] = 'default'; |
4080 |
||
4081 |
return $templates; |
|
4082 |
} |
|
4083 |
||
4084 |
/** |
|
4085 |
* Retrieve blog options. |
|
4086 |
* |
|
4087 |
* @since 2.6.0 |
|
4088 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4089 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4090 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4091 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4092 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4093 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4094 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4095 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4096 |
* } |
5 | 4097 |
* @return array|IXR_Error |
0 | 4098 |
*/ |
5 | 4099 |
public function wp_getOptions( $args ) { |
0 | 4100 |
$this->escape( $args ); |
4101 |
||
9 | 4102 |
$username = $args[1]; |
4103 |
$password = $args[2]; |
|
4104 |
$options = isset( $args[3] ) ? (array) $args[3] : array(); |
|
4105 |
||
4106 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4107 |
return $this->error; |
9 | 4108 |
} |
0 | 4109 |
|
4110 |
// If no specific options where asked for, return all of them |
|
9 | 4111 |
if ( count( $options ) == 0 ) { |
4112 |
$options = array_keys( $this->blog_options ); |
|
4113 |
} |
|
4114 |
||
4115 |
return $this->_getOptions( $options ); |
|
0 | 4116 |
} |
4117 |
||
4118 |
/** |
|
4119 |
* Retrieve blog options value from list. |
|
4120 |
* |
|
4121 |
* @since 2.6.0 |
|
4122 |
* |
|
4123 |
* @param array $options Options to retrieve. |
|
4124 |
* @return array |
|
4125 |
*/ |
|
9 | 4126 |
public function _getOptions( $options ) { |
4127 |
$data = array(); |
|
0 | 4128 |
$can_manage = current_user_can( 'manage_options' ); |
4129 |
foreach ( $options as $option ) { |
|
4130 |
if ( array_key_exists( $option, $this->blog_options ) ) { |
|
9 | 4131 |
$data[ $option ] = $this->blog_options[ $option ]; |
0 | 4132 |
//Is the value static or dynamic? |
9 | 4133 |
if ( isset( $data[ $option ]['option'] ) ) { |
4134 |
$data[ $option ]['value'] = get_option( $data[ $option ]['option'] ); |
|
4135 |
unset( $data[ $option ]['option'] ); |
|
0 | 4136 |
} |
4137 |
||
9 | 4138 |
if ( ! $can_manage ) { |
4139 |
$data[ $option ]['readonly'] = true; |
|
4140 |
} |
|
0 | 4141 |
} |
4142 |
} |
|
4143 |
||
4144 |
return $data; |
|
4145 |
} |
|
4146 |
||
4147 |
/** |
|
4148 |
* Update blog options. |
|
4149 |
* |
|
4150 |
* @since 2.6.0 |
|
4151 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4153 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4154 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4155 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4156 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4157 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4158 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4159 |
* } |
5 | 4160 |
* @return array|IXR_Error |
0 | 4161 |
*/ |
5 | 4162 |
public function wp_setOptions( $args ) { |
0 | 4163 |
$this->escape( $args ); |
4164 |
||
9 | 4165 |
$username = $args[1]; |
4166 |
$password = $args[2]; |
|
4167 |
$options = (array) $args[3]; |
|
4168 |
||
4169 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4170 |
return $this->error; |
9 | 4171 |
} |
4172 |
||
4173 |
if ( ! current_user_can( 'manage_options' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4174 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) ); |
9 | 4175 |
} |
0 | 4176 |
|
5 | 4177 |
$option_names = array(); |
0 | 4178 |
foreach ( $options as $o_name => $o_value ) { |
4179 |
$option_names[] = $o_name; |
|
9 | 4180 |
if ( ! array_key_exists( $o_name, $this->blog_options ) ) { |
0 | 4181 |
continue; |
9 | 4182 |
} |
4183 |
||
4184 |
if ( $this->blog_options[ $o_name ]['readonly'] == true ) { |
|
0 | 4185 |
continue; |
9 | 4186 |
} |
4187 |
||
4188 |
update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) ); |
|
0 | 4189 |
} |
4190 |
||
4191 |
//Now return the updated values |
|
9 | 4192 |
return $this->_getOptions( $option_names ); |
0 | 4193 |
} |
4194 |
||
4195 |
/** |
|
4196 |
* Retrieve a media item by ID |
|
4197 |
* |
|
4198 |
* @since 3.1.0 |
|
4199 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4200 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4201 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4202 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4203 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4204 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4205 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4206 |
* @type int $attachment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4207 |
* } |
5 | 4208 |
* @return array|IXR_Error Associative array contains: |
0 | 4209 |
* - 'date_created_gmt' |
4210 |
* - 'parent' |
|
4211 |
* - 'link' |
|
4212 |
* - 'thumbnail' |
|
4213 |
* - 'title' |
|
4214 |
* - 'caption' |
|
4215 |
* - 'description' |
|
4216 |
* - 'metadata' |
|
4217 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
public function wp_getMediaItem( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4219 |
$this->escape( $args ); |
0 | 4220 |
|
9 | 4221 |
$username = $args[1]; |
4222 |
$password = $args[2]; |
|
4223 |
$attachment_id = (int) $args[3]; |
|
4224 |
||
4225 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4226 |
return $this->error; |
9 | 4227 |
} |
4228 |
||
4229 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4230 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4231 |
} |
0 | 4232 |
|
5 | 4233 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4234 |
do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
|
0 | 4235 |
|
9 | 4236 |
if ( ! $attachment = get_post( $attachment_id ) ) { |
0 | 4237 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 4238 |
} |
0 | 4239 |
|
4240 |
return $this->_prepare_media_item( $attachment ); |
|
4241 |
} |
|
4242 |
||
4243 |
/** |
|
4244 |
* Retrieves a collection of media library items (or attachments) |
|
4245 |
* |
|
5 | 4246 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 4247 |
* array as last argument. |
4248 |
* |
|
4249 |
* Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
|
4250 |
* |
|
4251 |
* The defaults are as follows: |
|
4252 |
* - '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
|
4253 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 4254 |
* - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
4255 |
* - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
|
4256 |
* |
|
4257 |
* @since 3.1.0 |
|
4258 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4259 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4260 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4261 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4262 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4263 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4264 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4265 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4266 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4267 |
* @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents |
0 | 4268 |
*/ |
9 | 4269 |
public function wp_getMediaLibrary( $args ) { |
4270 |
$this->escape( $args ); |
|
4271 |
||
4272 |
$username = $args[1]; |
|
4273 |
$password = $args[2]; |
|
4274 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
|
4275 |
||
4276 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4277 |
return $this->error; |
9 | 4278 |
} |
4279 |
||
4280 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4281 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4282 |
} |
0 | 4283 |
|
5 | 4284 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4285 |
do_action( 'xmlrpc_call', 'wp.getMediaLibrary' ); |
|
0 | 4286 |
|
9 | 4287 |
$parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4288 |
$mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
|
4289 |
$offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
|
4290 |
$number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
|
4291 |
||
4292 |
$attachments = get_posts( |
|
4293 |
array( |
|
4294 |
'post_type' => 'attachment', |
|
4295 |
'post_parent' => $parent_id, |
|
4296 |
'offset' => $offset, |
|
4297 |
'numberposts' => $number, |
|
4298 |
'post_mime_type' => $mime_type, |
|
4299 |
) |
|
4300 |
); |
|
0 | 4301 |
|
4302 |
$attachments_struct = array(); |
|
4303 |
||
9 | 4304 |
foreach ( $attachments as $attachment ) { |
0 | 4305 |
$attachments_struct[] = $this->_prepare_media_item( $attachment ); |
9 | 4306 |
} |
0 | 4307 |
|
4308 |
return $attachments_struct; |
|
4309 |
} |
|
4310 |
||
4311 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4312 |
* 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
|
4313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4314 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4315 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4316 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4317 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4318 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4319 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4320 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4321 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4322 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4323 |
* @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
|
4324 |
*/ |
5 | 4325 |
public function wp_getPostFormats( $args ) { |
0 | 4326 |
$this->escape( $args ); |
4327 |
||
4328 |
$username = $args[1]; |
|
4329 |
$password = $args[2]; |
|
4330 |
||
9 | 4331 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4332 |
return $this->error; |
9 | 4333 |
} |
4334 |
||
4335 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4336 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4337 |
} |
|
0 | 4338 |
|
5 | 4339 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4340 |
do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
4341 |
||
4342 |
$formats = get_post_format_strings(); |
|
4343 |
||
5 | 4344 |
// find out if they want a list of currently supports formats |
0 | 4345 |
if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4346 |
if ( $args[3]['show-supported'] ) { |
|
4347 |
if ( current_theme_supports( 'post-formats' ) ) { |
|
4348 |
$supported = get_theme_support( 'post-formats' ); |
|
4349 |
||
9 | 4350 |
$data = array(); |
4351 |
$data['all'] = $formats; |
|
0 | 4352 |
$data['supported'] = $supported[0]; |
4353 |
||
4354 |
$formats = $data; |
|
4355 |
} |
|
4356 |
} |
|
4357 |
} |
|
4358 |
||
4359 |
return $formats; |
|
4360 |
} |
|
4361 |
||
4362 |
/** |
|
4363 |
* Retrieves a post type |
|
4364 |
* |
|
4365 |
* @since 3.4.0 |
|
4366 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4367 |
* @see get_post_type_object() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4368 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4369 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4370 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4371 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4372 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4373 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4374 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
* @type string $post_type_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4376 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4377 |
* } |
5 | 4378 |
* @return array|IXR_Error Array contains: |
0 | 4379 |
* - 'labels' |
4380 |
* - 'description' |
|
4381 |
* - 'capability_type' |
|
4382 |
* - 'cap' |
|
4383 |
* - 'map_meta_cap' |
|
4384 |
* - 'hierarchical' |
|
4385 |
* - 'menu_position' |
|
4386 |
* - 'taxonomies' |
|
4387 |
* - 'supports' |
|
4388 |
*/ |
|
5 | 4389 |
public function wp_getPostType( $args ) { |
9 | 4390 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4391 |
return $this->error; |
9 | 4392 |
} |
0 | 4393 |
|
4394 |
$this->escape( $args ); |
|
4395 |
||
4396 |
$username = $args[1]; |
|
4397 |
$password = $args[2]; |
|
4398 |
$post_type_name = $args[3]; |
|
4399 |
||
5 | 4400 |
if ( isset( $args[4] ) ) { |
0 | 4401 |
$fields = $args[4]; |
5 | 4402 |
} else { |
4403 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4404 |
* Filters the default query fields used by the given XML-RPC method. |
5 | 4405 |
* |
4406 |
* @since 3.4.0 |
|
4407 |
* |
|
4408 |
* @param array $fields An array of post type query fields for the given method. |
|
4409 |
* @param string $method The method name. |
|
4410 |
*/ |
|
0 | 4411 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
5 | 4412 |
} |
0 | 4413 |
|
9 | 4414 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4415 |
return $this->error; |
9 | 4416 |
} |
0 | 4417 |
|
5 | 4418 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4419 |
do_action( 'xmlrpc_call', 'wp.getPostType' ); |
4420 |
||
9 | 4421 |
if ( ! post_type_exists( $post_type_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4422 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 4423 |
} |
0 | 4424 |
|
4425 |
$post_type = get_post_type_object( $post_type_name ); |
|
4426 |
||
9 | 4427 |
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
|
4428 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 4429 |
} |
0 | 4430 |
|
4431 |
return $this->_prepare_post_type( $post_type, $fields ); |
|
4432 |
} |
|
4433 |
||
4434 |
/** |
|
4435 |
* Retrieves a post types |
|
4436 |
* |
|
4437 |
* @since 3.4.0 |
|
4438 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4439 |
* @see get_post_types() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4440 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4441 |
* @param array $args { |
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 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4449 |
* } |
5 | 4450 |
* @return array|IXR_Error |
0 | 4451 |
*/ |
5 | 4452 |
public function wp_getPostTypes( $args ) { |
9 | 4453 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4454 |
return $this->error; |
9 | 4455 |
} |
0 | 4456 |
|
4457 |
$this->escape( $args ); |
|
4458 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4459 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4460 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4461 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 4462 |
|
5 | 4463 |
if ( isset( $args[4] ) ) { |
0 | 4464 |
$fields = $args[4]; |
5 | 4465 |
} else { |
4466 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 4467 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
5 | 4468 |
} |
0 | 4469 |
|
9 | 4470 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4471 |
return $this->error; |
9 | 4472 |
} |
0 | 4473 |
|
5 | 4474 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4475 |
do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
4476 |
||
4477 |
$post_types = get_post_types( $filter, 'objects' ); |
|
4478 |
||
4479 |
$struct = array(); |
|
4480 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4481 |
foreach ( $post_types as $post_type ) { |
9 | 4482 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 4483 |
continue; |
9 | 4484 |
} |
4485 |
||
4486 |
$struct[ $post_type->name ] = $this->_prepare_post_type( $post_type, $fields ); |
|
0 | 4487 |
} |
4488 |
||
4489 |
return $struct; |
|
4490 |
} |
|
4491 |
||
4492 |
/** |
|
4493 |
* Retrieve revisions for a specific post. |
|
4494 |
* |
|
4495 |
* @since 3.5.0 |
|
4496 |
* |
|
4497 |
* The optional $fields parameter specifies what fields will be included |
|
4498 |
* in the response array. |
|
4499 |
* |
|
4500 |
* @uses wp_get_post_revisions() |
|
4501 |
* @see wp_getPost() for more on $fields |
|
4502 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4506 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4508 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4509 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4510 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4511 |
* } |
5 | 4512 |
* @return array|IXR_Error contains a collection of posts. |
0 | 4513 |
*/ |
5 | 4514 |
public function wp_getRevisions( $args ) { |
9 | 4515 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4516 |
return $this->error; |
9 | 4517 |
} |
0 | 4518 |
|
4519 |
$this->escape( $args ); |
|
4520 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4521 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4522 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4523 |
$post_id = (int) $args[3]; |
0 | 4524 |
|
5 | 4525 |
if ( isset( $args[4] ) ) { |
0 | 4526 |
$fields = $args[4]; |
5 | 4527 |
} else { |
4528 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4529 |
* Filters the default revision query fields used by the given XML-RPC method. |
5 | 4530 |
* |
4531 |
* @since 3.5.0 |
|
4532 |
* |
|
4533 |
* @param array $field An array of revision query fields. |
|
4534 |
* @param string $method The method name. |
|
4535 |
*/ |
|
0 | 4536 |
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
5 | 4537 |
} |
0 | 4538 |
|
9 | 4539 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4540 |
return $this->error; |
9 | 4541 |
} |
0 | 4542 |
|
5 | 4543 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4544 |
do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
4545 |
||
9 | 4546 |
if ( ! $post = get_post( $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4547 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4548 |
} |
4549 |
||
4550 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
0 | 4551 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4552 |
} |
0 | 4553 |
|
4554 |
// Check if revisions are enabled. |
|
9 | 4555 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4556 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4557 |
} |
0 | 4558 |
|
4559 |
$revisions = wp_get_post_revisions( $post_id ); |
|
4560 |
||
9 | 4561 |
if ( ! $revisions ) { |
0 | 4562 |
return array(); |
9 | 4563 |
} |
0 | 4564 |
|
4565 |
$struct = array(); |
|
4566 |
||
4567 |
foreach ( $revisions as $revision ) { |
|
9 | 4568 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
0 | 4569 |
continue; |
9 | 4570 |
} |
0 | 4571 |
|
4572 |
// Skip autosaves |
|
9 | 4573 |
if ( wp_is_post_autosave( $revision ) ) { |
0 | 4574 |
continue; |
9 | 4575 |
} |
0 | 4576 |
|
4577 |
$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); |
|
4578 |
} |
|
4579 |
||
4580 |
return $struct; |
|
4581 |
} |
|
4582 |
||
4583 |
/** |
|
4584 |
* Restore a post revision |
|
4585 |
* |
|
4586 |
* @since 3.5.0 |
|
4587 |
* |
|
4588 |
* @uses wp_restore_post_revision() |
|
4589 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4590 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4591 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4594 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4595 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4596 |
* @type int $revision_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4597 |
* } |
5 | 4598 |
* @return bool|IXR_Error false if there was an error restoring, true if success. |
0 | 4599 |
*/ |
5 | 4600 |
public function wp_restoreRevision( $args ) { |
9 | 4601 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4602 |
return $this->error; |
9 | 4603 |
} |
0 | 4604 |
|
4605 |
$this->escape( $args ); |
|
4606 |
||
4607 |
$username = $args[1]; |
|
4608 |
$password = $args[2]; |
|
4609 |
$revision_id = (int) $args[3]; |
|
4610 |
||
9 | 4611 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4612 |
return $this->error; |
9 | 4613 |
} |
0 | 4614 |
|
5 | 4615 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4616 |
do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
4617 |
||
9 | 4618 |
if ( ! $revision = wp_get_post_revision( $revision_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4619 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4620 |
} |
4621 |
||
4622 |
if ( wp_is_post_autosave( $revision ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4623 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4624 |
} |
4625 |
||
4626 |
if ( ! $post = get_post( $revision->post_parent ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4627 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4628 |
} |
4629 |
||
4630 |
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
|
4631 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4632 |
} |
0 | 4633 |
|
4634 |
// Check if revisions are disabled. |
|
9 | 4635 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4636 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4637 |
} |
0 | 4638 |
|
4639 |
$post = wp_restore_post_revision( $revision_id ); |
|
4640 |
||
4641 |
return (bool) $post; |
|
4642 |
} |
|
4643 |
||
4644 |
/* Blogger API functions. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4645 |
* specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
0 | 4646 |
*/ |
4647 |
||
4648 |
/** |
|
4649 |
* Retrieve blogs that user owns. |
|
4650 |
* |
|
4651 |
* Will make more sense once we support multiple blogs. |
|
4652 |
* |
|
4653 |
* @since 1.5.0 |
|
4654 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4655 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4656 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4657 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4658 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4659 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4660 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4661 |
* } |
5 | 4662 |
* @return array|IXR_Error |
0 | 4663 |
*/ |
9 | 4664 |
public function blogger_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4665 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4666 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4667 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4668 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4669 |
if ( is_multisite() ) { |
9 | 4670 |
return $this->_multisite_getUsersBlogs( $args ); |
4671 |
} |
|
4672 |
||
4673 |
$this->escape( $args ); |
|
0 | 4674 |
|
4675 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4676 |
$password = $args[2]; |
0 | 4677 |
|
9 | 4678 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4679 |
return $this->error; |
9 | 4680 |
} |
0 | 4681 |
|
5 | 4682 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4683 |
do_action( 'xmlrpc_call', 'blogger.getUsersBlogs' ); |
|
0 | 4684 |
|
9 | 4685 |
$is_admin = current_user_can( 'manage_options' ); |
0 | 4686 |
|
4687 |
$struct = array( |
|
4688 |
'isAdmin' => $is_admin, |
|
9 | 4689 |
'url' => get_option( 'home' ) . '/', |
0 | 4690 |
'blogid' => '1', |
9 | 4691 |
'blogName' => get_option( 'blogname' ), |
0 | 4692 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
4693 |
); |
|
4694 |
||
9 | 4695 |
return array( $struct ); |
0 | 4696 |
} |
4697 |
||
4698 |
/** |
|
4699 |
* Private function for retrieving a users blogs for multisite setups |
|
4700 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4701 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4702 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4703 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4704 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4705 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4706 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4707 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4708 |
* } |
5 | 4709 |
* @return array|IXR_Error |
0 | 4710 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4711 |
protected function _multisite_getUsersBlogs( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4712 |
$current_blog = get_site(); |
0 | 4713 |
|
4714 |
$domain = $current_blog->domain; |
|
9 | 4715 |
$path = $current_blog->path . 'xmlrpc.php'; |
0 | 4716 |
|
4717 |
$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) ); |
|
9 | 4718 |
$rpc->query( 'wp.getUsersBlogs', $args[1], $args[2] ); |
0 | 4719 |
$blogs = $rpc->getResponse(); |
4720 |
||
9 | 4721 |
if ( isset( $blogs['faultCode'] ) ) { |
4722 |
return new IXR_Error( $blogs['faultCode'], $blogs['faultString'] ); |
|
4723 |
} |
|
0 | 4724 |
|
4725 |
if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { |
|
4726 |
return $blogs; |
|
4727 |
} else { |
|
4728 |
foreach ( (array) $blogs as $blog ) { |
|
9 | 4729 |
if ( strpos( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { |
4730 |
return array( $blog ); |
|
4731 |
} |
|
0 | 4732 |
} |
4733 |
return array(); |
|
4734 |
} |
|
4735 |
} |
|
4736 |
||
4737 |
/** |
|
4738 |
* Retrieve user's data. |
|
4739 |
* |
|
4740 |
* Gives your client some info about you, so you don't have to. |
|
4741 |
* |
|
4742 |
* @since 1.5.0 |
|
4743 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4744 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4745 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4746 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4747 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4748 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4749 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4750 |
* } |
5 | 4751 |
* @return array|IXR_Error |
0 | 4752 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4753 |
public function blogger_getUserInfo( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4754 |
$this->escape( $args ); |
0 | 4755 |
|
4756 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4757 |
$password = $args[2]; |
0 | 4758 |
|
9 | 4759 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4760 |
return $this->error; |
9 | 4761 |
} |
4762 |
||
4763 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
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 access user data on this site.' ) ); |
9 | 4765 |
} |
0 | 4766 |
|
5 | 4767 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4768 |
do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
|
0 | 4769 |
|
4770 |
$struct = array( |
|
4771 |
'nickname' => $user->nickname, |
|
4772 |
'userid' => $user->ID, |
|
4773 |
'url' => $user->user_url, |
|
4774 |
'lastname' => $user->last_name, |
|
9 | 4775 |
'firstname' => $user->first_name, |
0 | 4776 |
); |
4777 |
||
4778 |
return $struct; |
|
4779 |
} |
|
4780 |
||
4781 |
/** |
|
4782 |
* Retrieve post. |
|
4783 |
* |
|
4784 |
* @since 1.5.0 |
|
4785 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4786 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4787 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4788 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4789 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4790 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4791 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4792 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4793 |
* } |
5 | 4794 |
* @return array|IXR_Error |
0 | 4795 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4796 |
public function blogger_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4797 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4798 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
$post_ID = (int) $args[1]; |
0 | 4800 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4801 |
$password = $args[3]; |
0 | 4802 |
|
9 | 4803 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4804 |
return $this->error; |
9 | 4805 |
} |
4806 |
||
4807 |
$post_data = get_post( $post_ID, ARRAY_A ); |
|
4808 |
if ( ! $post_data ) { |
|
0 | 4809 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4810 |
} |
4811 |
||
4812 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4813 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4814 |
} |
0 | 4815 |
|
5 | 4816 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4817 |
do_action( 'xmlrpc_call', 'blogger.getPost' ); |
|
0 | 4818 |
|
9 | 4819 |
$categories = implode( ',', wp_get_post_categories( $post_ID ) ); |
4820 |
||
4821 |
$content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
|
4822 |
$content .= '<category>' . $categories . '</category>'; |
|
4823 |
$content .= wp_unslash( $post_data['post_content'] ); |
|
0 | 4824 |
|
4825 |
$struct = array( |
|
9 | 4826 |
'userid' => $post_data['post_author'], |
0 | 4827 |
'dateCreated' => $this->_convert_date( $post_data['post_date'] ), |
4828 |
'content' => $content, |
|
9 | 4829 |
'postid' => (string) $post_data['ID'], |
0 | 4830 |
); |
4831 |
||
4832 |
return $struct; |
|
4833 |
} |
|
4834 |
||
4835 |
/** |
|
4836 |
* Retrieve list of recent posts. |
|
4837 |
* |
|
4838 |
* @since 1.5.0 |
|
4839 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4841 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4843 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4844 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4845 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4846 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4847 |
* @type int $numberposts (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4848 |
* } |
5 | 4849 |
* @return array|IXR_Error |
0 | 4850 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4851 |
public function blogger_getRecentPosts( $args ) { |
0 | 4852 |
|
9 | 4853 |
$this->escape( $args ); |
0 | 4854 |
|
4855 |
// $args[0] = appkey - ignored |
|
4856 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4857 |
$password = $args[3]; |
9 | 4858 |
if ( isset( $args[4] ) ) { |
0 | 4859 |
$query = array( 'numberposts' => absint( $args[4] ) ); |
9 | 4860 |
} else { |
0 | 4861 |
$query = array(); |
9 | 4862 |
} |
4863 |
||
4864 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4865 |
return $this->error; |
9 | 4866 |
} |
4867 |
||
4868 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4869 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4870 |
} |
0 | 4871 |
|
5 | 4872 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4873 |
do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
|
0 | 4874 |
|
4875 |
$posts_list = wp_get_recent_posts( $query ); |
|
4876 |
||
9 | 4877 |
if ( ! $posts_list ) { |
4878 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 4879 |
return $this->error; |
4880 |
} |
|
4881 |
||
5 | 4882 |
$recent_posts = array(); |
9 | 4883 |
foreach ( $posts_list as $entry ) { |
4884 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 4885 |
continue; |
9 | 4886 |
} |
0 | 4887 |
|
4888 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
9 | 4889 |
$categories = implode( ',', wp_get_post_categories( $entry['ID'] ) ); |
4890 |
||
4891 |
$content = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>'; |
|
4892 |
$content .= '<category>' . $categories . '</category>'; |
|
4893 |
$content .= wp_unslash( $entry['post_content'] ); |
|
0 | 4894 |
|
5 | 4895 |
$recent_posts[] = array( |
9 | 4896 |
'userid' => $entry['post_author'], |
0 | 4897 |
'dateCreated' => $post_date, |
9 | 4898 |
'content' => $content, |
4899 |
'postid' => (string) $entry['ID'], |
|
0 | 4900 |
); |
4901 |
} |
|
4902 |
||
4903 |
return $recent_posts; |
|
4904 |
} |
|
4905 |
||
4906 |
/** |
|
4907 |
* Deprecated. |
|
4908 |
* |
|
4909 |
* @since 1.5.0 |
|
4910 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4911 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4912 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4913 |
* @return IXR_Error Error object. |
0 | 4914 |
*/ |
9 | 4915 |
public function blogger_getTemplate( $args ) { |
4916 |
return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) ); |
|
0 | 4917 |
} |
4918 |
||
4919 |
/** |
|
4920 |
* Deprecated. |
|
4921 |
* |
|
4922 |
* @since 1.5.0 |
|
4923 |
* @deprecated 3.5.0 |
|
7
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 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4926 |
* @return IXR_Error Error object. |
0 | 4927 |
*/ |
9 | 4928 |
public function blogger_setTemplate( $args ) { |
4929 |
return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) ); |
|
0 | 4930 |
} |
4931 |
||
4932 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4933 |
* Creates new post. |
0 | 4934 |
* |
4935 |
* @since 1.5.0 |
|
4936 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4937 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4938 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4939 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4940 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4941 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4942 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4943 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4944 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4945 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4946 |
* } |
5 | 4947 |
* @return int|IXR_Error |
0 | 4948 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4949 |
public function blogger_newPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4950 |
$this->escape( $args ); |
0 | 4951 |
|
4952 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4953 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4954 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4955 |
$publish = $args[5]; |
0 | 4956 |
|
9 | 4957 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 4958 |
return $this->error; |
9 | 4959 |
} |
0 | 4960 |
|
5 | 4961 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4962 |
do_action( 'xmlrpc_call', 'blogger.newPost' ); |
|
0 | 4963 |
|
9 | 4964 |
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
4965 |
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
|
4966 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
|
4967 |
} |
|
4968 |
||
4969 |
$post_status = ( $publish ) ? 'publish' : 'draft'; |
|
0 | 4970 |
|
4971 |
$post_author = $user->ID; |
|
4972 |
||
9 | 4973 |
$post_title = xmlrpc_getposttitle( $content ); |
4974 |
$post_category = xmlrpc_getpostcategory( $content ); |
|
4975 |
$post_content = xmlrpc_removepostdata( $content ); |
|
4976 |
||
4977 |
$post_date = current_time( 'mysql' ); |
|
4978 |
$post_date_gmt = current_time( 'mysql', 1 ); |
|
4979 |
||
4980 |
$post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' ); |
|
4981 |
||
4982 |
$post_ID = wp_insert_post( $post_data ); |
|
4983 |
if ( is_wp_error( $post_ID ) ) { |
|
4984 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
4985 |
} |
|
4986 |
||
4987 |
if ( ! $post_ID ) { |
|
4988 |
return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) ); |
|
4989 |
} |
|
0 | 4990 |
|
4991 |
$this->attach_uploads( $post_ID, $post_content ); |
|
4992 |
||
5 | 4993 |
/** |
4994 |
* Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
4995 |
* |
|
4996 |
* @since 3.4.0 |
|
4997 |
* |
|
4998 |
* @param int $post_ID ID of the new post. |
|
4999 |
* @param array $args An array of new post arguments. |
|
5000 |
*/ |
|
0 | 5001 |
do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); |
5002 |
||
5003 |
return $post_ID; |
|
5004 |
} |
|
5005 |
||
5006 |
/** |
|
5007 |
* Edit a post. |
|
5008 |
* |
|
5009 |
* @since 1.5.0 |
|
5010 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5011 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5012 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5013 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5014 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5015 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5016 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5017 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5018 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5019 |
* @type bool $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5020 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5021 |
* @return true|IXR_Error true when done. |
0 | 5022 |
*/ |
5 | 5023 |
public function blogger_editPost( $args ) { |
0 | 5024 |
|
9 | 5025 |
$this->escape( $args ); |
0 | 5026 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5027 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5028 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5029 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5030 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5031 |
$publish = $args[5]; |
5 | 5032 |
|
5033 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 5034 |
return $this->error; |
5 | 5035 |
} |
5036 |
||
5037 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5038 |
do_action( 'xmlrpc_call', 'blogger.editPost' ); |
|
5039 |
||
5040 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
5041 |
||
5042 |
if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
|
5043 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
5044 |
} |
|
0 | 5045 |
|
9 | 5046 |
$this->escape( $actual_post ); |
0 | 5047 |
|
5 | 5048 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
9 | 5049 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5 | 5050 |
} |
5051 |
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
|
5052 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5053 |
} |
5054 |
||
9 | 5055 |
$postdata = array(); |
5056 |
$postdata['ID'] = $actual_post['ID']; |
|
5057 |
$postdata['post_content'] = xmlrpc_removepostdata( $content ); |
|
5058 |
$postdata['post_title'] = xmlrpc_getposttitle( $content ); |
|
5 | 5059 |
$postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
9 | 5060 |
$postdata['post_status'] = $actual_post['post_status']; |
5061 |
$postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
5062 |
$postdata['post_status'] = $publish ? 'publish' : 'draft'; |
|
5 | 5063 |
|
5064 |
$result = wp_update_post( $postdata ); |
|
5065 |
||
5066 |
if ( ! $result ) { |
|
9 | 5067 |
return new IXR_Error( 500, __( 'For some strange yet very annoying reason, this post could not be edited.' ) ); |
5 | 5068 |
} |
5069 |
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
|
5070 |
||
5071 |
/** |
|
5072 |
* Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
5073 |
* |
|
5074 |
* @since 3.4.0 |
|
5075 |
* |
|
5076 |
* @param int $post_ID ID of the updated post. |
|
5077 |
* @param array $args An array of arguments for the post to edit. |
|
5078 |
*/ |
|
0 | 5079 |
do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); |
5080 |
||
5081 |
return true; |
|
5082 |
} |
|
5083 |
||
5084 |
/** |
|
5085 |
* Remove a post. |
|
5086 |
* |
|
5087 |
* @since 1.5.0 |
|
5088 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5089 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5090 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5091 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5092 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5093 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5094 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5095 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5096 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5097 |
* @return true|IXR_Error True when post is deleted. |
0 | 5098 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5099 |
public function blogger_deletePost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5100 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5101 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5102 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5103 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5104 |
$password = $args[3]; |
0 | 5105 |
|
9 | 5106 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 5107 |
return $this->error; |
9 | 5108 |
} |
0 | 5109 |
|
5 | 5110 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5111 |
do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
|
0 | 5112 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5113 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5115 |
if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5116 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5117 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5118 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5119 |
if ( ! current_user_can( 'delete_post', $post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5120 |
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
|
5121 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5122 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5123 |
$result = wp_delete_post( $post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5125 |
if ( ! $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5126 |
return new IXR_Error( 500, __( 'The post cannot be deleted.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5127 |
} |
0 | 5128 |
|
5 | 5129 |
/** |
5130 |
* Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
|
5131 |
* |
|
5132 |
* @since 3.4.0 |
|
5133 |
* |
|
5134 |
* @param int $post_ID ID of the deleted post. |
|
5135 |
* @param array $args An array of arguments to delete the post. |
|
5136 |
*/ |
|
0 | 5137 |
do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); |
5138 |
||
5139 |
return true; |
|
5140 |
} |
|
5141 |
||
5142 |
/* MetaWeblog API functions |
|
5143 |
* specs on wherever Dave Winer wants them to be |
|
5144 |
*/ |
|
5145 |
||
5146 |
/** |
|
5147 |
* Create a new post. |
|
5148 |
* |
|
5149 |
* The 'content_struct' argument must contain: |
|
5150 |
* - title |
|
5151 |
* - description |
|
5152 |
* - mt_excerpt |
|
5153 |
* - mt_text_more |
|
5154 |
* - mt_keywords |
|
5155 |
* - mt_tb_ping_urls |
|
5156 |
* - categories |
|
5157 |
* |
|
5158 |
* Also, it can optionally contain: |
|
5159 |
* - wp_slug |
|
5160 |
* - wp_password |
|
5161 |
* - wp_page_parent_id |
|
5162 |
* - wp_page_order |
|
5163 |
* - wp_author_id |
|
5164 |
* - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' |
|
5165 |
* - mt_allow_comments - can be 'open' or 'closed' |
|
5166 |
* - mt_allow_pings - can be 'open' or 'closed' |
|
5167 |
* - date_created_gmt |
|
5168 |
* - dateCreated |
|
5169 |
* - wp_post_thumbnail |
|
5170 |
* |
|
5171 |
* @since 1.5.0 |
|
5172 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5173 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5174 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5175 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5176 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5177 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5178 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5179 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5180 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5181 |
* } |
5 | 5182 |
* @return int|IXR_Error |
0 | 5183 |
*/ |
9 | 5184 |
public function mw_newPost( $args ) { |
5185 |
$this->escape( $args ); |
|
0 | 5186 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5187 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5188 |
$password = $args[2]; |
0 | 5189 |
$content_struct = $args[3]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5190 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
0 | 5191 |
|
9 | 5192 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 5193 |
return $this->error; |
9 | 5194 |
} |
0 | 5195 |
|
5 | 5196 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5197 |
do_action( 'xmlrpc_call', 'metaWeblog.newPost' ); |
|
0 | 5198 |
|
5199 |
$page_template = ''; |
|
9 | 5200 |
if ( ! empty( $content_struct['post_type'] ) ) { |
0 | 5201 |
if ( $content_struct['post_type'] == 'page' ) { |
9 | 5202 |
if ( $publish ) { |
5203 |
$cap = 'publish_pages'; |
|
5204 |
} elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] ) { |
|
5205 |
$cap = 'publish_pages'; |
|
5206 |
} else { |
|
0 | 5207 |
$cap = 'edit_pages'; |
9 | 5208 |
} |
0 | 5209 |
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' ); |
9 | 5210 |
$post_type = 'page'; |
5211 |
if ( ! empty( $content_struct['wp_page_template'] ) ) { |
|
0 | 5212 |
$page_template = $content_struct['wp_page_template']; |
9 | 5213 |
} |
0 | 5214 |
} elseif ( $content_struct['post_type'] == 'post' ) { |
9 | 5215 |
if ( $publish ) { |
5216 |
$cap = 'publish_posts'; |
|
5217 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) { |
|
5218 |
$cap = 'publish_posts'; |
|
5219 |
} else { |
|
0 | 5220 |
$cap = 'edit_posts'; |
9 | 5221 |
} |
0 | 5222 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5223 |
$post_type = 'post'; |
0 | 5224 |
} else { |
5225 |
// No other post_type values are allowed here |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5226 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5227 |
} |
5228 |
} else { |
|
9 | 5229 |
if ( $publish ) { |
5230 |
$cap = 'publish_posts'; |
|
5231 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) { |
|
5232 |
$cap = 'publish_posts'; |
|
5233 |
} else { |
|
0 | 5234 |
$cap = 'edit_posts'; |
9 | 5235 |
} |
0 | 5236 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5237 |
$post_type = 'post'; |
5238 |
} |
|
5239 |
||
5240 |
if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) { |
|
0 | 5241 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) ); |
9 | 5242 |
} |
5243 |
if ( ! current_user_can( $cap ) ) { |
|
0 | 5244 |
return new IXR_Error( 401, $error_message ); |
9 | 5245 |
} |
0 | 5246 |
|
5247 |
// Check for a valid post format if one was given |
|
5248 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
|
5249 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5250 |
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
|
5251 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5252 |
} |
5253 |
} |
|
5254 |
||
5255 |
// Let WordPress generate the post_name (slug) unless |
|
5256 |
// one has been provided. |
|
9 | 5257 |
$post_name = ''; |
5258 |
if ( isset( $content_struct['wp_slug'] ) ) { |
|
0 | 5259 |
$post_name = $content_struct['wp_slug']; |
9 | 5260 |
} |
0 | 5261 |
|
5262 |
// Only use a password if one was given. |
|
9 | 5263 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5264 |
$post_password = $content_struct['wp_password']; |
9 | 5265 |
} else { |
5266 |
$post_password = ''; |
|
5267 |
} |
|
0 | 5268 |
|
5269 |
// Only set a post parent if one was provided. |
|
9 | 5270 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5271 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5272 |
} else { |
5273 |
$post_parent = 0; |
|
5274 |
} |
|
0 | 5275 |
|
5276 |
// Only set the menu_order if it was provided. |
|
9 | 5277 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5278 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5279 |
} else { |
5280 |
$menu_order = 0; |
|
5281 |
} |
|
0 | 5282 |
|
5283 |
$post_author = $user->ID; |
|
5284 |
||
5285 |
// If an author id was provided then use it instead. |
|
5286 |
if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
|
5287 |
switch ( $post_type ) { |
|
9 | 5288 |
case 'post': |
5289 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5290 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 5291 |
} |
0 | 5292 |
break; |
9 | 5293 |
case 'page': |
5294 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5295 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
9 | 5296 |
} |
0 | 5297 |
break; |
5298 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5299 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5300 |
} |
5301 |
$author = get_userdata( $content_struct['wp_author_id'] ); |
|
9 | 5302 |
if ( ! $author ) { |
0 | 5303 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 5304 |
} |
0 | 5305 |
$post_author = $content_struct['wp_author_id']; |
5306 |
} |
|
5307 |
||
9 | 5308 |
$post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; |
0 | 5309 |
$post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null; |
5310 |
||
5311 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5312 |
||
9 | 5313 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5314 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5315 |
case 'draft': |
5316 |
case 'pending': |
|
5317 |
case 'private': |
|
5318 |
case 'publish': |
|
9 | 5319 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5320 |
break; |
5321 |
default: |
|
5322 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5323 |
break; |
|
5324 |
} |
|
5325 |
} |
|
5326 |
||
9 | 5327 |
$post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : null; |
5328 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5329 |
||
5330 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5331 |
||
5332 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
|
5333 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5334 |
switch ( $content_struct['mt_allow_comments'] ) { |
5335 |
case 'closed': |
|
5336 |
$comment_status = 'closed'; |
|
5337 |
break; |
|
5338 |
case 'open': |
|
5339 |
$comment_status = 'open'; |
|
5340 |
break; |
|
5341 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5342 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5343 |
break; |
5344 |
} |
|
5345 |
} else { |
|
5346 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5347 |
case 0: |
|
5348 |
case 2: |
|
5349 |
$comment_status = 'closed'; |
|
5350 |
break; |
|
5351 |
case 1: |
|
5352 |
$comment_status = 'open'; |
|
5353 |
break; |
|
5354 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5355 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5356 |
break; |
5357 |
} |
|
5358 |
} |
|
5359 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5360 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5361 |
} |
5362 |
||
9 | 5363 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5364 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5365 |
switch ( $content_struct['mt_allow_pings'] ) { |
5366 |
case 'closed': |
|
5367 |
$ping_status = 'closed'; |
|
5368 |
break; |
|
5369 |
case 'open': |
|
5370 |
$ping_status = 'open'; |
|
5371 |
break; |
|
5372 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5373 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5374 |
break; |
5375 |
} |
|
5376 |
} else { |
|
5377 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
|
5378 |
case 0: |
|
5379 |
$ping_status = 'closed'; |
|
5380 |
break; |
|
5381 |
case 1: |
|
5382 |
$ping_status = 'open'; |
|
5383 |
break; |
|
5384 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5385 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5386 |
break; |
5387 |
} |
|
5388 |
} |
|
5389 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5390 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5391 |
} |
5392 |
||
9 | 5393 |
if ( $post_more ) { |
0 | 5394 |
$post_content = $post_content . '<!--more-->' . $post_more; |
9 | 5395 |
} |
0 | 5396 |
|
5397 |
$to_ping = null; |
|
5398 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5399 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5400 |
if ( is_array( $to_ping ) ) { |
5401 |
$to_ping = implode( ' ', $to_ping ); |
|
5402 |
} |
|
0 | 5403 |
} |
5404 |
||
5405 |
// Do some timestamp voodoo |
|
9 | 5406 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
0 | 5407 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force |
5408 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
|
9 | 5409 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5410 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5411 |
} |
5412 |
||
5413 |
if ( ! empty( $dateCreated ) ) { |
|
5414 |
$post_date = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
|
5415 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' ); |
|
0 | 5416 |
} else { |
9 | 5417 |
$post_date = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5418 |
$post_date_gmt = ''; |
0 | 5419 |
} |
5420 |
||
5421 |
$post_category = array(); |
|
5422 |
if ( isset( $content_struct['categories'] ) ) { |
|
5423 |
$catnames = $content_struct['categories']; |
|
5424 |
||
9 | 5425 |
if ( is_array( $catnames ) ) { |
5426 |
foreach ( $catnames as $cat ) { |
|
5427 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5428 |
} |
5429 |
} |
|
5430 |
} |
|
5431 |
||
9 | 5432 |
$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 | 5433 |
|
5434 |
$post_ID = $postdata['ID'] = get_default_post_to_edit( $post_type, true )->ID; |
|
5435 |
||
5436 |
// Only posts can be sticky |
|
5437 |
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
|
9 | 5438 |
$data = $postdata; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5439 |
$data['sticky'] = $content_struct['sticky']; |
9 | 5440 |
$error = $this->_toggle_sticky( $data ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5441 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5442 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5443 |
} |
0 | 5444 |
} |
5445 |
||
9 | 5446 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5447 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5448 |
} |
|
5449 |
||
5450 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
5451 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
|
0 | 5452 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5453 |
} |
0 | 5454 |
|
5455 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5456 |
} |
|
5457 |
||
5458 |
// Handle enclosures |
|
9 | 5459 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5460 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5461 |
|
5462 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5463 |
||
5464 |
// Handle post formats if assigned, value is validated earlier |
|
5465 |
// in this function |
|
9 | 5466 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 5467 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 5468 |
} |
0 | 5469 |
|
5470 |
$post_ID = wp_insert_post( $postdata, true ); |
|
9 | 5471 |
if ( is_wp_error( $post_ID ) ) { |
5472 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
5473 |
} |
|
5474 |
||
5475 |
if ( ! $post_ID ) { |
|
5476 |
return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) ); |
|
5477 |
} |
|
0 | 5478 |
|
5 | 5479 |
/** |
5480 |
* Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
5481 |
* |
|
5482 |
* @since 3.4.0 |
|
5483 |
* |
|
5484 |
* @param int $post_ID ID of the new post. |
|
5485 |
* @param array $args An array of arguments to create the new post. |
|
5486 |
*/ |
|
0 | 5487 |
do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); |
5488 |
||
9 | 5489 |
return strval( $post_ID ); |
0 | 5490 |
} |
5491 |
||
5 | 5492 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5493 |
* 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
|
5494 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5495 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5496 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5497 |
* @param integer $post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5498 |
* @param array $enclosure Enclosure data. |
5 | 5499 |
*/ |
5500 |
public function add_enclosure_if_new( $post_ID, $enclosure ) { |
|
0 | 5501 |
if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
5502 |
$encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
|
9 | 5503 |
$found = false; |
0 | 5504 |
if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) { |
5505 |
foreach ( $enclosures as $enc ) { |
|
5506 |
// This method used to omit the trailing new line. #23219 |
|
5507 |
if ( rtrim( $enc, "\n" ) == rtrim( $encstring, "\n" ) ) { |
|
5508 |
$found = true; |
|
5509 |
break; |
|
5510 |
} |
|
5511 |
} |
|
5512 |
} |
|
9 | 5513 |
if ( ! $found ) { |
0 | 5514 |
add_post_meta( $post_ID, 'enclosure', $encstring ); |
9 | 5515 |
} |
0 | 5516 |
} |
5517 |
} |
|
5518 |
||
5519 |
/** |
|
5520 |
* Attach upload to a post. |
|
5521 |
* |
|
5522 |
* @since 2.1.0 |
|
5523 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5524 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5525 |
* |
0 | 5526 |
* @param int $post_ID Post ID. |
5527 |
* @param string $post_content Post Content for attachment. |
|
5528 |
*/ |
|
5 | 5529 |
public function attach_uploads( $post_ID, $post_content ) { |
0 | 5530 |
global $wpdb; |
5531 |
||
5532 |
// find any unattached files |
|
5533 |
$attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); |
|
5534 |
if ( is_array( $attachments ) ) { |
|
5535 |
foreach ( $attachments as $file ) { |
|
9 | 5536 |
if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { |
5537 |
$wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); |
|
5538 |
} |
|
0 | 5539 |
} |
5540 |
} |
|
5541 |
} |
|
5542 |
||
5543 |
/** |
|
5544 |
* Edit a post. |
|
5545 |
* |
|
5546 |
* @since 1.5.0 |
|
5547 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5548 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5549 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5550 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5551 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5552 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5553 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5554 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5555 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5556 |
* } |
5 | 5557 |
* @return bool|IXR_Error True on success. |
0 | 5558 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5559 |
public function mw_editPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5560 |
$this->escape( $args ); |
0 | 5561 |
|
5562 |
$post_ID = (int) $args[0]; |
|
5563 |
$username = $args[1]; |
|
5564 |
$password = $args[2]; |
|
5565 |
$content_struct = $args[3]; |
|
5566 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
|
5567 |
||
9 | 5568 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 5569 |
return $this->error; |
9 | 5570 |
} |
0 | 5571 |
|
5 | 5572 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5573 |
do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
|
0 | 5574 |
|
5575 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5576 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5577 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5578 |
* If there is no post data for the give post id, stop now and return an error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5579 |
* 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
|
5580 |
*/ |
9 | 5581 |
if ( ! $postdata || empty( $postdata['ID'] ) ) { |
0 | 5582 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5583 |
} |
5584 |
||
5585 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5586 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5587 |
} |
0 | 5588 |
|
5589 |
// Use wp.editPost to edit post types other than post and page. |
|
9 | 5590 |
if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ) ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5591 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
9 | 5592 |
} |
0 | 5593 |
|
5594 |
// Thwart attempt to change the post type. |
|
9 | 5595 |
if ( ! empty( $content_struct['post_type'] ) && ( $content_struct['post_type'] != $postdata['post_type'] ) ) { |
0 | 5596 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 5597 |
} |
0 | 5598 |
|
5599 |
// Check for a valid post format if one was given |
|
5600 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
|
5601 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5602 |
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
|
5603 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5604 |
} |
5605 |
} |
|
5606 |
||
9 | 5607 |
$this->escape( $postdata ); |
5608 |
||
5609 |
$ID = $postdata['ID']; |
|
5610 |
$post_content = $postdata['post_content']; |
|
5611 |
$post_title = $postdata['post_title']; |
|
5612 |
$post_excerpt = $postdata['post_excerpt']; |
|
5613 |
$post_password = $postdata['post_password']; |
|
5614 |
$post_parent = $postdata['post_parent']; |
|
5615 |
$post_type = $postdata['post_type']; |
|
5616 |
$menu_order = $postdata['menu_order']; |
|
5617 |
$ping_status = $postdata['ping_status']; |
|
5618 |
$comment_status = $postdata['comment_status']; |
|
0 | 5619 |
|
5620 |
// Let WordPress manage slug if none was provided. |
|
5621 |
$post_name = $postdata['post_name']; |
|
9 | 5622 |
if ( isset( $content_struct['wp_slug'] ) ) { |
0 | 5623 |
$post_name = $content_struct['wp_slug']; |
9 | 5624 |
} |
0 | 5625 |
|
5626 |
// Only use a password if one was given. |
|
9 | 5627 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5628 |
$post_password = $content_struct['wp_password']; |
9 | 5629 |
} |
0 | 5630 |
|
5631 |
// Only set a post parent if one was given. |
|
9 | 5632 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5633 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5634 |
} |
0 | 5635 |
|
5636 |
// Only set the menu_order if it was given. |
|
9 | 5637 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5638 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5639 |
} |
0 | 5640 |
|
5 | 5641 |
$page_template = null; |
9 | 5642 |
if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) { |
0 | 5643 |
$page_template = $content_struct['wp_page_template']; |
9 | 5644 |
} |
0 | 5645 |
|
5646 |
$post_author = $postdata['post_author']; |
|
5647 |
||
5648 |
// Only set the post_author if one is set. |
|
5 | 5649 |
if ( isset( $content_struct['wp_author_id'] ) ) { |
5650 |
// Check permissions if attempting to switch author to or from another user. |
|
5651 |
if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) { |
|
5652 |
switch ( $post_type ) { |
|
5653 |
case 'post': |
|
5654 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5655 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the post author as this user.' ) ); |
5 | 5656 |
} |
5657 |
break; |
|
5658 |
case 'page': |
|
5659 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5660 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the page author as this user.' ) ); |
5 | 5661 |
} |
5662 |
break; |
|
5663 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5664 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
5 | 5665 |
} |
5666 |
$post_author = $content_struct['wp_author_id']; |
|
0 | 5667 |
} |
5668 |
} |
|
5669 |
||
9 | 5670 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
5671 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5672 |
switch ( $content_struct['mt_allow_comments'] ) { |
5673 |
case 'closed': |
|
5674 |
$comment_status = 'closed'; |
|
5675 |
break; |
|
5676 |
case 'open': |
|
5677 |
$comment_status = 'open'; |
|
5678 |
break; |
|
5679 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5680 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5681 |
break; |
5682 |
} |
|
5683 |
} else { |
|
5684 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5685 |
case 0: |
|
5686 |
case 2: |
|
5687 |
$comment_status = 'closed'; |
|
5688 |
break; |
|
5689 |
case 1: |
|
5690 |
$comment_status = 'open'; |
|
5691 |
break; |
|
5692 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5693 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5694 |
break; |
5695 |
} |
|
5696 |
} |
|
5697 |
} |
|
5698 |
||
9 | 5699 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5700 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5701 |
switch ( $content_struct['mt_allow_pings'] ) { |
5702 |
case 'closed': |
|
5703 |
$ping_status = 'closed'; |
|
5704 |
break; |
|
5705 |
case 'open': |
|
5706 |
$ping_status = 'open'; |
|
5707 |
break; |
|
5708 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5709 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5710 |
break; |
5711 |
} |
|
5712 |
} else { |
|
9 | 5713 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
0 | 5714 |
case 0: |
5715 |
$ping_status = 'closed'; |
|
5716 |
break; |
|
5717 |
case 1: |
|
5718 |
$ping_status = 'open'; |
|
5719 |
break; |
|
5720 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5721 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5722 |
break; |
5723 |
} |
|
5724 |
} |
|
5725 |
} |
|
5726 |
||
9 | 5727 |
if ( isset( $content_struct['title'] ) ) { |
5728 |
$post_title = $content_struct['title']; |
|
5729 |
} |
|
5730 |
||
5731 |
if ( isset( $content_struct['description'] ) ) { |
|
0 | 5732 |
$post_content = $content_struct['description']; |
9 | 5733 |
} |
0 | 5734 |
|
5735 |
$post_category = array(); |
|
5736 |
if ( isset( $content_struct['categories'] ) ) { |
|
5737 |
$catnames = $content_struct['categories']; |
|
9 | 5738 |
if ( is_array( $catnames ) ) { |
5739 |
foreach ( $catnames as $cat ) { |
|
5740 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5741 |
} |
5742 |
} |
|
5743 |
} |
|
5744 |
||
9 | 5745 |
if ( isset( $content_struct['mt_excerpt'] ) ) { |
5746 |
$post_excerpt = $content_struct['mt_excerpt']; |
|
5747 |
} |
|
0 | 5748 |
|
5749 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5750 |
||
5751 |
$post_status = $publish ? 'publish' : 'draft'; |
|
9 | 5752 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5753 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5754 |
case 'draft': |
5755 |
case 'pending': |
|
5756 |
case 'private': |
|
5757 |
case 'publish': |
|
9 | 5758 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5759 |
break; |
5760 |
default: |
|
5761 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5762 |
break; |
|
5763 |
} |
|
5764 |
} |
|
5765 |
||
5766 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5767 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5768 |
if ( 'publish' == $post_status || 'private' == $post_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5769 |
if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5770 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) ); |
5 | 5771 |
} elseif ( ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5772 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5773 |
} |
0 | 5774 |
} |
5775 |
||
9 | 5776 |
if ( $post_more ) { |
5777 |
$post_content = $post_content . '<!--more-->' . $post_more; |
|
5778 |
} |
|
0 | 5779 |
|
5780 |
$to_ping = null; |
|
5781 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5782 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5783 |
if ( is_array( $to_ping ) ) { |
5784 |
$to_ping = implode( ' ', $to_ping ); |
|
5785 |
} |
|
0 | 5786 |
} |
5787 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5788 |
// Do some timestamp voodoo. |
9 | 5789 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5790 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5791 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5792 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
0 | 5793 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
9 | 5794 |
} |
0 | 5795 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5796 |
// 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
|
5797 |
$edit_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5798 |
|
9 | 5799 |
if ( ! empty( $dateCreated ) ) { |
5800 |
$post_date = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
|
5801 |
$post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5802 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5803 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5804 |
$edit_date = true; |
0 | 5805 |
} else { |
5806 |
$post_date = $postdata['post_date']; |
|
5807 |
$post_date_gmt = $postdata['post_date_gmt']; |
|
5808 |
} |
|
5809 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5810 |
// We've got all the data -- post it. |
9 | 5811 |
$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' ); |
5812 |
||
5813 |
$result = wp_update_post( $newpost, true ); |
|
5814 |
if ( is_wp_error( $result ) ) { |
|
5815 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
5816 |
} |
|
5817 |
||
5818 |
if ( ! $result ) { |
|
5819 |
return new IXR_Error( 500, __( 'Sorry, your entry could not be edited.' ) ); |
|
5820 |
} |
|
0 | 5821 |
|
5822 |
// Only posts can be sticky |
|
5823 |
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
|
9 | 5824 |
$data = $newpost; |
5825 |
$data['sticky'] = $content_struct['sticky']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5826 |
$data['post_type'] = 'post'; |
9 | 5827 |
$error = $this->_toggle_sticky( $data, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5828 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5829 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5830 |
} |
0 | 5831 |
} |
5832 |
||
9 | 5833 |
if ( isset( $content_struct['custom_fields'] ) ) { |
5834 |
$this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); |
|
5835 |
} |
|
5836 |
||
5837 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5838 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5839 |
// Empty value deletes, non-empty value adds/updates. |
0 | 5840 |
if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
5841 |
delete_post_thumbnail( $post_ID ); |
|
5842 |
} else { |
|
9 | 5843 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { |
0 | 5844 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5845 |
} |
0 | 5846 |
} |
5847 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5848 |
} |
|
5849 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5850 |
// Handle enclosures. |
9 | 5851 |
$thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
5852 |
$this->add_enclosure_if_new( $post_ID, $thisEnclosure ); |
|
0 | 5853 |
|
5854 |
$this->attach_uploads( $ID, $post_content ); |
|
5855 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5856 |
// Handle post formats if assigned, validation is handled earlier in this function. |
9 | 5857 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
0 | 5858 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
9 | 5859 |
} |
0 | 5860 |
|
5 | 5861 |
/** |
5862 |
* Fires after a post has been successfully updated via the XML-RPC MovableType API. |
|
5863 |
* |
|
5864 |
* @since 3.4.0 |
|
5865 |
* |
|
5866 |
* @param int $post_ID ID of the updated post. |
|
5867 |
* @param array $args An array of arguments to update the post. |
|
5868 |
*/ |
|
0 | 5869 |
do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); |
5870 |
||
5871 |
return true; |
|
5872 |
} |
|
5873 |
||
5874 |
/** |
|
5875 |
* Retrieve post. |
|
5876 |
* |
|
5877 |
* @since 1.5.0 |
|
5878 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5879 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5880 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5881 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5882 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5883 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5884 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5885 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5886 |
* } |
5 | 5887 |
* @return array|IXR_Error |
0 | 5888 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5889 |
public function mw_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5890 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5891 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5892 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5893 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5894 |
$password = $args[2]; |
0 | 5895 |
|
9 | 5896 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 5897 |
return $this->error; |
9 | 5898 |
} |
5899 |
||
5900 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5901 |
if ( ! $postdata ) { |
|
0 | 5902 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5903 |
} |
5904 |
||
5905 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5906 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5907 |
} |
0 | 5908 |
|
5 | 5909 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5910 |
do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
|
0 | 5911 |
|
9 | 5912 |
if ( $postdata['post_date'] != '' ) { |
5913 |
$post_date = $this->_convert_date( $postdata['post_date'] ); |
|
5914 |
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
|
5915 |
$post_modified = $this->_convert_date( $postdata['post_modified'] ); |
|
0 | 5916 |
$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); |
5917 |
||
5918 |
$categories = array(); |
|
9 | 5919 |
$catids = wp_get_post_categories( $post_ID ); |
5920 |
foreach ( $catids as $catid ) { |
|
5921 |
$categories[] = get_cat_name( $catid ); |
|
5922 |
} |
|
0 | 5923 |
|
5924 |
$tagnames = array(); |
|
9 | 5925 |
$tags = wp_get_post_tags( $post_ID ); |
5926 |
if ( ! empty( $tags ) ) { |
|
5927 |
foreach ( $tags as $tag ) { |
|
0 | 5928 |
$tagnames[] = $tag->name; |
9 | 5929 |
} |
0 | 5930 |
$tagnames = implode( ', ', $tagnames ); |
5931 |
} else { |
|
5932 |
$tagnames = ''; |
|
5933 |
} |
|
5934 |
||
9 | 5935 |
$post = get_extended( $postdata['post_content'] ); |
5936 |
$link = get_permalink( $postdata['ID'] ); |
|
0 | 5937 |
|
5938 |
// Get the author info. |
|
9 | 5939 |
$author = get_userdata( $postdata['post_author'] ); |
5940 |
||
5941 |
$allow_comments = ( 'open' == $postdata['comment_status'] ) ? 1 : 0; |
|
5942 |
$allow_pings = ( 'open' == $postdata['ping_status'] ) ? 1 : 0; |
|
0 | 5943 |
|
5944 |
// Consider future posts as published |
|
9 | 5945 |
if ( $postdata['post_status'] === 'future' ) { |
0 | 5946 |
$postdata['post_status'] = 'publish'; |
9 | 5947 |
} |
0 | 5948 |
|
5949 |
// Get post format |
|
5950 |
$post_format = get_post_format( $post_ID ); |
|
9 | 5951 |
if ( empty( $post_format ) ) { |
0 | 5952 |
$post_format = 'standard'; |
9 | 5953 |
} |
0 | 5954 |
|
5955 |
$sticky = false; |
|
9 | 5956 |
if ( is_sticky( $post_ID ) ) { |
0 | 5957 |
$sticky = true; |
9 | 5958 |
} |
0 | 5959 |
|
5960 |
$enclosure = array(); |
|
9 | 5961 |
foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) { |
5962 |
if ( $key == 'enclosure' ) { |
|
0 | 5963 |
foreach ( (array) $val as $enc ) { |
9 | 5964 |
$encdata = explode( "\n", $enc ); |
5965 |
$enclosure['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
5966 |
$enclosure['length'] = (int) trim( $encdata[1] ); |
|
5967 |
$enclosure['type'] = trim( $encdata[2] ); |
|
0 | 5968 |
break 2; |
5969 |
} |
|
5970 |
} |
|
5971 |
} |
|
5972 |
||
5973 |
$resp = array( |
|
9 | 5974 |
'dateCreated' => $post_date, |
5975 |
'userid' => $postdata['post_author'], |
|
5976 |
'postid' => $postdata['ID'], |
|
5977 |
'description' => $post['main'], |
|
5978 |
'title' => $postdata['post_title'], |
|
5979 |
'link' => $link, |
|
5980 |
'permaLink' => $link, |
|
0 | 5981 |
// commented out because no other tool seems to use this |
5982 |
// 'content' => $entry['post_content'], |
|
9 | 5983 |
'categories' => $categories, |
5984 |
'mt_excerpt' => $postdata['post_excerpt'], |
|
5985 |
'mt_text_more' => $post['extended'], |
|
5986 |
'wp_more_text' => $post['more_text'], |
|
5987 |
'mt_allow_comments' => $allow_comments, |
|
5988 |
'mt_allow_pings' => $allow_pings, |
|
5989 |
'mt_keywords' => $tagnames, |
|
5990 |
'wp_slug' => $postdata['post_name'], |
|
5991 |
'wp_password' => $postdata['post_password'], |
|
5992 |
'wp_author_id' => (string) $author->ID, |
|
0 | 5993 |
'wp_author_display_name' => $author->display_name, |
9 | 5994 |
'date_created_gmt' => $post_date_gmt, |
5995 |
'post_status' => $postdata['post_status'], |
|
5996 |
'custom_fields' => $this->get_custom_fields( $post_ID ), |
|
5997 |
'wp_post_format' => $post_format, |
|
5998 |
'sticky' => $sticky, |
|
5999 |
'date_modified' => $post_modified, |
|
6000 |
'date_modified_gmt' => $post_modified_gmt, |
|
0 | 6001 |
); |
6002 |
||
9 | 6003 |
if ( ! empty( $enclosure ) ) { |
6004 |
$resp['enclosure'] = $enclosure; |
|
6005 |
} |
|
0 | 6006 |
|
6007 |
$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] ); |
|
6008 |
||
6009 |
return $resp; |
|
6010 |
} else { |
|
9 | 6011 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
0 | 6012 |
} |
6013 |
} |
|
6014 |
||
6015 |
/** |
|
6016 |
* Retrieve list of recent posts. |
|
6017 |
* |
|
6018 |
* @since 1.5.0 |
|
6019 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6020 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6021 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6022 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6023 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6024 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6025 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6026 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6027 |
* } |
5 | 6028 |
* @return array|IXR_Error |
0 | 6029 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6030 |
public function mw_getRecentPosts( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6031 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6032 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6033 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6034 |
$password = $args[2]; |
9 | 6035 |
if ( isset( $args[3] ) ) { |
0 | 6036 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6037 |
} else { |
0 | 6038 |
$query = array(); |
9 | 6039 |
} |
6040 |
||
6041 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 6042 |
return $this->error; |
9 | 6043 |
} |
6044 |
||
6045 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6046 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 6047 |
} |
0 | 6048 |
|
5 | 6049 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6050 |
do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
|
0 | 6051 |
|
6052 |
$posts_list = wp_get_recent_posts( $query ); |
|
6053 |
||
9 | 6054 |
if ( ! $posts_list ) { |
0 | 6055 |
return array(); |
9 | 6056 |
} |
0 | 6057 |
|
5 | 6058 |
$recent_posts = array(); |
9 | 6059 |
foreach ( $posts_list as $entry ) { |
6060 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6061 |
continue; |
9 | 6062 |
} |
6063 |
||
6064 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
6065 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
6066 |
$post_modified = $this->_convert_date( $entry['post_modified'] ); |
|
0 | 6067 |
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] ); |
6068 |
||
6069 |
$categories = array(); |
|
9 | 6070 |
$catids = wp_get_post_categories( $entry['ID'] ); |
6071 |
foreach ( $catids as $catid ) { |
|
6072 |
$categories[] = get_cat_name( $catid ); |
|
6073 |
} |
|
0 | 6074 |
|
6075 |
$tagnames = array(); |
|
9 | 6076 |
$tags = wp_get_post_tags( $entry['ID'] ); |
6077 |
if ( ! empty( $tags ) ) { |
|
0 | 6078 |
foreach ( $tags as $tag ) { |
6079 |
$tagnames[] = $tag->name; |
|
6080 |
} |
|
6081 |
$tagnames = implode( ', ', $tagnames ); |
|
6082 |
} else { |
|
6083 |
$tagnames = ''; |
|
6084 |
} |
|
6085 |
||
9 | 6086 |
$post = get_extended( $entry['post_content'] ); |
6087 |
$link = get_permalink( $entry['ID'] ); |
|
0 | 6088 |
|
6089 |
// Get the post author info. |
|
9 | 6090 |
$author = get_userdata( $entry['post_author'] ); |
6091 |
||
6092 |
$allow_comments = ( 'open' == $entry['comment_status'] ) ? 1 : 0; |
|
6093 |
$allow_pings = ( 'open' == $entry['ping_status'] ) ? 1 : 0; |
|
0 | 6094 |
|
6095 |
// Consider future posts as published |
|
9 | 6096 |
if ( $entry['post_status'] === 'future' ) { |
0 | 6097 |
$entry['post_status'] = 'publish'; |
9 | 6098 |
} |
0 | 6099 |
|
6100 |
// Get post format |
|
6101 |
$post_format = get_post_format( $entry['ID'] ); |
|
9 | 6102 |
if ( empty( $post_format ) ) { |
0 | 6103 |
$post_format = 'standard'; |
9 | 6104 |
} |
0 | 6105 |
|
5 | 6106 |
$recent_posts[] = array( |
9 | 6107 |
'dateCreated' => $post_date, |
6108 |
'userid' => $entry['post_author'], |
|
6109 |
'postid' => (string) $entry['ID'], |
|
6110 |
'description' => $post['main'], |
|
6111 |
'title' => $entry['post_title'], |
|
6112 |
'link' => $link, |
|
6113 |
'permaLink' => $link, |
|
0 | 6114 |
// commented out because no other tool seems to use this |
6115 |
// 'content' => $entry['post_content'], |
|
9 | 6116 |
'categories' => $categories, |
6117 |
'mt_excerpt' => $entry['post_excerpt'], |
|
6118 |
'mt_text_more' => $post['extended'], |
|
6119 |
'wp_more_text' => $post['more_text'], |
|
6120 |
'mt_allow_comments' => $allow_comments, |
|
6121 |
'mt_allow_pings' => $allow_pings, |
|
6122 |
'mt_keywords' => $tagnames, |
|
6123 |
'wp_slug' => $entry['post_name'], |
|
6124 |
'wp_password' => $entry['post_password'], |
|
6125 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6126 |
'wp_author_display_name' => $author->display_name, |
9 | 6127 |
'date_created_gmt' => $post_date_gmt, |
6128 |
'post_status' => $entry['post_status'], |
|
6129 |
'custom_fields' => $this->get_custom_fields( $entry['ID'] ), |
|
6130 |
'wp_post_format' => $post_format, |
|
6131 |
'date_modified' => $post_modified, |
|
6132 |
'date_modified_gmt' => $post_modified_gmt, |
|
6133 |
'sticky' => ( $entry['post_type'] === 'post' && is_sticky( $entry['ID'] ) ), |
|
6134 |
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ), |
|
0 | 6135 |
); |
6136 |
} |
|
6137 |
||
6138 |
return $recent_posts; |
|
6139 |
} |
|
6140 |
||
6141 |
/** |
|
6142 |
* Retrieve the list of categories on a given blog. |
|
6143 |
* |
|
6144 |
* @since 1.5.0 |
|
6145 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6146 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6147 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6148 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6149 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6150 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6151 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6152 |
* } |
5 | 6153 |
* @return array|IXR_Error |
0 | 6154 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6155 |
public function mw_getCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6156 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6157 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6158 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6159 |
$password = $args[2]; |
0 | 6160 |
|
9 | 6161 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6162 |
return $this->error; |
9 | 6163 |
} |
6164 |
||
6165 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6166 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6167 |
} |
0 | 6168 |
|
5 | 6169 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6170 |
do_action( 'xmlrpc_call', 'metaWeblog.getCategories' ); |
|
0 | 6171 |
|
6172 |
$categories_struct = array(); |
|
6173 |
||
9 | 6174 |
if ( $cats = get_categories( array( 'get' => 'all' ) ) ) { |
0 | 6175 |
foreach ( $cats as $cat ) { |
9 | 6176 |
$struct = array(); |
6177 |
$struct['categoryId'] = $cat->term_id; |
|
6178 |
$struct['parentId'] = $cat->parent; |
|
6179 |
$struct['description'] = $cat->name; |
|
0 | 6180 |
$struct['categoryDescription'] = $cat->description; |
9 | 6181 |
$struct['categoryName'] = $cat->name; |
6182 |
$struct['htmlUrl'] = esc_html( get_category_link( $cat->term_id ) ); |
|
6183 |
$struct['rssUrl'] = esc_html( get_category_feed_link( $cat->term_id, 'rss2' ) ); |
|
0 | 6184 |
|
6185 |
$categories_struct[] = $struct; |
|
6186 |
} |
|
6187 |
} |
|
6188 |
||
6189 |
return $categories_struct; |
|
6190 |
} |
|
6191 |
||
6192 |
/** |
|
6193 |
* Uploads a file, following your settings. |
|
6194 |
* |
|
6195 |
* Adapted from a patch by Johann Richard. |
|
6196 |
* |
|
6197 |
* @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/ |
|
6198 |
* |
|
6199 |
* @since 1.5.0 |
|
6200 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6201 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6202 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6203 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6204 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6205 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6206 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6207 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6208 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6209 |
* @type array $data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6210 |
* } |
5 | 6211 |
* @return array|IXR_Error |
0 | 6212 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6213 |
public function mw_newMediaObject( $args ) { |
0 | 6214 |
global $wpdb; |
6215 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6216 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6217 |
$password = $this->escape( $args[2] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6218 |
$data = $args[3]; |
0 | 6219 |
|
6220 |
$name = sanitize_file_name( $data['name'] ); |
|
6221 |
$type = $data['type']; |
|
6222 |
$bits = $data['bits']; |
|
6223 |
||
9 | 6224 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6225 |
return $this->error; |
9 | 6226 |
} |
0 | 6227 |
|
5 | 6228 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6229 |
do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' ); |
|
0 | 6230 |
|
9 | 6231 |
if ( ! current_user_can( 'upload_files' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6232 |
$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
|
6233 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6234 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6235 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6236 |
if ( is_multisite() && upload_is_user_over_quota( false ) ) { |
9 | 6237 |
$this->error = new IXR_Error( |
6238 |
401, |
|
6239 |
sprintf( |
|
6240 |
/* translators: %s: allowed space allocation */ |
|
6241 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
|
6242 |
size_format( get_space_allowed() * MB_IN_BYTES ) |
|
6243 |
) |
|
6244 |
); |
|
0 | 6245 |
return $this->error; |
6246 |
} |
|
6247 |
||
5 | 6248 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6249 |
* Filters whether to preempt the XML-RPC media upload. |
5 | 6250 |
* |
6251 |
* Passing a truthy value will effectively short-circuit the media upload, |
|
6252 |
* returning that value as a 500 error instead. |
|
6253 |
* |
|
6254 |
* @since 2.1.0 |
|
6255 |
* |
|
6256 |
* @param bool $error Whether to pre-empt the media upload. Default false. |
|
6257 |
*/ |
|
6258 |
if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) { |
|
6259 |
return new IXR_Error( 500, $upload_err ); |
|
6260 |
} |
|
0 | 6261 |
|
9 | 6262 |
$upload = wp_upload_bits( $name, null, $bits ); |
6263 |
if ( ! empty( $upload['error'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6264 |
/* translators: 1: file name, 2: error message */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6265 |
$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
|
6266 |
return new IXR_Error( 500, $errorString ); |
0 | 6267 |
} |
6268 |
// Construct the attachment array |
|
6269 |
$post_id = 0; |
|
6270 |
if ( ! empty( $data['post_id'] ) ) { |
|
6271 |
$post_id = (int) $data['post_id']; |
|
6272 |
||
9 | 6273 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6274 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6275 |
} |
0 | 6276 |
} |
6277 |
$attachment = array( |
|
9 | 6278 |
'post_title' => $name, |
6279 |
'post_content' => '', |
|
6280 |
'post_type' => 'attachment', |
|
6281 |
'post_parent' => $post_id, |
|
0 | 6282 |
'post_mime_type' => $type, |
9 | 6283 |
'guid' => $upload['url'], |
0 | 6284 |
); |
6285 |
||
6286 |
// Save the data |
|
9 | 6287 |
$id = wp_insert_attachment( $attachment, $upload['file'], $post_id ); |
0 | 6288 |
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
6289 |
||
5 | 6290 |
/** |
6291 |
* Fires after a new attachment has been added via the XML-RPC MovableType API. |
|
6292 |
* |
|
6293 |
* @since 3.4.0 |
|
6294 |
* |
|
6295 |
* @param int $id ID of the new attachment. |
|
6296 |
* @param array $args An array of arguments to add the attachment. |
|
6297 |
*/ |
|
0 | 6298 |
do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args ); |
6299 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6300 |
$struct = $this->_prepare_media_item( get_post( $id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6301 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6302 |
// Deprecated values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6303 |
$struct['id'] = $struct['attachment_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6304 |
$struct['file'] = $struct['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6305 |
$struct['url'] = $struct['link']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6307 |
return $struct; |
0 | 6308 |
} |
6309 |
||
6310 |
/* MovableType API functions |
|
6311 |
* specs on http://www.movabletype.org/docs/mtmanual_programmatic.html |
|
6312 |
*/ |
|
6313 |
||
6314 |
/** |
|
6315 |
* Retrieve the post titles of recent posts. |
|
6316 |
* |
|
6317 |
* @since 1.5.0 |
|
6318 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6319 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6320 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6321 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6322 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6323 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6324 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6325 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6326 |
* } |
5 | 6327 |
* @return array|IXR_Error |
0 | 6328 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6329 |
public function mt_getRecentPostTitles( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6330 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6331 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6332 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6333 |
$password = $args[2]; |
9 | 6334 |
if ( isset( $args[3] ) ) { |
0 | 6335 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6336 |
} else { |
0 | 6337 |
$query = array(); |
9 | 6338 |
} |
6339 |
||
6340 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 6341 |
return $this->error; |
9 | 6342 |
} |
0 | 6343 |
|
5 | 6344 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6345 |
do_action( 'xmlrpc_call', 'mt.getRecentPostTitles' ); |
|
0 | 6346 |
|
6347 |
$posts_list = wp_get_recent_posts( $query ); |
|
6348 |
||
9 | 6349 |
if ( ! $posts_list ) { |
6350 |
$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
|
0 | 6351 |
return $this->error; |
6352 |
} |
|
6353 |
||
5 | 6354 |
$recent_posts = array(); |
0 | 6355 |
|
9 | 6356 |
foreach ( $posts_list as $entry ) { |
6357 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6358 |
continue; |
9 | 6359 |
} |
6360 |
||
6361 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
0 | 6362 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
6363 |
||
5 | 6364 |
$recent_posts[] = array( |
9 | 6365 |
'dateCreated' => $post_date, |
6366 |
'userid' => $entry['post_author'], |
|
6367 |
'postid' => (string) $entry['ID'], |
|
6368 |
'title' => $entry['post_title'], |
|
6369 |
'post_status' => $entry['post_status'], |
|
6370 |
'date_created_gmt' => $post_date_gmt, |
|
0 | 6371 |
); |
6372 |
} |
|
6373 |
||
6374 |
return $recent_posts; |
|
6375 |
} |
|
6376 |
||
6377 |
/** |
|
6378 |
* Retrieve list of all categories on blog. |
|
6379 |
* |
|
6380 |
* @since 1.5.0 |
|
6381 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6382 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6383 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6384 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6385 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6386 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6387 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6388 |
* } |
5 | 6389 |
* @return array|IXR_Error |
0 | 6390 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6391 |
public function mt_getCategoryList( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6392 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6393 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6394 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6395 |
$password = $args[2]; |
0 | 6396 |
|
9 | 6397 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6398 |
return $this->error; |
9 | 6399 |
} |
6400 |
||
6401 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6402 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6403 |
} |
0 | 6404 |
|
5 | 6405 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6406 |
do_action( 'xmlrpc_call', 'mt.getCategoryList' ); |
|
0 | 6407 |
|
6408 |
$categories_struct = array(); |
|
6409 |
||
9 | 6410 |
if ( $cats = get_categories( |
6411 |
array( |
|
6412 |
'hide_empty' => 0, |
|
6413 |
'hierarchical' => 0, |
|
6414 |
) |
|
6415 |
) ) { |
|
0 | 6416 |
foreach ( $cats as $cat ) { |
9 | 6417 |
$struct = array(); |
6418 |
$struct['categoryId'] = $cat->term_id; |
|
0 | 6419 |
$struct['categoryName'] = $cat->name; |
6420 |
||
6421 |
$categories_struct[] = $struct; |
|
6422 |
} |
|
6423 |
} |
|
6424 |
||
6425 |
return $categories_struct; |
|
6426 |
} |
|
6427 |
||
6428 |
/** |
|
6429 |
* Retrieve post categories. |
|
6430 |
* |
|
6431 |
* @since 1.5.0 |
|
6432 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6433 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6434 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6435 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6436 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6437 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6438 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6439 |
* } |
5 | 6440 |
* @return array|IXR_Error |
0 | 6441 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6442 |
public function mt_getPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6443 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6445 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6446 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6447 |
$password = $args[2]; |
0 | 6448 |
|
9 | 6449 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6450 |
return $this->error; |
9 | 6451 |
} |
6452 |
||
6453 |
if ( ! get_post( $post_ID ) ) { |
|
0 | 6454 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6455 |
} |
6456 |
||
6457 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6458 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6459 |
} |
0 | 6460 |
|
5 | 6461 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6462 |
do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
|
0 | 6463 |
|
6464 |
$categories = array(); |
|
9 | 6465 |
$catids = wp_get_post_categories( intval( $post_ID ) ); |
0 | 6466 |
// first listed category will be the primary category |
6467 |
$isPrimary = true; |
|
6468 |
foreach ( $catids as $catid ) { |
|
6469 |
$categories[] = array( |
|
9 | 6470 |
'categoryName' => get_cat_name( $catid ), |
6471 |
'categoryId' => (string) $catid, |
|
6472 |
'isPrimary' => $isPrimary, |
|
0 | 6473 |
); |
9 | 6474 |
$isPrimary = false; |
0 | 6475 |
} |
6476 |
||
6477 |
return $categories; |
|
6478 |
} |
|
6479 |
||
6480 |
/** |
|
6481 |
* Sets categories for a post. |
|
6482 |
* |
|
6483 |
* @since 1.5.0 |
|
6484 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6485 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6486 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6487 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6488 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6489 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6490 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6491 |
* @type array $categories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6492 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6493 |
* @return true|IXR_Error True on success. |
0 | 6494 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6495 |
public function mt_setPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6496 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6497 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6498 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6499 |
$username = $args[1]; |
0 | 6500 |
$password = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6501 |
$categories = $args[3]; |
0 | 6502 |
|
9 | 6503 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6504 |
return $this->error; |
9 | 6505 |
} |
0 | 6506 |
|
5 | 6507 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6508 |
do_action( 'xmlrpc_call', 'mt.setPostCategories' ); |
|
0 | 6509 |
|
9 | 6510 |
if ( ! get_post( $post_ID ) ) { |
0 | 6511 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6512 |
} |
6513 |
||
6514 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6515 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
|
6516 |
} |
|
0 | 6517 |
|
6518 |
$catids = array(); |
|
6519 |
foreach ( $categories as $cat ) { |
|
6520 |
$catids[] = $cat['categoryId']; |
|
6521 |
} |
|
6522 |
||
9 | 6523 |
wp_set_post_categories( $post_ID, $catids ); |
0 | 6524 |
|
6525 |
return true; |
|
6526 |
} |
|
6527 |
||
6528 |
/** |
|
6529 |
* Retrieve an array of methods supported by this server. |
|
6530 |
* |
|
6531 |
* @since 1.5.0 |
|
6532 |
* |
|
6533 |
* @return array |
|
6534 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6535 |
public function mt_supportedMethods() { |
5 | 6536 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6537 |
do_action( 'xmlrpc_call', 'mt.supportedMethods' ); |
|
0 | 6538 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6539 |
return array_keys( $this->methods ); |
0 | 6540 |
} |
6541 |
||
6542 |
/** |
|
6543 |
* Retrieve an empty array because we don't support per-post text filters. |
|
6544 |
* |
|
6545 |
* @since 1.5.0 |
|
6546 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6547 |
public function mt_supportedTextFilters() { |
5 | 6548 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6549 |
do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
|
6550 |
||
6551 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6552 |
* Filters the MoveableType text filters list for XML-RPC. |
5 | 6553 |
* |
6554 |
* @since 2.2.0 |
|
6555 |
* |
|
6556 |
* @param array $filters An array of text filters. |
|
6557 |
*/ |
|
6558 |
return apply_filters( 'xmlrpc_text_filters', array() ); |
|
0 | 6559 |
} |
6560 |
||
6561 |
/** |
|
6562 |
* Retrieve trackbacks sent to a given post. |
|
6563 |
* |
|
6564 |
* @since 1.5.0 |
|
6565 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6566 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6567 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6568 |
* @param int $post_ID |
5 | 6569 |
* @return array|IXR_Error |
0 | 6570 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6571 |
public function mt_getTrackbackPings( $post_ID ) { |
0 | 6572 |
global $wpdb; |
6573 |
||
5 | 6574 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6575 |
do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); |
|
0 | 6576 |
|
9 | 6577 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
6578 |
||
6579 |
if ( ! $actual_post ) { |
|
6580 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
6581 |
} |
|
6582 |
||
6583 |
$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 ) ); |
|
6584 |
||
6585 |
if ( ! $comments ) { |
|
0 | 6586 |
return array(); |
9 | 6587 |
} |
0 | 6588 |
|
6589 |
$trackback_pings = array(); |
|
6590 |
foreach ( $comments as $comment ) { |
|
6591 |
if ( 'trackback' == $comment->comment_type ) { |
|
9 | 6592 |
$content = $comment->comment_content; |
6593 |
$title = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) ); |
|
0 | 6594 |
$trackback_pings[] = array( |
6595 |
'pingTitle' => $title, |
|
6596 |
'pingURL' => $comment->comment_author_url, |
|
9 | 6597 |
'pingIP' => $comment->comment_author_IP, |
0 | 6598 |
); |
6599 |
} |
|
6600 |
} |
|
6601 |
||
6602 |
return $trackback_pings; |
|
6603 |
} |
|
6604 |
||
6605 |
/** |
|
6606 |
* Sets a post's publish status to 'publish'. |
|
6607 |
* |
|
6608 |
* @since 1.5.0 |
|
6609 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6610 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6611 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6612 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6613 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6614 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6615 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6616 |
* } |
5 | 6617 |
* @return int|IXR_Error |
0 | 6618 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6619 |
public function mt_publishPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6620 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6621 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6622 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6623 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6624 |
$password = $args[2]; |
0 | 6625 |
|
9 | 6626 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 6627 |
return $this->error; |
9 | 6628 |
} |
0 | 6629 |
|
5 | 6630 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6631 |
do_action( 'xmlrpc_call', 'mt.publishPost' ); |
|
0 | 6632 |
|
9 | 6633 |
$postdata = get_post( $post_ID, ARRAY_A ); |
6634 |
if ( ! $postdata ) { |
|
0 | 6635 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6636 |
} |
6637 |
||
6638 |
if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_ID ) ) { |
|
6639 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
|
6640 |
} |
|
0 | 6641 |
|
6642 |
$postdata['post_status'] = 'publish'; |
|
6643 |
||
6644 |
// retain old cats |
|
9 | 6645 |
$cats = wp_get_post_categories( $post_ID ); |
0 | 6646 |
$postdata['post_category'] = $cats; |
9 | 6647 |
$this->escape( $postdata ); |
0 | 6648 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6649 |
return wp_update_post( $postdata ); |
0 | 6650 |
} |
6651 |
||
6652 |
/* PingBack functions |
|
6653 |
* specs on www.hixie.ch/specs/pingback/pingback |
|
6654 |
*/ |
|
6655 |
||
6656 |
/** |
|
6657 |
* Retrieves a pingback and registers it. |
|
6658 |
* |
|
6659 |
* @since 1.5.0 |
|
6660 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6661 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6662 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6663 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6664 |
* @type string $pagelinkedfrom |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6665 |
* @type string $pagelinkedto |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6666 |
* } |
5 | 6667 |
* @return string|IXR_Error |
0 | 6668 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6669 |
public function pingback_ping( $args ) { |
0 | 6670 |
global $wpdb; |
6671 |
||
5 | 6672 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6673 |
do_action( 'xmlrpc_call', 'pingback.ping' ); |
|
0 | 6674 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6675 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6676 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6677 |
$pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
9 | 6678 |
$pagelinkedto = str_replace( '&', '&', $args[1] ); |
6679 |
$pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
|
0 | 6680 |
|
5 | 6681 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6682 |
* Filters the pingback source URI. |
5 | 6683 |
* |
6684 |
* @since 3.6.0 |
|
6685 |
* |
|
6686 |
* @param string $pagelinkedfrom URI of the page linked from. |
|
6687 |
* @param string $pagelinkedto URI of the page linked to. |
|
6688 |
*/ |
|
0 | 6689 |
$pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5 | 6690 |
|
9 | 6691 |
if ( ! $pagelinkedfrom ) { |
0 | 6692 |
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
9 | 6693 |
} |
0 | 6694 |
|
6695 |
// Check if the page linked to is in our site |
|
9 | 6696 |
$pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) ); |
6697 |
if ( ! $pos1 ) { |
|
0 | 6698 |
return $this->pingback_error( 0, __( 'Is there no link to us?' ) ); |
9 | 6699 |
} |
0 | 6700 |
|
6701 |
// let's find which post is linked to |
|
6702 |
// FIXME: does url_to_postid() cover all these cases already? |
|
6703 |
// if so, then let's use it and drop the old code. |
|
9 | 6704 |
$urltest = parse_url( $pagelinkedto ); |
6705 |
if ( $post_ID = url_to_postid( $pagelinkedto ) ) { |
|
5 | 6706 |
// $way |
9 | 6707 |
} elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) { |
0 | 6708 |
// the path defines the post_ID (archives/p/XXXX) |
9 | 6709 |
$blah = explode( '/', $match[0] ); |
0 | 6710 |
$post_ID = (int) $blah[1]; |
9 | 6711 |
} elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) { |
0 | 6712 |
// the querystring defines the post_ID (?p=XXXX) |
9 | 6713 |
$blah = explode( '=', $match[0] ); |
0 | 6714 |
$post_ID = (int) $blah[1]; |
9 | 6715 |
} elseif ( isset( $urltest['fragment'] ) ) { |
0 | 6716 |
// an #anchor is there, it's either... |
9 | 6717 |
if ( intval( $urltest['fragment'] ) ) { |
0 | 6718 |
// ...an integer #XXXX (simplest case) |
6719 |
$post_ID = (int) $urltest['fragment']; |
|
9 | 6720 |
} elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
0 | 6721 |
// ...a post id in the form 'post-###' |
9 | 6722 |
$post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
6723 |
} elseif ( is_string( $urltest['fragment'] ) ) { |
|
0 | 6724 |
// ...or a string #title, a little more complicated |
9 | 6725 |
$title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] ); |
6726 |
$sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
|
6727 |
if ( ! ( $post_ID = $wpdb->get_var( $sql ) ) ) { |
|
0 | 6728 |
// returning unknown error '0' is better than die()ing |
9 | 6729 |
return $this->pingback_error( 0, '' ); |
0 | 6730 |
} |
6731 |
} |
|
6732 |
} else { |
|
6733 |
// TODO: Attempt to extract a post ID from the given URL |
|
9 | 6734 |
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 | 6735 |
} |
6736 |
$post_ID = (int) $post_ID; |
|
6737 |
||
9 | 6738 |
$post = get_post( $post_ID ); |
6739 |
||
6740 |
if ( ! $post ) { // Post_ID not found |
|
6741 |
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.' ) ); |
|
6742 |
} |
|
6743 |
||
6744 |
if ( $post_ID == url_to_postid( $pagelinkedfrom ) ) { |
|
0 | 6745 |
return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); |
9 | 6746 |
} |
0 | 6747 |
|
6748 |
// Check if pings are on |
|
9 | 6749 |
if ( ! pings_open( $post ) ) { |
6750 |
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.' ) ); |
|
6751 |
} |
|
0 | 6752 |
|
6753 |
// Let's check that the remote site didn't already pingback this entry |
|
9 | 6754 |
if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom ) ) ) { |
0 | 6755 |
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
9 | 6756 |
} |
0 | 6757 |
|
6758 |
// very stupid, but gives time to the 'from' server to publish ! |
|
9 | 6759 |
sleep( 1 ); |
0 | 6760 |
|
5 | 6761 |
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
6762 |
||
6763 |
/** This filter is documented in wp-includes/class-http.php */ |
|
9 | 6764 |
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $url ); |
5 | 6765 |
|
0 | 6766 |
// Let's check the remote site |
6767 |
$http_api_args = array( |
|
9 | 6768 |
'timeout' => 10, |
6769 |
'redirection' => 0, |
|
0 | 6770 |
'limit_response_size' => 153600, // 150 KB |
9 | 6771 |
'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
6772 |
'headers' => array( |
|
5 | 6773 |
'X-Pingback-Forwarded-For' => $remote_ip, |
6774 |
), |
|
0 | 6775 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6776 |
|
9 | 6777 |
$request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6778 |
$remote_source = $remote_source_original = wp_remote_retrieve_body( $request ); |
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 |
if ( ! $remote_source ) { |
5 | 6781 |
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
|
6782 |
} |
5 | 6783 |
|
6784 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6785 |
* Filters the pingback remote source. |
5 | 6786 |
* |
6787 |
* @since 2.5.0 |
|
6788 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6789 |
* @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
|
6790 |
* @param string $pagelinkedto URL of the page linked to. |
5 | 6791 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6792 |
$remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
0 | 6793 |
|
6794 |
// Work around bug in strip_tags(): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6795 |
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6796 |
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
9 | 6797 |
$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
|
6798 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6799 |
preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6800 |
$title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6801 |
if ( empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6802 |
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
|
6803 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6804 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6805 |
$remote_source = strip_tags( $remote_source, '<a>' ); // just keep the tag we need |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6806 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6807 |
$p = explode( "\n\n", $remote_source ); |
0 | 6808 |
|
9 | 6809 |
$preg_target = preg_quote( $pagelinkedto, '|' ); |
0 | 6810 |
|
6811 |
foreach ( $p as $para ) { |
|
9 | 6812 |
if ( strpos( $para, $pagelinkedto ) !== false ) { // it exists, but is it a link? |
6813 |
preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context ); |
|
0 | 6814 |
|
6815 |
// If the URL isn't in a link context, keep looking |
|
9 | 6816 |
if ( empty( $context ) ) { |
0 | 6817 |
continue; |
9 | 6818 |
} |
0 | 6819 |
|
6820 |
// We're going to use this fake tag to mark the context in a bit |
|
6821 |
// the marker is needed in case the link text appears more than once in the paragraph |
|
9 | 6822 |
$excerpt = preg_replace( '|\</?wpcontext\>|', '', $para ); |
0 | 6823 |
|
6824 |
// prevent really long link text |
|
9 | 6825 |
if ( strlen( $context[1] ) > 100 ) { |
6826 |
$context[1] = substr( $context[1], 0, 100 ) . '…'; |
|
6827 |
} |
|
6828 |
||
6829 |
$marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // set up our marker |
|
6830 |
$excerpt = str_replace( $context[0], $marker, $excerpt ); // swap out the link for our marker |
|
6831 |
$excerpt = strip_tags( $excerpt, '<wpcontext>' ); // strip all tags but our context marker |
|
6832 |
$excerpt = trim( $excerpt ); |
|
6833 |
$preg_marker = preg_quote( $marker, '|' ); |
|
6834 |
$excerpt = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt ); |
|
6835 |
$excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper |
|
0 | 6836 |
break; |
6837 |
} |
|
6838 |
} |
|
6839 |
||
9 | 6840 |
if ( empty( $context ) ) { // Link to target not found |
0 | 6841 |
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 | 6842 |
} |
6843 |
||
6844 |
$pagelinkedfrom = str_replace( '&', '&', $pagelinkedfrom ); |
|
6845 |
||
6846 |
$context = '[…] ' . esc_html( $excerpt ) . ' […]'; |
|
0 | 6847 |
$pagelinkedfrom = $this->escape( $pagelinkedfrom ); |
6848 |
||
9 | 6849 |
$comment_post_ID = (int) $post_ID; |
6850 |
$comment_author = $title; |
|
0 | 6851 |
$comment_author_email = ''; |
9 | 6852 |
$this->escape( $comment_author ); |
0 | 6853 |
$comment_author_url = $pagelinkedfrom; |
9 | 6854 |
$comment_content = $context; |
6855 |
$this->escape( $comment_content ); |
|
0 | 6856 |
$comment_type = 'pingback'; |
6857 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6858 |
$commentdata = compact( |
9 | 6859 |
'comment_post_ID', |
6860 |
'comment_author', |
|
6861 |
'comment_author_url', |
|
6862 |
'comment_author_email', |
|
6863 |
'comment_content', |
|
6864 |
'comment_type', |
|
6865 |
'remote_source', |
|
6866 |
'remote_source_original' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6867 |
); |
0 | 6868 |
|
9 | 6869 |
$comment_ID = wp_new_comment( $commentdata ); |
5 | 6870 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6871 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6872 |
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
|
6873 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6874 |
|
5 | 6875 |
/** |
6876 |
* Fires after a post pingback has been sent. |
|
6877 |
* |
|
6878 |
* @since 0.71 |
|
6879 |
* |
|
6880 |
* @param int $comment_ID Comment ID. |
|
6881 |
*/ |
|
6882 |
do_action( 'pingback_post', $comment_ID ); |
|
0 | 6883 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6884 |
/* translators: 1: URL of the page linked from, 2: URL of the page linked to */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6885 |
return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
0 | 6886 |
} |
6887 |
||
6888 |
/** |
|
6889 |
* Retrieve array of URLs that pingbacked the given URL. |
|
6890 |
* |
|
6891 |
* Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
|
6892 |
* |
|
6893 |
* @since 1.5.0 |
|
6894 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6895 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6896 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6897 |
* @param string $url |
5 | 6898 |
* @return array|IXR_Error |
0 | 6899 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6900 |
public function pingback_extensions_getPingbacks( $url ) { |
0 | 6901 |
global $wpdb; |
6902 |
||
5 | 6903 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6904 |
do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
|
0 | 6905 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6906 |
$url = $this->escape( $url ); |
0 | 6907 |
|
9 | 6908 |
$post_ID = url_to_postid( $url ); |
6909 |
if ( ! $post_ID ) { |
|
0 | 6910 |
// We aren't sure that the resource is available and/or pingback enabled |
9 | 6911 |
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.' ) ); |
6912 |
} |
|
6913 |
||
6914 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
6915 |
||
6916 |
if ( ! $actual_post ) { |
|
0 | 6917 |
// No such post = resource not found |
9 | 6918 |
return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) ); |
6919 |
} |
|
6920 |
||
6921 |
$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 ) ); |
|
6922 |
||
6923 |
if ( ! $comments ) { |
|
0 | 6924 |
return array(); |
9 | 6925 |
} |
0 | 6926 |
|
6927 |
$pingbacks = array(); |
|
6928 |
foreach ( $comments as $comment ) { |
|
9 | 6929 |
if ( 'pingback' == $comment->comment_type ) { |
0 | 6930 |
$pingbacks[] = $comment->comment_author_url; |
9 | 6931 |
} |
0 | 6932 |
} |
6933 |
||
6934 |
return $pingbacks; |
|
6935 |
} |
|
6936 |
||
5 | 6937 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6938 |
* 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
|
6939 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6940 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6941 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6942 |
* @param int $code Error code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6943 |
* @param string $message Error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6944 |
* @return IXR_Error Error object. |
5 | 6945 |
*/ |
0 | 6946 |
protected function pingback_error( $code, $message ) { |
5 | 6947 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6948 |
* Filters the XML-RPC pingback error return. |
5 | 6949 |
* |
6950 |
* @since 3.5.1 |
|
6951 |
* |
|
6952 |
* @param IXR_Error $error An IXR_Error object containing the error code and message. |
|
6953 |
*/ |
|
0 | 6954 |
return apply_filters( 'xmlrpc_pingback_error', new IXR_Error( $code, $message ) ); |
6955 |
} |
|
6956 |
} |