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.


Top ↑

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 ) );
				}
			}
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More