function vf_widget_discussions_control() { // Get our options and see if we're handling a form submission. $options = get_option(VF_OPTIONS_NAME); $title = vf_get_value('widget-discussions-title', $options, 'Recent Discussions'); $categoryid = (int) vf_get_value('widget-discussions-categoryid', $options); $count = (int) vf_get_value('widget-discussions-count', $options, 10); if ($_POST['widget-discussions-submit']) { // Remember to sanitize and format use input appropriately. $title = strip_tags(stripslashes($_POST['widget-discussions-title'])); $categoryid = (int) vf_get_value('widget-discussions-categoryid', $_POST); $count = (int) vf_get_value('widget-discussions-count', $_POST); $options['widget-discussions-title'] = $title; $options['widget-discussions-categoryid'] = $categoryid; $options['widget-discussions-count'] = $count; update_option(VF_OPTIONS_NAME, $options); } // Be sure you format your options to be valid HTML attributes. $title = htmlspecialchars($title, ENT_QUOTES); // Retrieve & build the category dropdown $resturl = vf_get_value('url', $options, ''); $resturl = vf_combine_paths(array($resturl, '?p=categories/all.json'), '/'); $category_data = json_decode(vf_rest($resturl)); $select_options = vf_get_select_option('All Categories', '0', $categoryid); if (is_object($category_data)) { foreach ($category_data->Categories as $Category) { $select_options .= vf_get_select_option($Category->Name, $Category->CategoryID, $categoryid); } } // Here is our little form segment. Notice that we don't need a // complete form. This will be embedded into the existing form. echo '<p><label for="widget-discussions-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-discussions-title" name="widget-discussions-title" type="text" value="' . $title . '" /></label></p>'; echo '<p><label for="widget-discussions-categoryid">' . __('Filter to Category:') . ' <select id="widget-discussions-categoryid" name="widget-discussions-categoryid">' . $select_options . '</select></label></p>'; echo '<p><label for="widget-discussions-count">' . __('Number of Discussions to show:') . ' <input style="width: 40px;" id="widget-discussions-count" name="widget-discussions-count" type="text" value="' . $count . '" /></label></p>'; echo '<input type="hidden" id="widget-discussions-submit" name="widget-discussions-submit" value="1" />'; }
/** * Vanilla Comments administration page. */ function vf_comment_admin_page() { // Check that the user has the required capability if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $options = get_option(VF_OPTIONS_NAME); $embed_comments = vf_get_value('embed-comments', $options); $resturl = vf_get_value('url', $options, ''); $resturl = vf_combine_paths(array($resturl, '?p=categories/all.json'), '/'); $categoryid = vf_get_value('embed-categoryid', $options, '0'); $matchCategories = vf_get_value('embed-matchcategories', $options, '0'); $category_data = json_decode(vf_rest($resturl)); $select_options = vf_get_select_option('No Category', '0', $categoryid); if (is_object($category_data)) { foreach ($category_data->Categories as $Category) { $select_options .= vf_get_select_option($Category->Name, $Category->CategoryID, $categoryid); } } ?> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php _e('Vanilla Comment Integration'); ?> </h2> <?php vf_open_form('embed-comments-form'); ?> <p> <label> <input type="checkbox" name="<?php echo vf_get_option_name('embed-comments'); ?> " value="1"<?php echo $embed_comments == '1' ? ' checked="checked"' : ''; ?> /> Replace your blog's native commenting system with Vanilla comments. </label> </p> <p> <label> <select name="<?php echo vf_get_option_name('embed-categoryid'); ?> "><?php echo $select_options; ?> </select> <?php echo __('Place embedded comments into the selected category.'); ?> </label> </p> <p> <label> <input type="checkbox" name="<?php echo vf_get_option_name('embed-matchcategories'); ?> " value="1"<?php echo $matchCategories == '1' ? ' checked="checked"' : ''; ?> /> <?php echo __('Try and match your Wordpress category.'); ?> </label> </p> <p class="submit"><input type="submit" name="save" value="<?php _e('Save Changes'); ?> " /></p> </form> </div> <?php }