function frontier_posting_form_submit($frontier_post_shortcode_parms = array())
{
    extract($frontier_post_shortcode_parms);
    global $current_user;
    // which button has been pressed
    $tmp_return = isset($_POST['user_post_submit']) ? $_POST['user_post_submit'] : "savereturn";
    //Get Frontier Post capabilities
    $fp_capabilities = frontier_post_get_capabilities();
    if (isset($_POST['action']) && $_POST['action'] == "wpfrtp_save_post") {
        if (!wp_verify_nonce($_POST['frontier_add_edit_post_' . $_POST['postid']], 'frontier_add_edit_post')) {
            wp_die(__("Security violation (Nonce check) - Please contact your Wordpress administrator", "frontier-post"));
        }
        if (isset($_REQUEST['task']) && $_REQUEST['task'] == "new") {
            $tmp_task_new = true;
        } else {
            $tmp_task_new = false;
        }
        //fp_log("New post ? : ".$tmp_task_new);
        if (isset($_POST['post_status'])) {
            $post_status = $_POST['post_status'];
        } else {
            $post_status = 'draft';
        }
        //Check if Publish has been pressed
        if ($tmp_return === "publish" && current_user_can("frontier_post_can_publish")) {
            $post_status = 'publish';
        }
        $tmp_post_type = isset($_POST['posttype']) ? $_POST['posttype'] : 'post';
        $postid = $_POST['postid'];
        $tmp_title = trim($_POST['user_post_title']);
        $tmp_content = trim($_POST['user_post_desc']);
        // check empty title, and set status to draft if status is empty
        if (empty($tmp_title)) {
            if (strlen($tmp_content) > 20) {
                $tmp_title = wp_trim_words($tmp_content, 10);
            } else {
                $tmp_title = __("No Title", "frontier-post");
            }
            $post_status = 'draft';
            frontier_post_set_msg('<div id="frontier-post-alert">' . __("Warning", "frontier-post") . ': ' . __("Title was empty", "frontier-post") . ' - ' . __("Post status set to draft", "frontier-post") . '</div>');
        }
        $tmp_title = trim(strip_tags($tmp_title));
        if (empty($tmp_content)) {
            $tmp_content = __("No content", "frontier-post");
            $post_status = 'draft';
            frontier_post_set_msg('<div id="frontier-post-alert">' . __("Warning", "frontier-post") . ': ' . __("Content was empty", "frontier-post") . ' - ' . __("Post status set to draft", "frontier-post") . '</div>');
        }
        $tmp_excerpt = isset($_POST['user_post_excerpt']) ? trim($_POST['user_post_excerpt']) : null;
        $users_role = frontier_get_user_role();
        //****************************************************************************************************
        // Manage Categories
        //****************************************************************************************************
        // Do not manage categories for page
        if ($tmp_post_type != 'page') {
            $category_type = $fp_capabilities[$users_role]['fps_role_category_layout'] ? $fp_capabilities[$users_role]['fps_role_category_layout'] : "multi";
            $default_category = $fp_capabilities[$users_role]['fps_role_default_category'] ? $fp_capabilities[$users_role]['fps_role_default_category'] : get_option("default_category");
            $tmp_field_name = frontier_tax_field_name('category');
            if ($category_type != "hide" && $category_type != "readonly") {
                $tmp_categorymulti = isset($_POST[$tmp_field_name]) ? $_POST[$tmp_field_name] : array();
            }
            //frontier_post_set_msg("Default Category: ".$default_category);
            //frontier_post_set_msg("Post Categories: ".( isset($_POST['post_categories']) ? $_POST['post_categories'] : "NONE"));
            // if no category returned from entry form, check for hidden field, if this is empty set default category
            if (!isset($tmp_categorymulti) || count($tmp_categorymulti) == 0) {
                $tmp_categorymulti = isset($_POST['post_categories']) ? explode(',', $_POST['post_categories']) : array();
                // Do not use default category if post type = page
                if ($tmp_post_type != 'page') {
                    $tmp_categorymulti = count($tmp_categorymulti) > 0 && isset($tmp_categorymulti[0]) && $tmp_categorymulti[0] > 0 ? $tmp_categorymulti : array($default_category);
                }
            }
            //frontier_post_set_msg("Category from POST: ".print_r($tmp_categorymulti,true));
        }
        // do not manage categories for pages
        //****************************************************************************************************
        // Update post
        //****************************************************************************************************
        $tmp_post = array('ID' => $postid, 'post_type' => $tmp_post_type, 'post_title' => $tmp_title, 'post_status' => $post_status, 'post_content' => $tmp_content, 'post_excerpt' => $tmp_excerpt);
        // Do not manage categories for page
        if ($tmp_post_type != 'page') {
            $tmp_post['post_category'] = $tmp_categorymulti;
        }
        //****************************************************************************************************
        // Apply filter before update of post
        // filter:			frontier_post_pre_update
        // $tmp_post 		Array that holds the updated fields
        // $tmp_task_new  	Equals true if the user is adding a post
        // $_POST			Input form
        //****************************************************************************************************
        $tmp_post = apply_filters('frontier_post_pre_update', $tmp_post, $tmp_task_new, $_POST);
        //Set $post_status to tmp_post value, if changed by filter
        $post_status = $tmp_post['post_status'];
        //force save with draft status first, if new post and status is set to published to align with wordpress standard
        if ($tmp_task_new == true && $post_status == "publish") {
            $tmp_post['post_status'] = "draft";
            wp_update_post($tmp_post);
            $tmp_post = array('ID' => $postid, 'post_status' => $post_status);
            wp_update_post($tmp_post);
        } else {
            wp_update_post($tmp_post);
        }
        //****************************************************************************************************
        // Tags
        //****************************************************************************************************
        // Do not manage tags for page
        if (current_user_can('frontier_post_tags_edit') && $tmp_post_type != 'page') {
            $fp_tag_count = fp_get_option_int("fps_tag_count", 3);
            $taglist = array();
            for ($i = 0; $i < $fp_tag_count; $i++) {
                if (isset($_POST['user_post_tag' . $i])) {
                    array_push($taglist, fp_tag_transform($_POST['user_post_tag' . $i]));
                }
            }
            wp_set_post_tags($postid, $taglist);
        }
        //****************************************************************************************************
        // Add/Update message
        //****************************************************************************************************
        if ($tmp_task_new == true) {
            frontier_post_set_msg(__("Post added", "frontier-post") . ": " . $tmp_title);
        } else {
            frontier_post_set_msg(__("Post updated", "frontier-post") . ": " . $tmp_title);
        }
        //****************************************************************************************************
        // Taxonomies
        //****************************************************************************************************
        // Do not manage taxonomies for page
        if ($tmp_post_type != 'page') {
            foreach ($frontier_custom_tax as $tmp_tax_name) {
                if (!empty($tmp_tax_name) && $tmp_tax_name != 'category') {
                    $tmp_field_name = frontier_tax_field_name($tmp_tax_name);
                    $tmp_value = isset($_POST[$tmp_field_name]) ? $_POST[$tmp_field_name] : array();
                    if (is_array($tmp_value)) {
                        $tmp_tax_selected = $tmp_value;
                    } else {
                        $tmp_tax_selected = array($tmp_value);
                    }
                    wp_set_post_terms($postid, $tmp_tax_selected, $tmp_tax_name);
                    //error_log("set terms: ".$tmp_tax_name." : ". print_r($tmp_tax_selected,true));
                }
            }
        }
        // end do not manage taxonomies for pages
        //****************************************************************************************************
        // End updating post
        //****************************************************************************************************
        //Get the updated post
        $my_post = get_post($postid);
        // Delete users cache for My Posts widget
        fp_delete_my_post_w_cache();
        //***************************************************************************************
        //* Save post moderation fields
        //***************************************************************************************
        if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $my_post->post_author)) {
            if (isset($_POST['frontier_post_moderation_new_text'])) {
                $fp_moderation_comments_new = $_POST['frontier_post_moderation_new_text'];
                //$fp_moderation_comments_new = trim(stripslashes(strip_tags($fp_moderation_comments_new)));
                $fp_moderation_comments_new = wp_strip_all_tags($fp_moderation_comments_new);
                $fp_moderation_comments_new = nl2br($fp_moderation_comments_new);
                $fp_moderation_comments_new = stripslashes($fp_moderation_comments_new);
                $fp_moderation_comments_new = trim($fp_moderation_comments_new);
                if (strlen($fp_moderation_comments_new) > 0) {
                    global $current_user;
                    $fp_moderation_comments_old = get_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_TEXT', true);
                    $fp_moderation_comments = current_time('mysql') . " - " . $current_user->user_login . ":<br>";
                    $fp_moderation_comments .= $fp_moderation_comments_new . "<br>";
                    $fp_moderation_comments .= '<hr>' . "<br>";
                    $fp_moderation_comments .= $fp_moderation_comments_old . "<br>";
                    update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_TEXT', $fp_moderation_comments);
                    update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_DATE', current_time('mysql'));
                    update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_FLAG', 'true');
                    // Email author on moderation comments
                    if (isset($_POST['frontier_post_moderation_send_email']) && $_POST['frontier_post_moderation_send_email'] == "true") {
                        $to = get_the_author_meta('email', $my_post->post_author);
                        $subject = __("Moderator has commented your pending post", "frontier-post") . " (" . get_bloginfo("name") . ")";
                        $body = __("Moderator has commented your pending post", "frontier-post") . ": " . $my_post->post_title . " (" . get_bloginfo("name") . ")" . "\r\n\r\n";
                        $body .= "Comments: " . $_POST['frontier_post_moderation_new_text'] . "\r\n\r\n";
                        if (!wp_mail($to, $subject, $body)) {
                            frontier_post_set_msg(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")");
                        }
                    }
                }
            }
        }
        //****************************************************************************************************
        // Action fires after add/update of post, and after taxonomies are updated
        // Do action 		frontier_post_post_save
        // $my_post 		Post object for the post just updated
        // $tmp_task_new  	Equals true if the user is adding a post
        // $_POST			Input form
        //****************************************************************************************************
        do_action('frontier_post_post_save', $my_post, $tmp_task_new, $_POST);
        //If save, set task to edit
        if ($tmp_return == "save") {
            $_REQUEST['task'] = "edit";
            $_REQUEST['postid'] = $postid;
        }
        // if shortcode frontier_mode=add, return to add form instead of list
        if ($frontier_mode == "add" && $tmp_return == "savereturn") {
            $tmp_return = "add";
        }
        switch ($tmp_return) {
            case 'preview':
                frontier_preview_post($postid);
                break;
            case 'add':
                frontier_post_add_edit($frontier_post_shortcode_parms);
                break;
            case 'savereturn':
                frontier_user_post_list($frontier_post_shortcode_parms);
                break;
            case 'save':
                frontier_post_add_edit($frontier_post_shortcode_parms);
                break;
            case 'delete':
                frontier_prepare_delete_post($frontier_post_shortcode_parms);
                break;
            default:
                frontier_user_post_list($frontier_post_shortcode_parms);
                break;
        }
    } else {
        frontier_post_set_msg(__("Error - Unable to save post", "frontier-post"));
        frontier_user_post_list($frontier_post_shortcode_parms);
    }
    // end isset post
}
function frontier_post_add_edit($frontier_post_shortcode_parms = array())
{
    require_once ABSPATH . '/wp-admin/includes/post.php';
    global $current_user;
    global $wpdb;
    //add_thickbox();
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    //set start of output debug query
    $qlog = $wpdb->queries;
    $qlog_start = count($qlog);
    $fps_access_check_msg = "";
    $user_can_edit_this_post = false;
    //Reset access message
    $fps_access_check_msg = "";
    //Get Frontier Post capabilities
    $fp_capabilities = frontier_post_get_capabilities();
    //$fp_settings		= frontier_post_get_settings()
    // Get vars from shortcode
    extract($frontier_post_shortcode_parms);
    if (!is_user_logged_in()) {
        echo fp_login_text();
    } else {
        // Check if new, and if Edit that current users is allowed to edit
        if (isset($_REQUEST['task']) && $_REQUEST['task'] == "edit") {
            $thispost = get_post($_REQUEST['postid']);
            $user_post_excerpt = get_post_meta($thispost->ID, "user_post_excerpt");
            $tmp_task_new = false;
            if (frontier_can_edit($thispost) == true) {
                $user_can_edit_this_post = true;
            }
        } else {
            $tmp_post_type = post_type_exists($frontier_add_post_type) ? $frontier_add_post_type : 'post';
            if (frontier_can_add($tmp_post_type) == true) {
                if (empty($thispost->ID)) {
                    $thispost = get_default_post_to_edit("{$tmp_post_type}", true);
                    $thispost->post_author = $current_user->ID;
                    $thispost->post_type = $tmp_post_type;
                    //echo "New post for edit: ".$thispost->ID."<br>";
                }
                $_REQUEST['task'] = "new";
                $tmp_task_new = true;
                $user_can_edit_this_post = true;
            }
        }
    }
    // Do not proceed with all the processing if user is not able to add/edit
    if ($user_can_edit_this_post == true) {
        $post_id = $thispost->ID;
        //get users role:
        $users_role = frontier_get_user_role();
        // get list of taxonomies
        $tax_form_lists = frontier_get_tax_lists($frontier_page_id, intval($frontier_parent_cat_id), intval($fps_cache_time_tax_lists));
        //******************************************************************************************
        // Set defaults, so post can be saved without errors
        //******************************************************************************************
        if (!isset($thispost->post_type)) {
            $thispost->post_type = 'post';
        }
        if (!isset($thispost->post_content)) {
            $thispost->post_content = '';
        }
        // Call media fix (to support older versions)
        frontier_media_fix($post_id);
        //******************************************************************************************
        // Manage post status
        //******************************************************************************************
        //build post status list based on current status and users capability
        $tmp_status_list = get_post_statuses();
        $tmp_status_list = array_reverse($tmp_status_list);
        // Remove private status from array if not allowed
        if (!current_user_can('frontier_post_can_private')) {
            unset($tmp_status_list['private']);
        }
        // Remove draft status from array if user is not allowed to use drafts
        if (!current_user_can('frontier_post_can_draft')) {
            unset($tmp_status_list['draft']);
        }
        // Remove pending status from array if user is not allowed to use pending status or if it is a page we are editing
        if (!current_user_can('frontier_post_can_pending') || $thispost->post_type == 'page') {
            unset($tmp_status_list['pending']);
        }
        // Remove publish status from array if not allowed
        if (!current_user_can('frontier_post_can_publish')) {
            unset($tmp_status_list['publish']);
        }
        // Set default status if new post - Check if the default status is in the allowed statuses, and if so set the default status
        $tmp_default_status = fp_get_option("fps_default_status", "publish");
        if ($tmp_task_new == true && array_key_exists($tmp_default_status, $tmp_status_list)) {
            $thispost->post_status = $tmp_default_status;
        }
        $status_list = array();
        $tmp_post_status = $thispost->post_status ? $thispost->post_status : $tmp_default_status;
        // if The deafult status is not in the list, set default status to the first in the list
        if (!in_array($tmp_post_status, array_keys($tmp_status_list))) {
            $tmp_post_status = current(array_keys($tmp_status_list));
        }
        $status_list = $tmp_status_list;
        //**************************************************************************************************
        // -- Setup wp_editor layout
        // full: full Tiny MCE
        // minimal-visual: Teeny layout
        // minimal-html: simple layout with html options
        // text: text only
        //**************************************************************************************************
        // If capabilities is managed from other plugin, use default setting for all profiles
        if (get_option("frontier_post_external_cap", "false") == "true") {
            $editor_type = fp_get_option("fps_default_editor", "full");
        } else {
            $editor_type = $fp_capabilities[$users_role]['fps_role_editor_type'] ? $fp_capabilities[$users_role]['fps_role_editor_type'] : "full";
        }
        $editor_layout = array('dfw' => false, 'tabfocus_elements' => 'sample-permalink,post-preview', 'editor_height' => 300);
        $frontier_media_button = current_user_can('frontier_post_can_media') ? current_user_can('frontier_post_can_media') : false;
        // Call to wp_editor in done in entry form
        //************************************************************************
        // Setup category
        //************************************************************************
        // Do not manage categories for page
        if ($thispost->post_type != 'page') {
            // If capabilities is managed from other plugin, use default setting for all profiles
            if (fp_get_option("fps_external_cap", "false") == "true") {
                $category_type = fp_get_option("fps_default_cat_select", "multi");
            } else {
                $category_type = $fp_capabilities[$users_role]['fps_role_category_layout'] ? $fp_capabilities[$users_role]['fps_role_category_layout'] : "multi";
            }
            $default_category = $fp_capabilities[$users_role]['fps_role_default_category'] ? $fp_capabilities[$users_role]['fps_role_default_category'] : get_option("default_category");
            // set default category, if new and category parsed from shortcode,
            if ($tmp_task_new) {
                $cats_selected = $frontier_cat_id;
                if (count($frontier_cat_id) > 0 && $frontier_cat_id[0] > 0) {
                    $default_category = $frontier_cat_id[0];
                }
            } else {
                $cats_selected = $thispost->post_category;
            }
            // if no category selected (from post), insert default category.
            // removed in version 3.5.7, as default category is set on save
            /*
            if (empty($cats_selected[0]))
            	$cats_selected[0] = $default_category;
            */
            // Build list of categories (3 levels)
            // removed in version 3.5.7
            /*
            if ( ($category_type == "multi") || ($category_type == "checkbox") )
            	{
            	$catlist 		= array();
            	$catlist 		= frontier_tax_list("category", fp_get_option("fps_excl_cats", ''), $frontier_parent_cat_id );
            	}
            */
        } else {
            $cats_selected = array();
        }
        // end exclude categories for pages
        // Set variable for hidden field, if category field is removed from the form
        $cats_selected_txt = implode(',', $cats_selected);
        //echo "Cats selected: ".$cats_selected_txt."<hr>";
        //***************************************************************************************
        //* Set tags
        //***************************************************************************************
        $fp_tag_count = fp_get_option_int("fps_tag_count", 3);
        if (current_user_can('frontier_post_tags_edit') && $thispost->post_type != 'page') {
            $taglist = array();
            if (isset($thispost->ID)) {
                $tmptags = get_the_tags($thispost->ID);
                if ($tmptags) {
                    foreach ($tmptags as $tag) {
                        array_push($taglist, $tag->name);
                    }
                }
            }
        }
        $hide_post_status = fp_get_option("fps_hide_status", "false") == "true" ? true : false;
        $frontier_use_feat_img = fp_get_option("fps_show_feat_img", "false");
        //***************************************************************************************
        //* Get post moderation fields
        //***************************************************************************************
        if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $thispost->post_author)) {
            $fp_moderation_comments = get_post_meta($post_id, 'FRONTIER_POST_MODERATION_TEXT', true);
        }
    }
    // end if OK to Edit
    if ($user_can_edit_this_post) {
        $fp_form = $frontier_edit_form;
        if ($thispost->post_type == 'page') {
            $fp_form = "page";
        }
        //echo "Form: ".$fp_form."<br>";
        switch ($fp_form) {
            case "standard":
                include frontier_load_form("frontier_post_form_standard.php");
                break;
            case "old":
                include frontier_load_form("frontier_post_form_old.php");
                break;
            case "simple":
                include frontier_load_form("frontier_post_form_simple.php");
                break;
            case "page":
                include frontier_load_form("frontier_post_form_page.php");
                break;
            default:
                include frontier_load_form("frontier_post_form_standard.php");
                break;
        }
        //output debug query
        if (1 === 2) {
            error_log('---------------- SQL LOG START (' . $qlog_start . ')---------------');
            global $wpdb;
            $q_log = $wpdb->queries;
            error_log("Queries");
            error_log(print_r($q_log, true));
            $l = 0;
            echo "<hr>Queries<hr>";
            foreach ($q_log as $tmp_sql) {
                if ($l >= $qlog_start) {
                    //error_log('('.zeroise($l,3).') '.$tmp_sql[1].' '.$tmp_sql[0]);
                    echo '(' . zeroise($l, 3) . ') ' . $tmp_sql[1] . ' ' . $tmp_sql[0] . "<hr>";
                }
                $l++;
            }
            error_log('---------------- SQL LOG END---------------');
        }
    } else {
        // Echo reason why user cant add/edit post.
        global $fps_access_check_msg;
        if (empty($fps_access_check_msg) || $fps_access_check_msg < " ") {
            echo __("You are not allowed to edit this post, sorry ", "frontier-post");
        } else {
            echo "<br>" . $fps_access_check_msg;
        }
        //Reset message once displayed
        $fps_access_check_msg = "";
    }
}
function frontier_post_add_edit($fpost_sc_parms = array(), $fp_use_quickpost = false)
{
    require_once ABSPATH . '/wp-admin/includes/post.php';
    global $current_user;
    //global $wpdb;
    global $fps_access_check_msg;
    //Reset access message
    $fps_access_check_msg = "";
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    $user_can_edit_this_post = false;
    //Get Frontier Post capabilities
    $fp_capabilities = frontier_post_get_capabilities();
    //$fp_settings		= frontier_post_get_settings()
    // Get vars from shortcode
    //extract($frontier_post_shortcode_parms);
    if (!is_user_logged_in()) {
        // stop and display message
        echo fp_login_text();
    } else {
        // Check if new, and if Edit that current users is allowed to edit
        if (isset($_REQUEST['task']) && $_REQUEST['task'] == "edit") {
            $thispost = get_post($_REQUEST['postid']);
            $user_post_excerpt = get_post_meta($thispost->ID, "user_post_excerpt");
            $tmp_task_new = false;
            if (frontier_can_edit($thispost)) {
                $user_can_edit_this_post = true;
            }
        } else {
            if (frontier_can_add($fpost_sc_parms['frontier_add_post_type'])) {
                if (empty($thispost->ID)) {
                    $thispost = get_default_post_to_edit($fpost_sc_parms['frontier_add_post_type'], true);
                    $thispost->post_author = $current_user->ID;
                    $thispost->post_type = $fpost_sc_parms['frontier_add_post_type'];
                    //echo "New post for edit: <pre>".print_r($thispost, true)."</pre><br>";
                }
                $_REQUEST['task'] = "new";
                $tmp_task_new = true;
                $user_can_edit_this_post = true;
            } else {
                echo '<br><div id="frontier-post-alert">';
                echo $fps_access_check_msg;
                echo '</div><br>';
                return;
            }
        }
    }
    //**************************************************************************************************
    // Do not proceed with all the processing if user is not able to add/edit
    //**************************************************************************************************
    if (!$user_can_edit_this_post) {
        // Echo reason why user cant add/edit post.
        global $fps_access_check_msg;
        if (empty($fps_access_check_msg) || $fps_access_check_msg < " ") {
            echo __("You are not allowed to edit this post, sorry ", "frontier-post");
        } else {
            echo "<br>" . $fps_access_check_msg;
        }
        //Reset message once displayed
        $fps_access_check_msg = "";
        return;
    } else {
        $post_id = $thispost->ID;
        $users_role = frontier_get_user_role();
        $tax_form_lists = frontier_get_tax_lists($fpost_sc_parms['frontier_page_id'], intval($fpost_sc_parms['frontier_parent_cat_id']), intval($fpost_sc_parms['fps_cache_time_tax_lists']));
        //******************************************************************************************
        // Set defaults, so post can be saved without errors
        //******************************************************************************************
        if (!isset($thispost->post_type)) {
            $thispost->post_type = 'post';
        }
        if (!isset($thispost->post_content)) {
            $thispost->post_content = '';
        }
        // Call media fix (to support older versions)
        frontier_media_fix($post_id);
        //******************************************************************************************
        // Manage post status
        //******************************************************************************************
        //build post status list based on current status and users capability
        $tmp_status_list = get_post_statuses();
        $tmp_status_list = array_reverse($tmp_status_list);
        // Remove private status from array if not allowed
        if (!current_user_can('frontier_post_can_private')) {
            unset($tmp_status_list['private']);
        }
        // Remove draft status from array if user is not allowed to use drafts
        if (!current_user_can('frontier_post_can_draft')) {
            unset($tmp_status_list['draft']);
        }
        // Remove pending status from array if user is not allowed to use pending status or if it is a page we are editing
        if (!current_user_can('frontier_post_can_pending') || $thispost->post_type == 'page') {
            unset($tmp_status_list['pending']);
        }
        // Remove publish status from array if not allowed
        if (!current_user_can('frontier_post_can_publish')) {
            unset($tmp_status_list['publish']);
        }
        // Add Future to status list, if post status is future
        if ($thispost->post_status == "future") {
            $tmp_status_list['future'] = __("Future", "frontier-post");
        }
        // Set default status if new post - Check if the default status is in the allowed statuses, and if so set the default status
        $tmp_default_status = fp_get_option("fps_default_status", "publish");
        if ($tmp_task_new == true && array_key_exists($tmp_default_status, $tmp_status_list)) {
            $thispost->post_status = $tmp_default_status;
        }
        $status_list = array();
        $tmp_post_status = $thispost->post_status ? $thispost->post_status : $tmp_default_status;
        // if The deafult status is not in the list, set default status to the first in the list
        if (!in_array($tmp_post_status, array_keys($tmp_status_list))) {
            $tmp_post_status = current(array_keys($tmp_status_list));
        }
        $status_list = $tmp_status_list;
        //************************************************************************
        // Setup category
        //************************************************************************
        // Do not manage categories for page
        if ($thispost->post_type != 'page') {
            // If capabilities is managed from other plugin, use default setting for all profiles
            if (fp_get_option("fps_external_cap", "false") == "true") {
                $category_type = fp_get_option("fps_default_cat_select", "multi");
            } else {
                $category_type = $fp_capabilities[$users_role]['fps_role_category_layout'] ? $fp_capabilities[$users_role]['fps_role_category_layout'] : "multi";
            }
            $default_category = $fp_capabilities[$users_role]['fps_role_default_category'] ? $fp_capabilities[$users_role]['fps_role_default_category'] : get_option("default_category");
            // set default category, if new and category parsed from shortcode,
            if ($tmp_task_new) {
                $cats_selected = $fpost_sc_parms['frontier_cat_id'];
                if (count($cats_selected) > 0 && ${$cats_selected}[0] > 0) {
                    $default_category = $frontier_cat_id[0];
                }
            } else {
                $cats_selected = $thispost->post_category;
            }
        } else {
            $cats_selected = array();
        }
        // end exclude categories for pages
        // Set variable for hidden field, if category field is removed from the form
        $cats_selected_txt = implode(',', $cats_selected);
        //***************************************************************************************
        //* Set tags
        //***************************************************************************************
        $fp_tag_count = fp_get_option_int("fps_tag_count", 3);
        if (current_user_can('frontier_post_tags_edit') && $thispost->post_type != 'page') {
            $taglist = array();
            if (isset($thispost->ID)) {
                $tmptags = get_the_tags($thispost->ID);
                if ($tmptags) {
                    foreach ($tmptags as $tag) {
                        array_push($taglist, $tag->name);
                    }
                }
            }
        }
        //***************************************************************************************
        //* Get post moderation fields
        //***************************************************************************************
        if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $thispost->post_author)) {
            $fp_moderation_comments = get_post_meta($post_id, 'FRONTIER_POST_MODERATION_TEXT', true);
        }
        //***************************************************************************************
        // Enqueue media javascript
        //***************************************************************************************
        wp_enqueue_media(array('post' => $thispost->ID));
        //***************************************************************************************
        // Setup entry form
        //***************************************************************************************
        $fp_form = $fpost_sc_parms['frontier_edit_form'];
        // override if this is a quickpost
        if (fp_bool($fp_use_quickpost)) {
            $fp_form = "quickpost";
        }
        if ($thispost->post_type == 'page') {
            $fp_form = "page";
        }
        switch ($fp_form) {
            case "standard":
                include frontier_load_form("frontier_post_form_standard.php");
                break;
            case "old":
                include frontier_load_form("frontier_post_form_old.php");
                break;
            case "simple":
                include frontier_load_form("frontier_post_form_simple.php");
                break;
            case "page":
                include frontier_load_form("frontier_post_form_page.php");
                break;
            case "quickpost":
                include frontier_load_form("frontier_post_form_quickpost.php");
                break;
            default:
                include frontier_load_form("frontier_post_form_standard.php");
                break;
        }
    }
    // end  $user_can_edit_this_post
}
Example #4
0
function fp_get_tax_layout($tax_list, $layout_list = array())
{
    $tmp_layout_list = array();
    if (!array_key_exists('category', $tax_list)) {
        $fp_capabilities = frontier_post_get_capabilities();
        $tmp_layout_list['category'] = $fp_capabilities[frontier_get_user_role()]['fps_role_category_layout'] ? $fp_capabilities[frontier_get_user_role()]['fps_role_category_layout'] : "multi";
    }
    if (count($tax_list) > 0) {
        include FRONTIER_POST_DIR . "/include/frontier_post_defaults.php";
        $chk_layout = array_values($category_types);
        $s = 0;
        foreach ($tax_list as $tmp_tax) {
            if ($s >= count($layout_list) || empty($layout_list[$s])) {
                $tmp_layout = fp_get_option('fps_default_tax_select', 'radio');
            } else {
                $tmp_layout = $layout_list[$s];
            }
            // Check that it is a valid layout
            if (!in_array($tmp_layout, $chk_layout, true)) {
                $tmp_layout = fp_get_option('fps_default_tax_select', 'radio');
            }
            $tmp_layout_list[$tmp_tax] = $tmp_layout;
            $s++;
        }
    }
    return $tmp_layout_list;
}
function frontier_post_wp_editor_args($editor_lines = 300)
{
    global $dfw;
    $media_button = current_user_can('frontier_post_can_media') ? current_user_can('frontier_post_can_media') : false;
    $editor_layout = array('dfw' => $dfw, 'editor_height' => $editor_lines, 'media_buttons' => $media_button);
    //$editor_layout		 	= array('dfw' => false, 'tabfocus_elements' => 'sample-permalink,post-preview', 'editor_height' => 300 );
    // If capabilities is managed from other plugin, use default setting for all profiles
    if (fp_get_option_bool("frontier_post_external_cap")) {
        $editor_type = fp_get_option("fps_default_editor", "full");
    } else {
        //Get Frontier Post capabilities
        $user_role = frontier_get_user_role();
        $fp_capabilities = frontier_post_get_capabilities();
        $editor_type = $fp_capabilities[$user_role]['fps_role_editor_type'] ? $fp_capabilities[$user_role]['fps_role_editor_type'] : "full";
    }
    if ($editor_type == "full") {
        $editor_layout = array_merge($editor_layout, array('teeny' => false, 'quicktags' => false, 'tinymce' => true));
    }
    if ($editor_type == "minimal-visual") {
        $editor_layout = array_merge($editor_layout, array('teeny' => true, 'quicktags' => false));
    }
    if ($editor_type == "minimal-html") {
        $editor_layout = array_merge($editor_layout, array('teeny' => true, 'tinymce' => false));
    }
    if ($editor_type == "text") {
        $editor_layout = array_merge($editor_layout, array('quicktags' => false, 'tinymce' => false));
    }
    return $editor_layout;
}