• A plugin I have (wp-veriteco-timeline) is causing this error when I hit Publish on its Custom Post Type BUT it IS saving the Featured Image and content.

    “Warning: Creating default object from empty value in /…/wp-content/plugins/wp-veriteco-timeline/wp-veriteco-timeline.php on line 60”

    “Warning: Cannot modify header information – headers already sent by (output started at /…/wp-content/plugins/wp-veriteco-timeline/wp-veriteco-timeline.php:60) in /…/wp-admin/post.php on line 197”

    Anyone see anything wrong with this code as regards WP?

    $thumbnail_id = get_post_thumbnail_id( $this->post_id );
    
    			if( $thumbnail_id ) {
    				// if there is featured image
    				$img = wp_get_attachment_image_src( $thumbnail_id, 'full' );
    				$thumbnail_image = get_post( $thumbnail_id, 'OBJECT' );
    				if ($thumbnail_image && isset($thumbnail_image)) {
    					$this->asset->media = $img[0];
    					$this->asset->caption = $thumbnail_image->post_excerpt;
    				}
    			} else if( $meta['wpvt_video'][0] ) {
    				// otherwise, look for youtube link
    				$this->asset->media = $meta['wpvt_video'][0];
    				$this->asset->caption = $meta['wpvt_video_caption'][0];
    			}

    Thanks for anyone’s help.

    GN

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s nothing wrong that I can see provided all the variables have expected values. What if a post has no assigned thumbnail? Then $meta had better have the proper keys and values or warnings will occur. What about $this->post_id? Is it possible for this to be unassigned? Exactly what is at line 60 anyway?

    The empty value warning means something is missing a value that should not. The headers sent warning is because your code is creating output when it should not. Plugin files should not output code directly, all output should be from within callbacks to actions, call_user_func, etc., where output is appropriate.

    Accommodating the chance that variables are not assigned the values expected, and trapping and handling such conditions, is critical to building robust, error free code. Anything derived from user input, no matter how indirect, is to be considered with great suspicion. If not due to actual maliciousness, then due to cluelessness.

Viewing 1 replies (of 1 total)

The topic ‘plugin php error "Warning: Creating default object in…"’ is closed to new replies.