author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3 |
* XML-RPC protocol support for WordPress. |
0 | 4 |
* |
5 |
* @package WordPress |
|
5 | 6 |
* @subpackage Publishing |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
10 |
* WordPress XMLRPC server implementation. |
|
11 |
* |
|
12 |
* Implements compatibility for Blogger API, MetaWeblog API, MovableType, and |
|
13 |
* pingback. Additional WordPress API for managing comments, pages, posts, |
|
14 |
* options, etc. |
|
15 |
* |
|
16 |
* As of WordPress 3.5.0, XML-RPC is enabled by default. It can be disabled |
|
18 | 17 |
* via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::set_is_enabled(). |
0 | 18 |
* |
19 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @see IXR_Server |
0 | 22 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
#[AllowDynamicProperties] |
0 | 24 |
class wp_xmlrpc_server extends IXR_Server { |
5 | 25 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* Methods. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* |
5 | 28 |
* @var array |
29 |
*/ |
|
30 |
public $methods; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
|
5 | 32 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* Blog options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* |
5 | 35 |
* @var array |
36 |
*/ |
|
37 |
public $blog_options; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
|
5 | 39 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* IXR_Error instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* |
5 | 42 |
* @var IXR_Error |
43 |
*/ |
|
44 |
public $error; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
|
0 | 46 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* 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
|
48 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
protected $auth_failed = false; |
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 |
/** |
18 | 54 |
* Flags that XML-RPC is enabled |
55 |
* |
|
56 |
* @var bool |
|
57 |
*/ |
|
58 |
private $is_enabled; |
|
59 |
||
60 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* Registers all of the XMLRPC methods that XMLRPC server understands. |
0 | 62 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
* Sets up server and method property. Passes XMLRPC methods through the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
* {@see 'xmlrpc_methods'} filter to allow plugins to extend or replace |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
* XML-RPC methods. |
0 | 66 |
* |
67 |
* @since 1.5.0 |
|
68 |
*/ |
|
5 | 69 |
public function __construct() { |
0 | 70 |
$this->methods = array( |
16 | 71 |
// WordPress API. |
9 | 72 |
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', |
73 |
'wp.newPost' => 'this:wp_newPost', |
|
74 |
'wp.editPost' => 'this:wp_editPost', |
|
75 |
'wp.deletePost' => 'this:wp_deletePost', |
|
76 |
'wp.getPost' => 'this:wp_getPost', |
|
77 |
'wp.getPosts' => 'this:wp_getPosts', |
|
78 |
'wp.newTerm' => 'this:wp_newTerm', |
|
79 |
'wp.editTerm' => 'this:wp_editTerm', |
|
80 |
'wp.deleteTerm' => 'this:wp_deleteTerm', |
|
81 |
'wp.getTerm' => 'this:wp_getTerm', |
|
82 |
'wp.getTerms' => 'this:wp_getTerms', |
|
83 |
'wp.getTaxonomy' => 'this:wp_getTaxonomy', |
|
84 |
'wp.getTaxonomies' => 'this:wp_getTaxonomies', |
|
85 |
'wp.getUser' => 'this:wp_getUser', |
|
86 |
'wp.getUsers' => 'this:wp_getUsers', |
|
87 |
'wp.getProfile' => 'this:wp_getProfile', |
|
88 |
'wp.editProfile' => 'this:wp_editProfile', |
|
89 |
'wp.getPage' => 'this:wp_getPage', |
|
90 |
'wp.getPages' => 'this:wp_getPages', |
|
91 |
'wp.newPage' => 'this:wp_newPage', |
|
92 |
'wp.deletePage' => 'this:wp_deletePage', |
|
93 |
'wp.editPage' => 'this:wp_editPage', |
|
94 |
'wp.getPageList' => 'this:wp_getPageList', |
|
95 |
'wp.getAuthors' => 'this:wp_getAuthors', |
|
16 | 96 |
'wp.getCategories' => 'this:mw_getCategories', // Alias. |
9 | 97 |
'wp.getTags' => 'this:wp_getTags', |
98 |
'wp.newCategory' => 'this:wp_newCategory', |
|
99 |
'wp.deleteCategory' => 'this:wp_deleteCategory', |
|
100 |
'wp.suggestCategories' => 'this:wp_suggestCategories', |
|
16 | 101 |
'wp.uploadFile' => 'this:mw_newMediaObject', // Alias. |
102 |
'wp.deleteFile' => 'this:wp_deletePost', // Alias. |
|
9 | 103 |
'wp.getCommentCount' => 'this:wp_getCommentCount', |
104 |
'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
|
105 |
'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
|
106 |
'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
|
107 |
'wp.getOptions' => 'this:wp_getOptions', |
|
108 |
'wp.setOptions' => 'this:wp_setOptions', |
|
109 |
'wp.getComment' => 'this:wp_getComment', |
|
110 |
'wp.getComments' => 'this:wp_getComments', |
|
111 |
'wp.deleteComment' => 'this:wp_deleteComment', |
|
112 |
'wp.editComment' => 'this:wp_editComment', |
|
113 |
'wp.newComment' => 'this:wp_newComment', |
|
114 |
'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', |
|
115 |
'wp.getMediaItem' => 'this:wp_getMediaItem', |
|
116 |
'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', |
|
117 |
'wp.getPostFormats' => 'this:wp_getPostFormats', |
|
118 |
'wp.getPostType' => 'this:wp_getPostType', |
|
119 |
'wp.getPostTypes' => 'this:wp_getPostTypes', |
|
120 |
'wp.getRevisions' => 'this:wp_getRevisions', |
|
121 |
'wp.restoreRevision' => 'this:wp_restoreRevision', |
|
0 | 122 |
|
16 | 123 |
// Blogger API. |
9 | 124 |
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
125 |
'blogger.getUserInfo' => 'this:blogger_getUserInfo', |
|
126 |
'blogger.getPost' => 'this:blogger_getPost', |
|
127 |
'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', |
|
128 |
'blogger.newPost' => 'this:blogger_newPost', |
|
129 |
'blogger.editPost' => 'this:blogger_editPost', |
|
130 |
'blogger.deletePost' => 'this:blogger_deletePost', |
|
0 | 131 |
|
16 | 132 |
// MetaWeblog API (with MT extensions to structs). |
9 | 133 |
'metaWeblog.newPost' => 'this:mw_newPost', |
134 |
'metaWeblog.editPost' => 'this:mw_editPost', |
|
135 |
'metaWeblog.getPost' => 'this:mw_getPost', |
|
136 |
'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', |
|
137 |
'metaWeblog.getCategories' => 'this:mw_getCategories', |
|
138 |
'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', |
|
0 | 139 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
* MetaWeblog API aliases for Blogger API. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
* See http://www.xmlrpc.com/stories/storyReader$2460 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
*/ |
9 | 144 |
'metaWeblog.deletePost' => 'this:blogger_deletePost', |
145 |
'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|
0 | 146 |
|
16 | 147 |
// MovableType API. |
9 | 148 |
'mt.getCategoryList' => 'this:mt_getCategoryList', |
149 |
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', |
|
150 |
'mt.getPostCategories' => 'this:mt_getPostCategories', |
|
151 |
'mt.setPostCategories' => 'this:mt_setPostCategories', |
|
152 |
'mt.supportedMethods' => 'this:mt_supportedMethods', |
|
153 |
'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', |
|
154 |
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', |
|
155 |
'mt.publishPost' => 'this:mt_publishPost', |
|
0 | 156 |
|
16 | 157 |
// Pingback. |
9 | 158 |
'pingback.ping' => 'this:pingback_ping', |
0 | 159 |
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', |
160 |
||
9 | 161 |
'demo.sayHello' => 'this:sayHello', |
162 |
'demo.addTwoNumbers' => 'this:addTwoNumbers', |
|
0 | 163 |
); |
164 |
||
165 |
$this->initialise_blog_option_info(); |
|
5 | 166 |
|
167 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* Filters the methods exposed by the XML-RPC server. |
5 | 169 |
* |
170 |
* This filter can be used to add new methods, and remove built-in methods. |
|
171 |
* |
|
172 |
* @since 1.5.0 |
|
173 |
* |
|
16 | 174 |
* @param string[] $methods An array of XML-RPC methods, keyed by their methodName. |
5 | 175 |
*/ |
176 |
$this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
|
18 | 177 |
|
178 |
$this->set_is_enabled(); |
|
179 |
} |
|
180 |
||
181 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
* Sets wp_xmlrpc_server::$is_enabled property. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
* Determines whether the xmlrpc server is enabled on this WordPress install |
18 | 185 |
* and set the is_enabled property accordingly. |
186 |
* |
|
187 |
* @since 5.7.3 |
|
188 |
*/ |
|
189 |
private function set_is_enabled() { |
|
190 |
/* |
|
191 |
* Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
|
19 | 192 |
* option was deprecated in 3.5.0. Use the {@see 'xmlrpc_enabled'} hook instead. |
18 | 193 |
*/ |
194 |
$is_enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
|
195 |
if ( false === $is_enabled ) { |
|
196 |
$is_enabled = apply_filters( 'option_enable_xmlrpc', true ); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Filters whether XML-RPC methods requiring authentication are enabled. |
|
201 |
* |
|
202 |
* Contrary to the way it's named, this filter does not control whether XML-RPC is *fully* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
* enabled, rather, it only controls whether XML-RPC methods requiring authentication - |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
* such as for publishing purposes - are enabled. |
18 | 205 |
* |
206 |
* Further, the filter does not control whether pingbacks or other custom endpoints that don't |
|
207 |
* require authentication are enabled. This behavior is expected, and due to how parity was matched |
|
208 |
* with the `enable_xmlrpc` UI option the filter replaced when it was introduced in 3.5. |
|
209 |
* |
|
210 |
* To disable XML-RPC methods that require authentication, use: |
|
211 |
* |
|
212 |
* add_filter( 'xmlrpc_enabled', '__return_false' ); |
|
213 |
* |
|
214 |
* For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
|
215 |
* and {@see 'xmlrpc_element_limit'} hooks. |
|
216 |
* |
|
217 |
* @since 3.5.0 |
|
218 |
* |
|
219 |
* @param bool $is_enabled Whether XML-RPC is enabled. Default true. |
|
220 |
*/ |
|
221 |
$this->is_enabled = apply_filters( 'xmlrpc_enabled', $is_enabled ); |
|
0 | 222 |
} |
223 |
||
5 | 224 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
225 |
* Makes private/protected methods readable for backward compatibility. |
5 | 226 |
* |
227 |
* @since 4.0.0 |
|
228 |
* |
|
16 | 229 |
* @param string $name Method to call. |
230 |
* @param array $arguments Arguments to pass when calling. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* @return array|IXR_Error|false Return value of the callback, false otherwise. |
5 | 232 |
*/ |
233 |
public function __call( $name, $arguments ) { |
|
234 |
if ( '_multisite_getUsersBlogs' === $name ) { |
|
16 | 235 |
return $this->_multisite_getUsersBlogs( ...$arguments ); |
5 | 236 |
} |
237 |
return false; |
|
238 |
} |
|
239 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* Serves the XML-RPC request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
*/ |
5 | 245 |
public function serve_request() { |
9 | 246 |
$this->IXR_Server( $this->methods ); |
0 | 247 |
} |
248 |
||
249 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
250 |
* Tests XMLRPC API by saying, "Hello!" to client. |
0 | 251 |
* |
252 |
* @since 1.5.0 |
|
253 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* @return string Hello string response. |
0 | 255 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
public function sayHello() { |
0 | 257 |
return 'Hello!'; |
258 |
} |
|
259 |
||
260 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
* Tests XMLRPC API by adding two numbers for client. |
0 | 262 |
* |
263 |
* @since 1.5.0 |
|
264 |
* |
|
16 | 265 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
* @type int $0 A number to add. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
* @type int $1 A second number to add. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
* @return int Sum of the two given numbers. |
0 | 272 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
public function addTwoNumbers( $args ) { |
0 | 274 |
$number1 = $args[0]; |
275 |
$number2 = $args[1]; |
|
276 |
return $number1 + $number2; |
|
277 |
} |
|
278 |
||
279 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
* Logs user in. |
0 | 281 |
* |
282 |
* @since 2.8.0 |
|
283 |
* |
|
284 |
* @param string $username User's username. |
|
285 |
* @param string $password User's password. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
* @return WP_User|false WP_User object if authentication passed, false otherwise. |
0 | 287 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
288 |
public function login( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
289 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
290 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
291 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
292 |
) { |
18 | 293 |
if ( ! $this->is_enabled ) { |
0 | 294 |
$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
295 |
return false; |
|
296 |
} |
|
297 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
if ( $this->auth_failed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
$user = new WP_Error( 'login_prevented' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
$user = wp_authenticate( $username, $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
if ( is_wp_error( $user ) ) { |
0 | 305 |
$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) ); |
5 | 306 |
|
16 | 307 |
// Flag that authentication has failed once on this wp_xmlrpc_server instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
$this->auth_failed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
|
5 | 310 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
* Filters the XML-RPC user login error message. |
5 | 312 |
* |
313 |
* @since 3.5.0 |
|
314 |
* |
|
18 | 315 |
* @param IXR_Error $error The XML-RPC error message. |
316 |
* @param WP_Error $user WP_Error object. |
|
5 | 317 |
*/ |
0 | 318 |
$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user ); |
319 |
return false; |
|
320 |
} |
|
321 |
||
322 |
wp_set_current_user( $user->ID ); |
|
323 |
return $user; |
|
324 |
} |
|
325 |
||
326 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
* Checks user's credentials. Deprecated. |
0 | 328 |
* |
329 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
* @deprecated 2.8.0 Use wp_xmlrpc_server::login() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
* @see wp_xmlrpc_server::login() |
0 | 332 |
* |
333 |
* @param string $username User's username. |
|
334 |
* @param string $password User's password. |
|
335 |
* @return bool Whether authentication passed. |
|
336 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
337 |
public function login_pass_ok( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
338 |
$username, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
339 |
#[\SensitiveParameter] |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
340 |
$password |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
341 |
) { |
0 | 342 |
return (bool) $this->login( $username, $password ); |
343 |
} |
|
344 |
||
345 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
* Escapes string or array of strings for database. |
0 | 347 |
* |
348 |
* @since 1.5.2 |
|
349 |
* |
|
350 |
* @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
|
351 |
* @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
|
352 |
* when array is passed. |
0 | 353 |
*/ |
5 | 354 |
public function escape( &$data ) { |
9 | 355 |
if ( ! is_array( $data ) ) { |
0 | 356 |
return wp_slash( $data ); |
9 | 357 |
} |
0 | 358 |
|
359 |
foreach ( $data as &$v ) { |
|
9 | 360 |
if ( is_array( $v ) ) { |
0 | 361 |
$this->escape( $v ); |
9 | 362 |
} elseif ( ! is_object( $v ) ) { |
0 | 363 |
$v = wp_slash( $v ); |
9 | 364 |
} |
0 | 365 |
} |
366 |
} |
|
367 |
||
368 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
* Sends error response to client. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
* Sends an XML error response to the client. If the endpoint is enabled |
18 | 372 |
* an HTTP 200 response is always sent per the XML-RPC specification. |
373 |
* |
|
374 |
* @since 5.7.3 |
|
375 |
* |
|
376 |
* @param IXR_Error|string $error Error code or an error object. |
|
377 |
* @param false $message Error message. Optional. |
|
378 |
*/ |
|
379 |
public function error( $error, $message = false ) { |
|
380 |
// Accepts either an error object or an error code and message |
|
381 |
if ( $message && ! is_object( $error ) ) { |
|
382 |
$error = new IXR_Error( $error, $message ); |
|
383 |
} |
|
384 |
||
385 |
if ( ! $this->is_enabled ) { |
|
386 |
status_header( $error->code ); |
|
387 |
} |
|
388 |
||
389 |
$this->output( $error->getXml() ); |
|
390 |
} |
|
391 |
||
392 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
* Retrieves custom fields for post. |
0 | 394 |
* |
395 |
* @since 2.5.0 |
|
396 |
* |
|
397 |
* @param int $post_id Post ID. |
|
398 |
* @return array Custom fields, if exist. |
|
399 |
*/ |
|
9 | 400 |
public function get_custom_fields( $post_id ) { |
0 | 401 |
$post_id = (int) $post_id; |
402 |
||
403 |
$custom_fields = array(); |
|
404 |
||
9 | 405 |
foreach ( (array) has_meta( $post_id ) as $meta ) { |
0 | 406 |
// Don't expose protected fields. |
9 | 407 |
if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) { |
0 | 408 |
continue; |
9 | 409 |
} |
0 | 410 |
|
411 |
$custom_fields[] = array( |
|
9 | 412 |
'id' => $meta['meta_id'], |
413 |
'key' => $meta['meta_key'], |
|
414 |
'value' => $meta['meta_value'], |
|
0 | 415 |
); |
416 |
} |
|
417 |
||
418 |
return $custom_fields; |
|
419 |
} |
|
420 |
||
421 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
* Sets custom fields for post. |
0 | 423 |
* |
424 |
* @since 2.5.0 |
|
425 |
* |
|
16 | 426 |
* @param int $post_id Post ID. |
427 |
* @param array $fields Custom fields. |
|
0 | 428 |
*/ |
9 | 429 |
public function set_custom_fields( $post_id, $fields ) { |
0 | 430 |
$post_id = (int) $post_id; |
431 |
||
432 |
foreach ( (array) $fields as $meta ) { |
|
9 | 433 |
if ( isset( $meta['id'] ) ) { |
0 | 434 |
$meta['id'] = (int) $meta['id']; |
9 | 435 |
$pmeta = get_metadata_by_mid( 'post', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
437 |
if ( ! $pmeta || (int) $pmeta->post_id !== $post_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
continue; |
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 |
|
9 | 441 |
if ( isset( $meta['key'] ) ) { |
0 | 442 |
$meta['key'] = wp_unslash( $meta['key'] ); |
9 | 443 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
0 | 444 |
continue; |
9 | 445 |
} |
0 | 446 |
$meta['value'] = wp_unslash( $meta['value'] ); |
9 | 447 |
if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) { |
0 | 448 |
update_metadata_by_mid( 'post', $meta['id'], $meta['value'] ); |
9 | 449 |
} |
0 | 450 |
} elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) { |
451 |
delete_metadata_by_mid( 'post', $meta['id'] ); |
|
452 |
} |
|
453 |
} elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { |
|
454 |
add_post_meta( $post_id, $meta['key'], $meta['value'] ); |
|
455 |
} |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
460 |
* Retrieves custom fields for a term. |
7
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 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* @return array Array of custom fields, if they exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
public function get_term_custom_fields( $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
$custom_fields = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
$custom_fields[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
'id' => $meta['meta_id'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
'key' => $meta['meta_key'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
'value' => $meta['meta_value'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
return $custom_fields; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
* Sets custom fields for a term. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* |
16 | 493 |
* @param int $term_id Term ID. |
494 |
* @param array $fields Custom fields. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
public function set_term_custom_fields( $term_id, $fields ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$term_id = (int) $term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
foreach ( (array) $fields as $meta ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
if ( isset( $meta['id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
$meta['id'] = (int) $meta['id']; |
9 | 502 |
$pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
if ( isset( $meta['key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
$meta['key'] = wp_unslash( $meta['key'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
if ( $meta['key'] !== $pmeta->meta_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
$meta['value'] = wp_unslash( $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
} elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
delete_metadata_by_mid( 'term', $meta['id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
} elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
* Sets up blog options property. |
0 | 523 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* Passes property through {@see 'xmlrpc_blog_options'} filter. |
0 | 525 |
* |
526 |
* @since 2.6.0 |
|
527 |
*/ |
|
5 | 528 |
public function initialise_blog_option_info() { |
0 | 529 |
$this->blog_options = array( |
16 | 530 |
// Read-only options. |
9 | 531 |
'software_name' => array( |
532 |
'desc' => __( 'Software Name' ), |
|
533 |
'readonly' => true, |
|
534 |
'value' => 'WordPress', |
|
0 | 535 |
), |
9 | 536 |
'software_version' => array( |
537 |
'desc' => __( 'Software Version' ), |
|
538 |
'readonly' => true, |
|
539 |
'value' => get_bloginfo( 'version' ), |
|
0 | 540 |
), |
9 | 541 |
'blog_url' => array( |
542 |
'desc' => __( 'WordPress Address (URL)' ), |
|
543 |
'readonly' => true, |
|
544 |
'option' => 'siteurl', |
|
0 | 545 |
), |
9 | 546 |
'home_url' => array( |
547 |
'desc' => __( 'Site Address (URL)' ), |
|
548 |
'readonly' => true, |
|
549 |
'option' => 'home', |
|
0 | 550 |
), |
9 | 551 |
'login_url' => array( |
552 |
'desc' => __( 'Login Address (URL)' ), |
|
553 |
'readonly' => true, |
|
554 |
'value' => wp_login_url(), |
|
0 | 555 |
), |
9 | 556 |
'admin_url' => array( |
557 |
'desc' => __( 'The URL to the admin area' ), |
|
558 |
'readonly' => true, |
|
559 |
'value' => get_admin_url(), |
|
0 | 560 |
), |
561 |
'image_default_link_type' => array( |
|
9 | 562 |
'desc' => __( 'Image default link type' ), |
563 |
'readonly' => true, |
|
564 |
'option' => 'image_default_link_type', |
|
0 | 565 |
), |
9 | 566 |
'image_default_size' => array( |
567 |
'desc' => __( 'Image default size' ), |
|
568 |
'readonly' => true, |
|
569 |
'option' => 'image_default_size', |
|
0 | 570 |
), |
9 | 571 |
'image_default_align' => array( |
572 |
'desc' => __( 'Image default align' ), |
|
573 |
'readonly' => true, |
|
574 |
'option' => 'image_default_align', |
|
0 | 575 |
), |
9 | 576 |
'template' => array( |
577 |
'desc' => __( 'Template' ), |
|
578 |
'readonly' => true, |
|
579 |
'option' => 'template', |
|
0 | 580 |
), |
9 | 581 |
'stylesheet' => array( |
582 |
'desc' => __( 'Stylesheet' ), |
|
583 |
'readonly' => true, |
|
584 |
'option' => 'stylesheet', |
|
0 | 585 |
), |
9 | 586 |
'post_thumbnail' => array( |
587 |
'desc' => __( 'Post Thumbnail' ), |
|
588 |
'readonly' => true, |
|
589 |
'value' => current_theme_supports( 'post-thumbnails' ), |
|
0 | 590 |
), |
591 |
||
16 | 592 |
// Updatable options. |
9 | 593 |
'time_zone' => array( |
594 |
'desc' => __( 'Time Zone' ), |
|
595 |
'readonly' => false, |
|
596 |
'option' => 'gmt_offset', |
|
0 | 597 |
), |
9 | 598 |
'blog_title' => array( |
599 |
'desc' => __( 'Site Title' ), |
|
600 |
'readonly' => false, |
|
601 |
'option' => 'blogname', |
|
0 | 602 |
), |
9 | 603 |
'blog_tagline' => array( |
604 |
'desc' => __( 'Site Tagline' ), |
|
605 |
'readonly' => false, |
|
606 |
'option' => 'blogdescription', |
|
0 | 607 |
), |
9 | 608 |
'date_format' => array( |
609 |
'desc' => __( 'Date Format' ), |
|
610 |
'readonly' => false, |
|
611 |
'option' => 'date_format', |
|
0 | 612 |
), |
9 | 613 |
'time_format' => array( |
614 |
'desc' => __( 'Time Format' ), |
|
615 |
'readonly' => false, |
|
616 |
'option' => 'time_format', |
|
0 | 617 |
), |
9 | 618 |
'users_can_register' => array( |
619 |
'desc' => __( 'Allow new users to sign up' ), |
|
620 |
'readonly' => false, |
|
621 |
'option' => 'users_can_register', |
|
0 | 622 |
), |
9 | 623 |
'thumbnail_size_w' => array( |
624 |
'desc' => __( 'Thumbnail Width' ), |
|
625 |
'readonly' => false, |
|
626 |
'option' => 'thumbnail_size_w', |
|
0 | 627 |
), |
9 | 628 |
'thumbnail_size_h' => array( |
629 |
'desc' => __( 'Thumbnail Height' ), |
|
630 |
'readonly' => false, |
|
631 |
'option' => 'thumbnail_size_h', |
|
0 | 632 |
), |
9 | 633 |
'thumbnail_crop' => array( |
634 |
'desc' => __( 'Crop thumbnail to exact dimensions' ), |
|
635 |
'readonly' => false, |
|
636 |
'option' => 'thumbnail_crop', |
|
0 | 637 |
), |
9 | 638 |
'medium_size_w' => array( |
639 |
'desc' => __( 'Medium size image width' ), |
|
640 |
'readonly' => false, |
|
641 |
'option' => 'medium_size_w', |
|
0 | 642 |
), |
9 | 643 |
'medium_size_h' => array( |
644 |
'desc' => __( 'Medium size image height' ), |
|
645 |
'readonly' => false, |
|
646 |
'option' => 'medium_size_h', |
|
0 | 647 |
), |
9 | 648 |
'medium_large_size_w' => array( |
649 |
'desc' => __( 'Medium-Large size image width' ), |
|
650 |
'readonly' => false, |
|
651 |
'option' => 'medium_large_size_w', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
), |
9 | 653 |
'medium_large_size_h' => array( |
654 |
'desc' => __( 'Medium-Large size image height' ), |
|
655 |
'readonly' => false, |
|
656 |
'option' => 'medium_large_size_h', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
), |
9 | 658 |
'large_size_w' => array( |
659 |
'desc' => __( 'Large size image width' ), |
|
660 |
'readonly' => false, |
|
661 |
'option' => 'large_size_w', |
|
0 | 662 |
), |
9 | 663 |
'large_size_h' => array( |
664 |
'desc' => __( 'Large size image height' ), |
|
665 |
'readonly' => false, |
|
666 |
'option' => 'large_size_h', |
|
0 | 667 |
), |
9 | 668 |
'default_comment_status' => array( |
16 | 669 |
'desc' => __( 'Allow people to submit comments on new posts.' ), |
9 | 670 |
'readonly' => false, |
671 |
'option' => 'default_comment_status', |
|
0 | 672 |
), |
9 | 673 |
'default_ping_status' => array( |
16 | 674 |
'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new posts.' ), |
9 | 675 |
'readonly' => false, |
676 |
'option' => 'default_ping_status', |
|
677 |
), |
|
0 | 678 |
); |
679 |
||
5 | 680 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
* Filters the XML-RPC blog options property. |
5 | 682 |
* |
683 |
* @since 2.6.0 |
|
684 |
* |
|
685 |
* @param array $blog_options An array of XML-RPC blog options. |
|
686 |
*/ |
|
0 | 687 |
$this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options ); |
688 |
} |
|
689 |
||
690 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
691 |
* Retrieves the blogs of the user. |
0 | 692 |
* |
693 |
* @since 2.6.0 |
|
694 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
698 |
* @type string $0 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
699 |
* @type string $1 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* } |
5 | 701 |
* @return array|IXR_Error Array contains: |
0 | 702 |
* - 'isAdmin' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* - 'isPrimary' - whether the blog is the user's primary blog |
0 | 704 |
* - 'url' |
705 |
* - 'blogid' |
|
706 |
* - 'blogName' |
|
707 |
* - 'xmlrpc' - url of xmlrpc endpoint |
|
708 |
*/ |
|
5 | 709 |
public function wp_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
if ( ! $this->minimum_args( $args, 2 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
|
16 | 714 |
// If this isn't on WPMU then just use blogger_getUsersBlogs(). |
9 | 715 |
if ( ! is_multisite() ) { |
0 | 716 |
array_unshift( $args, 1 ); |
717 |
return $this->blogger_getUsersBlogs( $args ); |
|
718 |
} |
|
719 |
||
720 |
$this->escape( $args ); |
|
721 |
||
722 |
$username = $args[0]; |
|
723 |
$password = $args[1]; |
|
724 |
||
16 | 725 |
$user = $this->login( $username, $password ); |
726 |
if ( ! $user ) { |
|
0 | 727 |
return $this->error; |
9 | 728 |
} |
0 | 729 |
|
5 | 730 |
/** |
731 |
* Fires after the XML-RPC user has been authenticated but before the rest of |
|
732 |
* the method logic begins. |
|
733 |
* |
|
734 |
* All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
|
735 |
* equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
|
736 |
* |
|
737 |
* @since 2.5.0 |
|
18 | 738 |
* @since 5.7.0 Added the `$args` and `$server` parameters. |
5 | 739 |
* |
18 | 740 |
* @param string $name The method name. |
741 |
* @param array|string $args The escaped arguments passed to the method. |
|
742 |
* @param wp_xmlrpc_server $server The XML-RPC server instance. |
|
5 | 743 |
*/ |
18 | 744 |
do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this ); |
0 | 745 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
746 |
$blogs = (array) get_blogs_of_user( $user->ID ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
747 |
$struct = array(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
748 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
$primary_blog_id = 0; |
9 | 750 |
$active_blog = get_active_blog_for_user( $user->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
if ( $active_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
$primary_blog_id = (int) $active_blog->blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
} |
0 | 754 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
755 |
$current_network_id = get_current_network_id(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
756 |
|
0 | 757 |
foreach ( $blogs as $blog ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
// Don't include blogs that aren't hosted at this site. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
759 |
if ( $blog->site_id !== $current_network_id ) { |
0 | 760 |
continue; |
9 | 761 |
} |
0 | 762 |
|
763 |
$blog_id = $blog->userblog_id; |
|
764 |
||
765 |
switch_to_blog( $blog_id ); |
|
766 |
||
9 | 767 |
$is_admin = current_user_can( 'manage_options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
$is_primary = ( (int) $blog_id === $primary_blog_id ); |
0 | 769 |
|
770 |
$struct[] = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
'isAdmin' => $is_admin, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
'isPrimary' => $is_primary, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
'blogid' => (string) $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
'blogName' => get_option( 'blogname' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
0 | 777 |
); |
778 |
||
779 |
restore_current_blog(); |
|
780 |
} |
|
781 |
||
782 |
return $struct; |
|
783 |
} |
|
784 |
||
785 |
/** |
|
786 |
* Checks if the method received at least the minimum number of arguments. |
|
787 |
* |
|
788 |
* @since 3.4.0 |
|
789 |
* |
|
16 | 790 |
* @param array $args An array of arguments to check. |
791 |
* @param int $count Minimum number of arguments. |
|
792 |
* @return bool True if `$args` contains at least `$count` arguments, false otherwise. |
|
0 | 793 |
*/ |
794 |
protected function minimum_args( $args, $count ) { |
|
16 | 795 |
if ( ! is_array( $args ) || count( $args ) < $count ) { |
0 | 796 |
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) ); |
797 |
return false; |
|
798 |
} |
|
799 |
||
800 |
return true; |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Prepares taxonomy data for return in an XML-RPC object. |
|
805 |
* |
|
18 | 806 |
* @param WP_Taxonomy $taxonomy The unprepared taxonomy data. |
807 |
* @param array $fields The subset of taxonomy fields to return. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
* @return array The prepared taxonomy data. |
0 | 809 |
*/ |
810 |
protected function _prepare_taxonomy( $taxonomy, $fields ) { |
|
811 |
$_taxonomy = array( |
|
9 | 812 |
'name' => $taxonomy->name, |
813 |
'label' => $taxonomy->label, |
|
0 | 814 |
'hierarchical' => (bool) $taxonomy->hierarchical, |
9 | 815 |
'public' => (bool) $taxonomy->public, |
816 |
'show_ui' => (bool) $taxonomy->show_ui, |
|
817 |
'_builtin' => (bool) $taxonomy->_builtin, |
|
0 | 818 |
); |
819 |
||
16 | 820 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 821 |
$_taxonomy['labels'] = (array) $taxonomy->labels; |
9 | 822 |
} |
823 |
||
16 | 824 |
if ( in_array( 'cap', $fields, true ) ) { |
0 | 825 |
$_taxonomy['cap'] = (array) $taxonomy->cap; |
9 | 826 |
} |
827 |
||
16 | 828 |
if ( in_array( 'menu', $fields, true ) ) { |
18 | 829 |
$_taxonomy['show_in_menu'] = (bool) $taxonomy->show_in_menu; |
9 | 830 |
} |
831 |
||
16 | 832 |
if ( in_array( 'object_type', $fields, true ) ) { |
0 | 833 |
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
9 | 834 |
} |
0 | 835 |
|
5 | 836 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* Filters XML-RPC-prepared data for the given taxonomy. |
5 | 838 |
* |
839 |
* @since 3.4.0 |
|
840 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
* @param array $_taxonomy An array of taxonomy data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
* @param WP_Taxonomy $taxonomy Taxonomy object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
* @param array $fields The subset of taxonomy fields to return. |
5 | 844 |
*/ |
0 | 845 |
return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
846 |
} |
|
847 |
||
848 |
/** |
|
849 |
* Prepares term data for return in an XML-RPC object. |
|
850 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
* @param array|object $term The unprepared term data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
* @return array The prepared term data. |
0 | 853 |
*/ |
854 |
protected function _prepare_term( $term ) { |
|
855 |
$_term = $term; |
|
9 | 856 |
if ( ! is_array( $_term ) ) { |
0 | 857 |
$_term = get_object_vars( $_term ); |
9 | 858 |
} |
0 | 859 |
|
860 |
// For integers which may be larger than XML-RPC supports ensure we return strings. |
|
18 | 861 |
$_term['term_id'] = (string) $_term['term_id']; |
862 |
$_term['term_group'] = (string) $_term['term_group']; |
|
863 |
$_term['term_taxonomy_id'] = (string) $_term['term_taxonomy_id']; |
|
864 |
$_term['parent'] = (string) $_term['parent']; |
|
0 | 865 |
|
866 |
// Count we are happy to return as an integer because people really shouldn't use terms that much. |
|
18 | 867 |
$_term['count'] = (int) $_term['count']; |
0 | 868 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
// Get term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
$_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
|
871 |
|
5 | 872 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
* Filters XML-RPC-prepared data for the given term. |
5 | 874 |
* |
875 |
* @since 3.4.0 |
|
876 |
* |
|
877 |
* @param array $_term An array of term data. |
|
878 |
* @param array|object $term Term object or array. |
|
879 |
*/ |
|
0 | 880 |
return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
881 |
} |
|
882 |
||
883 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
884 |
* Converts a WordPress date string to an IXR_Date object. |
0 | 885 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* @param string $date Date string to convert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* @return IXR_Date IXR_Date object. |
0 | 888 |
*/ |
889 |
protected function _convert_date( $date ) { |
|
16 | 890 |
if ( '0000-00-00 00:00:00' === $date ) { |
0 | 891 |
return new IXR_Date( '00000000T00:00:00Z' ); |
892 |
} |
|
893 |
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) ); |
|
894 |
} |
|
895 |
||
896 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
897 |
* Converts a WordPress GMT date string to an IXR_Date object. |
0 | 898 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* @param string $date_gmt WordPress GMT date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* @param string $date Date string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
* @return IXR_Date IXR_Date object. |
0 | 902 |
*/ |
903 |
protected function _convert_date_gmt( $date_gmt, $date ) { |
|
16 | 904 |
if ( '0000-00-00 00:00:00' !== $date && '0000-00-00 00:00:00' === $date_gmt ) { |
0 | 905 |
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) ); |
906 |
} |
|
907 |
return $this->_convert_date( $date_gmt ); |
|
908 |
} |
|
909 |
||
910 |
/** |
|
911 |
* Prepares post data for return in an XML-RPC object. |
|
912 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
* @param array $post The unprepared post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
* @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
|
915 |
* @return array The prepared post data. |
0 | 916 |
*/ |
917 |
protected function _prepare_post( $post, $fields ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
// Holds the data for this post. built up based on $fields. |
18 | 919 |
$_post = array( 'post_id' => (string) $post['ID'] ); |
0 | 920 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
// Prepare common post fields. |
0 | 922 |
$post_fields = array( |
923 |
'post_title' => $post['post_title'], |
|
924 |
'post_date' => $this->_convert_date( $post['post_date'] ), |
|
925 |
'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
|
926 |
'post_modified' => $this->_convert_date( $post['post_modified'] ), |
|
927 |
'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ), |
|
928 |
'post_status' => $post['post_status'], |
|
929 |
'post_type' => $post['post_type'], |
|
930 |
'post_name' => $post['post_name'], |
|
931 |
'post_author' => $post['post_author'], |
|
932 |
'post_password' => $post['post_password'], |
|
933 |
'post_excerpt' => $post['post_excerpt'], |
|
934 |
'post_content' => $post['post_content'], |
|
18 | 935 |
'post_parent' => (string) $post['post_parent'], |
0 | 936 |
'post_mime_type' => $post['post_mime_type'], |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
'link' => get_permalink( $post['ID'] ), |
0 | 938 |
'guid' => $post['guid'], |
18 | 939 |
'menu_order' => (int) $post['menu_order'], |
0 | 940 |
'comment_status' => $post['comment_status'], |
941 |
'ping_status' => $post['ping_status'], |
|
16 | 942 |
'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ), |
0 | 943 |
); |
944 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
// Thumbnail. |
0 | 946 |
$post_fields['post_thumbnail'] = array(); |
9 | 947 |
$thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
0 | 948 |
if ( $thumbnail_id ) { |
9 | 949 |
$thumbnail_size = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail'; |
0 | 950 |
$post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
951 |
} |
|
952 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
// Consider future posts as published. |
16 | 954 |
if ( 'future' === $post_fields['post_status'] ) { |
0 | 955 |
$post_fields['post_status'] = 'publish'; |
9 | 956 |
} |
0 | 957 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
// Fill in blank post format. |
0 | 959 |
$post_fields['post_format'] = get_post_format( $post['ID'] ); |
9 | 960 |
if ( empty( $post_fields['post_format'] ) ) { |
0 | 961 |
$post_fields['post_format'] = 'standard'; |
9 | 962 |
} |
0 | 963 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
// Merge requested $post_fields fields into $_post. |
16 | 965 |
if ( in_array( 'post', $fields, true ) ) { |
0 | 966 |
$_post = array_merge( $_post, $post_fields ); |
967 |
} else { |
|
968 |
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
|
9 | 969 |
$_post = array_merge( $_post, $requested_fields ); |
0 | 970 |
} |
971 |
||
16 | 972 |
$all_taxonomy_fields = in_array( 'taxonomies', $fields, true ); |
973 |
||
974 |
if ( $all_taxonomy_fields || in_array( 'terms', $fields, true ) ) { |
|
0 | 975 |
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' ); |
9 | 976 |
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies ); |
977 |
$_post['terms'] = array(); |
|
0 | 978 |
foreach ( $terms as $term ) { |
979 |
$_post['terms'][] = $this->_prepare_term( $term ); |
|
980 |
} |
|
981 |
} |
|
982 |
||
16 | 983 |
if ( in_array( 'custom_fields', $fields, true ) ) { |
0 | 984 |
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] ); |
9 | 985 |
} |
0 | 986 |
|
16 | 987 |
if ( in_array( 'enclosure', $fields, true ) ) { |
0 | 988 |
$_post['enclosure'] = array(); |
9 | 989 |
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' ); |
0 | 990 |
if ( ! empty( $enclosures ) ) { |
9 | 991 |
$encdata = explode( "\n", $enclosures[0] ); |
992 |
$_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
0 | 993 |
$_post['enclosure']['length'] = (int) trim( $encdata[1] ); |
9 | 994 |
$_post['enclosure']['type'] = trim( $encdata[2] ); |
0 | 995 |
} |
996 |
} |
|
997 |
||
5 | 998 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* Filters XML-RPC-prepared date for the given post. |
5 | 1000 |
* |
1001 |
* @since 3.4.0 |
|
1002 |
* |
|
1003 |
* @param array $_post An array of modified post data. |
|
1004 |
* @param array $post An array of post data. |
|
1005 |
* @param array $fields An array of post fields. |
|
1006 |
*/ |
|
0 | 1007 |
return apply_filters( 'xmlrpc_prepare_post', $_post, $post, $fields ); |
1008 |
} |
|
1009 |
||
1010 |
/** |
|
1011 |
* Prepares post data for return in an XML-RPC object. |
|
1012 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
* @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
|
1015 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
* @param WP_Post_Type $post_type Post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
* @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
|
1018 |
* @return array The prepared post type data. |
0 | 1019 |
*/ |
1020 |
protected function _prepare_post_type( $post_type, $fields ) { |
|
1021 |
$_post_type = array( |
|
9 | 1022 |
'name' => $post_type->name, |
1023 |
'label' => $post_type->label, |
|
0 | 1024 |
'hierarchical' => (bool) $post_type->hierarchical, |
9 | 1025 |
'public' => (bool) $post_type->public, |
1026 |
'show_ui' => (bool) $post_type->show_ui, |
|
1027 |
'_builtin' => (bool) $post_type->_builtin, |
|
1028 |
'has_archive' => (bool) $post_type->has_archive, |
|
1029 |
'supports' => get_all_post_type_supports( $post_type->name ), |
|
0 | 1030 |
); |
1031 |
||
16 | 1032 |
if ( in_array( 'labels', $fields, true ) ) { |
0 | 1033 |
$_post_type['labels'] = (array) $post_type->labels; |
1034 |
} |
|
1035 |
||
16 | 1036 |
if ( in_array( 'cap', $fields, true ) ) { |
9 | 1037 |
$_post_type['cap'] = (array) $post_type->cap; |
0 | 1038 |
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; |
1039 |
} |
|
1040 |
||
16 | 1041 |
if ( in_array( 'menu', $fields, true ) ) { |
0 | 1042 |
$_post_type['menu_position'] = (int) $post_type->menu_position; |
9 | 1043 |
$_post_type['menu_icon'] = $post_type->menu_icon; |
1044 |
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; |
|
1045 |
} |
|
1046 |
||
16 | 1047 |
if ( in_array( 'taxonomies', $fields, true ) ) { |
0 | 1048 |
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
9 | 1049 |
} |
0 | 1050 |
|
5 | 1051 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* Filters XML-RPC-prepared date for the given post type. |
5 | 1053 |
* |
1054 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
* @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
5 | 1056 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
* @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
|
1058 |
* @param WP_Post_Type $post_type Post type object. |
5 | 1059 |
*/ |
0 | 1060 |
return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
1061 |
} |
|
1062 |
||
1063 |
/** |
|
1064 |
* Prepares media item data for return in an XML-RPC object. |
|
1065 |
* |
|
18 | 1066 |
* @param WP_Post $media_item The unprepared media item data. |
1067 |
* @param string $thumbnail_size The image size to use for the thumbnail URL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @return array The prepared media item data. |
0 | 1069 |
*/ |
1070 |
protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
|
1071 |
$_media_item = array( |
|
18 | 1072 |
'attachment_id' => (string) $media_item->ID, |
0 | 1073 |
'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
1074 |
'parent' => $media_item->post_parent, |
|
1075 |
'link' => wp_get_attachment_url( $media_item->ID ), |
|
1076 |
'title' => $media_item->post_title, |
|
1077 |
'caption' => $media_item->post_excerpt, |
|
1078 |
'description' => $media_item->post_content, |
|
1079 |
'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
9 | 1080 |
'type' => $media_item->post_mime_type, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1081 |
'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ), |
0 | 1082 |
); |
1083 |
||
1084 |
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
|
9 | 1085 |
if ( $thumbnail_src ) { |
0 | 1086 |
$_media_item['thumbnail'] = $thumbnail_src[0]; |
9 | 1087 |
} else { |
0 | 1088 |
$_media_item['thumbnail'] = $_media_item['link']; |
9 | 1089 |
} |
0 | 1090 |
|
5 | 1091 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
* Filters XML-RPC-prepared data for the given media item. |
5 | 1093 |
* |
1094 |
* @since 3.4.0 |
|
1095 |
* |
|
18 | 1096 |
* @param array $_media_item An array of media item data. |
1097 |
* @param WP_Post $media_item Media item object. |
|
1098 |
* @param string $thumbnail_size Image size. |
|
5 | 1099 |
*/ |
0 | 1100 |
return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1101 |
} |
|
1102 |
||
1103 |
/** |
|
1104 |
* Prepares page data for return in an XML-RPC object. |
|
1105 |
* |
|
18 | 1106 |
* @param WP_Post $page The unprepared page data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
* @return array The prepared page data. |
0 | 1108 |
*/ |
1109 |
protected function _prepare_page( $page ) { |
|
1110 |
// Get all of the page content and link. |
|
1111 |
$full_page = get_extended( $page->post_content ); |
|
9 | 1112 |
$link = get_permalink( $page->ID ); |
0 | 1113 |
|
1114 |
// Get info the page parent if there is one. |
|
9 | 1115 |
$parent_title = ''; |
0 | 1116 |
if ( ! empty( $page->post_parent ) ) { |
9 | 1117 |
$parent = get_post( $page->post_parent ); |
0 | 1118 |
$parent_title = $parent->post_title; |
1119 |
} |
|
1120 |
||
1121 |
// Determine comment and ping settings. |
|
1122 |
$allow_comments = comments_open( $page->ID ) ? 1 : 0; |
|
9 | 1123 |
$allow_pings = pings_open( $page->ID ) ? 1 : 0; |
0 | 1124 |
|
1125 |
// Format page date. |
|
9 | 1126 |
$page_date = $this->_convert_date( $page->post_date ); |
0 | 1127 |
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date ); |
1128 |
||
1129 |
// Pull the categories info together. |
|
1130 |
$categories = array(); |
|
5 | 1131 |
if ( is_object_in_taxonomy( 'page', 'category' ) ) { |
1132 |
foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) { |
|
1133 |
$categories[] = get_cat_name( $cat_id ); |
|
1134 |
} |
|
0 | 1135 |
} |
1136 |
||
1137 |
// Get the author info. |
|
1138 |
$author = get_userdata( $page->post_author ); |
|
1139 |
||
1140 |
$page_template = get_page_template_slug( $page->ID ); |
|
9 | 1141 |
if ( empty( $page_template ) ) { |
0 | 1142 |
$page_template = 'default'; |
9 | 1143 |
} |
0 | 1144 |
|
1145 |
$_page = array( |
|
1146 |
'dateCreated' => $page_date, |
|
1147 |
'userid' => $page->post_author, |
|
1148 |
'page_id' => $page->ID, |
|
1149 |
'page_status' => $page->post_status, |
|
1150 |
'description' => $full_page['main'], |
|
1151 |
'title' => $page->post_title, |
|
1152 |
'link' => $link, |
|
1153 |
'permaLink' => $link, |
|
1154 |
'categories' => $categories, |
|
1155 |
'excerpt' => $page->post_excerpt, |
|
1156 |
'text_more' => $full_page['extended'], |
|
1157 |
'mt_allow_comments' => $allow_comments, |
|
1158 |
'mt_allow_pings' => $allow_pings, |
|
1159 |
'wp_slug' => $page->post_name, |
|
1160 |
'wp_password' => $page->post_password, |
|
1161 |
'wp_author' => $author->display_name, |
|
1162 |
'wp_page_parent_id' => $page->post_parent, |
|
1163 |
'wp_page_parent_title' => $parent_title, |
|
1164 |
'wp_page_order' => $page->menu_order, |
|
1165 |
'wp_author_id' => (string) $author->ID, |
|
1166 |
'wp_author_display_name' => $author->display_name, |
|
1167 |
'date_created_gmt' => $page_date_gmt, |
|
1168 |
'custom_fields' => $this->get_custom_fields( $page->ID ), |
|
9 | 1169 |
'wp_page_template' => $page_template, |
0 | 1170 |
); |
1171 |
||
5 | 1172 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* Filters XML-RPC-prepared data for the given page. |
5 | 1174 |
* |
1175 |
* @since 3.4.0 |
|
1176 |
* |
|
1177 |
* @param array $_page An array of page data. |
|
1178 |
* @param WP_Post $page Page object. |
|
1179 |
*/ |
|
0 | 1180 |
return apply_filters( 'xmlrpc_prepare_page', $_page, $page ); |
1181 |
} |
|
1182 |
||
1183 |
/** |
|
1184 |
* Prepares comment data for return in an XML-RPC object. |
|
1185 |
* |
|
18 | 1186 |
* @param WP_Comment $comment The unprepared comment data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
* @return array The prepared comment data. |
0 | 1188 |
*/ |
1189 |
protected function _prepare_comment( $comment ) { |
|
1190 |
// Format page date. |
|
1191 |
$comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
|
1192 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1193 |
if ( '0' === $comment->comment_approved ) { |
0 | 1194 |
$comment_status = 'hold'; |
16 | 1195 |
} elseif ( 'spam' === $comment->comment_approved ) { |
0 | 1196 |
$comment_status = 'spam'; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1197 |
} elseif ( '1' === $comment->comment_approved ) { |
0 | 1198 |
$comment_status = 'approve'; |
5 | 1199 |
} else { |
0 | 1200 |
$comment_status = $comment->comment_approved; |
5 | 1201 |
} |
0 | 1202 |
$_comment = array( |
1203 |
'date_created_gmt' => $comment_date_gmt, |
|
1204 |
'user_id' => $comment->user_id, |
|
1205 |
'comment_id' => $comment->comment_ID, |
|
1206 |
'parent' => $comment->comment_parent, |
|
1207 |
'status' => $comment_status, |
|
1208 |
'content' => $comment->comment_content, |
|
9 | 1209 |
'link' => get_comment_link( $comment ), |
0 | 1210 |
'post_id' => $comment->comment_post_ID, |
9 | 1211 |
'post_title' => get_the_title( $comment->comment_post_ID ), |
0 | 1212 |
'author' => $comment->comment_author, |
1213 |
'author_url' => $comment->comment_author_url, |
|
1214 |
'author_email' => $comment->comment_author_email, |
|
1215 |
'author_ip' => $comment->comment_author_IP, |
|
1216 |
'type' => $comment->comment_type, |
|
1217 |
); |
|
1218 |
||
5 | 1219 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
* Filters XML-RPC-prepared data for the given comment. |
5 | 1221 |
* |
1222 |
* @since 3.4.0 |
|
1223 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* @param array $_comment An array of prepared comment data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* @param WP_Comment $comment Comment object. |
5 | 1226 |
*/ |
0 | 1227 |
return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1228 |
} |
|
1229 |
||
1230 |
/** |
|
1231 |
* Prepares user data for return in an XML-RPC object. |
|
1232 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
* @param WP_User $user The unprepared user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* @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
|
1235 |
* @return array The prepared user data. |
0 | 1236 |
*/ |
1237 |
protected function _prepare_user( $user, $fields ) { |
|
18 | 1238 |
$_user = array( 'user_id' => (string) $user->ID ); |
0 | 1239 |
|
1240 |
$user_fields = array( |
|
9 | 1241 |
'username' => $user->user_login, |
1242 |
'first_name' => $user->user_firstname, |
|
1243 |
'last_name' => $user->user_lastname, |
|
1244 |
'registered' => $this->_convert_date( $user->user_registered ), |
|
1245 |
'bio' => $user->user_description, |
|
1246 |
'email' => $user->user_email, |
|
1247 |
'nickname' => $user->nickname, |
|
1248 |
'nicename' => $user->user_nicename, |
|
1249 |
'url' => $user->user_url, |
|
1250 |
'display_name' => $user->display_name, |
|
1251 |
'roles' => $user->roles, |
|
0 | 1252 |
); |
1253 |
||
16 | 1254 |
if ( in_array( 'all', $fields, true ) ) { |
0 | 1255 |
$_user = array_merge( $_user, $user_fields ); |
1256 |
} else { |
|
16 | 1257 |
if ( in_array( 'basic', $fields, true ) ) { |
0 | 1258 |
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); |
9 | 1259 |
$fields = array_merge( $fields, $basic_fields ); |
0 | 1260 |
} |
1261 |
$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); |
|
9 | 1262 |
$_user = array_merge( $_user, $requested_fields ); |
0 | 1263 |
} |
1264 |
||
5 | 1265 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
* Filters XML-RPC-prepared data for the given user. |
5 | 1267 |
* |
1268 |
* @since 3.5.0 |
|
1269 |
* |
|
1270 |
* @param array $_user An array of user data. |
|
1271 |
* @param WP_User $user User object. |
|
1272 |
* @param array $fields An array of user fields. |
|
1273 |
*/ |
|
0 | 1274 |
return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); |
1275 |
} |
|
1276 |
||
1277 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1278 |
* Creates a new post for any registered post type. |
0 | 1279 |
* |
1280 |
* @since 3.4.0 |
|
1281 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* @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
|
1283 |
* |
16 | 1284 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* 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
|
1286 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1288 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1290 |
* @type array $3 { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
* 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
|
1292 |
* additional post fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
* @type string $post_type Post type. Default 'post'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
* @type string $post_status Post status. Default 'draft' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
* @type string $post_title Post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
* @type int $post_author Post author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
* @type string $post_excerpt Post excerpt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
* @type string $post_content Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
* @type string $post_date_gmt Post date in GMT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
* @type string $post_date Post date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
* @type string $post_password Post password (20-character limit). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
* @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
|
1304 |
* @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
|
1305 |
* @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
|
1306 |
* `$post_status` is 'private'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
* @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
|
1308 |
* @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
|
1309 |
* @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
|
1310 |
* of term IDs as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* @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
|
1312 |
* of term names as values. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
* @type array $enclosure { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
* 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
|
1315 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* @type string $url URL for the feed enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* @type int $length Size in bytes of the enclosure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* @type string $type Mime-type for the enclosure. |
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 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
* @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
0 | 1323 |
*/ |
5 | 1324 |
public function wp_newPost( $args ) { |
9 | 1325 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1326 |
return $this->error; |
9 | 1327 |
} |
0 | 1328 |
|
1329 |
$this->escape( $args ); |
|
1330 |
||
1331 |
$username = $args[1]; |
|
1332 |
$password = $args[2]; |
|
1333 |
$content_struct = $args[3]; |
|
1334 |
||
16 | 1335 |
$user = $this->login( $username, $password ); |
1336 |
if ( ! $user ) { |
|
0 | 1337 |
return $this->error; |
9 | 1338 |
} |
0 | 1339 |
|
16 | 1340 |
// Convert the date field back to IXR form. |
5 | 1341 |
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
1342 |
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1343 |
} |
|
1344 |
||
16 | 1345 |
/* |
1346 |
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1347 |
* since _insert_post() will ignore the non-GMT date if the GMT date is set. |
|
1348 |
*/ |
|
5 | 1349 |
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
16 | 1350 |
if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
5 | 1351 |
unset( $content_struct['post_date_gmt'] ); |
1352 |
} else { |
|
1353 |
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1354 |
} |
|
1355 |
} |
|
1356 |
||
1357 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 1358 |
do_action( 'xmlrpc_call', 'wp.newPost', $args, $this ); |
0 | 1359 |
|
1360 |
unset( $content_struct['ID'] ); |
|
1361 |
||
1362 |
return $this->_insert_post( $user, $content_struct ); |
|
1363 |
} |
|
1364 |
||
1365 |
/** |
|
1366 |
* Helper method for filtering out elements from an array. |
|
1367 |
* |
|
1368 |
* @since 3.4.0 |
|
1369 |
* |
|
1370 |
* @param int $count Number to compare to one. |
|
18 | 1371 |
* @return bool True if the number is greater than one, false otherwise. |
0 | 1372 |
*/ |
1373 |
private function _is_greater_than_one( $count ) { |
|
1374 |
return $count > 1; |
|
1375 |
} |
|
1376 |
||
1377 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1378 |
* Encapsulates the logic for sticking a post and determining if |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1379 |
* the user has permission to do so. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* @param array $post_data |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
* @param bool $update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
* @return void|IXR_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
private function _toggle_sticky( $post_data, $update = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
$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
|
1389 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
// Private and password-protected posts cannot be stickied. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
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
|
1392 |
// 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
|
1393 |
if ( ! empty( $post_data['sticky'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
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
|
1395 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
if ( $update ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
} |
9 | 1400 |
} elseif ( isset( $post_data['sticky'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
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
|
1402 |
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
|
1403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
$sticky = wp_validate_boolean( $post_data['sticky'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
if ( $sticky ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
stick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
unstick_post( $post_data['ID'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
* Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
0 | 1416 |
* |
1417 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
* @param WP_User $user The post author if post_author isn't set in $content_struct. |
5 | 1422 |
* @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
|
1423 |
* @return IXR_Error|string |
0 | 1424 |
*/ |
1425 |
protected function _insert_post( $user, $content_struct ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
'post_status' => 'draft', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
'post_type' => 'post', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1429 |
'post_author' => 0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1430 |
'post_password' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1431 |
'post_excerpt' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1432 |
'post_content' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1433 |
'post_title' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1434 |
'post_date' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1435 |
'post_date_gmt' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
'post_format' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
'post_name' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
'post_thumbnail' => null, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1439 |
'post_parent' => 0, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1440 |
'ping_status' => '', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1441 |
'comment_status' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
'custom_fields' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
'terms_names' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
'terms' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
'sticky' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
'enclosure' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
'ID' => null, |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
0 | 1451 |
|
1452 |
$post_type = get_post_type_object( $post_data['post_type'] ); |
|
9 | 1453 |
if ( ! $post_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 1455 |
} |
0 | 1456 |
|
1457 |
$update = ! empty( $post_data['ID'] ); |
|
1458 |
||
1459 |
if ( $update ) { |
|
9 | 1460 |
if ( ! get_post( $post_data['ID'] ) ) { |
0 | 1461 |
return new IXR_Error( 401, __( 'Invalid post ID.' ) ); |
9 | 1462 |
} |
1463 |
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) { |
|
0 | 1464 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1465 |
} |
16 | 1466 |
if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) { |
0 | 1467 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 1468 |
} |
0 | 1469 |
} else { |
9 | 1470 |
if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 1471 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
9 | 1472 |
} |
0 | 1473 |
} |
1474 |
||
1475 |
switch ( $post_data['post_status'] ) { |
|
1476 |
case 'draft': |
|
1477 |
case 'pending': |
|
1478 |
break; |
|
1479 |
case 'private': |
|
9 | 1480 |
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
|
1481 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
9 | 1482 |
} |
0 | 1483 |
break; |
1484 |
case 'publish': |
|
1485 |
case 'future': |
|
9 | 1486 |
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
|
1487 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
9 | 1488 |
} |
0 | 1489 |
break; |
1490 |
default: |
|
9 | 1491 |
if ( ! get_post_status_object( $post_data['post_status'] ) ) { |
0 | 1492 |
$post_data['post_status'] = 'draft'; |
9 | 1493 |
} |
1494 |
break; |
|
1495 |
} |
|
1496 |
||
1497 |
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
|
1498 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
9 | 1499 |
} |
0 | 1500 |
|
1501 |
$post_data['post_author'] = absint( $post_data['post_author'] ); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1502 |
if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] !== $user->ID ) { |
9 | 1503 |
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
|
1504 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 1505 |
} |
0 | 1506 |
|
1507 |
$author = get_userdata( $post_data['post_author'] ); |
|
1508 |
||
9 | 1509 |
if ( ! $author ) { |
0 | 1510 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 1511 |
} |
0 | 1512 |
} else { |
1513 |
$post_data['post_author'] = $user->ID; |
|
1514 |
} |
|
1515 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1516 |
if ( 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { |
0 | 1517 |
unset( $post_data['comment_status'] ); |
9 | 1518 |
} |
1519 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1520 |
if ( 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { |
0 | 1521 |
unset( $post_data['ping_status'] ); |
9 | 1522 |
} |
0 | 1523 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
// Do some timestamp voodoo. |
0 | 1525 |
if ( ! empty( $post_data['post_date_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1527 |
$date_created = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
0 | 1528 |
} elseif ( ! empty( $post_data['post_date'] ) ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1529 |
$date_created = $post_data['post_date']->getIso(); |
0 | 1530 |
} |
1531 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
// 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
|
1533 |
$post_data['edit_date'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1535 |
if ( ! empty( $date_created ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1536 |
$post_data['post_date'] = iso8601_to_datetime( $date_created ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1537 |
$post_data['post_date_gmt'] = iso8601_to_datetime( $date_created, 'gmt' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1539 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1540 |
$post_data['edit_date'] = true; |
0 | 1541 |
} |
1542 |
||
9 | 1543 |
if ( ! isset( $post_data['ID'] ) ) { |
0 | 1544 |
$post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
9 | 1545 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1546 |
$post_id = $post_data['ID']; |
0 | 1547 |
|
16 | 1548 |
if ( 'post' === $post_data['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1549 |
$error = $this->_toggle_sticky( $post_data, $update ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1550 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
return $error; |
0 | 1552 |
} |
1553 |
} |
|
1554 |
||
1555 |
if ( isset( $post_data['post_thumbnail'] ) ) { |
|
16 | 1556 |
// Empty value deletes, non-empty value adds/updates. |
9 | 1557 |
if ( ! $post_data['post_thumbnail'] ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1558 |
delete_post_thumbnail( $post_id ); |
9 | 1559 |
} elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) { |
0 | 1560 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 1561 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1562 |
set_post_thumbnail( $post_id, $post_data['post_thumbnail'] ); |
0 | 1563 |
unset( $content_struct['post_thumbnail'] ); |
1564 |
} |
|
1565 |
||
9 | 1566 |
if ( isset( $post_data['custom_fields'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1567 |
$this->set_custom_fields( $post_id, $post_data['custom_fields'] ); |
9 | 1568 |
} |
0 | 1569 |
|
1570 |
if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
|
1571 |
$post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
|
1572 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
// Accumulate term IDs from terms and terms_names. |
0 | 1574 |
$terms = array(); |
1575 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
// First validate the terms specified by ID. |
0 | 1577 |
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1578 |
$taxonomies = array_keys( $post_data['terms'] ); |
|
1579 |
||
16 | 1580 |
// Validating term IDs. |
0 | 1581 |
foreach ( $taxonomies as $taxonomy ) { |
9 | 1582 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1583 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1584 |
} |
1585 |
||
1586 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1587 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1588 |
} |
1589 |
||
1590 |
$term_ids = $post_data['terms'][ $taxonomy ]; |
|
5 | 1591 |
$terms[ $taxonomy ] = array(); |
0 | 1592 |
foreach ( $term_ids as $term_id ) { |
1593 |
$term = get_term_by( 'id', $term_id, $taxonomy ); |
|
1594 |
||
9 | 1595 |
if ( ! $term ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
9 | 1597 |
} |
1598 |
||
1599 |
$terms[ $taxonomy ][] = (int) $term_id; |
|
0 | 1600 |
} |
1601 |
} |
|
1602 |
} |
|
1603 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1604 |
// Now validate terms specified by name. |
0 | 1605 |
if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1606 |
$taxonomies = array_keys( $post_data['terms_names'] ); |
|
1607 |
||
1608 |
foreach ( $taxonomies as $taxonomy ) { |
|
9 | 1609 |
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) { |
0 | 1610 |
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
9 | 1611 |
} |
1612 |
||
1613 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) { |
|
0 | 1614 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
9 | 1615 |
} |
0 | 1616 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1618 |
* 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
|
1619 |
* in the hierarchy share the same name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
*/ |
0 | 1621 |
$ambiguous_terms = array(); |
1622 |
if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
9 | 1623 |
$tax_term_names = get_terms( |
1624 |
array( |
|
16 | 1625 |
'taxonomy' => $taxonomy, |
9 | 1626 |
'fields' => 'names', |
1627 |
'hide_empty' => false, |
|
1628 |
) |
|
1629 |
); |
|
0 | 1630 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
// Count the number of terms with the same name. |
0 | 1632 |
$tax_term_names_count = array_count_values( $tax_term_names ); |
1633 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
// Filter out non-ambiguous term names. |
9 | 1635 |
$ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) ); |
0 | 1636 |
|
1637 |
$ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
|
1638 |
} |
|
1639 |
||
9 | 1640 |
$term_names = $post_data['terms_names'][ $taxonomy ]; |
0 | 1641 |
foreach ( $term_names as $term_name ) { |
16 | 1642 |
if ( in_array( $term_name, $ambiguous_terms, true ) ) { |
0 | 1643 |
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
9 | 1644 |
} |
0 | 1645 |
|
1646 |
$term = get_term_by( 'name', $term_name, $taxonomy ); |
|
1647 |
||
1648 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1649 |
// Term doesn't exist, so check that the user is allowed to create new terms. |
9 | 1650 |
if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->edit_terms ) ) { |
0 | 1651 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
9 | 1652 |
} |
0 | 1653 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
// Create the new term. |
0 | 1655 |
$term_info = wp_insert_term( $term_name, $taxonomy ); |
9 | 1656 |
if ( is_wp_error( $term_info ) ) { |
0 | 1657 |
return new IXR_Error( 500, $term_info->get_error_message() ); |
9 | 1658 |
} |
1659 |
||
1660 |
$terms[ $taxonomy ][] = (int) $term_info['term_id']; |
|
0 | 1661 |
} else { |
9 | 1662 |
$terms[ $taxonomy ][] = (int) $term->term_id; |
0 | 1663 |
} |
1664 |
} |
|
1665 |
} |
|
1666 |
} |
|
1667 |
||
1668 |
$post_data['tax_input'] = $terms; |
|
1669 |
unset( $post_data['terms'], $post_data['terms_names'] ); |
|
1670 |
} |
|
1671 |
||
1672 |
if ( isset( $post_data['post_format'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1673 |
$format = set_post_format( $post_id, $post_data['post_format'] ); |
0 | 1674 |
|
9 | 1675 |
if ( is_wp_error( $format ) ) { |
0 | 1676 |
return new IXR_Error( 500, $format->get_error_message() ); |
9 | 1677 |
} |
0 | 1678 |
|
1679 |
unset( $post_data['post_format'] ); |
|
1680 |
} |
|
1681 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
// Handle enclosures. |
0 | 1683 |
$enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1684 |
$this->add_enclosure_if_new( $post_id, $enclosure ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1685 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1686 |
$this->attach_uploads( $post_id, $post_data['post_content'] ); |
0 | 1687 |
|
5 | 1688 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1689 |
* Filters post data array to be inserted via XML-RPC. |
5 | 1690 |
* |
1691 |
* @since 3.4.0 |
|
1692 |
* |
|
1693 |
* @param array $post_data Parsed array of post data. |
|
1694 |
* @param array $content_struct Post data array. |
|
1695 |
*/ |
|
0 | 1696 |
$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); |
1697 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1698 |
// Remove all null values to allow for using the insert/update post default values for those keys instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1699 |
$post_data = array_filter( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1700 |
$post_data, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
static function ( $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
return null !== $value; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1704 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1705 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1706 |
$post_id = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1707 |
if ( is_wp_error( $post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1708 |
return new IXR_Error( 500, $post_id->get_error_message() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1709 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1710 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1711 |
if ( ! $post_id ) { |
16 | 1712 |
if ( $update ) { |
1713 |
return new IXR_Error( 401, __( 'Sorry, the post could not be updated.' ) ); |
|
1714 |
} else { |
|
1715 |
return new IXR_Error( 401, __( 'Sorry, the post could not be created.' ) ); |
|
1716 |
} |
|
9 | 1717 |
} |
0 | 1718 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1719 |
return (string) $post_id; |
0 | 1720 |
} |
1721 |
||
1722 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1723 |
* Edits a post for any registered post type. |
0 | 1724 |
* |
1725 |
* The $content_struct parameter only needs to contain fields that |
|
1726 |
* should be changed. All other fields will retain their existing values. |
|
1727 |
* |
|
1728 |
* @since 3.4.0 |
|
1729 |
* |
|
16 | 1730 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1733 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1734 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1735 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1736 |
* @type int $3 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1737 |
* @type array $4 Extra content arguments. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
* @return true|IXR_Error True on success, IXR_Error on failure. |
0 | 1740 |
*/ |
5 | 1741 |
public function wp_editPost( $args ) { |
9 | 1742 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 1743 |
return $this->error; |
9 | 1744 |
} |
0 | 1745 |
|
1746 |
$this->escape( $args ); |
|
1747 |
||
1748 |
$username = $args[1]; |
|
1749 |
$password = $args[2]; |
|
1750 |
$post_id = (int) $args[3]; |
|
1751 |
$content_struct = $args[4]; |
|
1752 |
||
16 | 1753 |
$user = $this->login( $username, $password ); |
1754 |
if ( ! $user ) { |
|
0 | 1755 |
return $this->error; |
9 | 1756 |
} |
0 | 1757 |
|
5 | 1758 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1759 |
do_action( 'xmlrpc_call', 'wp.editPost', $args, $this ); |
0 | 1760 |
|
1761 |
$post = get_post( $post_id, ARRAY_A ); |
|
1762 |
||
9 | 1763 |
if ( empty( $post['ID'] ) ) { |
0 | 1764 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1765 |
} |
0 | 1766 |
|
1767 |
if ( isset( $content_struct['if_not_modified_since'] ) ) { |
|
1768 |
// If the post has been modified since the date provided, return an error. |
|
1769 |
if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { |
|
1770 |
return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); |
|
1771 |
} |
|
1772 |
} |
|
1773 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
// Convert the date field back to IXR form. |
0 | 1775 |
$post['post_date'] = $this->_convert_date( $post['post_date'] ); |
1776 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* 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
|
1779 |
* 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
|
1780 |
*/ |
16 | 1781 |
if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { |
0 | 1782 |
unset( $post['post_date_gmt'] ); |
9 | 1783 |
} else { |
0 | 1784 |
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); |
9 | 1785 |
} |
0 | 1786 |
|
16 | 1787 |
/* |
1788 |
* If the API client did not provide 'post_date', then we must not perpetuate the value that |
|
1789 |
* was stored in the database, or it will appear to be an intentional edit. Conveying it here |
|
1790 |
* as if it was coming from the API client will cause an otherwise zeroed out 'post_date_gmt' |
|
1791 |
* to get set with the value that was originally stored in the database when the draft was created. |
|
1792 |
*/ |
|
1793 |
if ( ! isset( $content_struct['post_date'] ) ) { |
|
1794 |
unset( $post['post_date'] ); |
|
1795 |
} |
|
1796 |
||
0 | 1797 |
$this->escape( $post ); |
1798 |
$merged_content_struct = array_merge( $post, $content_struct ); |
|
1799 |
||
1800 |
$retval = $this->_insert_post( $user, $merged_content_struct ); |
|
9 | 1801 |
if ( $retval instanceof IXR_Error ) { |
0 | 1802 |
return $retval; |
9 | 1803 |
} |
0 | 1804 |
|
1805 |
return true; |
|
1806 |
} |
|
1807 |
||
1808 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1809 |
* Deletes a post for any registered post type. |
0 | 1810 |
* |
1811 |
* @since 3.4.0 |
|
1812 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
* @see wp_delete_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
* |
16 | 1815 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1818 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1819 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1820 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1821 |
* @type int $3 Post ID. |
7
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 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 1824 |
*/ |
5 | 1825 |
public function wp_deletePost( $args ) { |
9 | 1826 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1827 |
return $this->error; |
9 | 1828 |
} |
0 | 1829 |
|
1830 |
$this->escape( $args ); |
|
1831 |
||
9 | 1832 |
$username = $args[1]; |
1833 |
$password = $args[2]; |
|
1834 |
$post_id = (int) $args[3]; |
|
1835 |
||
16 | 1836 |
$user = $this->login( $username, $password ); |
1837 |
if ( ! $user ) { |
|
0 | 1838 |
return $this->error; |
9 | 1839 |
} |
0 | 1840 |
|
5 | 1841 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1842 |
do_action( 'xmlrpc_call', 'wp.deletePost', $args, $this ); |
0 | 1843 |
|
1844 |
$post = get_post( $post_id, ARRAY_A ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1845 |
if ( empty( $post['ID'] ) ) { |
0 | 1846 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1849 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
0 | 1850 |
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
|
1851 |
} |
0 | 1852 |
|
1853 |
$result = wp_delete_post( $post_id ); |
|
1854 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
if ( ! $result ) { |
16 | 1856 |
return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
} |
0 | 1858 |
|
1859 |
return true; |
|
1860 |
} |
|
1861 |
||
1862 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1863 |
* Retrieves a post. |
0 | 1864 |
* |
1865 |
* @since 3.4.0 |
|
1866 |
* |
|
1867 |
* The optional $fields parameter specifies what fields will be included |
|
1868 |
* in the response array. This should be a list of field names. 'post_id' will |
|
1869 |
* always be included in the response regardless of the value of $fields. |
|
1870 |
* |
|
1871 |
* Instead of, or in addition to, individual field names, conceptual group |
|
1872 |
* names can be used to specify multiple fields. The available conceptual |
|
1873 |
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields', |
|
1874 |
* and 'enclosure'. |
|
1875 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
* @see get_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1878 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1881 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1882 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1883 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1884 |
* @type int $3 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1885 |
* @type array $4 Optional. The subset of post type fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
* } |
5 | 1887 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 1888 |
* - 'post_id' |
1889 |
* - 'post_title' |
|
1890 |
* - 'post_date' |
|
1891 |
* - 'post_date_gmt' |
|
1892 |
* - 'post_modified' |
|
1893 |
* - 'post_modified_gmt' |
|
1894 |
* - 'post_status' |
|
1895 |
* - 'post_type' |
|
1896 |
* - 'post_name' |
|
1897 |
* - 'post_author' |
|
1898 |
* - 'post_password' |
|
1899 |
* - 'post_excerpt' |
|
1900 |
* - 'post_content' |
|
1901 |
* - 'link' |
|
1902 |
* - 'comment_status' |
|
1903 |
* - 'ping_status' |
|
1904 |
* - 'sticky' |
|
1905 |
* - 'custom_fields' |
|
1906 |
* - 'terms' |
|
1907 |
* - 'categories' |
|
1908 |
* - 'tags' |
|
1909 |
* - 'enclosure' |
|
1910 |
*/ |
|
5 | 1911 |
public function wp_getPost( $args ) { |
9 | 1912 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 1913 |
return $this->error; |
9 | 1914 |
} |
0 | 1915 |
|
1916 |
$this->escape( $args ); |
|
1917 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
$post_id = (int) $args[3]; |
0 | 1921 |
|
5 | 1922 |
if ( isset( $args[4] ) ) { |
0 | 1923 |
$fields = $args[4]; |
5 | 1924 |
} else { |
1925 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1926 |
* Filters the default post query fields used by the given XML-RPC method. |
5 | 1927 |
* |
1928 |
* @since 3.4.0 |
|
1929 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1930 |
* @param array $fields An array of post fields to retrieve. By default, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1931 |
* contains 'post', 'terms', and 'custom_fields'. |
5 | 1932 |
* @param string $method Method name. |
1933 |
*/ |
|
0 | 1934 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
5 | 1935 |
} |
0 | 1936 |
|
16 | 1937 |
$user = $this->login( $username, $password ); |
1938 |
if ( ! $user ) { |
|
0 | 1939 |
return $this->error; |
9 | 1940 |
} |
0 | 1941 |
|
5 | 1942 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 1943 |
do_action( 'xmlrpc_call', 'wp.getPost', $args, $this ); |
0 | 1944 |
|
1945 |
$post = get_post( $post_id, ARRAY_A ); |
|
1946 |
||
9 | 1947 |
if ( empty( $post['ID'] ) ) { |
0 | 1948 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 1949 |
} |
1950 |
||
1951 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 1953 |
} |
0 | 1954 |
|
1955 |
return $this->_prepare_post( $post, $fields ); |
|
1956 |
} |
|
1957 |
||
1958 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1959 |
* Retrieves posts. |
0 | 1960 |
* |
1961 |
* @since 3.4.0 |
|
1962 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
* @see wp_get_recent_posts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
* @see wp_getPost() for more on `$fields` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
* @see get_posts() for more on `$filter` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1968 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1969 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1970 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1971 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1972 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1973 |
* @type array $3 Optional. Modifies the query used to retrieve posts. Accepts 'post_type', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1974 |
* 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1975 |
* Default empty array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1976 |
* @type array $4 Optional. The subset of post type fields to return in the response array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
* @return array|IXR_Error Array containing a collection of posts. |
0 | 1979 |
*/ |
5 | 1980 |
public function wp_getPosts( $args ) { |
9 | 1981 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 1982 |
return $this->error; |
9 | 1983 |
} |
0 | 1984 |
|
1985 |
$this->escape( $args ); |
|
1986 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1988 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 1990 |
|
5 | 1991 |
if ( isset( $args[4] ) ) { |
0 | 1992 |
$fields = $args[4]; |
5 | 1993 |
} else { |
1994 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 1995 |
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
5 | 1996 |
} |
0 | 1997 |
|
16 | 1998 |
$user = $this->login( $username, $password ); |
1999 |
if ( ! $user ) { |
|
0 | 2000 |
return $this->error; |
9 | 2001 |
} |
0 | 2002 |
|
5 | 2003 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2004 |
do_action( 'xmlrpc_call', 'wp.getPosts', $args, $this ); |
0 | 2005 |
|
2006 |
$query = array(); |
|
2007 |
||
2008 |
if ( isset( $filter['post_type'] ) ) { |
|
2009 |
$post_type = get_post_type_object( $filter['post_type'] ); |
|
9 | 2010 |
if ( ! ( (bool) $post_type ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 2012 |
} |
0 | 2013 |
} else { |
2014 |
$post_type = get_post_type_object( 'post' ); |
|
2015 |
} |
|
2016 |
||
9 | 2017 |
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
|
2018 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 2019 |
} |
0 | 2020 |
|
2021 |
$query['post_type'] = $post_type->name; |
|
2022 |
||
9 | 2023 |
if ( isset( $filter['post_status'] ) ) { |
0 | 2024 |
$query['post_status'] = $filter['post_status']; |
9 | 2025 |
} |
2026 |
||
2027 |
if ( isset( $filter['number'] ) ) { |
|
0 | 2028 |
$query['numberposts'] = absint( $filter['number'] ); |
9 | 2029 |
} |
2030 |
||
2031 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2032 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2033 |
} |
0 | 2034 |
|
2035 |
if ( isset( $filter['orderby'] ) ) { |
|
2036 |
$query['orderby'] = $filter['orderby']; |
|
2037 |
||
9 | 2038 |
if ( isset( $filter['order'] ) ) { |
0 | 2039 |
$query['order'] = $filter['order']; |
9 | 2040 |
} |
0 | 2041 |
} |
2042 |
||
2043 |
if ( isset( $filter['s'] ) ) { |
|
2044 |
$query['s'] = $filter['s']; |
|
2045 |
} |
|
2046 |
||
2047 |
$posts_list = wp_get_recent_posts( $query ); |
|
2048 |
||
9 | 2049 |
if ( ! $posts_list ) { |
0 | 2050 |
return array(); |
9 | 2051 |
} |
0 | 2052 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
// Holds all the posts data. |
0 | 2054 |
$struct = array(); |
2055 |
||
2056 |
foreach ( $posts_list as $post ) { |
|
9 | 2057 |
if ( ! current_user_can( 'edit_post', $post['ID'] ) ) { |
0 | 2058 |
continue; |
9 | 2059 |
} |
0 | 2060 |
|
2061 |
$struct[] = $this->_prepare_post( $post, $fields ); |
|
2062 |
} |
|
2063 |
||
2064 |
return $struct; |
|
2065 |
} |
|
2066 |
||
2067 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2068 |
* Creates a new term. |
0 | 2069 |
* |
2070 |
* @since 3.4.0 |
|
2071 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
* @see wp_insert_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2077 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2078 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2079 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2080 |
* @type array $3 Content struct for adding a new term. The struct must contain |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2081 |
* the term 'name' and 'taxonomy'. Optional accepted values include |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2082 |
* 'parent', 'description', and 'slug'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
* @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
0 | 2085 |
*/ |
5 | 2086 |
public function wp_newTerm( $args ) { |
9 | 2087 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2088 |
return $this->error; |
9 | 2089 |
} |
0 | 2090 |
|
2091 |
$this->escape( $args ); |
|
2092 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
$content_struct = $args[3]; |
0 | 2096 |
|
16 | 2097 |
$user = $this->login( $username, $password ); |
2098 |
if ( ! $user ) { |
|
0 | 2099 |
return $this->error; |
9 | 2100 |
} |
0 | 2101 |
|
5 | 2102 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2103 |
do_action( 'xmlrpc_call', 'wp.newTerm', $args, $this ); |
0 | 2104 |
|
9 | 2105 |
if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2107 |
} |
0 | 2108 |
|
2109 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2110 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
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
|
2113 |
} |
0 | 2114 |
|
2115 |
$taxonomy = (array) $taxonomy; |
|
2116 |
||
16 | 2117 |
// Hold the data of the term. |
0 | 2118 |
$term_data = array(); |
2119 |
||
2120 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
9 | 2121 |
if ( empty( $term_data['name'] ) ) { |
0 | 2122 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2123 |
} |
0 | 2124 |
|
2125 |
if ( isset( $content_struct['parent'] ) ) { |
|
9 | 2126 |
if ( ! $taxonomy['hierarchical'] ) { |
0 | 2127 |
return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
9 | 2128 |
} |
0 | 2129 |
|
2130 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2131 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2132 |
||
2133 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2134 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2135 |
} |
2136 |
||
2137 |
if ( ! $parent_term ) { |
|
0 | 2138 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2139 |
} |
0 | 2140 |
|
2141 |
$term_data['parent'] = $content_struct['parent']; |
|
2142 |
} |
|
2143 |
||
9 | 2144 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2145 |
$term_data['description'] = $content_struct['description']; |
9 | 2146 |
} |
2147 |
||
2148 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2149 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2150 |
} |
2151 |
||
2152 |
$term = wp_insert_term( $term_data['name'], $taxonomy['name'], $term_data ); |
|
2153 |
||
2154 |
if ( is_wp_error( $term ) ) { |
|
0 | 2155 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2156 |
} |
2157 |
||
2158 |
if ( ! $term ) { |
|
16 | 2159 |
return new IXR_Error( 500, __( 'Sorry, the term could not be created.' ) ); |
9 | 2160 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2161 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2162 |
// Add term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2163 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2164 |
$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
|
2165 |
} |
0 | 2166 |
|
18 | 2167 |
return (string) $term['term_id']; |
0 | 2168 |
} |
2169 |
||
2170 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2171 |
* Edits a term. |
0 | 2172 |
* |
2173 |
* @since 3.4.0 |
|
2174 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
* @see wp_update_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2179 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2180 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2181 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2182 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2183 |
* @type int $3 Term ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2184 |
* @type array $4 Content struct for editing a term. The struct must contain the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2185 |
* term 'taxonomy'. Optional accepted values include 'name', 'parent', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2186 |
* 'description', and 'slug'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2187 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2188 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2189 |
*/ |
5 | 2190 |
public function wp_editTerm( $args ) { |
9 | 2191 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2192 |
return $this->error; |
9 | 2193 |
} |
0 | 2194 |
|
2195 |
$this->escape( $args ); |
|
2196 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
$term_id = (int) $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
$content_struct = $args[4]; |
0 | 2201 |
|
16 | 2202 |
$user = $this->login( $username, $password ); |
2203 |
if ( ! $user ) { |
|
0 | 2204 |
return $this->error; |
9 | 2205 |
} |
0 | 2206 |
|
5 | 2207 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2208 |
do_action( 'xmlrpc_call', 'wp.editTerm', $args, $this ); |
0 | 2209 |
|
9 | 2210 |
if ( ! taxonomy_exists( $content_struct['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.' ) ); |
9 | 2212 |
} |
0 | 2213 |
|
2214 |
$taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
|
2215 |
||
2216 |
$taxonomy = (array) $taxonomy; |
|
2217 |
||
16 | 2218 |
// Hold the data of the term. |
0 | 2219 |
$term_data = array(); |
2220 |
||
9 | 2221 |
$term = get_term( $term_id, $content_struct['taxonomy'] ); |
2222 |
||
2223 |
if ( is_wp_error( $term ) ) { |
|
0 | 2224 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2225 |
} |
2226 |
||
2227 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2229 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
if ( ! current_user_can( 'edit_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
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
|
2233 |
} |
0 | 2234 |
|
2235 |
if ( isset( $content_struct['name'] ) ) { |
|
2236 |
$term_data['name'] = trim( $content_struct['name'] ); |
|
2237 |
||
9 | 2238 |
if ( empty( $term_data['name'] ) ) { |
0 | 2239 |
return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
9 | 2240 |
} |
0 | 2241 |
} |
2242 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
if ( ! empty( $content_struct['parent'] ) ) { |
9 | 2244 |
if ( ! $taxonomy['hierarchical'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
9 | 2246 |
} |
0 | 2247 |
|
2248 |
$parent_term_id = (int) $content_struct['parent']; |
|
9 | 2249 |
$parent_term = get_term( $parent_term_id, $taxonomy['name'] ); |
2250 |
||
2251 |
if ( is_wp_error( $parent_term ) ) { |
|
0 | 2252 |
return new IXR_Error( 500, $parent_term->get_error_message() ); |
9 | 2253 |
} |
2254 |
||
2255 |
if ( ! $parent_term ) { |
|
0 | 2256 |
return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
9 | 2257 |
} |
0 | 2258 |
|
2259 |
$term_data['parent'] = $content_struct['parent']; |
|
2260 |
} |
|
2261 |
||
9 | 2262 |
if ( isset( $content_struct['description'] ) ) { |
0 | 2263 |
$term_data['description'] = $content_struct['description']; |
9 | 2264 |
} |
2265 |
||
2266 |
if ( isset( $content_struct['slug'] ) ) { |
|
0 | 2267 |
$term_data['slug'] = $content_struct['slug']; |
9 | 2268 |
} |
2269 |
||
2270 |
$term = wp_update_term( $term_id, $taxonomy['name'], $term_data ); |
|
2271 |
||
2272 |
if ( is_wp_error( $term ) ) { |
|
0 | 2273 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2274 |
} |
2275 |
||
2276 |
if ( ! $term ) { |
|
0 | 2277 |
return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
9 | 2278 |
} |
0 | 2279 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
// Update term meta. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
if ( isset( $content_struct['custom_fields'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
$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
|
2283 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
|
0 | 2285 |
return true; |
2286 |
} |
|
2287 |
||
2288 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2289 |
* Deletes a term. |
0 | 2290 |
* |
2291 |
* @since 3.4.0 |
|
2292 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2293 |
* @see wp_delete_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2294 |
* |
16 | 2295 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2296 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2297 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2298 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2299 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2300 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2301 |
* @type string $3 Taxonomy name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2302 |
* @type int $4 Term ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2303 |
* } |
18 | 2304 |
* @return true|IXR_Error True on success, IXR_Error instance on failure. |
0 | 2305 |
*/ |
5 | 2306 |
public function wp_deleteTerm( $args ) { |
9 | 2307 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2308 |
return $this->error; |
9 | 2309 |
} |
0 | 2310 |
|
2311 |
$this->escape( $args ); |
|
2312 |
||
9 | 2313 |
$username = $args[1]; |
2314 |
$password = $args[2]; |
|
2315 |
$taxonomy = $args[3]; |
|
2316 |
$term_id = (int) $args[4]; |
|
2317 |
||
16 | 2318 |
$user = $this->login( $username, $password ); |
2319 |
if ( ! $user ) { |
|
0 | 2320 |
return $this->error; |
9 | 2321 |
} |
0 | 2322 |
|
5 | 2323 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2324 |
do_action( 'xmlrpc_call', 'wp.deleteTerm', $args, $this ); |
0 | 2325 |
|
9 | 2326 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2327 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2328 |
} |
0 | 2329 |
|
2330 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
9 | 2331 |
$term = get_term( $term_id, $taxonomy->name ); |
2332 |
||
2333 |
if ( is_wp_error( $term ) ) { |
|
0 | 2334 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2335 |
} |
2336 |
||
2337 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2338 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2339 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
if ( ! current_user_can( 'delete_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
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
|
2343 |
} |
0 | 2344 |
|
2345 |
$result = wp_delete_term( $term_id, $taxonomy->name ); |
|
2346 |
||
9 | 2347 |
if ( is_wp_error( $result ) ) { |
0 | 2348 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2349 |
} |
2350 |
||
2351 |
if ( ! $result ) { |
|
0 | 2352 |
return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
9 | 2353 |
} |
0 | 2354 |
|
2355 |
return $result; |
|
2356 |
} |
|
2357 |
||
2358 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2359 |
* Retrieves a term. |
0 | 2360 |
* |
2361 |
* @since 3.4.0 |
|
2362 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2363 |
* @see get_term() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2364 |
* |
16 | 2365 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2368 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2369 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2370 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2371 |
* @type string $3 Taxonomy name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2372 |
* @type int $4 Term ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
* @return array|IXR_Error IXR_Error on failure, array on success, containing: |
0 | 2375 |
* - 'term_id' |
2376 |
* - 'name' |
|
2377 |
* - 'slug' |
|
2378 |
* - 'term_group' |
|
2379 |
* - 'term_taxonomy_id' |
|
2380 |
* - 'taxonomy' |
|
2381 |
* - 'description' |
|
2382 |
* - 'parent' |
|
2383 |
* - 'count' |
|
2384 |
*/ |
|
5 | 2385 |
public function wp_getTerm( $args ) { |
9 | 2386 |
if ( ! $this->minimum_args( $args, 5 ) ) { |
0 | 2387 |
return $this->error; |
9 | 2388 |
} |
0 | 2389 |
|
2390 |
$this->escape( $args ); |
|
2391 |
||
9 | 2392 |
$username = $args[1]; |
2393 |
$password = $args[2]; |
|
2394 |
$taxonomy = $args[3]; |
|
2395 |
$term_id = (int) $args[4]; |
|
2396 |
||
16 | 2397 |
$user = $this->login( $username, $password ); |
2398 |
if ( ! $user ) { |
|
0 | 2399 |
return $this->error; |
9 | 2400 |
} |
0 | 2401 |
|
5 | 2402 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2403 |
do_action( 'xmlrpc_call', 'wp.getTerm', $args, $this ); |
0 | 2404 |
|
9 | 2405 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2406 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2407 |
} |
0 | 2408 |
|
2409 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2410 |
||
9 | 2411 |
$term = get_term( $term_id, $taxonomy->name, ARRAY_A ); |
2412 |
||
2413 |
if ( is_wp_error( $term ) ) { |
|
0 | 2414 |
return new IXR_Error( 500, $term->get_error_message() ); |
9 | 2415 |
} |
2416 |
||
2417 |
if ( ! $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
9 | 2419 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2420 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2421 |
if ( ! current_user_can( 'assign_term', $term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2422 |
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
|
2423 |
} |
0 | 2424 |
|
2425 |
return $this->_prepare_term( $term ); |
|
2426 |
} |
|
2427 |
||
2428 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2429 |
* Retrieves all terms for a taxonomy. |
0 | 2430 |
* |
2431 |
* @since 3.4.0 |
|
2432 |
* |
|
2433 |
* The optional $filter parameter modifies the query used to retrieve terms. |
|
2434 |
* Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
|
2435 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2436 |
* @see get_terms() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2437 |
* |
16 | 2438 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2439 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2440 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2441 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2442 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2443 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2444 |
* @type string $3 Taxonomy name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2445 |
* @type array $4 Optional. Modifies the query used to retrieve posts. Accepts 'number', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2446 |
* 'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2447 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2448 |
* @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
0 | 2449 |
*/ |
5 | 2450 |
public function wp_getTerms( $args ) { |
9 | 2451 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2452 |
return $this->error; |
9 | 2453 |
} |
0 | 2454 |
|
2455 |
$this->escape( $args ); |
|
2456 |
||
9 | 2457 |
$username = $args[1]; |
2458 |
$password = $args[2]; |
|
2459 |
$taxonomy = $args[3]; |
|
2460 |
$filter = isset( $args[4] ) ? $args[4] : array(); |
|
2461 |
||
16 | 2462 |
$user = $this->login( $username, $password ); |
2463 |
if ( ! $user ) { |
|
0 | 2464 |
return $this->error; |
9 | 2465 |
} |
0 | 2466 |
|
5 | 2467 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2468 |
do_action( 'xmlrpc_call', 'wp.getTerms', $args, $this ); |
0 | 2469 |
|
9 | 2470 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2472 |
} |
0 | 2473 |
|
2474 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2475 |
||
9 | 2476 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2478 |
} |
0 | 2479 |
|
16 | 2480 |
$query = array( 'taxonomy' => $taxonomy->name ); |
0 | 2481 |
|
9 | 2482 |
if ( isset( $filter['number'] ) ) { |
0 | 2483 |
$query['number'] = absint( $filter['number'] ); |
9 | 2484 |
} |
2485 |
||
2486 |
if ( isset( $filter['offset'] ) ) { |
|
0 | 2487 |
$query['offset'] = absint( $filter['offset'] ); |
9 | 2488 |
} |
0 | 2489 |
|
2490 |
if ( isset( $filter['orderby'] ) ) { |
|
2491 |
$query['orderby'] = $filter['orderby']; |
|
2492 |
||
9 | 2493 |
if ( isset( $filter['order'] ) ) { |
0 | 2494 |
$query['order'] = $filter['order']; |
9 | 2495 |
} |
2496 |
} |
|
2497 |
||
2498 |
if ( isset( $filter['hide_empty'] ) ) { |
|
0 | 2499 |
$query['hide_empty'] = $filter['hide_empty']; |
9 | 2500 |
} else { |
0 | 2501 |
$query['get'] = 'all'; |
9 | 2502 |
} |
2503 |
||
2504 |
if ( isset( $filter['search'] ) ) { |
|
0 | 2505 |
$query['search'] = $filter['search']; |
9 | 2506 |
} |
0 | 2507 |
|
16 | 2508 |
$terms = get_terms( $query ); |
0 | 2509 |
|
9 | 2510 |
if ( is_wp_error( $terms ) ) { |
0 | 2511 |
return new IXR_Error( 500, $terms->get_error_message() ); |
9 | 2512 |
} |
0 | 2513 |
|
2514 |
$struct = array(); |
|
2515 |
||
2516 |
foreach ( $terms as $term ) { |
|
2517 |
$struct[] = $this->_prepare_term( $term ); |
|
2518 |
} |
|
2519 |
||
2520 |
return $struct; |
|
2521 |
} |
|
2522 |
||
2523 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2524 |
* Retrieves a taxonomy. |
0 | 2525 |
* |
2526 |
* @since 3.4.0 |
|
2527 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
* @see get_taxonomy() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
* |
16 | 2530 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2531 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2532 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2533 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2534 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2535 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2536 |
* @type string $3 Taxonomy name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2537 |
* @type array $4 Optional. Array of taxonomy fields to limit to in the return. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2538 |
* Accepts 'labels', 'cap', 'menu', and 'object_type'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2539 |
* Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2540 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2541 |
* @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
0 | 2542 |
*/ |
5 | 2543 |
public function wp_getTaxonomy( $args ) { |
9 | 2544 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2545 |
return $this->error; |
9 | 2546 |
} |
0 | 2547 |
|
2548 |
$this->escape( $args ); |
|
2549 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2550 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2551 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2552 |
$taxonomy = $args[3]; |
0 | 2553 |
|
5 | 2554 |
if ( isset( $args[4] ) ) { |
0 | 2555 |
$fields = $args[4]; |
5 | 2556 |
} else { |
2557 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2558 |
* Filters the default taxonomy query fields used by the given XML-RPC method. |
5 | 2559 |
* |
2560 |
* @since 3.4.0 |
|
2561 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2562 |
* @param array $fields An array of taxonomy fields to retrieve. By default, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2563 |
* contains 'labels', 'cap', and 'object_type'. |
5 | 2564 |
* @param string $method The method name. |
2565 |
*/ |
|
0 | 2566 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
5 | 2567 |
} |
0 | 2568 |
|
16 | 2569 |
$user = $this->login( $username, $password ); |
2570 |
if ( ! $user ) { |
|
0 | 2571 |
return $this->error; |
9 | 2572 |
} |
0 | 2573 |
|
5 | 2574 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2575 |
do_action( 'xmlrpc_call', 'wp.getTaxonomy', $args, $this ); |
0 | 2576 |
|
9 | 2577 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2578 |
return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
9 | 2579 |
} |
0 | 2580 |
|
2581 |
$taxonomy = get_taxonomy( $taxonomy ); |
|
2582 |
||
9 | 2583 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2584 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
9 | 2585 |
} |
0 | 2586 |
|
2587 |
return $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2588 |
} |
|
2589 |
||
2590 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2591 |
* Retrieves all taxonomies. |
0 | 2592 |
* |
2593 |
* @since 3.4.0 |
|
2594 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
* @see get_taxonomies() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
* |
16 | 2597 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2600 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2601 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2602 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2603 |
* @type array $3 Optional. An array of arguments for retrieving taxonomies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2604 |
* @type array $4 Optional. The subset of taxonomy fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2606 |
* @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
|
2607 |
* by `$fields`, or an IXR_Error instance on failure. |
0 | 2608 |
*/ |
5 | 2609 |
public function wp_getTaxonomies( $args ) { |
9 | 2610 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2611 |
return $this->error; |
9 | 2612 |
} |
0 | 2613 |
|
2614 |
$this->escape( $args ); |
|
2615 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2617 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2618 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 2619 |
|
5 | 2620 |
if ( isset( $args[4] ) ) { |
0 | 2621 |
$fields = $args[4]; |
5 | 2622 |
} else { |
2623 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2624 |
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
5 | 2625 |
} |
0 | 2626 |
|
16 | 2627 |
$user = $this->login( $username, $password ); |
2628 |
if ( ! $user ) { |
|
0 | 2629 |
return $this->error; |
9 | 2630 |
} |
0 | 2631 |
|
5 | 2632 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2633 |
do_action( 'xmlrpc_call', 'wp.getTaxonomies', $args, $this ); |
0 | 2634 |
|
2635 |
$taxonomies = get_taxonomies( $filter, 'objects' ); |
|
2636 |
||
16 | 2637 |
// Holds all the taxonomy data. |
0 | 2638 |
$struct = array(); |
2639 |
||
2640 |
foreach ( $taxonomies as $taxonomy ) { |
|
16 | 2641 |
// Capability check for post types. |
9 | 2642 |
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) { |
0 | 2643 |
continue; |
9 | 2644 |
} |
0 | 2645 |
|
2646 |
$struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); |
|
2647 |
} |
|
2648 |
||
2649 |
return $struct; |
|
2650 |
} |
|
2651 |
||
2652 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2653 |
* Retrieves a user. |
0 | 2654 |
* |
2655 |
* The optional $fields parameter specifies what fields will be included |
|
2656 |
* in the response array. This should be a list of field names. 'user_id' will |
|
2657 |
* always be included in the response regardless of the value of $fields. |
|
2658 |
* |
|
2659 |
* Instead of, or in addition to, individual field names, conceptual group |
|
2660 |
* names can be used to specify multiple fields. The available conceptual |
|
2661 |
* groups are 'basic' and 'all'. |
|
2662 |
* |
|
2663 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2664 |
* |
16 | 2665 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2667 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2668 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2669 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2670 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2671 |
* @type int $3 User ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2672 |
* @type array $4 Optional. Array of fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
* } |
5 | 2674 |
* @return array|IXR_Error Array contains (based on $fields parameter): |
0 | 2675 |
* - 'user_id' |
2676 |
* - 'username' |
|
2677 |
* - 'first_name' |
|
2678 |
* - 'last_name' |
|
2679 |
* - 'registered' |
|
2680 |
* - 'bio' |
|
2681 |
* - 'email' |
|
2682 |
* - 'nickname' |
|
2683 |
* - 'nicename' |
|
2684 |
* - 'url' |
|
2685 |
* - 'display_name' |
|
2686 |
* - 'roles' |
|
2687 |
*/ |
|
5 | 2688 |
public function wp_getUser( $args ) { |
9 | 2689 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2690 |
return $this->error; |
9 | 2691 |
} |
0 | 2692 |
|
2693 |
$this->escape( $args ); |
|
2694 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2697 |
$user_id = (int) $args[3]; |
0 | 2698 |
|
5 | 2699 |
if ( isset( $args[4] ) ) { |
0 | 2700 |
$fields = $args[4]; |
5 | 2701 |
} else { |
2702 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
* Filters the default user query fields used by the given XML-RPC method. |
5 | 2704 |
* |
2705 |
* @since 3.5.0 |
|
2706 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2707 |
* @param array $fields An array of user fields to retrieve. By default, contains 'all'. |
5 | 2708 |
* @param string $method The method name. |
2709 |
*/ |
|
0 | 2710 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
5 | 2711 |
} |
0 | 2712 |
|
16 | 2713 |
$user = $this->login( $username, $password ); |
2714 |
if ( ! $user ) { |
|
0 | 2715 |
return $this->error; |
9 | 2716 |
} |
0 | 2717 |
|
5 | 2718 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2719 |
do_action( 'xmlrpc_call', 'wp.getUser', $args, $this ); |
0 | 2720 |
|
9 | 2721 |
if ( ! current_user_can( 'edit_user', $user_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2722 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
9 | 2723 |
} |
0 | 2724 |
|
2725 |
$user_data = get_userdata( $user_id ); |
|
2726 |
||
9 | 2727 |
if ( ! $user_data ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
return new IXR_Error( 404, __( 'Invalid user ID.' ) ); |
9 | 2729 |
} |
0 | 2730 |
|
2731 |
return $this->_prepare_user( $user_data, $fields ); |
|
2732 |
} |
|
2733 |
||
2734 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2735 |
* Retrieves users. |
0 | 2736 |
* |
2737 |
* The optional $filter parameter modifies the query used to retrieve users. |
|
2738 |
* Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', |
|
2739 |
* 'who', 'orderby', and 'order'. |
|
2740 |
* |
|
2741 |
* The optional $fields parameter specifies what fields will be included |
|
2742 |
* in the response array. |
|
2743 |
* |
|
2744 |
* @uses get_users() |
|
2745 |
* @see wp_getUser() for more on $fields and return values |
|
2746 |
* |
|
16 | 2747 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2748 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2749 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2750 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2751 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2752 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2753 |
* @type array $3 Optional. Arguments for the user query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2754 |
* @type array $4 Optional. Fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2755 |
* } |
5 | 2756 |
* @return array|IXR_Error users data |
0 | 2757 |
*/ |
5 | 2758 |
public function wp_getUsers( $args ) { |
9 | 2759 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2760 |
return $this->error; |
9 | 2761 |
} |
0 | 2762 |
|
2763 |
$this->escape( $args ); |
|
2764 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2765 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2766 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
$filter = isset( $args[3] ) ? $args[3] : array(); |
0 | 2768 |
|
5 | 2769 |
if ( isset( $args[4] ) ) { |
0 | 2770 |
$fields = $args[4]; |
5 | 2771 |
} else { |
2772 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2773 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
5 | 2774 |
} |
0 | 2775 |
|
16 | 2776 |
$user = $this->login( $username, $password ); |
2777 |
if ( ! $user ) { |
|
0 | 2778 |
return $this->error; |
9 | 2779 |
} |
0 | 2780 |
|
5 | 2781 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2782 |
do_action( 'xmlrpc_call', 'wp.getUsers', $args, $this ); |
0 | 2783 |
|
9 | 2784 |
if ( ! current_user_can( 'list_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2785 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
9 | 2786 |
} |
0 | 2787 |
|
2788 |
$query = array( 'fields' => 'all_with_meta' ); |
|
2789 |
||
2790 |
$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50; |
|
2791 |
$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0; |
|
2792 |
||
2793 |
if ( isset( $filter['orderby'] ) ) { |
|
2794 |
$query['orderby'] = $filter['orderby']; |
|
2795 |
||
9 | 2796 |
if ( isset( $filter['order'] ) ) { |
0 | 2797 |
$query['order'] = $filter['order']; |
9 | 2798 |
} |
0 | 2799 |
} |
2800 |
||
2801 |
if ( isset( $filter['role'] ) ) { |
|
9 | 2802 |
if ( get_role( $filter['role'] ) === null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
return new IXR_Error( 403, __( 'Invalid role.' ) ); |
9 | 2804 |
} |
0 | 2805 |
|
2806 |
$query['role'] = $filter['role']; |
|
2807 |
} |
|
2808 |
||
2809 |
if ( isset( $filter['who'] ) ) { |
|
2810 |
$query['who'] = $filter['who']; |
|
2811 |
} |
|
2812 |
||
2813 |
$users = get_users( $query ); |
|
2814 |
||
2815 |
$_users = array(); |
|
2816 |
foreach ( $users as $user_data ) { |
|
9 | 2817 |
if ( current_user_can( 'edit_user', $user_data->ID ) ) { |
0 | 2818 |
$_users[] = $this->_prepare_user( $user_data, $fields ); |
9 | 2819 |
} |
0 | 2820 |
} |
2821 |
return $_users; |
|
2822 |
} |
|
2823 |
||
2824 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2825 |
* Retrieves information about the requesting user. |
0 | 2826 |
* |
2827 |
* @uses get_userdata() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
* |
16 | 2829 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2830 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2831 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2832 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2833 |
* @type string $1 Username |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2834 |
* @type string $2 Password |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2835 |
* @type array $3 Optional. Fields to return. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2836 |
* } |
5 | 2837 |
* @return array|IXR_Error (@see wp_getUser) |
0 | 2838 |
*/ |
5 | 2839 |
public function wp_getProfile( $args ) { |
9 | 2840 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 2841 |
return $this->error; |
9 | 2842 |
} |
0 | 2843 |
|
2844 |
$this->escape( $args ); |
|
2845 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
$password = $args[2]; |
0 | 2848 |
|
5 | 2849 |
if ( isset( $args[3] ) ) { |
0 | 2850 |
$fields = $args[3]; |
5 | 2851 |
} else { |
2852 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 2853 |
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
5 | 2854 |
} |
0 | 2855 |
|
16 | 2856 |
$user = $this->login( $username, $password ); |
2857 |
if ( ! $user ) { |
|
0 | 2858 |
return $this->error; |
9 | 2859 |
} |
0 | 2860 |
|
5 | 2861 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2862 |
do_action( 'xmlrpc_call', 'wp.getProfile', $args, $this ); |
0 | 2863 |
|
9 | 2864 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2866 |
} |
0 | 2867 |
|
2868 |
$user_data = get_userdata( $user->ID ); |
|
2869 |
||
2870 |
return $this->_prepare_user( $user_data, $fields ); |
|
2871 |
} |
|
2872 |
||
2873 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2874 |
* Edits user's profile. |
0 | 2875 |
* |
2876 |
* @uses wp_update_user() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
* |
16 | 2878 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2879 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2880 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2881 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2882 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2883 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2884 |
* @type array $3 Content struct. It can optionally contain: |
0 | 2885 |
* - 'first_name' |
2886 |
* - 'last_name' |
|
2887 |
* - 'website' |
|
2888 |
* - 'display_name' |
|
2889 |
* - 'nickname' |
|
2890 |
* - 'nicename' |
|
2891 |
* - 'bio' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2892 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2893 |
* @return true|IXR_Error True, on success. |
0 | 2894 |
*/ |
5 | 2895 |
public function wp_editProfile( $args ) { |
9 | 2896 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 2897 |
return $this->error; |
9 | 2898 |
} |
0 | 2899 |
|
2900 |
$this->escape( $args ); |
|
2901 |
||
2902 |
$username = $args[1]; |
|
2903 |
$password = $args[2]; |
|
2904 |
$content_struct = $args[3]; |
|
2905 |
||
16 | 2906 |
$user = $this->login( $username, $password ); |
2907 |
if ( ! $user ) { |
|
0 | 2908 |
return $this->error; |
9 | 2909 |
} |
0 | 2910 |
|
5 | 2911 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 2912 |
do_action( 'xmlrpc_call', 'wp.editProfile', $args, $this ); |
0 | 2913 |
|
9 | 2914 |
if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
9 | 2916 |
} |
0 | 2917 |
|
16 | 2918 |
// Holds data of the user. |
9 | 2919 |
$user_data = array(); |
0 | 2920 |
$user_data['ID'] = $user->ID; |
2921 |
||
16 | 2922 |
// Only set the user details if they were given. |
9 | 2923 |
if ( isset( $content_struct['first_name'] ) ) { |
0 | 2924 |
$user_data['first_name'] = $content_struct['first_name']; |
9 | 2925 |
} |
2926 |
||
2927 |
if ( isset( $content_struct['last_name'] ) ) { |
|
0 | 2928 |
$user_data['last_name'] = $content_struct['last_name']; |
9 | 2929 |
} |
2930 |
||
2931 |
if ( isset( $content_struct['url'] ) ) { |
|
0 | 2932 |
$user_data['user_url'] = $content_struct['url']; |
9 | 2933 |
} |
2934 |
||
2935 |
if ( isset( $content_struct['display_name'] ) ) { |
|
0 | 2936 |
$user_data['display_name'] = $content_struct['display_name']; |
9 | 2937 |
} |
2938 |
||
2939 |
if ( isset( $content_struct['nickname'] ) ) { |
|
0 | 2940 |
$user_data['nickname'] = $content_struct['nickname']; |
9 | 2941 |
} |
2942 |
||
2943 |
if ( isset( $content_struct['nicename'] ) ) { |
|
0 | 2944 |
$user_data['user_nicename'] = $content_struct['nicename']; |
9 | 2945 |
} |
2946 |
||
2947 |
if ( isset( $content_struct['bio'] ) ) { |
|
0 | 2948 |
$user_data['description'] = $content_struct['bio']; |
9 | 2949 |
} |
0 | 2950 |
|
2951 |
$result = wp_update_user( $user_data ); |
|
2952 |
||
9 | 2953 |
if ( is_wp_error( $result ) ) { |
0 | 2954 |
return new IXR_Error( 500, $result->get_error_message() ); |
9 | 2955 |
} |
2956 |
||
2957 |
if ( ! $result ) { |
|
16 | 2958 |
return new IXR_Error( 500, __( 'Sorry, the user could not be updated.' ) ); |
9 | 2959 |
} |
0 | 2960 |
|
2961 |
return true; |
|
2962 |
} |
|
2963 |
||
2964 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2965 |
* Retrieves a page. |
0 | 2966 |
* |
2967 |
* @since 2.2.0 |
|
2968 |
* |
|
16 | 2969 |
* @param array $args { |
7
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 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2972 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2973 |
* @type int $1 Page ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2974 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2975 |
* @type string $3 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
* } |
5 | 2977 |
* @return array|IXR_Error |
0 | 2978 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
public function wp_getPage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2980 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
$password = $args[3]; |
0 | 2985 |
|
16 | 2986 |
$user = $this->login( $username, $password ); |
2987 |
if ( ! $user ) { |
|
0 | 2988 |
return $this->error; |
2989 |
} |
|
2990 |
||
9 | 2991 |
$page = get_post( $page_id ); |
2992 |
if ( ! $page ) { |
|
0 | 2993 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 2994 |
} |
2995 |
||
2996 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 2998 |
} |
0 | 2999 |
|
5 | 3000 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3001 |
do_action( 'xmlrpc_call', 'wp.getPage', $args, $this ); |
0 | 3002 |
|
3003 |
// If we found the page then format the data. |
|
16 | 3004 |
if ( $page->ID && ( 'page' === $page->post_type ) ) { |
0 | 3005 |
return $this->_prepare_page( $page ); |
9 | 3006 |
} else { |
16 | 3007 |
// If the page doesn't exist, indicate that. |
5 | 3008 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
0 | 3009 |
} |
3010 |
} |
|
3011 |
||
3012 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3013 |
* Retrieves Pages. |
0 | 3014 |
* |
3015 |
* @since 2.2.0 |
|
3016 |
* |
|
16 | 3017 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3020 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3021 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3022 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3023 |
* @type int $3 Optional. Number of pages. Default 10. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
* } |
5 | 3025 |
* @return array|IXR_Error |
0 | 3026 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
public function wp_getPages( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
$this->escape( $args ); |
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 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
$password = $args[2]; |
9 | 3032 |
$num_pages = isset( $args[3] ) ? (int) $args[3] : 10; |
3033 |
||
16 | 3034 |
$user = $this->login( $username, $password ); |
3035 |
if ( ! $user ) { |
|
0 | 3036 |
return $this->error; |
9 | 3037 |
} |
3038 |
||
3039 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3041 |
} |
0 | 3042 |
|
5 | 3043 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3044 |
do_action( 'xmlrpc_call', 'wp.getPages', $args, $this ); |
0 | 3045 |
|
9 | 3046 |
$pages = get_posts( |
3047 |
array( |
|
3048 |
'post_type' => 'page', |
|
3049 |
'post_status' => 'any', |
|
3050 |
'numberposts' => $num_pages, |
|
3051 |
) |
|
3052 |
); |
|
3053 |
$num_pages = count( $pages ); |
|
0 | 3054 |
|
3055 |
// If we have pages, put together their info. |
|
3056 |
if ( $num_pages >= 1 ) { |
|
3057 |
$pages_struct = array(); |
|
3058 |
||
9 | 3059 |
foreach ( $pages as $page ) { |
3060 |
if ( current_user_can( 'edit_page', $page->ID ) ) { |
|
0 | 3061 |
$pages_struct[] = $this->_prepare_page( $page ); |
9 | 3062 |
} |
0 | 3063 |
} |
3064 |
||
5 | 3065 |
return $pages_struct; |
0 | 3066 |
} |
5 | 3067 |
|
3068 |
return array(); |
|
0 | 3069 |
} |
3070 |
||
3071 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3072 |
* Creates a new page. |
0 | 3073 |
* |
3074 |
* @since 2.2.0 |
|
3075 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* @see wp_xmlrpc_server::mw_newPost() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
* |
16 | 3078 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3081 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3082 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3083 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3084 |
* @type array $3 Content struct. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
* } |
5 | 3086 |
* @return int|IXR_Error |
0 | 3087 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3088 |
public function wp_newPage( $args ) { |
16 | 3089 |
// Items not escaped here will be escaped in wp_newPost(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
$password = $this->escape( $args[2] ); |
0 | 3092 |
|
16 | 3093 |
$user = $this->login( $username, $password ); |
3094 |
if ( ! $user ) { |
|
0 | 3095 |
return $this->error; |
9 | 3096 |
} |
0 | 3097 |
|
5 | 3098 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3099 |
do_action( 'xmlrpc_call', 'wp.newPage', $args, $this ); |
0 | 3100 |
|
3101 |
// Mark this as content for a page. |
|
9 | 3102 |
$args[3]['post_type'] = 'page'; |
0 | 3103 |
|
16 | 3104 |
// Let mw_newPost() do all of the heavy lifting. |
5 | 3105 |
return $this->mw_newPost( $args ); |
0 | 3106 |
} |
3107 |
||
3108 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3109 |
* Deletes a page. |
0 | 3110 |
* |
3111 |
* @since 2.2.0 |
|
3112 |
* |
|
16 | 3113 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3116 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3117 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3118 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3119 |
* @type int $3 Page ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
* @return true|IXR_Error True, if success. |
0 | 3122 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
public function wp_deletePage( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3125 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
$page_id = (int) $args[3]; |
0 | 3129 |
|
16 | 3130 |
$user = $this->login( $username, $password ); |
3131 |
if ( ! $user ) { |
|
0 | 3132 |
return $this->error; |
9 | 3133 |
} |
0 | 3134 |
|
5 | 3135 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3136 |
do_action( 'xmlrpc_call', 'wp.deletePage', $args, $this ); |
0 | 3137 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3138 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3139 |
* Get the current page based on the 'page_id' and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3140 |
* make sure it is a page and not a post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3141 |
*/ |
9 | 3142 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3143 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3144 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3145 |
} |
0 | 3146 |
|
3147 |
// Make sure the user can delete pages. |
|
9 | 3148 |
if ( ! current_user_can( 'delete_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) ); |
9 | 3150 |
} |
0 | 3151 |
|
3152 |
// Attempt to delete the page. |
|
9 | 3153 |
$result = wp_delete_post( $page_id ); |
3154 |
if ( ! $result ) { |
|
5 | 3155 |
return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
9 | 3156 |
} |
5 | 3157 |
|
3158 |
/** |
|
3159 |
* Fires after a page has been successfully deleted via XML-RPC. |
|
3160 |
* |
|
3161 |
* @since 3.4.0 |
|
3162 |
* |
|
3163 |
* @param int $page_id ID of the deleted page. |
|
3164 |
* @param array $args An array of arguments to delete the page. |
|
3165 |
*/ |
|
16 | 3166 |
do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3167 |
|
5 | 3168 |
return true; |
0 | 3169 |
} |
3170 |
||
3171 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3172 |
* Edits a page. |
0 | 3173 |
* |
3174 |
* @since 2.2.0 |
|
3175 |
* |
|
16 | 3176 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3178 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3179 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3180 |
* @type int $1 Page ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3181 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3182 |
* @type string $3 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3183 |
* @type string $4 Content. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3184 |
* @type int $5 Publish flag. 0 for draft, 1 for publish. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
* } |
5 | 3186 |
* @return array|IXR_Error |
0 | 3187 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
public function wp_editPage( $args ) { |
16 | 3189 |
// Items will be escaped in mw_editPost(). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
$page_id = (int) $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
$publish = $args[5]; |
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 |
$escaped_username = $this->escape( $username ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
$escaped_password = $this->escape( $password ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
|
16 | 3199 |
$user = $this->login( $escaped_username, $escaped_password ); |
3200 |
if ( ! $user ) { |
|
0 | 3201 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
} |
0 | 3203 |
|
5 | 3204 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3205 |
do_action( 'xmlrpc_call', 'wp.editPage', $args, $this ); |
0 | 3206 |
|
3207 |
// Get the page data and make sure it is a page. |
|
9 | 3208 |
$actual_page = get_post( $page_id, ARRAY_A ); |
16 | 3209 |
if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
5 | 3210 |
return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
9 | 3211 |
} |
0 | 3212 |
|
3213 |
// Make sure the user is allowed to edit pages. |
|
9 | 3214 |
if ( ! current_user_can( 'edit_page', $page_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
9 | 3216 |
} |
0 | 3217 |
|
3218 |
// Mark this as content for a page. |
|
3219 |
$content['post_type'] = 'page'; |
|
3220 |
||
16 | 3221 |
// Arrange args in the way mw_editPost() understands. |
0 | 3222 |
$args = array( |
3223 |
$page_id, |
|
3224 |
$username, |
|
3225 |
$password, |
|
3226 |
$content, |
|
9 | 3227 |
$publish, |
0 | 3228 |
); |
3229 |
||
16 | 3230 |
// Let mw_editPost() do all of the heavy lifting. |
5 | 3231 |
return $this->mw_editPost( $args ); |
0 | 3232 |
} |
3233 |
||
3234 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3235 |
* Retrieves page list. |
0 | 3236 |
* |
3237 |
* @since 2.2.0 |
|
3238 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
* |
16 | 3241 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3244 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3245 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3246 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
* } |
5 | 3248 |
* @return array|IXR_Error |
0 | 3249 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
public function wp_getPageList( $args ) { |
0 | 3251 |
global $wpdb; |
3252 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
$password = $args[2]; |
0 | 3257 |
|
16 | 3258 |
$user = $this->login( $username, $password ); |
3259 |
if ( ! $user ) { |
|
0 | 3260 |
return $this->error; |
9 | 3261 |
} |
3262 |
||
3263 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3264 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
9 | 3265 |
} |
0 | 3266 |
|
5 | 3267 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3268 |
do_action( 'xmlrpc_call', 'wp.getPageList', $args, $this ); |
0 | 3269 |
|
16 | 3270 |
// Get list of page IDs and titles. |
9 | 3271 |
$page_list = $wpdb->get_results( |
3272 |
" |
|
0 | 3273 |
SELECT ID page_id, |
3274 |
post_title page_title, |
|
3275 |
post_parent page_parent_id, |
|
3276 |
post_date_gmt, |
|
3277 |
post_date, |
|
3278 |
post_status |
|
3279 |
FROM {$wpdb->posts} |
|
3280 |
WHERE post_type = 'page' |
|
3281 |
ORDER BY ID |
|
9 | 3282 |
" |
3283 |
); |
|
0 | 3284 |
|
3285 |
// The date needs to be formatted properly. |
|
9 | 3286 |
$num_pages = count( $page_list ); |
0 | 3287 |
for ( $i = 0; $i < $num_pages; $i++ ) { |
9 | 3288 |
$page_list[ $i ]->dateCreated = $this->_convert_date( $page_list[ $i ]->post_date ); |
3289 |
$page_list[ $i ]->date_created_gmt = $this->_convert_date_gmt( $page_list[ $i ]->post_date_gmt, $page_list[ $i ]->post_date ); |
|
3290 |
||
3291 |
unset( $page_list[ $i ]->post_date_gmt ); |
|
3292 |
unset( $page_list[ $i ]->post_date ); |
|
3293 |
unset( $page_list[ $i ]->post_status ); |
|
0 | 3294 |
} |
3295 |
||
5 | 3296 |
return $page_list; |
0 | 3297 |
} |
3298 |
||
3299 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3300 |
* Retrieves authors list. |
0 | 3301 |
* |
3302 |
* @since 2.2.0 |
|
3303 |
* |
|
16 | 3304 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3307 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3308 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3309 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
* } |
5 | 3311 |
* @return array|IXR_Error |
0 | 3312 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
public function wp_getAuthors( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
$password = $args[2]; |
0 | 3318 |
|
16 | 3319 |
$user = $this->login( $username, $password ); |
3320 |
if ( ! $user ) { |
|
0 | 3321 |
return $this->error; |
9 | 3322 |
} |
3323 |
||
3324 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 3326 |
} |
5 | 3327 |
|
3328 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 3329 |
do_action( 'xmlrpc_call', 'wp.getAuthors', $args, $this ); |
0 | 3330 |
|
3331 |
$authors = array(); |
|
9 | 3332 |
foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
0 | 3333 |
$authors[] = array( |
9 | 3334 |
'user_id' => $user->ID, |
3335 |
'user_login' => $user->user_login, |
|
3336 |
'display_name' => $user->display_name, |
|
0 | 3337 |
); |
3338 |
} |
|
3339 |
||
3340 |
return $authors; |
|
3341 |
} |
|
3342 |
||
3343 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3344 |
* Gets the list of all tags. |
0 | 3345 |
* |
3346 |
* @since 2.7.0 |
|
3347 |
* |
|
16 | 3348 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3349 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3351 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3352 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3353 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
* } |
5 | 3355 |
* @return array|IXR_Error |
0 | 3356 |
*/ |
5 | 3357 |
public function wp_getTags( $args ) { |
0 | 3358 |
$this->escape( $args ); |
3359 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3360 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3361 |
$password = $args[2]; |
0 | 3362 |
|
16 | 3363 |
$user = $this->login( $username, $password ); |
3364 |
if ( ! $user ) { |
|
0 | 3365 |
return $this->error; |
9 | 3366 |
} |
3367 |
||
3368 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 3369 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
9 | 3370 |
} |
0 | 3371 |
|
5 | 3372 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3373 |
do_action( 'xmlrpc_call', 'wp.getKeywords', $args, $this ); |
0 | 3374 |
|
3375 |
$tags = array(); |
|
3376 |
||
16 | 3377 |
$all_tags = get_tags(); |
3378 |
if ( $all_tags ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
foreach ( (array) $all_tags as $tag ) { |
9 | 3380 |
$struct = array(); |
3381 |
$struct['tag_id'] = $tag->term_id; |
|
3382 |
$struct['name'] = $tag->name; |
|
3383 |
$struct['count'] = $tag->count; |
|
3384 |
$struct['slug'] = $tag->slug; |
|
3385 |
$struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
|
3386 |
$struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) ); |
|
0 | 3387 |
|
3388 |
$tags[] = $struct; |
|
3389 |
} |
|
3390 |
} |
|
3391 |
||
3392 |
return $tags; |
|
3393 |
} |
|
3394 |
||
3395 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3396 |
* Creates a new category. |
0 | 3397 |
* |
3398 |
* @since 2.2.0 |
|
3399 |
* |
|
16 | 3400 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3403 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3404 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3405 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3406 |
* @type array $3 Category. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
* } |
5 | 3408 |
* @return int|IXR_Error Category ID. |
0 | 3409 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
public function wp_newCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
$category = $args[3]; |
0 | 3416 |
|
16 | 3417 |
$user = $this->login( $username, $password ); |
3418 |
if ( ! $user ) { |
|
0 | 3419 |
return $this->error; |
9 | 3420 |
} |
0 | 3421 |
|
5 | 3422 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3423 |
do_action( 'xmlrpc_call', 'wp.newCategory', $args, $this ); |
0 | 3424 |
|
3425 |
// 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
|
3426 |
if ( ! current_user_can( 'manage_categories' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
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
|
3428 |
} |
0 | 3429 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3430 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3431 |
* If no slug was provided, make it empty |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3432 |
* so that WordPress will generate one. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3433 |
*/ |
9 | 3434 |
if ( empty( $category['slug'] ) ) { |
0 | 3435 |
$category['slug'] = ''; |
9 | 3436 |
} |
0 | 3437 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3438 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3439 |
* If no parent_id was provided, make it empty |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3440 |
* so that it will be a top-level page (no parent). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3441 |
*/ |
9 | 3442 |
if ( ! isset( $category['parent_id'] ) ) { |
0 | 3443 |
$category['parent_id'] = ''; |
9 | 3444 |
} |
0 | 3445 |
|
16 | 3446 |
// If no description was provided, make it empty. |
9 | 3447 |
if ( empty( $category['description'] ) ) { |
3448 |
$category['description'] = ''; |
|
3449 |
} |
|
0 | 3450 |
|
3451 |
$new_category = array( |
|
9 | 3452 |
'cat_name' => $category['name'], |
3453 |
'category_nicename' => $category['slug'], |
|
3454 |
'category_parent' => $category['parent_id'], |
|
3455 |
'category_description' => $category['description'], |
|
0 | 3456 |
); |
3457 |
||
9 | 3458 |
$cat_id = wp_insert_category( $new_category, true ); |
0 | 3459 |
if ( is_wp_error( $cat_id ) ) { |
16 | 3460 |
if ( 'term_exists' === $cat_id->get_error_code() ) { |
0 | 3461 |
return (int) $cat_id->get_error_data(); |
9 | 3462 |
} else { |
16 | 3463 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
9 | 3464 |
} |
0 | 3465 |
} elseif ( ! $cat_id ) { |
16 | 3466 |
return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) ); |
0 | 3467 |
} |
3468 |
||
5 | 3469 |
/** |
3470 |
* Fires after a new category has been successfully created via XML-RPC. |
|
3471 |
* |
|
3472 |
* @since 3.4.0 |
|
3473 |
* |
|
3474 |
* @param int $cat_id ID of the new category. |
|
3475 |
* @param array $args An array of new category arguments. |
|
3476 |
*/ |
|
16 | 3477 |
do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3478 |
|
3479 |
return $cat_id; |
|
3480 |
} |
|
3481 |
||
3482 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3483 |
* Deletes a category. |
0 | 3484 |
* |
3485 |
* @since 2.5.0 |
|
3486 |
* |
|
16 | 3487 |
* @param array $args { |
7
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 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3490 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3491 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3492 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3493 |
* @type int $3 Category ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
* @return bool|IXR_Error See wp_delete_term() for return info. |
0 | 3496 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3497 |
public function wp_deleteCategory( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3498 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3499 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3500 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3501 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3502 |
$category_id = (int) $args[3]; |
0 | 3503 |
|
16 | 3504 |
$user = $this->login( $username, $password ); |
3505 |
if ( ! $user ) { |
|
0 | 3506 |
return $this->error; |
9 | 3507 |
} |
0 | 3508 |
|
5 | 3509 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3510 |
do_action( 'xmlrpc_call', 'wp.deleteCategory', $args, $this ); |
0 | 3511 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
if ( ! current_user_can( 'delete_term', $category_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
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
|
3514 |
} |
0 | 3515 |
|
3516 |
$status = wp_delete_term( $category_id, 'category' ); |
|
3517 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3518 |
if ( true === $status ) { |
5 | 3519 |
/** |
3520 |
* Fires after a category has been successfully deleted via XML-RPC. |
|
3521 |
* |
|
3522 |
* @since 3.4.0 |
|
3523 |
* |
|
3524 |
* @param int $category_id ID of the deleted category. |
|
3525 |
* @param array $args An array of arguments to delete the category. |
|
3526 |
*/ |
|
16 | 3527 |
do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3528 |
} |
0 | 3529 |
|
3530 |
return $status; |
|
3531 |
} |
|
3532 |
||
3533 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3534 |
* Retrieves category list. |
0 | 3535 |
* |
3536 |
* @since 2.2.0 |
|
3537 |
* |
|
16 | 3538 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3541 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3542 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3543 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3544 |
* @type array $3 Category |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3545 |
* @type int $4 Max number of results. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
* } |
5 | 3547 |
* @return array|IXR_Error |
0 | 3548 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
public function wp_suggestCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3550 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3551 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3552 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
$category = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
$max_results = (int) $args[4]; |
0 | 3556 |
|
16 | 3557 |
$user = $this->login( $username, $password ); |
3558 |
if ( ! $user ) { |
|
0 | 3559 |
return $this->error; |
9 | 3560 |
} |
3561 |
||
3562 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
5 | 3563 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 3564 |
} |
5 | 3565 |
|
3566 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 3567 |
do_action( 'xmlrpc_call', 'wp.suggestCategories', $args, $this ); |
0 | 3568 |
|
3569 |
$category_suggestions = array(); |
|
9 | 3570 |
$args = array( |
3571 |
'get' => 'all', |
|
3572 |
'number' => $max_results, |
|
3573 |
'name__like' => $category, |
|
3574 |
); |
|
3575 |
foreach ( (array) get_categories( $args ) as $cat ) { |
|
0 | 3576 |
$category_suggestions[] = array( |
9 | 3577 |
'category_id' => $cat->term_id, |
3578 |
'category_name' => $cat->name, |
|
0 | 3579 |
); |
3580 |
} |
|
3581 |
||
5 | 3582 |
return $category_suggestions; |
0 | 3583 |
} |
3584 |
||
3585 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3586 |
* Retrieves a comment. |
0 | 3587 |
* |
3588 |
* @since 2.7.0 |
|
3589 |
* |
|
16 | 3590 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3593 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3594 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3595 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3596 |
* @type int $3 Comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
* } |
5 | 3598 |
* @return array|IXR_Error |
0 | 3599 |
*/ |
9 | 3600 |
public function wp_getComment( $args ) { |
3601 |
$this->escape( $args ); |
|
3602 |
||
3603 |
$username = $args[1]; |
|
3604 |
$password = $args[2]; |
|
3605 |
$comment_id = (int) $args[3]; |
|
0 | 3606 |
|
16 | 3607 |
$user = $this->login( $username, $password ); |
3608 |
if ( ! $user ) { |
|
0 | 3609 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
} |
0 | 3611 |
|
5 | 3612 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3613 |
do_action( 'xmlrpc_call', 'wp.getComment', $args, $this ); |
0 | 3614 |
|
16 | 3615 |
$comment = get_comment( $comment_id ); |
3616 |
if ( ! $comment ) { |
|
0 | 3617 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3618 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3619 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
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
|
3622 |
} |
0 | 3623 |
|
3624 |
return $this->_prepare_comment( $comment ); |
|
3625 |
} |
|
3626 |
||
3627 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3628 |
* Retrieves comments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3629 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3630 |
* Besides the common blog_id (unused), username, and password arguments, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3631 |
* it takes a filter array as the last argument. |
0 | 3632 |
* |
3633 |
* Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
|
3634 |
* |
|
3635 |
* The defaults are as follows: |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3636 |
* - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3637 |
* - 'post_id' - Default is ''. The post where the comment is posted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3638 |
* Empty string shows all comments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3639 |
* - 'number' - Default is 10. Total number of media items to retrieve. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3640 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
0 | 3641 |
* |
3642 |
* @since 2.7.0 |
|
3643 |
* |
|
16 | 3644 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3646 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3647 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3648 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3649 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3650 |
* @type array $3 Optional. Query arguments. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3652 |
* @return array|IXR_Error Array containing a collection of comments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3653 |
* See wp_xmlrpc_server::wp_getComment() for a description |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3654 |
* of each item contents. |
0 | 3655 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
public function wp_getComments( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3658 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
$password = $args[2]; |
9 | 3661 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
|
16 | 3663 |
$user = $this->login( $username, $password ); |
3664 |
if ( ! $user ) { |
|
0 | 3665 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
} |
0 | 3667 |
|
5 | 3668 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3669 |
do_action( 'xmlrpc_call', 'wp.getComments', $args, $this ); |
0 | 3670 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
if ( isset( $struct['status'] ) ) { |
0 | 3672 |
$status = $struct['status']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
} else { |
0 | 3674 |
$status = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
} |
0 | 3680 |
|
3681 |
$post_id = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3682 |
if ( isset( $struct['post_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3683 |
$post_id = absint( $struct['post_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3684 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3685 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
$post_type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
if ( isset( $struct['post_type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
$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
|
3689 |
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
|
3690 |
return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
$post_type = $struct['post_type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3693 |
} |
0 | 3694 |
|
3695 |
$offset = 0; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
if ( isset( $struct['offset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
$offset = absint( $struct['offset'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
} |
0 | 3699 |
|
3700 |
$number = 10; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
if ( isset( $struct['number'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
$number = absint( $struct['number'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3704 |
|
9 | 3705 |
$comments = get_comments( |
3706 |
array( |
|
3707 |
'status' => $status, |
|
3708 |
'post_id' => $post_id, |
|
3709 |
'offset' => $offset, |
|
3710 |
'number' => $number, |
|
3711 |
'post_type' => $post_type, |
|
3712 |
) |
|
3713 |
); |
|
0 | 3714 |
|
3715 |
$comments_struct = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
if ( is_array( $comments ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
foreach ( $comments as $comment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
$comments_struct[] = $this->_prepare_comment( $comment ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
} |
0 | 3720 |
} |
3721 |
||
3722 |
return $comments_struct; |
|
3723 |
} |
|
3724 |
||
3725 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3726 |
* Deletes a comment. |
0 | 3727 |
* |
16 | 3728 |
* 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
|
3729 |
* See wp_delete_comment() for more information on this behavior. |
0 | 3730 |
* |
3731 |
* @since 2.7.0 |
|
3732 |
* |
|
16 | 3733 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3735 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3736 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3737 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3738 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3739 |
* @type int $3 Comment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
* @return bool|IXR_Error See wp_delete_comment(). |
0 | 3742 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
public function wp_deleteComment( $args ) { |
9 | 3744 |
$this->escape( $args ); |
3745 |
||
3746 |
$username = $args[1]; |
|
3747 |
$password = $args[2]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3748 |
$comment_id = (int) $args[3]; |
0 | 3749 |
|
16 | 3750 |
$user = $this->login( $username, $password ); |
3751 |
if ( ! $user ) { |
|
0 | 3752 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3755 |
if ( ! get_comment( $comment_id ) ) { |
0 | 3756 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3759 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
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
|
3761 |
} |
0 | 3762 |
|
5 | 3763 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3764 |
do_action( 'xmlrpc_call', 'wp.deleteComment', $args, $this ); |
0 | 3765 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3766 |
$status = wp_delete_comment( $comment_id ); |
0 | 3767 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3768 |
if ( true === $status ) { |
5 | 3769 |
/** |
3770 |
* Fires after a comment has been successfully deleted via XML-RPC. |
|
3771 |
* |
|
3772 |
* @since 3.4.0 |
|
3773 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3774 |
* @param int $comment_id ID of the deleted comment. |
5 | 3775 |
* @param array $args An array of arguments to delete the comment. |
3776 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3777 |
do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5 | 3778 |
} |
0 | 3779 |
|
3780 |
return $status; |
|
3781 |
} |
|
3782 |
||
3783 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3784 |
* Edits a comment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3785 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3786 |
* Besides the common blog_id (unused), username, and password arguments, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3787 |
* it takes a comment_id integer and a content_struct array as the last argument. |
0 | 3788 |
* |
3789 |
* The allowed keys in the content_struct array are: |
|
3790 |
* - 'author' |
|
3791 |
* - 'author_url' |
|
3792 |
* - 'author_email' |
|
3793 |
* - 'content' |
|
3794 |
* - 'date_created_gmt' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3795 |
* - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details. |
0 | 3796 |
* |
3797 |
* @since 2.7.0 |
|
3798 |
* |
|
16 | 3799 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3800 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3802 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3803 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3804 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3805 |
* @type int $3 Comment ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3806 |
* @type array $4 Content structure. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
* @return true|IXR_Error True, on success. |
0 | 3809 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
public function wp_editComment( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
$this->escape( $args ); |
0 | 3812 |
|
9 | 3813 |
$username = $args[1]; |
3814 |
$password = $args[2]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3815 |
$comment_id = (int) $args[3]; |
0 | 3816 |
$content_struct = $args[4]; |
3817 |
||
16 | 3818 |
$user = $this->login( $username, $password ); |
3819 |
if ( ! $user ) { |
|
0 | 3820 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3821 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3823 |
if ( ! get_comment( $comment_id ) ) { |
0 | 3824 |
return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3827 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
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
|
3829 |
} |
0 | 3830 |
|
5 | 3831 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 3832 |
do_action( 'xmlrpc_call', 'wp.editComment', $args, $this ); |
9 | 3833 |
$comment = array( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3834 |
'comment_ID' => $comment_id, |
9 | 3835 |
); |
3836 |
||
3837 |
if ( isset( $content_struct['status'] ) ) { |
|
0 | 3838 |
$statuses = get_comment_statuses(); |
9 | 3839 |
$statuses = array_keys( $statuses ); |
3840 |
||
16 | 3841 |
if ( ! in_array( $content_struct['status'], $statuses, true ) ) { |
0 | 3842 |
return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
9 | 3843 |
} |
3844 |
||
3845 |
$comment['comment_approved'] = $content_struct['status']; |
|
0 | 3846 |
} |
3847 |
||
16 | 3848 |
// Do some timestamp voodoo. |
9 | 3849 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 3850 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3851 |
$date_created = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3852 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3853 |
$comment['comment_date'] = get_date_from_gmt( $date_created ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3854 |
$comment['comment_date_gmt'] = iso8601_to_datetime( $date_created, 'gmt' ); |
9 | 3855 |
} |
3856 |
||
3857 |
if ( isset( $content_struct['content'] ) ) { |
|
3858 |
$comment['comment_content'] = $content_struct['content']; |
|
3859 |
} |
|
3860 |
||
3861 |
if ( isset( $content_struct['author'] ) ) { |
|
3862 |
$comment['comment_author'] = $content_struct['author']; |
|
3863 |
} |
|
3864 |
||
3865 |
if ( isset( $content_struct['author_url'] ) ) { |
|
3866 |
$comment['comment_author_url'] = $content_struct['author_url']; |
|
3867 |
} |
|
3868 |
||
3869 |
if ( isset( $content_struct['author_email'] ) ) { |
|
3870 |
$comment['comment_author_email'] = $content_struct['author_email']; |
|
3871 |
} |
|
3872 |
||
16 | 3873 |
$result = wp_update_comment( $comment, true ); |
9 | 3874 |
if ( is_wp_error( $result ) ) { |
3875 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
3876 |
} |
|
3877 |
||
3878 |
if ( ! $result ) { |
|
16 | 3879 |
return new IXR_Error( 500, __( 'Sorry, the comment could not be updated.' ) ); |
9 | 3880 |
} |
0 | 3881 |
|
5 | 3882 |
/** |
3883 |
* Fires after a comment has been successfully updated via XML-RPC. |
|
3884 |
* |
|
3885 |
* @since 3.4.0 |
|
3886 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3887 |
* @param int $comment_id ID of the updated comment. |
5 | 3888 |
* @param array $args An array of arguments to update the comment. |
3889 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3890 |
do_action( 'xmlrpc_call_success_wp_editComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 3891 |
|
3892 |
return true; |
|
3893 |
} |
|
3894 |
||
3895 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3896 |
* Creates a new comment. |
0 | 3897 |
* |
3898 |
* @since 2.7.0 |
|
3899 |
* |
|
16 | 3900 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3903 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3904 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3905 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3906 |
* @type string|int $3 Post ID or URL. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3907 |
* @type array $4 Content structure. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
* @return int|IXR_Error See wp_new_comment(). |
0 | 3910 |
*/ |
9 | 3911 |
public function wp_newComment( $args ) { |
3912 |
$this->escape( $args ); |
|
0 | 3913 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
$post = $args[3]; |
0 | 3917 |
$content_struct = $args[4]; |
3918 |
||
5 | 3919 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
* Filters whether to allow anonymous comments over XML-RPC. |
5 | 3921 |
* |
3922 |
* @since 2.7.0 |
|
3923 |
* |
|
3924 |
* @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3925 |
* Default false. |
|
3926 |
*/ |
|
3927 |
$allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
|
0 | 3928 |
|
9 | 3929 |
$user = $this->login( $username, $password ); |
3930 |
||
3931 |
if ( ! $user ) { |
|
0 | 3932 |
$logged_in = false; |
9 | 3933 |
if ( $allow_anon && get_option( 'comment_registration' ) ) { |
16 | 3934 |
return new IXR_Error( 403, __( 'Sorry, you must be logged in to comment.' ) ); |
5 | 3935 |
} elseif ( ! $allow_anon ) { |
0 | 3936 |
return $this->error; |
5 | 3937 |
} |
0 | 3938 |
} else { |
3939 |
$logged_in = true; |
|
3940 |
} |
|
3941 |
||
9 | 3942 |
if ( is_numeric( $post ) ) { |
3943 |
$post_id = absint( $post ); |
|
3944 |
} else { |
|
3945 |
$post_id = url_to_postid( $post ); |
|
3946 |
} |
|
0 | 3947 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
if ( ! $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
if ( ! get_post( $post_id ) ) { |
0 | 3953 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
if ( ! comments_open( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
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
|
3958 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
|
18 | 3960 |
if ( |
3961 |
'publish' === get_post_status( $post_id ) && |
|
3962 |
! current_user_can( 'edit_post', $post_id ) && |
|
3963 |
post_password_required( $post_id ) |
|
3964 |
) { |
|
3965 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
|
3966 |
} |
|
3967 |
||
3968 |
if ( |
|
3969 |
'private' === get_post_status( $post_id ) && |
|
3970 |
! current_user_can( 'read_post', $post_id ) |
|
3971 |
) { |
|
3972 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
$comment = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
'comment_post_ID' => $post_id, |
18 | 3977 |
'comment_content' => trim( $content_struct['content'] ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
); |
0 | 3979 |
|
3980 |
if ( $logged_in ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
$display_name = $user->display_name; |
9 | 3982 |
$user_email = $user->user_email; |
3983 |
$user_url = $user->user_url; |
|
3984 |
||
3985 |
$comment['comment_author'] = $this->escape( $display_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
$comment['comment_author_email'] = $this->escape( $user_email ); |
9 | 3987 |
$comment['comment_author_url'] = $this->escape( $user_url ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3988 |
$comment['user_id'] = $user->ID; |
0 | 3989 |
} else { |
3990 |
$comment['comment_author'] = ''; |
|
9 | 3991 |
if ( isset( $content_struct['author'] ) ) { |
0 | 3992 |
$comment['comment_author'] = $content_struct['author']; |
9 | 3993 |
} |
0 | 3994 |
|
3995 |
$comment['comment_author_email'] = ''; |
|
9 | 3996 |
if ( isset( $content_struct['author_email'] ) ) { |
0 | 3997 |
$comment['comment_author_email'] = $content_struct['author_email']; |
9 | 3998 |
} |
0 | 3999 |
|
4000 |
$comment['comment_author_url'] = ''; |
|
9 | 4001 |
if ( isset( $content_struct['author_url'] ) ) { |
0 | 4002 |
$comment['comment_author_url'] = $content_struct['author_url']; |
9 | 4003 |
} |
0 | 4004 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4005 |
$comment['user_id'] = 0; |
0 | 4006 |
|
9 | 4007 |
if ( get_option( 'require_name_email' ) ) { |
18 | 4008 |
if ( strlen( $comment['comment_author_email'] ) < 6 || '' === $comment['comment_author'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4009 |
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
9 | 4010 |
} elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
9 | 4012 |
} |
0 | 4013 |
} |
4014 |
} |
|
4015 |
||
9 | 4016 |
$comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
0 | 4017 |
|
18 | 4018 |
/** This filter is documented in wp-includes/comment.php */ |
4019 |
$allow_empty = apply_filters( 'allow_empty_comment', false, $comment ); |
|
4020 |
||
4021 |
if ( ! $allow_empty && '' === $comment['comment_content'] ) { |
|
4022 |
return new IXR_Error( 403, __( 'Comment is required.' ) ); |
|
4023 |
} |
|
4024 |
||
5 | 4025 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4026 |
do_action( 'xmlrpc_call', 'wp.newComment', $args, $this ); |
0 | 4027 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4028 |
$comment_id = wp_new_comment( $comment, true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4029 |
if ( is_wp_error( $comment_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4030 |
return new IXR_Error( 403, $comment_id->get_error_message() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4031 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4032 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4033 |
if ( ! $comment_id ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4034 |
return new IXR_Error( 403, __( 'An error occurred while processing your comment. Please ensure all fields are filled correctly and try again.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4035 |
} |
0 | 4036 |
|
5 | 4037 |
/** |
4038 |
* Fires after a new comment has been successfully created via XML-RPC. |
|
4039 |
* |
|
4040 |
* @since 3.4.0 |
|
4041 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4042 |
* @param int $comment_id ID of the new comment. |
5 | 4043 |
* @param array $args An array of new comment arguments. |
4044 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4045 |
do_action( 'xmlrpc_call_success_wp_newComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4046 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4047 |
return $comment_id; |
0 | 4048 |
} |
4049 |
||
4050 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4051 |
* Retrieves all of the comment status. |
0 | 4052 |
* |
4053 |
* @since 2.7.0 |
|
4054 |
* |
|
16 | 4055 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4058 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4059 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4060 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4061 |
* } |
5 | 4062 |
* @return array|IXR_Error |
0 | 4063 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4064 |
public function wp_getCommentStatusList( $args ) { |
0 | 4065 |
$this->escape( $args ); |
4066 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4067 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4068 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4069 |
|
16 | 4070 |
$user = $this->login( $username, $password ); |
4071 |
if ( ! $user ) { |
|
0 | 4072 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4073 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4074 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
if ( ! current_user_can( 'publish_posts' ) ) { |
9 | 4076 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4077 |
} |
0 | 4078 |
|
5 | 4079 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4080 |
do_action( 'xmlrpc_call', 'wp.getCommentStatusList', $args, $this ); |
0 | 4081 |
|
4082 |
return get_comment_statuses(); |
|
4083 |
} |
|
4084 |
||
4085 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4086 |
* Retrieves comment counts. |
0 | 4087 |
* |
4088 |
* @since 2.5.0 |
|
4089 |
* |
|
16 | 4090 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4091 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4092 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4093 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4094 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4095 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4096 |
* @type int $3 Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4097 |
* } |
5 | 4098 |
* @return array|IXR_Error |
0 | 4099 |
*/ |
5 | 4100 |
public function wp_getCommentCount( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4101 |
$this->escape( $args ); |
0 | 4102 |
|
9 | 4103 |
$username = $args[1]; |
4104 |
$password = $args[2]; |
|
4105 |
$post_id = (int) $args[3]; |
|
0 | 4106 |
|
16 | 4107 |
$user = $this->login( $username, $password ); |
4108 |
if ( ! $user ) { |
|
0 | 4109 |
return $this->error; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4110 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4112 |
$post = get_post( $post_id, ARRAY_A ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4113 |
if ( empty( $post['ID'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4114 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4115 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4116 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4117 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 4118 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details of this post.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4119 |
} |
0 | 4120 |
|
5 | 4121 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4122 |
do_action( 'xmlrpc_call', 'wp.getCommentCount', $args, $this ); |
0 | 4123 |
|
4124 |
$count = wp_count_comments( $post_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4125 |
|
0 | 4126 |
return array( |
9 | 4127 |
'approved' => $count->approved, |
0 | 4128 |
'awaiting_moderation' => $count->moderated, |
9 | 4129 |
'spam' => $count->spam, |
4130 |
'total_comments' => $count->total_comments, |
|
0 | 4131 |
); |
4132 |
} |
|
4133 |
||
4134 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4135 |
* Retrieves post statuses. |
0 | 4136 |
* |
4137 |
* @since 2.5.0 |
|
4138 |
* |
|
16 | 4139 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4141 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4142 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4143 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4144 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
* } |
5 | 4146 |
* @return array|IXR_Error |
0 | 4147 |
*/ |
5 | 4148 |
public function wp_getPostStatusList( $args ) { |
0 | 4149 |
$this->escape( $args ); |
4150 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4151 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
$password = $args[2]; |
0 | 4153 |
|
16 | 4154 |
$user = $this->login( $username, $password ); |
4155 |
if ( ! $user ) { |
|
0 | 4156 |
return $this->error; |
9 | 4157 |
} |
4158 |
||
4159 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4160 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4161 |
} |
|
0 | 4162 |
|
5 | 4163 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4164 |
do_action( 'xmlrpc_call', 'wp.getPostStatusList', $args, $this ); |
0 | 4165 |
|
4166 |
return get_post_statuses(); |
|
4167 |
} |
|
4168 |
||
4169 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4170 |
* Retrieves page statuses. |
0 | 4171 |
* |
4172 |
* @since 2.5.0 |
|
4173 |
* |
|
16 | 4174 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4175 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4176 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4177 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4178 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4179 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4180 |
* } |
5 | 4181 |
* @return array|IXR_Error |
0 | 4182 |
*/ |
5 | 4183 |
public function wp_getPageStatusList( $args ) { |
0 | 4184 |
$this->escape( $args ); |
4185 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4186 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4187 |
$password = $args[2]; |
0 | 4188 |
|
16 | 4189 |
$user = $this->login( $username, $password ); |
4190 |
if ( ! $user ) { |
|
0 | 4191 |
return $this->error; |
9 | 4192 |
} |
4193 |
||
4194 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4195 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4196 |
} |
|
0 | 4197 |
|
5 | 4198 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4199 |
do_action( 'xmlrpc_call', 'wp.getPageStatusList', $args, $this ); |
0 | 4200 |
|
4201 |
return get_page_statuses(); |
|
4202 |
} |
|
4203 |
||
4204 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4205 |
* Retrieves page templates. |
0 | 4206 |
* |
4207 |
* @since 2.6.0 |
|
4208 |
* |
|
16 | 4209 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4212 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4213 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4214 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
* } |
5 | 4216 |
* @return array|IXR_Error |
0 | 4217 |
*/ |
5 | 4218 |
public function wp_getPageTemplates( $args ) { |
0 | 4219 |
$this->escape( $args ); |
4220 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4222 |
$password = $args[2]; |
0 | 4223 |
|
16 | 4224 |
$user = $this->login( $username, $password ); |
4225 |
if ( ! $user ) { |
|
0 | 4226 |
return $this->error; |
9 | 4227 |
} |
4228 |
||
4229 |
if ( ! current_user_can( 'edit_pages' ) ) { |
|
4230 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4231 |
} |
|
4232 |
||
4233 |
$templates = get_page_templates(); |
|
0 | 4234 |
$templates['Default'] = 'default'; |
4235 |
||
4236 |
return $templates; |
|
4237 |
} |
|
4238 |
||
4239 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4240 |
* Retrieves blog options. |
0 | 4241 |
* |
4242 |
* @since 2.6.0 |
|
4243 |
* |
|
16 | 4244 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4245 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4246 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4247 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4248 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4249 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4250 |
* @type array $3 Optional. Options. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4251 |
* } |
5 | 4252 |
* @return array|IXR_Error |
0 | 4253 |
*/ |
5 | 4254 |
public function wp_getOptions( $args ) { |
0 | 4255 |
$this->escape( $args ); |
4256 |
||
9 | 4257 |
$username = $args[1]; |
4258 |
$password = $args[2]; |
|
4259 |
$options = isset( $args[3] ) ? (array) $args[3] : array(); |
|
4260 |
||
16 | 4261 |
$user = $this->login( $username, $password ); |
4262 |
if ( ! $user ) { |
|
0 | 4263 |
return $this->error; |
9 | 4264 |
} |
0 | 4265 |
|
16 | 4266 |
// If no specific options where asked for, return all of them. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4267 |
if ( count( $options ) === 0 ) { |
9 | 4268 |
$options = array_keys( $this->blog_options ); |
4269 |
} |
|
4270 |
||
4271 |
return $this->_getOptions( $options ); |
|
0 | 4272 |
} |
4273 |
||
4274 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4275 |
* Retrieves blog options value from list. |
0 | 4276 |
* |
4277 |
* @since 2.6.0 |
|
4278 |
* |
|
4279 |
* @param array $options Options to retrieve. |
|
4280 |
* @return array |
|
4281 |
*/ |
|
9 | 4282 |
public function _getOptions( $options ) { |
4283 |
$data = array(); |
|
0 | 4284 |
$can_manage = current_user_can( 'manage_options' ); |
4285 |
foreach ( $options as $option ) { |
|
4286 |
if ( array_key_exists( $option, $this->blog_options ) ) { |
|
9 | 4287 |
$data[ $option ] = $this->blog_options[ $option ]; |
16 | 4288 |
// Is the value static or dynamic? |
9 | 4289 |
if ( isset( $data[ $option ]['option'] ) ) { |
4290 |
$data[ $option ]['value'] = get_option( $data[ $option ]['option'] ); |
|
4291 |
unset( $data[ $option ]['option'] ); |
|
0 | 4292 |
} |
4293 |
||
9 | 4294 |
if ( ! $can_manage ) { |
4295 |
$data[ $option ]['readonly'] = true; |
|
4296 |
} |
|
0 | 4297 |
} |
4298 |
} |
|
4299 |
||
4300 |
return $data; |
|
4301 |
} |
|
4302 |
||
4303 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4304 |
* Updates blog options. |
0 | 4305 |
* |
4306 |
* @since 2.6.0 |
|
4307 |
* |
|
16 | 4308 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4309 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4310 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4311 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4312 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4313 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4314 |
* @type array $3 Options. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4315 |
* } |
5 | 4316 |
* @return array|IXR_Error |
0 | 4317 |
*/ |
5 | 4318 |
public function wp_setOptions( $args ) { |
0 | 4319 |
$this->escape( $args ); |
4320 |
||
9 | 4321 |
$username = $args[1]; |
4322 |
$password = $args[2]; |
|
4323 |
$options = (array) $args[3]; |
|
4324 |
||
16 | 4325 |
$user = $this->login( $username, $password ); |
4326 |
if ( ! $user ) { |
|
0 | 4327 |
return $this->error; |
9 | 4328 |
} |
4329 |
||
4330 |
if ( ! current_user_can( 'manage_options' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4331 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) ); |
9 | 4332 |
} |
0 | 4333 |
|
5 | 4334 |
$option_names = array(); |
0 | 4335 |
foreach ( $options as $o_name => $o_value ) { |
4336 |
$option_names[] = $o_name; |
|
9 | 4337 |
if ( ! array_key_exists( $o_name, $this->blog_options ) ) { |
0 | 4338 |
continue; |
9 | 4339 |
} |
4340 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4341 |
if ( $this->blog_options[ $o_name ]['readonly'] ) { |
0 | 4342 |
continue; |
9 | 4343 |
} |
4344 |
||
4345 |
update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) ); |
|
0 | 4346 |
} |
4347 |
||
16 | 4348 |
// Now return the updated values. |
9 | 4349 |
return $this->_getOptions( $option_names ); |
0 | 4350 |
} |
4351 |
||
4352 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4353 |
* Retrieves a media item by ID. |
0 | 4354 |
* |
4355 |
* @since 3.1.0 |
|
4356 |
* |
|
16 | 4357 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4358 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4359 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4360 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4361 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4362 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4363 |
* @type int $3 Attachment ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4364 |
* } |
5 | 4365 |
* @return array|IXR_Error Associative array contains: |
0 | 4366 |
* - 'date_created_gmt' |
4367 |
* - 'parent' |
|
4368 |
* - 'link' |
|
4369 |
* - 'thumbnail' |
|
4370 |
* - 'title' |
|
4371 |
* - 'caption' |
|
4372 |
* - 'description' |
|
4373 |
* - 'metadata' |
|
4374 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
public function wp_getMediaItem( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4376 |
$this->escape( $args ); |
0 | 4377 |
|
9 | 4378 |
$username = $args[1]; |
4379 |
$password = $args[2]; |
|
4380 |
$attachment_id = (int) $args[3]; |
|
4381 |
||
16 | 4382 |
$user = $this->login( $username, $password ); |
4383 |
if ( ! $user ) { |
|
0 | 4384 |
return $this->error; |
9 | 4385 |
} |
4386 |
||
4387 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4389 |
} |
0 | 4390 |
|
5 | 4391 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4392 |
do_action( 'xmlrpc_call', 'wp.getMediaItem', $args, $this ); |
0 | 4393 |
|
16 | 4394 |
$attachment = get_post( $attachment_id ); |
18 | 4395 |
if ( ! $attachment || 'attachment' !== $attachment->post_type ) { |
0 | 4396 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 4397 |
} |
0 | 4398 |
|
4399 |
return $this->_prepare_media_item( $attachment ); |
|
4400 |
} |
|
4401 |
||
4402 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4403 |
* Retrieves a collection of media library items (or attachments). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4404 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4405 |
* Besides the common blog_id (unused), username, and password arguments, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4406 |
* it takes a filter array as the last argument. |
0 | 4407 |
* |
4408 |
* Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
|
4409 |
* |
|
4410 |
* The defaults are as follows: |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4411 |
* - 'number' - Default is 5. Total number of media items to retrieve. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4412 |
* - 'offset' - Default is 0. See WP_Query::query() for more. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4413 |
* - 'parent_id' - Default is ''. The post where the media item is attached. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4414 |
* Empty string shows all media items. 0 shows unattached media items. |
0 | 4415 |
* - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
4416 |
* |
|
4417 |
* @since 3.1.0 |
|
4418 |
* |
|
16 | 4419 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4422 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4423 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4424 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4425 |
* @type array $3 Optional. Query arguments. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4426 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4427 |
* @return array|IXR_Error Array containing a collection of media items. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4428 |
* See wp_xmlrpc_server::wp_getMediaItem() for a description |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4429 |
* of each item contents. |
0 | 4430 |
*/ |
9 | 4431 |
public function wp_getMediaLibrary( $args ) { |
4432 |
$this->escape( $args ); |
|
4433 |
||
4434 |
$username = $args[1]; |
|
4435 |
$password = $args[2]; |
|
4436 |
$struct = isset( $args[3] ) ? $args[3] : array(); |
|
4437 |
||
16 | 4438 |
$user = $this->login( $username, $password ); |
4439 |
if ( ! $user ) { |
|
0 | 4440 |
return $this->error; |
9 | 4441 |
} |
4442 |
||
4443 |
if ( ! current_user_can( 'upload_files' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4444 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
9 | 4445 |
} |
0 | 4446 |
|
5 | 4447 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4448 |
do_action( 'xmlrpc_call', 'wp.getMediaLibrary', $args, $this ); |
0 | 4449 |
|
9 | 4450 |
$parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4451 |
$mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
|
4452 |
$offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
|
4453 |
$number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
|
4454 |
||
4455 |
$attachments = get_posts( |
|
4456 |
array( |
|
4457 |
'post_type' => 'attachment', |
|
4458 |
'post_parent' => $parent_id, |
|
4459 |
'offset' => $offset, |
|
4460 |
'numberposts' => $number, |
|
4461 |
'post_mime_type' => $mime_type, |
|
4462 |
) |
|
4463 |
); |
|
0 | 4464 |
|
4465 |
$attachments_struct = array(); |
|
4466 |
||
9 | 4467 |
foreach ( $attachments as $attachment ) { |
0 | 4468 |
$attachments_struct[] = $this->_prepare_media_item( $attachment ); |
9 | 4469 |
} |
0 | 4470 |
|
4471 |
return $attachments_struct; |
|
4472 |
} |
|
4473 |
||
4474 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4475 |
* 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
|
4476 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4477 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4478 |
* |
16 | 4479 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4480 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4481 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4482 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4483 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4484 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
* @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
|
4487 |
*/ |
5 | 4488 |
public function wp_getPostFormats( $args ) { |
0 | 4489 |
$this->escape( $args ); |
4490 |
||
4491 |
$username = $args[1]; |
|
4492 |
$password = $args[2]; |
|
4493 |
||
16 | 4494 |
$user = $this->login( $username, $password ); |
4495 |
if ( ! $user ) { |
|
0 | 4496 |
return $this->error; |
9 | 4497 |
} |
4498 |
||
4499 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
4500 |
return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
|
4501 |
} |
|
0 | 4502 |
|
5 | 4503 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4504 |
do_action( 'xmlrpc_call', 'wp.getPostFormats', $args, $this ); |
0 | 4505 |
|
4506 |
$formats = get_post_format_strings(); |
|
4507 |
||
16 | 4508 |
// Find out if they want a list of currently supports formats. |
0 | 4509 |
if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4510 |
if ( $args[3]['show-supported'] ) { |
|
4511 |
if ( current_theme_supports( 'post-formats' ) ) { |
|
4512 |
$supported = get_theme_support( 'post-formats' ); |
|
4513 |
||
9 | 4514 |
$data = array(); |
4515 |
$data['all'] = $formats; |
|
0 | 4516 |
$data['supported'] = $supported[0]; |
4517 |
||
4518 |
$formats = $data; |
|
4519 |
} |
|
4520 |
} |
|
4521 |
} |
|
4522 |
||
4523 |
return $formats; |
|
4524 |
} |
|
4525 |
||
4526 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4527 |
* Retrieves a post type. |
0 | 4528 |
* |
4529 |
* @since 3.4.0 |
|
4530 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
* @see get_post_type_object() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
* |
16 | 4533 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4534 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4536 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4537 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4538 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4539 |
* @type string $3 Post type name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4540 |
* @type array $4 Optional. Fields to fetch. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4541 |
* } |
5 | 4542 |
* @return array|IXR_Error Array contains: |
0 | 4543 |
* - 'labels' |
4544 |
* - 'description' |
|
4545 |
* - 'capability_type' |
|
4546 |
* - 'cap' |
|
4547 |
* - 'map_meta_cap' |
|
4548 |
* - 'hierarchical' |
|
4549 |
* - 'menu_position' |
|
4550 |
* - 'taxonomies' |
|
4551 |
* - 'supports' |
|
4552 |
*/ |
|
5 | 4553 |
public function wp_getPostType( $args ) { |
9 | 4554 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4555 |
return $this->error; |
9 | 4556 |
} |
0 | 4557 |
|
4558 |
$this->escape( $args ); |
|
4559 |
||
4560 |
$username = $args[1]; |
|
4561 |
$password = $args[2]; |
|
4562 |
$post_type_name = $args[3]; |
|
4563 |
||
5 | 4564 |
if ( isset( $args[4] ) ) { |
0 | 4565 |
$fields = $args[4]; |
5 | 4566 |
} else { |
4567 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4568 |
* Filters the default post type query fields used by the given XML-RPC method. |
5 | 4569 |
* |
4570 |
* @since 3.4.0 |
|
4571 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4572 |
* @param array $fields An array of post type fields to retrieve. By default, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4573 |
* contains 'labels', 'cap', and 'taxonomies'. |
5 | 4574 |
* @param string $method The method name. |
4575 |
*/ |
|
0 | 4576 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
5 | 4577 |
} |
0 | 4578 |
|
16 | 4579 |
$user = $this->login( $username, $password ); |
4580 |
if ( ! $user ) { |
|
0 | 4581 |
return $this->error; |
9 | 4582 |
} |
0 | 4583 |
|
5 | 4584 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4585 |
do_action( 'xmlrpc_call', 'wp.getPostType', $args, $this ); |
0 | 4586 |
|
9 | 4587 |
if ( ! post_type_exists( $post_type_name ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
9 | 4589 |
} |
0 | 4590 |
|
4591 |
$post_type = get_post_type_object( $post_type_name ); |
|
4592 |
||
9 | 4593 |
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
|
4594 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
9 | 4595 |
} |
0 | 4596 |
|
4597 |
return $this->_prepare_post_type( $post_type, $fields ); |
|
4598 |
} |
|
4599 |
||
4600 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4601 |
* Retrieves post types. |
0 | 4602 |
* |
4603 |
* @since 3.4.0 |
|
4604 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4605 |
* @see get_post_types() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4606 |
* |
16 | 4607 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4608 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4609 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4610 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4611 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4612 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4613 |
* @type array $3 Optional. Query arguments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4614 |
* @type array $4 Optional. Fields to fetch. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4615 |
* } |
5 | 4616 |
* @return array|IXR_Error |
0 | 4617 |
*/ |
5 | 4618 |
public function wp_getPostTypes( $args ) { |
9 | 4619 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4620 |
return $this->error; |
9 | 4621 |
} |
0 | 4622 |
|
4623 |
$this->escape( $args ); |
|
4624 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4625 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4626 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4627 |
$filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
0 | 4628 |
|
5 | 4629 |
if ( isset( $args[4] ) ) { |
0 | 4630 |
$fields = $args[4]; |
5 | 4631 |
} else { |
4632 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
0 | 4633 |
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
5 | 4634 |
} |
0 | 4635 |
|
16 | 4636 |
$user = $this->login( $username, $password ); |
4637 |
if ( ! $user ) { |
|
0 | 4638 |
return $this->error; |
9 | 4639 |
} |
0 | 4640 |
|
5 | 4641 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4642 |
do_action( 'xmlrpc_call', 'wp.getPostTypes', $args, $this ); |
0 | 4643 |
|
4644 |
$post_types = get_post_types( $filter, 'objects' ); |
|
4645 |
||
4646 |
$struct = array(); |
|
4647 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4648 |
foreach ( $post_types as $post_type ) { |
9 | 4649 |
if ( ! current_user_can( $post_type->cap->edit_posts ) ) { |
0 | 4650 |
continue; |
9 | 4651 |
} |
4652 |
||
4653 |
$struct[ $post_type->name ] = $this->_prepare_post_type( $post_type, $fields ); |
|
0 | 4654 |
} |
4655 |
||
4656 |
return $struct; |
|
4657 |
} |
|
4658 |
||
4659 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4660 |
* Retrieves revisions for a specific post. |
0 | 4661 |
* |
4662 |
* @since 3.5.0 |
|
4663 |
* |
|
4664 |
* The optional $fields parameter specifies what fields will be included |
|
4665 |
* in the response array. |
|
4666 |
* |
|
4667 |
* @uses wp_get_post_revisions() |
|
4668 |
* @see wp_getPost() for more on $fields |
|
4669 |
* |
|
16 | 4670 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4671 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4672 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4673 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4674 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4675 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4676 |
* @type int $3 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4677 |
* @type array $4 Optional. Fields to fetch. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4678 |
* } |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4679 |
* @return array|IXR_Error Array containing a collection of posts. |
0 | 4680 |
*/ |
5 | 4681 |
public function wp_getRevisions( $args ) { |
9 | 4682 |
if ( ! $this->minimum_args( $args, 4 ) ) { |
0 | 4683 |
return $this->error; |
9 | 4684 |
} |
0 | 4685 |
|
4686 |
$this->escape( $args ); |
|
4687 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4688 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4689 |
$password = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4690 |
$post_id = (int) $args[3]; |
0 | 4691 |
|
5 | 4692 |
if ( isset( $args[4] ) ) { |
0 | 4693 |
$fields = $args[4]; |
5 | 4694 |
} else { |
4695 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4696 |
* Filters the default revision query fields used by the given XML-RPC method. |
5 | 4697 |
* |
4698 |
* @since 3.5.0 |
|
4699 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4700 |
* @param array $field An array of revision fields to retrieve. By default, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4701 |
* contains 'post_date' and 'post_date_gmt'. |
5 | 4702 |
* @param string $method The method name. |
4703 |
*/ |
|
0 | 4704 |
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
5 | 4705 |
} |
0 | 4706 |
|
16 | 4707 |
$user = $this->login( $username, $password ); |
4708 |
if ( ! $user ) { |
|
0 | 4709 |
return $this->error; |
9 | 4710 |
} |
0 | 4711 |
|
5 | 4712 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4713 |
do_action( 'xmlrpc_call', 'wp.getRevisions', $args, $this ); |
0 | 4714 |
|
16 | 4715 |
$post = get_post( $post_id ); |
4716 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4717 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4718 |
} |
4719 |
||
4720 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
0 | 4721 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 4722 |
} |
0 | 4723 |
|
4724 |
// Check if revisions are enabled. |
|
9 | 4725 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4726 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4727 |
} |
0 | 4728 |
|
4729 |
$revisions = wp_get_post_revisions( $post_id ); |
|
4730 |
||
9 | 4731 |
if ( ! $revisions ) { |
0 | 4732 |
return array(); |
9 | 4733 |
} |
0 | 4734 |
|
4735 |
$struct = array(); |
|
4736 |
||
4737 |
foreach ( $revisions as $revision ) { |
|
9 | 4738 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
0 | 4739 |
continue; |
9 | 4740 |
} |
0 | 4741 |
|
16 | 4742 |
// Skip autosaves. |
9 | 4743 |
if ( wp_is_post_autosave( $revision ) ) { |
0 | 4744 |
continue; |
9 | 4745 |
} |
0 | 4746 |
|
4747 |
$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); |
|
4748 |
} |
|
4749 |
||
4750 |
return $struct; |
|
4751 |
} |
|
4752 |
||
4753 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4754 |
* Restores a post revision. |
0 | 4755 |
* |
4756 |
* @since 3.5.0 |
|
4757 |
* |
|
4758 |
* @uses wp_restore_post_revision() |
|
4759 |
* |
|
16 | 4760 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4761 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4762 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4763 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4764 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4765 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4766 |
* @type int $3 Revision ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4767 |
* } |
5 | 4768 |
* @return bool|IXR_Error false if there was an error restoring, true if success. |
0 | 4769 |
*/ |
5 | 4770 |
public function wp_restoreRevision( $args ) { |
9 | 4771 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
0 | 4772 |
return $this->error; |
9 | 4773 |
} |
0 | 4774 |
|
4775 |
$this->escape( $args ); |
|
4776 |
||
4777 |
$username = $args[1]; |
|
4778 |
$password = $args[2]; |
|
4779 |
$revision_id = (int) $args[3]; |
|
4780 |
||
16 | 4781 |
$user = $this->login( $username, $password ); |
4782 |
if ( ! $user ) { |
|
0 | 4783 |
return $this->error; |
9 | 4784 |
} |
0 | 4785 |
|
5 | 4786 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4787 |
do_action( 'xmlrpc_call', 'wp.restoreRevision', $args, $this ); |
0 | 4788 |
|
16 | 4789 |
$revision = wp_get_post_revision( $revision_id ); |
4790 |
if ( ! $revision ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4791 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4792 |
} |
4793 |
||
4794 |
if ( wp_is_post_autosave( $revision ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4795 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4796 |
} |
4797 |
||
16 | 4798 |
$post = get_post( $revision->post_parent ); |
4799 |
if ( ! $post ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4800 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4801 |
} |
4802 |
||
4803 |
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
|
4804 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4805 |
} |
0 | 4806 |
|
4807 |
// Check if revisions are disabled. |
|
9 | 4808 |
if ( ! wp_revisions_enabled( $post ) ) { |
0 | 4809 |
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
9 | 4810 |
} |
0 | 4811 |
|
4812 |
$post = wp_restore_post_revision( $revision_id ); |
|
4813 |
||
4814 |
return (bool) $post; |
|
4815 |
} |
|
4816 |
||
16 | 4817 |
/* |
4818 |
* Blogger API functions. |
|
4819 |
* Specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
|
0 | 4820 |
*/ |
4821 |
||
4822 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4823 |
* Retrieves blogs that user owns. |
0 | 4824 |
* |
4825 |
* Will make more sense once we support multiple blogs. |
|
4826 |
* |
|
4827 |
* @since 1.5.0 |
|
4828 |
* |
|
16 | 4829 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4830 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4831 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4832 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4833 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4834 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4835 |
* } |
5 | 4836 |
* @return array|IXR_Error |
0 | 4837 |
*/ |
9 | 4838 |
public function blogger_getUsersBlogs( $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4839 |
if ( ! $this->minimum_args( $args, 3 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4840 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4841 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4842 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4843 |
if ( is_multisite() ) { |
9 | 4844 |
return $this->_multisite_getUsersBlogs( $args ); |
4845 |
} |
|
4846 |
||
4847 |
$this->escape( $args ); |
|
0 | 4848 |
|
4849 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4850 |
$password = $args[2]; |
0 | 4851 |
|
16 | 4852 |
$user = $this->login( $username, $password ); |
4853 |
if ( ! $user ) { |
|
0 | 4854 |
return $this->error; |
9 | 4855 |
} |
0 | 4856 |
|
5 | 4857 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4858 |
do_action( 'xmlrpc_call', 'blogger.getUsersBlogs', $args, $this ); |
0 | 4859 |
|
9 | 4860 |
$is_admin = current_user_can( 'manage_options' ); |
0 | 4861 |
|
4862 |
$struct = array( |
|
4863 |
'isAdmin' => $is_admin, |
|
9 | 4864 |
'url' => get_option( 'home' ) . '/', |
0 | 4865 |
'blogid' => '1', |
9 | 4866 |
'blogName' => get_option( 'blogname' ), |
0 | 4867 |
'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
4868 |
); |
|
4869 |
||
9 | 4870 |
return array( $struct ); |
0 | 4871 |
} |
4872 |
||
4873 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4874 |
* Private function for retrieving a users blogs for multisite setups. |
0 | 4875 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4876 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4877 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4878 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4879 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4880 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4881 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4882 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4883 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4884 |
* } |
5 | 4885 |
* @return array|IXR_Error |
0 | 4886 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4887 |
protected function _multisite_getUsersBlogs( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4888 |
$current_blog = get_site(); |
0 | 4889 |
|
4890 |
$domain = $current_blog->domain; |
|
9 | 4891 |
$path = $current_blog->path . 'xmlrpc.php'; |
0 | 4892 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4893 |
$blogs = $this->wp_getUsersBlogs( $args ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4894 |
if ( $blogs instanceof IXR_Error ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4895 |
return $blogs; |
9 | 4896 |
} |
0 | 4897 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4898 |
if ( $_SERVER['HTTP_HOST'] === $domain && $_SERVER['REQUEST_URI'] === $path ) { |
0 | 4899 |
return $blogs; |
4900 |
} else { |
|
4901 |
foreach ( (array) $blogs as $blog ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4902 |
if ( str_contains( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { |
9 | 4903 |
return array( $blog ); |
4904 |
} |
|
0 | 4905 |
} |
4906 |
return array(); |
|
4907 |
} |
|
4908 |
} |
|
4909 |
||
4910 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4911 |
* Retrieves user's data. |
0 | 4912 |
* |
4913 |
* Gives your client some info about you, so you don't have to. |
|
4914 |
* |
|
4915 |
* @since 1.5.0 |
|
4916 |
* |
|
16 | 4917 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4918 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4919 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4920 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4921 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4922 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4923 |
* } |
5 | 4924 |
* @return array|IXR_Error |
0 | 4925 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4926 |
public function blogger_getUserInfo( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4927 |
$this->escape( $args ); |
0 | 4928 |
|
4929 |
$username = $args[1]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4930 |
$password = $args[2]; |
0 | 4931 |
|
16 | 4932 |
$user = $this->login( $username, $password ); |
4933 |
if ( ! $user ) { |
|
0 | 4934 |
return $this->error; |
9 | 4935 |
} |
4936 |
||
4937 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4938 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
9 | 4939 |
} |
0 | 4940 |
|
5 | 4941 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4942 |
do_action( 'xmlrpc_call', 'blogger.getUserInfo', $args, $this ); |
0 | 4943 |
|
4944 |
$struct = array( |
|
4945 |
'nickname' => $user->nickname, |
|
4946 |
'userid' => $user->ID, |
|
4947 |
'url' => $user->user_url, |
|
4948 |
'lastname' => $user->last_name, |
|
9 | 4949 |
'firstname' => $user->first_name, |
0 | 4950 |
); |
4951 |
||
4952 |
return $struct; |
|
4953 |
} |
|
4954 |
||
4955 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4956 |
* Retrieves a post. |
0 | 4957 |
* |
4958 |
* @since 1.5.0 |
|
4959 |
* |
|
16 | 4960 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4961 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4962 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4963 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4964 |
* @type int $1 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4965 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4966 |
* @type string $3 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4967 |
* } |
5 | 4968 |
* @return array|IXR_Error |
0 | 4969 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4970 |
public function blogger_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4971 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4972 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4973 |
$post_id = (int) $args[1]; |
0 | 4974 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4975 |
$password = $args[3]; |
0 | 4976 |
|
16 | 4977 |
$user = $this->login( $username, $password ); |
4978 |
if ( ! $user ) { |
|
0 | 4979 |
return $this->error; |
9 | 4980 |
} |
4981 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4982 |
$post_data = get_post( $post_id, ARRAY_A ); |
9 | 4983 |
if ( ! $post_data ) { |
0 | 4984 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 4985 |
} |
4986 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4987 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4988 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 4989 |
} |
0 | 4990 |
|
5 | 4991 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 4992 |
do_action( 'xmlrpc_call', 'blogger.getPost', $args, $this ); |
0 | 4993 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4994 |
$categories = implode( ',', wp_get_post_categories( $post_id ) ); |
9 | 4995 |
|
4996 |
$content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
|
4997 |
$content .= '<category>' . $categories . '</category>'; |
|
4998 |
$content .= wp_unslash( $post_data['post_content'] ); |
|
0 | 4999 |
|
5000 |
$struct = array( |
|
9 | 5001 |
'userid' => $post_data['post_author'], |
0 | 5002 |
'dateCreated' => $this->_convert_date( $post_data['post_date'] ), |
5003 |
'content' => $content, |
|
9 | 5004 |
'postid' => (string) $post_data['ID'], |
0 | 5005 |
); |
5006 |
||
5007 |
return $struct; |
|
5008 |
} |
|
5009 |
||
5010 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5011 |
* Retrieves the list of recent posts. |
0 | 5012 |
* |
5013 |
* @since 1.5.0 |
|
5014 |
* |
|
16 | 5015 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5016 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5017 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5018 |
* @type string $0 App key (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5019 |
* @type int $1 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5020 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5021 |
* @type string $3 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5022 |
* @type int $4 Optional. Number of posts. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5023 |
* } |
5 | 5024 |
* @return array|IXR_Error |
0 | 5025 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5026 |
public function blogger_getRecentPosts( $args ) { |
0 | 5027 |
|
9 | 5028 |
$this->escape( $args ); |
0 | 5029 |
|
16 | 5030 |
// $args[0] = appkey - ignored. |
0 | 5031 |
$username = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5032 |
$password = $args[3]; |
9 | 5033 |
if ( isset( $args[4] ) ) { |
0 | 5034 |
$query = array( 'numberposts' => absint( $args[4] ) ); |
9 | 5035 |
} else { |
0 | 5036 |
$query = array(); |
9 | 5037 |
} |
5038 |
||
16 | 5039 |
$user = $this->login( $username, $password ); |
5040 |
if ( ! $user ) { |
|
0 | 5041 |
return $this->error; |
9 | 5042 |
} |
5043 |
||
5044 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5045 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 5046 |
} |
0 | 5047 |
|
5 | 5048 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5049 |
do_action( 'xmlrpc_call', 'blogger.getRecentPosts', $args, $this ); |
0 | 5050 |
|
5051 |
$posts_list = wp_get_recent_posts( $query ); |
|
5052 |
||
9 | 5053 |
if ( ! $posts_list ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5054 |
$this->error = new IXR_Error( 500, __( 'No posts found or an error occurred while retrieving posts.' ) ); |
0 | 5055 |
return $this->error; |
5056 |
} |
|
5057 |
||
5 | 5058 |
$recent_posts = array(); |
9 | 5059 |
foreach ( $posts_list as $entry ) { |
5060 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 5061 |
continue; |
9 | 5062 |
} |
0 | 5063 |
|
5064 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
9 | 5065 |
$categories = implode( ',', wp_get_post_categories( $entry['ID'] ) ); |
5066 |
||
5067 |
$content = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>'; |
|
5068 |
$content .= '<category>' . $categories . '</category>'; |
|
5069 |
$content .= wp_unslash( $entry['post_content'] ); |
|
0 | 5070 |
|
5 | 5071 |
$recent_posts[] = array( |
9 | 5072 |
'userid' => $entry['post_author'], |
0 | 5073 |
'dateCreated' => $post_date, |
9 | 5074 |
'content' => $content, |
5075 |
'postid' => (string) $entry['ID'], |
|
0 | 5076 |
); |
5077 |
} |
|
5078 |
||
5079 |
return $recent_posts; |
|
5080 |
} |
|
5081 |
||
5082 |
/** |
|
5083 |
* Deprecated. |
|
5084 |
* |
|
5085 |
* @since 1.5.0 |
|
5086 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5087 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5088 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5089 |
* @return IXR_Error Error object. |
0 | 5090 |
*/ |
9 | 5091 |
public function blogger_getTemplate( $args ) { |
16 | 5092 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 5093 |
} |
5094 |
||
5095 |
/** |
|
5096 |
* Deprecated. |
|
5097 |
* |
|
5098 |
* @since 1.5.0 |
|
5099 |
* @deprecated 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5101 |
* @param array $args Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5102 |
* @return IXR_Error Error object. |
0 | 5103 |
*/ |
9 | 5104 |
public function blogger_setTemplate( $args ) { |
16 | 5105 |
return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) ); |
0 | 5106 |
} |
5107 |
||
5108 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5109 |
* Creates a new post. |
0 | 5110 |
* |
5111 |
* @since 1.5.0 |
|
5112 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5113 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5114 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5115 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5116 |
* @type string $0 App key (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5117 |
* @type int $1 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5118 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5119 |
* @type string $3 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5120 |
* @type string $4 Content. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5121 |
* @type int $5 Publish flag. 0 for draft, 1 for publish. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5122 |
* } |
5 | 5123 |
* @return int|IXR_Error |
0 | 5124 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5125 |
public function blogger_newPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5126 |
$this->escape( $args ); |
0 | 5127 |
|
5128 |
$username = $args[2]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5129 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5130 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5131 |
$publish = $args[5]; |
0 | 5132 |
|
16 | 5133 |
$user = $this->login( $username, $password ); |
5134 |
if ( ! $user ) { |
|
0 | 5135 |
return $this->error; |
9 | 5136 |
} |
0 | 5137 |
|
5 | 5138 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5139 |
do_action( 'xmlrpc_call', 'blogger.newPost', $args, $this ); |
0 | 5140 |
|
9 | 5141 |
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
5142 |
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
|
5143 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
|
5144 |
} |
|
5145 |
||
5146 |
$post_status = ( $publish ) ? 'publish' : 'draft'; |
|
0 | 5147 |
|
5148 |
$post_author = $user->ID; |
|
5149 |
||
9 | 5150 |
$post_title = xmlrpc_getposttitle( $content ); |
5151 |
$post_category = xmlrpc_getpostcategory( $content ); |
|
5152 |
$post_content = xmlrpc_removepostdata( $content ); |
|
5153 |
||
5154 |
$post_date = current_time( 'mysql' ); |
|
5155 |
$post_date_gmt = current_time( 'mysql', 1 ); |
|
5156 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5157 |
$post_data = compact( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5158 |
'post_author', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5159 |
'post_date', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5160 |
'post_date_gmt', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5161 |
'post_content', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5162 |
'post_title', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5163 |
'post_category', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5164 |
'post_status' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5165 |
); |
9 | 5166 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5167 |
$post_id = wp_insert_post( $post_data ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5168 |
if ( is_wp_error( $post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5169 |
return new IXR_Error( 500, $post_id->get_error_message() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5170 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5171 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5172 |
if ( ! $post_id ) { |
16 | 5173 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5174 |
} |
0 | 5175 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5176 |
$this->attach_uploads( $post_id, $post_content ); |
0 | 5177 |
|
5 | 5178 |
/** |
5179 |
* Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
5180 |
* |
|
5181 |
* @since 3.4.0 |
|
5182 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5183 |
* @param int $post_id ID of the new post. |
5 | 5184 |
* @param array $args An array of new post arguments. |
5185 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5186 |
do_action( 'xmlrpc_call_success_blogger_newPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5187 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5188 |
return $post_id; |
0 | 5189 |
} |
5190 |
||
5191 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5192 |
* Edits a post. |
0 | 5193 |
* |
5194 |
* @since 1.5.0 |
|
5195 |
* |
|
16 | 5196 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5197 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5198 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5199 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5200 |
* @type int $1 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5201 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5202 |
* @type string $3 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5203 |
* @type string $4 Content |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5204 |
* @type int $5 Publish flag. 0 for draft, 1 for publish. |
7
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 |
* @return true|IXR_Error true when done. |
0 | 5207 |
*/ |
5 | 5208 |
public function blogger_editPost( $args ) { |
0 | 5209 |
|
9 | 5210 |
$this->escape( $args ); |
0 | 5211 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5212 |
$post_id = (int) $args[1]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5213 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5214 |
$password = $args[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5215 |
$content = $args[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5216 |
$publish = $args[5]; |
5 | 5217 |
|
16 | 5218 |
$user = $this->login( $username, $password ); |
5219 |
if ( ! $user ) { |
|
0 | 5220 |
return $this->error; |
5 | 5221 |
} |
5222 |
||
5223 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
18 | 5224 |
do_action( 'xmlrpc_call', 'blogger.editPost', $args, $this ); |
5 | 5225 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5226 |
$actual_post = get_post( $post_id, ARRAY_A ); |
5 | 5227 |
|
16 | 5228 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5 | 5229 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5230 |
} |
|
0 | 5231 |
|
9 | 5232 |
$this->escape( $actual_post ); |
0 | 5233 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5234 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 5235 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5 | 5236 |
} |
16 | 5237 |
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
|
5238 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5239 |
} |
5240 |
||
9 | 5241 |
$postdata = array(); |
5242 |
$postdata['ID'] = $actual_post['ID']; |
|
5243 |
$postdata['post_content'] = xmlrpc_removepostdata( $content ); |
|
5244 |
$postdata['post_title'] = xmlrpc_getposttitle( $content ); |
|
5 | 5245 |
$postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
9 | 5246 |
$postdata['post_status'] = $actual_post['post_status']; |
5247 |
$postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
5248 |
$postdata['post_status'] = $publish ? 'publish' : 'draft'; |
|
5 | 5249 |
|
5250 |
$result = wp_update_post( $postdata ); |
|
5251 |
||
5252 |
if ( ! $result ) { |
|
16 | 5253 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
5 | 5254 |
} |
5255 |
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
|
5256 |
||
5257 |
/** |
|
5258 |
* Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
5259 |
* |
|
5260 |
* @since 3.4.0 |
|
5261 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5262 |
* @param int $post_id ID of the updated post. |
5 | 5263 |
* @param array $args An array of arguments for the post to edit. |
5264 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5265 |
do_action( 'xmlrpc_call_success_blogger_editPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5266 |
|
5267 |
return true; |
|
5268 |
} |
|
5269 |
||
5270 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5271 |
* Deletes a post. |
0 | 5272 |
* |
5273 |
* @since 1.5.0 |
|
5274 |
* |
|
16 | 5275 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5276 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5277 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5278 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5279 |
* @type int $1 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5280 |
* @type string $2 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5281 |
* @type string $3 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5282 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5283 |
* @return true|IXR_Error True when post is deleted. |
0 | 5284 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5285 |
public function blogger_deletePost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5286 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5287 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5288 |
$post_id = (int) $args[1]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5289 |
$username = $args[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5290 |
$password = $args[3]; |
0 | 5291 |
|
16 | 5292 |
$user = $this->login( $username, $password ); |
5293 |
if ( ! $user ) { |
|
0 | 5294 |
return $this->error; |
9 | 5295 |
} |
0 | 5296 |
|
5 | 5297 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5298 |
do_action( 'xmlrpc_call', 'blogger.deletePost', $args, $this ); |
0 | 5299 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5300 |
$actual_post = get_post( $post_id, ARRAY_A ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5301 |
|
16 | 5302 |
if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5303 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5304 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5305 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5306 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5307 |
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
|
5308 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5309 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5310 |
$result = wp_delete_post( $post_id ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5311 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5312 |
if ( ! $result ) { |
16 | 5313 |
return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5314 |
} |
0 | 5315 |
|
5 | 5316 |
/** |
5317 |
* Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
|
5318 |
* |
|
5319 |
* @since 3.4.0 |
|
5320 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5321 |
* @param int $post_id ID of the deleted post. |
5 | 5322 |
* @param array $args An array of arguments to delete the post. |
5323 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5324 |
do_action( 'xmlrpc_call_success_blogger_deletePost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 5325 |
|
5326 |
return true; |
|
5327 |
} |
|
5328 |
||
16 | 5329 |
/* |
5330 |
* MetaWeblog API functions. |
|
5331 |
* Specs on wherever Dave Winer wants them to be. |
|
0 | 5332 |
*/ |
5333 |
||
5334 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5335 |
* Creates a new post. |
0 | 5336 |
* |
5337 |
* The 'content_struct' argument must contain: |
|
5338 |
* - title |
|
5339 |
* - description |
|
5340 |
* - mt_excerpt |
|
5341 |
* - mt_text_more |
|
5342 |
* - mt_keywords |
|
5343 |
* - mt_tb_ping_urls |
|
5344 |
* - categories |
|
5345 |
* |
|
5346 |
* Also, it can optionally contain: |
|
5347 |
* - wp_slug |
|
5348 |
* - wp_password |
|
5349 |
* - wp_page_parent_id |
|
5350 |
* - wp_page_order |
|
5351 |
* - wp_author_id |
|
5352 |
* - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' |
|
5353 |
* - mt_allow_comments - can be 'open' or 'closed' |
|
5354 |
* - mt_allow_pings - can be 'open' or 'closed' |
|
5355 |
* - date_created_gmt |
|
5356 |
* - dateCreated |
|
5357 |
* - wp_post_thumbnail |
|
5358 |
* |
|
5359 |
* @since 1.5.0 |
|
5360 |
* |
|
16 | 5361 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5362 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5363 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5364 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5365 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5366 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5367 |
* @type array $3 Content structure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5368 |
* @type int $4 Optional. Publish flag. 0 for draft, 1 for publish. Default 0. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5369 |
* } |
5 | 5370 |
* @return int|IXR_Error |
0 | 5371 |
*/ |
9 | 5372 |
public function mw_newPost( $args ) { |
5373 |
$this->escape( $args ); |
|
0 | 5374 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5375 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5376 |
$password = $args[2]; |
0 | 5377 |
$content_struct = $args[3]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5378 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
0 | 5379 |
|
16 | 5380 |
$user = $this->login( $username, $password ); |
5381 |
if ( ! $user ) { |
|
0 | 5382 |
return $this->error; |
9 | 5383 |
} |
0 | 5384 |
|
5 | 5385 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5386 |
do_action( 'xmlrpc_call', 'metaWeblog.newPost', $args, $this ); |
0 | 5387 |
|
5388 |
$page_template = ''; |
|
9 | 5389 |
if ( ! empty( $content_struct['post_type'] ) ) { |
16 | 5390 |
if ( 'page' === $content_struct['post_type'] ) { |
9 | 5391 |
if ( $publish ) { |
5392 |
$cap = 'publish_pages'; |
|
16 | 5393 |
} elseif ( isset( $content_struct['page_status'] ) && 'publish' === $content_struct['page_status'] ) { |
9 | 5394 |
$cap = 'publish_pages'; |
5395 |
} else { |
|
0 | 5396 |
$cap = 'edit_pages'; |
9 | 5397 |
} |
0 | 5398 |
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' ); |
9 | 5399 |
$post_type = 'page'; |
5400 |
if ( ! empty( $content_struct['wp_page_template'] ) ) { |
|
0 | 5401 |
$page_template = $content_struct['wp_page_template']; |
9 | 5402 |
} |
16 | 5403 |
} elseif ( 'post' === $content_struct['post_type'] ) { |
9 | 5404 |
if ( $publish ) { |
5405 |
$cap = 'publish_posts'; |
|
16 | 5406 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5407 |
$cap = 'publish_posts'; |
5408 |
} else { |
|
0 | 5409 |
$cap = 'edit_posts'; |
9 | 5410 |
} |
0 | 5411 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5412 |
$post_type = 'post'; |
0 | 5413 |
} else { |
16 | 5414 |
// No other 'post_type' values are allowed here. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5415 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5416 |
} |
5417 |
} else { |
|
9 | 5418 |
if ( $publish ) { |
5419 |
$cap = 'publish_posts'; |
|
16 | 5420 |
} elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) { |
9 | 5421 |
$cap = 'publish_posts'; |
5422 |
} else { |
|
0 | 5423 |
$cap = 'edit_posts'; |
9 | 5424 |
} |
0 | 5425 |
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' ); |
9 | 5426 |
$post_type = 'post'; |
5427 |
} |
|
5428 |
||
5429 |
if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) { |
|
0 | 5430 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) ); |
9 | 5431 |
} |
5432 |
if ( ! current_user_can( $cap ) ) { |
|
0 | 5433 |
return new IXR_Error( 401, $error_message ); |
9 | 5434 |
} |
0 | 5435 |
|
16 | 5436 |
// Check for a valid post format if one was given. |
0 | 5437 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5438 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5439 |
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
|
5440 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5441 |
} |
5442 |
} |
|
5443 |
||
16 | 5444 |
// Let WordPress generate the 'post_name' (slug) unless |
0 | 5445 |
// one has been provided. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5446 |
$post_name = null; |
9 | 5447 |
if ( isset( $content_struct['wp_slug'] ) ) { |
0 | 5448 |
$post_name = $content_struct['wp_slug']; |
9 | 5449 |
} |
0 | 5450 |
|
5451 |
// Only use a password if one was given. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5452 |
$post_password = ''; |
9 | 5453 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5454 |
$post_password = $content_struct['wp_password']; |
9 | 5455 |
} |
0 | 5456 |
|
16 | 5457 |
// Only set a post parent if one was given. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5458 |
$post_parent = 0; |
9 | 5459 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5460 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5461 |
} |
0 | 5462 |
|
16 | 5463 |
// Only set the 'menu_order' if it was given. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5464 |
$menu_order = 0; |
9 | 5465 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5466 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5467 |
} |
0 | 5468 |
|
5469 |
$post_author = $user->ID; |
|
5470 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5471 |
// If an author ID was provided then use it instead. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5472 |
if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID !== (int) $content_struct['wp_author_id'] ) ) { |
0 | 5473 |
switch ( $post_type ) { |
9 | 5474 |
case 'post': |
5475 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5476 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
9 | 5477 |
} |
0 | 5478 |
break; |
9 | 5479 |
case 'page': |
5480 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5481 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
9 | 5482 |
} |
0 | 5483 |
break; |
5484 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5485 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
0 | 5486 |
} |
5487 |
$author = get_userdata( $content_struct['wp_author_id'] ); |
|
9 | 5488 |
if ( ! $author ) { |
0 | 5489 |
return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
9 | 5490 |
} |
0 | 5491 |
$post_author = $content_struct['wp_author_id']; |
5492 |
} |
|
5493 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5494 |
$post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5495 |
$post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : ''; |
0 | 5496 |
|
5497 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5498 |
||
9 | 5499 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5500 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5501 |
case 'draft': |
5502 |
case 'pending': |
|
5503 |
case 'private': |
|
5504 |
case 'publish': |
|
9 | 5505 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5506 |
break; |
5507 |
default: |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5508 |
// Deliberably left empty. |
0 | 5509 |
break; |
5510 |
} |
|
5511 |
} |
|
5512 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5513 |
$post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5514 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5515 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5516 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); |
9 | 5517 |
|
5518 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
|
5519 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5520 |
switch ( $content_struct['mt_allow_comments'] ) { |
5521 |
case 'closed': |
|
5522 |
$comment_status = 'closed'; |
|
5523 |
break; |
|
5524 |
case 'open': |
|
5525 |
$comment_status = 'open'; |
|
5526 |
break; |
|
5527 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5528 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5529 |
break; |
5530 |
} |
|
5531 |
} else { |
|
5532 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5533 |
case 0: |
|
5534 |
case 2: |
|
5535 |
$comment_status = 'closed'; |
|
5536 |
break; |
|
5537 |
case 1: |
|
5538 |
$comment_status = 'open'; |
|
5539 |
break; |
|
5540 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5541 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5542 |
break; |
5543 |
} |
|
5544 |
} |
|
5545 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5546 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5547 |
} |
5548 |
||
9 | 5549 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5550 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5551 |
switch ( $content_struct['mt_allow_pings'] ) { |
5552 |
case 'closed': |
|
5553 |
$ping_status = 'closed'; |
|
5554 |
break; |
|
5555 |
case 'open': |
|
5556 |
$ping_status = 'open'; |
|
5557 |
break; |
|
5558 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5559 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5560 |
break; |
5561 |
} |
|
5562 |
} else { |
|
5563 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
|
5564 |
case 0: |
|
5565 |
$ping_status = 'closed'; |
|
5566 |
break; |
|
5567 |
case 1: |
|
5568 |
$ping_status = 'open'; |
|
5569 |
break; |
|
5570 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5571 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5572 |
break; |
5573 |
} |
|
5574 |
} |
|
5575 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5576 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5577 |
} |
5578 |
||
9 | 5579 |
if ( $post_more ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5580 |
$post_content .= '<!--more-->' . $post_more; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5581 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5582 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5583 |
$to_ping = ''; |
0 | 5584 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
5585 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5586 |
if ( is_array( $to_ping ) ) { |
5587 |
$to_ping = implode( ' ', $to_ping ); |
|
5588 |
} |
|
0 | 5589 |
} |
5590 |
||
16 | 5591 |
// Do some timestamp voodoo. |
9 | 5592 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
16 | 5593 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5594 |
$date_created = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 5595 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5596 |
$date_created = $content_struct['dateCreated']->getIso(); |
9 | 5597 |
} |
5598 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5599 |
$post_date = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5600 |
$post_date_gmt = ''; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5601 |
if ( ! empty( $date_created ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5602 |
$post_date = iso8601_to_datetime( $date_created ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5603 |
$post_date_gmt = iso8601_to_datetime( $date_created, 'gmt' ); |
0 | 5604 |
} |
5605 |
||
5606 |
$post_category = array(); |
|
5607 |
if ( isset( $content_struct['categories'] ) ) { |
|
5608 |
$catnames = $content_struct['categories']; |
|
5609 |
||
9 | 5610 |
if ( is_array( $catnames ) ) { |
5611 |
foreach ( $catnames as $cat ) { |
|
5612 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5613 |
} |
5614 |
} |
|
5615 |
} |
|
5616 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5617 |
$postdata = compact( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5618 |
'post_author', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5619 |
'post_date', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5620 |
'post_date_gmt', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5621 |
'post_content', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5622 |
'post_title', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5623 |
'post_category', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5624 |
'post_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5625 |
'post_excerpt', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5626 |
'comment_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5627 |
'ping_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5628 |
'to_ping', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5629 |
'post_type', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5630 |
'post_name', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5631 |
'post_password', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5632 |
'post_parent', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5633 |
'menu_order', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5634 |
'tags_input', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5635 |
'page_template' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5636 |
); |
0 | 5637 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5638 |
$post_id = get_default_post_to_edit( $post_type, true )->ID; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5639 |
$postdata['ID'] = $post_id; |
16 | 5640 |
|
5641 |
// Only posts can be sticky. |
|
5642 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 5643 |
$data = $postdata; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5644 |
$data['sticky'] = $content_struct['sticky']; |
9 | 5645 |
$error = $this->_toggle_sticky( $data ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5646 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5647 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5648 |
} |
0 | 5649 |
} |
5650 |
||
9 | 5651 |
if ( isset( $content_struct['custom_fields'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5652 |
$this->set_custom_fields( $post_id, $content_struct['custom_fields'] ); |
9 | 5653 |
} |
5654 |
||
5655 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5656 |
if ( set_post_thumbnail( $post_id, $content_struct['wp_post_thumbnail'] ) === false ) { |
0 | 5657 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 5658 |
} |
0 | 5659 |
|
5660 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
5661 |
} |
|
5662 |
||
16 | 5663 |
// Handle enclosures. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5664 |
$enclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5665 |
$this->add_enclosure_if_new( $post_id, $enclosure ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5666 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5667 |
$this->attach_uploads( $post_id, $post_content ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5668 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5669 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5670 |
* Handle post formats if assigned, value is validated earlier |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5671 |
* in this function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5672 |
*/ |
9 | 5673 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5674 |
set_post_format( $post_id, $content_struct['wp_post_format'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5675 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5676 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5677 |
$post_id = wp_insert_post( $postdata, true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5678 |
if ( is_wp_error( $post_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5679 |
return new IXR_Error( 500, $post_id->get_error_message() ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5680 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5681 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5682 |
if ( ! $post_id ) { |
16 | 5683 |
return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); |
9 | 5684 |
} |
0 | 5685 |
|
5 | 5686 |
/** |
5687 |
* Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
5688 |
* |
|
5689 |
* @since 3.4.0 |
|
5690 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5691 |
* @param int $post_id ID of the new post. |
5 | 5692 |
* @param array $args An array of arguments to create the new post. |
5693 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5694 |
do_action( 'xmlrpc_call_success_mw_newPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5695 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5696 |
return (string) $post_id; |
0 | 5697 |
} |
5698 |
||
5 | 5699 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5700 |
* 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
|
5701 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5702 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5703 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5704 |
* @param int $post_id Post ID. |
18 | 5705 |
* @param array $enclosure Enclosure data. |
5 | 5706 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5707 |
public function add_enclosure_if_new( $post_id, $enclosure ) { |
0 | 5708 |
if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
16 | 5709 |
$encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
5710 |
$found = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5711 |
$enclosures = get_post_meta( $post_id, 'enclosure' ); |
16 | 5712 |
if ( $enclosures ) { |
0 | 5713 |
foreach ( $enclosures as $enc ) { |
5714 |
// This method used to omit the trailing new line. #23219 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5715 |
if ( rtrim( $enc, "\n" ) === rtrim( $encstring, "\n" ) ) { |
0 | 5716 |
$found = true; |
5717 |
break; |
|
5718 |
} |
|
5719 |
} |
|
5720 |
} |
|
9 | 5721 |
if ( ! $found ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5722 |
add_post_meta( $post_id, 'enclosure', $encstring ); |
9 | 5723 |
} |
0 | 5724 |
} |
5725 |
} |
|
5726 |
||
5727 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5728 |
* Attaches an upload to a post. |
0 | 5729 |
* |
5730 |
* @since 2.1.0 |
|
5731 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5732 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5733 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5734 |
* @param int $post_id Post ID. |
0 | 5735 |
* @param string $post_content Post Content for attachment. |
5736 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5737 |
public function attach_uploads( $post_id, $post_content ) { |
0 | 5738 |
global $wpdb; |
5739 |
||
16 | 5740 |
// Find any unattached files. |
0 | 5741 |
$attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); |
5742 |
if ( is_array( $attachments ) ) { |
|
5743 |
foreach ( $attachments as $file ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5744 |
if ( ! empty( $file->guid ) && str_contains( $post_content, $file->guid ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5745 |
$wpdb->update( $wpdb->posts, array( 'post_parent' => $post_id ), array( 'ID' => $file->ID ) ); |
9 | 5746 |
} |
0 | 5747 |
} |
5748 |
} |
|
5749 |
} |
|
5750 |
||
5751 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5752 |
* Edits a post. |
0 | 5753 |
* |
5754 |
* @since 1.5.0 |
|
5755 |
* |
|
16 | 5756 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5757 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5758 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5759 |
* @type int $0 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5760 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5761 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5762 |
* @type array $3 Content structure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5763 |
* @type int $4 Optional. Publish flag. 0 for draft, 1 for publish. Default 0. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5764 |
* } |
18 | 5765 |
* @return true|IXR_Error True on success. |
0 | 5766 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5767 |
public function mw_editPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5768 |
$this->escape( $args ); |
0 | 5769 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5770 |
$post_id = (int) $args[0]; |
0 | 5771 |
$username = $args[1]; |
5772 |
$password = $args[2]; |
|
5773 |
$content_struct = $args[3]; |
|
5774 |
$publish = isset( $args[4] ) ? $args[4] : 0; |
|
5775 |
||
16 | 5776 |
$user = $this->login( $username, $password ); |
5777 |
if ( ! $user ) { |
|
0 | 5778 |
return $this->error; |
9 | 5779 |
} |
0 | 5780 |
|
5 | 5781 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 5782 |
do_action( 'xmlrpc_call', 'metaWeblog.editPost', $args, $this ); |
0 | 5783 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5784 |
$postdata = get_post( $post_id, ARRAY_A ); |
0 | 5785 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5786 |
/* |
16 | 5787 |
* If there is no post data for the give post ID, stop now and return an error. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5788 |
* 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
|
5789 |
*/ |
9 | 5790 |
if ( ! $postdata || empty( $postdata['ID'] ) ) { |
0 | 5791 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 5792 |
} |
5793 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5794 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5795 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 5796 |
} |
0 | 5797 |
|
5798 |
// Use wp.editPost to edit post types other than post and page. |
|
16 | 5799 |
if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5800 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
9 | 5801 |
} |
0 | 5802 |
|
5803 |
// Thwart attempt to change the post type. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5804 |
if ( ! empty( $content_struct['post_type'] ) && ( $content_struct['post_type'] !== $postdata['post_type'] ) ) { |
0 | 5805 |
return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
9 | 5806 |
} |
0 | 5807 |
|
16 | 5808 |
// Check for a valid post format if one was given. |
0 | 5809 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
5810 |
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
|
9 | 5811 |
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
|
5812 |
return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
0 | 5813 |
} |
5814 |
} |
|
5815 |
||
9 | 5816 |
$this->escape( $postdata ); |
5817 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5818 |
$post_id = $postdata['ID']; |
9 | 5819 |
$post_content = $postdata['post_content']; |
5820 |
$post_title = $postdata['post_title']; |
|
5821 |
$post_excerpt = $postdata['post_excerpt']; |
|
5822 |
$post_password = $postdata['post_password']; |
|
5823 |
$post_parent = $postdata['post_parent']; |
|
5824 |
$post_type = $postdata['post_type']; |
|
5825 |
$menu_order = $postdata['menu_order']; |
|
5826 |
$ping_status = $postdata['ping_status']; |
|
5827 |
$comment_status = $postdata['comment_status']; |
|
0 | 5828 |
|
5829 |
// Let WordPress manage slug if none was provided. |
|
5830 |
$post_name = $postdata['post_name']; |
|
9 | 5831 |
if ( isset( $content_struct['wp_slug'] ) ) { |
0 | 5832 |
$post_name = $content_struct['wp_slug']; |
9 | 5833 |
} |
0 | 5834 |
|
5835 |
// Only use a password if one was given. |
|
9 | 5836 |
if ( isset( $content_struct['wp_password'] ) ) { |
0 | 5837 |
$post_password = $content_struct['wp_password']; |
9 | 5838 |
} |
0 | 5839 |
|
5840 |
// Only set a post parent if one was given. |
|
9 | 5841 |
if ( isset( $content_struct['wp_page_parent_id'] ) ) { |
0 | 5842 |
$post_parent = $content_struct['wp_page_parent_id']; |
9 | 5843 |
} |
0 | 5844 |
|
16 | 5845 |
// Only set the 'menu_order' if it was given. |
9 | 5846 |
if ( isset( $content_struct['wp_page_order'] ) ) { |
0 | 5847 |
$menu_order = $content_struct['wp_page_order']; |
9 | 5848 |
} |
0 | 5849 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5850 |
$page_template = ''; |
16 | 5851 |
if ( ! empty( $content_struct['wp_page_template'] ) && 'page' === $post_type ) { |
0 | 5852 |
$page_template = $content_struct['wp_page_template']; |
9 | 5853 |
} |
0 | 5854 |
|
5855 |
$post_author = $postdata['post_author']; |
|
5856 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5857 |
// If an author ID was provided then use it instead. |
5 | 5858 |
if ( isset( $content_struct['wp_author_id'] ) ) { |
5859 |
// Check permissions if attempting to switch author to or from another user. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
5860 |
if ( $user->ID !== (int) $content_struct['wp_author_id'] || $user->ID !== (int) $post_author ) { |
5 | 5861 |
switch ( $post_type ) { |
5862 |
case 'post': |
|
5863 |
if ( ! current_user_can( 'edit_others_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5864 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the post author as this user.' ) ); |
5 | 5865 |
} |
5866 |
break; |
|
5867 |
case 'page': |
|
5868 |
if ( ! current_user_can( 'edit_others_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5869 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to change the page author as this user.' ) ); |
5 | 5870 |
} |
5871 |
break; |
|
5872 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5873 |
return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
5 | 5874 |
} |
5875 |
$post_author = $content_struct['wp_author_id']; |
|
0 | 5876 |
} |
5877 |
} |
|
5878 |
||
9 | 5879 |
if ( isset( $content_struct['mt_allow_comments'] ) ) { |
5880 |
if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { |
|
0 | 5881 |
switch ( $content_struct['mt_allow_comments'] ) { |
5882 |
case 'closed': |
|
5883 |
$comment_status = 'closed'; |
|
5884 |
break; |
|
5885 |
case 'open': |
|
5886 |
$comment_status = 'open'; |
|
5887 |
break; |
|
5888 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5889 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5890 |
break; |
5891 |
} |
|
5892 |
} else { |
|
5893 |
switch ( (int) $content_struct['mt_allow_comments'] ) { |
|
5894 |
case 0: |
|
5895 |
case 2: |
|
5896 |
$comment_status = 'closed'; |
|
5897 |
break; |
|
5898 |
case 1: |
|
5899 |
$comment_status = 'open'; |
|
5900 |
break; |
|
5901 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5902 |
$comment_status = get_default_comment_status( $post_type ); |
0 | 5903 |
break; |
5904 |
} |
|
5905 |
} |
|
5906 |
} |
|
5907 |
||
9 | 5908 |
if ( isset( $content_struct['mt_allow_pings'] ) ) { |
5909 |
if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) { |
|
0 | 5910 |
switch ( $content_struct['mt_allow_pings'] ) { |
5911 |
case 'closed': |
|
5912 |
$ping_status = 'closed'; |
|
5913 |
break; |
|
5914 |
case 'open': |
|
5915 |
$ping_status = 'open'; |
|
5916 |
break; |
|
5917 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5918 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5919 |
break; |
5920 |
} |
|
5921 |
} else { |
|
9 | 5922 |
switch ( (int) $content_struct['mt_allow_pings'] ) { |
0 | 5923 |
case 0: |
5924 |
$ping_status = 'closed'; |
|
5925 |
break; |
|
5926 |
case 1: |
|
5927 |
$ping_status = 'open'; |
|
5928 |
break; |
|
5929 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5930 |
$ping_status = get_default_comment_status( $post_type, 'pingback' ); |
0 | 5931 |
break; |
5932 |
} |
|
5933 |
} |
|
5934 |
} |
|
5935 |
||
9 | 5936 |
if ( isset( $content_struct['title'] ) ) { |
5937 |
$post_title = $content_struct['title']; |
|
5938 |
} |
|
5939 |
||
5940 |
if ( isset( $content_struct['description'] ) ) { |
|
0 | 5941 |
$post_content = $content_struct['description']; |
9 | 5942 |
} |
0 | 5943 |
|
5944 |
$post_category = array(); |
|
5945 |
if ( isset( $content_struct['categories'] ) ) { |
|
5946 |
$catnames = $content_struct['categories']; |
|
9 | 5947 |
if ( is_array( $catnames ) ) { |
5948 |
foreach ( $catnames as $cat ) { |
|
5949 |
$post_category[] = get_cat_ID( $cat ); |
|
0 | 5950 |
} |
5951 |
} |
|
5952 |
} |
|
5953 |
||
9 | 5954 |
if ( isset( $content_struct['mt_excerpt'] ) ) { |
5955 |
$post_excerpt = $content_struct['mt_excerpt']; |
|
5956 |
} |
|
0 | 5957 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5958 |
$post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; |
0 | 5959 |
|
5960 |
$post_status = $publish ? 'publish' : 'draft'; |
|
9 | 5961 |
if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { |
5962 |
switch ( $content_struct[ "{$post_type}_status" ] ) { |
|
0 | 5963 |
case 'draft': |
5964 |
case 'pending': |
|
5965 |
case 'private': |
|
5966 |
case 'publish': |
|
9 | 5967 |
$post_status = $content_struct[ "{$post_type}_status" ]; |
0 | 5968 |
break; |
5969 |
default: |
|
5970 |
$post_status = $publish ? 'publish' : 'draft'; |
|
5971 |
break; |
|
5972 |
} |
|
5973 |
} |
|
5974 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5975 |
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); |
0 | 5976 |
|
16 | 5977 |
if ( 'publish' === $post_status || 'private' === $post_status ) { |
5978 |
if ( 'page' === $post_type && ! current_user_can( 'publish_pages' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5979 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) ); |
5 | 5980 |
} elseif ( ! current_user_can( 'publish_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5981 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
5 | 5982 |
} |
0 | 5983 |
} |
5984 |
||
9 | 5985 |
if ( $post_more ) { |
5986 |
$post_content = $post_content . '<!--more-->' . $post_more; |
|
5987 |
} |
|
0 | 5988 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5989 |
$to_ping = ''; |
0 | 5990 |
if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { |
5991 |
$to_ping = $content_struct['mt_tb_ping_urls']; |
|
9 | 5992 |
if ( is_array( $to_ping ) ) { |
5993 |
$to_ping = implode( ' ', $to_ping ); |
|
5994 |
} |
|
0 | 5995 |
} |
5996 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5997 |
// Do some timestamp voodoo. |
9 | 5998 |
if ( ! empty( $content_struct['date_created_gmt'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5999 |
// We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6000 |
$date_created = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
9 | 6001 |
} elseif ( ! empty( $content_struct['dateCreated'] ) ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6002 |
$date_created = $content_struct['dateCreated']->getIso(); |
9 | 6003 |
} |
0 | 6004 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6005 |
// 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
|
6006 |
$edit_date = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6007 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6008 |
if ( ! empty( $date_created ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6009 |
$post_date = iso8601_to_datetime( $date_created ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6010 |
$post_date_gmt = iso8601_to_datetime( $date_created, 'gmt' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6011 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6012 |
// Flag the post date to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6013 |
$edit_date = true; |
0 | 6014 |
} else { |
6015 |
$post_date = $postdata['post_date']; |
|
6016 |
$post_date_gmt = $postdata['post_date_gmt']; |
|
6017 |
} |
|
6018 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6019 |
$newpost = array( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6020 |
'ID' => $post_id, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6021 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6022 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6023 |
$newpost += compact( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6024 |
'post_content', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6025 |
'post_title', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6026 |
'post_category', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6027 |
'post_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6028 |
'post_excerpt', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6029 |
'comment_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6030 |
'ping_status', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6031 |
'edit_date', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6032 |
'post_date', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6033 |
'post_date_gmt', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6034 |
'to_ping', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6035 |
'post_name', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6036 |
'post_password', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6037 |
'post_parent', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6038 |
'menu_order', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6039 |
'post_author', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6040 |
'tags_input', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6041 |
'page_template' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6042 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6043 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6044 |
// We've got all the data -- post it. |
9 | 6045 |
$result = wp_update_post( $newpost, true ); |
6046 |
if ( is_wp_error( $result ) ) { |
|
6047 |
return new IXR_Error( 500, $result->get_error_message() ); |
|
6048 |
} |
|
6049 |
||
6050 |
if ( ! $result ) { |
|
16 | 6051 |
return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) ); |
6052 |
} |
|
6053 |
||
6054 |
// Only posts can be sticky. |
|
6055 |
if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { |
|
9 | 6056 |
$data = $newpost; |
6057 |
$data['sticky'] = $content_struct['sticky']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6058 |
$data['post_type'] = 'post'; |
9 | 6059 |
$error = $this->_toggle_sticky( $data, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6060 |
if ( $error ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6061 |
return $error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6062 |
} |
0 | 6063 |
} |
6064 |
||
9 | 6065 |
if ( isset( $content_struct['custom_fields'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6066 |
$this->set_custom_fields( $post_id, $content_struct['custom_fields'] ); |
9 | 6067 |
} |
6068 |
||
6069 |
if ( isset( $content_struct['wp_post_thumbnail'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6070 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6071 |
// Empty value deletes, non-empty value adds/updates. |
0 | 6072 |
if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6073 |
delete_post_thumbnail( $post_id ); |
0 | 6074 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6075 |
if ( set_post_thumbnail( $post_id, $content_struct['wp_post_thumbnail'] ) === false ) { |
0 | 6076 |
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
9 | 6077 |
} |
0 | 6078 |
} |
6079 |
unset( $content_struct['wp_post_thumbnail'] ); |
|
6080 |
} |
|
6081 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6082 |
// Handle enclosures. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6083 |
$enclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6084 |
$this->add_enclosure_if_new( $post_id, $enclosure ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6085 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6086 |
$this->attach_uploads( $post_id, $post_content ); |
0 | 6087 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6088 |
// Handle post formats if assigned, validation is handled earlier in this function. |
9 | 6089 |
if ( isset( $content_struct['wp_post_format'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6090 |
set_post_format( $post_id, $content_struct['wp_post_format'] ); |
9 | 6091 |
} |
0 | 6092 |
|
5 | 6093 |
/** |
6094 |
* Fires after a post has been successfully updated via the XML-RPC MovableType API. |
|
6095 |
* |
|
6096 |
* @since 3.4.0 |
|
6097 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6098 |
* @param int $post_id ID of the updated post. |
5 | 6099 |
* @param array $args An array of arguments to update the post. |
6100 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6101 |
do_action( 'xmlrpc_call_success_mw_editPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
0 | 6102 |
|
6103 |
return true; |
|
6104 |
} |
|
6105 |
||
6106 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6107 |
* Retrieves a post. |
0 | 6108 |
* |
6109 |
* @since 1.5.0 |
|
6110 |
* |
|
16 | 6111 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6112 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6113 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6114 |
* @type int $0 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6115 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6116 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6117 |
* } |
5 | 6118 |
* @return array|IXR_Error |
0 | 6119 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6120 |
public function mw_getPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6121 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6122 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6123 |
$post_id = (int) $args[0]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6124 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6125 |
$password = $args[2]; |
0 | 6126 |
|
16 | 6127 |
$user = $this->login( $username, $password ); |
6128 |
if ( ! $user ) { |
|
0 | 6129 |
return $this->error; |
9 | 6130 |
} |
6131 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6132 |
$postdata = get_post( $post_id, ARRAY_A ); |
9 | 6133 |
if ( ! $postdata ) { |
0 | 6134 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6135 |
} |
6136 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6137 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6138 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6139 |
} |
0 | 6140 |
|
5 | 6141 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6142 |
do_action( 'xmlrpc_call', 'metaWeblog.getPost', $args, $this ); |
0 | 6143 |
|
16 | 6144 |
if ( '' !== $postdata['post_date'] ) { |
9 | 6145 |
$post_date = $this->_convert_date( $postdata['post_date'] ); |
6146 |
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
|
6147 |
$post_modified = $this->_convert_date( $postdata['post_modified'] ); |
|
0 | 6148 |
$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); |
6149 |
||
6150 |
$categories = array(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6151 |
$cat_ids = wp_get_post_categories( $post_id ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6152 |
foreach ( $cat_ids as $cat_id ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6153 |
$categories[] = get_cat_name( $cat_id ); |
9 | 6154 |
} |
0 | 6155 |
|
6156 |
$tagnames = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6157 |
$tags = wp_get_post_tags( $post_id ); |
9 | 6158 |
if ( ! empty( $tags ) ) { |
6159 |
foreach ( $tags as $tag ) { |
|
0 | 6160 |
$tagnames[] = $tag->name; |
9 | 6161 |
} |
0 | 6162 |
$tagnames = implode( ', ', $tagnames ); |
6163 |
} else { |
|
6164 |
$tagnames = ''; |
|
6165 |
} |
|
6166 |
||
9 | 6167 |
$post = get_extended( $postdata['post_content'] ); |
6168 |
$link = get_permalink( $postdata['ID'] ); |
|
0 | 6169 |
|
6170 |
// Get the author info. |
|
9 | 6171 |
$author = get_userdata( $postdata['post_author'] ); |
6172 |
||
16 | 6173 |
$allow_comments = ( 'open' === $postdata['comment_status'] ) ? 1 : 0; |
6174 |
$allow_pings = ( 'open' === $postdata['ping_status'] ) ? 1 : 0; |
|
6175 |
||
6176 |
// Consider future posts as published. |
|
6177 |
if ( 'future' === $postdata['post_status'] ) { |
|
0 | 6178 |
$postdata['post_status'] = 'publish'; |
9 | 6179 |
} |
0 | 6180 |
|
16 | 6181 |
// Get post format. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6182 |
$post_format = get_post_format( $post_id ); |
9 | 6183 |
if ( empty( $post_format ) ) { |
0 | 6184 |
$post_format = 'standard'; |
9 | 6185 |
} |
0 | 6186 |
|
6187 |
$sticky = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6188 |
if ( is_sticky( $post_id ) ) { |
0 | 6189 |
$sticky = true; |
9 | 6190 |
} |
0 | 6191 |
|
6192 |
$enclosure = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6193 |
foreach ( (array) get_post_custom( $post_id ) as $key => $val ) { |
16 | 6194 |
if ( 'enclosure' === $key ) { |
0 | 6195 |
foreach ( (array) $val as $enc ) { |
9 | 6196 |
$encdata = explode( "\n", $enc ); |
6197 |
$enclosure['url'] = trim( htmlspecialchars( $encdata[0] ) ); |
|
6198 |
$enclosure['length'] = (int) trim( $encdata[1] ); |
|
6199 |
$enclosure['type'] = trim( $encdata[2] ); |
|
0 | 6200 |
break 2; |
6201 |
} |
|
6202 |
} |
|
6203 |
} |
|
6204 |
||
6205 |
$resp = array( |
|
9 | 6206 |
'dateCreated' => $post_date, |
6207 |
'userid' => $postdata['post_author'], |
|
6208 |
'postid' => $postdata['ID'], |
|
6209 |
'description' => $post['main'], |
|
6210 |
'title' => $postdata['post_title'], |
|
6211 |
'link' => $link, |
|
6212 |
'permaLink' => $link, |
|
16 | 6213 |
// Commented out because no other tool seems to use this. |
6214 |
// 'content' => $entry['post_content'], |
|
9 | 6215 |
'categories' => $categories, |
6216 |
'mt_excerpt' => $postdata['post_excerpt'], |
|
6217 |
'mt_text_more' => $post['extended'], |
|
6218 |
'wp_more_text' => $post['more_text'], |
|
6219 |
'mt_allow_comments' => $allow_comments, |
|
6220 |
'mt_allow_pings' => $allow_pings, |
|
6221 |
'mt_keywords' => $tagnames, |
|
6222 |
'wp_slug' => $postdata['post_name'], |
|
6223 |
'wp_password' => $postdata['post_password'], |
|
6224 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6225 |
'wp_author_display_name' => $author->display_name, |
9 | 6226 |
'date_created_gmt' => $post_date_gmt, |
6227 |
'post_status' => $postdata['post_status'], |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6228 |
'custom_fields' => $this->get_custom_fields( $post_id ), |
9 | 6229 |
'wp_post_format' => $post_format, |
6230 |
'sticky' => $sticky, |
|
6231 |
'date_modified' => $post_modified, |
|
6232 |
'date_modified_gmt' => $post_modified_gmt, |
|
0 | 6233 |
); |
6234 |
||
9 | 6235 |
if ( ! empty( $enclosure ) ) { |
6236 |
$resp['enclosure'] = $enclosure; |
|
6237 |
} |
|
0 | 6238 |
|
6239 |
$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] ); |
|
6240 |
||
6241 |
return $resp; |
|
6242 |
} else { |
|
9 | 6243 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
0 | 6244 |
} |
6245 |
} |
|
6246 |
||
6247 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6248 |
* Retrieves list of recent posts. |
0 | 6249 |
* |
6250 |
* @since 1.5.0 |
|
6251 |
* |
|
16 | 6252 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6253 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6254 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6255 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6256 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6257 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6258 |
* @type int $3 Optional. Number of posts. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6259 |
* } |
5 | 6260 |
* @return array|IXR_Error |
0 | 6261 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6262 |
public function mw_getRecentPosts( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6263 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6264 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6265 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6266 |
$password = $args[2]; |
9 | 6267 |
if ( isset( $args[3] ) ) { |
0 | 6268 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6269 |
} else { |
0 | 6270 |
$query = array(); |
9 | 6271 |
} |
6272 |
||
16 | 6273 |
$user = $this->login( $username, $password ); |
6274 |
if ( ! $user ) { |
|
0 | 6275 |
return $this->error; |
9 | 6276 |
} |
6277 |
||
6278 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6279 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
9 | 6280 |
} |
0 | 6281 |
|
5 | 6282 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6283 |
do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts', $args, $this ); |
0 | 6284 |
|
6285 |
$posts_list = wp_get_recent_posts( $query ); |
|
6286 |
||
9 | 6287 |
if ( ! $posts_list ) { |
0 | 6288 |
return array(); |
9 | 6289 |
} |
0 | 6290 |
|
5 | 6291 |
$recent_posts = array(); |
9 | 6292 |
foreach ( $posts_list as $entry ) { |
6293 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6294 |
continue; |
9 | 6295 |
} |
6296 |
||
6297 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
6298 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
|
6299 |
$post_modified = $this->_convert_date( $entry['post_modified'] ); |
|
0 | 6300 |
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] ); |
6301 |
||
6302 |
$categories = array(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6303 |
$cat_ids = wp_get_post_categories( $entry['ID'] ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6304 |
foreach ( $cat_ids as $cat_id ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6305 |
$categories[] = get_cat_name( $cat_id ); |
9 | 6306 |
} |
0 | 6307 |
|
6308 |
$tagnames = array(); |
|
9 | 6309 |
$tags = wp_get_post_tags( $entry['ID'] ); |
6310 |
if ( ! empty( $tags ) ) { |
|
0 | 6311 |
foreach ( $tags as $tag ) { |
6312 |
$tagnames[] = $tag->name; |
|
6313 |
} |
|
6314 |
$tagnames = implode( ', ', $tagnames ); |
|
6315 |
} else { |
|
6316 |
$tagnames = ''; |
|
6317 |
} |
|
6318 |
||
9 | 6319 |
$post = get_extended( $entry['post_content'] ); |
6320 |
$link = get_permalink( $entry['ID'] ); |
|
0 | 6321 |
|
6322 |
// Get the post author info. |
|
9 | 6323 |
$author = get_userdata( $entry['post_author'] ); |
6324 |
||
16 | 6325 |
$allow_comments = ( 'open' === $entry['comment_status'] ) ? 1 : 0; |
6326 |
$allow_pings = ( 'open' === $entry['ping_status'] ) ? 1 : 0; |
|
6327 |
||
6328 |
// Consider future posts as published. |
|
6329 |
if ( 'future' === $entry['post_status'] ) { |
|
0 | 6330 |
$entry['post_status'] = 'publish'; |
9 | 6331 |
} |
0 | 6332 |
|
16 | 6333 |
// Get post format. |
0 | 6334 |
$post_format = get_post_format( $entry['ID'] ); |
9 | 6335 |
if ( empty( $post_format ) ) { |
0 | 6336 |
$post_format = 'standard'; |
9 | 6337 |
} |
0 | 6338 |
|
5 | 6339 |
$recent_posts[] = array( |
9 | 6340 |
'dateCreated' => $post_date, |
6341 |
'userid' => $entry['post_author'], |
|
6342 |
'postid' => (string) $entry['ID'], |
|
6343 |
'description' => $post['main'], |
|
6344 |
'title' => $entry['post_title'], |
|
6345 |
'link' => $link, |
|
6346 |
'permaLink' => $link, |
|
16 | 6347 |
// Commented out because no other tool seems to use this. |
0 | 6348 |
// 'content' => $entry['post_content'], |
9 | 6349 |
'categories' => $categories, |
6350 |
'mt_excerpt' => $entry['post_excerpt'], |
|
6351 |
'mt_text_more' => $post['extended'], |
|
6352 |
'wp_more_text' => $post['more_text'], |
|
6353 |
'mt_allow_comments' => $allow_comments, |
|
6354 |
'mt_allow_pings' => $allow_pings, |
|
6355 |
'mt_keywords' => $tagnames, |
|
6356 |
'wp_slug' => $entry['post_name'], |
|
6357 |
'wp_password' => $entry['post_password'], |
|
6358 |
'wp_author_id' => (string) $author->ID, |
|
0 | 6359 |
'wp_author_display_name' => $author->display_name, |
9 | 6360 |
'date_created_gmt' => $post_date_gmt, |
6361 |
'post_status' => $entry['post_status'], |
|
6362 |
'custom_fields' => $this->get_custom_fields( $entry['ID'] ), |
|
6363 |
'wp_post_format' => $post_format, |
|
6364 |
'date_modified' => $post_modified, |
|
6365 |
'date_modified_gmt' => $post_modified_gmt, |
|
16 | 6366 |
'sticky' => ( 'post' === $entry['post_type'] && is_sticky( $entry['ID'] ) ), |
9 | 6367 |
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ), |
0 | 6368 |
); |
6369 |
} |
|
6370 |
||
6371 |
return $recent_posts; |
|
6372 |
} |
|
6373 |
||
6374 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6375 |
* Retrieves the list of categories on a given blog. |
0 | 6376 |
* |
6377 |
* @since 1.5.0 |
|
6378 |
* |
|
16 | 6379 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6380 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6381 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6382 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6383 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6384 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6385 |
* } |
5 | 6386 |
* @return array|IXR_Error |
0 | 6387 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6388 |
public function mw_getCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6389 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6391 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6392 |
$password = $args[2]; |
0 | 6393 |
|
16 | 6394 |
$user = $this->login( $username, $password ); |
6395 |
if ( ! $user ) { |
|
0 | 6396 |
return $this->error; |
9 | 6397 |
} |
6398 |
||
6399 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6400 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6401 |
} |
0 | 6402 |
|
5 | 6403 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6404 |
do_action( 'xmlrpc_call', 'metaWeblog.getCategories', $args, $this ); |
0 | 6405 |
|
6406 |
$categories_struct = array(); |
|
6407 |
||
16 | 6408 |
$cats = get_categories( array( 'get' => 'all' ) ); |
6409 |
if ( $cats ) { |
|
0 | 6410 |
foreach ( $cats as $cat ) { |
9 | 6411 |
$struct = array(); |
6412 |
$struct['categoryId'] = $cat->term_id; |
|
6413 |
$struct['parentId'] = $cat->parent; |
|
6414 |
$struct['description'] = $cat->name; |
|
0 | 6415 |
$struct['categoryDescription'] = $cat->description; |
9 | 6416 |
$struct['categoryName'] = $cat->name; |
6417 |
$struct['htmlUrl'] = esc_html( get_category_link( $cat->term_id ) ); |
|
6418 |
$struct['rssUrl'] = esc_html( get_category_feed_link( $cat->term_id, 'rss2' ) ); |
|
0 | 6419 |
|
6420 |
$categories_struct[] = $struct; |
|
6421 |
} |
|
6422 |
} |
|
6423 |
||
6424 |
return $categories_struct; |
|
6425 |
} |
|
6426 |
||
6427 |
/** |
|
6428 |
* Uploads a file, following your settings. |
|
6429 |
* |
|
6430 |
* Adapted from a patch by Johann Richard. |
|
6431 |
* |
|
6432 |
* @link http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/ |
|
6433 |
* |
|
6434 |
* @since 1.5.0 |
|
6435 |
* |
|
16 | 6436 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6437 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6438 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6439 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6440 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6441 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6442 |
* @type array $3 Data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6443 |
* } |
5 | 6444 |
* @return array|IXR_Error |
0 | 6445 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6446 |
public function mw_newMediaObject( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6447 |
$username = $this->escape( $args[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6448 |
$password = $this->escape( $args[2] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6449 |
$data = $args[3]; |
0 | 6450 |
|
6451 |
$name = sanitize_file_name( $data['name'] ); |
|
6452 |
$type = $data['type']; |
|
6453 |
$bits = $data['bits']; |
|
6454 |
||
16 | 6455 |
$user = $this->login( $username, $password ); |
6456 |
if ( ! $user ) { |
|
0 | 6457 |
return $this->error; |
9 | 6458 |
} |
0 | 6459 |
|
5 | 6460 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6461 |
do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject', $args, $this ); |
0 | 6462 |
|
9 | 6463 |
if ( ! current_user_can( 'upload_files' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6464 |
$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
|
6465 |
return $this->error; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6466 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6467 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6468 |
if ( is_multisite() && upload_is_user_over_quota( false ) ) { |
9 | 6469 |
$this->error = new IXR_Error( |
6470 |
401, |
|
6471 |
sprintf( |
|
16 | 6472 |
/* translators: %s: Allowed space allocation. */ |
9 | 6473 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
6474 |
size_format( get_space_allowed() * MB_IN_BYTES ) |
|
6475 |
) |
|
6476 |
); |
|
0 | 6477 |
return $this->error; |
6478 |
} |
|
6479 |
||
5 | 6480 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6481 |
* Filters whether to preempt the XML-RPC media upload. |
5 | 6482 |
* |
19 | 6483 |
* Returning a truthy value will effectively short-circuit the media upload, |
5 | 6484 |
* returning that value as a 500 error instead. |
6485 |
* |
|
6486 |
* @since 2.1.0 |
|
6487 |
* |
|
6488 |
* @param bool $error Whether to pre-empt the media upload. Default false. |
|
6489 |
*/ |
|
16 | 6490 |
$upload_err = apply_filters( 'pre_upload_error', false ); |
6491 |
if ( $upload_err ) { |
|
5 | 6492 |
return new IXR_Error( 500, $upload_err ); |
6493 |
} |
|
0 | 6494 |
|
9 | 6495 |
$upload = wp_upload_bits( $name, null, $bits ); |
6496 |
if ( ! empty( $upload['error'] ) ) { |
|
16 | 6497 |
/* translators: 1: File name, 2: Error message. */ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6498 |
$error_string = sprintf( __( 'Could not write file %1$s (%2$s).' ), $name, $upload['error'] ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6499 |
return new IXR_Error( 500, $error_string ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6500 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6501 |
|
16 | 6502 |
// Construct the attachment array. |
0 | 6503 |
$post_id = 0; |
6504 |
if ( ! empty( $data['post_id'] ) ) { |
|
6505 |
$post_id = (int) $data['post_id']; |
|
6506 |
||
9 | 6507 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6508 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6509 |
} |
0 | 6510 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6511 |
|
0 | 6512 |
$attachment = array( |
9 | 6513 |
'post_title' => $name, |
6514 |
'post_content' => '', |
|
6515 |
'post_type' => 'attachment', |
|
6516 |
'post_parent' => $post_id, |
|
0 | 6517 |
'post_mime_type' => $type, |
9 | 6518 |
'guid' => $upload['url'], |
0 | 6519 |
); |
6520 |
||
16 | 6521 |
// Save the data. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6522 |
$attachment_id = wp_insert_attachment( $attachment, $upload['file'], $post_id ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6523 |
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $upload['file'] ) ); |
0 | 6524 |
|
5 | 6525 |
/** |
6526 |
* Fires after a new attachment has been added via the XML-RPC MovableType API. |
|
6527 |
* |
|
6528 |
* @since 3.4.0 |
|
6529 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6530 |
* @param int $attachment_id ID of the new attachment. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6531 |
* @param array $args An array of arguments to add the attachment. |
5 | 6532 |
*/ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6533 |
do_action( 'xmlrpc_call_success_mw_newMediaObject', $attachment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6534 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6535 |
$struct = $this->_prepare_media_item( get_post( $attachment_id ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6536 |
|
16 | 6537 |
// Deprecated values. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6538 |
$struct['id'] = $struct['attachment_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6539 |
$struct['file'] = $struct['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6540 |
$struct['url'] = $struct['link']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6541 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6542 |
return $struct; |
0 | 6543 |
} |
6544 |
||
16 | 6545 |
/* |
6546 |
* MovableType API functions. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6547 |
* Specs archive on http://web.archive.org/web/20050220091302/http://www.movabletype.org:80/docs/mtmanual_programmatic.html |
0 | 6548 |
*/ |
6549 |
||
6550 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6551 |
* Retrieves the post titles of recent posts. |
0 | 6552 |
* |
6553 |
* @since 1.5.0 |
|
6554 |
* |
|
16 | 6555 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6556 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6557 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6558 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6559 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6560 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6561 |
* @type int $3 Optional. Number of posts. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6562 |
* } |
5 | 6563 |
* @return array|IXR_Error |
0 | 6564 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6565 |
public function mt_getRecentPostTitles( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6566 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6568 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6569 |
$password = $args[2]; |
9 | 6570 |
if ( isset( $args[3] ) ) { |
0 | 6571 |
$query = array( 'numberposts' => absint( $args[3] ) ); |
9 | 6572 |
} else { |
0 | 6573 |
$query = array(); |
9 | 6574 |
} |
6575 |
||
16 | 6576 |
$user = $this->login( $username, $password ); |
6577 |
if ( ! $user ) { |
|
0 | 6578 |
return $this->error; |
9 | 6579 |
} |
0 | 6580 |
|
5 | 6581 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6582 |
do_action( 'xmlrpc_call', 'mt.getRecentPostTitles', $args, $this ); |
0 | 6583 |
|
6584 |
$posts_list = wp_get_recent_posts( $query ); |
|
6585 |
||
9 | 6586 |
if ( ! $posts_list ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6587 |
$this->error = new IXR_Error( 500, __( 'No posts found or an error occurred while retrieving posts.' ) ); |
0 | 6588 |
return $this->error; |
6589 |
} |
|
6590 |
||
5 | 6591 |
$recent_posts = array(); |
0 | 6592 |
|
9 | 6593 |
foreach ( $posts_list as $entry ) { |
6594 |
if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) { |
|
0 | 6595 |
continue; |
9 | 6596 |
} |
6597 |
||
6598 |
$post_date = $this->_convert_date( $entry['post_date'] ); |
|
0 | 6599 |
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
6600 |
||
5 | 6601 |
$recent_posts[] = array( |
9 | 6602 |
'dateCreated' => $post_date, |
6603 |
'userid' => $entry['post_author'], |
|
6604 |
'postid' => (string) $entry['ID'], |
|
6605 |
'title' => $entry['post_title'], |
|
6606 |
'post_status' => $entry['post_status'], |
|
6607 |
'date_created_gmt' => $post_date_gmt, |
|
0 | 6608 |
); |
6609 |
} |
|
6610 |
||
6611 |
return $recent_posts; |
|
6612 |
} |
|
6613 |
||
6614 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6615 |
* Retrieves the list of all categories on a blog. |
0 | 6616 |
* |
6617 |
* @since 1.5.0 |
|
6618 |
* |
|
16 | 6619 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6620 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6621 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6622 |
* @type int $0 Blog ID (unused). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6623 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6624 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6625 |
* } |
5 | 6626 |
* @return array|IXR_Error |
0 | 6627 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6628 |
public function mt_getCategoryList( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6629 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6630 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6631 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6632 |
$password = $args[2]; |
0 | 6633 |
|
16 | 6634 |
$user = $this->login( $username, $password ); |
6635 |
if ( ! $user ) { |
|
0 | 6636 |
return $this->error; |
9 | 6637 |
} |
6638 |
||
6639 |
if ( ! current_user_can( 'edit_posts' ) ) { |
|
0 | 6640 |
return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
9 | 6641 |
} |
0 | 6642 |
|
5 | 6643 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6644 |
do_action( 'xmlrpc_call', 'mt.getCategoryList', $args, $this ); |
0 | 6645 |
|
6646 |
$categories_struct = array(); |
|
6647 |
||
16 | 6648 |
$cats = get_categories( |
9 | 6649 |
array( |
6650 |
'hide_empty' => 0, |
|
6651 |
'hierarchical' => 0, |
|
6652 |
) |
|
16 | 6653 |
); |
6654 |
if ( $cats ) { |
|
0 | 6655 |
foreach ( $cats as $cat ) { |
9 | 6656 |
$struct = array(); |
6657 |
$struct['categoryId'] = $cat->term_id; |
|
0 | 6658 |
$struct['categoryName'] = $cat->name; |
6659 |
||
6660 |
$categories_struct[] = $struct; |
|
6661 |
} |
|
6662 |
} |
|
6663 |
||
6664 |
return $categories_struct; |
|
6665 |
} |
|
6666 |
||
6667 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6668 |
* Retrieves post categories. |
0 | 6669 |
* |
6670 |
* @since 1.5.0 |
|
6671 |
* |
|
16 | 6672 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6673 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6674 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6675 |
* @type int $0 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6676 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6677 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6678 |
* } |
5 | 6679 |
* @return array|IXR_Error |
0 | 6680 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6681 |
public function mt_getPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6682 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6683 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6684 |
$post_id = (int) $args[0]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6685 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6686 |
$password = $args[2]; |
0 | 6687 |
|
16 | 6688 |
$user = $this->login( $username, $password ); |
6689 |
if ( ! $user ) { |
|
0 | 6690 |
return $this->error; |
9 | 6691 |
} |
6692 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6693 |
if ( ! get_post( $post_id ) ) { |
0 | 6694 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6695 |
} |
6696 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6697 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6698 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
9 | 6699 |
} |
0 | 6700 |
|
5 | 6701 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6702 |
do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this ); |
0 | 6703 |
|
6704 |
$categories = array(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6705 |
$cat_ids = wp_get_post_categories( (int) $post_id ); |
16 | 6706 |
// First listed category will be the primary category. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6707 |
$is_primary = true; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6708 |
foreach ( $cat_ids as $cat_id ) { |
0 | 6709 |
$categories[] = array( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6710 |
'categoryName' => get_cat_name( $cat_id ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6711 |
'categoryId' => (string) $cat_id, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6712 |
'isPrimary' => $is_primary, |
0 | 6713 |
); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6714 |
$is_primary = false; |
0 | 6715 |
} |
6716 |
||
6717 |
return $categories; |
|
6718 |
} |
|
6719 |
||
6720 |
/** |
|
6721 |
* Sets categories for a post. |
|
6722 |
* |
|
6723 |
* @since 1.5.0 |
|
6724 |
* |
|
16 | 6725 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6726 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6727 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6728 |
* @type int $0 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6729 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6730 |
* @type string $2 Password. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6731 |
* @type array $3 Categories. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6732 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6733 |
* @return true|IXR_Error True on success. |
0 | 6734 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6735 |
public function mt_setPostCategories( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6736 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6737 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6738 |
$post_id = (int) $args[0]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6739 |
$username = $args[1]; |
0 | 6740 |
$password = $args[2]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6741 |
$categories = $args[3]; |
0 | 6742 |
|
16 | 6743 |
$user = $this->login( $username, $password ); |
6744 |
if ( ! $user ) { |
|
0 | 6745 |
return $this->error; |
9 | 6746 |
} |
0 | 6747 |
|
5 | 6748 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6749 |
do_action( 'xmlrpc_call', 'mt.setPostCategories', $args, $this ); |
0 | 6750 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6751 |
if ( ! get_post( $post_id ) ) { |
0 | 6752 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6753 |
} |
6754 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6755 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 6756 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
6757 |
} |
|
0 | 6758 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6759 |
$cat_ids = array(); |
0 | 6760 |
foreach ( $categories as $cat ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6761 |
$cat_ids[] = $cat['categoryId']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6762 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6763 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6764 |
wp_set_post_categories( $post_id, $cat_ids ); |
0 | 6765 |
|
6766 |
return true; |
|
6767 |
} |
|
6768 |
||
6769 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6770 |
* Retrieves an array of methods supported by this server. |
0 | 6771 |
* |
6772 |
* @since 1.5.0 |
|
6773 |
* |
|
6774 |
* @return array |
|
6775 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6776 |
public function mt_supportedMethods() { |
5 | 6777 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6778 |
do_action( 'xmlrpc_call', 'mt.supportedMethods', array(), $this ); |
0 | 6779 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6780 |
return array_keys( $this->methods ); |
0 | 6781 |
} |
6782 |
||
6783 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6784 |
* Retrieves an empty array because we don't support per-post text filters. |
0 | 6785 |
* |
6786 |
* @since 1.5.0 |
|
6787 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6788 |
public function mt_supportedTextFilters() { |
5 | 6789 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6790 |
do_action( 'xmlrpc_call', 'mt.supportedTextFilters', array(), $this ); |
5 | 6791 |
|
6792 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6793 |
* Filters the MoveableType text filters list for XML-RPC. |
5 | 6794 |
* |
6795 |
* @since 2.2.0 |
|
6796 |
* |
|
6797 |
* @param array $filters An array of text filters. |
|
6798 |
*/ |
|
6799 |
return apply_filters( 'xmlrpc_text_filters', array() ); |
|
0 | 6800 |
} |
6801 |
||
6802 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6803 |
* Retrieves trackbacks sent to a given post. |
0 | 6804 |
* |
6805 |
* @since 1.5.0 |
|
6806 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6807 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6808 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6809 |
* @param int $post_id |
5 | 6810 |
* @return array|IXR_Error |
0 | 6811 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6812 |
public function mt_getTrackbackPings( $post_id ) { |
0 | 6813 |
global $wpdb; |
6814 |
||
5 | 6815 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6816 |
do_action( 'xmlrpc_call', 'mt.getTrackbackPings', $post_id, $this ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6817 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6818 |
$actual_post = get_post( $post_id, ARRAY_A ); |
9 | 6819 |
|
6820 |
if ( ! $actual_post ) { |
|
6821 |
return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
6822 |
} |
|
6823 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6824 |
$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 ) ); |
9 | 6825 |
|
6826 |
if ( ! $comments ) { |
|
0 | 6827 |
return array(); |
9 | 6828 |
} |
0 | 6829 |
|
6830 |
$trackback_pings = array(); |
|
6831 |
foreach ( $comments as $comment ) { |
|
16 | 6832 |
if ( 'trackback' === $comment->comment_type ) { |
9 | 6833 |
$content = $comment->comment_content; |
6834 |
$title = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) ); |
|
0 | 6835 |
$trackback_pings[] = array( |
6836 |
'pingTitle' => $title, |
|
6837 |
'pingURL' => $comment->comment_author_url, |
|
9 | 6838 |
'pingIP' => $comment->comment_author_IP, |
0 | 6839 |
); |
6840 |
} |
|
6841 |
} |
|
6842 |
||
6843 |
return $trackback_pings; |
|
6844 |
} |
|
6845 |
||
6846 |
/** |
|
6847 |
* Sets a post's publish status to 'publish'. |
|
6848 |
* |
|
6849 |
* @since 1.5.0 |
|
6850 |
* |
|
16 | 6851 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6852 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6853 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6854 |
* @type int $0 Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6855 |
* @type string $1 Username. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6856 |
* @type string $2 Password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6857 |
* } |
5 | 6858 |
* @return int|IXR_Error |
0 | 6859 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6860 |
public function mt_publishPost( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6861 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6862 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6863 |
$post_id = (int) $args[0]; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6864 |
$username = $args[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6865 |
$password = $args[2]; |
0 | 6866 |
|
16 | 6867 |
$user = $this->login( $username, $password ); |
6868 |
if ( ! $user ) { |
|
0 | 6869 |
return $this->error; |
9 | 6870 |
} |
0 | 6871 |
|
5 | 6872 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6873 |
do_action( 'xmlrpc_call', 'mt.publishPost', $args, $this ); |
0 | 6874 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6875 |
$postdata = get_post( $post_id, ARRAY_A ); |
9 | 6876 |
if ( ! $postdata ) { |
0 | 6877 |
return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
9 | 6878 |
} |
6879 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6880 |
if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_id ) ) { |
9 | 6881 |
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
6882 |
} |
|
0 | 6883 |
|
6884 |
$postdata['post_status'] = 'publish'; |
|
6885 |
||
16 | 6886 |
// Retain old categories. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6887 |
$postdata['post_category'] = wp_get_post_categories( $post_id ); |
9 | 6888 |
$this->escape( $postdata ); |
0 | 6889 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6890 |
return wp_update_post( $postdata ); |
0 | 6891 |
} |
6892 |
||
16 | 6893 |
/* |
6894 |
* Pingback functions. |
|
6895 |
* Specs on www.hixie.ch/specs/pingback/pingback |
|
0 | 6896 |
*/ |
6897 |
||
6898 |
/** |
|
6899 |
* Retrieves a pingback and registers it. |
|
6900 |
* |
|
6901 |
* @since 1.5.0 |
|
6902 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6903 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6904 |
* |
16 | 6905 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6906 |
* Method arguments. Note: arguments must be ordered as documented. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6907 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6908 |
* @type string $0 URL of page linked from. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6909 |
* @type string $1 URL of page linked to. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6910 |
* } |
5 | 6911 |
* @return string|IXR_Error |
0 | 6912 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6913 |
public function pingback_ping( $args ) { |
0 | 6914 |
global $wpdb; |
6915 |
||
5 | 6916 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 6917 |
do_action( 'xmlrpc_call', 'pingback.ping', $args, $this ); |
0 | 6918 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6919 |
$this->escape( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6921 |
$pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
9 | 6922 |
$pagelinkedto = str_replace( '&', '&', $args[1] ); |
6923 |
$pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
|
0 | 6924 |
|
5 | 6925 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6926 |
* Filters the pingback source URI. |
5 | 6927 |
* |
6928 |
* @since 3.6.0 |
|
6929 |
* |
|
6930 |
* @param string $pagelinkedfrom URI of the page linked from. |
|
6931 |
* @param string $pagelinkedto URI of the page linked to. |
|
6932 |
*/ |
|
0 | 6933 |
$pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5 | 6934 |
|
9 | 6935 |
if ( ! $pagelinkedfrom ) { |
0 | 6936 |
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
9 | 6937 |
} |
0 | 6938 |
|
16 | 6939 |
// Check if the page linked to is on our site. |
9 | 6940 |
$pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) ); |
6941 |
if ( ! $pos1 ) { |
|
0 | 6942 |
return $this->pingback_error( 0, __( 'Is there no link to us?' ) ); |
9 | 6943 |
} |
0 | 6944 |
|
16 | 6945 |
/* |
6946 |
* Let's find which post is linked to. |
|
6947 |
* FIXME: Does url_to_postid() cover all these cases already? |
|
6948 |
* If so, then let's use it and drop the old code. |
|
6949 |
*/ |
|
9 | 6950 |
$urltest = parse_url( $pagelinkedto ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6951 |
$post_id = url_to_postid( $pagelinkedto ); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6952 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6953 |
if ( $post_id ) { |
5 | 6954 |
// $way |
9 | 6955 |
} elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) { |
16 | 6956 |
// The path defines the post_ID (archives/p/XXXX). |
9 | 6957 |
$blah = explode( '/', $match[0] ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6958 |
$post_id = (int) $blah[1]; |
9 | 6959 |
} elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) { |
16 | 6960 |
// The query string defines the post_ID (?p=XXXX). |
9 | 6961 |
$blah = explode( '=', $match[0] ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6962 |
$post_id = (int) $blah[1]; |
9 | 6963 |
} elseif ( isset( $urltest['fragment'] ) ) { |
16 | 6964 |
// An #anchor is there, it's either... |
18 | 6965 |
if ( (int) $urltest['fragment'] ) { |
16 | 6966 |
// ...an integer #XXXX (simplest case), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6967 |
$post_id = (int) $urltest['fragment']; |
9 | 6968 |
} elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
16 | 6969 |
// ...a post ID in the form 'post-###', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6970 |
$post_id = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
9 | 6971 |
} elseif ( is_string( $urltest['fragment'] ) ) { |
16 | 6972 |
// ...or a string #title, a little more complicated. |
6973 |
$title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] ); |
|
6974 |
$sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6975 |
$post_id = $wpdb->get_var( $sql ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6976 |
if ( ! $post_id ) { |
16 | 6977 |
// Returning unknown error '0' is better than die()'ing. |
9 | 6978 |
return $this->pingback_error( 0, '' ); |
0 | 6979 |
} |
6980 |
} |
|
6981 |
} else { |
|
16 | 6982 |
// TODO: Attempt to extract a post ID from the given URL. |
19 | 6983 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); |
0 | 6984 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6985 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6986 |
$post_id = (int) $post_id; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6987 |
$post = get_post( $post_id ); |
9 | 6988 |
|
16 | 6989 |
if ( ! $post ) { // Post not found. |
19 | 6990 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); |
9 | 6991 |
} |
6992 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
6993 |
if ( url_to_postid( $pagelinkedfrom ) === $post_id ) { |
0 | 6994 |
return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); |
9 | 6995 |
} |
0 | 6996 |
|
16 | 6997 |
// Check if pings are on. |
9 | 6998 |
if ( ! pings_open( $post ) ) { |
19 | 6999 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); |
9 | 7000 |
} |
0 | 7001 |
|
16 | 7002 |
// Let's check that the remote site didn't already pingback this entry. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7003 |
if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_id, $pagelinkedfrom ) ) ) { |
0 | 7004 |
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
9 | 7005 |
} |
0 | 7006 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7007 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7008 |
* The remote site may have sent the pingback before it finished publishing its own content |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7009 |
* containing this pingback URL. If that happens then it won't be immediately possible to fetch |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7010 |
* the pinging post; adding a small delay reduces the likelihood of this happening. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7011 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7012 |
* While there are more robust methods than calling `sleep()` here (because `sleep()` merely |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7013 |
* mitigates the risk of requesting the remote post before it's available), this is effective |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7014 |
* enough for most cases and avoids introducing more complexity into this code. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7015 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7016 |
* One way to improve the reliability of this code might be to add failure-handling to the remote |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7017 |
* fetch and retry up to a set number of times if it receives a 404. This could also handle 401 and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7018 |
* 403 responses to differentiate the "does not exist" failure from the "may not access" failure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7019 |
*/ |
9 | 7020 |
sleep( 1 ); |
0 | 7021 |
|
5 | 7022 |
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
7023 |
||
19 | 7024 |
/** This filter is documented in wp-includes/class-wp-http.php */ |
16 | 7025 |
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $pagelinkedfrom ); |
7026 |
||
7027 |
// Let's check the remote site. |
|
0 | 7028 |
$http_api_args = array( |
9 | 7029 |
'timeout' => 10, |
7030 |
'redirection' => 0, |
|
0 | 7031 |
'limit_response_size' => 153600, // 150 KB |
9 | 7032 |
'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
7033 |
'headers' => array( |
|
5 | 7034 |
'X-Pingback-Forwarded-For' => $remote_ip, |
7035 |
), |
|
0 | 7036 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7037 |
|
16 | 7038 |
$request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
7039 |
$remote_source = wp_remote_retrieve_body( $request ); |
|
7040 |
$remote_source_original = $remote_source; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7041 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7042 |
if ( ! $remote_source ) { |
5 | 7043 |
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
|
7044 |
} |
5 | 7045 |
|
7046 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7047 |
* Filters the pingback remote source. |
5 | 7048 |
* |
7049 |
* @since 2.5.0 |
|
7050 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7051 |
* @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
|
7052 |
* @param string $pagelinkedto URL of the page linked to. |
5 | 7053 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7054 |
$remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
0 | 7055 |
|
7056 |
// Work around bug in strip_tags(): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7057 |
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7058 |
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
9 | 7059 |
$remote_source = preg_replace( '/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/', "\n\n", $remote_source ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7060 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7061 |
preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7062 |
$title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7063 |
if ( empty( $title ) ) { |
19 | 7064 |
return $this->pingback_error( 32, __( 'A title on that page cannot be found.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7065 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7066 |
|
16 | 7067 |
// Remove all script and style tags including their content. |
7068 |
$remote_source = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $remote_source ); |
|
7069 |
// Just keep the tag we need. |
|
7070 |
$remote_source = strip_tags( $remote_source, '<a>' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7071 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7072 |
$p = explode( "\n\n", $remote_source ); |
0 | 7073 |
|
9 | 7074 |
$preg_target = preg_quote( $pagelinkedto, '|' ); |
0 | 7075 |
|
7076 |
foreach ( $p as $para ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7077 |
if ( str_contains( $para, $pagelinkedto ) ) { // It exists, but is it a link? |
9 | 7078 |
preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context ); |
0 | 7079 |
|
16 | 7080 |
// If the URL isn't in a link context, keep looking. |
9 | 7081 |
if ( empty( $context ) ) { |
0 | 7082 |
continue; |
9 | 7083 |
} |
0 | 7084 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7085 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7086 |
* We're going to use this fake tag to mark the context in a bit. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7087 |
* The marker is needed in case the link text appears more than once in the paragraph. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7088 |
*/ |
9 | 7089 |
$excerpt = preg_replace( '|\</?wpcontext\>|', '', $para ); |
0 | 7090 |
|
7091 |
// prevent really long link text |
|
9 | 7092 |
if ( strlen( $context[1] ) > 100 ) { |
7093 |
$context[1] = substr( $context[1], 0, 100 ) . '…'; |
|
7094 |
} |
|
7095 |
||
16 | 7096 |
$marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // Set up our marker. |
7097 |
$excerpt = str_replace( $context[0], $marker, $excerpt ); // Swap out the link for our marker. |
|
7098 |
$excerpt = strip_tags( $excerpt, '<wpcontext>' ); // Strip all tags but our context marker. |
|
9 | 7099 |
$excerpt = trim( $excerpt ); |
7100 |
$preg_marker = preg_quote( $marker, '|' ); |
|
7101 |
$excerpt = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt ); |
|
16 | 7102 |
$excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper. |
0 | 7103 |
break; |
7104 |
} |
|
7105 |
} |
|
7106 |
||
16 | 7107 |
if ( empty( $context ) ) { // Link to target not found. |
0 | 7108 |
return $this->pingback_error( 17, __( 'The source URL does not contain a link to the target URL, and so cannot be used as a source.' ) ); |
9 | 7109 |
} |
7110 |
||
7111 |
$pagelinkedfrom = str_replace( '&', '&', $pagelinkedfrom ); |
|
7112 |
||
7113 |
$context = '[…] ' . esc_html( $excerpt ) . ' […]'; |
|
0 | 7114 |
$pagelinkedfrom = $this->escape( $pagelinkedfrom ); |
7115 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7116 |
$comment_post_id = (int) $post_id; |
9 | 7117 |
$comment_author = $title; |
0 | 7118 |
$comment_author_email = ''; |
9 | 7119 |
$this->escape( $comment_author ); |
0 | 7120 |
$comment_author_url = $pagelinkedfrom; |
9 | 7121 |
$comment_content = $context; |
7122 |
$this->escape( $comment_content ); |
|
0 | 7123 |
$comment_type = 'pingback'; |
7124 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7125 |
$commentdata = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7126 |
'comment_post_ID' => $comment_post_id, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7127 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7128 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7129 |
$commentdata += compact( |
9 | 7130 |
'comment_author', |
7131 |
'comment_author_url', |
|
7132 |
'comment_author_email', |
|
7133 |
'comment_content', |
|
7134 |
'comment_type', |
|
7135 |
'remote_source', |
|
7136 |
'remote_source_original' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7137 |
); |
0 | 7138 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7139 |
$comment_id = wp_new_comment( $commentdata ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7140 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7141 |
if ( is_wp_error( $comment_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7142 |
return $this->pingback_error( 0, $comment_id->get_error_message() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7143 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7144 |
|
5 | 7145 |
/** |
7146 |
* Fires after a post pingback has been sent. |
|
7147 |
* |
|
7148 |
* @since 0.71 |
|
7149 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7150 |
* @param int $comment_id Comment ID. |
5 | 7151 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7152 |
do_action( 'pingback_post', $comment_id ); |
0 | 7153 |
|
16 | 7154 |
/* translators: 1: URL of the page linked from, 2: URL of the page linked to. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7155 |
return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
0 | 7156 |
} |
7157 |
||
7158 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7159 |
* Retrieves an array of URLs that pingbacked the given URL. |
0 | 7160 |
* |
7161 |
* Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
|
7162 |
* |
|
7163 |
* @since 1.5.0 |
|
7164 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7165 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7166 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7167 |
* @param string $url |
5 | 7168 |
* @return array|IXR_Error |
0 | 7169 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7170 |
public function pingback_extensions_getPingbacks( $url ) { |
0 | 7171 |
global $wpdb; |
7172 |
||
5 | 7173 |
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
18 | 7174 |
do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks', $url, $this ); |
0 | 7175 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7176 |
$url = $this->escape( $url ); |
0 | 7177 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7178 |
$post_id = url_to_postid( $url ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7179 |
if ( ! $post_id ) { |
16 | 7180 |
// We aren't sure that the resource is available and/or pingback enabled. |
19 | 7181 |
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); |
9 | 7182 |
} |
7183 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7184 |
$actual_post = get_post( $post_id, ARRAY_A ); |
9 | 7185 |
|
7186 |
if ( ! $actual_post ) { |
|
16 | 7187 |
// No such post = resource not found. |
9 | 7188 |
return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) ); |
7189 |
} |
|
7190 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7191 |
$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 ) ); |
9 | 7192 |
|
7193 |
if ( ! $comments ) { |
|
0 | 7194 |
return array(); |
9 | 7195 |
} |
0 | 7196 |
|
7197 |
$pingbacks = array(); |
|
7198 |
foreach ( $comments as $comment ) { |
|
16 | 7199 |
if ( 'pingback' === $comment->comment_type ) { |
0 | 7200 |
$pingbacks[] = $comment->comment_author_url; |
9 | 7201 |
} |
0 | 7202 |
} |
7203 |
||
7204 |
return $pingbacks; |
|
7205 |
} |
|
7206 |
||
5 | 7207 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7208 |
* 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
|
7209 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7210 |
* @since 3.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7212 |
* @param int $code Error code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7213 |
* @param string $message Error message. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7214 |
* @return IXR_Error Error object. |
5 | 7215 |
*/ |
0 | 7216 |
protected function pingback_error( $code, $message ) { |
5 | 7217 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7218 |
* Filters the XML-RPC pingback error return. |
5 | 7219 |
* |
7220 |
* @since 3.5.1 |
|
7221 |
* |
|
7222 |
* @param IXR_Error $error An IXR_Error object containing the error code and message. |
|
7223 |
*/ |
|
0 | 7224 |
return apply_filters( 'xmlrpc_pingback_error', new IXR_Error( $code, $message ) ); |
7225 |
} |
|
7226 |
} |