function fp_post_set_defaults()
{
    include FRONTIER_POST_DIR . '/include/frontier_post_defaults.php';
    $fps_save_general_options = frontier_post_get_settings();
    $tmp_option_list = array_keys($fps_general_defaults);
    foreach ($tmp_option_list as $tmp_option_name) {
        if (!key_exists($tmp_option_name, $fps_save_general_options)) {
            $fps_save_general_options[$tmp_option_name] = $fps_general_defaults[$tmp_option_name];
        }
    }
    $fps_save_general_options['fps_frontier_post_version'] = FRONTIER_POST_VERSION;
    update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
}
function frontier_post_admin_page_advanced()
{
    //must 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.'));
    }
    include FRONTIER_POST_DIR . "/include/frontier_post_defaults.php";
    //echo print_r(fp_get_option("fps_custom_post_type_list"), true);
    //echo "<br>";
    //****************************************************************************
    // Save settings
    //*******************************************************************************
    // See if the user has posted us some information
    // If they did, this hidden field will be set to 'Y'
    if (isset($_POST["frontier_isupdated_advanced_hidden"]) && $_POST["frontier_isupdated_advanced_hidden"] == 'Y') {
        if (!check_admin_referer('frontier_post_admin_advanced', 'frontier_post_admin')) {
            wp_die(__("Security violation (Nonce check) - Please contact your Wordpress administrator", "frontier-post"));
        }
        $fps_save_general_options = frontier_post_get_settings();
        foreach ($fps_advanced_option_list as $tmp_option_name) {
            if (!key_exists($tmp_option_name, $fps_save_general_options)) {
                $fps_save_general_options[$tmp_option_name] = $fps_general_defaults[$tmp_option_name];
            }
            $fps_save_general_options[$tmp_option_name] = isset($_POST[$tmp_option_name]) ? $_POST[$tmp_option_name] : "";
            /*
            if (is_array($fps_save_general_options[$tmp_option_name]))
            	{
            	echo "Saving. ".$tmp_option_name." - Value: ";
            	echo print_r($fps_save_general_options[$tmp_option_name], true);
            	echo"<br>";
            	}
            else
            	echo "Saving. ".$tmp_option_name." - Value: ".$fps_save_general_options[$tmp_option_name]."<br>";
            */
        }
        if (intval($fps_save_general_options["fps_tag_count"]) == 0) {
            $fps_save_general_options["fps_tag_count"] = 3;
        }
        update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
        // Put an settings updated message on the screen
        echo '<div class="updated"><p><strong>' . __("Settings saved.", 'frontier-post') . '</strong></p></div>';
    }
    // end save settngs
    //**********************************************************************
    //* Form start
    //**********************************************************************
    // Load settings from options
    $fps_general_options = frontier_post_get_settings();
    echo '<div class="wrap">';
    echo '<div class="frontier-admin-menu">';
    echo '<h2>' . __("Frontier Post Advanced Settings", "frontier-post") . '</h2>';
    echo '<hr>' . __("Documentation", "frontier_post") . ': <a href="http://wpfrontier.com/frontier-post-advanced-settings/" target="_blank">Advanced settings</a><hr>';
    echo '<form name="frontier_post_settings" method="post" action="">';
    echo '<input type="hidden" name="frontier_isupdated_advanced_hidden" value="Y">';
    wp_nonce_field('frontier_post_admin_advanced', 'frontier_post_admin');
    echo '<table border="1" cellspacing="0" cellpadding="2">';
    echo "<tr>";
    echo "<td>" . __("Add Frontier Author user role", "frontier-post") . "</td>";
    fps_html_field("fps_author_role", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Adds a new role: Frontend Author to Wordpress", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Show ID in category list", "frontier-post") . "</td>";
    fps_html_field("fps_catid_list", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("If checked ID column will be added to the standard category list in admin panel", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Number of tags", "frontier-post") . "</td>";
    echo "<td></td>";
    if (intval($fps_general_options["fps_tag_count"]) == 0) {
        $fps_general_options["fps_tag_count"] = 3;
    }
    fps_html_field("fps_tag_count", 'text', $fps_general_options, true, 1);
    echo " " . __("number of tags to edit on the input form", "frontier-post");
    echo "</tr><tr>";
    echo "<td>" . __("Tag transformation", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_tags_transform", 'select', $fps_general_options, true, 1, $fp_tag_transform_list);
    echo "</tr><tr>";
    echo "<td>" . __("Hide post status", "frontier-post") . "</td>";
    fps_html_field("fps_hide_status", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Hide the post status on the entry form", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Input form", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_default_form", 'select', $fps_general_options, true, 1, $frontier_post_forms);
    echo "</tr><tr>";
    echo "<td>" . __("Height of editor", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_editor_lines", 'text', $fps_general_options, true, 1);
    echo "</tr><tr>";
    echo "<td>" . __("Custom login text", "frontier-post") . "</td>";
    fps_html_field("fps_use_custom_login_txt", 'checkbox', $fps_general_options, true);
    echo "<td align='left'>";
    echo '<textarea rows="4" cols="100" name="fps_custom_login_txt">' . stripslashes($fps_general_options['fps_custom_login_txt']) . '</textarea>';
    echo '<br>' . __("This text (and link) is displayed when a user is required to login", "frontier-post");
    echo ' - Default text: ' . __("Please log in !", "frontier-post") . '&nbsp;<a href="' . wp_login_url() . '">' . __("Login Page", "frontier-post") . '</a>';
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Hide title on these pages", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td>";
    echo fps_text_field("fps_hide_title_ids", $fps_general_options['fps_hide_title_ids'], 100);
    echo '<br>' . __("comma separated list of IDs", "frontier-post");
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Allow Custom Taxonomies", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td><strong>" . __("Taxonomies", "frontier-post") . ":</strong><br>";
    echo fps_checkbox_select_field("fps_custom_tax_list[]", $fps_general_options["fps_custom_tax_list"], fp_get_tax_list()) . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Default Taxonomy layout", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_default_tax_select", 'select', $fps_general_options, true, 1, array_flip($category_types));
    echo "</tr><tr>";
    echo "<td>" . __("Allow shortcode in Post Types", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td><strong>" . __("Post Types", "frontier-post") . ":</strong><br>";
    echo fps_checkbox_select_field("fps_sc_allowed_in[]", $fps_general_options["fps_sc_allowed_in"], fp_get_post_type_list());
    echo "<strong>" . __("It only recommended to allow shortcode in pages, allowing in posts can enable authors to display information they might not have access to !!", "frontier-post") . "</strong></td>";
    echo "</tr><tr>";
    echo "<td>" . __("Custom delete text", "frontier-post") . "</td>";
    echo "<td>&nbsp;</td>";
    echo "<td align='left'>";
    echo '<textarea rows="3" cols="100" name="fps_custom_delete_txt">' . stripslashes($fps_general_options['fps_custom_delete_txt']) . '</textarea>';
    echo '<br>' . __("This text is displayed when a user is confirming delete of a post", "frontier-post");
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Send email to Admins on post to approve", "frontier-post") . "</td>";
    fps_html_field("fps_mail_to_approve", 'checkbox', $fps_general_options, true);
    echo "<td>";
    echo fps_text_field("fps_mail_address", $fps_general_options['fps_mail_address'], 100);
    echo '<br>' . __("Approver email (ex: name1@domain.xx, name2@domain.xx)", "frontier-post");
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Send email to author when post is approved", "frontier-post") . "</td>";
    fps_html_field("fps_mail_approved", 'checkbox', $fps_general_options, true);
    echo "</tr><tr>";
    echo "<td>" . __("Disable control of Admin Bar", "frontier-post") . "</td>";
    fps_html_field("fps_disable_abar_ctrl", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("If this is checked, frontier post will not enable/disable the admin bar (Check this if another plugin is enabling/disabling the admin bar to avoid conflict)", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Keep Frontier Post settings on uninstall", "frontier-post") . "</td>";
    fps_html_field("fps_keep_options_uninstall", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("If this is checked, the Frontier Settings will not be deleted on uninstall", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Template directory", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td>";
    echo frontier_template_dir();
    // check if frontuier post templates are used
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_standard.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_standard.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_old.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_old.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_simple.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_simple.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_list.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_list.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_page.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_page.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier_post_form_preview.php"), false, true)) {
        echo "<br /><strong><font color='red'> frontier_post_form_preview.php </font> " . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    if (locate_template(array('/plugins/frontier-post/' . "frontier-post.css"), false, true)) {
        echo "<br /><strong><font color='red'> frontier-post.css </font>" . __("exists in the template directory", "fontier-post") . "</strong>";
    }
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Set Capabilities externally", "frontier-post") . "</td>";
    fps_html_field("fps_external_cap", 'checkbox', $fps_general_options, true);
    echo '<td>' . __("If checked capabilities will be managed from external plugin ex.: User Role Editor", "frontier-post") . '</td>';
    echo "</tr><tr>";
    if (fp_get_option_bool("fps_external_cap")) {
        echo "<td>" . __("Default Editor", "frontier-post") . "</td>";
        fps_html_field("fps_default_editor", 'select', $fps_general_options, true, 1, array_flip($editor_types));
        echo "</tr><tr>";
        echo "<td>" . __("Default category select", "frontier-post") . "</td>";
        fps_html_field("fps_default_cat_select", 'select', $fps_general_options, true, 1, array_flip($category_types));
        echo "</tr><tr>";
    }
    echo "</tr><tr>";
    echo "<td>" . __("Use tinymce Word count", "frontier-post") . "</td>";
    fps_html_field("fps_tinymce_wordcount", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("If this is checked, the tinymce Wordcount will be used instead of standard wordcount", "frontier-post") . "</td>";
    echo "</tr><tr>";
    $tmp_edit_link_types = array("post" => __("Post", "frontier-post"), "page" => __("Page", "frontier-post"));
    echo "<td>" . __("Super Admin Edit Link", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td><strong>" . __("Redirect to Frontier Post edit form for the below post types", "frontier-post") . ":</strong><br>";
    echo fps_checkbox_select_field("fps_sc_super_admin_types[]", $fps_general_options["fps_sc_super_admin_types"], $tmp_edit_link_types);
    echo "" . __("If above post types are checked, the standard Wordpress edit link is changed to point at Frontier Post, as opposed to the backend.", "frontier-post") . "</td>";
    // moderation
    echo "</tr><tr>";
    echo "<th colspan='3'>Post Moderation<th>";
    echo "</tr><tr>";
    echo "<td>" . __("Activate post moderation", "frontier-post") . "</td>";
    fps_html_field("fps_use_moderation", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("If this is checked, moderation comments can be edited on the post form", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Cache time for taxonomy lists", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_cache_time_tax_lists", 'select', $fps_general_options, true, 1, $fp_cache_time_list);
    echo '</tr></table>';
    echo '<p class="submit"><input type="submit" name="Submit" class="button-primary" value="' . __('Save Changes') . '"></p>';
    echo '</form>';
    echo '<hr>';
    echo '</div>';
    //frontier-admin-menu
    echo '</div>';
    //wrap
}
function frontier_post_admin_page_general()
{
    //must 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.'));
    }
    require FRONTIER_POST_DIR . "/include/frontier_post_defaults.php";
    //include("../include/frontier_post_defaults.php");
    echo '<strong>Frontier Post  - Version: ' . FRONTIER_POST_VERSION . '</strong>';
    // ****************************************************************************
    // Save settings
    //*******************************************************************************
    // See if the user has posted us some information
    // If they did, this hidden field will be set to 'Y'
    if (isset($_POST["frontier_isupdated_general_hidden"]) && $_POST["frontier_isupdated_general_hidden"] == 'Y') {
        $fps_save_general_options = frontier_post_get_settings();
        foreach ($fps_general_option_list as $tmp_option_name) {
            if (!key_exists($tmp_option_name, $fps_save_general_options)) {
                $fps_save_general_options[$tmp_option_name] = $fps_general_defaults[$tmp_option_name];
            }
            $fps_save_general_options[$tmp_option_name] = isset($_POST[$tmp_option_name]) ? $_POST[$tmp_option_name] : "";
            //echo "Saving. ".$tmp_option_name." - Value: ".$fps_save_general_options[$tmp_option_name]."<br>";
        }
        update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
        // Put an settings updated message on the screen
        echo '<div class="updated"><p><strong>' . __('Settings saved.', 'frontier-post') . '</strong></p></div>';
    }
    // end update options
    $fps_general_options = frontier_post_get_settings();
    $fps_post_status_list = get_post_statuses();
    echo '<div class="wrap">';
    echo '<div class="frontier-admin-menu">';
    echo '<h2>' . __("Frontier Post Settings", "frontier-post") . '</h2>';
    echo '<hr>' . __("Documentation", "frontier_post") . ': <a href="http://wpfrontier.com/frontier-post-settings/" target="_blank">General Settings</a>';
    echo ' - <a href="http://wpfrontier.com/frontier-post-shortcodes/" target="_blank">Shortcodes</a><hr>';
    echo '<form name="frontier_post_settings" method="post" action="">';
    echo '<input type="hidden" name="frontier_isupdated_general_hidden" value="Y">';
    echo '<table border="1" cellspacing="0" cellpadding="0">';
    echo "<tr>";
    echo "<td>" . __("Allow edit of posts with comments", "frontier-post") . "</td>";
    fps_html_field("fps_edit_w_comments", 'checkbox', $fps_general_options, true);
    echo "<td>" . __("Max age in days to allow edit of post", "frontier-post") . "</td>";
    fps_html_field("fps_edit_max_age", 'text', $fps_general_options, true);
    echo "</tr><tr>";
    echo "<td>" . __("Allow deletion of posts with comments", "frontier-post") . "</td>";
    fps_html_field("fps_del_w_comments", 'checkbox', $fps_general_options, true);
    echo "<td>" . __("Max age in days to allow delete of post", "frontier-post") . "</td>";
    fps_html_field("fps_delete_max_age", 'text', $fps_general_options, true);
    echo "</tr><tr>";
    echo "<td>" . __("Number of post per page", "frontier-post") . "</td>";
    fps_html_field("fps_ppp", 'text', $fps_general_options, true);
    echo "<td>" . __("Page containing [frontier-post] shortcode", "frontier-post") . "</td>";
    echo "<td>";
    wp_dropdown_pages(array('name' => 'fps_page_id', 'id' => 'fps_page_id', 'dept' => 1, 'hide_empty' => 0, 'selected' => $fps_general_options['fps_page_id'], 'hierarchical' => true, 'show_option_none' => __('None')));
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Default status for new posts", "frontier-post") . "</td>";
    fps_html_field("fps_default_status", 'select', $fps_general_options, true, 1, $fps_post_status_list);
    echo "<td>" . __("Page for pending posts ", "frontier-post") . "</td>";
    echo "<td>";
    wp_dropdown_pages(array('name' => 'fps_pending_page_id', 'id' => 'fps_pending_page_id', 'dept' => 1, 'hide_empty' => 0, 'selected' => $fps_general_options['fps_pending_page_id'], 'hierarchical' => true, 'show_option_none' => __('None')));
    echo "</td>";
    echo '</tr></table><hr>';
    //*****************************************************************************
    // Additional options
    //*****************************************************************************
    //echo '<hr>';
    //echo '<h2>'.__("Additional options", "frontier-post").'</h2>';
    echo '<table border="1" cellspacing="	"2" cellpadding="1">';
    echo "<tr>";
    echo '<th colspan="3"></center>' . __("Additional options", "frontier-post") . '</center></th>';
    echo "</tr><tr>";
    echo "<td>" . __("Allow users to change status from Published", "frontier-post") . "</td>";
    fps_html_field("fps_change_status", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Once published users can change status back to draft/pending", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Use featured image", "frontier-post") . "</td>";
    fps_html_field("fps_show_feat_img", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Enables selection of featured image from frontend form ", "frontier-post") . "(does not work perfectly)</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Show link to login page", "frontier-post") . "</td>";
    fps_html_field("fps_show_login", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Shows link to wp-login.php after text: Please login", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Show add/update/delete messages", "frontier-post") . "</td>";
    fps_html_field("fps_show_msg", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Show message on the form confirming a post has been added/updated/deleted", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Show edit/delete/view icons in list", "frontier-post") . "</td>";
    fps_html_field("fps_use_icons", 'checkbox', $fps_general_options, true, 1);
    $tmptext = "<td>" . __("Show icons instead of text for edit/delete/view in list", "frontier-post");
    $tmptext .= "&nbsp" . '<img height="12px" src="' . FRONTIER_POST_URL . '/images/edit.png' . '"></img>';
    $tmptext .= "&nbsp" . '<img height="12px" src="' . FRONTIER_POST_URL . '/images/delete.png' . '"></img>';
    $tmptext .= "&nbsp" . '<img height="12px" src="' . FRONTIER_POST_URL . '/images/view.png' . '"></img>';
    $tmptext .= "</td>";
    echo $tmptext;
    echo "</tr><tr>";
    echo "<td>" . __("Hide Add New Post link on list", "frontier-post") . "</td>";
    fps_html_field("fps_hide_add_on_list", 'checkbox', $fps_general_options, true, 1);
    echo "<td>" . __("Hide add new post on list form", "frontier-post") . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Show submit buttons on post edit form", "frontier-post") . "</td>";
    echo "<td></td>";
    echo '<td>';
    echo '&nbsp;' . __("Save", "frontier-post") . '&nbsp;' . fps_checkbox_field("fps_submit_save", $fps_general_options['fps_submit_save']);
    echo '&nbsp;|&nbsp' . __("Save & Return", "frontier-post") . '&nbsp;' . fps_checkbox_field("fps_submit_savereturn", $fps_general_options['fps_submit_savereturn']);
    echo '&nbsp;|&nbsp' . __("Save & Preview", "frontier-post") . '&nbsp;' . fps_checkbox_field("fps_submit_preview", $fps_general_options['fps_submit_preview']);
    echo '&nbsp;|&nbsp' . __("Cancel", "frontier-post") . '&nbsp;' . fps_checkbox_field("fps_submit_cancel", $fps_general_options['fps_submit_cancel']);
    echo "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("Allowed Post Types", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td><strong>" . __("Post Types", "frontier-post") . ":</strong><br>";
    echo fps_checkbox_select_field("fps_custom_post_type_list[]", $fps_general_options["fps_custom_post_type_list"], fp_get_post_type_list()) . "</td>";
    echo "</tr><tr>";
    echo "<td>" . __("List Layout", "frontier-post") . "</td>";
    echo "<td></td>";
    fps_html_field("fps_default_list", 'select', $fps_general_options, true, 1, $frontier_list_forms);
    echo "</tr><tr>";
    echo "<td>" . __("Exclude categories", "frontier-post") . "</td>";
    echo "<td></td>";
    echo "<td>";
    echo fps_text_field("fps_excl_cats", $fps_general_options['fps_excl_cats'], 100);
    echo '<br>' . __('comma separated list of IDs', 'frontier-post');
    echo "</td>";
    echo '</tr></table>';
    echo '<p class="submit"><input type="submit" name="Submit" class="button-primary" value="' . __('Save Changes') . '"></p>';
    echo '</form>';
    echo '<hr>';
    echo '</div>';
    //frontier-admin-menu
    echo '</div>';
    //wrap
}
//
//**********************************************************************************
if (is_admin()) {
    $fp_last_upgrade = fp_get_option('fps_options_migrated_version', get_option("frontier_post_version", '0.0.0'));
    // Upgrade old versions, but dont run upgrade if fresh install
    if ($fp_last_upgrade != '0.0.0' && version_compare($fp_last_upgrade, '3.1.0') < 0) {
        include FRONTIER_POST_DIR . "/admin/frontier-post-convert-options.php";
        // run the migration
        fps_cnv_general_options();
    }
    // Normal version update to capture new settings etc
    $fp_version = fp_get_option('fps_frontier_post_version', '0.0.0');
    // Update defaults, but dont if fresh install - Must be the activation trigger
    // Changed in v 3.5.2, always check for updates
    if (version_compare(FRONTIER_POST_VERSION, $fp_version, '>')) {
        $fps_save_general_options = frontier_post_get_settings();
        $tmp_option_list = array_keys($fps_general_defaults);
        foreach ($tmp_option_list as $tmp_option_name) {
            if (!key_exists($tmp_option_name, $fps_save_general_options)) {
                $fps_save_general_options[$tmp_option_name] = $fps_general_defaults[$tmp_option_name];
            }
        }
        $fps_save_general_options['fps_frontier_post_version'] = FRONTIER_POST_VERSION;
        update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
        fp_delete_widget_cache();
    }
}
//**********************************************************************************
// Main program
//
//**********************************************************************************
function frontier_post_set_defaults()
{
    if (!defined('FRONTIER_POST_SETTINGS_OPTION_NAME')) {
        define('FRONTIER_POST_SETTINGS_OPTION_NAME', "frontier_post_general_options");
    }
    if (!defined('FRONTIER_POST_CAPABILITY_OPTION_NAME')) {
        define('FRONTIER_POST_CAPABILITY_OPTION_NAME', "frontier_post_capabilities");
    }
    include FRONTIER_POST_DIR . '/include/frontier_post_defaults.php';
    $fp_last_upgrade = fp_get_option('fps_options_migrated_version', get_option("frontier_post_version", '0.0.0'));
    // Upgrade old versions, but dont run upgrade if fresh install
    if ($fp_last_upgrade != '0.0.0' && version_compare($fp_last_upgrade, '3.3.0') < 0) {
        include FRONTIER_POST_DIR . '/admin/frontier-post-convert-options.php';
        fps_cnv_general_options(true);
        $fp_upgrade_msg = 'Frontier Post - Settings upgraded from version: ' . $fp_last_upgrade . ' to version: ' . FRONTIER_POST_VERSION;
    } else {
        //******************************************************************************
        // add settings if not already there
        //******************************************************************************
        if (!fp_get_option_bool('fps_keep_options_uninstall', false)) {
            // Set default capabilities
            $saved_capabilities = frontier_post_get_capabilities();
            // administrators capabilities
            $tmp_administrator_cap = array('frontier_post_can_add' => 'true', 'frontier_post_can_edit' => 'true', 'frontier_post_can_delete' => 'true', 'frontier_post_can_publish' => 'true', 'frontier_post_can_draft' => 'true', 'frontier_post_can_pending' => 'true', 'frontier_post_can_private' => 'true', 'frontier_post_redir_edit' => 'true', 'frontier_post_show_admin_bar' => 'true', 'frontier_post_exerpt_edit' => 'true', 'frontier_post_tags_edit' => 'true', 'frontier_post_can_media' => 'true', 'frontier_post_can_page' => 'true', 'fps_role_editor_type' => 'full', 'fps_role_category_layout' => 'multi', 'fps_role_default_category' => get_option("default_category"), 'fps_role_allowed_categories' => '');
            // editor
            $tmp_editor_cap = $tmp_administrator_cap;
            // Author
            $tmp_author_cap = $tmp_editor_cap;
            $tmp_author_cap['frontier_post_can_private'] = 'false';
            $tmp_author_cap['frontier_post_show_admin_bar'] = 'false';
            $tmp_author_cap['frontier_post_can_page'] = 'false';
            // Contributor
            $tmp_contributor_cap = $tmp_author_cap;
            $tmp_contributor_cap['frontier_post_can_delete'] = 'false';
            $tmp_contributor_cap['frontier_post_can_publish'] = 'false';
            $tmp_contributor_cap['frontier_post_redir_edit'] = 'false';
            $tmp_contributor_cap['frontier_post_tags_edit'] = 'false';
            $tmp_contributor_cap['frontier_post_can_media'] = 'false';
            $tmp_contributor_cap['fps_role_editor_type'] = 'minimal-visual';
            // Subscriber
            $tmp_subscriber_cap = $tmp_contributor_cap;
            $tmp_subscriber_cap['frontier_post_can_add'] = 'false';
            $tmp_subscriber_cap['frontier_post_can_edit'] = 'false';
            $tmp_subscriber_cap['frontier_post_can_pending'] = 'false';
            $tmp_subscriber_cap['frontier_post_can_draft'] = 'false';
            $wp_roles = new WP_Roles();
            $roles = $wp_roles->get_names();
            $saved_capabilities = frontier_post_get_capabilities();
            foreach ($roles as $key => $item) {
                switch ($key) {
                    case 'administrator':
                        $tmp_cap_list = $tmp_administrator_cap;
                        break;
                    case 'editor':
                        $tmp_cap_list = $tmp_editor_cap;
                        break;
                    case 'author':
                        $tmp_cap_list = $tmp_author_cap;
                        break;
                    case 'frontier-author':
                        $tmp_cap_list = $tmp_author_cap;
                        break;
                    case 'contributor':
                        $tmp_cap_list = $tmp_contributor_cap;
                        break;
                    case 'subscriber':
                        $tmp_cap_list = $tmp_subscriber_cap;
                        break;
                    default:
                        $tmp_cap_list = $tmp_contributor_cap;
                        break;
                }
                $saved_capabilities[$key] = $tmp_cap_list;
            }
            // roles
            // Save options
            update_option(FRONTIER_POST_CAPABILITY_OPTION_NAME, $saved_capabilities);
        }
        // end update settings if not saved from during previous uninstall
    }
    //end Upgrade or not
    // update default settings
    fp_post_set_defaults();
    // Set Wordpress capabilities
    frontier_post_set_cap();
    global $wpdb;
    // Check if page containing [frontier-post] exists already, else create it
    $tmp_id = $wpdb->get_var("SELECT id \r\n\t\t  FROM {$wpdb->posts} \r\n\t\t  WHERE post_type='page' AND \r\n\t\t  post_status='publish' AND \r\n\t\t post_content LIKE '%[frontier-post]%'\r\n\t\t");
    if ((int) $tmp_id <= 0) {
        // Add new page
        $my_page = array('post_title' => __('My Posts', 'frontier-post'), 'post_content' => '[frontier-post]', 'post_status' => 'publish', 'comment_status' => 'closed', 'post_type' => 'page', 'ping_status' => 'closed');
        // Insert the page into the database
        $tmp_id = wp_insert_post($my_page);
        // save page id
        $fps_save_general_options = frontier_post_get_settings();
        $fps_save_general_options['fps_page_id'] = $tmp_id;
        update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
    } else {
        if (fp_get_option_int('fps_page_id', 0) === 0) {
            // save page id
            $fps_save_general_options = frontier_post_get_settings();
            $fps_save_general_options['fps_page_id'] = $tmp_id;
            update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_save_general_options);
        }
    }
    //save to options that capabilities has been migrated
    $fps_general_options = frontier_post_get_settings();
    $fps_general_options['fps_options_migrated'] = "true";
    $fps_general_options['fps_options_migrated_version'] = FRONTIER_POST_VERSION;
    update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_general_options);
    // Put an updated message on the screen - NO NO, Cant do that in activation script.
    //echo '<div class="updated"><p><strong>'.__("Frontier Post - Default settings and capabilities set - Please review settings and capabilities", 'frontier-post' ).'</strong></p></div>';
}
Example #6
0
function fp_get_option_bool($tmp_option_name)
{
    $fp_settings = frontier_post_get_settings();
    if (array_key_exists($tmp_option_name, $fp_settings)) {
        $tmp_value = $fp_settings[$tmp_option_name] ? $fp_settings[$tmp_option_name] : "false";
        return fp_bool($tmp_value);
    } else {
        return false;
    }
}
function fp_get_option_bool($tmp_option_name)
{
    $fp_settings = frontier_post_get_settings();
    if (array_key_exists($tmp_option_name, $fp_settings)) {
        $tmp_value = $fp_settings[$tmp_option_name] ? $fp_settings[$tmp_option_name] : "false";
        if (in_array($tmp_value, array('true', 'True', 'TRUE', 'yes', 'Yes', 'y', 'Y', '1', 'on', 'On', 'ON', true, 1), true)) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
function frontier_post_admin_list_cap()
{
    //must 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.'));
    }
    global $wpdb;
    // Show content statistics
    $fp_sql = "SELECT post_status, post_type, count(*) as post_count FROM {$wpdb->posts} GROUP BY post_type, post_status ORDER BY post_type, post_status;";
    $fp_stat = $wpdb->get_results($fp_sql);
    echo '<hr>';
    echo '<h2>Post DB content breakdown</strong></h2>';
    echo '<table border="1" cellpadding="2" cellspacing="4"><tr><th>Post Type</th><th>Post Status</th><th>record count</th></tr>';
    foreach ($fp_stat as $stat) {
        echo '<tr>';
        echo '<td>' . $stat->post_type . '</td>';
        echo '<td>' . $stat->post_status . '</td>';
        echo '<td align="right">' . $stat->post_count . '</td>';
        echo '</tr>';
    }
    echo '</table>';
    echo '<h2>Frontier Option values per role</strong></h2>';
    echo '<hr>';
    echo '<table border="1" cellpadding="2" cellspacing="4"><tr><th>key</th><th>Value</th></tr>';
    $fps_general_options = frontier_post_get_settings();
    foreach ($fps_general_options as $key => $value) {
        echo '<tr>';
        echo '<td>' . $key . '</td>';
        if (is_array($value)) {
            echo '<td>' . print_r($value, true) . '</td>';
        } else {
            echo '<td>' . $value . '</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
    echo '<h2>List capabilties per role</strong></h2>';
    echo '<hr>';
    // Reinstate roles
    $wp_roles = new WP_Roles();
    $roles = $wp_roles->get_names();
    $roles = array_reverse($roles);
    foreach ($roles as $key => $item) {
        $xrole = get_role($key);
        $xrole_caps = $xrole->capabilities;
        echo '<strong>' . $item . '</strong><br>';
        foreach ($xrole_caps as $tmp_cap_name => $tmp_cap) {
            //echo 'pos: '.strpos($tmp_cap_name, "rontier_post").'  -  ';
            if (strpos($tmp_cap_name, "rontier_post") == 1) {
                echo '<strong>' . $tmp_cap_name . '</strong><br>';
            } else {
                echo $tmp_cap_name . '<br>';
            }
        }
        echo '<hr>';
    }
    echo '<hr>';
    echo '<h2>List frontier options</strong></h2>';
    $fp_sql = "SELECT option_name  FROM {$wpdb->options} WHERE option_name LIKE 'frontier_post%';";
    $fp_options = $wpdb->get_results($fp_sql);
    foreach ($fp_options as $option) {
        echo $option->option_name . '<br>';
    }
    echo '<hr>';
}
function fps_cnv_general_options($suppress_output = false)
{
    // Move values from old single options to new array based options
    include FRONTIER_POST_DIR . "/include/frontier_post_defaults.php";
    $frontier_submit_buttons = get_option("frontier_post_submit_buttons", array('save' => 'true', 'savereturn' => 'true', 'preview' => 'true', 'cancel' => 'true'));
    $cnv_table = array('fps_edit_max_age' => get_option('frontier_post_edit_max_age', 10), 'fps_delete_max_age' => get_option('frontier_post_delete_max_age', 3), 'fps_ppp' => get_option('frontier_post_ppp', 25), 'fps_page_id' => get_option('frontier_post_page_id', 0), 'fps_del_w_comments' => get_option("frontier_post_del_w_comments", "false"), 'fps_edit_w_comments' => get_option("frontier_post_edit_w_comments", "false"), 'fps_author_role' => get_option("frontier_post_author_role", "false"), 'fps_mail_to_approve' => get_option("frontier_post_mail_to_approve", "false"), 'fps_mail_approved' => get_option("frontier_post_mail_approved", "false"), 'fps_mail_address' => get_option("frontier_post_mail_address", ""), 'fps_excl_cats' => get_option("frontier_post_excl_cats", ""), 'fps_show_feat_img' => get_option("frontier_post_show_feat_img", "false"), 'fps_show_login' => get_option("frontier_post_show_login", "false"), 'fps_change_status' => get_option("frontier_post_change_status", "true"), 'fps_catid_list' => get_option("frontier_post_catid_list", ""), 'fps_editor_lines' => get_option('frontier_post_editor_lines', 300), 'fps_default_status' => get_option("frontier_default_status", "publish"), 'fps_hide_status' => get_option("frontier_post_hide_status", "false"), 'fps_show_msg' => get_option("frontier_post_show_msg", "false"), 'fps_hide_title_ids' => get_option("frontier_post_hide_title_ids", ""), 'fps_default_editor' => get_option("frontier_default_editor", "full"), 'fps_default_cat_select' => get_option("frontier_default_cat_select", "multi"), 'fps_external_cap' => get_option("frontier_post_external_cap", "false"), 'fps_submit_save' => $frontier_submit_buttons['save'], 'fps_submit_savereturn' => $frontier_submit_buttons['savereturn'], 'fps_submit_preview' => $frontier_submit_buttons['preview'], 'fps_submit_cancel' => $frontier_submit_buttons['cancel']);
    $fps_save_general_options['fps_frontier_post_version'] = FRONTIER_POST_VERSION;
    update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $cnv_table);
    //Update default values for settings that doesnt exists.
    fp_post_set_defaults();
    // Rolebased settings
    $old_capabilities = get_option('frontier_post_options', array());
    $wp_roles = new WP_Roles();
    $roles = $wp_roles->get_names();
    $tmp_array = array_merge($fp_capability_list, $fp_role_option_list);
    $tmp_cap_list = array_keys($tmp_array);
    $saved_capabilities = frontier_post_get_capabilities();
    // Loop through the roles
    foreach ($roles as $key => $item) {
        $xrole = get_role($key);
        if (!array_key_exists($key, $saved_capabilities)) {
            $saved_capabilities[$key] = array();
        }
        if (!array_key_exists($key, $old_capabilities)) {
            $old_capabilities[$key] = array();
        }
        // set capabilities
        foreach ($tmp_cap_list as $tmp_cap) {
            $xrole_old_cap = $old_capabilities[$key];
            $xrole_cap = $saved_capabilities[$key];
            $old_cap_name = str_replace('frontier_post_', '', $tmp_cap);
            $def_value = "false";
            if ($tmp_cap == 'fps_role_editor_type') {
                $def_value = "minimal-visual";
                $old_cap_name = 'editor';
            }
            if ($tmp_cap == 'fps_role_category_layout') {
                $def_value = "multi";
                $old_cap_name = 'category';
            }
            if ($tmp_cap == 'fps_role_default_category') {
                $def_value = get_option("default_category");
                $old_cap_name = 'default_category';
            }
            if (array_key_exists($old_cap_name, $xrole_old_cap)) {
                $saved_capabilities[$key][$tmp_cap] = $xrole_old_cap[$old_cap_name];
            } else {
                if (!array_key_exists($tmp_cap, $xrole_cap)) {
                    $saved_capabilities[$key][$tmp_cap] = $def_value;
                }
            }
        }
        //caps
    }
    // roles
    // Save options
    update_option(FRONTIER_POST_CAPABILITY_OPTION_NAME, $saved_capabilities);
    // Set Wordpress capabilities
    frontier_post_set_cap();
    //save to options that capabilities has been migrated
    $fps_general_options = frontier_post_get_settings();
    $fps_general_options['fps_options_migrated'] = "true";
    $fps_general_options['fps_options_migrated_version'] = FRONTIER_POST_VERSION;
    update_option(FRONTIER_POST_SETTINGS_OPTION_NAME, $fps_general_options);
    $fp_last_upgrade = fp_get_option('fps_options_migrated_version', get_option("frontier_post_version", '0.0.0'));
    $fp_upgrade_msg = 'Frontier Post - Settings upgraded from version: ' . $fp_last_upgrade . ' to version: ' . FRONTIER_POST_VERSION;
    if (!$suppress_output) {
        echo '<div class="updated"><p><strong>' . $fp_upgrade_msg . '</strong></p></div>';
    }
    // Finally delete frontier_post_version
    delete_option("frontier_post_version");
}