Example #1
0
/**
 * {@internal Missing Short Description }}
 * 
 * {@internal Missing Long Description }}
 * 
 * @hook	action	bf_above_admin_content
 * @hook	action	bf_below_admin_content
 * 
 * @hook	action	bf_admin_$name
 * @hook	action	bf_admin_load_$submit
 * @since	0.5.2
 */
function bf_admin()
{
    global $bf_options, $wpdb;
    if (isset($_GET['page']) && $_GET['page'] == 'bf-options') {
        //print_r($_POST);
        foreach (bf_allowed_submit_values() as $submit_value) {
            if (isset($_REQUEST[$submit_value])) {
                // Check whether form is submitted from WP admin itself
                if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bf-admin')) {
                    die('Security Error');
                }
                do_action("bf_admin_load_{$submit_value}");
            }
        }
        $nonce = wp_create_nonce('bf-admin');
        // create nonce token for security
        ?>
		<div class="wrap clearfix">
		<?php 
        do_action('bf_above_admin_content');
        ?>
		
		<h2 id="bf-header"><?php 
        printf(__('%s Options', 'buffet'), get_current_theme());
        ?>
</h2>
		</div>
		
		<p id="bf-help-links">
		<?php 
        bf_admin_help_links();
        ?>
		</p>
		
		<form id="bf-settings-form" method="post" action="themes.php?page=bf-options&_wpnonce=<?php 
        echo $nonce;
        ?>
">
		
		<ul id="bf-tabs" class="clearfix">
			<?php 
        $tabs = array_merge(bf_admin_tabs(), array('reset' => __('Reset', 'buffet')));
        foreach ($tabs as $id => $name) {
            ?>
			<li><a href="#<?php 
            echo $id;
            ?>
"><?php 
            echo $name;
            ?>
</a></li>
			<?php 
        }
        ?>
		</ul>
		
		<?php 
        foreach ($tabs as $id => $name) {
            echo '<div id="' . $id . '" class="padding-content">';
            do_action("bf_admin_{$id}");
            echo '</div>';
        }
        $hooks = bf_get_option('hooks');
        ?>
		
		</form><!-- #bf-settings-form -->
		
		<?php 
        do_action('bf_below_admin_content');
        ?>
		
		</div><!-- .wrap -->
<?php 
    }
}
function buddyforms_settings_page()
{
    global $pagenow, $buddyforms;
    ?>
    <div class="wrap">
        <?php 
    include BUDDYFORMS_INCLUDES_PATH . '/admin/admin-credits.php';
    if ('true' == esc_attr($_GET['updated'])) {
        echo '<div class="updated" ><p>BuddyForms...</p></div>';
    }
    if (isset($_GET['tab'])) {
        bf_admin_tabs($_GET['tab']);
    } else {
        bf_admin_tabs('homepage');
    }
    ?>

        <div id="poststuff">
            <!--			<form method="post" action="--><?php 
    //admin_url( 'edit.php?post_type=buddyforms&page=bf_settings' );
    ?>
<!--">-->
            <?php 
    if ($pagenow == 'edit.php' && $_GET['page'] == 'bf_settings') {
        if (isset($_GET['tab'])) {
            $tab = $_GET['tab'];
        } else {
            $tab = 'general';
        }
        switch ($tab) {
            case 'general':
                $buddyforms_posttypes_default = get_option('buddyforms_posttypes_default');
                ?>
                        <h2><?php 
                _e('Post Types Default Form', 'buddyforms');
                ?>
</h2>
                        <p>Select a default form for every post type.</p>

                        <p>This will make sure that posts created before BuddyForms will have a form associated. <br>
                            If you select none the post edit link will point to the admin for posts not created with BuddyForms</p>

                        <form method="post" action="options.php">

                            <?php 
                settings_fields('buddyforms_posttypes_default');
                ?>

                            <table class="form-table">
                                <tbody>
                                <?php 
                if (isset($buddyforms) && is_array($buddyforms)) {
                    $post_types_forms = array();
                    foreach ($buddyforms as $key => $buddyform) {
                        $post_types_forms[$buddyform['post_type']][$key] = $buddyform;
                    }
                    foreach ($post_types_forms as $post_type => $post_types_form) {
                        ?>
                                        <tr valign="top">
                                            <th scope="row" valign="top">
                                                <?php 
                        $post_type_object = get_post_type_object($post_type);
                        echo $post_type_object->labels->name;
                        ?>
                                            </th>
                                            <td>
                                                <select name="buddyforms_posttypes_default[<?php 
                        echo $post_type;
                        ?>
]"
                                                        class="regular-radio">
                                                    <option value="none">None</option>
                                                    <?php 
                        foreach ($post_types_form as $form_key => $form) {
                            ?>
                                                        <option <?php 
                            echo selected($buddyforms_posttypes_default[$post_type], $form_key, true);
                            ?>
                                                            value="<?php 
                            echo $form_key;
                            ?>
"><?php 
                            echo $form['name'];
                            ?>
</option>
                                                    <?php 
                        }
                        ?>
                                                </select>
                                            </td>
                                        </tr>
                                    <?php 
                    }
                } else {
                    echo '<h3>You need to create at least one form to select a post type default.</h3>';
                }
                ?>
                                </tbody>
                            </table>
                            <?php 
                submit_button();
                ?>

                        </form>
                        <?php 
                break;
            case 'license':
                $license = get_option('buddyforms_edd_license_key');
                $status = get_option('buddyforms_edd_license_status');
                ?>
                        <h2><?php 
                _e('Plugin License Options');
                ?>
</h2>
                        <form method="post" action="options.php">

                            <?php 
                settings_fields('buddyforms_edd_license');
                ?>

                            <table class="form-table">
                                <tbody>
                                <tr valign="top">
                                    <th scope="row" valign="top">
                                        <?php 
                _e('License Key');
                ?>
                                    </th>
                                    <td>
                                        <input id="buddyforms_edd_license_key" name="buddyforms_edd_license_key" type="text" class="regular-text" value="<?php 
                esc_attr_e($license);
                ?>
" />
                                        <label class="description" for="buddyforms_edd_license_key"><?php 
                _e('Enter your license key');
                ?>
</label>
                                    </td>
                                </tr>
                                <?php 
                if (false !== $license) {
                    ?>
                                    <tr valign="top">
                                        <th scope="row" valign="top">
                                            <?php 
                    _e('Activate License');
                    ?>
                                        </th>
                                        <td>
                                            <?php 
                    if ($status !== false && $status == 'valid') {
                        ?>
                                                <span style="color:green;"><?php 
                        _e('active');
                        ?>
</span>
                                                <?php 
                        wp_nonce_field('buddyforms_edd_nonce', 'buddyforms_edd_nonce');
                        ?>
                                                <input type="submit" class="button-secondary" name="edd_license_deactivate" value="<?php 
                        _e('Deactivate License');
                        ?>
"/>
                                            <?php 
                    } else {
                        wp_nonce_field('buddyforms_edd_nonce', 'buddyforms_edd_nonce');
                        ?>
                                                <input type="submit" class="button-secondary" name="edd_license_activate" value="<?php 
                        _e('Activate License');
                        ?>
"/>
                                            <?php 
                    }
                    ?>
                                        </td>
                                    </tr>
                                <?php 
                }
                ?>
                                </tbody>
                            </table>
                            <?php 
                submit_button();
                ?>
                        </form>
                        <?php 
                break;
            default:
                do_action('buddyforms_settings_page_tab', $tab);
                break;
        }
    }
    ?>


        </div>

    </div>

    <?php 
}