X

Reset options back to default with update_option

LayerSlider Review - settings

Adding this snippet to the functions.php of your wordpress theme will check if an option was updated by a user. If so, it will save it back to the default option you've set. Should work with almost any site option. (inspect element on input field and input's "id" should be the "name" you need.)



Code Snippet:


$options = array(
array( 'name' => 'thumbnail_size_w', 'value' => '150' ),
array( 'name' => 'thumbnail_size_h', 'value' => '150' ),
array( 'name' => 'medium_size_w', 'value' => '250' ),
array( 'name' => 'medium_size_h', 'value' => '250' ),
array( 'name' => 'large_size_w', 'value' => '728' ),
array( 'name' => 'large_size_h', 'value' => '728' ),
array( 'name' => 'embed_size_w', 'value' => '728' ),
array( 'name' => 'embed_size_h', 'value' => '600' ),
);

foreach ( $options as $option ) {
if ( get_option( $option['name'] ) != $option['value'] ) {
update_option( $option['name'], $option['value'] );
} else {
$deprecated = ' ';
$autoload = 'no';
add_option( $option['name'], $option['value'], $deprecated, $autoload );
}
}

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!