Can’t get plugin settings page to save data

While you are using Settins API, that’s why you don’t need to use update_option or add_option functions. Settings API would handle that by self. There were few issues that’s why your code is not working. 1. add_settings_section( ‘wpa_ad_insert_main’, ‘Ad Insertion Settings’, ‘wpa_ad_insert_section_text’, ‘wpa_ad_insert’ ); 3rd parameter is the callback function. Since, you don’t need this … Read more

How to add settings subpage from a plugin to a settings page created in theme?

This is just a typo Wrong //wvdh-startpoint add_submenu_page( ‘wvdh-startpoint’, ‘page-from-plugin’, ‘menu-from-plugin’, ‘manage_options’, ‘plugin-slug’, ‘wvdh_settings_page’ ); Correct //wdvh-startpoint add_submenu_page( ‘wdvh-startpoint’, ‘page-from-plugin’, ‘menu-from-plugin’, ‘manage_options’, ‘plugin-slug’, ‘wvdh_settings_page’ );

Hide output of add_settings_field()

You can hide it using jQuery which will be inserted in the wp-admin header: add_action( ‘admin_head’, ‘wpse_239421_hide_section’ ); function wpse_239421_hide_section() { ?> <script type=”text/javascript”> jQuery(document).ready(function($) { $(‘[scope=row]’).closest(‘tr’).hide(); } ); </script> <?php } This will remove the closet tr bases on the scope=row.

PHP Notice: Undefined offset: 0 in /wordpress/wp-includes/plugin.php and Register Settings API change

https://make.wordpress.org/core/2016/10/26/registering-your-settings-in-wordpress-4-7/ The register_setting() function signature changed in v4.7 allowing an array for the third option in place of a callback function in prior versions. Passing an array to register_setting() in WordPress v4.6.x and earlier will result in the errors above. WordPress v4.6.8 function definition: https://github.com/WordPress/WordPress/blob/1aa173010736085a921beb10fd420d6d863419a5/wp-admin/includes/plugin.php#L1767-L1795 /** * Register a setting and its sanitization callback * … Read more

redirect on theme switch – WordPress

You could use the after_theme_switch hook to do this, and wp_safe_redirect() works fine to redirect to local urls only. In your callback function check for the $_GET[‘activated’] flag or you may get a “too many redirects” type of error. add_action( ‘after_switch_theme’, ‘my_theme_redirect’ ); function my_theme_redirect() { if( isset( $_GET[‘activated’] ) ) { wp_safe_redirect( admin_url(‘admin.php?page=alecaddd_sunset’) ); … Read more

get_option array value defaults and best practices

First question: Is this a good practice? Based on the type of value you are saving, array as settings value is definitely good practice. How can I do this for a value within an array ex. get_option(‘header’)[‘header_logo’][‘image’]? If you believe option value for header might be empty or not saved, you can use this – … Read more

Saving plugin’s settings in 1 field in json format

There’s always a character limit, but option_value is LONGTEXT so unless you anticipate more than 4GB of data you should be fine. I’d suggest json is unnecessary – you can save a PHP array as the value and it will be serialized/deserialized automatically. That said, as Tom points out, this is really micro-optimising, and won’t … Read more

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