wordpress / latest / classes / wp_xmlrpc_server / attach_uploads.html

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. View all references

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

Uses

Uses Description

Used By

Used By Description

Changelog

Version Description
2.1.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/attach_uploads