示例#1
0
    /**
     * Builds the options settings page
     *
     * @since 1.0
     * @global $rc_options array The global options array populated by populate_opts().
     * @global $rc_user_options array The global options array populated by populate_user_opts().
     * @uses get_option() A safe way to get options from the options database table.
     * @uses wp_list_categories() Displays a list of categories
     */
    public function admin()
    {
        // Default main tab is Roles
        $tab = 'roles';
        // Set variables if the Users tab is selected
        if (isset($_GET['type']) && $_GET['type'] == 'users') {
            $tab = 'users';
        }
        // Setup links for Roles/Users tabs
        $roles_tab = esc_url(admin_url('options-general.php?page=restrict-categories'));
        $users_tab = add_query_arg('type', 'users', $roles_tab);
        ?>

		<div class="wrap">
			<h2>
			<?php 
        _e('Restrict Categories', 'restrict-categories');
        // If searched, output the query
        if (isset($_REQUEST['rc-search']) && !empty($_REQUEST['rc-search'])) {
            echo '<span class="subtitle">' . sprintf(__('Search results for "%s"', 'restrict-categories'), $_REQUEST['rc-search']) . '</span>';
            echo sprintf('<span class="subtitle"><a href="%1$s">%2$s</a></span>', $users_tab, __('View All Users', 'restrict-categories'));
        }
        ?>
			</h2>

            <h2 class="nav-tab-wrapper">
            	<a href="<?php 
        echo $roles_tab;
        ?>
" class="nav-tab <?php 
        echo $tab == 'roles' ? 'nav-tab-active' : '';
        ?>
"><?php 
        _e('Roles', 'restrict-categories');
        ?>
</a>
                <a href="<?php 
        echo $users_tab;
        ?>
" class="nav-tab <?php 
        echo $tab == 'users' ? 'nav-tab-active' : '';
        ?>
"><?php 
        _e('Users', 'restrict-categories');
        ?>
</a>
            </h2>

			<?php 
        // Create a new instance of our user/roles boxes class
        $boxes = new RestrictCats_User_Role_Boxes();
        if ($tab == 'roles') {
            $rc_options = $this->populate_opts();
            ?>
            	<form method="post" action="options.php">
	                <fieldset>
	                    <?php 
            settings_fields('RestrictCats_options_group');
            // Create boxes for Roles
            $boxes->start_box(get_option('RestrictCats_options'), $rc_options, 'RestrictCats_options');
            ?>
	                </fieldset>
	                <?php 
            submit_button();
            ?>
            	</form>
			<?php 
        } elseif ($tab == 'users') {
            $rc_user_options = $this->populate_user_opts();
            ?>
            	<form method="post" action="options-general.php?page=restrict-categories&type=users">
            		<fieldset>
						<p style="float: left; margin-top:8px;">Selecting categories for a user will <em>override</em> the categories you have chosen for that user's role.</p>
						<p style="float:right; margin-top:8px;">
							<input type="search" id="rc-search-users" name="rc-search" value="">
							<?php 
            submit_button(__('Search Users', 'restrict-categories'), 'secondary', 'rc-search-users', false);
            ?>
						</p>
            		</fieldset>
				</form>

				<form method="post" action="options.php">
	                <fieldset>
	                    <?php 
            settings_fields('RestrictCats_user_options_group');
            // Create boxes for Users
            $boxes->start_box(get_option('RestrictCats_user_options'), $rc_user_options, 'RestrictCats_user_options');
            ?>
	                </fieldset>
	                <?php 
            submit_button();
            ?>
                </form>
                <?php 
        }
        ?>

            <h3><?php 
        _e('Reset to Default Settings', 'restrict-categories');
        ?>
</h3>
			<p><?php 
        _e('This option will reset all changes you have made to the default configuration.  <strong>You cannot undo this process</strong>.', 'restrict-categories');
        ?>
</p>
			<form method="post">
				<?php 
        submit_button(__('Reset', 'restrict-categories'), 'secondary', 'reset');
        ?>
                <input type="hidden" name="action" value="reset" />
                <?php 
        wp_nonce_field('rc-reset-nonce');
        ?>
			</form>
		</div>
	<?php 
    }
    /**
     * Builds the options settings page
     * 
     * @since 1.0
     * @global $rc_options array The global options array populated by populate_opts().
     * @global $rc_user_options array The global options array populated by populate_user_opts().
     * @uses get_option() A safe way to get options from the options database table.
     * @uses wp_list_categories() Displays a list of categories
     */
    public function admin()
    {
        $rc_options = $this->populate_opts();
        $rc_user_options = $this->populate_user_opts();
        /* Display message for resetting form */
        if ($_POST['reset']) {
            _e('<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Settings reset.</strong></p></div>', 'restrict-categories');
        }
        /* Default main tab is Roles */
        $tab = 'roles';
        /* Set variables if the Users tab is selected */
        if (isset($_GET['type']) && $_GET['type'] == 'users') {
            $tab = 'users';
        }
        /* Setup links for Roles/Users tabs */
        $roles_tab = esc_url(admin_url('options-general.php?page=restrict-categories'));
        $users_tab = add_query_arg('type', 'users', $roles_tab);
        ?>
	
		<div class="wrap">
			<?php 
        screen_icon('options-general');
        ?>
			<h2><?php 
        _e('Restrict Categories', 'restrict-categories');
        ?>
</h2>
            <h2 class="nav-tab-wrapper">
            	<a href="<?php 
        echo $roles_tab;
        ?>
" class="nav-tab <?php 
        echo $tab == 'roles' ? 'nav-tab-active' : '';
        ?>
">Roles</a>
                <a href="<?php 
        echo $users_tab;
        ?>
" class="nav-tab <?php 
        echo $tab == 'users' ? 'nav-tab-active' : '';
        ?>
">Users</a>
            </h2>
			
			<form method="post" action="options.php">
			<?php 
        /* Create a new instance of our user/roles boxes class */
        $boxes = new RestrictCats_User_Role_Boxes();
        if ($tab == 'roles') {
            ?>
                <fieldset>
                    <?php 
            settings_fields('RestrictCats_options_group');
            /* Create boxes for Roles */
            $boxes->start_box(get_option('RestrictCats_options'), $rc_options, 'RestrictCats_options');
            ?>
 
                </fieldset>
			<?php 
        } elseif ($tab == 'users') {
            settings_fields('RestrictCats_user_options_group');
            ?>
                <fieldset>
                    <p>Selecting categories for a user will <em>override</em> the categories you have chosen for that user's role.</p>
                    <?php 
            /* Create boxes for Users */
            $boxes->start_box(get_option('RestrictCats_user_options'), $rc_user_options, 'RestrictCats_user_options');
            ?>
 
                </fieldset>
                <?php 
        }
        ?>
                
                <p class="submit">
                    <input type="submit" class="button-primary" value="<?php 
        _e('Save Changes');
        ?>
" />
                </p>
			</form>
            
            <h3><?php 
        _e('Reset to Default Settings', 'restrict-categories');
        ?>
</h3>
			<p><?php 
        _e('This option will reset all changes you have made to the default configuration.  <strong>You cannot undo this process</strong>.', 'restrict-categories');
        ?>
</p>
			<form method="post">
                <input class="button-secondary" name="reset" type="submit" value="<?php 
        _e('Reset', 'restrict-categories');
        ?>
" />
                <input type="hidden" name="action" value="reset" />
                <?php 
        wp_nonce_field('rc-reset-nonce');
        ?>
			</form>
		</div>
	<?php 
    }