0

I am receiving the following error in PHP

8 Undefined offset: 1/Applications/MAMP/htdocs/wordpress/wp-content/plugins/wp-plugin/core.php 2178

Here is the PHP code that causes it:

if (isset ( $attachements_to_attach ) && count ( $attachements_to_attach ) > 0) {
            
            require_once (ABSPATH . 'wp-admin/includes/image.php');
            
            foreach ( $attachements_to_attach as $attachements_to_attach_single ) {
                
                $file = $attachements_to_attach_single [0];
                $attachment = $attachements_to_attach_single [1];
                $post_id = $id;
                
                if (! function_exists ( 'wp_plugin_filter_image_sizes' )) {
                    function wp_plugin_filter_image_sizes($sizes) {
                        $sizes = array ();
                        return $sizes;
                    }
                }
                
                if (! in_array ( 'OPT_FEED_MEDIA_ALL', $camp_opt )) {
                    add_filter ( 'intermediate_image_sizes_advanced', 'wp_plugin_filter_image_sizes' );
                }
                
                $attach_id = wp_insert_attachment ( $attachment, $file, $post_id );
                $attach_data = wp_generate_attachment_metadata ( $attach_id, $file );
                wp_update_attachment_metadata ( $attach_id, $attach_data );

            } <!-- error in this line
            
            // remove sizes filter
            remove_filter ( 'intermediate_image_sizes_advanced', 'wp_plugin_filter_image_sizes' );
        }
  • 1
    Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Tangentially Perpendicular Sep 14 '21 at 21:50
  • Looks like you have spaces in your `$file` and `$attachment` variables before the index brackets `[]`. You should probably test to see if those values exist first. – disinfor Sep 15 '21 at 00:03

0 Answers0