author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
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 |
|
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 |
|
5 | 94 |
'wp.deleteFile' => 'this:wp_deletePost', // Alias |
0 | 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', |
|
114 |
||
115 |
// Blogger API |
|
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', |
|
123 |
||
124 |
// MetaWeblog API (with MT extensions to structs) |
|
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', |
|
131 |
||
132 |
// MetaWeblog API aliases for Blogger API |
|
133 |
// see http://www.xmlrpc.com/stories/storyReader$2460 |
|
134 |
'metaWeblog.deletePost' => 'this:blogger_deletePost', |
|
135 |
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|
136 |
||
137 |
// MovableType API |
|
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', |
|
146 |
||
147 |
// PingBack |
|
148 |
'pingback.ping' => 'this:pingback_ping', |
|
149 |
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', |
|
150 |
||
151 |
'demo.sayHello' => 'this:sayHello', |
|
152 |
'demo.addTwoNumbers' => 'this:addTwoNumbers' |
|
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 |
* |
|
174 |
* @param callable $name Method to call. |
|
175 |
* @param array $arguments Arguments to pass when calling. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* @return array|IXR_Error|false Return value of the callback, false otherwise. |
5 | 177 |
*/ |
178 |
public function __call( $name, $arguments ) { |
|
179 |
if ( '_multisite_getUsersBlogs' === $name ) { |
|
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() { |
0 | 191 |
$this->IXR_Server($this->methods); |
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 ) { |
0 | 325 |
if ( ! is_array( $data ) ) |
326 |
return wp_slash( $data ); |
|
327 |
||
328 |
foreach ( $data as &$v ) { |
|
329 |
if ( is_array( $v ) ) |
|
330 |
$this->escape( $v ); |
|
331 |
elseif ( ! is_object( $v ) ) |
|
332 |
$v = wp_slash( $v ); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Retrieve custom fields for post. |
|
338 |
* |
|
339 |
* @since 2.5.0 |
|
340 |
* |
|
341 |
* @param int $post_id Post ID. |
|
342 |
* @return array Custom fields, if exist. |
|
343 |
*/ |
|
5 | 344 |
public function get_custom_fields($post_id) { |
0 | 345 |
$post_id = (int) $post_id; |
346 |
||
347 |
$custom_fields = array(); |
|
348 |
||
349 |
foreach ( (array) has_meta($post_id) as $meta ) { |
|
350 |
// Don't expose protected fields. |
|
351 |
if ( ! current_user_can( 'edit_post_meta', $post_id , $meta['meta_key'] ) ) |
|
352 |
continue; |
|
353 |
||
354 |
$custom_fields[] = array( |
|
355 |
"id" => $meta['meta_id'], |
|
356 |
"key" => $meta['meta_key'], |
|
357 |
"value" => $meta['meta_value'] |
|
358 |
); |
|
359 |
} |
|
360 |
||
361 |
return $custom_fields; |
|
362 |
} |
|
363 |
||
364 |
/** |
|
365 |
* Set custom fields for post. |
|
366 |
* |
|
367 |
* @since 2.5.0 |
|
368 |
* |
|
369 |
* @param int $post_id Post ID. |
|
370 |
* @param array $fields Custom fields. |
|
371 |
*/ |
|
5 | 372 |
public function set_custom_fields($post_id, $fields) { |
0 | 373 |
$post_id = (int) $post_id; |
374 |
||
375 |
foreach ( (array) $fields as $meta ) { |
|
376 |
if ( isset($meta['id']) ) { |
|
377 |
$meta['id'] = (int) $meta['id']; |
|
378 |
$pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
if ( ! $pmeta || $pmeta->post_id != $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
continue; |
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 |
|
0 | 384 |
if ( isset($meta['key']) ) { |
385 |
$meta['key'] = wp_unslash( $meta['key'] ); |
|
386 |
if ( $meta['key'] !== $pmeta->meta_key ) |
|
387 |
continue; |
|
388 |
$meta['value'] = wp_unslash( $meta['value'] ); |
|
389 |
if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) |
|
390 |
update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
|
391 |
} elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
|
392 |
delete_metadata_by_mid( 'post', $meta['id'] ); |
|
393 |
} |
|
394 |
} elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { |
|
395 |
add_post_meta( $post_id, $meta['key'], $meta['value'] ); |
|
396 |
} |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
* Retrieve custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* @return array Array of custom fields, if they exist. |
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 |
public function get_term_custom_fields( $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
$custom_fields = array(); |
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 |
foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
continue; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
$custom_fields[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
'id' => $meta['meta_id'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
'key' => $meta['meta_key'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
'value' => $meta['meta_value'], |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
return $custom_fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
} |
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 |
* Set custom fields for a term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @since 4.9.0 |
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 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
* @param array $fields Custom fields. |
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 |
public function set_term_custom_fields( $term_id, $fields ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
foreach ( (array) $fields as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
if ( isset( $meta['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
$meta['id'] = (int) $meta['id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
$pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
if ( isset( $meta['key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
$meta['key'] = wp_unslash( $meta['key'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
$meta['value'] = wp_unslash( $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
} elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
delete_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
} elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
} |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
/** |
0 | 463 |
* Set up blog options property. |
464 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* Passes property through {@see 'xmlrpc_blog_options'} filter. |
0 | 466 |
* |
467 |
* @since 2.6.0 |
|
468 |
*/ |
|
5 | 469 |
public function initialise_blog_option_info() { |
0 | 470 |
$this->blog_options = array( |
471 |
// Read only options |
|
472 |
'software_name' => array( |
|
473 |
'desc' => __( 'Software Name' ), |
|
474 |
'readonly' => true, |
|
475 |
'value' => 'WordPress' |
|
476 |
), |
|
477 |
'software_version' => array( |
|
478 |
'desc' => __( 'Software Version' ), |
|
479 |
'readonly' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
'value' => get_bloginfo( 'version' ) |
0 | 481 |
), |
482 |
'blog_url' => array( |
|
483 |
'desc' => __( 'WordPress Address (URL)' ), |
|
484 |
'readonly' => true, |
|
485 |
'option' => 'siteurl' |
|
486 |
), |
|
487 |
'home_url' => array( |
|
488 |
'desc' => __( 'Site Address (URL)' ), |
|
489 |
'readonly' => true, |
|
490 |
'option' => 'home' |
|
491 |
), |
|
492 |
'login_url' => array( |
|
493 |
'desc' => __( 'Login Address (URL)' ), |
|
494 |
'readonly' => true, |
|
495 |
'value' => wp_login_url( ) |
|
496 |
), |
|
497 |
'admin_url' => array( |
|
498 |
'desc' => __( 'The URL to the admin area' ), |
|
499 |
'readonly' => true, |
|
500 |
'value' => get_admin_url( ) |
|
501 |
), |
|
502 |
'image_default_link_type' => array( |
|
503 |
'desc' => __( 'Image default link type' ), |
|
504 |
'readonly' => true, |
|
505 |
'option' => 'image_default_link_type' |
|
506 |
), |
|
507 |
'image_default_size' => array( |
|
508 |
'desc' => __( 'Image default size' ), |
|
509 |
'readonly' => true, |
|
510 |
'option' => 'image_default_size' |
|
511 |
), |
|
512 |
'image_default_align' => array( |
|
513 |
'desc' => __( 'Image default align' ), |
|
514 |
'readonly' => true, |
|
515 |
'option' => 'image_default_align' |
|
516 |
), |
|
517 |
'template' => array( |
|
518 |
'desc' => __( 'Template' ), |
|
519 |
'readonly' => true, |
|
520 |
'option' => 'template' |
|
521 |
), |
|
522 |
'stylesheet' => array( |
|
523 |
'desc' => __( 'Stylesheet' ), |
|
524 |
'readonly' => true, |
|
525 |
'option' => 'stylesheet' |
|
526 |
), |
|
527 |
'post_thumbnail' => array( |
|
528 |
'desc' => __('Post Thumbnail'), |
|
529 |
'readonly' => true, |
|
530 |
'value' => current_theme_supports( 'post-thumbnails' ) |
|
531 |
), |
|
532 |
||
533 |
// Updatable options |
|
534 |
'time_zone' => array( |
|
535 |
'desc' => __( 'Time Zone' ), |
|
536 |
'readonly' => false, |
|
537 |
'option' => 'gmt_offset' |
|
538 |
), |
|
539 |
'blog_title' => array( |
|
540 |
'desc' => __( 'Site Title' ), |
|
541 |
'readonly' => false, |
|
542 |
'option' => 'blogname' |
|
543 |
), |
|
544 |
'blog_tagline' => array( |
|
545 |
'desc' => __( 'Site Tagline' ), |
|
546 |
'readonly' => false, |
|
547 |
'option' => 'blogdescription' |
|
548 |
), |
|
549 |
'date_format' => array( |
|
550 |
'desc' => __( 'Date Format' ), |
|
551 |
'readonly' => false, |
|
552 |
'option' => 'date_format' |
|
553 |
), |
|
554 |
'time_format' => array( |
|
555 |
'desc' => __( 'Time Format' ), |
|
556 |
'readonly' => false, |
|
557 |
'option' => 'time_format' |
|
558 |
), |
|
559 |
'users_can_register' => array( |
|
560 |
'desc' => __( 'Allow new users to sign up' ), |
|
561 |
'readonly' => false, |
|
562 |
'option' => 'users_can_register' |
|
563 |
), |
|
564 |
'thumbnail_size_w' => array( |
|
565 |
'desc' => __( 'Thumbnail Width' ), |
|
566 |
'readonly' => false, |
|
567 |
'option' => 'thumbnail_size_w' |
|
568 |
), |
|
569 |
'thumbnail_size_h' => array( |
|
570 |
'desc' => __( 'Thumbnail Height' ), |
|
571 |
'readonly' => false, |
|
572 |
'option' => 'thumbnail_size_h' |
|
573 |
), |
|
574 |
'thumbnail_crop' => array( |
|
575 |
'desc' => __( 'Crop thumbnail to exact dimensions' ), |
|
576 |
'readonly' => false, |
|
577 |
'option' => 'thumbnail_crop' |
|
578 |
), |
|
579 |
'medium_size_w' => array( |
|
580 |
'desc' => __( 'Medium size image width' ), |
|
581 |
'readonly' => false, |
|
582 |
'option' => 'medium_size_w' |
|
583 |
), |
|
584 |
'medium_size_h' => array( |
|
585 |
'desc' => __( 'Medium size image height' ), |
|
586 |
'readonly' => false, |
|
587 |
'option' => 'medium_size_h' |
|
588 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
'medium_large_size_w' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
'desc' => __( 'Medium-Large size image width' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
'readonly' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
'option' => 'medium_large_size_w' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
'medium_large_size_h' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
'desc' => __( 'Medium-Large size image height' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
'readonly' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
'option' => 'medium_large_size_h' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
), |
0 | 599 |
'large_size_w' => array( |
600 |
'desc' => __( 'Large size image width' ), |
|
601 |
'readonly' => false, |
|
602 |
'option' => 'large_size_w' |
|
603 |
), |
|
604 |
'large_size_h' => array( |
|
605 |
'desc' => __( 'Large size image height' ), |
|
606 |
'readonly' => false, |
|
607 |
'option' => 'large_size_h' |
|
608 |
), |
|
609 |
'default_comment_status' => array( |
|
610 |
'desc' => __( 'Allow people to post comments on new articles' ), |
|
611 |
'readonly' => false, |
|
612 |
'option' => 'default_comment_status' |
|
613 |
), |
|
614 |
'default_ping_status' => array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ), |
0 | 616 |
'readonly' => false, |
617 |
'option' => 'default_ping_status' |
|
618 |
) |
|
619 |
); |
|
620 |
||
5 | 621 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* Filters the XML-RPC blog options property. |
5 | 623 |
* |
624 |
* @since 2.6.0 |
|
625 |
* |
|
626 |
* @param array $blog_options An array of XML-RPC blog options. |
|
627 |
*/ |
|
0 | 628 |
$this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); |
629 |
} |
|
630 |
||
631 |
/** |
|
632 |
* Retrieve the blogs of the user. |
|
633 |
* |
|
634 |
* @since 2.6.0 |
|
635 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* } |
5 | 642 |
* @return array|IXR_Error Array contains: |
0 | 643 |
* - 'isAdmin' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
* - 'isPrimary' - whether the blog is the user's primary blog |
0 | 645 |
* - 'url' |
646 |
* - 'blogid' |
|
647 |
* - 'blogName' |
|
648 |
* - 'xmlrpc' - url of xmlrpc endpoint |
|
649 |
*/ |
|
5 | 650 |
public function wp_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
if ( ! $this->minimum_args( $args, 2 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
|
0 | 655 |
// If this isn't on WPMU then just use blogger_getUsersBlogs |
656 |
if ( !is_multisite() ) { |
|
657 |
array_unshift( $args, 1 ); |
|
658 |
return $this->blogger_getUsersBlogs( $args ); |
|
659 |
} |
|
660 |
||
661 |
$this->escape( $args ); |
|
662 |
||
663 |
$username = $args[0]; |
|
664 |
$password = $args[1]; |
|
665 |
||
666 |
if ( !$user = $this->login($username, $password) ) |
|
667 |
return $this->error; |
|
668 |
||
5 | 669 |
/** |
670 |
* Fires after the XML-RPC user has been authenticated but before the rest of |
|
671 |
* the method logic begins. |
|
672 |
* |
|
673 |
* All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
|
674 |
* equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
|
675 |
* |
|
676 |
* @since 2.5.0 |
|
677 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
* @param string $name The method name. |
5 | 679 |
*/ |
0 | 680 |
do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
681 |
||
682 |
$blogs = (array) get_blogs_of_user( $user->ID ); |
|
683 |
$struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
$primary_blog_id = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
$active_blog = get_active_blog_for_user( $user->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
if ( $active_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
$primary_blog_id = (int) $active_blog->blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
} |
0 | 689 |
|
690 |
foreach ( $blogs as $blog ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
// Don't include blogs that aren't hosted at this site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
if ( $blog->site_id != get_current_network_id() ) |
0 | 693 |
continue; |
694 |
||
695 |
$blog_id = $blog->userblog_id; |
|
696 |
||
697 |
switch_to_blog( $blog_id ); |
|
698 |
||
699 |
$is_admin = current_user_can( 'manage_options' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
$is_primary = ( (int) $blog_id === $primary_blog_id ); |
0 | 701 |
|
702 |
$struct[] = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
'isAdmin' => $is_admin, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
'isPrimary' => $is_primary, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
'blogid' => (string) $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
'blogName' => get_option( 'blogname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
0 | 709 |
); |
710 |
||
711 |
restore_current_blog(); |
|
712 |
} |
|
713 |
||
714 |
return $struct; |
|
715 |
} |
|
716 |
||
717 |
/** |
|
718 |
* Checks if the method received at least the minimum number of arguments. |
|
719 |
* |
|
720 |
* @since 3.4.0 |
|
721 |
* |
|
722 |
* @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
|
723 |
* @param int $count Minimum number of arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* @return bool if `$args` contains at least $count arguments. |
0 | 725 |
*/ |
726 |
protected function minimum_args( $args, $count ) { |
|
727 |
if ( count( $args ) < $count ) { |
|
728 |
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) ); |
|
729 |
return false; |
|
730 |
} |
|
731 |
||
732 |
return true; |
|
733 |
} |
|
734 |
||
735 |
/** |
|
736 |
* Prepares taxonomy data for return in an XML-RPC object. |
|
737 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* @param object $taxonomy The unprepared taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* @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
|
741 |
* @return array The prepared taxonomy data. |
0 | 742 |
*/ |
743 |
protected function _prepare_taxonomy( $taxonomy, $fields ) { |
|
744 |
$_taxonomy = array( |
|
745 |
'name' => $taxonomy->name, |
|
746 |
'label' => $taxonomy->label, |
|
747 |
'hierarchical' => (bool) $taxonomy->hierarchical, |
|
748 |
'public' => (bool) $taxonomy->public, |
|
749 |
'show_ui' => (bool) $taxonomy->show_ui, |
|
750 |
'_builtin' => (bool) $taxonomy->_builtin, |
|
751 |
); |
|
752 |
||
753 |
if ( in_array( 'labels', $fields ) ) |
|
754 |
$_taxonomy['labels'] = (array) $taxonomy->labels; |
|
755 |
||
756 |
if ( in_array( 'cap', $fields ) ) |
|
757 |
$_taxonomy['cap'] = (array) $taxonomy->cap; |
|
758 |
||
759 |
if ( in_array( 'menu', $fields ) ) |
|
760 |
$_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu; |
|
761 |
||
762 |
if ( in_array( 'object_type', $fields ) ) |
|
763 |
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
|
764 |
||
5 | 765 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
* Filters XML-RPC-prepared data for the given taxonomy. |
5 | 767 |
* |
768 |
* @since 3.4.0 |
|
769 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
* @param array $_taxonomy An array of taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
* @param WP_Taxonomy $taxonomy Taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
* @param array $fields The subset of taxonomy fields to return. |
5 | 773 |
*/ |
0 | 774 |
return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
775 |
} |
|
776 |
||
777 |
/** |
|
778 |
* Prepares term data for return in an XML-RPC object. |
|
779 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
* @param array|object $term The unprepared term data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
* @return array The prepared term data. |
0 | 783 |
*/ |
784 |
protected function _prepare_term( $term ) { |
|
785 |
$_term = $term; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
if ( ! is_array( $_term ) ) |
0 | 787 |
$_term = get_object_vars( $_term ); |
788 |
||
789 |
// For integers which may be larger than XML-RPC supports ensure we return strings. |
|
790 |
$_term['term_id'] = strval( $_term['term_id'] ); |
|
791 |
$_term['term_group'] = strval( $_term['term_group'] ); |
|
792 |
$_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] ); |
|
793 |
$_term['parent'] = strval( $_term['parent'] ); |
|
794 |
||
795 |
// Count we are happy to return as an integer because people really shouldn't use terms that much. |
|
796 |
$_term['count'] = intval( $_term['count'] ); |
|
797 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
// Get term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
$_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
|
800 |
|
5 | 801 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* Filters XML-RPC-prepared data for the given term. |
5 | 803 |
* |
804 |
* @since 3.4.0 |
|
805 |
* |
|
806 |
* @param array $_term An array of term data. |
|
807 |
* @param array|object $term Term object or array. |
|
808 |
*/ |
|
0 | 809 |
return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
810 |
} |
|
811 |
||
812 |
/** |
|
813 |
* Convert a WordPress date string to an IXR_Date object. |
|
814 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* @param string $date Date string to convert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* @return IXR_Date IXR_Date object. |
0 | 818 |
*/ |
819 |
protected function _convert_date( $date ) { |
|
820 |
if ( $date === '0000-00-00 00:00:00' ) { |
|
821 |
return new IXR_Date( '00000000T00:00:00Z' ); |
|
822 |
} |
|
823 |
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); |
|
824 |
} |
|
825 |
||
826 |
/** |
|
827 |
* Convert a WordPress GMT date string to an IXR_Date object. |
|
828 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* @param string $date_gmt WordPress GMT date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* @param string $date Date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
* @return IXR_Date IXR_Date object. |
0 | 833 |
*/ |
834 |
protected function _convert_date_gmt( $date_gmt, $date ) { |
|
835 |
if ( $date !== '0000-00-00 00:00:00' && $date_gmt === '0000-00-00 00:00:00' ) { |
|
836 |
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) ); |
|
837 |
} |
|
838 |
return $this->_convert_date( $date_gmt ); |
|
839 |
} |
|
840 |
||
841 |
/** |
|
842 |
* Prepares post data for return in an XML-RPC object. |
|
843 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
* @param array $post The unprepared post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
* @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
|
847 |
* @return array The prepared post data. |
0 | 848 |
*/ |
849 |
protected function _prepare_post( $post, $fields ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
// Holds the data for this post. built up based on $fields. |
0 | 851 |
$_post = array( 'post_id' => strval( $post['ID'] ) ); |
852 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
// Prepare common post fields. |
0 | 854 |
$post_fields = array( |
855 |
'post_title' => $post['post_title'], |
|
856 |
'post_date' => $this->_convert_date( $post['post_date'] ), |
|
857 |
'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
|
858 |
'post_modified' => $this->_convert_date( $post['post_modified'] ), |
|
859 |
'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ), |
|
860 |
'post_status' => $post['post_status'], |
|
861 |
'post_type' => $post['post_type'], |
|
862 |
'post_name' => $post['post_name'], |
|
863 |
'post_author' => $post['post_author'], |
|
864 |
'post_password' => $post['post_password'], |
|
865 |
'post_excerpt' => $post['post_excerpt'], |
|
866 |
'post_content' => $post['post_content'], |
|
867 |
'post_parent' => strval( $post['post_parent'] ), |
|
868 |
'post_mime_type' => $post['post_mime_type'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
'link' => get_permalink( $post['ID'] ), |
0 | 870 |
'guid' => $post['guid'], |
871 |
'menu_order' => intval( $post['menu_order'] ), |
|
872 |
'comment_status' => $post['comment_status'], |
|
873 |
'ping_status' => $post['ping_status'], |
|
874 |
'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), |
|
875 |
); |
|
876 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
// Thumbnail. |
0 | 878 |
$post_fields['post_thumbnail'] = array(); |
879 |
$thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
|
880 |
if ( $thumbnail_id ) { |
|
881 |
$thumbnail_size = current_theme_supports('post-thumbnail') ? 'post-thumbnail' : 'thumbnail'; |
|
882 |
$post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
|
883 |
} |
|
884 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
// Consider future posts as published. |
0 | 886 |
if ( $post_fields['post_status'] === 'future' ) |
887 |
$post_fields['post_status'] = 'publish'; |
|
888 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
// Fill in blank post format. |
0 | 890 |
$post_fields['post_format'] = get_post_format( $post['ID'] ); |
891 |
if ( empty( $post_fields['post_format'] ) ) |
|
892 |
$post_fields['post_format'] = 'standard'; |
|
893 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
// Merge requested $post_fields fields into $_post. |
0 | 895 |
if ( in_array( 'post', $fields ) ) { |
896 |
$_post = array_merge( $_post, $post_fields ); |
|
897 |
} else { |
|
898 |
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
|
899 |
$_post = array_merge( $_post, $requested_fields ); |
|
900 |
} |
|
901 |
||
902 |
$all_taxonomy_fields = in_array( 'taxonomies', $fields ); |
|
903 |
||
904 |
if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) { |
|
905 |
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' ); |
|
906 |
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies ); |
|
907 |
$_post['terms'] = array(); |
|
908 |
foreach ( $terms as $term ) { |
|
909 |
$_post['terms'][] = $this->_prepare_term( $term ); |
|
910 |
} |
|
911 |
} |
|
912 |
||
913 |
if ( in_array( 'custom_fields', $fields ) ) |
|
914 |
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] ); |
|
915 |
||
916 |
if ( in_array( 'enclosure', $fields ) ) { |
|
917 |
$_post['enclosure'] = array(); |
|
918 |
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' ); |
|
919 |
if ( ! empty( $enclosures ) ) { |
|
920 |
$encdata = explode( "\n", $enclosures[0] ); |
|
921 |
$_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
922 |
$_post['enclosure']['length'] = (int) trim( $encdata[1] ); |
|
923 |
$_post['enclosure']['type'] = trim( $encdata[2] ); |
|
924 |
} |
|
925 |
} |
|
926 |
||
5 | 927 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* Filters XML-RPC-prepared date for the given post. |
5 | 929 |
* |
930 |
* @since 3.4.0 |
|
931 |
* |
|
932 |
* @param array $_post An array of modified post data. |
|
933 |
* @param array $post An array of post data. |
|
934 |
* @param array $fields An array of post fields. |
|
935 |
*/ |
|
0 | 936 |
return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields ); |
937 |
} |
|
938 |
||
939 |
/** |
|
940 |
* Prepares post data for return in an XML-RPC object. |
|
941 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
* @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
|
944 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
* @param WP_Post_Type $post_type Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
* @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
|
947 |
* @return array The prepared post type data. |
0 | 948 |
*/ |
949 |
protected function _prepare_post_type( $post_type, $fields ) { |
|
950 |
$_post_type = array( |
|
951 |
'name' => $post_type->name, |
|
952 |
'label' => $post_type->label, |
|
953 |
'hierarchical' => (bool) $post_type->hierarchical, |
|
954 |
'public' => (bool) $post_type->public, |
|
955 |
'show_ui' => (bool) $post_type->show_ui, |
|
956 |
'_builtin' => (bool) $post_type->_builtin, |
|
957 |
'has_archive' => (bool) $post_type->has_archive, |
|
958 |
'supports' => get_all_post_type_supports( $post_type->name ), |
|
959 |
); |
|
960 |
||
961 |
if ( in_array( 'labels', $fields ) ) { |
|
962 |
$_post_type['labels'] = (array) $post_type->labels; |
|
963 |
} |
|
964 |
||
965 |
if ( in_array( 'cap', $fields ) ) { |
|
966 |
$_post_type['cap'] = (array) $post_type->cap; |
|
967 |
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; |
|
968 |
} |
|
969 |
||
970 |
if ( in_array( 'menu', $fields ) ) { |
|
971 |
$_post_type['menu_position'] = (int) $post_type->menu_position; |
|
972 |
$_post_type['menu_icon'] = $post_type->menu_icon; |
|
973 |
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; |
|
974 |
} |
|
975 |
||
976 |
if ( in_array( 'taxonomies', $fields ) ) |
|
977 |
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
|
978 |
||
5 | 979 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
* Filters XML-RPC-prepared date for the given post type. |
5 | 981 |
* |
982 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 984 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* @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
|
986 |
* @param WP_Post_Type $post_type Post type object. |
5 | 987 |
*/ |
0 | 988 |
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
989 |
} |
|
990 |
||
991 |
/** |
|
992 |
* Prepares media item data for return in an XML-RPC object. |
|
993 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* @param object $media_item The unprepared media item data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* @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
|
997 |
* @return array The prepared media item data. |
0 | 998 |
*/ |
999 |
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
|
1000 |
$_media_item = array( |
|
1001 |
'attachment_id' => strval( $media_item->ID ), |
|
1002 |
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
|
1003 |
'parent' => $media_item->post_parent, |
|
1004 |
'link' => wp_get_attachment_url( $media_item->ID ), |
|
1005 |
'title' => $media_item->post_title, |
|
1006 |
'caption' => $media_item->post_excerpt, |
|
1007 |
'description' => $media_item->post_content, |
|
1008 |
'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
'type' => $media_item->post_mime_type |
0 | 1010 |
); |
1011 |
||
1012 |
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
|
1013 |
if ( $thumbnail_src ) |
|
1014 |
$_media_item['thumbnail'] = $thumbnail_src[0]; |
|
1015 |
else |
|
1016 |
$_media_item['thumbnail'] = $_media_item['link']; |
|
1017 |
||
5 | 1018 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
* Filters XML-RPC-prepared data for the given media item. |
5 | 1020 |
* |
1021 |
* @since 3.4.0 |
|
1022 |
* |
|
1023 |
* @param array $_media_item An array of media item data. |
|
1024 |
* @param object $media_item Media item object. |
|
1025 |
* @param string $thumbnail_size Image size. |
|
1026 |
*/ |
|
0 | 1027 |
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1028 |
} |
|
1029 |
||
1030 |
/** |
|
1031 |
* Prepares page data for return in an XML-RPC object. |
|
1032 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
* @param object $page The unprepared page data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
* @return array The prepared page data. |
0 | 1036 |
*/ |
1037 |
protected function _prepare_page( $page ) { |
|
1038 |
// Get all of the page content and link. |
|
1039 |
$full_page = get_extended( $page->post_content ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
$link = get_permalink( $page->ID ); |
0 | 1041 |
|
1042 |
// Get info the page parent if there is one. |
|
1043 |
$parent_title = ""; |
|
1044 |
if ( ! empty( $page->post_parent ) ) { |
|
1045 |
$parent = get_post( $page->post_parent ); |
|
1046 |
$parent_title = $parent->post_title; |
|
1047 |
} |
|
1048 |
||
1049 |
// Determine comment and ping settings. |
|
1050 |
$allow_comments = comments_open( $page->ID ) ? 1 : 0; |
|
1051 |
$allow_pings = pings_open( $page->ID ) ? 1 : 0; |
|
1052 |
||
1053 |
// Format page date. |
|
1054 |
$page_date = $this->_convert_date( $page->post_date ); |
|
1055 |
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); |
|
1056 |
||
1057 |
// Pull the categories info together. |
|
1058 |
$categories = array(); |
|
5 | 1059 |
if ( is_object_in_taxonomy( 'page', 'category' ) ) { |
1060 |
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { |
|
1061 |
$categories[] = get_cat_name( $cat_id ); |
|
1062 |
} |
|
0 | 1063 |
} |
1064 |
||
1065 |
// Get the author info. |
|
1066 |
$author = get_userdata( $page->post_author ); |
|
1067 |
||
1068 |
$page_template = get_page_template_slug( $page->ID ); |
|
1069 |
if ( empty( $page_template ) ) |
|
1070 |
$page_template = 'default'; |
|
1071 |
||
1072 |
$_page = array( |
|
1073 |
'dateCreated' => $page_date, |
|
1074 |
'userid' => $page->post_author, |
|
1075 |
'page_id' => $page->ID, |
|
1076 |
'page_status' => $page->post_status, |
|
1077 |
'description' => $full_page['main'], |
|
1078 |
'title' => $page->post_title, |
|
1079 |
'link' => $link, |
|
1080 |
'permaLink' => $link, |
|
1081 |
'categories' => $categories, |
|
1082 |
'excerpt' => $page->post_excerpt, |
|
1083 |
'text_more' => $full_page['extended'], |
|
1084 |
'mt_allow_comments' => $allow_comments, |
|
1085 |
'mt_allow_pings' => $allow_pings, |
|
1086 |
'wp_slug' => $page->post_name, |
|
1087 |
'wp_password' => $page->post_password, |
|
1088 |
'wp_author' => $author->display_name, |
|
1089 |
'wp_page_parent_id' => $page->post_parent, |
|
1090 |
'wp_page_parent_title' => $parent_title, |
|
1091 |
'wp_page_order' => $page->menu_order, |
|
1092 |
'wp_author_id' => (string) $author->ID, |
|
1093 |
'wp_author_display_name' => $author->display_name, |
|
1094 |
'date_created_gmt' => $page_date_gmt, |
|
1095 |
'custom_fields' => $this->get_custom_fields( $page->ID ), |
|
1096 |
'wp_page_template' => $page_template |
|
1097 |
); |
|
1098 |
||
5 | 1099 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* Filters XML-RPC-prepared data for the given page. |
5 | 1101 |
* |
1102 |
* @since 3.4.0 |
|
1103 |
* |
|
1104 |
* @param array $_page An array of page data. |
|
1105 |
* @param WP_Post $page Page object. |
|
1106 |
*/ |
|
0 | 1107 |
return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); |
1108 |
} |
|
1109 |
||
1110 |
/** |
|
1111 |
* Prepares comment data for return in an XML-RPC object. |
|
1112 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* @param object $comment The unprepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* @return array The prepared comment data. |
0 | 1116 |
*/ |
1117 |
protected function _prepare_comment( $comment ) { |
|
1118 |
// Format page date. |
|
1119 |
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
|
1120 |
||
5 | 1121 |
if ( '0' == $comment->comment_approved ) { |
0 | 1122 |
$comment_status = 'hold'; |
5 | 1123 |
} elseif ( 'spam' == $comment->comment_approved ) { |
0 | 1124 |
$comment_status = 'spam'; |
5 | 1125 |
} elseif ( '1' == $comment->comment_approved ) { |
0 | 1126 |
$comment_status = 'approve'; |
5 | 1127 |
} else { |
0 | 1128 |
$comment_status = $comment->comment_approved; |
5 | 1129 |
} |
0 | 1130 |
$_comment = array( |
1131 |
'date_created_gmt' => $comment_date_gmt, |
|
1132 |
'user_id' => $comment->user_id, |
|
1133 |
'comment_id' => $comment->comment_ID, |
|
1134 |
'parent' => $comment->comment_parent, |
|
1135 |
'status' => $comment_status, |
|
1136 |
'content' => $comment->comment_content, |
|
1137 |
'link' => get_comment_link($comment), |
|
1138 |
'post_id' => $comment->comment_post_ID, |
|
1139 |
'post_title' => get_the_title($comment->comment_post_ID), |
|
1140 |
'author' => $comment->comment_author, |
|
1141 |
'author_url' => $comment->comment_author_url, |
|
1142 |
'author_email' => $comment->comment_author_email, |
|
1143 |
'author_ip' => $comment->comment_author_IP, |
|
1144 |
'type' => $comment->comment_type, |
|
1145 |
); |
|
1146 |
||
5 | 1147 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
* Filters XML-RPC-prepared data for the given comment. |
5 | 1149 |
* |
1150 |
* @since 3.4.0 |
|
1151 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
* @param array $_comment An array of prepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
* @param WP_Comment $comment Comment object. |
5 | 1154 |
*/ |
0 | 1155 |
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1156 |
} |
|
1157 |
||
1158 |
/** |
|
1159 |
* Prepares user data for return in an XML-RPC object. |
|
1160 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* @param WP_User $user The unprepared user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* @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
|
1164 |
* @return array The prepared user data. |
0 | 1165 |
*/ |
1166 |
protected function _prepare_user( $user, $fields ) { |
|
1167 |
$_user = array( 'user_id' => strval( $user->ID ) ); |
|
1168 |
||
1169 |
$user_fields = array( |
|
1170 |
'username' => $user->user_login, |
|
1171 |
'first_name' => $user->user_firstname, |
|
1172 |
'last_name' => $user->user_lastname, |
|
1173 |
'registered' => $this->_convert_date( $user->user_registered ), |
|
1174 |
'bio' => $user->user_description, |
|
1175 |
'email' => $user->user_email, |
|
1176 |
'nickname' => $user->nickname, |
|
1177 |
'nicename' => $user->user_nicename, |
|
1178 |
'url' => $user->user_url, |
|
1179 |
'display_name' => $user->display_name, |
|
1180 |
'roles' => $user->roles, |
|
1181 |
); |
|
1182 |
||
1183 |
if ( in_array( 'all', $fields ) ) { |
|
1184 |
$_user = array_merge( $_user, $user_fields ); |
|
1185 |
} else { |
|
1186 |
if ( in_array( 'basic', $fields ) ) { |
|
1187 |
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); |
|
1188 |
$fields = array_merge( $fields, $basic_fields ); |
|
1189 |
} |
|
1190 |
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); |
|
1191 |
$_user = array_merge( $_user, $requested_fields ); |
|
1192 |
} |
|
1193 |
||
5 | 1194 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
* Filters XML-RPC-prepared data for the given user. |
5 | 1196 |
* |
1197 |
* @since 3.5.0 |
|
1198 |
* |
|
1199 |
* @param array $_user An array of user data. |
|
1200 |
* @param WP_User $user User object. |
|
1201 |
* @param array $fields An array of user fields. |
|
1202 |
*/ |
|
0 | 1203 |
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); |
1204 |
} |
|
1205 |
||
1206 |
/** |
|
1207 |
* Create a new post for any registered post type. |
|
1208 |
* |
|
1209 |
* @since 3.4.0 |
|
1210 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
* @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
|
1212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
* 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
|
1215 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
* @type array $content_struct { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
* 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
|
1221 |
* additional post fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
* @type string $post_type Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* @type string $post_status Post status. Default 'draft' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* @type string $post_title Post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @type int $post_author Post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @type string $post_excerpt Post excerpt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* @type string $post_content Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
* @type string $post_date_gmt Post date in GMT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
* @type string $post_date Post date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
* @type string $post_password Post password (20-character limit). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
* @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
|
1233 |
* @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
|
1234 |
* @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
|
1235 |
* `$post_status` is 'private'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
* @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
|
1237 |
* @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
|
1238 |
* @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
|
1239 |
* of term IDs as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
* @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
|
1241 |
* of term names as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
* @type array $enclosure { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
* 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
|
1244 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
* @type string $url URL for the feed enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
* @type int $length Size in bytes of the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
* @type string $type Mime-type for the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
0 | 1252 |
*/ |
5 | 1253 |
public function wp_newPost( $args ) { |
0 | 1254 |
if ( ! $this->minimum_args( $args, 4 ) ) |
1255 |
return $this->error; |
|
1256 |
||
1257 |
$this->escape( $args ); |
|
1258 |
||
1259 |
$username = $args[1]; |
|
1260 |
$password = $args[2]; |
|
1261 |
$content_struct = $args[3]; |
|
1262 |
||
1263 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1264 |
return $this->error; |
|
1265 |
||
5 | 1266 |
// convert the date field back to IXR form |
1267 |
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
|
1268 |
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1269 |
} |
|
1270 |
||
1271 |
// ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1272 |
// since _insert_post will ignore the non-GMT date if the GMT date is set |
|
1273 |
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
|
1274 |
if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { |
|
1275 |
unset( $content_struct['post_date_gmt'] ); |
|
1276 |
} else { |
|
1277 |
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1278 |
} |
|
1279 |
} |
|
1280 |
||
1281 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1282 |
do_action( 'xmlrpc_call', 'wp.newPost' ); |
1283 |
||
1284 |
unset( $content_struct['ID'] ); |
|
1285 |
||
1286 |
return $this->_insert_post( $user, $content_struct ); |
|
1287 |
} |
|
1288 |
||
1289 |
/** |
|
1290 |
* Helper method for filtering out elements from an array. |
|
1291 |
* |
|
1292 |
* @since 3.4.0 |
|
1293 |
* |
|
1294 |
* @param int $count Number to compare to one. |
|
1295 |
*/ |
|
1296 |
private function _is_greater_than_one( $count ) { |
|
1297 |
return $count > 1; |
|
1298 |
} |
|
1299 |
||
1300 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
* Encapsulate the logic for sticking a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
* 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
|
1303 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* @param array $post_data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
* @param bool $update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
* @return void|IXR_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
private function _toggle_sticky( $post_data, $update = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
$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
|
1312 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
// Private and password-protected posts cannot be stickied. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
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
|
1315 |
// 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
|
1316 |
if ( ! empty( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
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
|
1318 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
if ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
} elseif ( isset( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
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
|
1325 |
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
|
1326 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
$sticky = wp_validate_boolean( $post_data['sticky'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
if ( $sticky ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
stick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
} else { |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
|
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 |
* Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
0 | 1339 |
* |
1340 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
* @param WP_User $user The post author if post_author isn't set in $content_struct. |
5 | 1345 |
* @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
|
1346 |
* @return IXR_Error|string |
0 | 1347 |
*/ |
1348 |
protected function _insert_post( $user, $content_struct ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
'post_status' => 'draft', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
'post_type' => 'post', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
'post_author' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
'post_password' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
'post_excerpt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
'post_content' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
'post_title' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
'post_date' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
'post_date_gmt' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
'post_format' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
'post_name' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
'post_thumbnail' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
'post_parent' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
'ping_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
'comment_status' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
'custom_fields' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
'terms_names' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
'terms' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
'sticky' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
'enclosure' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
'ID' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
0 | 1374 |
|
1375 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
|
1376 |
if ( ! $post_type ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
0 | 1378 |
|
1379 |
$update = ! empty( $post_data['ID'] ); |
|
1380 |
||
1381 |
if ( $update ) { |
|
1382 |
if ( ! get_post( $post_data['ID'] ) ) |
|
1383 |
return new IXR_Error( 401, __( 'Invalid post ID.' ) ); |
|
1384 |
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) |
|
1385 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
|
1386 |
if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) ) |
|
1387 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
|
1388 |
} else { |
|
1389 |
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) |
|
1390 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
|
1391 |
} |
|
1392 |
||
1393 |
switch ( $post_data['post_status'] ) { |
|
1394 |
case 'draft': |
|
1395 |
case 'pending': |
|
1396 |
break; |
|
1397 |
case 'private': |
|
1398 |
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
|
1399 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
0 | 1400 |
break; |
1401 |
case 'publish': |
|
1402 |
case 'future': |
|
1403 |
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
|
1404 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
0 | 1405 |
break; |
1406 |
default: |
|
1407 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) |
|
1408 |
$post_data['post_status'] = 'draft'; |
|
1409 |
break; |
|
1410 |
} |
|
1411 |
||
1412 |
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
|
1413 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
0 | 1414 |
|
1415 |
$post_data['post_author'] = absint( $post_data['post_author'] ); |
|
1416 |
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
|
1417 |
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
|
1418 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
0 | 1419 |
|
1420 |
$author = get_userdata( $post_data['post_author'] ); |
|
1421 |
||
1422 |
if ( ! $author ) |
|
1423 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
|
1424 |
} else { |
|
1425 |
$post_data['post_author'] = $user->ID; |
|
1426 |
} |
|
1427 |
||
1428 |
if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) |
|
1429 |
unset( $post_data['comment_status'] ); |
|
1430 |
||
1431 |
if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) |
|
1432 |
unset( $post_data['ping_status'] ); |
|
1433 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
// Do some timestamp voodoo. |
0 | 1435 |
if ( ! empty( $post_data['post_date_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 1437 |
$dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1438 |
} elseif ( ! empty( $post_data['post_date'] ) ) { |
|
1439 |
$dateCreated = $post_data['post_date']->getIso(); |
|
1440 |
} |
|
1441 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
// 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
|
1443 |
$post_data['edit_date'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
|
0 | 1445 |
if ( ! empty( $dateCreated ) ) { |
1446 |
$post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
|
1447 |
$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
|
1448 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
$post_data['edit_date'] = true; |
0 | 1451 |
} |
1452 |
||
1453 |
if ( ! isset( $post_data['ID'] ) ) |
|
1454 |
$post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
|
1455 |
$post_ID = $post_data['ID']; |
|
1456 |
||
1457 |
if ( $post_data['post_type'] == 'post' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
$error = $this->_toggle_sticky( $post_data, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
return $error; |
0 | 1461 |
} |
1462 |
} |
|
1463 |
||
1464 |
if ( isset( $post_data['post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
// empty value deletes, non-empty value adds/updates. |
0 | 1466 |
if ( ! $post_data['post_thumbnail'] ) |
1467 |
delete_post_thumbnail( $post_ID ); |
|
1468 |
elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) |
|
1469 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
|
1470 |
set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
|
1471 |
unset( $content_struct['post_thumbnail'] ); |
|
1472 |
} |
|
1473 |
||
1474 |
if ( isset( $post_data['custom_fields'] ) ) |
|
1475 |
$this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
|
1476 |
||
1477 |
if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
|
1478 |
$post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
|
1479 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
// Accumulate term IDs from terms and terms_names. |
0 | 1481 |
$terms = array(); |
1482 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
// First validate the terms specified by ID. |
0 | 1484 |
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1485 |
$taxonomies = array_keys( $post_data['terms'] ); |
|
1486 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
// Validating term ids. |
0 | 1488 |
foreach ( $taxonomies as $taxonomy ) { |
1489 |
if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
|
1490 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
|
1491 |
||
1492 |
if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
|
1493 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
|
1494 |
||
1495 |
$term_ids = $post_data['terms'][$taxonomy]; |
|
5 | 1496 |
$terms[ $taxonomy ] = array(); |
0 | 1497 |
foreach ( $term_ids as $term_id ) { |
1498 |
$term = get_term_by( 'id', $term_id, $taxonomy ); |
|
1499 |
||
1500 |
if ( ! $term ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
0 | 1502 |
|
1503 |
$terms[$taxonomy][] = (int) $term_id; |
|
1504 |
} |
|
1505 |
} |
|
1506 |
} |
|
1507 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
// Now validate terms specified by name. |
0 | 1509 |
if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1510 |
$taxonomies = array_keys( $post_data['terms_names'] ); |
|
1511 |
||
1512 |
foreach ( $taxonomies as $taxonomy ) { |
|
1513 |
if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
|
1514 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
|
1515 |
||
1516 |
if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
|
1517 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
|
1518 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
* 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
|
1521 |
* in the hierarchy share the same name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
*/ |
0 | 1523 |
$ambiguous_terms = array(); |
1524 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
1525 |
$tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) ); |
|
1526 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
// Count the number of terms with the same name. |
0 | 1528 |
$tax_term_names_count = array_count_values( $tax_term_names ); |
1529 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
// Filter out non-ambiguous term names. |
0 | 1531 |
$ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') ); |
1532 |
||
1533 |
$ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
|
1534 |
} |
|
1535 |
||
1536 |
$term_names = $post_data['terms_names'][$taxonomy]; |
|
1537 |
foreach ( $term_names as $term_name ) { |
|
1538 |
if ( in_array( $term_name, $ambiguous_terms ) ) |
|
1539 |
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
|
1540 |
||
1541 |
$term = get_term_by( 'name', $term_name, $taxonomy ); |
|
1542 |
||
1543 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
// Term doesn't exist, so check that the user is allowed to create new terms. |
0 | 1545 |
if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) ) |
1546 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
|
1547 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
// Create the new term. |
0 | 1549 |
$term_info = wp_insert_term( $term_name, $taxonomy ); |
1550 |
if ( is_wp_error( $term_info ) ) |
|
1551 |
return new IXR_Error( 500, $term_info->get_error_message() ); |
|
1552 |
||
1553 |
$terms[$taxonomy][] = (int) $term_info['term_id']; |
|
1554 |
} else { |
|
1555 |
$terms[$taxonomy][] = (int) $term->term_id; |
|
1556 |
} |
|
1557 |
} |
|
1558 |
} |
|
1559 |
} |
|
1560 |
||
1561 |
$post_data['tax_input'] = $terms; |
|
1562 |
unset( $post_data['terms'], $post_data['terms_names'] ); |
|
1563 |
} |
|
1564 |
||
1565 |
if ( isset( $post_data['post_format'] ) ) { |
|
1566 |
$format = set_post_format( $post_ID, $post_data['post_format'] ); |
|
1567 |
||
1568 |
if ( is_wp_error( $format ) ) |
|
1569 |
return new IXR_Error( 500, $format->get_error_message() ); |
|
1570 |
||
1571 |
unset( $post_data['post_format'] ); |
|
1572 |
} |
|
1573 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
// Handle enclosures. |
0 | 1575 |
$enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; |
1576 |
$this->add_enclosure_if_new( $post_ID, $enclosure ); |
|
1577 |
||
1578 |
$this->attach_uploads( $post_ID, $post_data['post_content'] ); |
|
1579 |
||
5 | 1580 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
* Filters post data array to be inserted via XML-RPC. |
5 | 1582 |
* |
1583 |
* @since 3.4.0 |
|
1584 |
* |
|
1585 |
* @param array $post_data Parsed array of post data. |
|
1586 |
* @param array $content_struct Post data array. |
|
1587 |
*/ |
|
0 | 1588 |
$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); |
1589 |
||
1590 |
$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); |
|
1591 |
if ( is_wp_error( $post_ID ) ) |
|
1592 |
return new IXR_Error( 500, $post_ID->get_error_message() ); |
|
1593 |
||
1594 |
if ( ! $post_ID ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
return new IXR_Error( 401, __( 'Sorry, your entry could not be posted.' ) ); |
0 | 1596 |
|
1597 |
return strval( $post_ID ); |
|
1598 |
} |
|
1599 |
||
1600 |
/** |
|
1601 |
* Edit a post for any registered post type. |
|
1602 |
* |
|
1603 |
* The $content_struct parameter only needs to contain fields that |
|
1604 |
* should be changed. All other fields will retain their existing values. |
|
1605 |
* |
|
1606 |
* @since 3.4.0 |
|
1607 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1608 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1609 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1610 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1612 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1615 |
* @type array $content_struct Extra content arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
* @return true|IXR_Error True on success, IXR_Error on failure. |
0 | 1618 |
*/ |
5 | 1619 |
public function wp_editPost( $args ) { |
0 | 1620 |
if ( ! $this->minimum_args( $args, 5 ) ) |
1621 |
return $this->error; |
|
1622 |
||
1623 |
$this->escape( $args ); |
|
1624 |
||
1625 |
$username = $args[1]; |
|
1626 |
$password = $args[2]; |
|
1627 |
$post_id = (int) $args[3]; |
|
1628 |
$content_struct = $args[4]; |
|
1629 |
||
1630 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1631 |
return $this->error; |
|
1632 |
||
5 | 1633 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1634 |
do_action( 'xmlrpc_call', 'wp.editPost' ); |
1635 |
||
1636 |
$post = get_post( $post_id, ARRAY_A ); |
|
1637 |
||
1638 |
if ( empty( $post['ID'] ) ) |
|
1639 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
1640 |
||
1641 |
if ( isset( $content_struct['if_not_modified_since'] ) ) { |
|
1642 |
// If the post has been modified since the date provided, return an error. |
|
1643 |
if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { |
|
1644 |
return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); |
|
1645 |
} |
|
1646 |
} |
|
1647 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
// Convert the date field back to IXR form. |
0 | 1649 |
$post['post_date'] = $this->_convert_date( $post['post_date'] ); |
1650 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* 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
|
1653 |
* 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
|
1654 |
*/ |
0 | 1655 |
if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) |
1656 |
unset( $post['post_date_gmt'] ); |
|
1657 |
else |
|
1658 |
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); |
|
1659 |
||
1660 |
$this->escape( $post ); |
|
1661 |
$merged_content_struct = array_merge( $post, $content_struct ); |
|
1662 |
||
1663 |
$retval = $this->_insert_post( $user, $merged_content_struct ); |
|
1664 |
if ( $retval instanceof IXR_Error ) |
|
1665 |
return $retval; |
|
1666 |
||
1667 |
return true; |
|
1668 |
} |
|
1669 |
||
1670 |
/** |
|
1671 |
* Delete a post for any registered post type. |
|
1672 |
* |
|
1673 |
* @since 3.4.0 |
|
1674 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
* @see wp_delete_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 1686 |
*/ |
5 | 1687 |
public function wp_deletePost( $args ) { |
0 | 1688 |
if ( ! $this->minimum_args( $args, 4 ) ) |
1689 |
return $this->error; |
|
1690 |
||
1691 |
$this->escape( $args ); |
|
1692 |
||
1693 |
$username = $args[1]; |
|
1694 |
$password = $args[2]; |
|
1695 |
$post_id = (int) $args[3]; |
|
1696 |
||
1697 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1698 |
return $this->error; |
|
1699 |
||
5 | 1700 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1701 |
do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1702 |
||
1703 |
$post = get_post( $post_id, ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1704 |
if ( empty( $post['ID'] ) ) { |
0 | 1705 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
0 | 1709 |
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
|
1710 |
} |
0 | 1711 |
|
1712 |
$result = wp_delete_post( $post_id ); |
|
1713 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
if ( ! $result ) { |
0 | 1715 |
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
|
1716 |
} |
0 | 1717 |
|
1718 |
return true; |
|
1719 |
} |
|
1720 |
||
1721 |
/** |
|
1722 |
* Retrieve a post. |
|
1723 |
* |
|
1724 |
* @since 3.4.0 |
|
1725 |
* |
|
1726 |
* The optional $fields parameter specifies what fields will be included |
|
1727 |
* in the response array. This should be a list of field names. 'post_id' will |
|
1728 |
* always be included in the response regardless of the value of $fields. |
|
1729 |
* |
|
1730 |
* Instead of, or in addition to, individual field names, conceptual group |
|
1731 |
* names can be used to specify multiple fields. The available conceptual |
|
1732 |
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields', |
|
1733 |
* and 'enclosure'. |
|
1734 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
* @see get_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
* @type int $post_id Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* @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
|
1745 |
* } |
5 | 1746 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 1747 |
* - 'post_id' |
1748 |
* - 'post_title' |
|
1749 |
* - 'post_date' |
|
1750 |
* - 'post_date_gmt' |
|
1751 |
* - 'post_modified' |
|
1752 |
* - 'post_modified_gmt' |
|
1753 |
* - 'post_status' |
|
1754 |
* - 'post_type' |
|
1755 |
* - 'post_name' |
|
1756 |
* - 'post_author' |
|
1757 |
* - 'post_password' |
|
1758 |
* - 'post_excerpt' |
|
1759 |
* - 'post_content' |
|
1760 |
* - 'link' |
|
1761 |
* - 'comment_status' |
|
1762 |
* - 'ping_status' |
|
1763 |
* - 'sticky' |
|
1764 |
* - 'custom_fields' |
|
1765 |
* - 'terms' |
|
1766 |
* - 'categories' |
|
1767 |
* - 'tags' |
|
1768 |
* - 'enclosure' |
|
1769 |
*/ |
|
5 | 1770 |
public function wp_getPost( $args ) { |
0 | 1771 |
if ( ! $this->minimum_args( $args, 4 ) ) |
1772 |
return $this->error; |
|
1773 |
||
1774 |
$this->escape( $args ); |
|
1775 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
$post_id = (int) $args[3]; |
0 | 1779 |
|
5 | 1780 |
if ( isset( $args[4] ) ) { |
0 | 1781 |
$fields = $args[4]; |
5 | 1782 |
} else { |
1783 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
* Filters the list of post query fields used by the given XML-RPC method. |
5 | 1785 |
* |
1786 |
* @since 3.4.0 |
|
1787 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
* @param array $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'. |
5 | 1789 |
* @param string $method Method name. |
1790 |
*/ |
|
0 | 1791 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
5 | 1792 |
} |
0 | 1793 |
|
1794 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1795 |
return $this->error; |
|
1796 |
||
5 | 1797 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1798 |
do_action( 'xmlrpc_call', 'wp.getPost' ); |
1799 |
||
1800 |
$post = get_post( $post_id, ARRAY_A ); |
|
1801 |
||
1802 |
if ( empty( $post['ID'] ) ) |
|
1803 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
1804 |
||
1805 |
if ( ! current_user_can( 'edit_post', $post_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 1807 |
|
1808 |
return $this->_prepare_post( $post, $fields ); |
|
1809 |
} |
|
1810 |
||
1811 |
/** |
|
1812 |
* Retrieve posts. |
|
1813 |
* |
|
1814 |
* @since 3.4.0 |
|
1815 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* @see wp_get_recent_posts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
* @see wp_getPost() for more on `$fields` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
* @see get_posts() for more on `$filter` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1819 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1823 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
* @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
|
1827 |
* 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
* @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
|
1830 |
* } |
5 | 1831 |
* @return array|IXR_Error Array contains a collection of posts. |
0 | 1832 |
*/ |
5 | 1833 |
public function wp_getPosts( $args ) { |
0 | 1834 |
if ( ! $this->minimum_args( $args, 3 ) ) |
1835 |
return $this->error; |
|
1836 |
||
1837 |
$this->escape( $args ); |
|
1838 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1840 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1841 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 1842 |
|
5 | 1843 |
if ( isset( $args[4] ) ) { |
0 | 1844 |
$fields = $args[4]; |
5 | 1845 |
} else { |
1846 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1847 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
5 | 1848 |
} |
0 | 1849 |
|
1850 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1851 |
return $this->error; |
|
1852 |
||
5 | 1853 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1854 |
do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1855 |
||
1856 |
$query = array(); |
|
1857 |
||
1858 |
if ( isset( $filter['post_type'] ) ) { |
|
1859 |
$post_type = get_post_type_object( $filter['post_type'] ); |
|
1860 |
if ( ! ( (bool) $post_type ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
0 | 1862 |
} else { |
1863 |
$post_type = get_post_type_object( 'post' ); |
|
1864 |
} |
|
1865 |
||
1866 |
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
|
1867 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
0 | 1868 |
|
1869 |
$query['post_type'] = $post_type->name; |
|
1870 |
||
1871 |
if ( isset( $filter['post_status'] ) ) |
|
1872 |
$query['post_status'] = $filter['post_status']; |
|
1873 |
||
1874 |
if ( isset( $filter['number'] ) ) |
|
1875 |
$query['numberposts'] = absint( $filter['number'] ); |
|
1876 |
||
1877 |
if ( isset( $filter['offset'] ) ) |
|
1878 |
$query['offset'] = absint( $filter['offset'] ); |
|
1879 |
||
1880 |
if ( isset( $filter['orderby'] ) ) { |
|
1881 |
$query['orderby'] = $filter['orderby']; |
|
1882 |
||
1883 |
if ( isset( $filter['order'] ) ) |
|
1884 |
$query['order'] = $filter['order']; |
|
1885 |
} |
|
1886 |
||
1887 |
if ( isset( $filter['s'] ) ) { |
|
1888 |
$query['s'] = $filter['s']; |
|
1889 |
} |
|
1890 |
||
1891 |
$posts_list = wp_get_recent_posts( $query ); |
|
1892 |
||
1893 |
if ( ! $posts_list ) |
|
1894 |
return array(); |
|
1895 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
// Holds all the posts data. |
0 | 1897 |
$struct = array(); |
1898 |
||
1899 |
foreach ( $posts_list as $post ) { |
|
1900 |
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) |
|
1901 |
continue; |
|
1902 |
||
1903 |
$struct[] = $this->_prepare_post( $post, $fields ); |
|
1904 |
} |
|
1905 |
||
1906 |
return $struct; |
|
1907 |
} |
|
1908 |
||
1909 |
/** |
|
1910 |
* Create a new term. |
|
1911 |
* |
|
1912 |
* @since 3.4.0 |
|
1913 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
* @see wp_insert_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
* @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
|
1923 |
* the term 'name' and 'taxonomy'. Optional accepted values include |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1924 |
* 'parent', 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1925 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
0 | 1927 |
*/ |
5 | 1928 |
public function wp_newTerm( $args ) { |
0 | 1929 |
if ( ! $this->minimum_args( $args, 4 ) ) |
1930 |
return $this->error; |
|
1931 |
||
1932 |
$this->escape( $args ); |
|
1933 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
$content_struct = $args[3]; |
0 | 1937 |
|
1938 |
if ( ! $user = $this->login( $username, $password ) ) |
|
1939 |
return $this->error; |
|
1940 |
||
5 | 1941 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 1942 |
do_action( 'xmlrpc_call', 'wp.newTerm' ); |
1943 |
||
1944 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1945 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 1946 |
|
1947 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
1948 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1949 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1950 |
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
|
1951 |
} |
0 | 1952 |
|
1953 |
$taxonomy = (array) $taxonomy; |
|
1954 |
||
1955 |
// hold the data of the term |
|
1956 |
$term_data = array(); |
|
1957 |
||
1958 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
1959 |
if ( empty( $term_data['name'] ) ) |
|
1960 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
|
1961 |
||
1962 |
if ( isset( $content_struct['parent'] ) ) { |
|
1963 |
if ( ! $taxonomy['hierarchical'] ) |
|
1964 |
return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
|
1965 |
||
1966 |
$parent_term_id = (int) $content_struct['parent']; |
|
1967 |
$parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
|
1968 |
||
1969 |
if ( is_wp_error( $parent_term ) ) |
|
1970 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
|
1971 |
||
1972 |
if ( ! $parent_term ) |
|
1973 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
|
1974 |
||
1975 |
$term_data['parent'] = $content_struct['parent']; |
|
1976 |
} |
|
1977 |
||
1978 |
if ( isset( $content_struct['description'] ) ) |
|
1979 |
$term_data['description'] = $content_struct['description']; |
|
1980 |
||
1981 |
if ( isset( $content_struct['slug'] ) ) |
|
1982 |
$term_data['slug'] = $content_struct['slug']; |
|
1983 |
||
1984 |
$term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data ); |
|
1985 |
||
1986 |
if ( is_wp_error( $term ) ) |
|
1987 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
1988 |
||
1989 |
if ( ! $term ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
// Add term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
$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
|
1995 |
} |
0 | 1996 |
|
1997 |
return strval( $term['term_id'] ); |
|
1998 |
} |
|
1999 |
||
2000 |
/** |
|
2001 |
* Edit a term. |
|
2002 |
* |
|
2003 |
* @since 3.4.0 |
|
2004 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2005 |
* @see wp_update_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2006 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2007 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2014 |
* @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
|
2015 |
* term ''taxonomy'. Optional accepted values include 'name', 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2016 |
* 'description', and 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2017 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2019 |
*/ |
5 | 2020 |
public function wp_editTerm( $args ) { |
0 | 2021 |
if ( ! $this->minimum_args( $args, 5 ) ) |
2022 |
return $this->error; |
|
2023 |
||
2024 |
$this->escape( $args ); |
|
2025 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
$term_id = (int) $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
$content_struct = $args[4]; |
0 | 2030 |
|
2031 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2032 |
return $this->error; |
|
2033 |
||
5 | 2034 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2035 |
do_action( 'xmlrpc_call', 'wp.editTerm' ); |
2036 |
||
2037 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 2039 |
|
2040 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2041 |
||
2042 |
$taxonomy = (array) $taxonomy; |
|
2043 |
||
2044 |
// hold the data of the term |
|
2045 |
$term_data = array(); |
|
2046 |
||
2047 |
$term = get_term( $term_id , $content_struct['taxonomy'] ); |
|
2048 |
||
2049 |
if ( is_wp_error( $term ) ) |
|
2050 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
2051 |
||
2052 |
if ( ! $term ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
if ( ! current_user_can( 'edit_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
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
|
2057 |
} |
0 | 2058 |
|
2059 |
if ( isset( $content_struct['name'] ) ) { |
|
2060 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
2061 |
||
2062 |
if ( empty( $term_data['name'] ) ) |
|
2063 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
|
2064 |
} |
|
2065 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
if ( ! empty( $content_struct['parent'] ) ) { |
0 | 2067 |
if ( ! $taxonomy['hierarchical'] ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
0 | 2069 |
|
2070 |
$parent_term_id = (int) $content_struct['parent']; |
|
2071 |
$parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
|
2072 |
||
2073 |
if ( is_wp_error( $parent_term ) ) |
|
2074 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
|
2075 |
||
2076 |
if ( ! $parent_term ) |
|
2077 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
|
2078 |
||
2079 |
$term_data['parent'] = $content_struct['parent']; |
|
2080 |
} |
|
2081 |
||
2082 |
if ( isset( $content_struct['description'] ) ) |
|
2083 |
$term_data['description'] = $content_struct['description']; |
|
2084 |
||
2085 |
if ( isset( $content_struct['slug'] ) ) |
|
2086 |
$term_data['slug'] = $content_struct['slug']; |
|
2087 |
||
2088 |
$term = wp_update_term( $term_id , $taxonomy['name'] , $term_data ); |
|
2089 |
||
2090 |
if ( is_wp_error( $term ) ) |
|
2091 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
2092 |
||
2093 |
if ( ! $term ) |
|
2094 |
return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
|
2095 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
// Update term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2097 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
$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
|
2099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
|
0 | 2101 |
return true; |
2102 |
} |
|
2103 |
||
2104 |
/** |
|
2105 |
* Delete a term. |
|
2106 |
* |
|
2107 |
* @since 3.4.0 |
|
2108 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
* @see wp_delete_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2116 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2117 |
* @type string $taxnomy_name Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2118 |
* @type int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
* @return bool|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2121 |
*/ |
5 | 2122 |
public function wp_deleteTerm( $args ) { |
0 | 2123 |
if ( ! $this->minimum_args( $args, 5 ) ) |
2124 |
return $this->error; |
|
2125 |
||
2126 |
$this->escape( $args ); |
|
2127 |
||
2128 |
$username = $args[1]; |
|
2129 |
$password = $args[2]; |
|
2130 |
$taxonomy = $args[3]; |
|
2131 |
$term_id = (int) $args[4]; |
|
2132 |
||
2133 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2134 |
return $this->error; |
|
2135 |
||
5 | 2136 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2137 |
do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
2138 |
||
2139 |
if ( ! taxonomy_exists( $taxonomy ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 2141 |
|
2142 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2143 |
$term = get_term( $term_id, $taxonomy->name ); |
|
2144 |
||
2145 |
if ( is_wp_error( $term ) ) |
|
2146 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
2147 |
||
2148 |
if ( ! $term ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2149 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2151 |
if ( ! current_user_can( 'delete_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2152 |
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
|
2153 |
} |
0 | 2154 |
|
2155 |
$result = wp_delete_term( $term_id, $taxonomy->name ); |
|
2156 |
||
2157 |
if ( is_wp_error( $result ) ) |
|
2158 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
2159 |
||
2160 |
if ( ! $result ) |
|
2161 |
return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
|
2162 |
||
2163 |
return $result; |
|
2164 |
} |
|
2165 |
||
2166 |
/** |
|
2167 |
* Retrieve a term. |
|
2168 |
* |
|
2169 |
* @since 3.4.0 |
|
2170 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2171 |
* @see get_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2179 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2180 |
* @type string $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2181 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
* @return array|IXR_Error IXR_Error on failure, array on success, containing: |
0 | 2183 |
* - 'term_id' |
2184 |
* - 'name' |
|
2185 |
* - 'slug' |
|
2186 |
* - 'term_group' |
|
2187 |
* - 'term_taxonomy_id' |
|
2188 |
* - 'taxonomy' |
|
2189 |
* - 'description' |
|
2190 |
* - 'parent' |
|
2191 |
* - 'count' |
|
2192 |
*/ |
|
5 | 2193 |
public function wp_getTerm( $args ) { |
0 | 2194 |
if ( ! $this->minimum_args( $args, 5 ) ) |
2195 |
return $this->error; |
|
2196 |
||
2197 |
$this->escape( $args ); |
|
2198 |
||
2199 |
$username = $args[1]; |
|
2200 |
$password = $args[2]; |
|
2201 |
$taxonomy = $args[3]; |
|
2202 |
$term_id = (int) $args[4]; |
|
2203 |
||
2204 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2205 |
return $this->error; |
|
2206 |
||
5 | 2207 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2208 |
do_action( 'xmlrpc_call', 'wp.getTerm' ); |
2209 |
||
2210 |
if ( ! taxonomy_exists( $taxonomy ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 2212 |
|
2213 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2214 |
||
2215 |
$term = get_term( $term_id , $taxonomy->name, ARRAY_A ); |
|
2216 |
||
2217 |
if ( is_wp_error( $term ) ) |
|
2218 |
return new IXR_Error( 500, $term->get_error_message() ); |
|
2219 |
||
2220 |
if ( ! $term ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
if ( ! current_user_can( 'assign_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2224 |
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
|
2225 |
} |
0 | 2226 |
|
2227 |
return $this->_prepare_term( $term ); |
|
2228 |
} |
|
2229 |
||
2230 |
/** |
|
2231 |
* Retrieve all terms for a taxonomy. |
|
2232 |
* |
|
2233 |
* @since 3.4.0 |
|
2234 |
* |
|
2235 |
* The optional $filter parameter modifies the query used to retrieve terms. |
|
2236 |
* Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
|
2237 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
* @see get_terms() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2247 |
* @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
|
2248 |
* '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
|
2249 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
* @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
0 | 2251 |
*/ |
5 | 2252 |
public function wp_getTerms( $args ) { |
0 | 2253 |
if ( ! $this->minimum_args( $args, 4 ) ) |
2254 |
return $this->error; |
|
2255 |
||
2256 |
$this->escape( $args ); |
|
2257 |
||
2258 |
$username = $args[1]; |
|
2259 |
$password = $args[2]; |
|
2260 |
$taxonomy = $args[3]; |
|
2261 |
$filter = isset( $args[4] ) ? $args[4] : array(); |
|
2262 |
||
2263 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2264 |
return $this->error; |
|
2265 |
||
5 | 2266 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2267 |
do_action( 'xmlrpc_call', 'wp.getTerms' ); |
2268 |
||
2269 |
if ( ! taxonomy_exists( $taxonomy ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 2271 |
|
2272 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2273 |
||
2274 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
0 | 2276 |
|
2277 |
$query = array(); |
|
2278 |
||
2279 |
if ( isset( $filter['number'] ) ) |
|
2280 |
$query['number'] = absint( $filter['number'] ); |
|
2281 |
||
2282 |
if ( isset( $filter['offset'] ) ) |
|
2283 |
$query['offset'] = absint( $filter['offset'] ); |
|
2284 |
||
2285 |
if ( isset( $filter['orderby'] ) ) { |
|
2286 |
$query['orderby'] = $filter['orderby']; |
|
2287 |
||
2288 |
if ( isset( $filter['order'] ) ) |
|
2289 |
$query['order'] = $filter['order']; |
|
2290 |
} |
|
2291 |
||
2292 |
if ( isset( $filter['hide_empty'] ) ) |
|
2293 |
$query['hide_empty'] = $filter['hide_empty']; |
|
2294 |
else |
|
2295 |
$query['get'] = 'all'; |
|
2296 |
||
2297 |
if ( isset( $filter['search'] ) ) |
|
2298 |
$query['search'] = $filter['search']; |
|
2299 |
||
2300 |
$terms = get_terms( $taxonomy->name, $query ); |
|
2301 |
||
2302 |
if ( is_wp_error( $terms ) ) |
|
2303 |
return new IXR_Error( 500, $terms->get_error_message() ); |
|
2304 |
||
2305 |
$struct = array(); |
|
2306 |
||
2307 |
foreach ( $terms as $term ) { |
|
2308 |
$struct[] = $this->_prepare_term( $term ); |
|
2309 |
} |
|
2310 |
||
2311 |
return $struct; |
|
2312 |
} |
|
2313 |
||
2314 |
/** |
|
2315 |
* Retrieve a taxonomy. |
|
2316 |
* |
|
2317 |
* @since 3.4.0 |
|
2318 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
* @see get_taxonomy() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
* Method arguments. Note: arguments must be ordered as documented. |
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 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2327 |
* @type string $taxnomy Taxonomy name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2328 |
* @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
|
2329 |
* Accepts 'labels', 'cap', 'menu', and 'object_type'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2330 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
* @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
0 | 2333 |
*/ |
5 | 2334 |
public function wp_getTaxonomy( $args ) { |
0 | 2335 |
if ( ! $this->minimum_args( $args, 4 ) ) |
2336 |
return $this->error; |
|
2337 |
||
2338 |
$this->escape( $args ); |
|
2339 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
$taxonomy = $args[3]; |
0 | 2343 |
|
5 | 2344 |
if ( isset( $args[4] ) ) { |
0 | 2345 |
$fields = $args[4]; |
5 | 2346 |
} else { |
2347 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2348 |
* Filters the taxonomy query fields used by the given XML-RPC method. |
5 | 2349 |
* |
2350 |
* @since 3.4.0 |
|
2351 |
* |
|
2352 |
* @param array $fields An array of taxonomy fields to retrieve. |
|
2353 |
* @param string $method The method name. |
|
2354 |
*/ |
|
0 | 2355 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
5 | 2356 |
} |
0 | 2357 |
|
2358 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2359 |
return $this->error; |
|
2360 |
||
5 | 2361 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2362 |
do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2363 |
||
2364 |
if ( ! taxonomy_exists( $taxonomy ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
0 | 2366 |
|
2367 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2368 |
||
2369 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2370 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
0 | 2371 |
|
2372 |
return $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2373 |
} |
|
2374 |
||
2375 |
/** |
|
2376 |
* Retrieve all taxonomies. |
|
2377 |
* |
|
2378 |
* @since 3.4.0 |
|
2379 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2380 |
* @see get_taxonomies() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2381 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2382 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2383 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2384 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2385 |
* @type int $blog_id Blog ID (unused). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2388 |
* @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
|
2389 |
* @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
|
2390 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
* @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
|
2392 |
* by `$fields`, or an IXR_Error instance on failure. |
0 | 2393 |
*/ |
5 | 2394 |
public function wp_getTaxonomies( $args ) { |
0 | 2395 |
if ( ! $this->minimum_args( $args, 3 ) ) |
2396 |
return $this->error; |
|
2397 |
||
2398 |
$this->escape( $args ); |
|
2399 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 2403 |
|
5 | 2404 |
if ( isset( $args[4] ) ) { |
0 | 2405 |
$fields = $args[4]; |
5 | 2406 |
} else { |
2407 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2408 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
5 | 2409 |
} |
0 | 2410 |
|
2411 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2412 |
return $this->error; |
|
2413 |
||
5 | 2414 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2415 |
do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
2416 |
||
2417 |
$taxonomies = get_taxonomies( $filter, 'objects' ); |
|
2418 |
||
2419 |
// holds all the taxonomy data |
|
2420 |
$struct = array(); |
|
2421 |
||
2422 |
foreach ( $taxonomies as $taxonomy ) { |
|
2423 |
// capability check for post_types |
|
2424 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
|
2425 |
continue; |
|
2426 |
||
2427 |
$struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2428 |
} |
|
2429 |
||
2430 |
return $struct; |
|
2431 |
} |
|
2432 |
||
2433 |
/** |
|
2434 |
* Retrieve a user. |
|
2435 |
* |
|
2436 |
* The optional $fields parameter specifies what fields will be included |
|
2437 |
* in the response array. This should be a list of field names. 'user_id' will |
|
2438 |
* always be included in the response regardless of the value of $fields. |
|
2439 |
* |
|
2440 |
* Instead of, or in addition to, individual field names, conceptual group |
|
2441 |
* names can be used to specify multiple fields. The available conceptual |
|
2442 |
* groups are 'basic' and 'all'. |
|
2443 |
* |
|
2444 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2445 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2446 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2448 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2449 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2450 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2451 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2452 |
* @type int $user_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
* } |
5 | 2455 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 2456 |
* - 'user_id' |
2457 |
* - 'username' |
|
2458 |
* - 'first_name' |
|
2459 |
* - 'last_name' |
|
2460 |
* - 'registered' |
|
2461 |
* - 'bio' |
|
2462 |
* - 'email' |
|
2463 |
* - 'nickname' |
|
2464 |
* - 'nicename' |
|
2465 |
* - 'url' |
|
2466 |
* - 'display_name' |
|
2467 |
* - 'roles' |
|
2468 |
*/ |
|
5 | 2469 |
public function wp_getUser( $args ) { |
0 | 2470 |
if ( ! $this->minimum_args( $args, 4 ) ) |
2471 |
return $this->error; |
|
2472 |
||
2473 |
$this->escape( $args ); |
|
2474 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2475 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2476 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
$user_id = (int) $args[3]; |
0 | 2478 |
|
5 | 2479 |
if ( isset( $args[4] ) ) { |
0 | 2480 |
$fields = $args[4]; |
5 | 2481 |
} else { |
2482 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2483 |
* Filters the default user query fields used by the given XML-RPC method. |
5 | 2484 |
* |
2485 |
* @since 3.5.0 |
|
2486 |
* |
|
2487 |
* @param array $fields User query fields for given method. Default 'all'. |
|
2488 |
* @param string $method The method name. |
|
2489 |
*/ |
|
0 | 2490 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
5 | 2491 |
} |
0 | 2492 |
|
2493 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2494 |
return $this->error; |
|
2495 |
||
5 | 2496 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2497 |
do_action( 'xmlrpc_call', 'wp.getUser' ); |
2498 |
||
2499 |
if ( ! current_user_can( 'edit_user', $user_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2500 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
0 | 2501 |
|
2502 |
$user_data = get_userdata( $user_id ); |
|
2503 |
||
2504 |
if ( ! $user_data ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2505 |
return new IXR_Error( 404, __( 'Invalid user ID.' ) ); |
0 | 2506 |
|
2507 |
return $this->_prepare_user( $user_data, $fields ); |
|
2508 |
} |
|
2509 |
||
2510 |
/** |
|
2511 |
* Retrieve users. |
|
2512 |
* |
|
2513 |
* The optional $filter parameter modifies the query used to retrieve users. |
|
2514 |
* Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', |
|
2515 |
* 'who', 'orderby', and 'order'. |
|
2516 |
* |
|
2517 |
* The optional $fields parameter specifies what fields will be included |
|
2518 |
* in the response array. |
|
2519 |
* |
|
2520 |
* @uses get_users() |
|
2521 |
* @see wp_getUser() for more on $fields and return values |
|
2522 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2523 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2524 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2525 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2530 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2531 |
* } |
5 | 2532 |
* @return array|IXR_Error users data |
0 | 2533 |
*/ |
5 | 2534 |
public function wp_getUsers( $args ) { |
0 | 2535 |
if ( ! $this->minimum_args( $args, 3 ) ) |
2536 |
return $this->error; |
|
2537 |
||
2538 |
$this->escape( $args ); |
|
2539 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2540 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2541 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2542 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 2543 |
|
5 | 2544 |
if ( isset( $args[4] ) ) { |
0 | 2545 |
$fields = $args[4]; |
5 | 2546 |
} else { |
2547 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2548 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
5 | 2549 |
} |
0 | 2550 |
|
2551 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2552 |
return $this->error; |
|
2553 |
||
5 | 2554 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2555 |
do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2556 |
||
2557 |
if ( ! current_user_can( 'list_users' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2558 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
0 | 2559 |
|
2560 |
$query = array( 'fields' => 'all_with_meta' ); |
|
2561 |
||
2562 |
$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50; |
|
2563 |
$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0; |
|
2564 |
||
2565 |
if ( isset( $filter['orderby'] ) ) { |
|
2566 |
$query['orderby'] = $filter['orderby']; |
|
2567 |
||
2568 |
if ( isset( $filter['order'] ) ) |
|
2569 |
$query['order'] = $filter['order']; |
|
2570 |
} |
|
2571 |
||
2572 |
if ( isset( $filter['role'] ) ) { |
|
2573 |
if ( get_role( $filter['role'] ) === null ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
return new IXR_Error( 403, __( 'Invalid role.' ) ); |
0 | 2575 |
|
2576 |
$query['role'] = $filter['role']; |
|
2577 |
} |
|
2578 |
||
2579 |
if ( isset( $filter['who'] ) ) { |
|
2580 |
$query['who'] = $filter['who']; |
|
2581 |
} |
|
2582 |
||
2583 |
$users = get_users( $query ); |
|
2584 |
||
2585 |
$_users = array(); |
|
2586 |
foreach ( $users as $user_data ) { |
|
2587 |
if ( current_user_can( 'edit_user', $user_data->ID ) ) |
|
2588 |
$_users[] = $this->_prepare_user( $user_data, $fields ); |
|
2589 |
} |
|
2590 |
return $_users; |
|
2591 |
} |
|
2592 |
||
2593 |
/** |
|
2594 |
* Retrieve information about the requesting user. |
|
2595 |
* |
|
2596 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2597 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2601 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
* } |
5 | 2606 |
* @return array|IXR_Error (@see wp_getUser) |
0 | 2607 |
*/ |
5 | 2608 |
public function wp_getProfile( $args ) { |
0 | 2609 |
if ( ! $this->minimum_args( $args, 3 ) ) |
2610 |
return $this->error; |
|
2611 |
||
2612 |
$this->escape( $args ); |
|
2613 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
$password = $args[2]; |
0 | 2616 |
|
5 | 2617 |
if ( isset( $args[3] ) ) { |
0 | 2618 |
$fields = $args[3]; |
5 | 2619 |
} else { |
2620 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2621 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
5 | 2622 |
} |
0 | 2623 |
|
2624 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2625 |
return $this->error; |
|
2626 |
||
5 | 2627 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2628 |
do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2629 |
||
2630 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2631 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
0 | 2632 |
|
2633 |
$user_data = get_userdata( $user->ID ); |
|
2634 |
||
2635 |
return $this->_prepare_user( $user_data, $fields ); |
|
2636 |
} |
|
2637 |
||
2638 |
/** |
|
2639 |
* Edit user's profile. |
|
2640 |
* |
|
2641 |
* @uses wp_update_user() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2642 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2643 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2645 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
* @type array $content_struct It can optionally contain: |
0 | 2650 |
* - 'first_name' |
2651 |
* - 'last_name' |
|
2652 |
* - 'website' |
|
2653 |
* - 'display_name' |
|
2654 |
* - 'nickname' |
|
2655 |
* - 'nicename' |
|
2656 |
* - 'bio' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2657 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
* @return true|IXR_Error True, on success. |
0 | 2659 |
*/ |
5 | 2660 |
public function wp_editProfile( $args ) { |
0 | 2661 |
if ( ! $this->minimum_args( $args, 4 ) ) |
2662 |
return $this->error; |
|
2663 |
||
2664 |
$this->escape( $args ); |
|
2665 |
||
2666 |
$username = $args[1]; |
|
2667 |
$password = $args[2]; |
|
2668 |
$content_struct = $args[3]; |
|
2669 |
||
2670 |
if ( ! $user = $this->login( $username, $password ) ) |
|
2671 |
return $this->error; |
|
2672 |
||
5 | 2673 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 2674 |
do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2675 |
||
2676 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
0 | 2678 |
|
2679 |
// holds data of the user |
|
2680 |
$user_data = array(); |
|
2681 |
$user_data['ID'] = $user->ID; |
|
2682 |
||
2683 |
// only set the user details if it was given |
|
2684 |
if ( isset( $content_struct['first_name'] ) ) |
|
2685 |
$user_data['first_name'] = $content_struct['first_name']; |
|
2686 |
||
2687 |
if ( isset( $content_struct['last_name'] ) ) |
|
2688 |
$user_data['last_name'] = $content_struct['last_name']; |
|
2689 |
||
2690 |
if ( isset( $content_struct['url'] ) ) |
|
2691 |
$user_data['user_url'] = $content_struct['url']; |
|
2692 |
||
2693 |
if ( isset( $content_struct['display_name'] ) ) |
|
2694 |
$user_data['display_name'] = $content_struct['display_name']; |
|
2695 |
||
2696 |
if ( isset( $content_struct['nickname'] ) ) |
|
2697 |
$user_data['nickname'] = $content_struct['nickname']; |
|
2698 |
||
2699 |
if ( isset( $content_struct['nicename'] ) ) |
|
2700 |
$user_data['user_nicename'] = $content_struct['nicename']; |
|
2701 |
||
2702 |
if ( isset( $content_struct['bio'] ) ) |
|
2703 |
$user_data['description'] = $content_struct['bio']; |
|
2704 |
||
2705 |
$result = wp_update_user( $user_data ); |
|
2706 |
||
2707 |
if ( is_wp_error( $result ) ) |
|
2708 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
2709 |
||
2710 |
if ( ! $result ) |
|
2711 |
return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) ); |
|
2712 |
||
2713 |
return true; |
|
2714 |
} |
|
2715 |
||
2716 |
/** |
|
2717 |
* Retrieve page. |
|
2718 |
* |
|
2719 |
* @since 2.2.0 |
|
2720 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2721 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2722 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2723 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2724 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2725 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2726 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2727 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
* } |
5 | 2729 |
* @return array|IXR_Error |
0 | 2730 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2731 |
public function wp_getPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2732 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2733 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2734 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2735 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2736 |
$password = $args[3]; |
0 | 2737 |
|
2738 |
if ( !$user = $this->login($username, $password) ) { |
|
2739 |
return $this->error; |
|
2740 |
} |
|
2741 |
||
2742 |
$page = get_post($page_id); |
|
2743 |
if ( ! $page ) |
|
2744 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
2745 |
||
2746 |
if ( !current_user_can( 'edit_page', $page_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2747 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
0 | 2748 |
|
5 | 2749 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2750 |
do_action( 'xmlrpc_call', 'wp.getPage' ); |
|
0 | 2751 |
|
2752 |
// If we found the page then format the data. |
|
2753 |
if ( $page->ID && ($page->post_type == 'page') ) { |
|
2754 |
return $this->_prepare_page( $page ); |
|
2755 |
} |
|
2756 |
// If the page doesn't exist indicate that. |
|
2757 |
else { |
|
5 | 2758 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2759 |
} |
2760 |
} |
|
2761 |
||
2762 |
/** |
|
2763 |
* Retrieve Pages. |
|
2764 |
* |
|
2765 |
* @since 2.2.0 |
|
2766 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2768 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2769 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2771 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2772 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2773 |
* @type int $num_pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
* } |
5 | 2775 |
* @return array|IXR_Error |
0 | 2776 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2777 |
public function wp_getPages( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2779 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2780 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2781 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2782 |
$num_pages = isset($args[3]) ? (int) $args[3] : 10; |
0 | 2783 |
|
2784 |
if ( !$user = $this->login($username, $password) ) |
|
2785 |
return $this->error; |
|
2786 |
||
2787 |
if ( !current_user_can( 'edit_pages' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
0 | 2789 |
|
5 | 2790 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2791 |
do_action( 'xmlrpc_call', 'wp.getPages' ); |
|
0 | 2792 |
|
2793 |
$pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) ); |
|
2794 |
$num_pages = count($pages); |
|
2795 |
||
2796 |
// If we have pages, put together their info. |
|
2797 |
if ( $num_pages >= 1 ) { |
|
2798 |
$pages_struct = array(); |
|
2799 |
||
2800 |
foreach ($pages as $page) { |
|
2801 |
if ( current_user_can( 'edit_page', $page->ID ) ) |
|
2802 |
$pages_struct[] = $this->_prepare_page( $page ); |
|
2803 |
} |
|
2804 |
||
5 | 2805 |
return $pages_struct; |
0 | 2806 |
} |
5 | 2807 |
|
2808 |
return array(); |
|
0 | 2809 |
} |
2810 |
||
2811 |
/** |
|
2812 |
* Create new page. |
|
2813 |
* |
|
2814 |
* @since 2.2.0 |
|
2815 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
* @see wp_xmlrpc_server::mw_newPost() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2819 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2823 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2824 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2825 |
* } |
5 | 2826 |
* @return int|IXR_Error |
0 | 2827 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
public function wp_newPage( $args ) { |
0 | 2829 |
// 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
|
2830 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2831 |
$password = $this->escape( $args[2] ); |
0 | 2832 |
|
2833 |
if ( !$user = $this->login($username, $password) ) |
|
2834 |
return $this->error; |
|
2835 |
||
5 | 2836 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2837 |
do_action( 'xmlrpc_call', 'wp.newPage' ); |
|
0 | 2838 |
|
2839 |
// Mark this as content for a page. |
|
2840 |
$args[3]["post_type"] = 'page'; |
|
2841 |
||
2842 |
// Let mw_newPost do all of the heavy lifting. |
|
5 | 2843 |
return $this->mw_newPost( $args ); |
0 | 2844 |
} |
2845 |
||
2846 |
/** |
|
2847 |
* Delete page. |
|
2848 |
* |
|
2849 |
* @since 2.2.0 |
|
2850 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2856 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
* @return true|IXR_Error True, if success. |
0 | 2860 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
public function wp_deletePage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
$page_id = (int) $args[3]; |
0 | 2867 |
|
2868 |
if ( !$user = $this->login($username, $password) ) |
|
2869 |
return $this->error; |
|
2870 |
||
5 | 2871 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2872 |
do_action( 'xmlrpc_call', 'wp.deletePage' ); |
|
0 | 2873 |
|
2874 |
// Get the current page based on the page_id and |
|
2875 |
// make sure it is a page and not a post. |
|
2876 |
$actual_page = get_post($page_id, ARRAY_A); |
|
2877 |
if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
|
5 | 2878 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2879 |
|
2880 |
// Make sure the user can delete pages. |
|
2881 |
if ( !current_user_can('delete_page', $page_id) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) ); |
0 | 2883 |
|
2884 |
// Attempt to delete the page. |
|
2885 |
$result = wp_delete_post($page_id); |
|
2886 |
if ( !$result ) |
|
5 | 2887 |
return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
2888 |
||
2889 |
/** |
|
2890 |
* Fires after a page has been successfully deleted via XML-RPC. |
|
2891 |
* |
|
2892 |
* @since 3.4.0 |
|
2893 |
* |
|
2894 |
* @param int $page_id ID of the deleted page. |
|
2895 |
* @param array $args An array of arguments to delete the page. |
|
2896 |
*/ |
|
0 | 2897 |
do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); |
2898 |
||
5 | 2899 |
return true; |
0 | 2900 |
} |
2901 |
||
2902 |
/** |
|
2903 |
* Edit page. |
|
2904 |
* |
|
2905 |
* @since 2.2.0 |
|
2906 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2907 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2910 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
* @type int $page_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2913 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
* } |
5 | 2917 |
* @return array|IXR_Error |
0 | 2918 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
public function wp_editPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
// Items will be escaped in mw_editPost. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
$publish = $args[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
$escaped_username = $this->escape( $username ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2928 |
$escaped_password = $this->escape( $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
if ( !$user = $this->login( $escaped_username, $escaped_password ) ) { |
0 | 2931 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
} |
0 | 2933 |
|
5 | 2934 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2935 |
do_action( 'xmlrpc_call', 'wp.editPage' ); |
|
0 | 2936 |
|
2937 |
// Get the page data and make sure it is a page. |
|
2938 |
$actual_page = get_post($page_id, ARRAY_A); |
|
2939 |
if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
|
5 | 2940 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 2941 |
|
2942 |
// Make sure the user is allowed to edit pages. |
|
2943 |
if ( !current_user_can('edit_page', $page_id) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2944 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
0 | 2945 |
|
2946 |
// Mark this as content for a page. |
|
2947 |
$content['post_type'] = 'page'; |
|
2948 |
||
2949 |
// Arrange args in the way mw_editPost understands. |
|
2950 |
$args = array( |
|
2951 |
$page_id, |
|
2952 |
$username, |
|
2953 |
$password, |
|
2954 |
$content, |
|
2955 |
$publish |
|
2956 |
); |
|
2957 |
||
2958 |
// Let mw_editPost do all of the heavy lifting. |
|
5 | 2959 |
return $this->mw_editPost( $args ); |
0 | 2960 |
} |
2961 |
||
2962 |
/** |
|
2963 |
* Retrieve page list. |
|
2964 |
* |
|
2965 |
* @since 2.2.0 |
|
2966 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2969 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2970 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2974 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2975 |
* } |
5 | 2976 |
* @return array|IXR_Error |
0 | 2977 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
public function wp_getPageList( $args ) { |
0 | 2979 |
global $wpdb; |
2980 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
$password = $args[2]; |
0 | 2985 |
|
2986 |
if ( !$user = $this->login($username, $password) ) |
|
2987 |
return $this->error; |
|
2988 |
||
2989 |
if ( !current_user_can( 'edit_pages' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
0 | 2991 |
|
5 | 2992 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2993 |
do_action( 'xmlrpc_call', 'wp.getPageList' ); |
|
0 | 2994 |
|
2995 |
// Get list of pages ids and titles |
|
2996 |
$page_list = $wpdb->get_results(" |
|
2997 |
SELECT ID page_id, |
|
2998 |
post_title page_title, |
|
2999 |
post_parent page_parent_id, |
|
3000 |
post_date_gmt, |
|
3001 |
post_date, |
|
3002 |
post_status |
|
3003 |
FROM {$wpdb->posts} |
|
3004 |
WHERE post_type = 'page' |
|
3005 |
ORDER BY ID |
|
3006 |
"); |
|
3007 |
||
3008 |
// The date needs to be formatted properly. |
|
3009 |
$num_pages = count($page_list); |
|
3010 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
|
3011 |
$page_list[$i]->dateCreated = $this->_convert_date( $page_list[$i]->post_date ); |
|
3012 |
$page_list[$i]->date_created_gmt = $this->_convert_date_gmt( $page_list[$i]->post_date_gmt, $page_list[$i]->post_date ); |
|
3013 |
||
3014 |
unset($page_list[$i]->post_date_gmt); |
|
3015 |
unset($page_list[$i]->post_date); |
|
3016 |
unset($page_list[$i]->post_status); |
|
3017 |
} |
|
3018 |
||
5 | 3019 |
return $page_list; |
0 | 3020 |
} |
3021 |
||
3022 |
/** |
|
3023 |
* Retrieve authors list. |
|
3024 |
* |
|
3025 |
* @since 2.2.0 |
|
3026 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
* } |
5 | 3034 |
* @return array|IXR_Error |
0 | 3035 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
public function wp_getAuthors( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
$password = $args[2]; |
0 | 3041 |
|
3042 |
if ( !$user = $this->login($username, $password) ) |
|
3043 |
return $this->error; |
|
3044 |
||
3045 |
if ( !current_user_can('edit_posts') ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3046 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
5 | 3047 |
|
3048 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3049 |
do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
|
0 | 3050 |
|
3051 |
$authors = array(); |
|
3052 |
foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user ) { |
|
3053 |
$authors[] = array( |
|
3054 |
'user_id' => $user->ID, |
|
3055 |
'user_login' => $user->user_login, |
|
3056 |
'display_name' => $user->display_name |
|
3057 |
); |
|
3058 |
} |
|
3059 |
||
3060 |
return $authors; |
|
3061 |
} |
|
3062 |
||
3063 |
/** |
|
3064 |
* Get list of all tags |
|
3065 |
* |
|
3066 |
* @since 2.7.0 |
|
3067 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
* } |
5 | 3075 |
* @return array|IXR_Error |
0 | 3076 |
*/ |
5 | 3077 |
public function wp_getTags( $args ) { |
0 | 3078 |
$this->escape( $args ); |
3079 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
$password = $args[2]; |
0 | 3082 |
|
3083 |
if ( !$user = $this->login($username, $password) ) |
|
3084 |
return $this->error; |
|
3085 |
||
3086 |
if ( !current_user_can( 'edit_posts' ) ) |
|
3087 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
|
3088 |
||
5 | 3089 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 3090 |
do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
3091 |
||
3092 |
$tags = array(); |
|
3093 |
||
3094 |
if ( $all_tags = get_tags() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3095 |
foreach ( (array) $all_tags as $tag ) { |
5 | 3096 |
$struct = array(); |
0 | 3097 |
$struct['tag_id'] = $tag->term_id; |
3098 |
$struct['name'] = $tag->name; |
|
3099 |
$struct['count'] = $tag->count; |
|
3100 |
$struct['slug'] = $tag->slug; |
|
3101 |
$struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
|
3102 |
$struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) ); |
|
3103 |
||
3104 |
$tags[] = $struct; |
|
3105 |
} |
|
3106 |
} |
|
3107 |
||
3108 |
return $tags; |
|
3109 |
} |
|
3110 |
||
3111 |
/** |
|
3112 |
* Create new category. |
|
3113 |
* |
|
3114 |
* @since 2.2.0 |
|
3115 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
* } |
5 | 3124 |
* @return int|IXR_Error Category ID. |
0 | 3125 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
public function wp_newCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
$this->escape( $args ); |
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 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
$category = $args[3]; |
0 | 3132 |
|
3133 |
if ( !$user = $this->login($username, $password) ) |
|
3134 |
return $this->error; |
|
3135 |
||
5 | 3136 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3137 |
do_action( 'xmlrpc_call', 'wp.newCategory' ); |
|
0 | 3138 |
|
3139 |
// 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
|
3140 |
if ( ! current_user_can( 'manage_categories' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
} |
0 | 3143 |
|
3144 |
// If no slug was provided make it empty so that |
|
3145 |
// WordPress will generate one. |
|
3146 |
if ( empty($category['slug']) ) |
|
3147 |
$category['slug'] = ''; |
|
3148 |
||
3149 |
// If no parent_id was provided make it empty |
|
3150 |
// so that it will be a top level page (no parent). |
|
3151 |
if ( !isset($category['parent_id']) ) |
|
3152 |
$category['parent_id'] = ''; |
|
3153 |
||
3154 |
// If no description was provided make it empty. |
|
3155 |
if ( empty($category["description"]) ) |
|
3156 |
$category["description"] = ""; |
|
3157 |
||
3158 |
$new_category = array( |
|
3159 |
'cat_name' => $category['name'], |
|
3160 |
'category_nicename' => $category['slug'], |
|
3161 |
'category_parent' => $category['parent_id'], |
|
3162 |
'category_description' => $category['description'] |
|
3163 |
); |
|
3164 |
||
3165 |
$cat_id = wp_insert_category($new_category, true); |
|
3166 |
if ( is_wp_error( $cat_id ) ) { |
|
3167 |
if ( 'term_exists' == $cat_id->get_error_code() ) |
|
3168 |
return (int) $cat_id->get_error_data(); |
|
3169 |
else |
|
5 | 3170 |
return new IXR_Error(500, __('Sorry, the new category failed.')); |
0 | 3171 |
} elseif ( ! $cat_id ) { |
5 | 3172 |
return new IXR_Error(500, __('Sorry, the new category failed.')); |
0 | 3173 |
} |
3174 |
||
5 | 3175 |
/** |
3176 |
* Fires after a new category has been successfully created via XML-RPC. |
|
3177 |
* |
|
3178 |
* @since 3.4.0 |
|
3179 |
* |
|
3180 |
* @param int $cat_id ID of the new category. |
|
3181 |
* @param array $args An array of new category arguments. |
|
3182 |
*/ |
|
0 | 3183 |
do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); |
3184 |
||
3185 |
return $cat_id; |
|
3186 |
} |
|
3187 |
||
3188 |
/** |
|
3189 |
* Remove category. |
|
3190 |
* |
|
3191 |
* @since 2.5.0 |
|
3192 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
* @type int $category_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
* @return bool|IXR_Error See wp_delete_term() for return info. |
0 | 3202 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
public function wp_deleteCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3206 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
$category_id = (int) $args[3]; |
0 | 3209 |
|
3210 |
if ( !$user = $this->login($username, $password) ) |
|
3211 |
return $this->error; |
|
3212 |
||
5 | 3213 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3214 |
do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
|
0 | 3215 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3216 |
if ( ! current_user_can( 'delete_term', $category_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
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
|
3218 |
} |
0 | 3219 |
|
3220 |
$status = wp_delete_term( $category_id, 'category' ); |
|
3221 |
||
5 | 3222 |
if ( true == $status ) { |
3223 |
/** |
|
3224 |
* Fires after a category has been successfully deleted via XML-RPC. |
|
3225 |
* |
|
3226 |
* @since 3.4.0 |
|
3227 |
* |
|
3228 |
* @param int $category_id ID of the deleted category. |
|
3229 |
* @param array $args An array of arguments to delete the category. |
|
3230 |
*/ |
|
0 | 3231 |
do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); |
5 | 3232 |
} |
0 | 3233 |
|
3234 |
return $status; |
|
3235 |
} |
|
3236 |
||
3237 |
/** |
|
3238 |
* Retrieve category list. |
|
3239 |
* |
|
3240 |
* @since 2.2.0 |
|
3241 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3244 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3248 |
* @type array $category |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
* @type int $max_results |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
* } |
5 | 3251 |
* @return array|IXR_Error |
0 | 3252 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
public function wp_suggestCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
$category = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
$max_results = (int) $args[4]; |
0 | 3260 |
|
3261 |
if ( !$user = $this->login($username, $password) ) |
|
3262 |
return $this->error; |
|
3263 |
||
3264 |
if ( !current_user_can( 'edit_posts' ) ) |
|
5 | 3265 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
3266 |
||
3267 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3268 |
do_action( 'xmlrpc_call', 'wp.suggestCategories' ); |
|
0 | 3269 |
|
3270 |
$category_suggestions = array(); |
|
3271 |
$args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); |
|
3272 |
foreach ( (array) get_categories($args) as $cat ) { |
|
3273 |
$category_suggestions[] = array( |
|
3274 |
'category_id' => $cat->term_id, |
|
3275 |
'category_name' => $cat->name |
|
3276 |
); |
|
3277 |
} |
|
3278 |
||
5 | 3279 |
return $category_suggestions; |
0 | 3280 |
} |
3281 |
||
3282 |
/** |
|
3283 |
* Retrieve comment. |
|
3284 |
* |
|
3285 |
* @since 2.7.0 |
|
3286 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3291 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
* @type int $comment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
* } |
5 | 3295 |
* @return array|IXR_Error |
0 | 3296 |
*/ |
5 | 3297 |
public function wp_getComment($args) { |
0 | 3298 |
$this->escape($args); |
3299 |
||
3300 |
$username = $args[1]; |
|
3301 |
$password = $args[2]; |
|
3302 |
$comment_id = (int) $args[3]; |
|
3303 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3305 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
} |
0 | 3307 |
|
5 | 3308 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3309 |
do_action( 'xmlrpc_call', 'wp.getComment' ); |
|
0 | 3310 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3311 |
if ( ! $comment = get_comment( $comment_id ) ) { |
0 | 3312 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
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
|
3317 |
} |
0 | 3318 |
|
3319 |
return $this->_prepare_comment( $comment ); |
|
3320 |
} |
|
3321 |
||
3322 |
/** |
|
3323 |
* Retrieve comments. |
|
3324 |
* |
|
5 | 3325 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 3326 |
* array as last argument. |
3327 |
* |
|
3328 |
* Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
|
3329 |
* |
|
3330 |
* The defaults are as follows: |
|
3331 |
* - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
|
3332 |
* - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
|
3333 |
* - '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
|
3334 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 3335 |
* |
3336 |
* @since 2.7.0 |
|
3337 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3340 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3341 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3343 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3344 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3345 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
* @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents |
0 | 3347 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3348 |
public function wp_getComments( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3349 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3351 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3353 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3356 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
} |
0 | 3358 |
|
5 | 3359 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3360 |
do_action( 'xmlrpc_call', 'wp.getComments' ); |
|
0 | 3361 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3362 |
if ( isset( $struct['status'] ) ) { |
0 | 3363 |
$status = $struct['status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3364 |
} else { |
0 | 3365 |
$status = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3366 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3368 |
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
} |
0 | 3371 |
|
3372 |
$post_id = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
if ( isset( $struct['post_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
$post_id = absint( $struct['post_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
$post_type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
if ( isset( $struct['post_type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
$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
|
3380 |
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
|
3381 |
return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
$post_type = $struct['post_type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
} |
0 | 3385 |
|
3386 |
$offset = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
if ( isset( $struct['offset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
$offset = absint( $struct['offset'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
} |
0 | 3390 |
|
3391 |
$number = 10; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
if ( isset( $struct['number'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
$number = absint( $struct['number'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
$comments = get_comments( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
'status' => $status, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
'post_id' => $post_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3399 |
'offset' => $offset, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
'number' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
'post_type' => $post_type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
) ); |
0 | 3403 |
|
3404 |
$comments_struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
$comments_struct[] = $this->_prepare_comment( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
} |
0 | 3409 |
} |
3410 |
||
3411 |
return $comments_struct; |
|
3412 |
} |
|
3413 |
||
3414 |
/** |
|
3415 |
* Delete a comment. |
|
3416 |
* |
|
3417 |
* 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
|
3418 |
* See wp_delete_comment() for more information on this behavior. |
0 | 3419 |
* |
3420 |
* @since 2.7.0 |
|
3421 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
* @type int $comment_ID |
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 |
* @return bool|IXR_Error See wp_delete_comment(). |
0 | 3431 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
public function wp_deleteComment( $args ) { |
0 | 3433 |
$this->escape($args); |
3434 |
||
3435 |
$username = $args[1]; |
|
3436 |
$password = $args[2]; |
|
3437 |
$comment_ID = (int) $args[3]; |
|
3438 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3439 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3440 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3441 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3444 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3445 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3446 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3447 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3448 |
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
|
3449 |
} |
0 | 3450 |
|
5 | 3451 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3452 |
do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
|
0 | 3453 |
|
3454 |
$status = wp_delete_comment( $comment_ID ); |
|
3455 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3456 |
if ( $status ) { |
5 | 3457 |
/** |
3458 |
* Fires after a comment has been successfully deleted via XML-RPC. |
|
3459 |
* |
|
3460 |
* @since 3.4.0 |
|
3461 |
* |
|
3462 |
* @param int $comment_ID ID of the deleted comment. |
|
3463 |
* @param array $args An array of arguments to delete the comment. |
|
3464 |
*/ |
|
0 | 3465 |
do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); |
5 | 3466 |
} |
0 | 3467 |
|
3468 |
return $status; |
|
3469 |
} |
|
3470 |
||
3471 |
/** |
|
3472 |
* Edit comment. |
|
3473 |
* |
|
5 | 3474 |
* Besides the common blog_id (unused), username, and password arguments, it takes a |
0 | 3475 |
* comment_id integer and a content_struct array as last argument. |
3476 |
* |
|
3477 |
* The allowed keys in the content_struct array are: |
|
3478 |
* - 'author' |
|
3479 |
* - 'author_url' |
|
3480 |
* - 'author_email' |
|
3481 |
* - 'content' |
|
3482 |
* - 'date_created_gmt' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3483 |
* - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details |
0 | 3484 |
* |
3485 |
* @since 2.7.0 |
|
3486 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3487 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3488 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3490 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3491 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3492 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3493 |
* @type int $comment_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
* @return true|IXR_Error True, on success. |
0 | 3497 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3498 |
public function wp_editComment( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3499 |
$this->escape( $args ); |
0 | 3500 |
|
3501 |
$username = $args[1]; |
|
3502 |
$password = $args[2]; |
|
3503 |
$comment_ID = (int) $args[3]; |
|
3504 |
$content_struct = $args[4]; |
|
3505 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3506 |
if ( !$user = $this->login( $username, $password ) ) { |
0 | 3507 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3508 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
if ( ! get_comment( $comment_ID ) ) { |
0 | 3511 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
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
|
3516 |
} |
0 | 3517 |
|
5 | 3518 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3519 |
do_action( 'xmlrpc_call', 'wp.editComment' ); |
|
0 | 3520 |
|
3521 |
if ( isset($content_struct['status']) ) { |
|
3522 |
$statuses = get_comment_statuses(); |
|
3523 |
$statuses = array_keys($statuses); |
|
3524 |
||
3525 |
if ( ! in_array($content_struct['status'], $statuses) ) |
|
3526 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
|
3527 |
$comment_approved = $content_struct['status']; |
|
3528 |
} |
|
3529 |
||
3530 |
// Do some timestamp voodoo |
|
3531 |
if ( !empty( $content_struct['date_created_gmt'] ) ) { |
|
3532 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force |
|
3533 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
|
3534 |
$comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
|
3535 |
$comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
|
3536 |
} |
|
3537 |
||
3538 |
if ( isset($content_struct['content']) ) |
|
3539 |
$comment_content = $content_struct['content']; |
|
3540 |
||
3541 |
if ( isset($content_struct['author']) ) |
|
3542 |
$comment_author = $content_struct['author']; |
|
3543 |
||
3544 |
if ( isset($content_struct['author_url']) ) |
|
3545 |
$comment_author_url = $content_struct['author_url']; |
|
3546 |
||
3547 |
if ( isset($content_struct['author_email']) ) |
|
3548 |
$comment_author_email = $content_struct['author_email']; |
|
3549 |
||
3550 |
// We've got all the data -- post it: |
|
3551 |
$comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); |
|
3552 |
||
3553 |
$result = wp_update_comment($comment); |
|
3554 |
if ( is_wp_error( $result ) ) |
|
3555 |
return new IXR_Error(500, $result->get_error_message()); |
|
3556 |
||
3557 |
if ( !$result ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
return new IXR_Error(500, __('Sorry, the comment could not be edited.')); |
0 | 3559 |
|
5 | 3560 |
/** |
3561 |
* Fires after a comment has been successfully updated via XML-RPC. |
|
3562 |
* |
|
3563 |
* @since 3.4.0 |
|
3564 |
* |
|
3565 |
* @param int $comment_ID ID of the updated comment. |
|
3566 |
* @param array $args An array of arguments to update the comment. |
|
3567 |
*/ |
|
0 | 3568 |
do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); |
3569 |
||
3570 |
return true; |
|
3571 |
} |
|
3572 |
||
3573 |
/** |
|
3574 |
* Create new comment. |
|
3575 |
* |
|
3576 |
* @since 2.7.0 |
|
3577 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
* @type string|int $post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
* @return int|IXR_Error See wp_new_comment(). |
0 | 3588 |
*/ |
5 | 3589 |
public function wp_newComment($args) { |
0 | 3590 |
$this->escape($args); |
3591 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
$post = $args[3]; |
0 | 3595 |
$content_struct = $args[4]; |
3596 |
||
5 | 3597 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
* Filters whether to allow anonymous comments over XML-RPC. |
5 | 3599 |
* |
3600 |
* @since 2.7.0 |
|
3601 |
* |
|
3602 |
* @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3603 |
* Default false. |
|
3604 |
*/ |
|
3605 |
$allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
|
0 | 3606 |
|
3607 |
$user = $this->login($username, $password); |
|
3608 |
||
3609 |
if ( !$user ) { |
|
3610 |
$logged_in = false; |
|
5 | 3611 |
if ( $allow_anon && get_option('comment_registration') ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
return new IXR_Error( 403, __( 'You must be registered to comment.' ) ); |
5 | 3613 |
} elseif ( ! $allow_anon ) { |
0 | 3614 |
return $this->error; |
5 | 3615 |
} |
0 | 3616 |
} else { |
3617 |
$logged_in = true; |
|
3618 |
} |
|
3619 |
||
3620 |
if ( is_numeric($post) ) |
|
3621 |
$post_id = absint($post); |
|
3622 |
else |
|
3623 |
$post_id = url_to_postid($post); |
|
3624 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3625 |
if ( ! $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
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 ( ! get_post( $post_id ) ) { |
0 | 3630 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3631 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3633 |
if ( ! comments_open( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3634 |
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
|
3635 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
if ( empty( $content_struct['content'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
return new IXR_Error( 403, __( 'Comment is required.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3640 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3641 |
$comment = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3642 |
'comment_post_ID' => $post_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3643 |
'comment_content' => $content_struct['content'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
); |
0 | 3645 |
|
3646 |
if ( $logged_in ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
$display_name = $user->display_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
$user_email = $user->user_email; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
$user_url = $user->user_url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
$comment['comment_author'] = $this->escape( $display_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
$comment['comment_author_email'] = $this->escape( $user_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
$comment['comment_author_url'] = $this->escape( $user_url ); |
0 | 3654 |
$comment['user_ID'] = $user->ID; |
3655 |
} else { |
|
3656 |
$comment['comment_author'] = ''; |
|
3657 |
if ( isset($content_struct['author']) ) |
|
3658 |
$comment['comment_author'] = $content_struct['author']; |
|
3659 |
||
3660 |
$comment['comment_author_email'] = ''; |
|
3661 |
if ( isset($content_struct['author_email']) ) |
|
3662 |
$comment['comment_author_email'] = $content_struct['author_email']; |
|
3663 |
||
3664 |
$comment['comment_author_url'] = ''; |
|
3665 |
if ( isset($content_struct['author_url']) ) |
|
3666 |
$comment['comment_author_url'] = $content_struct['author_url']; |
|
3667 |
||
3668 |
$comment['user_ID'] = 0; |
|
3669 |
||
3670 |
if ( get_option('require_name_email') ) { |
|
3671 |
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
|
3672 |
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
0 | 3673 |
elseif ( !is_email($comment['comment_author_email']) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
0 | 3675 |
} |
3676 |
} |
|
3677 |
||
3678 |
$comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0; |
|
3679 |
||
5 | 3680 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3681 |
do_action( 'xmlrpc_call', 'wp.newComment' ); |
|
0 | 3682 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3683 |
$comment_ID = wp_new_comment( $comment, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3684 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3685 |
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
|
3686 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
if ( ! $comment_ID ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3689 |
return new IXR_Error( 403, __( 'Something went wrong.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
} |
0 | 3691 |
|
5 | 3692 |
/** |
3693 |
* Fires after a new comment has been successfully created via XML-RPC. |
|
3694 |
* |
|
3695 |
* @since 3.4.0 |
|
3696 |
* |
|
3697 |
* @param int $comment_ID ID of the new comment. |
|
3698 |
* @param array $args An array of new comment arguments. |
|
3699 |
*/ |
|
0 | 3700 |
do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); |
3701 |
||
3702 |
return $comment_ID; |
|
3703 |
} |
|
3704 |
||
3705 |
/** |
|
3706 |
* Retrieve all of the comment status. |
|
3707 |
* |
|
3708 |
* @since 2.7.0 |
|
3709 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3715 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
* } |
5 | 3717 |
* @return array|IXR_Error |
0 | 3718 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
public function wp_getCommentStatusList( $args ) { |
0 | 3720 |
$this->escape( $args ); |
3721 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3726 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3728 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3729 |
if ( ! current_user_can( 'publish_posts' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3731 |
} |
0 | 3732 |
|
5 | 3733 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3734 |
do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
|
0 | 3735 |
|
3736 |
return get_comment_statuses(); |
|
3737 |
} |
|
3738 |
||
3739 |
/** |
|
3740 |
* Retrieve comment count. |
|
3741 |
* |
|
3742 |
* @since 2.5.0 |
|
3743 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
* } |
5 | 3752 |
* @return array|IXR_Error |
0 | 3753 |
*/ |
5 | 3754 |
public function wp_getCommentCount( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
$this->escape( $args ); |
0 | 3756 |
|
3757 |
$username = $args[1]; |
|
3758 |
$password = $args[2]; |
|
3759 |
$post_id = (int) $args[3]; |
|
3760 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
if ( ! $user = $this->login( $username, $password ) ) { |
0 | 3762 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3764 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3765 |
$post = get_post( $post_id, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
if ( empty( $post['ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details of this post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
} |
0 | 3773 |
|
5 | 3774 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3775 |
do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
|
0 | 3776 |
|
3777 |
$count = wp_count_comments( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3778 |
|
0 | 3779 |
return array( |
3780 |
'approved' => $count->approved, |
|
3781 |
'awaiting_moderation' => $count->moderated, |
|
3782 |
'spam' => $count->spam, |
|
3783 |
'total_comments' => $count->total_comments |
|
3784 |
); |
|
3785 |
} |
|
3786 |
||
3787 |
/** |
|
3788 |
* Retrieve post statuses. |
|
3789 |
* |
|
3790 |
* @since 2.5.0 |
|
3791 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3792 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3795 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3796 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3797 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3798 |
* } |
5 | 3799 |
* @return array|IXR_Error |
0 | 3800 |
*/ |
5 | 3801 |
public function wp_getPostStatusList( $args ) { |
0 | 3802 |
$this->escape( $args ); |
3803 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3804 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
$password = $args[2]; |
0 | 3806 |
|
3807 |
if ( !$user = $this->login($username, $password) ) |
|
3808 |
return $this->error; |
|
3809 |
||
3810 |
if ( !current_user_can( 'edit_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
0 | 3812 |
|
5 | 3813 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3814 |
do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
|
0 | 3815 |
|
3816 |
return get_post_statuses(); |
|
3817 |
} |
|
3818 |
||
3819 |
/** |
|
3820 |
* Retrieve page statuses. |
|
3821 |
* |
|
3822 |
* @since 2.5.0 |
|
3823 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
* Method arguments. Note: arguments must be ordered as documented. |
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 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3830 |
* } |
5 | 3831 |
* @return array|IXR_Error |
0 | 3832 |
*/ |
5 | 3833 |
public function wp_getPageStatusList( $args ) { |
0 | 3834 |
$this->escape( $args ); |
3835 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3836 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3837 |
$password = $args[2]; |
0 | 3838 |
|
3839 |
if ( !$user = $this->login($username, $password) ) |
|
3840 |
return $this->error; |
|
3841 |
||
3842 |
if ( !current_user_can( 'edit_pages' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3843 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
0 | 3844 |
|
5 | 3845 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3846 |
do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
|
0 | 3847 |
|
3848 |
return get_page_statuses(); |
|
3849 |
} |
|
3850 |
||
3851 |
/** |
|
3852 |
* Retrieve page templates. |
|
3853 |
* |
|
3854 |
* @since 2.6.0 |
|
3855 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3856 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3857 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3858 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3859 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3860 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3862 |
* } |
5 | 3863 |
* @return array|IXR_Error |
0 | 3864 |
*/ |
5 | 3865 |
public function wp_getPageTemplates( $args ) { |
0 | 3866 |
$this->escape( $args ); |
3867 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
$password = $args[2]; |
0 | 3870 |
|
3871 |
if ( !$user = $this->login($username, $password) ) |
|
3872 |
return $this->error; |
|
3873 |
||
3874 |
if ( !current_user_can( 'edit_pages' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
0 | 3876 |
|
3877 |
$templates = get_page_templates(); |
|
3878 |
$templates['Default'] = 'default'; |
|
3879 |
||
3880 |
return $templates; |
|
3881 |
} |
|
3882 |
||
3883 |
/** |
|
3884 |
* Retrieve blog options. |
|
3885 |
* |
|
3886 |
* @since 2.6.0 |
|
3887 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3889 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3892 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3893 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3894 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3895 |
* } |
5 | 3896 |
* @return array|IXR_Error |
0 | 3897 |
*/ |
5 | 3898 |
public function wp_getOptions( $args ) { |
0 | 3899 |
$this->escape( $args ); |
3900 |
||
3901 |
$username = $args[1]; |
|
3902 |
$password = $args[2]; |
|
3903 |
$options = isset( $args[3] ) ? (array) $args[3] : array(); |
|
3904 |
||
3905 |
if ( !$user = $this->login($username, $password) ) |
|
3906 |
return $this->error; |
|
3907 |
||
3908 |
// If no specific options where asked for, return all of them |
|
3909 |
if ( count( $options ) == 0 ) |
|
3910 |
$options = array_keys($this->blog_options); |
|
3911 |
||
3912 |
return $this->_getOptions($options); |
|
3913 |
} |
|
3914 |
||
3915 |
/** |
|
3916 |
* Retrieve blog options value from list. |
|
3917 |
* |
|
3918 |
* @since 2.6.0 |
|
3919 |
* |
|
3920 |
* @param array $options Options to retrieve. |
|
3921 |
* @return array |
|
3922 |
*/ |
|
5 | 3923 |
public function _getOptions($options) { |
0 | 3924 |
$data = array(); |
3925 |
$can_manage = current_user_can( 'manage_options' ); |
|
3926 |
foreach ( $options as $option ) { |
|
3927 |
if ( array_key_exists( $option, $this->blog_options ) ) { |
|
3928 |
$data[$option] = $this->blog_options[$option]; |
|
3929 |
//Is the value static or dynamic? |
|
3930 |
if ( isset( $data[$option]['option'] ) ) { |
|
3931 |
$data[$option]['value'] = get_option( $data[$option]['option'] ); |
|
3932 |
unset($data[$option]['option']); |
|
3933 |
} |
|
3934 |
||
3935 |
if ( ! $can_manage ) |
|
3936 |
$data[$option]['readonly'] = true; |
|
3937 |
} |
|
3938 |
} |
|
3939 |
||
3940 |
return $data; |
|
3941 |
} |
|
3942 |
||
3943 |
/** |
|
3944 |
* Update blog options. |
|
3945 |
* |
|
3946 |
* @since 2.6.0 |
|
3947 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
* @type array $options |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
* } |
5 | 3956 |
* @return array|IXR_Error |
0 | 3957 |
*/ |
5 | 3958 |
public function wp_setOptions( $args ) { |
0 | 3959 |
$this->escape( $args ); |
3960 |
||
3961 |
$username = $args[1]; |
|
3962 |
$password = $args[2]; |
|
3963 |
$options = (array) $args[3]; |
|
3964 |
||
3965 |
if ( !$user = $this->login($username, $password) ) |
|
3966 |
return $this->error; |
|
3967 |
||
3968 |
if ( !current_user_can( 'manage_options' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) ); |
0 | 3970 |
|
5 | 3971 |
$option_names = array(); |
0 | 3972 |
foreach ( $options as $o_name => $o_value ) { |
3973 |
$option_names[] = $o_name; |
|
3974 |
if ( !array_key_exists( $o_name, $this->blog_options ) ) |
|
3975 |
continue; |
|
3976 |
||
3977 |
if ( $this->blog_options[$o_name]['readonly'] == true ) |
|
3978 |
continue; |
|
3979 |
||
5 | 3980 |
update_option( $this->blog_options[$o_name]['option'], wp_unslash( $o_value ) ); |
0 | 3981 |
} |
3982 |
||
3983 |
//Now return the updated values |
|
3984 |
return $this->_getOptions($option_names); |
|
3985 |
} |
|
3986 |
||
3987 |
/** |
|
3988 |
* Retrieve a media item by ID |
|
3989 |
* |
|
3990 |
* @since 3.1.0 |
|
3991 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
* @type int $attachment_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
* } |
5 | 4000 |
* @return array|IXR_Error Associative array contains: |
0 | 4001 |
* - 'date_created_gmt' |
4002 |
* - 'parent' |
|
4003 |
* - 'link' |
|
4004 |
* - 'thumbnail' |
|
4005 |
* - 'title' |
|
4006 |
* - 'caption' |
|
4007 |
* - 'description' |
|
4008 |
* - 'metadata' |
|
4009 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
public function wp_getMediaItem( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
$this->escape( $args ); |
0 | 4012 |
|
4013 |
$username = $args[1]; |
|
4014 |
$password = $args[2]; |
|
4015 |
$attachment_id = (int) $args[3]; |
|
4016 |
||
4017 |
if ( !$user = $this->login($username, $password) ) |
|
4018 |
return $this->error; |
|
4019 |
||
4020 |
if ( !current_user_can( 'upload_files' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4021 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
0 | 4022 |
|
5 | 4023 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4024 |
do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
|
0 | 4025 |
|
4026 |
if ( ! $attachment = get_post($attachment_id) ) |
|
4027 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
|
4028 |
||
4029 |
return $this->_prepare_media_item( $attachment ); |
|
4030 |
} |
|
4031 |
||
4032 |
/** |
|
4033 |
* Retrieves a collection of media library items (or attachments) |
|
4034 |
* |
|
5 | 4035 |
* Besides the common blog_id (unused), username, and password arguments, it takes a filter |
0 | 4036 |
* array as last argument. |
4037 |
* |
|
4038 |
* Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
|
4039 |
* |
|
4040 |
* The defaults are as follows: |
|
4041 |
* - '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
|
4042 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 4043 |
* - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
4044 |
* - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
|
4045 |
* |
|
4046 |
* @since 3.1.0 |
|
4047 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4048 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4049 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4050 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4051 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4052 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4053 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4054 |
* @type array $struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4055 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
* @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents |
0 | 4057 |
*/ |
5 | 4058 |
public function wp_getMediaLibrary($args) { |
0 | 4059 |
$this->escape($args); |
4060 |
||
4061 |
$username = $args[1]; |
|
4062 |
$password = $args[2]; |
|
4063 |
$struct = isset( $args[3] ) ? $args[3] : array() ; |
|
4064 |
||
4065 |
if ( !$user = $this->login($username, $password) ) |
|
4066 |
return $this->error; |
|
4067 |
||
4068 |
if ( !current_user_can( 'upload_files' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4069 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
0 | 4070 |
|
5 | 4071 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4072 |
do_action( 'xmlrpc_call', 'wp.getMediaLibrary' ); |
|
0 | 4073 |
|
4074 |
$parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : '' ; |
|
4075 |
$mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : '' ; |
|
4076 |
$offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0 ; |
|
4077 |
$number = ( isset($struct['number']) ) ? absint($struct['number']) : -1 ; |
|
4078 |
||
4079 |
$attachments = get_posts( array('post_type' => 'attachment', 'post_parent' => $parent_id, 'offset' => $offset, 'numberposts' => $number, 'post_mime_type' => $mime_type ) ); |
|
4080 |
||
4081 |
$attachments_struct = array(); |
|
4082 |
||
4083 |
foreach ($attachments as $attachment ) |
|
4084 |
$attachments_struct[] = $this->_prepare_media_item( $attachment ); |
|
4085 |
||
4086 |
return $attachments_struct; |
|
4087 |
} |
|
4088 |
||
4089 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4090 |
* 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
|
4091 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4092 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4093 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4094 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4095 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4096 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4097 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4098 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4099 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4100 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4101 |
* @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
|
4102 |
*/ |
5 | 4103 |
public function wp_getPostFormats( $args ) { |
0 | 4104 |
$this->escape( $args ); |
4105 |
||
4106 |
$username = $args[1]; |
|
4107 |
$password = $args[2]; |
|
4108 |
||
4109 |
if ( !$user = $this->login( $username, $password ) ) |
|
4110 |
return $this->error; |
|
4111 |
||
4112 |
if ( !current_user_can( 'edit_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4113 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
0 | 4114 |
|
5 | 4115 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4116 |
do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
4117 |
||
4118 |
$formats = get_post_format_strings(); |
|
4119 |
||
5 | 4120 |
// find out if they want a list of currently supports formats |
0 | 4121 |
if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4122 |
if ( $args[3]['show-supported'] ) { |
|
4123 |
if ( current_theme_supports( 'post-formats' ) ) { |
|
4124 |
$supported = get_theme_support( 'post-formats' ); |
|
4125 |
||
5 | 4126 |
$data = array(); |
0 | 4127 |
$data['all'] = $formats; |
4128 |
$data['supported'] = $supported[0]; |
|
4129 |
||
4130 |
$formats = $data; |
|
4131 |
} |
|
4132 |
} |
|
4133 |
} |
|
4134 |
||
4135 |
return $formats; |
|
4136 |
} |
|
4137 |
||
4138 |
/** |
|
4139 |
* Retrieves a post type |
|
4140 |
* |
|
4141 |
* @since 3.4.0 |
|
4142 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4143 |
* @see get_post_type_object() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4144 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4147 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4148 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4149 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4150 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
* @type string $post_type_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4153 |
* } |
5 | 4154 |
* @return array|IXR_Error Array contains: |
0 | 4155 |
* - 'labels' |
4156 |
* - 'description' |
|
4157 |
* - 'capability_type' |
|
4158 |
* - 'cap' |
|
4159 |
* - 'map_meta_cap' |
|
4160 |
* - 'hierarchical' |
|
4161 |
* - 'menu_position' |
|
4162 |
* - 'taxonomies' |
|
4163 |
* - 'supports' |
|
4164 |
*/ |
|
5 | 4165 |
public function wp_getPostType( $args ) { |
0 | 4166 |
if ( ! $this->minimum_args( $args, 4 ) ) |
4167 |
return $this->error; |
|
4168 |
||
4169 |
$this->escape( $args ); |
|
4170 |
||
4171 |
$username = $args[1]; |
|
4172 |
$password = $args[2]; |
|
4173 |
$post_type_name = $args[3]; |
|
4174 |
||
5 | 4175 |
if ( isset( $args[4] ) ) { |
0 | 4176 |
$fields = $args[4]; |
5 | 4177 |
} else { |
4178 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4179 |
* Filters the default query fields used by the given XML-RPC method. |
5 | 4180 |
* |
4181 |
* @since 3.4.0 |
|
4182 |
* |
|
4183 |
* @param array $fields An array of post type query fields for the given method. |
|
4184 |
* @param string $method The method name. |
|
4185 |
*/ |
|
0 | 4186 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
5 | 4187 |
} |
0 | 4188 |
|
4189 |
if ( !$user = $this->login( $username, $password ) ) |
|
4190 |
return $this->error; |
|
4191 |
||
5 | 4192 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4193 |
do_action( 'xmlrpc_call', 'wp.getPostType' ); |
4194 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4195 |
if ( ! post_type_exists( $post_type_name ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4196 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
0 | 4197 |
|
4198 |
$post_type = get_post_type_object( $post_type_name ); |
|
4199 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4200 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4201 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
0 | 4202 |
|
4203 |
return $this->_prepare_post_type( $post_type, $fields ); |
|
4204 |
} |
|
4205 |
||
4206 |
/** |
|
4207 |
* Retrieves a post types |
|
4208 |
* |
|
4209 |
* @since 3.4.0 |
|
4210 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
* @see get_post_types() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4217 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4219 |
* @type array $filter (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4220 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
* } |
5 | 4222 |
* @return array|IXR_Error |
0 | 4223 |
*/ |
5 | 4224 |
public function wp_getPostTypes( $args ) { |
0 | 4225 |
if ( ! $this->minimum_args( $args, 3 ) ) |
4226 |
return $this->error; |
|
4227 |
||
4228 |
$this->escape( $args ); |
|
4229 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4230 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4231 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4232 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 4233 |
|
5 | 4234 |
if ( isset( $args[4] ) ) { |
0 | 4235 |
$fields = $args[4]; |
5 | 4236 |
} else { |
4237 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 4238 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
5 | 4239 |
} |
0 | 4240 |
|
4241 |
if ( ! $user = $this->login( $username, $password ) ) |
|
4242 |
return $this->error; |
|
4243 |
||
5 | 4244 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4245 |
do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
4246 |
||
4247 |
$post_types = get_post_types( $filter, 'objects' ); |
|
4248 |
||
4249 |
$struct = array(); |
|
4250 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4251 |
foreach ( $post_types as $post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4252 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
0 | 4253 |
continue; |
4254 |
||
4255 |
$struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields ); |
|
4256 |
} |
|
4257 |
||
4258 |
return $struct; |
|
4259 |
} |
|
4260 |
||
4261 |
/** |
|
4262 |
* Retrieve revisions for a specific post. |
|
4263 |
* |
|
4264 |
* @since 3.5.0 |
|
4265 |
* |
|
4266 |
* The optional $fields parameter specifies what fields will be included |
|
4267 |
* in the response array. |
|
4268 |
* |
|
4269 |
* @uses wp_get_post_revisions() |
|
4270 |
* @see wp_getPost() for more on $fields |
|
4271 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4272 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4273 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4274 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4275 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4276 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4277 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4278 |
* @type int $post_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4279 |
* @type array $fields (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4280 |
* } |
5 | 4281 |
* @return array|IXR_Error contains a collection of posts. |
0 | 4282 |
*/ |
5 | 4283 |
public function wp_getRevisions( $args ) { |
0 | 4284 |
if ( ! $this->minimum_args( $args, 4 ) ) |
4285 |
return $this->error; |
|
4286 |
||
4287 |
$this->escape( $args ); |
|
4288 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4289 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4290 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4291 |
$post_id = (int) $args[3]; |
0 | 4292 |
|
5 | 4293 |
if ( isset( $args[4] ) ) { |
0 | 4294 |
$fields = $args[4]; |
5 | 4295 |
} else { |
4296 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4297 |
* Filters the default revision query fields used by the given XML-RPC method. |
5 | 4298 |
* |
4299 |
* @since 3.5.0 |
|
4300 |
* |
|
4301 |
* @param array $field An array of revision query fields. |
|
4302 |
* @param string $method The method name. |
|
4303 |
*/ |
|
0 | 4304 |
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
5 | 4305 |
} |
0 | 4306 |
|
4307 |
if ( ! $user = $this->login( $username, $password ) ) |
|
4308 |
return $this->error; |
|
4309 |
||
5 | 4310 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4311 |
do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
4312 |
||
4313 |
if ( ! $post = get_post( $post_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4314 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
0 | 4315 |
|
4316 |
if ( ! current_user_can( 'edit_post', $post_id ) ) |
|
4317 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
|
4318 |
||
4319 |
// Check if revisions are enabled. |
|
4320 |
if ( ! wp_revisions_enabled( $post ) ) |
|
4321 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
|
4322 |
||
4323 |
$revisions = wp_get_post_revisions( $post_id ); |
|
4324 |
||
4325 |
if ( ! $revisions ) |
|
4326 |
return array(); |
|
4327 |
||
4328 |
$struct = array(); |
|
4329 |
||
4330 |
foreach ( $revisions as $revision ) { |
|
4331 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) |
|
4332 |
continue; |
|
4333 |
||
4334 |
// Skip autosaves |
|
4335 |
if ( wp_is_post_autosave( $revision ) ) |
|
4336 |
continue; |
|
4337 |
||
4338 |
$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); |
|
4339 |
} |
|
4340 |
||
4341 |
return $struct; |
|
4342 |
} |
|
4343 |
||
4344 |
/** |
|
4345 |
* Restore a post revision |
|
4346 |
* |
|
4347 |
* @since 3.5.0 |
|
4348 |
* |
|
4349 |
* @uses wp_restore_post_revision() |
|
4350 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4351 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4352 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4353 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4354 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4355 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4356 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4357 |
* @type int $revision_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4358 |
* } |
5 | 4359 |
* @return bool|IXR_Error false if there was an error restoring, true if success. |
0 | 4360 |
*/ |
5 | 4361 |
public function wp_restoreRevision( $args ) { |
0 | 4362 |
if ( ! $this->minimum_args( $args, 3 ) ) |
4363 |
return $this->error; |
|
4364 |
||
4365 |
$this->escape( $args ); |
|
4366 |
||
4367 |
$username = $args[1]; |
|
4368 |
$password = $args[2]; |
|
4369 |
$revision_id = (int) $args[3]; |
|
4370 |
||
4371 |
if ( ! $user = $this->login( $username, $password ) ) |
|
4372 |
return $this->error; |
|
4373 |
||
5 | 4374 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
0 | 4375 |
do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
4376 |
||
4377 |
if ( ! $revision = wp_get_post_revision( $revision_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
0 | 4379 |
|
4380 |
if ( wp_is_post_autosave( $revision ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
0 | 4382 |
|
4383 |
if ( ! $post = get_post( $revision->post_parent ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
0 | 4385 |
|
4386 |
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
|
4387 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 4388 |
|
4389 |
// Check if revisions are disabled. |
|
4390 |
if ( ! wp_revisions_enabled( $post ) ) |
|
4391 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
|
4392 |
||
4393 |
$post = wp_restore_post_revision( $revision_id ); |
|
4394 |
||
4395 |
return (bool) $post; |
|
4396 |
} |
|
4397 |
||
4398 |
/* Blogger API functions. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4399 |
* specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
0 | 4400 |
*/ |
4401 |
||
4402 |
/** |
|
4403 |
* Retrieve blogs that user owns. |
|
4404 |
* |
|
4405 |
* Will make more sense once we support multiple blogs. |
|
4406 |
* |
|
4407 |
* @since 1.5.0 |
|
4408 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4409 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4410 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4411 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4412 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4413 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4414 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4415 |
* } |
5 | 4416 |
* @return array|IXR_Error |
0 | 4417 |
*/ |
5 | 4418 |
public function blogger_getUsersBlogs($args) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4419 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4422 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4423 |
if ( is_multisite() ) { |
0 | 4424 |
return $this->_multisite_getUsersBlogs($args); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4425 |
} |
0 | 4426 |
|
4427 |
$this->escape($args); |
|
4428 |
||
4429 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4430 |
$password = $args[2]; |
0 | 4431 |
|
4432 |
if ( !$user = $this->login($username, $password) ) |
|
4433 |
return $this->error; |
|
4434 |
||
5 | 4435 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4436 |
do_action( 'xmlrpc_call', 'blogger.getUsersBlogs' ); |
|
0 | 4437 |
|
4438 |
$is_admin = current_user_can('manage_options'); |
|
4439 |
||
4440 |
$struct = array( |
|
4441 |
'isAdmin' => $is_admin, |
|
4442 |
'url' => get_option('home') . '/', |
|
4443 |
'blogid' => '1', |
|
4444 |
'blogName' => get_option('blogname'), |
|
4445 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
|
4446 |
); |
|
4447 |
||
4448 |
return array($struct); |
|
4449 |
} |
|
4450 |
||
4451 |
/** |
|
4452 |
* Private function for retrieving a users blogs for multisite setups |
|
4453 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4454 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4455 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4456 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4457 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4458 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4459 |
* @type string $username Username. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4460 |
* @type string $password Password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4461 |
* } |
5 | 4462 |
* @return array|IXR_Error |
0 | 4463 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4464 |
protected function _multisite_getUsersBlogs( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4465 |
$current_blog = get_site(); |
0 | 4466 |
|
4467 |
$domain = $current_blog->domain; |
|
4468 |
$path = $current_blog->path . 'xmlrpc.php'; |
|
4469 |
||
4470 |
$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) ); |
|
4471 |
$rpc->query('wp.getUsersBlogs', $args[1], $args[2]); |
|
4472 |
$blogs = $rpc->getResponse(); |
|
4473 |
||
4474 |
if ( isset($blogs['faultCode']) ) |
|
4475 |
return new IXR_Error($blogs['faultCode'], $blogs['faultString']); |
|
4476 |
||
4477 |
if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { |
|
4478 |
return $blogs; |
|
4479 |
} else { |
|
4480 |
foreach ( (array) $blogs as $blog ) { |
|
4481 |
if ( strpos($blog['url'], $_SERVER['HTTP_HOST']) ) |
|
4482 |
return array($blog); |
|
4483 |
} |
|
4484 |
return array(); |
|
4485 |
} |
|
4486 |
} |
|
4487 |
||
4488 |
/** |
|
4489 |
* Retrieve user's data. |
|
4490 |
* |
|
4491 |
* Gives your client some info about you, so you don't have to. |
|
4492 |
* |
|
4493 |
* @since 1.5.0 |
|
4494 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4495 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4496 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4497 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4500 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4501 |
* } |
5 | 4502 |
* @return array|IXR_Error |
0 | 4503 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
public function blogger_getUserInfo( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
$this->escape( $args ); |
0 | 4506 |
|
4507 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4508 |
$password = $args[2]; |
0 | 4509 |
|
4510 |
if ( !$user = $this->login($username, $password) ) |
|
4511 |
return $this->error; |
|
4512 |
||
4513 |
if ( !current_user_can( 'edit_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4514 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
0 | 4515 |
|
5 | 4516 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4517 |
do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
|
0 | 4518 |
|
4519 |
$struct = array( |
|
4520 |
'nickname' => $user->nickname, |
|
4521 |
'userid' => $user->ID, |
|
4522 |
'url' => $user->user_url, |
|
4523 |
'lastname' => $user->last_name, |
|
4524 |
'firstname' => $user->first_name |
|
4525 |
); |
|
4526 |
||
4527 |
return $struct; |
|
4528 |
} |
|
4529 |
||
4530 |
/** |
|
4531 |
* Retrieve post. |
|
4532 |
* |
|
4533 |
* @since 1.5.0 |
|
4534 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4536 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4537 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4538 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4539 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4540 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4541 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4542 |
* } |
5 | 4543 |
* @return array|IXR_Error |
0 | 4544 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4545 |
public function blogger_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4546 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4547 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4548 |
$post_ID = (int) $args[1]; |
0 | 4549 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4550 |
$password = $args[3]; |
0 | 4551 |
|
4552 |
if ( !$user = $this->login($username, $password) ) |
|
4553 |
return $this->error; |
|
4554 |
||
4555 |
$post_data = get_post($post_ID, ARRAY_A); |
|
4556 |
if ( ! $post_data ) |
|
4557 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
4558 |
||
4559 |
if ( !current_user_can( 'edit_post', $post_ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4560 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 4561 |
|
5 | 4562 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4563 |
do_action( 'xmlrpc_call', 'blogger.getPost' ); |
|
0 | 4564 |
|
4565 |
$categories = implode(',', wp_get_post_categories($post_ID)); |
|
4566 |
||
4567 |
$content = '<title>'.wp_unslash($post_data['post_title']).'</title>'; |
|
4568 |
$content .= '<category>'.$categories.'</category>'; |
|
4569 |
$content .= wp_unslash($post_data['post_content']); |
|
4570 |
||
4571 |
$struct = array( |
|
4572 |
'userid' => $post_data['post_author'], |
|
4573 |
'dateCreated' => $this->_convert_date( $post_data['post_date'] ), |
|
4574 |
'content' => $content, |
|
4575 |
'postid' => (string) $post_data['ID'] |
|
4576 |
); |
|
4577 |
||
4578 |
return $struct; |
|
4579 |
} |
|
4580 |
||
4581 |
/** |
|
4582 |
* Retrieve list of recent posts. |
|
4583 |
* |
|
4584 |
* @since 1.5.0 |
|
4585 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4589 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4590 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4591 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
* @type int $numberposts (optional) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4594 |
* } |
5 | 4595 |
* @return array|IXR_Error |
0 | 4596 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4597 |
public function blogger_getRecentPosts( $args ) { |
0 | 4598 |
|
4599 |
$this->escape($args); |
|
4600 |
||
4601 |
// $args[0] = appkey - ignored |
|
4602 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4603 |
$password = $args[3]; |
0 | 4604 |
if ( isset( $args[4] ) ) |
4605 |
$query = array( 'numberposts' => absint( $args[4] ) ); |
|
4606 |
else |
|
4607 |
$query = array(); |
|
4608 |
||
4609 |
if ( !$user = $this->login($username, $password) ) |
|
4610 |
return $this->error; |
|
4611 |
||
4612 |
if ( ! current_user_can( 'edit_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4613 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
0 | 4614 |
|
5 | 4615 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4616 |
do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
|
0 | 4617 |
|
4618 |
$posts_list = wp_get_recent_posts( $query ); |
|
4619 |
||
4620 |
if ( !$posts_list ) { |
|
4621 |
$this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
|
4622 |
return $this->error; |
|
4623 |
} |
|
4624 |
||
5 | 4625 |
$recent_posts = array(); |
0 | 4626 |
foreach ($posts_list as $entry) { |
4627 |
if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
|
4628 |
continue; |
|
4629 |
||
4630 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
4631 |
$categories = implode(',', wp_get_post_categories($entry['ID'])); |
|
4632 |
||
4633 |
$content = '<title>'.wp_unslash($entry['post_title']).'</title>'; |
|
4634 |
$content .= '<category>'.$categories.'</category>'; |
|
4635 |
$content .= wp_unslash($entry['post_content']); |
|
4636 |
||
5 | 4637 |
$recent_posts[] = array( |
0 | 4638 |
'userid' => $entry['post_author'], |
4639 |
'dateCreated' => $post_date, |
|
4640 |
'content' => $content, |
|
4641 |
'postid' => (string) $entry['ID'], |
|
4642 |
); |
|
4643 |
} |
|
4644 |
||
4645 |
return $recent_posts; |
|
4646 |
} |
|
4647 |
||
4648 |
/** |
|
4649 |
* Deprecated. |
|
4650 |
* |
|
4651 |
* @since 1.5.0 |
|
4652 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4653 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4654 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4655 |
* @return IXR_Error Error object. |
0 | 4656 |
*/ |
5 | 4657 |
public function blogger_getTemplate($args) { |
0 | 4658 |
return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4659 |
} |
|
4660 |
||
4661 |
/** |
|
4662 |
* Deprecated. |
|
4663 |
* |
|
4664 |
* @since 1.5.0 |
|
4665 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4666 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4667 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4668 |
* @return IXR_Error Error object. |
0 | 4669 |
*/ |
5 | 4670 |
public function blogger_setTemplate($args) { |
0 | 4671 |
return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4672 |
} |
|
4673 |
||
4674 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4675 |
* Creates new post. |
0 | 4676 |
* |
4677 |
* @since 1.5.0 |
|
4678 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4679 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4680 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4681 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4682 |
* @type string $appkey (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4683 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4684 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4685 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4686 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4687 |
* @type string $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4688 |
* } |
5 | 4689 |
* @return int|IXR_Error |
0 | 4690 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4691 |
public function blogger_newPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4692 |
$this->escape( $args ); |
0 | 4693 |
|
4694 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4695 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4696 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4697 |
$publish = $args[5]; |
0 | 4698 |
|
4699 |
if ( !$user = $this->login($username, $password) ) |
|
4700 |
return $this->error; |
|
4701 |
||
5 | 4702 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4703 |
do_action( 'xmlrpc_call', 'blogger.newPost' ); |
|
0 | 4704 |
|
4705 |
$cap = ($publish) ? 'publish_posts' : 'edit_posts'; |
|
4706 |
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) ) |
|
4707 |
return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.')); |
|
4708 |
||
4709 |
$post_status = ($publish) ? 'publish' : 'draft'; |
|
4710 |
||
4711 |
$post_author = $user->ID; |
|
4712 |
||
4713 |
$post_title = xmlrpc_getposttitle($content); |
|
4714 |
$post_category = xmlrpc_getpostcategory($content); |
|
4715 |
$post_content = xmlrpc_removepostdata($content); |
|
4716 |
||
4717 |
$post_date = current_time('mysql'); |
|
4718 |
$post_date_gmt = current_time('mysql', 1); |
|
4719 |
||
5 | 4720 |
$post_data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); |
0 | 4721 |
|
4722 |
$post_ID = wp_insert_post($post_data); |
|
4723 |
if ( is_wp_error( $post_ID ) ) |
|
4724 |
return new IXR_Error(500, $post_ID->get_error_message()); |
|
4725 |
||
4726 |
if ( !$post_ID ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4727 |
return new IXR_Error(500, __('Sorry, your entry could not be posted.')); |
0 | 4728 |
|
4729 |
$this->attach_uploads( $post_ID, $post_content ); |
|
4730 |
||
5 | 4731 |
/** |
4732 |
* Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
4733 |
* |
|
4734 |
* @since 3.4.0 |
|
4735 |
* |
|
4736 |
* @param int $post_ID ID of the new post. |
|
4737 |
* @param array $args An array of new post arguments. |
|
4738 |
*/ |
|
0 | 4739 |
do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); |
4740 |
||
4741 |
return $post_ID; |
|
4742 |
} |
|
4743 |
||
4744 |
/** |
|
4745 |
* Edit a post. |
|
4746 |
* |
|
4747 |
* @since 1.5.0 |
|
4748 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4749 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4750 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4751 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4752 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4753 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4754 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4755 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4756 |
* @type string $content |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4757 |
* @type bool $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4758 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4759 |
* @return true|IXR_Error true when done. |
0 | 4760 |
*/ |
5 | 4761 |
public function blogger_editPost( $args ) { |
0 | 4762 |
|
4763 |
$this->escape($args); |
|
4764 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4765 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4766 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4767 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4768 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4769 |
$publish = $args[5]; |
5 | 4770 |
|
4771 |
if ( ! $user = $this->login( $username, $password ) ) { |
|
0 | 4772 |
return $this->error; |
5 | 4773 |
} |
4774 |
||
4775 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
4776 |
do_action( 'xmlrpc_call', 'blogger.editPost' ); |
|
4777 |
||
4778 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
|
4779 |
||
4780 |
if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
|
4781 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
4782 |
} |
|
0 | 4783 |
|
4784 |
$this->escape($actual_post); |
|
4785 |
||
5 | 4786 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4787 |
return new IXR_Error(401, __('Sorry, you are not allowed to edit this post.')); |
5 | 4788 |
} |
4789 |
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
|
4790 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 4791 |
} |
4792 |
||
4793 |
$postdata = array(); |
|
4794 |
$postdata['ID'] = $actual_post['ID']; |
|
4795 |
$postdata['post_content'] = xmlrpc_removepostdata( $content ); |
|
4796 |
$postdata['post_title'] = xmlrpc_getposttitle( $content ); |
|
4797 |
$postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
|
4798 |
$postdata['post_status'] = $actual_post['post_status']; |
|
4799 |
$postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4800 |
$postdata['post_status'] = $publish ? 'publish' : 'draft'; |
5 | 4801 |
|
4802 |
$result = wp_update_post( $postdata ); |
|
4803 |
||
4804 |
if ( ! $result ) { |
|
0 | 4805 |
return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); |
5 | 4806 |
} |
4807 |
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
|
4808 |
||
4809 |
/** |
|
4810 |
* Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
4811 |
* |
|
4812 |
* @since 3.4.0 |
|
4813 |
* |
|
4814 |
* @param int $post_ID ID of the updated post. |
|
4815 |
* @param array $args An array of arguments for the post to edit. |
|
4816 |
*/ |
|
0 | 4817 |
do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); |
4818 |
||
4819 |
return true; |
|
4820 |
} |
|
4821 |
||
4822 |
/** |
|
4823 |
* Remove a post. |
|
4824 |
* |
|
4825 |
* @since 1.5.0 |
|
4826 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4827 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4828 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4829 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4830 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4831 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4832 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4833 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4834 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4835 |
* @return true|IXR_Error True when post is deleted. |
0 | 4836 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4837 |
public function blogger_deletePost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4838 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4839 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
$post_ID = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4841 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
$password = $args[3]; |
0 | 4843 |
|
4844 |
if ( !$user = $this->login($username, $password) ) |
|
4845 |
return $this->error; |
|
4846 |
||
5 | 4847 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4848 |
do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
|
0 | 4849 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4850 |
$actual_post = get_post( $post_ID, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4851 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4852 |
if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4853 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4854 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4855 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4856 |
if ( ! current_user_can( 'delete_post', $post_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4857 |
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
|
4858 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4859 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4860 |
$result = wp_delete_post( $post_ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4861 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4862 |
if ( ! $result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4863 |
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
|
4864 |
} |
0 | 4865 |
|
5 | 4866 |
/** |
4867 |
* Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
|
4868 |
* |
|
4869 |
* @since 3.4.0 |
|
4870 |
* |
|
4871 |
* @param int $post_ID ID of the deleted post. |
|
4872 |
* @param array $args An array of arguments to delete the post. |
|
4873 |
*/ |
|
0 | 4874 |
do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); |
4875 |
||
4876 |
return true; |
|
4877 |
} |
|
4878 |
||
4879 |
/* MetaWeblog API functions |
|
4880 |
* specs on wherever Dave Winer wants them to be |
|
4881 |
*/ |
|
4882 |
||
4883 |
/** |
|
4884 |
* Create a new post. |
|
4885 |
* |
|
4886 |
* The 'content_struct' argument must contain: |
|
4887 |
* - title |
|
4888 |
* - description |
|
4889 |
* - mt_excerpt |
|
4890 |
* - mt_text_more |
|
4891 |
* - mt_keywords |
|
4892 |
* - mt_tb_ping_urls |
|
4893 |
* - categories |
|
4894 |
* |
|
4895 |
* Also, it can optionally contain: |
|
4896 |
* - wp_slug |
|
4897 |
* - wp_password |
|
4898 |
* - wp_page_parent_id |
|
4899 |
* - wp_page_order |
|
4900 |
* - wp_author_id |
|
4901 |
* - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' |
|
4902 |
* - mt_allow_comments - can be 'open' or 'closed' |
|
4903 |
* - mt_allow_pings - can be 'open' or 'closed' |
|
4904 |
* - date_created_gmt |
|
4905 |
* - dateCreated |
|
4906 |
* - wp_post_thumbnail |
|
4907 |
* |
|
4908 |
* @since 1.5.0 |
|
4909 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4910 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4911 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4912 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4913 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4914 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4915 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4916 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4917 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4918 |
* } |
5 | 4919 |
* @return int|IXR_Error |
0 | 4920 |
*/ |
5 | 4921 |
public function mw_newPost($args) { |
0 | 4922 |
$this->escape($args); |
4923 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4924 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4925 |
$password = $args[2]; |
0 | 4926 |
$content_struct = $args[3]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4927 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
0 | 4928 |
|
4929 |
if ( !$user = $this->login($username, $password) ) |
|
4930 |
return $this->error; |
|
4931 |
||
5 | 4932 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4933 |
do_action( 'xmlrpc_call', 'metaWeblog.newPost' ); |
|
0 | 4934 |
|
4935 |
$page_template = ''; |
|
4936 |
if ( !empty( $content_struct['post_type'] ) ) { |
|
4937 |
if ( $content_struct['post_type'] == 'page' ) { |
|
4938 |
if ( $publish ) |
|
4939 |
$cap = 'publish_pages'; |
|
4940 |
elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] ) |
|
4941 |
$cap = 'publish_pages'; |
|
4942 |
else |
|
4943 |
$cap = 'edit_pages'; |
|
4944 |
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' ); |
|
4945 |
$post_type = 'page'; |
|
4946 |
if ( !empty( $content_struct['wp_page_template'] ) ) |
|
4947 |
$page_template = $content_struct['wp_page_template']; |
|
4948 |
} elseif ( $content_struct['post_type'] == 'post' ) { |
|
4949 |
if ( $publish ) |
|
4950 |
$cap = 'publish_posts'; |
|
4951 |
elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) |
|
4952 |
$cap = 'publish_posts'; |
|
4953 |
else |
|
4954 |
$cap = 'edit_posts'; |
|
4955 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
|
4956 |
$post_type = 'post'; |
|
4957 |
} else { |
|
4958 |
// No other post_type values are allowed here |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4959 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 4960 |
} |
4961 |
} else { |
|
4962 |
if ( $publish ) |
|
4963 |
$cap = 'publish_posts'; |
|
4964 |
elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status']) |
|
4965 |
$cap = 'publish_posts'; |
|
4966 |
else |
|
4967 |
$cap = 'edit_posts'; |
|
4968 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
|
4969 |
$post_type = 'post'; |
|
4970 |
} |
|
4971 |
||
4972 |
if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) |
|
4973 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) ); |
|
4974 |
if ( !current_user_can( $cap ) ) |
|
4975 |
return new IXR_Error( 401, $error_message ); |
|
4976 |
||
4977 |
// Check for a valid post format if one was given |
|
4978 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
|
4979 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
4980 |
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
|
4981 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 4982 |
} |
4983 |
} |
|
4984 |
||
4985 |
// Let WordPress generate the post_name (slug) unless |
|
4986 |
// one has been provided. |
|
4987 |
$post_name = ""; |
|
4988 |
if ( isset($content_struct['wp_slug']) ) |
|
4989 |
$post_name = $content_struct['wp_slug']; |
|
4990 |
||
4991 |
// Only use a password if one was given. |
|
4992 |
if ( isset($content_struct['wp_password']) ) |
|
4993 |
$post_password = $content_struct['wp_password']; |
|
4994 |
||
4995 |
// Only set a post parent if one was provided. |
|
4996 |
if ( isset($content_struct['wp_page_parent_id']) ) |
|
4997 |
$post_parent = $content_struct['wp_page_parent_id']; |
|
4998 |
||
4999 |
// Only set the menu_order if it was provided. |
|
5000 |
if ( isset($content_struct['wp_page_order']) ) |
|
5001 |
$menu_order = $content_struct['wp_page_order']; |
|
5002 |
||
5003 |
$post_author = $user->ID; |
|
5004 |
||
5005 |
// If an author id was provided then use it instead. |
|
5006 |
if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
|
5007 |
switch ( $post_type ) { |
|
5008 |
case "post": |
|
5009 |
if ( !current_user_can( 'edit_others_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5010 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
0 | 5011 |
break; |
5012 |
case "page": |
|
5013 |
if ( !current_user_can( 'edit_others_pages' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5014 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
0 | 5015 |
break; |
5016 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5017 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5018 |
} |
5019 |
$author = get_userdata( $content_struct['wp_author_id'] ); |
|
5020 |
if ( ! $author ) |
|
5021 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
|
5022 |
$post_author = $content_struct['wp_author_id']; |
|
5023 |
} |
|
5024 |
||
5025 |
$post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; |
|
5026 |
$post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null; |
|
5027 |
||
5028 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5029 |
||
5030 |
if ( isset( $content_struct["{$post_type}_status"] ) ) { |
|
5031 |
switch ( $content_struct["{$post_type}_status"] ) { |
|
5032 |
case 'draft': |
|
5033 |
case 'pending': |
|
5034 |
case 'private': |
|
5035 |
case 'publish': |
|
5036 |
$post_status = $content_struct["{$post_type}_status"]; |
|
5037 |
break; |
|
5038 |
default: |
|
5039 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5040 |
break; |
|
5041 |
} |
|
5042 |
} |
|
5043 |
||
5044 |
$post_excerpt = isset($content_struct['mt_excerpt']) ? $content_struct['mt_excerpt'] : null; |
|
5045 |
$post_more = isset($content_struct['mt_text_more']) ? $content_struct['mt_text_more'] : null; |
|
5046 |
||
5047 |
$tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null; |
|
5048 |
||
5049 |
if ( isset($content_struct['mt_allow_comments']) ) { |
|
5050 |
if ( !is_numeric($content_struct['mt_allow_comments']) ) { |
|
5051 |
switch ( $content_struct['mt_allow_comments'] ) { |
|
5052 |
case 'closed': |
|
5053 |
$comment_status = 'closed'; |
|
5054 |
break; |
|
5055 |
case 'open': |
|
5056 |
$comment_status = 'open'; |
|
5057 |
break; |
|
5058 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5059 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5060 |
break; |
5061 |
} |
|
5062 |
} else { |
|
5063 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5064 |
case 0: |
|
5065 |
case 2: |
|
5066 |
$comment_status = 'closed'; |
|
5067 |
break; |
|
5068 |
case 1: |
|
5069 |
$comment_status = 'open'; |
|
5070 |
break; |
|
5071 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5072 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5073 |
break; |
5074 |
} |
|
5075 |
} |
|
5076 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5077 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5078 |
} |
5079 |
||
5080 |
if ( isset($content_struct['mt_allow_pings']) ) { |
|
5081 |
if ( !is_numeric($content_struct['mt_allow_pings']) ) { |
|
5082 |
switch ( $content_struct['mt_allow_pings'] ) { |
|
5083 |
case 'closed': |
|
5084 |
$ping_status = 'closed'; |
|
5085 |
break; |
|
5086 |
case 'open': |
|
5087 |
$ping_status = 'open'; |
|
5088 |
break; |
|
5089 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5090 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5091 |
break; |
5092 |
} |
|
5093 |
} else { |
|
5094 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
|
5095 |
case 0: |
|
5096 |
$ping_status = 'closed'; |
|
5097 |
break; |
|
5098 |
case 1: |
|
5099 |
$ping_status = 'open'; |
|
5100 |
break; |
|
5101 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5102 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5103 |
break; |
5104 |
} |
|
5105 |
} |
|
5106 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5107 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5108 |
} |
5109 |
||
5110 |
if ( $post_more ) |
|
5111 |
$post_content = $post_content . '<!--more-->' . $post_more; |
|
5112 |
||
5113 |
$to_ping = null; |
|
5114 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5115 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
5116 |
if ( is_array($to_ping) ) |
|
5117 |
$to_ping = implode(' ', $to_ping); |
|
5118 |
} |
|
5119 |
||
5120 |
// Do some timestamp voodoo |
|
5121 |
if ( !empty( $content_struct['date_created_gmt'] ) ) |
|
5122 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force |
|
5123 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
|
5124 |
elseif ( !empty( $content_struct['dateCreated']) ) |
|
5125 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
|
5126 |
||
5127 |
if ( !empty( $dateCreated ) ) { |
|
5128 |
$post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
|
5129 |
$post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
|
5130 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5131 |
$post_date = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5132 |
$post_date_gmt = ''; |
0 | 5133 |
} |
5134 |
||
5135 |
$post_category = array(); |
|
5136 |
if ( isset( $content_struct['categories'] ) ) { |
|
5137 |
$catnames = $content_struct['categories']; |
|
5138 |
||
5139 |
if ( is_array($catnames) ) { |
|
5140 |
foreach ($catnames as $cat) { |
|
5141 |
$post_category[] = get_cat_ID($cat); |
|
5142 |
} |
|
5143 |
} |
|
5144 |
} |
|
5145 |
||
5146 |
$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'); |
|
5147 |
||
5148 |
$post_ID = $postdata['ID'] = get_default_post_to_edit( $post_type, true )->ID; |
|
5149 |
||
5150 |
// Only posts can be sticky |
|
5151 |
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5152 |
$data = $postdata; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5153 |
$data['sticky'] = $content_struct['sticky']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5154 |
$error = $this->_toggle_sticky( $data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5155 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5156 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5157 |
} |
0 | 5158 |
} |
5159 |
||
5160 |
if ( isset($content_struct['custom_fields']) ) |
|
5161 |
$this->set_custom_fields($post_ID, $content_struct['custom_fields']); |
|
5162 |
||
5163 |
if ( isset ( $content_struct['wp_post_thumbnail'] ) ) { |
|
5164 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) |
|
5165 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
|
5166 |
||
5167 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5168 |
} |
|
5169 |
||
5170 |
// Handle enclosures |
|
5171 |
$thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; |
|
5172 |
$this->add_enclosure_if_new($post_ID, $thisEnclosure); |
|
5173 |
||
5174 |
$this->attach_uploads( $post_ID, $post_content ); |
|
5175 |
||
5176 |
// Handle post formats if assigned, value is validated earlier |
|
5177 |
// in this function |
|
5178 |
if ( isset( $content_struct['wp_post_format'] ) ) |
|
5179 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
|
5180 |
||
5181 |
$post_ID = wp_insert_post( $postdata, true ); |
|
5182 |
if ( is_wp_error( $post_ID ) ) |
|
5183 |
return new IXR_Error(500, $post_ID->get_error_message()); |
|
5184 |
||
5185 |
if ( !$post_ID ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5186 |
return new IXR_Error(500, __('Sorry, your entry could not be posted.')); |
0 | 5187 |
|
5 | 5188 |
/** |
5189 |
* Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
5190 |
* |
|
5191 |
* @since 3.4.0 |
|
5192 |
* |
|
5193 |
* @param int $post_ID ID of the new post. |
|
5194 |
* @param array $args An array of arguments to create the new post. |
|
5195 |
*/ |
|
0 | 5196 |
do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); |
5197 |
||
5198 |
return strval($post_ID); |
|
5199 |
} |
|
5200 |
||
5 | 5201 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5202 |
* 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
|
5203 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5204 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5205 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5206 |
* @param integer $post_ID Post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5207 |
* @param array $enclosure Enclosure data. |
5 | 5208 |
*/ |
5209 |
public function add_enclosure_if_new( $post_ID, $enclosure ) { |
|
0 | 5210 |
if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
5211 |
$encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
|
5212 |
$found = false; |
|
5213 |
if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) { |
|
5214 |
foreach ( $enclosures as $enc ) { |
|
5215 |
// This method used to omit the trailing new line. #23219 |
|
5216 |
if ( rtrim( $enc, "\n" ) == rtrim( $encstring, "\n" ) ) { |
|
5217 |
$found = true; |
|
5218 |
break; |
|
5219 |
} |
|
5220 |
} |
|
5221 |
} |
|
5222 |
if ( ! $found ) |
|
5223 |
add_post_meta( $post_ID, 'enclosure', $encstring ); |
|
5224 |
} |
|
5225 |
} |
|
5226 |
||
5227 |
/** |
|
5228 |
* Attach upload to a post. |
|
5229 |
* |
|
5230 |
* @since 2.1.0 |
|
5231 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5232 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5233 |
* |
0 | 5234 |
* @param int $post_ID Post ID. |
5235 |
* @param string $post_content Post Content for attachment. |
|
5236 |
*/ |
|
5 | 5237 |
public function attach_uploads( $post_ID, $post_content ) { |
0 | 5238 |
global $wpdb; |
5239 |
||
5240 |
// find any unattached files |
|
5241 |
$attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); |
|
5242 |
if ( is_array( $attachments ) ) { |
|
5243 |
foreach ( $attachments as $file ) { |
|
5244 |
if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) |
|
5245 |
$wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) ); |
|
5246 |
} |
|
5247 |
} |
|
5248 |
} |
|
5249 |
||
5250 |
/** |
|
5251 |
* Edit a post. |
|
5252 |
* |
|
5253 |
* @since 1.5.0 |
|
5254 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5255 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5256 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5257 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5258 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5259 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5260 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5261 |
* @type array $content_struct |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5262 |
* @type int $publish |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5263 |
* } |
5 | 5264 |
* @return bool|IXR_Error True on success. |
0 | 5265 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5266 |
public function mw_editPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5267 |
$this->escape( $args ); |
0 | 5268 |
|
5269 |
$post_ID = (int) $args[0]; |
|
5270 |
$username = $args[1]; |
|
5271 |
$password = $args[2]; |
|
5272 |
$content_struct = $args[3]; |
|
5273 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
|
5274 |
||
5275 |
if ( ! $user = $this->login($username, $password) ) |
|
5276 |
return $this->error; |
|
5277 |
||
5 | 5278 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5279 |
do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
|
0 | 5280 |
|
5281 |
$postdata = get_post( $post_ID, ARRAY_A ); |
|
5282 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5283 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5284 |
* 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
|
5285 |
* 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
|
5286 |
*/ |
0 | 5287 |
if ( ! $postdata || empty( $postdata[ 'ID' ] ) ) |
5288 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
5289 |
||
5290 |
if ( ! current_user_can( 'edit_post', $post_ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5291 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 5292 |
|
5293 |
// Use wp.editPost to edit post types other than post and page. |
|
5294 |
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
|
5295 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5296 |
|
5297 |
// Thwart attempt to change the post type. |
|
5298 |
if ( ! empty( $content_struct[ 'post_type' ] ) && ( $content_struct['post_type'] != $postdata[ 'post_type' ] ) ) |
|
5299 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
|
5300 |
||
5301 |
// Check for a valid post format if one was given |
|
5302 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
|
5303 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
5304 |
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
|
5305 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5306 |
} |
5307 |
} |
|
5308 |
||
5309 |
$this->escape($postdata); |
|
5 | 5310 |
|
5311 |
$ID = $postdata['ID']; |
|
5312 |
$post_content = $postdata['post_content']; |
|
5313 |
$post_title = $postdata['post_title']; |
|
5314 |
$post_excerpt = $postdata['post_excerpt']; |
|
5315 |
$post_password = $postdata['post_password']; |
|
5316 |
$post_parent = $postdata['post_parent']; |
|
5317 |
$post_type = $postdata['post_type']; |
|
5318 |
$menu_order = $postdata['menu_order']; |
|
0 | 5319 |
|
5320 |
// Let WordPress manage slug if none was provided. |
|
5321 |
$post_name = $postdata['post_name']; |
|
5322 |
if ( isset($content_struct['wp_slug']) ) |
|
5323 |
$post_name = $content_struct['wp_slug']; |
|
5324 |
||
5325 |
// Only use a password if one was given. |
|
5326 |
if ( isset($content_struct['wp_password']) ) |
|
5327 |
$post_password = $content_struct['wp_password']; |
|
5328 |
||
5329 |
// Only set a post parent if one was given. |
|
5330 |
if ( isset($content_struct['wp_page_parent_id']) ) |
|
5331 |
$post_parent = $content_struct['wp_page_parent_id']; |
|
5332 |
||
5333 |
// Only set the menu_order if it was given. |
|
5334 |
if ( isset($content_struct['wp_page_order']) ) |
|
5335 |
$menu_order = $content_struct['wp_page_order']; |
|
5336 |
||
5 | 5337 |
$page_template = null; |
0 | 5338 |
if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) |
5339 |
$page_template = $content_struct['wp_page_template']; |
|
5340 |
||
5341 |
$post_author = $postdata['post_author']; |
|
5342 |
||
5343 |
// Only set the post_author if one is set. |
|
5 | 5344 |
if ( isset( $content_struct['wp_author_id'] ) ) { |
5345 |
// Check permissions if attempting to switch author to or from another user. |
|
5346 |
if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) { |
|
5347 |
switch ( $post_type ) { |
|
5348 |
case 'post': |
|
5349 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5350 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the post author as this user.' ) ); |
5 | 5351 |
} |
5352 |
break; |
|
5353 |
case 'page': |
|
5354 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5355 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the page author as this user.' ) ); |
5 | 5356 |
} |
5357 |
break; |
|
5358 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5359 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
5 | 5360 |
} |
5361 |
$post_author = $content_struct['wp_author_id']; |
|
0 | 5362 |
} |
5363 |
} |
|
5364 |
||
5365 |
if ( isset($content_struct['mt_allow_comments']) ) { |
|
5366 |
if ( !is_numeric($content_struct['mt_allow_comments']) ) { |
|
5367 |
switch ( $content_struct['mt_allow_comments'] ) { |
|
5368 |
case 'closed': |
|
5369 |
$comment_status = 'closed'; |
|
5370 |
break; |
|
5371 |
case 'open': |
|
5372 |
$comment_status = 'open'; |
|
5373 |
break; |
|
5374 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5375 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5376 |
break; |
5377 |
} |
|
5378 |
} else { |
|
5379 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5380 |
case 0: |
|
5381 |
case 2: |
|
5382 |
$comment_status = 'closed'; |
|
5383 |
break; |
|
5384 |
case 1: |
|
5385 |
$comment_status = 'open'; |
|
5386 |
break; |
|
5387 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5388 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5389 |
break; |
5390 |
} |
|
5391 |
} |
|
5392 |
} |
|
5393 |
||
5394 |
if ( isset($content_struct['mt_allow_pings']) ) { |
|
5395 |
if ( !is_numeric($content_struct['mt_allow_pings']) ) { |
|
5396 |
switch ( $content_struct['mt_allow_pings'] ) { |
|
5397 |
case 'closed': |
|
5398 |
$ping_status = 'closed'; |
|
5399 |
break; |
|
5400 |
case 'open': |
|
5401 |
$ping_status = 'open'; |
|
5402 |
break; |
|
5403 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5404 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5405 |
break; |
5406 |
} |
|
5407 |
} else { |
|
5408 |
switch ( (int) $content_struct["mt_allow_pings"] ) { |
|
5409 |
case 0: |
|
5410 |
$ping_status = 'closed'; |
|
5411 |
break; |
|
5412 |
case 1: |
|
5413 |
$ping_status = 'open'; |
|
5414 |
break; |
|
5415 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5416 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5417 |
break; |
5418 |
} |
|
5419 |
} |
|
5420 |
} |
|
5421 |
||
5422 |
if ( isset( $content_struct['title'] ) ) |
|
5423 |
$post_title = $content_struct['title']; |
|
5424 |
||
5425 |
if ( isset( $content_struct['description'] ) ) |
|
5426 |
$post_content = $content_struct['description']; |
|
5427 |
||
5428 |
$post_category = array(); |
|
5429 |
if ( isset( $content_struct['categories'] ) ) { |
|
5430 |
$catnames = $content_struct['categories']; |
|
5431 |
if ( is_array($catnames) ) { |
|
5432 |
foreach ($catnames as $cat) { |
|
5433 |
$post_category[] = get_cat_ID($cat); |
|
5434 |
} |
|
5435 |
} |
|
5436 |
} |
|
5437 |
||
5438 |
if ( isset( $content_struct['mt_excerpt'] ) ) |
|
5439 |
$post_excerpt = $content_struct['mt_excerpt']; |
|
5440 |
||
5441 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; |
|
5442 |
||
5443 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5444 |
if ( isset( $content_struct["{$post_type}_status"] ) ) { |
|
5445 |
switch( $content_struct["{$post_type}_status"] ) { |
|
5446 |
case 'draft': |
|
5447 |
case 'pending': |
|
5448 |
case 'private': |
|
5449 |
case 'publish': |
|
5450 |
$post_status = $content_struct["{$post_type}_status"]; |
|
5451 |
break; |
|
5452 |
default: |
|
5453 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5454 |
break; |
|
5455 |
} |
|
5456 |
} |
|
5457 |
||
5458 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; |
|
5459 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5460 |
if ( 'publish' == $post_status || 'private' == $post_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5461 |
if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5462 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) ); |
5 | 5463 |
} elseif ( ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5464 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5465 |
} |
0 | 5466 |
} |
5467 |
||
5468 |
if ( $post_more ) |
|
5469 |
$post_content = $post_content . "<!--more-->" . $post_more; |
|
5470 |
||
5471 |
$to_ping = null; |
|
5472 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
|
5473 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
5474 |
if ( is_array($to_ping) ) |
|
5475 |
$to_ping = implode(' ', $to_ping); |
|
5476 |
} |
|
5477 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5478 |
// Do some timestamp voodoo. |
0 | 5479 |
if ( !empty( $content_struct['date_created_gmt'] ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5480 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
0 | 5481 |
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
5482 |
elseif ( !empty( $content_struct['dateCreated']) ) |
|
5483 |
$dateCreated = $content_struct['dateCreated']->getIso(); |
|
5484 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5485 |
// 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
|
5486 |
$edit_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5487 |
|
0 | 5488 |
if ( !empty( $dateCreated ) ) { |
5489 |
$post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
|
5490 |
$post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5491 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5492 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5493 |
$edit_date = true; |
0 | 5494 |
} else { |
5495 |
$post_date = $postdata['post_date']; |
|
5496 |
$post_date_gmt = $postdata['post_date_gmt']; |
|
5497 |
} |
|
5498 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5499 |
// We've got all the data -- post it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5500 |
$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'); |
0 | 5501 |
|
5502 |
$result = wp_update_post($newpost, true); |
|
5503 |
if ( is_wp_error( $result ) ) |
|
5504 |
return new IXR_Error(500, $result->get_error_message()); |
|
5505 |
||
5506 |
if ( !$result ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5507 |
return new IXR_Error(500, __('Sorry, your entry could not be edited.')); |
0 | 5508 |
|
5509 |
// Only posts can be sticky |
|
5510 |
if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5511 |
$data = $newpost; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5512 |
$data['sticky'] = $content_struct['sticky']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5513 |
$data['post_type'] = 'post'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5514 |
$error = $this->_toggle_sticky( $data, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5515 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5516 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5517 |
} |
0 | 5518 |
} |
5519 |
||
5520 |
if ( isset($content_struct['custom_fields']) ) |
|
5521 |
$this->set_custom_fields($post_ID, $content_struct['custom_fields']); |
|
5522 |
||
5523 |
if ( isset ( $content_struct['wp_post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5525 |
// Empty value deletes, non-empty value adds/updates. |
0 | 5526 |
if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
5527 |
delete_post_thumbnail( $post_ID ); |
|
5528 |
} else { |
|
5529 |
if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) |
|
5530 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
|
5531 |
} |
|
5532 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5533 |
} |
|
5534 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5535 |
// Handle enclosures. |
0 | 5536 |
$thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; |
5537 |
$this->add_enclosure_if_new($post_ID, $thisEnclosure); |
|
5538 |
||
5539 |
$this->attach_uploads( $ID, $post_content ); |
|
5540 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5541 |
// Handle post formats if assigned, validation is handled earlier in this function. |
0 | 5542 |
if ( isset( $content_struct['wp_post_format'] ) ) |
5543 |
set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
|
5544 |
||
5 | 5545 |
/** |
5546 |
* Fires after a post has been successfully updated via the XML-RPC MovableType API. |
|
5547 |
* |
|
5548 |
* @since 3.4.0 |
|
5549 |
* |
|
5550 |
* @param int $post_ID ID of the updated post. |
|
5551 |
* @param array $args An array of arguments to update the post. |
|
5552 |
*/ |
|
0 | 5553 |
do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); |
5554 |
||
5555 |
return true; |
|
5556 |
} |
|
5557 |
||
5558 |
/** |
|
5559 |
* Retrieve post. |
|
5560 |
* |
|
5561 |
* @since 1.5.0 |
|
5562 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5563 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5564 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5565 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5566 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5567 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5568 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5569 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5570 |
* } |
5 | 5571 |
* @return array|IXR_Error |
0 | 5572 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5573 |
public function mw_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5574 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5575 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5576 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5577 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5578 |
$password = $args[2]; |
0 | 5579 |
|
5580 |
if ( !$user = $this->login($username, $password) ) |
|
5581 |
return $this->error; |
|
5582 |
||
5583 |
$postdata = get_post($post_ID, ARRAY_A); |
|
5584 |
if ( ! $postdata ) |
|
5585 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
5586 |
||
5587 |
if ( !current_user_can( 'edit_post', $post_ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5588 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 5589 |
|
5 | 5590 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5591 |
do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
|
0 | 5592 |
|
5593 |
if ($postdata['post_date'] != '') { |
|
5594 |
$post_date = $this->_convert_date( $postdata['post_date'] ); |
|
5595 |
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
|
5596 |
$post_modified = $this->_convert_date( $postdata['post_modified'] ); |
|
5597 |
$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); |
|
5598 |
||
5599 |
$categories = array(); |
|
5600 |
$catids = wp_get_post_categories($post_ID); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5601 |
foreach ($catids as $catid) |
0 | 5602 |
$categories[] = get_cat_name($catid); |
5603 |
||
5604 |
$tagnames = array(); |
|
5605 |
$tags = wp_get_post_tags( $post_ID ); |
|
5606 |
if ( !empty( $tags ) ) { |
|
5607 |
foreach ( $tags as $tag ) |
|
5608 |
$tagnames[] = $tag->name; |
|
5609 |
$tagnames = implode( ', ', $tagnames ); |
|
5610 |
} else { |
|
5611 |
$tagnames = ''; |
|
5612 |
} |
|
5613 |
||
5614 |
$post = get_extended($postdata['post_content']); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5615 |
$link = get_permalink($postdata['ID']); |
0 | 5616 |
|
5617 |
// Get the author info. |
|
5618 |
$author = get_userdata($postdata['post_author']); |
|
5619 |
||
5620 |
$allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0; |
|
5621 |
$allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; |
|
5622 |
||
5623 |
// Consider future posts as published |
|
5624 |
if ( $postdata['post_status'] === 'future' ) |
|
5625 |
$postdata['post_status'] = 'publish'; |
|
5626 |
||
5627 |
// Get post format |
|
5628 |
$post_format = get_post_format( $post_ID ); |
|
5629 |
if ( empty( $post_format ) ) |
|
5630 |
$post_format = 'standard'; |
|
5631 |
||
5632 |
$sticky = false; |
|
5633 |
if ( is_sticky( $post_ID ) ) |
|
5634 |
$sticky = true; |
|
5635 |
||
5636 |
$enclosure = array(); |
|
5637 |
foreach ( (array) get_post_custom($post_ID) as $key => $val) { |
|
5638 |
if ($key == 'enclosure') { |
|
5639 |
foreach ( (array) $val as $enc ) { |
|
5640 |
$encdata = explode("\n", $enc); |
|
5641 |
$enclosure['url'] = trim(htmlspecialchars($encdata[0])); |
|
5642 |
$enclosure['length'] = (int) trim($encdata[1]); |
|
5643 |
$enclosure['type'] = trim($encdata[2]); |
|
5644 |
break 2; |
|
5645 |
} |
|
5646 |
} |
|
5647 |
} |
|
5648 |
||
5649 |
$resp = array( |
|
5650 |
'dateCreated' => $post_date, |
|
5651 |
'userid' => $postdata['post_author'], |
|
5652 |
'postid' => $postdata['ID'], |
|
5653 |
'description' => $post['main'], |
|
5654 |
'title' => $postdata['post_title'], |
|
5655 |
'link' => $link, |
|
5656 |
'permaLink' => $link, |
|
5657 |
// commented out because no other tool seems to use this |
|
5658 |
// 'content' => $entry['post_content'], |
|
5659 |
'categories' => $categories, |
|
5660 |
'mt_excerpt' => $postdata['post_excerpt'], |
|
5661 |
'mt_text_more' => $post['extended'], |
|
5662 |
'wp_more_text' => $post['more_text'], |
|
5663 |
'mt_allow_comments' => $allow_comments, |
|
5664 |
'mt_allow_pings' => $allow_pings, |
|
5665 |
'mt_keywords' => $tagnames, |
|
5666 |
'wp_slug' => $postdata['post_name'], |
|
5667 |
'wp_password' => $postdata['post_password'], |
|
5668 |
'wp_author_id' => (string) $author->ID, |
|
5669 |
'wp_author_display_name' => $author->display_name, |
|
5670 |
'date_created_gmt' => $post_date_gmt, |
|
5671 |
'post_status' => $postdata['post_status'], |
|
5672 |
'custom_fields' => $this->get_custom_fields($post_ID), |
|
5673 |
'wp_post_format' => $post_format, |
|
5674 |
'sticky' => $sticky, |
|
5675 |
'date_modified' => $post_modified, |
|
5676 |
'date_modified_gmt' => $post_modified_gmt |
|
5677 |
); |
|
5678 |
||
5679 |
if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure; |
|
5680 |
||
5681 |
$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] ); |
|
5682 |
||
5683 |
return $resp; |
|
5684 |
} else { |
|
5685 |
return new IXR_Error(404, __('Sorry, no such post.')); |
|
5686 |
} |
|
5687 |
} |
|
5688 |
||
5689 |
/** |
|
5690 |
* Retrieve list of recent posts. |
|
5691 |
* |
|
5692 |
* @since 1.5.0 |
|
5693 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5694 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5695 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5696 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5697 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5698 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5699 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5700 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5701 |
* } |
5 | 5702 |
* @return array|IXR_Error |
0 | 5703 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5704 |
public function mw_getRecentPosts( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5705 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5706 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5707 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5708 |
$password = $args[2]; |
0 | 5709 |
if ( isset( $args[3] ) ) |
5710 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
|
5711 |
else |
|
5712 |
$query = array(); |
|
5713 |
||
5714 |
if ( !$user = $this->login($username, $password) ) |
|
5715 |
return $this->error; |
|
5716 |
||
5717 |
if ( ! current_user_can( 'edit_posts' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5718 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
0 | 5719 |
|
5 | 5720 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5721 |
do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
|
0 | 5722 |
|
5723 |
$posts_list = wp_get_recent_posts( $query ); |
|
5724 |
||
5725 |
if ( !$posts_list ) |
|
5726 |
return array(); |
|
5727 |
||
5 | 5728 |
$recent_posts = array(); |
0 | 5729 |
foreach ($posts_list as $entry) { |
5730 |
if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
|
5731 |
continue; |
|
5732 |
||
5733 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
5734 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
5735 |
$post_modified = $this->_convert_date( $entry['post_modified'] ); |
|
5736 |
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] ); |
|
5737 |
||
5738 |
$categories = array(); |
|
5739 |
$catids = wp_get_post_categories($entry['ID']); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5740 |
foreach ( $catids as $catid ) |
0 | 5741 |
$categories[] = get_cat_name($catid); |
5742 |
||
5743 |
$tagnames = array(); |
|
5744 |
$tags = wp_get_post_tags( $entry['ID'] ); |
|
5745 |
if ( !empty( $tags ) ) { |
|
5746 |
foreach ( $tags as $tag ) { |
|
5747 |
$tagnames[] = $tag->name; |
|
5748 |
} |
|
5749 |
$tagnames = implode( ', ', $tagnames ); |
|
5750 |
} else { |
|
5751 |
$tagnames = ''; |
|
5752 |
} |
|
5753 |
||
5754 |
$post = get_extended($entry['post_content']); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5755 |
$link = get_permalink($entry['ID']); |
0 | 5756 |
|
5757 |
// Get the post author info. |
|
5758 |
$author = get_userdata($entry['post_author']); |
|
5759 |
||
5760 |
$allow_comments = ('open' == $entry['comment_status']) ? 1 : 0; |
|
5761 |
$allow_pings = ('open' == $entry['ping_status']) ? 1 : 0; |
|
5762 |
||
5763 |
// Consider future posts as published |
|
5764 |
if ( $entry['post_status'] === 'future' ) |
|
5765 |
$entry['post_status'] = 'publish'; |
|
5766 |
||
5767 |
// Get post format |
|
5768 |
$post_format = get_post_format( $entry['ID'] ); |
|
5769 |
if ( empty( $post_format ) ) |
|
5770 |
$post_format = 'standard'; |
|
5771 |
||
5 | 5772 |
$recent_posts[] = array( |
0 | 5773 |
'dateCreated' => $post_date, |
5774 |
'userid' => $entry['post_author'], |
|
5775 |
'postid' => (string) $entry['ID'], |
|
5776 |
'description' => $post['main'], |
|
5777 |
'title' => $entry['post_title'], |
|
5778 |
'link' => $link, |
|
5779 |
'permaLink' => $link, |
|
5780 |
// commented out because no other tool seems to use this |
|
5781 |
// 'content' => $entry['post_content'], |
|
5782 |
'categories' => $categories, |
|
5783 |
'mt_excerpt' => $entry['post_excerpt'], |
|
5784 |
'mt_text_more' => $post['extended'], |
|
5785 |
'wp_more_text' => $post['more_text'], |
|
5786 |
'mt_allow_comments' => $allow_comments, |
|
5787 |
'mt_allow_pings' => $allow_pings, |
|
5788 |
'mt_keywords' => $tagnames, |
|
5789 |
'wp_slug' => $entry['post_name'], |
|
5790 |
'wp_password' => $entry['post_password'], |
|
5791 |
'wp_author_id' => (string) $author->ID, |
|
5792 |
'wp_author_display_name' => $author->display_name, |
|
5793 |
'date_created_gmt' => $post_date_gmt, |
|
5794 |
'post_status' => $entry['post_status'], |
|
5795 |
'custom_fields' => $this->get_custom_fields($entry['ID']), |
|
5796 |
'wp_post_format' => $post_format, |
|
5797 |
'date_modified' => $post_modified, |
|
5 | 5798 |
'date_modified_gmt' => $post_modified_gmt, |
5799 |
'sticky' => ( $entry['post_type'] === 'post' && is_sticky( $entry['ID'] ) ), |
|
5800 |
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ) |
|
0 | 5801 |
); |
5802 |
} |
|
5803 |
||
5804 |
return $recent_posts; |
|
5805 |
} |
|
5806 |
||
5807 |
/** |
|
5808 |
* Retrieve the list of categories on a given blog. |
|
5809 |
* |
|
5810 |
* @since 1.5.0 |
|
5811 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5812 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5813 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5814 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5815 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5816 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5817 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5818 |
* } |
5 | 5819 |
* @return array|IXR_Error |
0 | 5820 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5821 |
public function mw_getCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5822 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5823 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5824 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5825 |
$password = $args[2]; |
0 | 5826 |
|
5827 |
if ( !$user = $this->login($username, $password) ) |
|
5828 |
return $this->error; |
|
5829 |
||
5830 |
if ( !current_user_can( 'edit_posts' ) ) |
|
5831 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
|
5832 |
||
5 | 5833 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5834 |
do_action( 'xmlrpc_call', 'metaWeblog.getCategories' ); |
|
0 | 5835 |
|
5836 |
$categories_struct = array(); |
|
5837 |
||
5838 |
if ( $cats = get_categories(array('get' => 'all')) ) { |
|
5839 |
foreach ( $cats as $cat ) { |
|
5 | 5840 |
$struct = array(); |
0 | 5841 |
$struct['categoryId'] = $cat->term_id; |
5842 |
$struct['parentId'] = $cat->parent; |
|
5843 |
$struct['description'] = $cat->name; |
|
5844 |
$struct['categoryDescription'] = $cat->description; |
|
5845 |
$struct['categoryName'] = $cat->name; |
|
5846 |
$struct['htmlUrl'] = esc_html(get_category_link($cat->term_id)); |
|
5847 |
$struct['rssUrl'] = esc_html(get_category_feed_link($cat->term_id, 'rss2')); |
|
5848 |
||
5849 |
$categories_struct[] = $struct; |
|
5850 |
} |
|
5851 |
} |
|
5852 |
||
5853 |
return $categories_struct; |
|
5854 |
} |
|
5855 |
||
5856 |
/** |
|
5857 |
* Uploads a file, following your settings. |
|
5858 |
* |
|
5859 |
* Adapted from a patch by Johann Richard. |
|
5860 |
* |
|
5861 |
* @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/ |
|
5862 |
* |
|
5863 |
* @since 1.5.0 |
|
5864 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5865 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5866 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5867 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5868 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5869 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5870 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5871 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5872 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5873 |
* @type array $data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5874 |
* } |
5 | 5875 |
* @return array|IXR_Error |
0 | 5876 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5877 |
public function mw_newMediaObject( $args ) { |
0 | 5878 |
global $wpdb; |
5879 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5880 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5881 |
$password = $this->escape( $args[2] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5882 |
$data = $args[3]; |
0 | 5883 |
|
5884 |
$name = sanitize_file_name( $data['name'] ); |
|
5885 |
$type = $data['type']; |
|
5886 |
$bits = $data['bits']; |
|
5887 |
||
5888 |
if ( !$user = $this->login($username, $password) ) |
|
5889 |
return $this->error; |
|
5890 |
||
5 | 5891 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5892 |
do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' ); |
|
0 | 5893 |
|
5894 |
if ( !current_user_can('upload_files') ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5895 |
$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
|
5896 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5897 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5898 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5899 |
if ( is_multisite() && upload_is_user_over_quota( false ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5900 |
$this->error = new IXR_Error( 401, __( 'Sorry, you have used your space allocation.' ) ); |
0 | 5901 |
return $this->error; |
5902 |
} |
|
5903 |
||
5 | 5904 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5905 |
* Filters whether to preempt the XML-RPC media upload. |
5 | 5906 |
* |
5907 |
* Passing a truthy value will effectively short-circuit the media upload, |
|
5908 |
* returning that value as a 500 error instead. |
|
5909 |
* |
|
5910 |
* @since 2.1.0 |
|
5911 |
* |
|
5912 |
* @param bool $error Whether to pre-empt the media upload. Default false. |
|
5913 |
*/ |
|
5914 |
if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) { |
|
5915 |
return new IXR_Error( 500, $upload_err ); |
|
5916 |
} |
|
0 | 5917 |
|
5918 |
$upload = wp_upload_bits($name, null, $bits); |
|
5919 |
if ( ! empty($upload['error']) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5920 |
/* translators: 1: file name, 2: error message */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5921 |
$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
|
5922 |
return new IXR_Error( 500, $errorString ); |
0 | 5923 |
} |
5924 |
// Construct the attachment array |
|
5925 |
$post_id = 0; |
|
5926 |
if ( ! empty( $data['post_id'] ) ) { |
|
5927 |
$post_id = (int) $data['post_id']; |
|
5928 |
||
5929 |
if ( ! current_user_can( 'edit_post', $post_id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5930 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 5931 |
} |
5932 |
$attachment = array( |
|
5933 |
'post_title' => $name, |
|
5934 |
'post_content' => '', |
|
5935 |
'post_type' => 'attachment', |
|
5936 |
'post_parent' => $post_id, |
|
5937 |
'post_mime_type' => $type, |
|
5938 |
'guid' => $upload[ 'url' ] |
|
5939 |
); |
|
5940 |
||
5941 |
// Save the data |
|
5942 |
$id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); |
|
5943 |
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
|
5944 |
||
5 | 5945 |
/** |
5946 |
* Fires after a new attachment has been added via the XML-RPC MovableType API. |
|
5947 |
* |
|
5948 |
* @since 3.4.0 |
|
5949 |
* |
|
5950 |
* @param int $id ID of the new attachment. |
|
5951 |
* @param array $args An array of arguments to add the attachment. |
|
5952 |
*/ |
|
0 | 5953 |
do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args ); |
5954 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5955 |
$struct = $this->_prepare_media_item( get_post( $id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5957 |
// Deprecated values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5958 |
$struct['id'] = $struct['attachment_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5959 |
$struct['file'] = $struct['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5960 |
$struct['url'] = $struct['link']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5961 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5962 |
return $struct; |
0 | 5963 |
} |
5964 |
||
5965 |
/* MovableType API functions |
|
5966 |
* specs on http://www.movabletype.org/docs/mtmanual_programmatic.html |
|
5967 |
*/ |
|
5968 |
||
5969 |
/** |
|
5970 |
* Retrieve the post titles of recent posts. |
|
5971 |
* |
|
5972 |
* @since 1.5.0 |
|
5973 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5974 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5975 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5976 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5977 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5978 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5979 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5980 |
* @type int $numberposts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5981 |
* } |
5 | 5982 |
* @return array|IXR_Error |
0 | 5983 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5984 |
public function mt_getRecentPostTitles( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5985 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5986 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5987 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5988 |
$password = $args[2]; |
0 | 5989 |
if ( isset( $args[3] ) ) |
5990 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
|
5991 |
else |
|
5992 |
$query = array(); |
|
5993 |
||
5994 |
if ( !$user = $this->login($username, $password) ) |
|
5995 |
return $this->error; |
|
5996 |
||
5 | 5997 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5998 |
do_action( 'xmlrpc_call', 'mt.getRecentPostTitles' ); |
|
0 | 5999 |
|
6000 |
$posts_list = wp_get_recent_posts( $query ); |
|
6001 |
||
6002 |
if ( !$posts_list ) { |
|
6003 |
$this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
|
6004 |
return $this->error; |
|
6005 |
} |
|
6006 |
||
5 | 6007 |
$recent_posts = array(); |
0 | 6008 |
|
6009 |
foreach ($posts_list as $entry) { |
|
6010 |
if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
|
6011 |
continue; |
|
6012 |
||
6013 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
6014 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
6015 |
||
5 | 6016 |
$recent_posts[] = array( |
0 | 6017 |
'dateCreated' => $post_date, |
6018 |
'userid' => $entry['post_author'], |
|
6019 |
'postid' => (string) $entry['ID'], |
|
6020 |
'title' => $entry['post_title'], |
|
6021 |
'post_status' => $entry['post_status'], |
|
6022 |
'date_created_gmt' => $post_date_gmt |
|
6023 |
); |
|
6024 |
} |
|
6025 |
||
6026 |
return $recent_posts; |
|
6027 |
} |
|
6028 |
||
6029 |
/** |
|
6030 |
* Retrieve list of all categories on blog. |
|
6031 |
* |
|
6032 |
* @since 1.5.0 |
|
6033 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6034 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6035 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6036 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6037 |
* @type int $blog_id (unused) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6038 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6039 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6040 |
* } |
5 | 6041 |
* @return array|IXR_Error |
0 | 6042 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6043 |
public function mt_getCategoryList( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6044 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6045 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6046 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6047 |
$password = $args[2]; |
0 | 6048 |
|
6049 |
if ( !$user = $this->login($username, $password) ) |
|
6050 |
return $this->error; |
|
6051 |
||
6052 |
if ( !current_user_can( 'edit_posts' ) ) |
|
6053 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
|
6054 |
||
5 | 6055 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6056 |
do_action( 'xmlrpc_call', 'mt.getCategoryList' ); |
|
0 | 6057 |
|
6058 |
$categories_struct = array(); |
|
6059 |
||
6060 |
if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) { |
|
6061 |
foreach ( $cats as $cat ) { |
|
5 | 6062 |
$struct = array(); |
0 | 6063 |
$struct['categoryId'] = $cat->term_id; |
6064 |
$struct['categoryName'] = $cat->name; |
|
6065 |
||
6066 |
$categories_struct[] = $struct; |
|
6067 |
} |
|
6068 |
} |
|
6069 |
||
6070 |
return $categories_struct; |
|
6071 |
} |
|
6072 |
||
6073 |
/** |
|
6074 |
* Retrieve post categories. |
|
6075 |
* |
|
6076 |
* @since 1.5.0 |
|
6077 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6078 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6079 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6080 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6081 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6082 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6083 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6084 |
* } |
5 | 6085 |
* @return array|IXR_Error |
0 | 6086 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6087 |
public function mt_getPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6088 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6089 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6090 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6091 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6092 |
$password = $args[2]; |
0 | 6093 |
|
6094 |
if ( !$user = $this->login($username, $password) ) |
|
6095 |
return $this->error; |
|
6096 |
||
6097 |
if ( ! get_post( $post_ID ) ) |
|
6098 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
6099 |
||
6100 |
if ( !current_user_can( 'edit_post', $post_ID ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6101 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
0 | 6102 |
|
5 | 6103 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6104 |
do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
|
0 | 6105 |
|
6106 |
$categories = array(); |
|
6107 |
$catids = wp_get_post_categories(intval($post_ID)); |
|
6108 |
// first listed category will be the primary category |
|
6109 |
$isPrimary = true; |
|
6110 |
foreach ( $catids as $catid ) { |
|
6111 |
$categories[] = array( |
|
6112 |
'categoryName' => get_cat_name($catid), |
|
6113 |
'categoryId' => (string) $catid, |
|
6114 |
'isPrimary' => $isPrimary |
|
6115 |
); |
|
6116 |
$isPrimary = false; |
|
6117 |
} |
|
6118 |
||
6119 |
return $categories; |
|
6120 |
} |
|
6121 |
||
6122 |
/** |
|
6123 |
* Sets categories for a post. |
|
6124 |
* |
|
6125 |
* @since 1.5.0 |
|
6126 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6127 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6128 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6129 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6130 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6131 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6132 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6133 |
* @type array $categories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6134 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6135 |
* @return true|IXR_Error True on success. |
0 | 6136 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6137 |
public function mt_setPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6138 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6140 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6141 |
$username = $args[1]; |
0 | 6142 |
$password = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6143 |
$categories = $args[3]; |
0 | 6144 |
|
6145 |
if ( !$user = $this->login($username, $password) ) |
|
6146 |
return $this->error; |
|
6147 |
||
5 | 6148 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6149 |
do_action( 'xmlrpc_call', 'mt.setPostCategories' ); |
|
0 | 6150 |
|
6151 |
if ( ! get_post( $post_ID ) ) |
|
6152 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
6153 |
||
6154 |
if ( !current_user_can('edit_post', $post_ID) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6155 |
return new IXR_Error(401, __('Sorry, you are not allowed to edit this post.')); |
0 | 6156 |
|
6157 |
$catids = array(); |
|
6158 |
foreach ( $categories as $cat ) { |
|
6159 |
$catids[] = $cat['categoryId']; |
|
6160 |
} |
|
6161 |
||
6162 |
wp_set_post_categories($post_ID, $catids); |
|
6163 |
||
6164 |
return true; |
|
6165 |
} |
|
6166 |
||
6167 |
/** |
|
6168 |
* Retrieve an array of methods supported by this server. |
|
6169 |
* |
|
6170 |
* @since 1.5.0 |
|
6171 |
* |
|
6172 |
* @return array |
|
6173 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6174 |
public function mt_supportedMethods() { |
5 | 6175 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6176 |
do_action( 'xmlrpc_call', 'mt.supportedMethods' ); |
|
0 | 6177 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6178 |
return array_keys( $this->methods ); |
0 | 6179 |
} |
6180 |
||
6181 |
/** |
|
6182 |
* Retrieve an empty array because we don't support per-post text filters. |
|
6183 |
* |
|
6184 |
* @since 1.5.0 |
|
6185 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6186 |
public function mt_supportedTextFilters() { |
5 | 6187 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6188 |
do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
|
6189 |
||
6190 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6191 |
* Filters the MoveableType text filters list for XML-RPC. |
5 | 6192 |
* |
6193 |
* @since 2.2.0 |
|
6194 |
* |
|
6195 |
* @param array $filters An array of text filters. |
|
6196 |
*/ |
|
6197 |
return apply_filters( 'xmlrpc_text_filters', array() ); |
|
0 | 6198 |
} |
6199 |
||
6200 |
/** |
|
6201 |
* Retrieve trackbacks sent to a given post. |
|
6202 |
* |
|
6203 |
* @since 1.5.0 |
|
6204 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6205 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6206 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6207 |
* @param int $post_ID |
5 | 6208 |
* @return array|IXR_Error |
0 | 6209 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6210 |
public function mt_getTrackbackPings( $post_ID ) { |
0 | 6211 |
global $wpdb; |
6212 |
||
5 | 6213 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6214 |
do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); |
|
0 | 6215 |
|
6216 |
$actual_post = get_post($post_ID, ARRAY_A); |
|
6217 |
||
6218 |
if ( !$actual_post ) |
|
6219 |
return new IXR_Error(404, __('Sorry, no such post.')); |
|
6220 |
||
6221 |
$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) ); |
|
6222 |
||
6223 |
if ( !$comments ) |
|
6224 |
return array(); |
|
6225 |
||
6226 |
$trackback_pings = array(); |
|
6227 |
foreach ( $comments as $comment ) { |
|
6228 |
if ( 'trackback' == $comment->comment_type ) { |
|
6229 |
$content = $comment->comment_content; |
|
6230 |
$title = substr($content, 8, (strpos($content, '</strong>') - 8)); |
|
6231 |
$trackback_pings[] = array( |
|
6232 |
'pingTitle' => $title, |
|
6233 |
'pingURL' => $comment->comment_author_url, |
|
6234 |
'pingIP' => $comment->comment_author_IP |
|
6235 |
); |
|
6236 |
} |
|
6237 |
} |
|
6238 |
||
6239 |
return $trackback_pings; |
|
6240 |
} |
|
6241 |
||
6242 |
/** |
|
6243 |
* Sets a post's publish status to 'publish'. |
|
6244 |
* |
|
6245 |
* @since 1.5.0 |
|
6246 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6247 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6248 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6249 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6250 |
* @type int $post_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6251 |
* @type string $username |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6252 |
* @type string $password |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6253 |
* } |
5 | 6254 |
* @return int|IXR_Error |
0 | 6255 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6256 |
public function mt_publishPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6257 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6258 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6259 |
$post_ID = (int) $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6260 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6261 |
$password = $args[2]; |
0 | 6262 |
|
6263 |
if ( !$user = $this->login($username, $password) ) |
|
6264 |
return $this->error; |
|
6265 |
||
5 | 6266 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6267 |
do_action( 'xmlrpc_call', 'mt.publishPost' ); |
|
0 | 6268 |
|
6269 |
$postdata = get_post($post_ID, ARRAY_A); |
|
6270 |
if ( ! $postdata ) |
|
6271 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
6272 |
||
6273 |
if ( !current_user_can('publish_posts') || !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 publish this post.')); |
0 | 6275 |
|
6276 |
$postdata['post_status'] = 'publish'; |
|
6277 |
||
6278 |
// retain old cats |
|
6279 |
$cats = wp_get_post_categories($post_ID); |
|
6280 |
$postdata['post_category'] = $cats; |
|
6281 |
$this->escape($postdata); |
|
6282 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6283 |
return wp_update_post( $postdata ); |
0 | 6284 |
} |
6285 |
||
6286 |
/* PingBack functions |
|
6287 |
* specs on www.hixie.ch/specs/pingback/pingback |
|
6288 |
*/ |
|
6289 |
||
6290 |
/** |
|
6291 |
* Retrieves a pingback and registers it. |
|
6292 |
* |
|
6293 |
* @since 1.5.0 |
|
6294 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6295 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6296 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6297 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6298 |
* @type string $pagelinkedfrom |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6299 |
* @type string $pagelinkedto |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6300 |
* } |
5 | 6301 |
* @return string|IXR_Error |
0 | 6302 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6303 |
public function pingback_ping( $args ) { |
0 | 6304 |
global $wpdb; |
6305 |
||
5 | 6306 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6307 |
do_action( 'xmlrpc_call', 'pingback.ping' ); |
|
0 | 6308 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6309 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6310 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6311 |
$pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6312 |
$pagelinkedto = str_replace( '&', '&', $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6313 |
$pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
0 | 6314 |
|
5 | 6315 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6316 |
* Filters the pingback source URI. |
5 | 6317 |
* |
6318 |
* @since 3.6.0 |
|
6319 |
* |
|
6320 |
* @param string $pagelinkedfrom URI of the page linked from. |
|
6321 |
* @param string $pagelinkedto URI of the page linked to. |
|
6322 |
*/ |
|
0 | 6323 |
$pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5 | 6324 |
|
0 | 6325 |
if ( ! $pagelinkedfrom ) |
6326 |
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
|
6327 |
||
6328 |
// Check if the page linked to is in our site |
|
6329 |
$pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home'))); |
|
6330 |
if ( !$pos1 ) |
|
6331 |
return $this->pingback_error( 0, __( 'Is there no link to us?' ) ); |
|
6332 |
||
6333 |
// let's find which post is linked to |
|
6334 |
// FIXME: does url_to_postid() cover all these cases already? |
|
6335 |
// if so, then let's use it and drop the old code. |
|
6336 |
$urltest = parse_url($pagelinkedto); |
|
6337 |
if ( $post_ID = url_to_postid($pagelinkedto) ) { |
|
5 | 6338 |
// $way |
6339 |
} elseif ( isset( $urltest['path'] ) && preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) { |
|
0 | 6340 |
// the path defines the post_ID (archives/p/XXXX) |
6341 |
$blah = explode('/', $match[0]); |
|
6342 |
$post_ID = (int) $blah[1]; |
|
6343 |
} elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) { |
|
6344 |
// the querystring defines the post_ID (?p=XXXX) |
|
6345 |
$blah = explode('=', $match[0]); |
|
6346 |
$post_ID = (int) $blah[1]; |
|
6347 |
} elseif ( isset($urltest['fragment']) ) { |
|
6348 |
// an #anchor is there, it's either... |
|
6349 |
if ( intval($urltest['fragment']) ) { |
|
6350 |
// ...an integer #XXXX (simplest case) |
|
6351 |
$post_ID = (int) $urltest['fragment']; |
|
6352 |
} elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) { |
|
6353 |
// ...a post id in the form 'post-###' |
|
6354 |
$post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); |
|
6355 |
} elseif ( is_string($urltest['fragment']) ) { |
|
6356 |
// ...or a string #title, a little more complicated |
|
6357 |
$title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); |
|
5 | 6358 |
$sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
0 | 6359 |
if (! ($post_ID = $wpdb->get_var($sql)) ) { |
6360 |
// returning unknown error '0' is better than die()ing |
|
6361 |
return $this->pingback_error( 0, '' ); |
|
6362 |
} |
|
6363 |
} |
|
6364 |
} else { |
|
6365 |
// TODO: Attempt to extract a post ID from the given URL |
|
6366 |
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.' ) ); |
|
6367 |
} |
|
6368 |
$post_ID = (int) $post_ID; |
|
6369 |
||
6370 |
$post = get_post($post_ID); |
|
6371 |
||
6372 |
if ( !$post ) // Post_ID not found |
|
6373 |
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.' ) ); |
|
6374 |
||
6375 |
if ( $post_ID == url_to_postid($pagelinkedfrom) ) |
|
6376 |
return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); |
|
6377 |
||
6378 |
// Check if pings are on |
|
6379 |
if ( !pings_open($post) ) |
|
6380 |
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.' ) ); |
|
6381 |
||
6382 |
// Let's check that the remote site didn't already pingback this entry |
|
6383 |
if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) ) |
|
6384 |
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
|
6385 |
||
6386 |
// very stupid, but gives time to the 'from' server to publish ! |
|
6387 |
sleep(1); |
|
6388 |
||
5 | 6389 |
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
6390 |
||
6391 |
/** This filter is documented in wp-includes/class-http.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6392 |
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ); |
5 | 6393 |
|
0 | 6394 |
// Let's check the remote site |
6395 |
$http_api_args = array( |
|
6396 |
'timeout' => 10, |
|
6397 |
'redirection' => 0, |
|
6398 |
'limit_response_size' => 153600, // 150 KB |
|
5 | 6399 |
'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
6400 |
'headers' => array( |
|
6401 |
'X-Pingback-Forwarded-For' => $remote_ip, |
|
6402 |
), |
|
0 | 6403 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6404 |
|
5 | 6405 |
$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
|
6406 |
$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
|
6407 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6408 |
if ( ! $remote_source ) { |
5 | 6409 |
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
|
6410 |
} |
5 | 6411 |
|
6412 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6413 |
* Filters the pingback remote source. |
5 | 6414 |
* |
6415 |
* @since 2.5.0 |
|
6416 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6417 |
* @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
|
6418 |
* @param string $pagelinkedto URL of the page linked to. |
5 | 6419 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6420 |
$remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
0 | 6421 |
|
6422 |
// Work around bug in strip_tags(): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6423 |
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6424 |
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6425 |
$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 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6426 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6427 |
preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6428 |
$title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6429 |
if ( empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6430 |
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
|
6431 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6432 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6433 |
$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
|
6434 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6435 |
$p = explode( "\n\n", $remote_source ); |
0 | 6436 |
|
6437 |
$preg_target = preg_quote($pagelinkedto, '|'); |
|
6438 |
||
6439 |
foreach ( $p as $para ) { |
|
6440 |
if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link? |
|
6441 |
preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context); |
|
6442 |
||
6443 |
// If the URL isn't in a link context, keep looking |
|
6444 |
if ( empty($context) ) |
|
6445 |
continue; |
|
6446 |
||
6447 |
// We're going to use this fake tag to mark the context in a bit |
|
6448 |
// the marker is needed in case the link text appears more than once in the paragraph |
|
6449 |
$excerpt = preg_replace('|\</?wpcontext\>|', '', $para); |
|
6450 |
||
6451 |
// prevent really long link text |
|
6452 |
if ( strlen($context[1]) > 100 ) |
|
6453 |
$context[1] = substr($context[1], 0, 100) . '…'; |
|
6454 |
||
6455 |
$marker = '<wpcontext>'.$context[1].'</wpcontext>'; // set up our marker |
|
6456 |
$excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker |
|
6457 |
$excerpt = strip_tags($excerpt, '<wpcontext>'); // strip all tags but our context marker |
|
6458 |
$excerpt = trim($excerpt); |
|
6459 |
$preg_marker = preg_quote($marker, '|'); |
|
6460 |
$excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt); |
|
6461 |
$excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper |
|
6462 |
break; |
|
6463 |
} |
|
6464 |
} |
|
6465 |
||
6466 |
if ( empty($context) ) // Link to target not found |
|
6467 |
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.' ) ); |
|
6468 |
||
6469 |
$pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); |
|
6470 |
||
6471 |
$context = '[…] ' . esc_html( $excerpt ) . ' […]'; |
|
6472 |
$pagelinkedfrom = $this->escape( $pagelinkedfrom ); |
|
6473 |
||
6474 |
$comment_post_ID = (int) $post_ID; |
|
6475 |
$comment_author = $title; |
|
6476 |
$comment_author_email = ''; |
|
6477 |
$this->escape($comment_author); |
|
6478 |
$comment_author_url = $pagelinkedfrom; |
|
6479 |
$comment_content = $context; |
|
6480 |
$this->escape($comment_content); |
|
6481 |
$comment_type = 'pingback'; |
|
6482 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6483 |
$commentdata = compact( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6484 |
'comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6485 |
'comment_content', 'comment_type', 'remote_source', 'remote_source_original' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6486 |
); |
0 | 6487 |
|
6488 |
$comment_ID = wp_new_comment($commentdata); |
|
5 | 6489 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6490 |
if ( is_wp_error( $comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6491 |
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
|
6492 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6493 |
|
5 | 6494 |
/** |
6495 |
* Fires after a post pingback has been sent. |
|
6496 |
* |
|
6497 |
* @since 0.71 |
|
6498 |
* |
|
6499 |
* @param int $comment_ID Comment ID. |
|
6500 |
*/ |
|
6501 |
do_action( 'pingback_post', $comment_ID ); |
|
0 | 6502 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6503 |
/* 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
|
6504 |
return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
0 | 6505 |
} |
6506 |
||
6507 |
/** |
|
6508 |
* Retrieve array of URLs that pingbacked the given URL. |
|
6509 |
* |
|
6510 |
* Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
|
6511 |
* |
|
6512 |
* @since 1.5.0 |
|
6513 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6514 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6515 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6516 |
* @param string $url |
5 | 6517 |
* @return array|IXR_Error |
0 | 6518 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6519 |
public function pingback_extensions_getPingbacks( $url ) { |
0 | 6520 |
global $wpdb; |
6521 |
||
5 | 6522 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6523 |
do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
|
0 | 6524 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6525 |
$url = $this->escape( $url ); |
0 | 6526 |
|
6527 |
$post_ID = url_to_postid($url); |
|
6528 |
if ( !$post_ID ) { |
|
6529 |
// We aren't sure that the resource is available and/or pingback enabled |
|
6530 |
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.' ) ); |
|
6531 |
} |
|
6532 |
||
6533 |
$actual_post = get_post($post_ID, ARRAY_A); |
|
6534 |
||
6535 |
if ( !$actual_post ) { |
|
6536 |
// No such post = resource not found |
|
6537 |
return $this->pingback_error( 32, __('The specified target URL does not exist.' ) ); |
|
6538 |
} |
|
6539 |
||
6540 |
$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) ); |
|
6541 |
||
6542 |
if ( !$comments ) |
|
6543 |
return array(); |
|
6544 |
||
6545 |
$pingbacks = array(); |
|
6546 |
foreach ( $comments as $comment ) { |
|
6547 |
if ( 'pingback' == $comment->comment_type ) |
|
6548 |
$pingbacks[] = $comment->comment_author_url; |
|
6549 |
} |
|
6550 |
||
6551 |
return $pingbacks; |
|
6552 |
} |
|
6553 |
||
5 | 6554 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6555 |
* 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
|
6556 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6557 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6558 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6559 |
* @param int $code Error code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6560 |
* @param string $message Error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6561 |
* @return IXR_Error Error object. |
5 | 6562 |
*/ |
0 | 6563 |
protected function pingback_error( $code, $message ) { |
5 | 6564 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6565 |
* Filters the XML-RPC pingback error return. |
5 | 6566 |
* |
6567 |
* @since 3.5.1 |
|
6568 |
* |
|
6569 |
* @param IXR_Error $error An IXR_Error object containing the error code and message. |
|
6570 |
*/ |
|
0 | 6571 |
return apply_filters( 'xmlrpc_pingback_error', new IXR_Error( $code, $message ) ); |
6572 |
} |
|
6573 |
} |