0
0
Wordpressframework~10 mins

Media library management in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to upload a file to the WordPress media library.

Wordpress
<?php
$attachment_id = media_handle_upload('[1]', 0);
?>
Drag options to blanks, or click blank then click option'
Amedia
Bupload
Cimage
Dfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'upload' or 'media' instead of the actual file input name.
Leaving the parameter empty.
2fill in blank
medium

Complete the code to get the URL of an attachment by its ID.

Wordpress
<?php
$url = wp_get_attachment_url([1]);
?>
Drag options to blanks, or click blank then click option'
A$media_id
B$post_id
C$attachment_id
D$file_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a post ID variable instead of attachment ID.
Using undefined variables.
3fill in blank
hard

Fix the error in the code to properly delete an attachment from the media library.

Wordpress
<?php
wp_delete_attachment([1], true);
?>
Drag options to blanks, or click blank then click option'
A$attachment_id
B$media_url
C$post_id
D$file_path
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a post ID or URL instead of attachment ID.
Omitting the second argument to force deletion.
4fill in blank
hard

Fill both blanks to create an array of attachment IDs for images uploaded by the current user.

Wordpress
<?php
$args = [
  'post_type' => '[1]',
  'author' => [2]
];
$attachments = get_posts($args);
?>
Drag options to blanks, or click blank then click option'
Aattachment
Bget_current_user_id()
Cpost
Dget_user_id()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'attachment' for post_type.
Using a non-existent function like get_user_id().
5fill in blank
hard

Fill all three blanks to update the alt text of an attachment.

Wordpress
<?php
update_post_meta([1], '[2]', [3]);
?>
Drag options to blanks, or click blank then click option'
A$attachment_id
B_wp_attachment_image_alt
C$alt_text
Dalt_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alt_text' as meta key instead of '_wp_attachment_image_alt'.
Passing the wrong variable for attachment ID.