wp_xmlrpc_server::attach_uploads() WordPress Method
The wp_xmlrpc_server::attach_uploads() method is used to attach files to a post when creating or editing it via the XML-RPC interface. This method can be used to upload both images and other types of files.
wp_xmlrpc_server::attach_uploads( int $post_ID, string $post_content ) #
Attach upload to a post.
Parameters
- $post_ID
(int)(Required)Post ID.
- $post_content
(string)(Required)Post Content for attachment.
Source
File: wp-includes/class-wp-xmlrpc-server.php
public function attach_uploads( $post_ID, $post_content ) { global $wpdb; // Find any unattached files. $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); if ( is_array( $attachments ) ) { foreach ( $attachments as $file ) { if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { $wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); } } } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |