I'm not exactly sure why this page was singled out for copyediting, but the example code section looks extremely confusing and overthought. The simple line
update_option( 'myhack_extraction_length', 255 );
would achieve the exact same result. Goldenapples 03:31, 22 May 2012 (UTC)
The example does not seem to be valid. It seems it is trying to get around the fact that you can't set autoload to 'no'
when calling update_option()
on an option that hasn't already been added:
<?php $option_name = 'myhack_extraction_length' ; $newvalue = '255' ; if ( get_option( $option_name ) != $newvalue ) { update_option( $option_name, $newvalue ); } else { $deprecated = ' '; $autoload = 'no'; add_option( $option_name, $newvalue, $deprecated, $autoload ); } ?>
A better example would seem to be:
<?php $option_name = 'myhack_extraction_length' ; $new_value = '255' ; $existing_value = get_option($option_name); if ($existing_value === false) { $autoload = 'no'; $deprecated = null; add_option($option_name, $new_value, $deprecated, $autoload); } else { update_option($option_name, $new_value); } ?>
The description says that you must sanitize the value but the parameter reference section says that you can store arrays, objects or whatever. These statements can't both be true.