0
0
Wordpressframework~20 mins

Media library management in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Media Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you upload an image larger than the max upload size?
In WordPress, if you try to upload an image file larger than the maximum upload size set in the server or WordPress settings, what will be the result?
AWordPress compresses the image to reduce size and then uploads.
BThe upload fails with an error message about file size limit.
CThe image uploads but is automatically resized to fit the limit.
DThe image uploads successfully without any warning.
Attempts:
2 left
💡 Hint
Think about server restrictions and WordPress upload handling.
state_output
intermediate
2:00remaining
What is the output of this WordPress media query?
Given this code snippet querying media attachments, what will be the count of items returned?
 $args = [
  'post_type' => 'attachment',
  'post_mime_type' => 'image/jpeg',
  'posts_per_page' => -1
];
$query = new WP_Query($args);
echo $query->found_posts;
Wordpress
$args = [
  'post_type' => 'attachment',
  'post_mime_type' => 'image/jpeg',
  'posts_per_page' => -1
];
$query = new WP_Query($args);
echo $query->found_posts;
AThe number of JPEG images in the media library.
BThe total number of all media items regardless of type.
CZero, because 'attachment' is not a valid post type.
DThe number of posts, not media items.
Attempts:
2 left
💡 Hint
Check the post_type and post_mime_type filters.
📝 Syntax
advanced
2:00remaining
Which option correctly registers a custom image size in WordPress?
You want to add a new image size called 'custom-thumb' with 300x200 pixels, cropped. Which code snippet correctly does this?
Aadd_image_size('custom-thumb', 300, 200);
Badd_image_size('custom-thumb', 300, 200, true);
Cadd_image_size('custom-thumb', array(300, 200), true);
Dadd_image_size('custom-thumb', 300, 200, 'crop');
Attempts:
2 left
💡 Hint
Check the parameters of add_image_size function.
🔧 Debug
advanced
2:00remaining
Why does this media upload code fail to attach metadata?
This code uploads an image and tries to generate metadata but the metadata is missing. Why?
$attach_id = media_handle_upload('file', 0);
wp_generate_attachment_metadata($attach_id, get_attached_file($attach_id));
Wordpress
$attach_id = media_handle_upload('file', 0);
wp_generate_attachment_metadata($attach_id, get_attached_file($attach_id));
Awp_generate_attachment_metadata returns metadata but it is not saved back to the database.
Bmedia_handle_upload does not upload the file correctly.
CThe code is missing a call to wp_update_attachment_metadata to save metadata.
Dget_attached_file returns false because attachment ID is invalid.
Attempts:
2 left
💡 Hint
Generating metadata alone does not save it.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using the WordPress REST API for media library management?
Why would a developer prefer to manage media library items using the WordPress REST API instead of traditional PHP functions?
AIt allows remote applications and JavaScript frontends to interact with media items asynchronously.
BIt automatically compresses all media files on upload.
CIt disables user permissions for media uploads to improve security.
DIt replaces the need for any PHP code in WordPress.
Attempts:
2 left
💡 Hint
Think about modern web app architectures and asynchronous data handling.