Esempio n. 1
0
/**
 * Separate settings by tab
 * 
 * Returns an array of tabs, each of
 * which is an indexed array of settings
 * included with the specified tab.
 *
 * @uses	quadro_get_option_parameters()	defined in \functions\options.php
 * @uses	quadro_get_settings_page_tabs()	defined in \functions\options.php
 * 
 * @return	array	$settingsbytab	array of arrays of settings by tab
 */
function quadro_get_settings_by_tab()
{
    // Get the list of settings page tabs
    $tabs = quadro_get_settings_page_tabs();
    // Initialize an array to hold
    // an indexed array of tabnames
    $settingsbytab = array();
    // Loop through the array of tabs
    foreach ($tabs as $tab) {
        $tabname = $tab['name'];
        // Add an indexed array key
        // to the settings-by-tab
        // array for each tab name
        $settingsbytab[] = $tabname;
    }
    // Get the array of option parameters
    $option_parameters = quadro_get_option_parameters();
    // Loop through the option parameters
    // array
    foreach ($option_parameters as $option_parameter) {
        $optiontab = $option_parameter['tab'];
        $optionname = $option_parameter['name'];
        // Add an indexed array key to the
        // settings-by-tab array for each
        // setting associated with each tab
        $settingsbytab[$optiontab][] = $optionname;
        $settingsbytab['all'][] = $optionname;
    }
    // Return the settings-by-tab
    // array
    return $settingsbytab;
}
Esempio n. 2
0
/**
 * Callback for get_settings_field()
 */
function quadro_setting_callback($option)
{
    global $quadro_options_group;
    $quadro_options = quadro_get_options();
    $option_parameters = quadro_get_option_parameters();
    $optionname = $option['name'];
    $optiontitle = $option['title'];
    $optiondescription = $option['description'];
    $fieldtype = $option['type'];
    $fieldname = $quadro_options_group . '[' . $optionname . ']';
    // Output checkbox form field markup
    if ('checkbox' == $fieldtype) {
        ?>
		<input type="checkbox" name="<?php 
        echo $fieldname;
        ?>
" <?php 
        checked($quadro_options[$optionname]);
        ?>
 />
		<?php 
    } else {
        if ('radio' == $fieldtype) {
            $valid_options = array();
            $valid_options = $option['valid_options'];
            $hide_option = '';
            if (isset($option['hide']) && $option['hide'] == true) {
                $hide_option .= 'data-hide="hideme" ';
                $hide_option .= 'data-if=' . json_encode($option['conditions']);
            }
            echo '<div ' . $hide_option . '>';
            foreach ($valid_options as $valid_option) {
                ?>
			<span class="radio-container">
				<label>
					<input type="radio" name="<?php 
                echo $fieldname;
                ?>
" <?php 
                checked($valid_option['name'] == $quadro_options[$optionname]);
                ?>
 value="<?php 
                echo $valid_option['name'];
                ?>
" />
					<?php 
                echo $valid_option['title'];
                ?>
					<?php 
                if ($valid_option['description']) {
                    ?>
						<small style="padding-left: 5px;"><em><?php 
                    echo $valid_option['description'];
                    ?>
</em></small>
					<?php 
                }
                ?>
				</label>
			</span>
			<?php 
            }
            echo '</div>';
        } else {
            if ('select' == $fieldtype) {
                $valid_options = array();
                $valid_options = $option['valid_options'];
                $hide_option = '';
                if (isset($option['hide']) && $option['hide'] == true) {
                    $hide_option .= 'data-hide="hideme" ';
                    $hide_option .= 'data-if=' . json_encode($option['conditions']);
                }
                ?>
		<select name="<?php 
                echo $fieldname;
                ?>
" <?php 
                echo $hide_option;
                ?>
>
		<?php 
                foreach ($valid_options as $valid_option) {
                    ?>
			<option <?php 
                    selected($valid_option['name'] == $quadro_options[$optionname]);
                    ?>
 value="<?php 
                    echo $valid_option['name'];
                    ?>
"><?php 
                    echo $valid_option['title'];
                    ?>
</option>
			<?php 
                }
                ?>
		</select>
		<?php 
            } else {
                if ('color' == $fieldtype) {
                    $hide_option = '';
                    if (isset($option['hide']) && $option['hide'] == true) {
                        $hide_option .= 'data-hide="hideme" ';
                        $hide_option .= 'data-if=' . json_encode($option['conditions']);
                    }
                    echo '<div ' . $hide_option . '>';
                    ?>
		</select>
		<input type="text" name="<?php 
                    echo $fieldname;
                    ?>
" value="<?php 
                    echo wp_filter_nohtml_kses($quadro_options[$optionname]);
                    ?>
" />
		<input type="button" class="quadropickcolor button-secondary" value="<?php 
                    esc_html_e('Select color', 'quadro');
                    ?>
">
		<div id="qcolorpicker"></div>
		<?php 
                    echo '</div>';
                } else {
                    if ('text' == $fieldtype) {
                        ?>
		<input type="text" name="<?php 
                        echo $fieldname;
                        ?>
" value="<?php 
                        echo esc_attr($quadro_options[$optionname]);
                        ?>
" />
		<?php 
                    } else {
                        if ('text-hideable' == $fieldtype) {
                            $hide_option = '';
                            if (isset($option['hide']) && $option['hide'] == true) {
                                $hide_option .= 'data-hide="hideme" ';
                                $hide_option .= 'data-if=' . json_encode($option['conditions']);
                            }
                            echo '<div ' . $hide_option . '>';
                            ?>
		<input type="text" name="<?php 
                            echo $fieldname;
                            ?>
" value="<?php 
                            echo esc_attr($quadro_options[$optionname]);
                            ?>
" />
		<?php 
                        } else {
                            if ('text-hideable-kses' == $fieldtype) {
                                $hide_option = '';
                                if (isset($option['hide']) && $option['hide'] == true) {
                                    $hide_option .= 'data-hide="hideme" ';
                                    $hide_option .= 'data-if=' . json_encode($option['conditions']);
                                }
                                echo '<div ' . $hide_option . '>';
                                ?>
		<input type="text" name="<?php 
                                echo $fieldname;
                                ?>
" value='<?php 
                                echo wp_kses_post($quadro_options[$optionname]);
                                ?>
' />
		<?php 
                            } else {
                                if ('textarea' == $fieldtype) {
                                    ?>
		<textarea name="<?php 
                                    echo $fieldname;
                                    ?>
"><?php 
                                    echo esc_attr($quadro_options[$optionname]);
                                    ?>
</textarea>
		<?php 
                                } else {
                                    if ('pass' == $fieldtype) {
                                        ?>
		<input type="password" name="<?php 
                                        echo $fieldname;
                                        ?>
" value="<?php 
                                        echo esc_attr($quadro_options[$optionname]);
                                        ?>
" />
		<?php 
                                    } else {
                                        if ('upload' == $fieldtype) {
                                            ?>
		<input class="upload" id="<?php 
                                            echo $fieldname;
                                            ?>
" type="text" name="<?php 
                                            echo $fieldname;
                                            ?>
" value="<?php 
                                            echo wp_filter_nohtml_kses($quadro_options[$optionname]);
                                            ?>
" />
		<input class="upload_file_button" type="button" value="<?php 
                                            esc_html_e('Select file', 'quadro');
                                            ?>
" />
		<p>Once you upload the file, click "Choose Image".</p>
		<?php 
                                        } else {
                                            if ('layout-picker' == $fieldtype) {
                                                $valid_options = array();
                                                $valid_options = $option['valid_options'];
                                                $hide_option = '';
                                                if (isset($option['hide']) && $option['hide'] == true) {
                                                    $hide_option .= 'data-hide="hideme" ';
                                                    $hide_option .= 'data-if=' . json_encode($option['conditions']);
                                                }
                                                echo '<div ' . $hide_option . '>';
                                                foreach ($valid_options as $valid_option) {
                                                    ?>
			<label class="layout-item <?php 
                                                    echo isset($valid_option['label-class']) ? $valid_option['label-class'] : '';
                                                    ?>
 <?php 
                                                    echo $optionname;
                                                    ?>
-layout">
			<input type="radio" name="<?php 
                                                    echo $fieldname;
                                                    ?>
" <?php 
                                                    checked($valid_option['name'] == $quadro_options[$optionname]);
                                                    ?>
 value="<?php 
                                                    echo $valid_option['name'];
                                                    ?>
" <?php 
                                                    echo isset($valid_option['disabled']) ? $valid_option['disabled'] : '';
                                                    ?>
/>
			<?php 
                                                    if ($valid_option['img'] != '') {
                                                        ?>
			<img src="<?php 
                                                        echo get_template_directory_uri() . $option['path'] . $valid_option['img'];
                                                        ?>
" alt="<?php 
                                                        echo $valid_option['title'];
                                                        ?>
">
			<?php 
                                                    }
                                                    ?>
			<span>
			<?php 
                                                    echo $valid_option['title'];
                                                    ?>
			<?php 
                                                    if ($valid_option['description']) {
                                                        ?>
				<span style="padding-left:5px;"><em><?php 
                                                        echo $valid_option['description'];
                                                        ?>
</em></span>
			<?php 
                                                    }
                                                    ?>
			</span>
			</label>
			<?php 
                                                }
                                                echo '</div>';
                                            } else {
                                                if ('repeatable' == $fieldtype) {
                                                    $repeat_fields = array();
                                                    $repeat_fields = $option['repeat_fields'];
                                                    $meta = $quadro_options[$optionname];
                                                    echo '<ul id="' . $fieldname . '-repeatable" class="custom_repeatable">';
                                                    // Make it behave as an array even if it's not
                                                    if (!is_array($meta)) {
                                                        $meta[0] = array();
                                                    }
                                                    $i = 0;
                                                    foreach ($meta as $row) {
                                                        echo '<li>';
                                                        $item_name = isset($option['item-name']) ? $option['item-name'] : esc_html__('Item', 'quadro');
                                                        echo '<h4 class="fields-toggle sort">' . $item_name . ' <span class="repeat-index">' . ($i + 1) . '</span><i class="fa fa-caret-up"></i></h4>';
                                                        echo '<div class="fields-wrapper">';
                                                        echo '<div class="fields-set">';
                                                        foreach ($repeat_fields as $repeat_field) {
                                                            $this_item = $repeat_field['name'];
                                                            $this_value = !empty($row) && isset($row[$this_item]) ? esc_attr($row[$this_item]) : '';
                                                            echo '<label><span>' . $repeat_field['title'] . '</span>';
                                                            // Swith through possible field types
                                                            switch ($repeat_field['type']) {
                                                                case 'text':
                                                                    echo '<input type="text" name="' . $fieldname . '[' . $i . '][' . $repeat_field['name'] . ']" id="' . $fieldname . '" value="' . $this_value . '" size="30" />';
                                                                    break;
                                                                case 'textarea':
                                                                    echo '<textarea name="' . $fieldname . '[' . $i . '][' . $repeat_field['name'] . ']" id="' . $fieldname . '" size="30" />' . $this_value . '</textarea>';
                                                                    break;
                                                                case 'checkbox':
                                                                    ?>
								<input type="checkbox" name="<?php 
                                                                    echo $fieldname . '[' . $i . '][' . $repeat_field['name'] . ']';
                                                                    ?>
" id="<?php 
                                                                    echo $fieldname;
                                                                    ?>
" <?php 
                                                                    checked($this_value == 'on');
                                                                    ?>
 />
								<?php 
                                                                    break;
                                                            }
                                                            if ($repeat_field['description']) {
                                                                ?>
						<span class="repeatable-item-desc"><em><?php 
                                                                echo $repeat_field['description'];
                                                                ?>
</em></span>
						<?php 
                                                            }
                                                            echo '</label>';
                                                        }
                                                        echo '<a class="repeatable-remove" href="#">' . esc_html__('Remove this item', 'quadro') . '</a>';
                                                        echo '</div><!-- .fields-set -->';
                                                        echo '</div><!-- .fields-wrapper -->';
                                                        echo '</li>';
                                                        $i++;
                                                    }
                                                    echo '</ul>';
                                                    echo '<a class="repeatable-add button" href="#">+ ' . $option['repeat-item'] . '</a>';
                                                } else {
                                                    if ('font' == $fieldtype) {
                                                        $hide_option = '';
                                                        if (isset($option['hide']) && $option['hide'] == true) {
                                                            $hide_option .= 'data-hide="hideme" ';
                                                            $hide_option .= 'data-if=' . json_encode($option['conditions']);
                                                        }
                                                        echo '<div ' . $hide_option . '>';
                                                        $valid_fonts = array();
                                                        $valid_fonts = quadro_get_valid_fontslist();
                                                        ?>
		<select name="<?php 
                                                        echo $fieldname;
                                                        ?>
">
		<?php 
                                                        foreach ($valid_fonts as $valid_font) {
                                                            ?>
			<option <?php 
                                                            selected($valid_font['css-name'] . '|' . $valid_font['font-family'] == $quadro_options[$optionname]);
                                                            ?>
 value="<?php 
                                                            echo esc_attr($valid_font['css-name']) . '|' . esc_attr($valid_font['font-family']);
                                                            ?>
"><?php 
                                                            echo $valid_font['font-name'];
                                                            ?>
</option>
		<?php 
                                                        }
                                                        ?>
		</select>
		<?php 
                                                    } else {
                                                        if ('number' == $fieldtype) {
                                                            ?>
		<input type="number" name="<?php 
                                                            echo $fieldname;
                                                            ?>
" min="<?php 
                                                            echo $option['min'];
                                                            ?>
" max="<?php 
                                                            echo $option['max'];
                                                            ?>
" value="<?php 
                                                            echo wp_filter_nohtml_kses($quadro_options[$optionname]);
                                                            ?>
" />
		<?php 
                                                        } else {
                                                            if ('greyed-out' == $fieldtype) {
                                                                $pro_desc = $option['pro_desc'];
                                                                $pro_url = $option['pro_url'];
                                                                ?>
		<p id="<?php 
                                                                echo $fieldname;
                                                                ?>
" class="greyed-out-option">
			<a href="<?php 
                                                                echo $pro_url;
                                                                ?>
"><?php 
                                                                echo $pro_desc;
                                                                ?>
</a>
		</p>
		<?php 
                                                            } else {
                                                                if ('skin_select' == $fieldtype) {
                                                                    $valid_options = array();
                                                                    $valid_options = $option['valid_options'];
                                                                    foreach ($valid_options as $valid_option) {
                                                                        ?>
			<label>
			<input type="radio" name="<?php 
                                                                        echo $fieldname;
                                                                        ?>
" class="skin-select-radio" <?php 
                                                                        checked($valid_option['name'] == $quadro_options[$optionname]);
                                                                        ?>
 value="<?php 
                                                                        echo $valid_option['name'];
                                                                        ?>
" />
			<input type="hidden" id="<?php 
                                                                        echo $valid_option['name'];
                                                                        ?>
-skin" value='<?php 
                                                                        echo json_encode($valid_option['settings']);
                                                                        /* 100% safe - ignore theme check nag */
                                                                        ?>
' />
			<span>
			<?php 
                                                                        echo $valid_option['title'];
                                                                        ?>
			<?php 
                                                                        if ($valid_option['description']) {
                                                                            ?>
				<span style="padding-left:5px;"><em><?php 
                                                                            echo $valid_option['description'];
                                                                            ?>
</em></span>
			<?php 
                                                                        }
                                                                        ?>
			</span>
			</label>
			<br />
			<?php 
                                                                    }
                                                                    echo '<input type="hidden" id="skin_confirm" value="' . esc_html__('By clicking OK you will replace some of your theme options. Are you sure?', 'quadro') . '" />';
                                                                    echo '<a href="#" id="quadro_skin_button" class="button" title="' . esc_html__('Set Skin', 'quadro') . '">' . esc_html__('Set Skin', 'quadro') . '</a>';
                                                                } else {
                                                                    if ('backup_options' == $fieldtype) {
                                                                        global $quadro_options_group;
                                                                        $backup = get_option($quadro_options_group . '_backup');
                                                                        if (!isset($backup['backup_log'])) {
                                                                            $log = esc_html__('No backups yet', 'quadro');
                                                                        } else {
                                                                            $log = $backup['backup_log'];
                                                                        }
                                                                        $output = '';
                                                                        $output .= '<div class="backup-box">';
                                                                        $output .= '<input type="hidden" id="backup_confirm" value="' . esc_html__('Click OK to backup your current saved options.', 'quadro') . '" />';
                                                                        $output .= '<input type="hidden" id="restore_confirm" value="' . esc_html__('Warning: All of your current saved options will be replaced with the data from your last backup! Proceed?', 'quadro') . '" />';
                                                                        $output .= '<p><strong>' . esc_html__('Last Backup : ', 'quadro') . '<span class="backup-log">' . $log . '</span></strong></p></div>' . "\n";
                                                                        $output .= '<a href="#" id="quadro_backup_button" class="button" title="' . esc_html__('Backup Options', 'quadro') . '">' . esc_html__('Backup Options', 'quadro') . '</a>';
                                                                        $output .= '<a href="#" id="quadro_restore_button" class="button" title="' . esc_html__('Restore Options', 'quadro') . '">' . esc_html__('Restore Options', 'quadro') . '</a>';
                                                                        $output .= '</div>';
                                                                        echo $output;
                                                                    } else {
                                                                        if ('transfer_options' == $fieldtype) {
                                                                            // Get Theme Options
                                                                            $data = quadro_get_options();
                                                                            echo '<input type="hidden" id="import_confirm" value="' . esc_html__('Click OK to import these options. All your theme options will be replaced!', 'quadro') . '" />';
                                                                            echo '<textarea id="export_data" rows="8">' . urlencode(serialize($data)) . '</textarea>' . "\n";
                                                                            echo '<a href="#" id="quadro_select_button" class="button" title="' . esc_html__('Select All', 'quadro') . '">' . esc_html__('Select All', 'quadro') . '</a>';
                                                                            echo '<a href="#" id="quadro_import_button" class="button" title="' . esc_html__('Import Options', 'quadro') . '">' . esc_html__('Import Options', 'quadro') . '</a>';
                                                                        } else {
                                                                            if ('dummy_import' == $fieldtype) {
                                                                                echo '<input type="hidden" id="dcontent_confirm" value="' . esc_html__('Click OK to import Dummy Content to your WordPress install. Several WP options and all your theme options will be replaced!', 'quadro') . '" />';
                                                                                echo '<input type="hidden" id="dcontent_success" value="' . esc_html__('Dummy Content successfully imported. Page needs to be refreshed.', 'quadro') . '" />';
                                                                                echo '<div class="loader-icon" style="display: none;"><i class="fa fa-spinner fa-spin"></i> ' . esc_html__('This may take a while. Please, don\'t refresh your browser till you get a nice message saying it went ok. ;)', 'quadro') . '</div>';
                                                                                echo '<a href="#" id="quadro_dcontent_button" class="button" title="' . esc_html__('Import Dummy Content', 'quadro') . '">' . esc_html__('Import Dummy Content', 'quadro') . '</a>';
                                                                            } else {
                                                                                if ('dummy_importx' == $fieldtype) {
                                                                                    echo '<div class="loader-icon" style="display: none;"><i class="fa fa-spinner fa-spin"></i> ' . esc_html__('This may take a while. Please, don\'t refresh your browser till you get a nice message saying it went ok. ;)', 'quadro') . '</div>';
                                                                                    echo '<a href="#" id="quadro_dcontentx_button" class="button button-primary" title="' . esc_html__('Open Demo Content Importer', 'quadro') . '">' . esc_html__('Open Demo Content Importer', 'quadro') . '</a>';
                                                                                    qi_dcontent_lightbox();
                                                                                } else {
                                                                                    if ('typekit_activate' == $fieldtype) {
                                                                                        echo '<a href="#" id="quadro_typekit_activate" class="button" title="' . esc_html__('Activate Typekit', 'quadro') . '">' . esc_html__('Activate Typekit', 'quadro') . '</a>';
                                                                                    } else {
                                                                                        if ('usercheck' == $fieldtype) {
                                                                                            echo '<a href="#" id="quadro_user_check" class="button" title="' . esc_html__('Check Now', 'quadro') . '">' . esc_html__('Check Now', 'quadro') . '</a>';
                                                                                        } else {
                                                                                            if ('portf-transients-del' == $fieldtype) {
                                                                                                echo '<a href="#" id="quadro_portf_transients_delete_button" class="button" title="' . esc_html__('Refresh Transients', 'quadro') . '">' . esc_html__('Refresh Transients', 'quadro') . '</a>';
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Output the setting description
    ?>
	<span class="description"><?php 
    echo $optiondescription;
    ?>
</span>
	<?php 
}