wp_ajax_set_attachment_thumbnail
Ajax handler for setting the featured image for an attachment.
Description
wp_ajax_set_attachment_thumbnail();
Usage
if ( !function_exists( 'wp_ajax_set_attachment_thumbnail' ) ) { require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; } // NOTICE! Understand what this does before running. $result = wp_ajax_set_attachment_thumbnail();
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/ajax-actions.php
- function wp_ajax_set_attachment_thumbnail() {
- if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) {
- }
- $thumbnail_id = (int) $_POST['thumbnail_id'];
- if ( empty( $thumbnail_id ) ) {
- }
- $post_ids = array();
- // For each URL, try to find its corresponding post ID.
- foreach ( $_POST['urls'] as $url ) {
- $post_id = attachment_url_to_postid( $url );
- if ( ! empty( $post_id ) ) {
- $post_ids[] = $post_id;
- }
- }
- if ( empty( $post_ids ) ) {
- }
- $success = 0;
- // For each found attachment, set its thumbnail.
- foreach ( $post_ids as $post_id ) {
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- continue;
- }
- if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) {
- $success++;
- }
- }
- if ( 0 === $success ) {
- } else {
- }
- }