though i am specifying it.
You’re not actually specifying it. You’re trying to use it in your regex and THEN you specified it.
You can’t use it in your “if” criteria when if it doesn’t exist. You need to check to see if it exists first.
The following would set your value if it is not set OR if it IS set and doesn’t match your regex:
$options = get_option( 'analytics' );
if ( ! isset( $options['analytics_startdate'] ) || ! preg_match( '/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $options['analytics_startdate'] ) ) {
$options['analytics_startdate'] = '2018-12-01';
}
Related Posts:
- WP_DEBUG is not set, but I’m still getting warnings
- How to display admin error notice if settings saved succesfully?
- Uncaught ReferenceError:switchEditors is not defined
- strange characters in wordpress website displayed for visitors [closed]
- How to fix ob_end_flush() error?
- wp_remote_get() not retrieving pages properly
- $wpdb->insert Database Error Duplicate Entry Error Logging
- 418 header status, I’m a teapot [closed]
- Handling duplicates with wp_insert_term()
- How can I create a custom page for this error?
- List Category Posts plugin upgrade fails with fatal error
- How to get a Custom 500 Error Page to show?
- How can I find the cause of theme crashing Apache in Xampplite?
- Allowed Memory Size Error in WordPress
- tb_show is not defined in advance custom field
- WordPress Admin Dashboard Does Not Display Correctly
- Warning: in_array() expects parameter 2 to be array, null given
- Can’t Change Theme And White Screen When Activating Any Plugin
- Call to undefined function
- “There doesn’t seem to be a wp-config.php file.” despite wp-config.php in root
- How to show the error causing the ‘There has been a critical error on your website’?
- White screen across whole of site including wp-admin
- Error Establishing a Database Connection, but credentials are OK
- Unable to Upload Files
- Feed could not be found
- How we store error/success messages to the next page
- Out of Memory when Uploading an Image
- error: An Unexpected HTTP Error occurred during the API request
- What might cause “junk after document element” error?
- How do you change error reporting to only show errors in WordPress?
- WordPress There is an error log for a transaction we did not do
- How to Debug WordPress
- getting error on localhost Warning: preg_match(): Null byte in regex in C:\xampp\htdocs\pamper\wp-includes\functions.php on line 5233 [closed]
- How do iterate through all errors for a WP_Error object?
- is_wp_error is missing error
- WordPress: Notice:Object of class WP_Query could not be converted to int in on line
- 500 error after update
- Problem with running javascript in a shortcode
- Accessing my site using wp-admin does not load
- Without access to the FTP, how can I fix the index page?
- How to catch all PHP errors with custom error handler?
- Trying to get property of non-object error with thumbnail
- I have an error message coming up after I type in my domain. How Do I get my site back
- Warning: spl_autoload() [function.spl-autoload] (Term Menu Order)
- Blog automatically redirected to error page
- Error establishing a database connection error on a site that was working fine previously
- 500 error for all pages and post after move localhost to server
- why would ABSPATH not get defined
- 404 Not found error after update to WordPress 5.0
- Keep getting this code reparted again and again?
- WordPress code problem [closed]
- WordPress fonts need to upload with Google fonts?
- Method Not Implemented GET to wp-admin/post.php not supported
- When sorting WP_List_Table, table sorts, but I also get SQL errors
- 403 Forbidden error nginx
- Getting 404 error on homepage only
- ‘Invalid Error’ when saving theme options – only in Google Chrome
- Fatal error, is this because of host?
- WordPress cracked? Posts not found in dashboard
- What are the issues using the Test Cookie Fix?
- Multiple use wp_logout_url() on page cause ‘header already sent’ error after submit form
- How do I fix this: syntax error, unexpected ‘:’, expecting ‘)’
- Plugin.php not found
- Getting an error on a new website
- Fatal error: Uncaught Error: Call to undefined function add_action()
- Undefined offset: 0 in WordPress after latest version upgrade [closed]
- Fatal error for category archives
- call_user_func_array() error on my blog
- 403. You don’t have permission to access this resource error
- How to identify the origin of an issue or an unexpected behavior?
- Error Warning: Invalid argument supplied for foreach()
- Gtmetrix: avoid bad requests
- Forbidden permission and editor error after update to WordPress 5.1.1
- CSS and JS not loading after uploading onto server
- : this page isn’t working. is unable to handle the request. Http error 500
- admin page error
- Theme unit test error
- Installation problem with wordpress xampp
- BuddyPress: bp-core-template-loader.php error blocking access to wp-admin
- 403 Forbidden on site logo image upload
- Undefined index action Cannot modify header
- Unnessary character on post after restore
- TOO MANY REDIRECTS ERROR when redirecting buddypress register page to WordPress sign up
- wp_list _table You do not have sufficient permissions to access this page error
- Dashboard doesn’t work propertly
- How to fix 502 errors on my WordPress site hosted on Windows Azure that only occur when I update a post?
- Error establishing a database connection in godaddy.com
- Where can I get a full list of wordpress errors in plain text?
- WordPress doesn’t recognise my email address and I’m missing the wp-config file in PHPmyadmin cPanel to make alterations
- Parse error: syntax error, unexpected ‘$q74ed’ (T_VARIABLE)
- Fixing this error “A description for this result is not available because of this site’s robots.txt”
- Fatal error: Call to a member function update() on a non-object in my resturant plugin file restaurants.php
- Fatal error: require(): Failed opening required ‘load.php’
- Can (slow) Internet speed get you a 500 server error? [closed]
- Better error messages upon critical errors – HTTP Error 500
- Getting 403 Forbidden Error while trying to edit or delete new posts or existing posts
- Creating a function inside a custom WordPress Plugin [closed]
- Apache error log lots of connection_refused
- Lots of warnings and errors instead of my WordPress site – Synology NAS – Intranet
- Critical error after updating my wordpress