Complete the code to upload a file to the WordPress media library.
<?php $attachment_id = media_handle_upload('[1]', 0); ?>
The media_handle_upload function requires the name of the file input field, which is usually file.
Complete the code to get the URL of an attachment by its ID.
<?php
$url = wp_get_attachment_url([1]);
?>The function wp_get_attachment_url expects the attachment ID, which is stored in $attachment_id.
Fix the error in the code to properly delete an attachment from the media library.
<?php
wp_delete_attachment([1], true);
?>The wp_delete_attachment function requires the attachment ID as the first argument to delete the media properly.
Fill both blanks to create an array of attachment IDs for images uploaded by the current user.
<?php $args = [ 'post_type' => '[1]', 'author' => [2] ]; $attachments = get_posts($args); ?>
The post_type for media files is attachment. To get the current user ID, use get_current_user_id().
Fill all three blanks to update the alt text of an attachment.
<?php update_post_meta([1], '[2]', [3]); ?>
To update the alt text, use update_post_meta with the attachment ID, the meta key _wp_attachment_image_alt, and the new alt text value.