/** * Creates an user blog post, auto redirects them to the post they have written * * @param: An array containing the post info e.g array( 'postTitle' =>, 'postContent' => ) * */ function nm_edit_user_blog_post($info) { check_admin_referer('user-blog-post_edit'); global $wpdb; $postContent = strip_tags($info['blogContent']); $postTags = $info['blogTags']; if (!is_user_logged_in()) { $feedback = "<p class='message error'>You have to be logged in to write a blog post</p>"; } elseif (!$postTags) { $feedback = "<p class='message error'>Please enter some tags that describe your blog post.</p>"; } elseif (!$postContent || preg_replace('/\\s+/', '', $postContent) == '') { $feedback = "<p class='message error'>You need to write the body of the blog post</p>"; } else { $newPost = array('ID' => $info['ID'], 'post_content' => $postContent, 'post_parent' => $info['blogGroup']); $acc = new ACL($newPost); switch ($info['access']) { case 'hidden': $acc->hidden(); break; case 'members': default: // Just in case something goes crazy $acc->member(); break; case 'friends': $acc->friend(); //public is a php keyword break; case 'public': $acc->everyone(); //public is a php keyword break; } wp_set_post_tags($info['ID'], $postTags); $postId = wp_update_post($newPost); $feedback = '<p class="message success">Blog post updated successfully | <a href="' . nm_get_user_blog_permalink($postId) . '">View ' . get_the_title($postId) . '<a/></p>'; } return $feedback; }
/** * Alerts your friends and subscribers when you write a new blog post * * @Param: the id of the blog post * @Param: your user id * * @author: Joe Hoyle * @version 1.0 **/ function nm_alert_friend_wrote_blog_post($postID, $userID) { $userInfo = get_userdata($userID); $friendList = new userFriends(); $friends = $friendList->get_friends($userInfo->ID); $readers = nm_get_blog_readers($userInfo->ID); $friends = nm_array_invert($friends); if (!empty($readers)) { foreach ($readers as $key => $reader) { $friends[] = $key; } } if ($friends) { query_posts('p=' . $postID); while (have_posts()) { the_post(); global $post; $alert = array(); $alert['content'] = '<a href="' . getProfileLink($userInfo->ID) . '" title="View ' . nm_user_public_name($userInfo) . 's profile">' . nm_user_public_name($userInfo) . '</a> has written a new blog post: <a href="' . nm_get_user_blog_permalink($post->ID) . '" title="View ' . $post->post_title . '">' . $post->post_title . '</a>.'; $alert['type'] = 'blog'; nm_add_alert($friends, $alert, 'true'); } rewind_posts(); } return $postID; }