How to Loop Plugin Option Field Set?

I figured it out after a little work. To start, I ended up using a single callback: array($this, ‘txs_loop_callbacks’) using the same add_settings_field registration above. Then I altered the final argument in the field resgistration, making each unique to that specific field: array(‘field’ => ‘txs_opacity_’.$i). Then in the loop callback I stored each field’s HTML … Read more

Where to store some per-template preferences?

If the options have “visual” impact on the website, consider using the customizer, it gives immediate visual feedback on what changing a value means. If the settings have no visual impact on the website, then maybe they don’t belong in the theme after all, but in a separate plugin. There are always edge cases, so … Read more

register_setting() vs add_option()

So do I still need to hook admin_init and call those register_setting() if I did add_option() before? Yes. You need. You may add add_option to set the default value. Another call to add_option will do nothing. However, the idea of register_setting() is more than just add_option(). Each setting has the context page such as (general, … Read more

Flush_rewrite_rules not working when settings updated

Does this work for you? Seems to work when I try it. function qd_settings_api_init() { add_settings_section( ‘qd_theme_setting_section’, ‘Theme Reading Settings’, ‘qd_theme_setting_section_callback_function’, ‘reading’ ); add_settings_field( ‘qd_news_page’, ‘News Page’, ‘qd_news_page_dropdown_cbf’, ‘reading’, ‘qd_theme_setting_section’ ); if (delete_transient(‘qd_flush_rules’)) flush_rewrite_rules(); // * Added register_setting( ‘reading’, ‘qd_news_page’, ‘qd_sanitize’ ); // * Changed } /* Added this function. */ function qd_sanitize($input) { set_transient(‘qd_flush_rules’); … Read more

Which to use to execute code during the saving of a plugin settings page?

If you’re using Settings API, then you should use a sanitize callback: register_setting( $option_group, $option_name, $sanitize_callback ); The myth is that the $sanitize_callback actually is a filter for your options when it’s saved in the database. This is the place where you can do something with your custom code. This is the sample code: register_setting( … Read more

Add settings fields on options discussion admin page

You have to call add_settings_section() first, pass a unique ID and assign it to the page (poor name) discussion: add_settings_section( ‘ads_id’, ‘Extra Settings’, ‘ads_description’, ‘discussion’ ); Then register a callback to save your field(s) … // Register a callback register_setting( ‘discussion’, ‘ads’, ‘trim’ ); … and then register one or more fields: // Register the … Read more

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