Example #1
0
"><?php 
        the_title();
        ?>
</a>
						</h2>

						<div class="meta">By 
							<?php 
        if (function_exists('coauthors_posts_links')) {
            ?>
								<?php 
            if (is_coauthor_for_post('Staff Reports')) {
                ?>
									<span class="author">Staff Reports</span>
								<?php 
            } elseif (is_coauthor_for_post('archives')) {
                ?>
									<span class="author"><?php 
                echo pd_is_archived(get_the_ID(), '_author');
                ?>
</span>
								<?php 
            } else {
                ?>
									<span class="author"><?php 
                coauthors();
                ?>
</span>
								<?php 
            }
            ?>
 /**
  * Allows coauthors to edit the post they're coauthors of
  * Pieces of code borrowed from http://pastebin.ca/1909968
  * 
  */
 function add_coauthor_cap($allcaps, $caps, $args)
 {
     // Load the post data:
     $user_id = isset($args[1]) ? $args[1] : 0;
     $post_id = isset($args[2]) ? $args[2] : 0;
     if (!$post_id) {
         $post_id = $this->get_post_id();
     }
     if (!$post_id) {
         return $allcaps;
     }
     $post = get_post($post_id);
     if (!$post) {
         return $allcaps;
     }
     $post_type_object = get_post_type_object($post->post_type);
     // Bail out if there's no post type object
     if (!is_object($post_type_object)) {
         return $allcaps;
     }
     // Bail out if we're not asking about a post
     if (!in_array($args[0], array($post_type_object->cap->edit_post, $post_type_object->cap->edit_others_posts))) {
         return $allcaps;
     }
     // Bail out for users who can already edit others posts
     if (isset($allcaps[$post_type_object->cap->edit_others_posts]) && $allcaps[$post_type_object->cap->edit_others_posts]) {
         return $allcaps;
     }
     // Bail out for users who can't publish posts if the post is already published
     if ('publish' == $post->post_status && (!isset($allcaps[$post_type_object->cap->edit_published_posts]) || !$allcaps[$post_type_object->cap->edit_published_posts])) {
         return $allcaps;
     }
     // Finally, double check that the user is a coauthor of the post
     if (is_coauthor_for_post($user_id, $post_id)) {
         foreach ($caps as $cap) {
             $allcaps[$cap] = true;
         }
     }
     return $allcaps;
 }
 /**
  * Allows coauthors to edit the post they're coauthors of
  */
 function filter_user_has_cap($allcaps, $caps, $args)
 {
     $cap = $args[0];
     $user_id = isset($args[1]) ? $args[1] : 0;
     $post_id = isset($args[2]) ? $args[2] : 0;
     $obj = get_post_type_object(get_post_type($post_id));
     if (!$obj || 'revision' == $obj->name) {
         return $allcaps;
     }
     $caps_to_modify = array($obj->cap->edit_post, 'edit_post', $obj->cap->edit_others_posts);
     if (!in_array($cap, $caps_to_modify)) {
         return $allcaps;
     }
     // We won't be doing any modification if they aren't already a co-author on the post
     if (!is_user_logged_in() || !is_coauthor_for_post($user_id, $post_id)) {
         return $allcaps;
     }
     $current_user = wp_get_current_user();
     if ('publish' == get_post_status($post_id) && (isset($obj->cap->edit_published_posts) && !empty($current_user->allcaps[$obj->cap->edit_published_posts]))) {
         $allcaps[$obj->cap->edit_published_posts] = true;
     } elseif ('private' == get_post_status($post_id) && (isset($obj->cap->edit_private_posts) && !empty($current_user->allcaps[$obj->cap->edit_private_posts]))) {
         $allcaps[$obj->cap->edit_private_posts] = true;
     }
     $allcaps[$obj->cap->edit_others_posts] = true;
     return $allcaps;
 }
Example #4
0
 function add_coauthor_cap($allcaps, $caps, $args)
 {
     if (in_array('edit_post', $args) || in_array('edit_others_posts', $args)) {
         // @TODO: Fix this disgusting hardcodedness. Ew.
         $user_id = $args[1];
         $post_id = $args[2];
         if (is_coauthor_for_post($user_id, $post_id)) {
             // @TODO check to see if can edit publish posts if post is published
             // @TODO check to see if can edit posts at all
             foreach ($caps as $cap) {
                 $allcaps[$cap] = 1;
             }
         }
     }
     return $allcaps;
 }