• hommealone

    (@hommealone)


    I’m finding this in my debug.log file, and I don’t know what it means. Can anyone help me to understand it (and possibly guide me to a way to fix it)?

    Undefined index: full in [path_to_wordpress_directory]/wp-includes/media.php on line 218

    This is repeated four times (line 218, line 219, line 220, line 221)

    What does “undefined index” mean in this context, and what does “full in” mean here?

    Here is the code found in wp-includes/media.php, beginning at line 217, though line 221):

    	$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) );
    	if ( empty( $meta_ids ) ) {
    		return add_metadata( $meta_type, $object_id, $raw_meta_key, $passed_value );
    	}
    

    Our theme has a custom built (bootstrap) slideshow, which pulls metadata from the images’ exif data to populate the slide captions. I am guessing that this error message may relate to that?

    When the site owner uploads images to create the slideshow, we use a script to set some pieces of wordpress information based on the exif data, like this:

    /* Automatically set the image Title, Alt-Text, Caption & Description upon upload.
     * see: https://brutalbusiness.com/automatically-set-the-wordpress-image-title-alt-text-other-meta/
    --------------------------------------------------------------------------------------*/
    add_action( 'add_attachment', 'fs_set_image_meta_upon_image_upload' );
    function fs_set_image_meta_upon_image_upload( $post_ID ) {
    
    	// Check if uploaded file is an image, else do nothing
    	if ( wp_attachment_is_image( $post_ID ) ) {
    		$image_metadata = wp_get_attachment_metadata( $post_ID );
    		
    		if ( wp_get_attachment_metadata( $post_ID ) ) {
    			$my_image_title = get_post( $post_ID )->post_title;
    			if( isset( $image_metadata['image_meta']['caption'] ) ) {
    				$image_exif_title = $image_metadata['image_meta']['caption'];
    				$my_image_title = $image_exif_title;
    			}
    		} else {
    			$my_image_title = get_post( $post_ID )->post_title;
    		}
    
    		// Sanitize the title:  remove hyphens, underscores & extra spaces:
    		$my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',  $my_image_title );
    
    		// Create an array with the image meta (Title, Caption, Description) to be updated
    		$my_image_meta = array(
    			'ID'		=> $post_ID,			// Specify the image (ID) to be updated
    			'post_title'	=> $my_image_title,		// Set image Title to sanitized title
    			'post_excerpt'	=> $my_image_title,		// Set image Caption (Excerpt) to sanitized title
    			'post_content'	=> $my_image_title,		// Set image Description (Content) to sanitized title
    		);
    
    		// Set the image Alt-Text
    		update_post_meta( $post_ID, '_wp_attachment_image_alt', $my_image_title );
    
    		// Set the image meta (e.g. Title, Excerpt, Content)
    		wp_update_post( $my_image_meta );
    
    	} 
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hommealone

    (@hommealone)

    Sorry, I quoted the code from meta.php, not media.php – !!

    Correction:
    Here are the lines from media.php

    
    	// If the file isn't an image, attempt to replace its URL with a rendered image from its meta.
    	// Otherwise, a non-image type could be returned.
    	if ( ! $is_image ) {
    		if ( ! empty( $meta['sizes'] ) ) {
    			$img_url          = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url );
    			$img_url_basename = $meta['sizes']['full']['file'];
    			$width            = $meta['sizes']['full']['width'];
    			$height           = $meta['sizes']['full']['height'];
    		} else {
    			return false;
    		}
    	}
    
    Thread Starter hommealone

    (@hommealone)

    Since Updates to Image Processing in WordPress 5.3 (see these update notes by Andrew Ozz), can I no longer hook into add_attachment()?

    If not, what would be the proper function to hook into?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Debug help: Undefined index: full in …/wp-includes/media.php on line 218’ is closed to new replies.