Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if settings_sections and settings_fields are array before foreach #91

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/class.settings-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ function add_field( $section, $field ) {
* registers them to WordPress and ready for use.
*/
function admin_init() {
if( ! is_array( $this->settings_sections ) )
return ;
//register settings sections
foreach ( $this->settings_sections as $section ) {
if ( false == get_option( $section['id'] ) ) {
Expand All @@ -115,6 +117,8 @@ function admin_init() {
add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
}

if( ! is_array($this->settings_fields) )
return ;
//register settings fields
foreach ( $this->settings_fields as $section => $field ) {
foreach ( $field as $option ) {
Expand All @@ -140,6 +144,7 @@ function admin_init() {
'min' => isset( $option['min'] ) ? $option['min'] : '',
'max' => isset( $option['max'] ) ? $option['max'] : '',
'step' => isset( $option['step'] ) ? $option['step'] : '',
'post_type' => isset( $option['post_type'] ) ? $option['post_type'] : 'page',
);

add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
Expand Down Expand Up @@ -415,12 +420,16 @@ function callback_color( $args ) {
function callback_pages( $args ) {

$dropdown_args = array(
'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'] ) ),
'name' => $args['section'] . '[' . $args['id'] . ']',
'id' => $args['section'] . '[' . $args['id'] . ']',
'echo' => 0
'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'] ) ),
'name' => $args['section'] . '[' . $args['id'] . ']',
'id' => $args['section'] . '[' . $args['id'] . ']',
'echo' => 0,
'post_type' => $args['post_type'],
'hierarchical' => true,
'show_option_none' => '— Select —',
);
$html = wp_dropdown_pages( $dropdown_args );
$html .= $this->get_field_description( $args );
echo $html;
}

Expand Down Expand Up @@ -502,6 +511,9 @@ function get_option( $option, $section, $default = '' ) {
function show_navigation() {
$html = '<h2 class="nav-tab-wrapper">';

if( ! is_array( $this->settings_sections ) )
return ;

$count = count( $this->settings_sections );

// don't show the navigation if only one section exists
Expand All @@ -524,6 +536,8 @@ function show_navigation() {
* This function displays every sections in a different form
*/
function show_forms() {
if( ! is_array( $this->settings_sections ) )
return ;
?>
<div class="metabox-holder">
<?php foreach ( $this->settings_sections as $form ) { ?>
Expand Down Expand Up @@ -566,15 +580,15 @@ function script() {
if (typeof(localStorage) != 'undefined' ) {
activetab = localStorage.getItem("activetab");
}

//if url has section id as hash then set it as active or override the current local storage value
if(window.location.hash){
activetab = window.location.hash;
if (typeof(localStorage) != 'undefined' ) {
localStorage.setItem("activetab", activetab);
}
}
}
}

if (activetab != '' && $(activetab).length ) {
$(activetab).fadeIn();
} else {
Expand Down