Whenever you use a value from an array, like $array['key']
where it’s possible that the 'key'
doesn’t exist (such as the first time a widget is used) you need to check that it exists before using it or you’ll get errors on those occasions where it hasn’t been set.
Your problem is that when the widget’s first added 'tick_the_snippet_type'
doesn’t exist on $instance
, so you need to account for this possibility. I’d suggest creating a variable to pass to checked()
which will either contain tick_the_snippet_type
or a default if it doesn’t exist:
if ( isset( $instance['tick_the_snippet_type'] ) ) {
$value = $instance['tick_the_snippet_type'];
} else {
$value = false;
}
Which can be written on one line with a ternary operator:
$value = isset( $instance['tick_the_snippet_type'] ) ? $instance['tick_the_snippet_type'] : false;
And then use this for checked:
<?php checked( $value, 'tick_snippet_4' ); ?>
Related Posts:
- Shortcode putting html such as
- How to get the registered sidebar’s name by its id?
- display most popular tags in two columns
- “Can’t use function return value in write context” error
- WordPress menu deletes when trying to add a hook
- Get widget settings function?
- javaScript in section of WP API
- Add before_content and after_content to register_sidebar
- PHP Deprecated: WP_RSSjb has a deprecated constructor
- How to put a variable in a instance in the widget
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Adding a widget function into the php theme file
- Widget back end radio button issue
- My website is not showing Footer section
- How to get post category list as select in front-end?
- Show different website layout if no sidebar added
- Add a select-option to the default widgets
- Programmatically revert to backup .htaccess a possibility?
- Can’t log in to WordPress wp-admin after adding code to functions.php
- How a HTML form can trigger a PHP function?
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Site title not showing. Please help me
- is_user_logged_in() not working in homepage
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Add disclaimer before certain posts and pages
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- WordPress – registering sidebar and adding a button directly after .textwidget
- List sibling pages widget, exclude current page
- Functions are causing errors
- syntax error unexpected ‘}’ at 364 line
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- Trying to insert widget code into theme function
- Display fields as values in array from external SQL DB
- Only Show Link If div Exists
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to output widget
- Trying to establish connection to External Database
- How to find error in my code when the error message is pointing to WP core file?
- add_action shortcut?
- Passing the custom field values in the wp_get_current_user array function
- Using fwrite() and “a” appends multiple times instead of once
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- How to style options page in dashboard?
- How to insert a single row to WP database table?
- Get date numerical and separate?
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- get_term_link() returns correct – But illogical error-messages disturb
- WSoD being caused by this piece of code
- Converting HTML Template to WordPress Theme
- Extending the WP_Widget_Text class
- Set the background to a default image if there isn’t a specified “featured image”
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- Add a variable in functions.php and call it in single.php
- How to access global variable $menu inside a class function
- Calling directories to load in wordpress
- WordPress add post format support not working
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Image media upload metabox
- How to remove the cufon script from Dzonia Lite theme [closed]
- How to remove or change the “W” icon in “My Sites”?
- get a simple array of all of the term names that exist in all taxonomies
- Login/logout in header
- Dynamic Sidebars & Echo
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- How does WordPress insert Paragraphs in posts
- WordPress Access allowed to fewer pages till user logs in
- Linking text within textarea of custom meta box
- Show css depending on activity type in BuddyPress activity-loop [closed]
- only show container with next/prev links if they exist?
- PHP Warning: Attempt to read property “term_id” on bool
- How to combine wordpress_logged_in cookies in one cookie?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Change the WP Video Shortcode Output
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- remove wp floating submenu in wp dashboard
- How to put “Read more” link in Custom Excerpt inside p tag?
- Two Different Links for Same Product – WooCommerce [closed]
- ACF: how do I get the fields and its values of a specific group?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- How do I add custom bulk actions to multiple custom post types?
- Error when adding excerpt to the content through functions.php
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Get post id in a function when edit/add a post
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- How to check if a meta value has already been assigned to any user?
- How to complete two other input fields, completed the first
- How to remove role=”navigation” from all nav elements?
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- How can I apply_filters from inside a function?
- function to assign user role based on a field from usermeta