Passing array in add_option()

I think that you have added bguru_options option before. If bguru_options already exists, add_option() does nothing. To modify the value of existing options you should use update_option() instead. EDIT I confirm what I thought. You are running add_option(‘bguru_options’, $default_options); in every admin_init. bguru_options option was added to database in the first run and subsequent calls … Read more

Add option for editors through `register_setting`

To allow users with capabilities other than manage_options to save a setting you can use the option_page_capability_{$option_page} hook. Despite the name, {$option_page} is the option group, which is what you set for the first argument of register_setting() and settings_fields() on your options page. So if you registered a setting: register_setting( ‘wpse_310606_setting_group’, ‘wpse_310606_setting’ ); You can … Read more

array_map() for sanitizing $_POST

It’s probably not a great idea. Firstly, if you’ve got other field types then you should probably use more appropriate functions. For example, textarea fields should be sanitised with sanitize_textarea_field(), and color pickers should be sanitized with sanitize_hex_color(). You should also consider that $_POST likely also contains fields that you don’t want to save, such … Read more

How to verify this checkbox is checked?

<?php echo “<input type=”checkbox” name=”automatic” value=”1″ “.checked(1, get_option(‘automatic’)).” />”; if (get_option(‘automatic’) === ‘1’) { require_once ‘myfile.php’; } ?>

update_option not working in stand-alone PHP script

I’m not sure why it does’t work for you, but the following works in the file wp-content/test.php: <?php // doesn’t make difference to have this or not, for the rest to work define( ‘WP_USE_THEMES’, false ); require( $_SERVER[‘DOCUMENT_ROOT’] .’/wp-load.php’ ); function my_function() { return ‘hello world’; } $value = my_function(); update_option( ‘my_option’, $value ); var_dump( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)