Example #1
0
function synved_option_wp_admin_init()
{
    global $synved_option_list;
    if ($synved_option_list != null) {
        foreach ($synved_option_list as $id => $list) {
            $dbname = synved_option_name_default($id);
            $group = synved_option_group_default($id);
            register_setting($group, $dbname, create_function('$value', 'return synved_option_setting_sanitize_cb(\'' . $id . '\', $value);'));
            $items = synved_option_item_list($id);
            foreach ($items as $name => $item) {
                synved_option_wp_handle_setting($id, null, null, $name, $item);
            }
        }
    }
}
function synved_option_page_cb($id, $name, $item)
{
    $group = synved_option_group_default($id);
    $label = synved_option_item_label($item);
    $title = synved_option_item_title($item);
    $tip = synved_option_item_tip($item);
    $role = synved_option_item_role($item);
    if (!current_user_can($role)) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'synved-option'));
    }
    if ($title === null) {
        $title = $label;
    }
    ?>
	<div class="wrap">
		<div class="icon32" id="icon-options-general"><br/></div>
		<h2><?php 
    echo $title;
    ?>
</h2>
		<p><?php 
    echo $tip;
    ?>
</p>
		<form action="options.php" method="post">
		<?php 
    settings_fields($group);
    ?>
		<?php 
    $page_slug = synved_option_page_slug($id, $name, $item);
    synved_option_render_page($page_slug);
    ?>
		<p class="submit">
			<input name="Submit" type="submit" class="button-primary" value="<?php 
    esc_attr_e('Save Changes');
    ?>
" />
		<?php 
    $render_fragment = synved_option_item_render_fragment($item);
    $out = null;
    if ($render_fragment != null) {
        $error = null;
        $new_out = null;
        try {
            $params = array();
            $new_out = $render_fragment->Invoke(array('page-submit-tail', '', $params, $name, $id, $item));
        } catch (Exception $ex) {
            $new_out = null;
            $error = $ex->getMessage();
        }
        if ($new_out !== null) {
            $out = $new_out;
        }
    }
    echo $out;
    ?>
		</p>
		</form>
	</div>
<?php 
}