Howdy! I’m breaking down the code of the WordPress Settings API and keep running across blocks of code that I don’t understand. The style is confusing me as there seem to be missing braces and else statements.
Here is the code to one of the functions.
function add_settings_section($id, $title, $callback, $page) {
global $wp_settings_sections;
if ( 'misc' == $page ) {
_deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
$page = 'general';
}
if ( !isset($wp_settings_sections) )
$wp_settings_sections = array();
if ( !isset($wp_settings_sections[$page]) )
$wp_settings_sections[$page] = array();
if ( !isset($wp_settings_sections[$page][$id]) )
$wp_settings_sections[$page][$id] = array();
$wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
}
What are the functions of the
[
$page] and [$id]
next to the variable name?
Within the function there is the block of if statements that seem to me to be missing brackets and else statements. Can someone explain this coding style to me? Also if you can explain what each if statement is doing. It seems like it is slowly populating an array. My confusion in this area comes in when the $wp_settings function is called from another function and uses [$page] as part of the array like this.
foreach ( (array) $wp_settings_sections[$page] as $section
While we are at it, I’ve never seen array used in such a manner in the line of code calling the variable which is global by the way.
This entire block of code has me stumped even though I can use it with no errors.
Hope I provided enough info.
Thanks in advance.