function frontier_email_on_transition($new_status, $old_status, $post) { if ($post->post_type !== 'post') { return; } //Don't touch anything that's not a post (i.e. ignore links and attachments and whatnot ) //If some variety of a draft is being published, dispatch an email if ($old_status != 'pending' && $new_status == 'pending' && fp_get_option("fps_mail_to_approve", "false") == "true") { $author_name = get_the_author_meta('display_name', $post->post_author); $to = get_option("frontier_post_mail_address") ? fp_get_option("fps_mail_address") : get_settings("admin_email"); $subject = __("Post for approval from", "frontier-post") . ": " . $author_name . " (" . get_bloginfo("name") . ")"; $body = __("Post for approval from", "frontier-post") . ": " . $author_name . " (" . get_bloginfo("name") . ")" . "\r\n\r\n"; $body = $body . "Title:: " . $post->post_title . "\r\n\r\n"; $body = $body . "Link to approvals: " . site_url('/wp-admin/edit.php?post_status=pending&post_type=post') . "\r\n\r\n"; //error_log('sending email: '.$subject.' To: '.$to); if (!wp_mail($to, $subject, $body)) { error_log(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")"); } } if ($old_status == 'pending' && $new_status == 'publish' && fp_get_option("fps_mail_approved", "false") == "true") { if ($post->post_author == get_current_user_id()) { return; } // no reason to send email if current user is able to publish :) $to = get_the_author_meta('email', $post->post_author); $subject = __("Your post has been approved", "frontier-post") . " (" . get_bloginfo("name") . ")"; $body = __("Your post has been approved", "frontier-post") . ": " . $post->title . " (" . get_bloginfo("name") . ")" . "\r\n\r\n"; $body = $body . "Title:: " . $post->post_title . "\r\n\r\n"; //error_log('sending email: '.$subject.' To: '.$to); if (!wp_mail($to, $subject, $body)) { error_log(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")"); } } }
function frontier_user_post_list($frontier_post_shortcode_parms = array()) { extract($frontier_post_shortcode_parms); global $post; global $current_user; get_currentuserinfo(); $tmp_p_id = get_the_id(); $pagenum = isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1; $ppp = (int) fp_get_option('fps_ppp', 5); $args = array('post_type' => $frontier_list_post_types, 'post_status' => 'draft, pending, publish, private', 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => $ppp, 'paged' => $pagenum); // add category from shortcode to limit posts if ($frontier_list_cat_id > 0) { $args["cat"] = implode(",", $frontier_list_cat_id); } //List all published posts if ($frontier_list_all_posts == "true") { // limit list to status=publish to the list, if users do not have private posts (editors & admins) if (!current_user_can('edit_private_posts')) { $args["post_status"] = "publish"; } } else { $args["author"] = $current_user->ID; } // List pending posts if ($frontier_list_pending_posts == "true") { if (!current_user_can('edit_others_posts')) { echo '<br><div id="frontier-post-alert">' . __("You do not have access to other users pending posts", "frontier-post") . '</div><br>'; return; } $args["post_status"] = "pending"; if (array_key_exists("author", $args)) { unset($args['author']); } } $user_posts = new WP_Query($args); $fp_show_icons = fp_get_option_bool('fps_use_icons'); $fp_list_form = fp_get_option("fps_default_list", "list"); switch ($fp_list_form) { case 'simple': include_once frontier_load_form("frontier_post_form_list.php"); break; case 'theme': include_once frontier_load_form("frontier_post_form_list_theme.php"); break; default: include_once frontier_load_form("frontier_post_form_list_detail.php"); break; } /* if (fp_get_option("fps_default_list", "list") == "simple") include_once(frontier_load_form("frontier_post_form_list.php")); else include_once(frontier_load_form("frontier_post_form_list_detail.php")); */ }
function frontier_can_edit($tmp_post) { global $fps_access_check_msg; $cur_user = wp_get_current_user(); $tmp_can_do = true; // Check if the user is allowed to edit posts if (!current_user_can('frontier_post_can_edit')) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit posts", "frontier-post") . "<br>"; } // Users can not edit other users posts unless they have capability "edit_others_posts" (Administrators & Editors) if ($cur_user->ID != $tmp_post->post_author && !current_user_can('edit_others_posts')) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit post from another user", "frontier-post") . "<br>"; } // Check that the age of the post is below the Frontier Post setting if ($tmp_post->post_status == "publish" && frontier_post_age($tmp_post->post_date) > fp_get_option_int('fps_edit_max_age')) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit post older than: ", "frontier-post") . fp_get_option_int('fps_edit_max_age') . " " . __("days", "frontier-post") . "<br>"; } // Check that user is allowed to edit posts that already has comments if (intval($tmp_post->comment_count) > 0 && !fp_get_option_bool("fps_edit_w_comments")) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit post that already has comments", "frontier-post") . "<br>"; } // Check if user is allowed to edit a post that is already published if (!fp_get_option("fps_change_status") && $tmp_post->post_status == "publish") { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit post that is published", "frontier-post") . "<br>"; } // check if it is an allowed posttype if (!fp_check_post_type($tmp_post->post_type)) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit", "frontier-post") . ": " . fp_get_posttype_label($tmp_post->post_type) . "<br>"; } // Always allow the boss if (current_user_can('administrator')) { $tmp_can_do = true; $fps_access_check_msg = ""; } // Last check, PRIVATE posts can only be edited by the author or Users with the capability edit_private_posts if ($cur_user->ID != $tmp_post->post_author && $tmp_post->post_status == "private" && !current_user_can('edit_private_posts')) { $tmp_can_do = false; $fps_access_check_msg = $fps_access_check_msg . __("You are not allowed to edit PRIVATE post from another user", "frontier-post") . "<br>"; } //$fps_access_check_msg = $fps_access_check_msg."Just testing<br>"; return $tmp_can_do; }
function frontier_email_on_transition($new_status, $old_status, $post) { if ($post->post_type !== 'post') { return; } //Don't touch anything that's not a post (i.e. ignore links and attachments and whatnot ) //If some variety of a draft is being published, dispatch an email if ($old_status != 'pending' && $new_status == 'pending' && fp_get_option("fps_mail_to_approve", "false") == "true") { $author_name = get_the_author_meta('display_name', $post->post_author); $to = fp_get_option("fps_mail_address") ? fp_get_option("fps_mail_address") : get_option("admin_email"); $subject = __("Post for approval from", "frontier-post") . ": " . $author_name . " (" . get_bloginfo("name") . ")"; $body = __("Post for approval from", "frontier-post") . ": " . $author_name . " (" . get_bloginfo("name") . ")" . "\r\n\r\n"; $body .= __("Title", "frontier-post") . ": " . $post->post_title . "\r\n\r\n"; $concat = get_option("permalink_structure") ? "?" : "&"; if (fp_get_option_int('fps_pending_page_id', 0) > 0) { $tmp_link = get_permalink(fp_get_option('fps_pending_page_id')) . $concat . 'task=approve&postid=' . $post->ID; } else { $tmp_link = site_url('/wp-admin/edit.php?post_status=pending&post_type=post'); } $body .= __("Link to approval", "frontier-post") . ": " . $tmp_link . "\r\n\r\n"; if (!wp_mail($to, $subject, $body)) { error_log(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")"); } } if ($old_status == 'pending' && $new_status == 'publish' && fp_get_option("fps_mail_approved", "false") == "true") { if ($post->post_author == get_current_user_id()) { return; } // no reason to send email if current user is able to publish :) $to = get_the_author_meta('email', $post->post_author); $subject = __("Your post has been approved", "frontier-post") . " (" . get_bloginfo("name") . ")"; $body = __("Your post has been approved", "frontier-post") . ": (" . get_bloginfo("name") . ")" . "\r\n\r\n"; $body .= __("Title", "frontier-post") . ": " . $post->post_title . "\r\n\r\n"; $body .= __("Link", "frontier-post") . ": " . get_permalink($post->ID) . "\r\n\r\n"; if (!wp_mail($to, $subject, $body)) { error_log(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")"); } } }
function frontier_post_hide_title($fp_tmp_title, $fp_tmp_id = 0) { $fp_tmp_id = (int) $fp_tmp_id; // only execute and hide title if id been parsed, if it is a page and if the page is in the list of pages where title should be hidden.... if ($fp_tmp_id > 0 && is_page($fp_tmp_id)) { $fp_tmp_id_list = explode(",", fp_get_option("fps_hide_title_ids", "")); if (in_array($fp_tmp_id, $fp_tmp_id_list)) { $fp_tmp_title = ""; } } return $fp_tmp_title; }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { global $current_user, $wpdb, $r; $instance = array_merge($this->defaults, $instance); $frontier_page_link = get_permalink(fp_get_option('fps_page_id')); $author = (int) $current_user->ID; $rec_limit = (int) (isset($instance['limit']) ? $instance['limit'] : 10); $excerpt_length = (int) (isset($instance['excerpt_length']) ? $instance['excerpt_length'] : 20); if (isset($instance['postdateformat']) && $instance['postdateformat'] != 'nodate') { $show_date = true; } else { $show_date = false; } if (isset($instance['cmtdateformat']) && $instance['cmtdateformat'] != 'nodate') { $show_comment_date = true; } else { $show_comment_date = false; } if (isset($instance['showcomments']) && $instance['showcomments'] != 'posts') { $show_comments = true; } else { $show_comments = false; } // Get comment icon from theme, first check local file path, if exists set tu url of icon $comment_icon = frontier_get_icon('comment'); // from version 3.4.6 caching will be available, and as such changed to handle in one array. // cache name must contain author id as results are specific to authors $fp_cache_name = FRONTIER_MY_POSTS_W_PREFIX . $this->number . "-U-" . $author; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; //echo "Cache name: ".$fp_cache_name."<br>"; $post_status_list = $instance['post_status_list']; // manage posts status if (!is_array($post_status_list)) { $post_status_list = array($post_status_list); } if (fp_bool($instance['show_pending_posts']) && !in_array('pending', $post_status_list)) { $post_status_list[] = 'pending'; } if (fp_bool($instance['show_draft_posts']) && !in_array('draft', $post_status_list)) { $post_status_list[] = 'draft'; } //echo "<pre>".print_r($post_status_list, true)."</pre><br>"; if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) { $fp_wdata = array(); $fp_wdata['tmp_post_cnt'] = $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM {$wpdb->posts} WHERE post_author = " . $author . " AND post_status = 'publish' AND post_type = 'post'"); // Build sql statement if ($show_comments) { $tmp_sql = " SELECT "; $tmp_sql .= " {$wpdb->posts}.ID \t\t\t\t\tAS post_id, "; $tmp_sql .= " {$wpdb->posts}.post_title \t\t\tAS post_title, "; $tmp_sql .= " {$wpdb->posts}.post_date \t\t\tAS post_date, "; $tmp_sql .= " {$wpdb->comments}.comment_ID \t\tAS comment_id, "; $tmp_sql .= " {$wpdb->comments}.comment_author \tAS comment_author, "; $tmp_sql .= " {$wpdb->comments}.comment_date \t\tAS comment_date, "; $tmp_sql .= " {$wpdb->comments}.comment_approved\tAS comment_approved, "; $tmp_sql .= " {$wpdb->comments}.comment_content \tAS comment_content "; $tmp_sql .= " FROM {$wpdb->posts} "; $tmp_sql .= " left OUTER JOIN {$wpdb->comments} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID "; $tmp_sql .= " WHERE {$wpdb->posts}.post_status IN ('" . implode("','", $post_status_list) . "') "; $tmp_sql .= " AND {$wpdb->posts}.post_type \t= '" . $instance['post_type'] . "'"; $tmp_sql .= " AND {$wpdb->posts}.post_author \t= " . $author . ""; $tmp_sql .= " ORDER BY {$wpdb->posts}.post_date DESC, {$wpdb->comments}.comment_date_gmt DESC"; $tmp_sql .= " LIMIT " . $rec_limit * 5 . ";"; } else { $tmp_sql = " SELECT {$wpdb->posts}.ID \tAS post_id, "; $tmp_sql .= " {$wpdb->posts}.post_title \tAS post_title, "; $tmp_sql .= " {$wpdb->posts}.post_date \tAS post_date "; $tmp_sql .= " FROM {$wpdb->posts} "; $tmp_sql .= " WHERE {$wpdb->posts}.post_author = " . $author . " "; $tmp_sql .= " AND {$wpdb->posts}.post_status IN ('" . implode("','", $post_status_list) . "') "; $tmp_sql .= " AND {$wpdb->posts}.post_type = '" . $instance['post_type'] . "' "; $tmp_sql .= " ORDER BY {$wpdb->posts}.post_date DESC "; $tmp_sql .= " LIMIT " . $rec_limit * 5 . ";"; // needs to multiply to account for non approved comments //echo "<pre>".print_r($tmp_sql, true)."</pre><br>"; } $fp_wdata['presult'] = $wpdb->get_results($tmp_sql); if ($fp_cache_time <= 0) { $fp_cache_test = "Caching disabled"; } else { $fp_cache_test = "Cache refreshed"; set_transient($fp_cache_name, $fp_wdata, $fp_cache_time); } } // end caching echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } //echo $args['before_widget']; //if ( $args['title'] ) echo $args['before_title'] . $args['title'] . $args['after_title']; //$title = apply_filters('widget_title', empty($instance['title']) ? __('My posts') : $instance['title'], $instance, $this->id_base); ?> <div class="frontier-my-post-widget"> <ul class="frontier-my-post-widget-list"> <?php $last_post = 0; $post_cnt = 0; if ($fp_wdata['presult']) { foreach ($fp_wdata['presult'] as $q_post) { $tmp_link = "xx"; if ($last_post != $q_post->post_id) { // $q_post is not a WP_post object $tmp_post = get_post($q_post->post_id); if ($post_cnt > 0) { echo "</li>"; } echo '<li class="frontier-my-post-widget-list">'; if ($instance['show_edit_link'] == 'before') { echo frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-edit-link') . ' '; } if ($instance['show_delete_link'] == 'before') { echo frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-delete-link') . ' '; } $post_cnt++; if ($show_date) { echo mysql2date($instance['postdateformat'], $q_post->post_date); echo ' '; } if ($tmp_post->post_status == "publish") { echo '<a class="frontier-my-post-widget-link frontier-my-post-widget-status-publish" href="' . get_permalink($q_post->post_id) . '">' . $q_post->post_title . '</a>'; } else { echo '<div id="frontier-my-post-widget-status-' . $tmp_post->post_status . '">' . $q_post->post_title . '</div>'; } if ($instance['show_edit_link'] == 'after') { echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-edit-link'); } if ($instance['show_delete_link'] == 'after') { echo frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-delete-link') . ' '; } } $last_post = $q_post->post_id; if ($show_comments && !empty($q_post->comment_id) && $q_post->comment_approved == 1) { echo "</br>" . $comment_icon . " "; if ($show_comment_date) { echo mysql2date($instance['cmtdateformat'], $q_post->comment_date) . " - "; } echo $q_post->comment_author; if ($instance['showcomments'] == 'excerpts') { $tmp_comment = substr($q_post->comment_content, 0, $excerpt_length); if (strlen($q_post->comment_content) > strlen($tmp_comment)) { $tmp_comment = $tmp_comment . "..."; } echo ": " . "</br><i>" . $tmp_comment . "</i>"; } } if ($post_cnt >= $rec_limit) { break; } } } else { echo "<li>" . $instance['no_posts_text'] . "</li>"; } ?> </li> </ul> <?php if (isset($instance['show_add_post']) && $instance['show_add_post'] == 1 && current_user_can('frontier_post_can_add')) { if ($instance['post_type'] !== "post") { $tmp_post_type_parm = "&frontier_add_post_type=" . $instance['post_type']; } else { $tmp_post_type_parm = ""; } echo '<p><center><a href="' . frontier_post_add_link() . $tmp_post_type_parm . '">' . __("Create New Post", "frontier-post") . '</a></center></p>'; } // Count authors posts - get_permalink(fp_get_option('fps_page_id')) if (isset($instance['show_post_count']) && $instance['show_post_count'] == 1) { //$tmp_post_cnt = $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM $wpdb->posts WHERE post_author = ".$author." AND post_status = 'publish' AND post_type = 'post'" ); $tmp_post_cnt = $fp_wdata['tmp_post_cnt']; echo '<p><center><a href="' . get_permalink(fp_get_option('fps_page_id')) . '">' . __("You have published: ", "frontier-post") . $tmp_post_cnt . ' ' . __("posts", "frontier-post") . '</a></center></p>'; } ?> </div> <?php //echo "<pre>".print_r($instance)."<pre>"; echo $args['after_widget']; } else { // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>"; } }
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>'; }
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_prepare_delete_post($frontier_post_shortcode_parms = array()) { extract($frontier_post_shortcode_parms); $frontier_permalink = get_permalink(); $concat = get_option("permalink_structure") ? "?" : "&"; //$post_task = isset($_GET['task']) ? $_GET['task'] : "notaskset"; //$post_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "Unknown"; if (isset($_POST['task'])) { $post_task = $_POST['task']; } else { if (isset($_GET['task'])) { $post_task = $_GET['task']; } else { $post_task = "notaskset"; } } if (isset($_POST['user_post_submit']) && $_POST['user_post_submit'] == "delete") { $post_task = "delete"; } $post_action = isset($_POST['action']) ? $_POST['action'] : "Unknown"; if ($post_task == "delete") { if ($_REQUEST['postid']) { $thispost = get_post($_REQUEST['postid']); $post_author = $thispost->post_author; //double check current user is equal to author (in case directly with param) if (frontier_can_delete($thispost) == true) { echo '<div id="frontier-post-alert">' . __("Delete", "frontier-post") . ': ' . fp_get_posttype_label_singular($thispost->post_type); $tmp_delete_txt = fp_get_option('fps_custom_delete_txt', ''); if (strlen($tmp_delete_txt) > 0) { echo '<br><br><p class="frontier-post-confirm-delete-text">' . $tmp_delete_txt . '</p>'; } echo '</div>'; echo '<br><br>'; ?> <div id="frontier-post-delete-post" class="frontier_post_delete_form"> <table> <form action="<?php echo $frontier_permalink; ?> " method="post" name="frontier_delete_post" id="frontier_delete_post" enctype="multipart/form-data" > <input type="hidden" name="action" value="wpfrtp_delete_post"> <input type="hidden" name="task" value="delete"> <input type="hidden" name="postid" id="postid" value="<?php if (isset($thispost->ID)) { echo $thispost->ID; } ?> "> <?php wp_nonce_field('frontier_delete_post', 'frontier_delete_post_' . $thispost->ID); ?> <tr> </tr><tr> <td><center> <button class="button frontier-post-form-delete" type="submit" name="submit_delete" id="submit_delete" value="deletego"><?php _e("Delete", "frontier-post"); ?> </button> <input type="reset" value=<?php _e("Cancel", "frontier-post"); ?> name="cancel" id="cancel" onclick="location.href='<?php the_permalink(); ?> '"> </center> </td></tr> </form> </table> <hr> <?php echo "<table>"; echo "<tr>"; echo "<td><h1>" . $thispost->post_title . "</h1></td>"; echo "</tr><tr><td>"; /* $content = $thispost->post_content; //$content = apply_filters( 'the_content', $content); $content = str_replace( ']]>', ']]>', $content ); */ $content = fp_view_post($thispost); echo $content; echo "</td>"; // echo $thispost->post_content; echo "</tr></table>"; ?> </div> <?php } } } }
function frontier_can_delete($tmp_post) { $fps_access_check_msg = ""; $cur_user = wp_get_current_user(); $tmp_can_do = true; // Check if the user is allowed to delete posts if (!current_user_can('frontier_post_can_delete')) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete posts", "frontier-post") . "<br>"; } // Users can not delete other users posts unless they have capability "delete_others_posts" (Administrators & Editors) if ($cur_user->ID != $tmp_post->post_author && !current_user_can('delete_others_posts')) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete post from another user", "frontier-post") . "<br>"; } // Check that the age of the post is below the Frontier Post setting if (frontier_post_age($tmp_post->post_date) > fp_get_option_int('fps_delete_max_age')) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete post older than: ", "frontier-post") . get_option('frontier_post_delete_max_age') . " " . __("days", "frontier-post") . "<br>"; } // Check that user is allowed to delete posts that already has comments if ((int) $tmp_post->comment_count > 0 && !fp_get_option_bool("fps_del_w_comments")) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to deelete post that already has comments", "frontier-post") . "<br>"; } // Check that user is allowed to delete published posts if (!fp_get_option("fps_change_status") && $tmp_post->post_status == "publish") { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete published posts", "frontier-post") . "<br>"; } // check if it is an allowed posttype if (!fp_check_post_type($tmp_post->post_type)) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete", "frontier-post") . ": " . fp_get_posttype_label($tmp_post->post_type) . "<br>"; } // Always allow the boss if (current_user_can('administrator')) { $tmp_can_do = true; $fps_access_check_msg = ""; } // Last check, PRIVATE posts can only be deleted by the author, or users with capability delete_private_posts (admins and editors) if ($tmp_post->post_status == "private" && ($cur_user->ID != $tmp_post->post_author || !current_user_can('frontier_post_can_private') || !current_user_can('frontier_post_can_delete'))) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to delete PRIVATE post from another user", "frontier-post") . "<br>"; } return $tmp_can_do; }
function fp_tag_transform($tmp_tag) { $tmp_transform = fp_get_option('fps_tags_transform', 'none'); switch ($tmp_transform) { case 'lower': return strtolower(sanitize_text_field($tmp_tag)); case 'upper': return strtoupper(sanitize_text_field($tmp_tag)); case 'ucwords': return ucwords(sanitize_text_field($tmp_tag)); default: return sanitize_text_field($tmp_tag); } }
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 }
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"); }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { global $current_user, $wpdb, $r; $instance = array_merge($this->defaults, $instance); $author = (int) $current_user->ID; $rec_limit = (int) (isset($instance['limit']) ? $instance['limit'] : 10); $excerpt_length = (int) (isset($instance['excerpt_length']) ? $instance['excerpt_length'] : 20); if (isset($instance['postdateformat']) && $instance['postdateformat'] != 'nodate') { $show_date = true; } else { $show_date = false; } if (isset($instance['cmtdateformat']) && $instance['cmtdateformat'] != 'nodate') { $show_comment_date = true; } else { $show_comment_date = false; } if (isset($instance['showcomments']) && $instance['showcomments'] != 'posts') { $show_comments = true; } else { $show_comments = false; } // Get comment icon from theme, first check local file path, if exists set tu url of icon $comment_icon = frontier_get_icon('comment'); // from version 3.4.6 caching will be available, and as such changed to handle in one array. // cache name must contain author id as results are specific to authors $fp_cache_name = $args['widget_id'] . "_fpuser_" . $author; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) { $fp_wdata = array(); $fp_wdata['tmp_post_cnt'] = $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM {$wpdb->posts} WHERE post_author = " . $author . " AND post_status = 'publish' AND post_type = 'post'"); // Build sql statement if ($show_comments) { $tmp_sql = " SELECT \n\t\t\t\t\t\t\t {$wpdb->posts}.ID \t\t\t\t\tAS post_id, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_title \t\t\tAS post_title, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_date \t\t\tAS post_date, \n\t\t\t\t\t\t\t {$wpdb->comments}.comment_ID \t\tAS comment_id, \n\t\t\t\t\t\t\t {$wpdb->comments}.comment_author \tAS comment_author,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_date \t\tAS comment_date,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_approved\tAS comment_approved,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_content \tAS comment_content \n\t\t\t\t\t\t\t\t FROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t left OUTER JOIN {$wpdb->comments} ON \n\t\t\t\t\t\t\t\t\t {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID \n\t\t\t\t\t\t\t\t WHERE {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\t\t\t AND {$wpdb->posts}.post_type \t= 'post' \n\t\t\t\t\t\t\t\t AND {$wpdb->posts}.post_author \t= " . $author . "\n\t\t\t\t\t\t\t\t ORDER BY {$wpdb->posts}.post_date DESC, {$wpdb->comments}.comment_date_gmt DESC \n\t\t\t\t\t\t\t\t LIMIT " . $rec_limit * 5; } else { $tmp_sql = " SELECT {$wpdb->posts}.ID \tAS post_id, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_title \tAS post_title, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_date \tAS post_date \n\t\t\t\t\t\t\t FROM {$wpdb->posts} \n\t\t\t\t\t\t\t WHERE {$wpdb->posts}.post_author = " . $author . " AND {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_type = 'post' \n\t\t\t\t\t\t\t ORDER BY {$wpdb->posts}.post_date DESC \n\t\t\t\t\t\t\t LIMIT " . $rec_limit * 5; // needs to multiply to account for non approved comments } $fp_wdata['presult'] = $wpdb->get_results($tmp_sql); if ($fp_cache_time <= 0) { $fp_cache_test = "Caching disabled"; } else { $fp_cache_test = "Cache refreshed"; set_transient($fp_cache_name, $fp_wdata, $fp_cache_time); } } // end caching echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } //echo $args['before_widget']; //if ( $args['title'] ) echo $args['before_title'] . $args['title'] . $args['after_title']; //$title = apply_filters('widget_title', empty($instance['title']) ? __('My posts') : $instance['title'], $instance, $this->id_base); ?> <div class="frontier-my-post-widget"> <ul> <?php $last_post = 0; $post_cnt = 0; if ($fp_wdata['presult']) { foreach ($fp_wdata['presult'] as $post) { $tmp_link = "xx"; if ($last_post != $post->post_id) { if ($post_cnt > 0) { echo "</li>"; } echo "<li>"; $post_cnt++; if ($show_date) { echo mysql2date($instance['postdateformat'], $post->post_date); echo ' '; } ?> <a href="<?php echo post_permalink($post->post_id); ?> "><?php echo $post->post_title; ?> </a> <?php } $last_post = $post->post_id; if ($show_comments && !empty($post->comment_id) && $post->comment_approved == 1) { echo "</br>" . $comment_icon . " "; if ($show_comment_date) { echo mysql2date($instance['cmtdateformat'], $post->comment_date) . " - "; } echo $post->comment_author; if ($instance['showcomments'] == 'excerpts') { $tmp_comment = substr($post->comment_content, 0, $excerpt_length); if (strlen($post->comment_content) > strlen($tmp_comment)) { $tmp_comment = $tmp_comment . "..."; } echo ": " . "</br><i>" . $tmp_comment . "</i>"; } } if ($post_cnt >= $rec_limit) { break; } } } else { echo "<li>" . $instance['no_posts_text'] . "</li>"; } ?> </li> </ul> <?php if (isset($instance['show_add_post']) && $instance['show_add_post'] == 1 && current_user_can('frontier_post_can_add')) { echo '<p><center><a href="' . frontier_post_add_link() . '">' . __("Create New Post", "frontier-post") . '</a></center></p>'; } // Count authors posts - get_permalink(fp_get_option('fps_page_id')) if (isset($instance['show_post_count']) && $instance['show_post_count'] == 1) { //$tmp_post_cnt = $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM $wpdb->posts WHERE post_author = ".$author." AND post_status = 'publish' AND post_type = 'post'" ); $tmp_post_cnt = $fp_wdata['tmp_post_cnt']; echo '<p><center><a href="' . get_permalink(fp_get_option('fps_page_id')) . '">' . __("You have published: ", "frontier-post") . $tmp_post_cnt . ' ' . __("posts", "frontier-post") . '</a></center></p>'; } ?> </div> <?php echo $args['after_widget']; } else { // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>"; } }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in() && current_user_can("edit_others_posts")) { $instance = array_merge($this->defaults, $instance); // from version 3.4.6 caching will be available, and as such changed to handle in one array. $fp_cache_name = $args['widget_id']; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; global $wpdb; //error_log(print_r($instance), true); if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) { $fp_wdata = array(); if (isset($instance['show_draft']) && $instance['show_draft'] == true) { $fp_wdata['draft_cnt'] = $wpdb->get_var("SELECT count(id) AS draft_cnt FROM {$wpdb->posts} WHERE post_status = 'draft'"); $fp_wdata['draft_txt'] = $fp_wdata['draft_cnt'] . ' ' . __('draft posts', 'frontier-post'); $fp_wdata['show_draft'] = true; } else { $fp_wdata['show_draft'] = false; } if (isset($instance['show_pending']) && $instance['show_pending'] == true) { $fp_wdata['pending_cnt'] = $wpdb->get_var("SELECT count(id) AS pending_cnt FROM {$wpdb->posts} WHERE post_status = 'pending'"); $fp_wdata['pending_txt'] = $fp_wdata['pending_cnt'] . ' ' . __('posts to be approved', 'frontier-post'); $fp_wdata['show_pending'] = true; } else { $fp_wdata['show_pending'] = false; } if (isset($instance['show_comments']) && $instance['show_comments'] == true) { $fp_wdata['cmt_pending_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 0"); $fp_wdata['cmt_pending_txt'] = $fp_wdata['cmt_pending_cnt'] . ' ' . __('comments to be approved', 'frontier-post'); $fp_wdata['show_comments'] = true; } else { $fp_wdata['show_comments'] = false; } if (isset($instance['show_comment_spam']) && $instance['show_comment_spam'] == true) { $fp_wdata['cmt_spam_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 'spam'"); $fp_wdata['cmt_spam_txt'] = $fp_wdata['cmt_spam_cnt'] . ' ' . __('spam comments', 'frontier-post'); $fp_wdata['show_comment_spam'] = true; } else { $fp_wdata['show_comment_spam'] = false; } if ($fp_cache_time <= 0) { $fp_cache_test = "Caching disabled"; } else { $fp_cache_test = "Cache refreshed"; set_transient($fp_cache_name, $fp_wdata, $fp_cache_time); } } // end caching echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } ?> <div class="frontier-my-post-widget"> <ul> <?php if ($fp_wdata['show_pending']) { if (fp_get_option_int('fps_pending_page_id', 0) > 0) { $tmp_link = get_permalink(fp_get_option('fps_pending_page_id')); } else { $tmp_link = site_url('/wp-admin/edit.php?post_status=pending&post_type=post'); } //echo ."<hr>"; //echo $tmp_link."<hr>"; ?> <li> <a href="<?php echo $tmp_link; ?> "><?php echo $fp_wdata['pending_txt']; ?> </a> </li> <?php } ?> <?php if ($fp_wdata['show_draft']) { ?> <li> <a href="<?php echo site_url('/wp-admin/edit.php?post_status=draft&post_type=post'); ?> "><?php echo $fp_wdata['draft_txt']; ?> </a> </li> <?php } ?> <?php if ($fp_wdata['show_comments']) { ?> <li> <a href="<?php echo site_url('/wp-admin/edit-comments.php?comment_status=moderated'); ?> "><?php echo $fp_wdata['cmt_pending_txt']; ?> </a> </li> <?php } ?> <?php if ($fp_wdata['show_comment_spam']) { ?> <li> <a href="<?php echo site_url('/wp-admin/edit-comments.php?comment_status=spam'); ?> "><?php echo $fp_wdata['cmt_spam_txt']; ?> </a> </li> <?php } ?> </ul> </div> <?php echo $args['after_widget']; } }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in() && current_user_can("edit_others_posts")) { $instance = array_merge($this->defaults, $instance); $frontier_page_link = get_permalink(fp_get_option('fps_page_id')); // from version 3.4.6 caching will be available, and as such changed to handle in one array. $fp_cache_name = FRONTIER_MY_APPROVALS_W_PREFIX . $this->number; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; global $wpdb; //error_log(print_r($instance), true); if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) { $fp_wdata = array(); if (isset($instance['show_draft']) && $instance['show_draft'] == true) { $fp_wdata['draft_cnt'] = $wpdb->get_var("SELECT count(id) AS draft_cnt FROM {$wpdb->posts} WHERE post_status = 'draft'"); $fp_wdata['draft_txt'] = $fp_wdata['draft_cnt'] . ' ' . __('draft posts', 'frontier-post'); $fp_wdata['show_draft'] = true; } else { $fp_wdata['show_draft'] = false; } if (isset($instance['show_pending']) && $instance['show_pending'] == true) { $fp_wdata['pending_cnt'] = $wpdb->get_var("SELECT count(id) AS pending_cnt FROM {$wpdb->posts} WHERE post_status = 'pending'"); $fp_wdata['pending_txt'] = $fp_wdata['pending_cnt'] . ' ' . __('posts to be approved', 'frontier-post'); $fp_wdata['show_pending'] = true; } else { $fp_wdata['show_pending'] = false; } if (isset($instance['show_comments']) && $instance['show_comments'] == true) { $fp_wdata['cmt_pending_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 0"); $fp_wdata['cmt_pending_txt'] = $fp_wdata['cmt_pending_cnt'] . ' ' . __('comments to be approved', 'frontier-post'); $fp_wdata['show_comments'] = true; } else { $fp_wdata['show_comments'] = false; } if (isset($instance['show_comment_spam']) && $instance['show_comment_spam'] == true) { $fp_wdata['cmt_spam_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 'spam'"); $fp_wdata['cmt_spam_txt'] = $fp_wdata['cmt_spam_cnt'] . ' ' . __('spam comments', 'frontier-post'); $fp_wdata['show_comment_spam'] = true; } else { $fp_wdata['show_comment_spam'] = false; } if (intval($instance['pending_count']) > 0) { //$tmp_sql = ""; $tmp_sql = "SELECT ID AS post_id, post_title AS post_title FROM {$wpdb->posts} WHERE post_status = 'pending' ORDER BY post_date DESC LIMIT " . intval($instance['pending_count']) . " "; $fp_wdata['pending_list'] = $wpdb->get_results($tmp_sql); $fp_wdata['pending_count'] = intval($instance['pending_count']); } else { $fp_wdata['pending_count'] = 0; } if (intval($instance['draft_count']) > 0) { //$tmp_sql = ""; $tmp_sql = "SELECT ID AS post_id, post_title AS post_title FROM {$wpdb->posts} WHERE post_status = 'draft' ORDER BY post_date DESC LIMIT " . intval($instance['draft_count']) . " "; $fp_wdata['draft_list'] = $wpdb->get_results($tmp_sql); $fp_wdata['draft_count'] = intval($instance['draft_count']); } else { $fp_wdata['draft_count'] = 0; } $fp_wdata['postdateformat'] = $instance['postdateformat']; $fp_wdata['show_author'] = fp_bool($instance['show_author']); if ($fp_cache_time <= 0) { $fp_cache_test = "Caching disabled"; } else { $fp_cache_test = "Cache refreshed"; set_transient($fp_cache_name, $fp_wdata, $fp_cache_time); } } // end caching echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; echo $instance['title']; echo $args['after_title']; } echo '<div class="frontier-my-post-widget">'; echo '<ul>'; if ($fp_wdata['show_pending']) { if (fp_get_option_int('fps_pending_page_id', 0) > 0) { $tmp_pending_link = get_permalink(fp_get_option('fps_pending_page_id')); } else { $tmp_pending_link = site_url('/wp-admin/edit.php?post_status=pending&post_type=post'); } if (fp_get_option_int('fps_draft_page_id', 0) > 0) { $tmp_draft_link = get_permalink(fp_get_option('fps_draft_page_id')); } else { $tmp_draft_link = site_url('/wp-admin/edit.php?post_status=draft&post_type=post'); } echo '<li>'; echo '<a href="' . $tmp_pending_link . '">' . $fp_wdata['pending_txt'] . '</a>'; echo '</li>'; } if (array_key_exists('pending_count', $fp_wdata) && $fp_wdata['pending_count'] > 0) { if (!$fp_wdata['show_pending']) { echo '<li>' . __("Pending posts", "frontier-post") . '</li>'; } echo '<ul class="frontier-my-approvals-pending">'; foreach ($fp_wdata['pending_list'] as $q_post) { $tmp_post = get_post($q_post->post_id); echo '<li class="frontier-my-approvals-pending">'; if ($fp_wdata['postdateformat'] != 'nodate') { echo '<div id="frontier-my-approvals-date-pending">' . mysql2date($instance['postdateformat'], $tmp_post->post_date) . ' </div>'; } echo $q_post->post_title; if ($fp_wdata['show_author']) { echo '<div id="frontier-my-approvals-author">' . ' (' . get_the_author_meta('nicename', $tmp_post->post_author) . ')</div>'; } echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-edit-link'); echo ' ' . frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-delete-link'); echo '</li>'; } echo '</ul>'; } if ($fp_wdata['show_draft']) { echo '<li>'; echo '<a href="' . $tmp_draft_link . '">' . $fp_wdata['draft_txt'] . '</a>'; echo '</li>'; } if (array_key_exists('draft_count', $fp_wdata) && $fp_wdata['draft_count'] > 0) { if (!$fp_wdata['show_draft']) { echo '<li>' . __("Draft posts", "frontier-post") . '</li>'; } echo '<ul class="frontier-my-approvals-draft">'; foreach ($fp_wdata['draft_list'] as $q_post) { $tmp_post = get_post($q_post->post_id); echo '<li class="frontier-my-approvals-draft">'; if ($fp_wdata['postdateformat'] != 'nodate') { echo '<div id="frontier-my-approvals-date-draft">' . mysql2date($instance['postdateformat'], $tmp_post->post_date) . ' </div>'; } echo $q_post->post_title; if ($fp_wdata['show_author']) { echo '<div id="frontier-my-approvals-author">' . ' (' . get_the_author_meta('nicename', $tmp_post->post_author) . ')</div>'; } echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-edit-link'); echo ' ' . frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-delete-link'); echo '</li>'; } echo '</ul>'; } if ($fp_wdata['show_comments']) { echo '<li>'; echo '<a href="' . site_url('/wp-admin/edit-comments.php?comment_status=moderated') . '">' . $fp_wdata['cmt_pending_txt'] . '</a>'; echo '</li>'; } if ($fp_wdata['show_comment_spam']) { echo '<li>'; echo '<a href="' . site_url('/wp-admin/edit-comments.php?comment_status=spam') . '">' . $fp_wdata['cmt_spam_txt'] . '</a>'; echo '</li>'; } echo '</ul>'; echo '</div>'; //echo "<pre>".print_r($fp_wdata, true)."</pre><br>"; echo $args['after_widget']; } }