WordPress.org

Ready to get started?Download WordPress

Forums

Category Posts Widget
[resolved] no defaults = undefined index (4 posts)

  1. Franz Josef Kaiser
    Member
    Posted 3 years ago #

    When you got (production environment) set WP_DEBUG to true in wp-config.php, you get a lot of undefined index, because the widget ain't got any default values. A fast hack is adding the following lines to form() function at between line 139 & 140. Btw: Every Widget should have defaults imho.

    // defaults
    	if(!isset($instance["title"])) { $instance["title"] = 'insert title here'; }
    	if(!isset($instance["cat"])) { $instance["cat"] = 'allgemein'; }
    	if(!isset($instance["num"])) { $instance["cat"] = '5'; }
    	if(!isset($instance["title_link"])) { $instance["title_link"] = false; }
    	if(!isset($instance["excerpt"])) { $instance["excerpt"] = false; }
    	if(!isset($instance["excerpt_length"])) { $instance["excerpt_length"] = '25'; }
    	if(!isset($instance["comment_num"])) { $instance["comment_num"] = false; }
    	if(!isset($instance["date"])) { $instance["date"] = false; }
    	if(!isset($instance["thumb"])) { $instance["thumb"] = false; }
    	if(!isset($instance["thumb_w"])) { $instance["thumb_w"] = '40'; }
    	if(!isset($instance["thumb_h"])) { $instance["thumb_h"] = '30'; }
  2. Franz Josef Kaiser
    Member
    Posted 3 years ago #

    Edit: Pls edit line 3 to your default category title. Currently it's the german wp edition default title.

  3. Franz Josef Kaiser
    Member
    Posted 3 years ago #

    sry. too fast. just don't use it when WP_DEBUG = true

  4. aaahaaap
    Member
    Posted 3 years ago #

    These notices still show when WP_DEBUG=true
    Please use isset in your code or set (sane) defaults.

    (Don't understand FJ Kaiser's comment about not using it, no piece of code should cause warnings or notices)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic