true ), 'object' ), array( 'attachment' => true ) ); foreach( $post_types as $type => $post_type_obj ) { $defined_meta_caps ['read'] []= $post_type_obj->cap->read_post; $defined_meta_caps ['edit'] []= $post_type_obj->cap->edit_post; $defined_meta_caps ['delete'] []= $post_type_obj->cap->delete_post; } } $matched_op = false; foreach( array_keys($defined_meta_caps) as $op ) { if ( in_array( $meta_cap, $defined_meta_caps[$op] ) ) { $matched_op = $op; break; } } if ( ! $matched_op ) return $caps; $object_id = ( is_array($args) ) ? $args[0] : $args; if ( ! $object_id ) return $caps; if ( ! $post = get_post( $object_id ) ) return $caps; if ( in_array( $post->post_type, array( 'revision', 'attachment' ) ) ) if ( ! $post = get_post( $post->post_parent ) ) return $caps; $use_post_types = scoper_get_option( 'use_post_types' ); if ( empty( $use_post_types[$post->post_type] ) ) return $caps; if ( ! $post_type_obj = get_post_type_object( $post->post_type ) ) return $caps; if ( ! $post_status_obj = get_post_status_object( $post->post_status ) ) return $caps; // no need to modify meta caps for post/page checks with built-in status if ( in_array( $post->post_type, array( 'post', 'page' ) ) && $post_status_obj->_builtin && $adjust_for_user && $caps ) return $caps; if ( ! $adjust_for_user ) { $is_post_author = false; } elseif ( ! $post->post_author ) { $is_post_author = true; //No author set yet so treat current user as author for cap checks $require_all_status_caps = true; } else { $post_author_data = get_userdata( $post->post_author ); $is_post_author = ( $user_id == $post_author_data->ID ); $require_all_status_caps = ! defined( 'SCOPER_LEGACY_META_CAPS' ); } // Need to override default output from core map_meta_caps. This filter hooks early to avoid wiping out other supplemental filters. $caps = array(); switch ( $op ) { case 'read': if ( ! empty($post_status_obj->private) ) { if ( $is_post_author ) $caps[] = 'read'; else $caps[] = $post_type_obj->cap->read_private_posts; } else $caps[] = 'read'; break; case 'edit' : $caps[] = $post_type_obj->cap->edit_posts; // The post is public, extra cap required. if ( ! empty($post_status_obj->public) ) { $caps[] = $post_type_obj->cap->edit_published_posts; } elseif ( 'trash' == $post->post_status ) { if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) $caps[] = $post_type_obj->cap->edit_published_posts; } // note: as of 3.0, WP core requires edit_published_posts, but not edit_private_posts, when logged user is the post author. That's inconsistent when used in conjunction with custom statuses if ( ! empty($post_status_obj->private) && ! $is_post_author ) //&& $require_all_status_caps ) $caps[] = $post_type_obj->cap->edit_private_posts; if ( ! $is_post_author ) $caps[] = $post_type_obj->cap->edit_others_posts; // The user is trying to edit someone else's post. break; case 'delete' : $caps[] = $post_type_obj->cap->delete_posts; // The post is public, extra cap required. if ( ! empty($post_status_obj->public) ) { $caps[] = $post_type_obj->cap->delete_published_posts; } elseif ( 'trash' == $post->post_status ) { if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) $caps[] = $post_type_obj->cap->delete_published_posts; } // note: as of 3.0, WP core requires delete_published_posts, but not delete_private_posts, when logged user is the post author. That's inconsistent when used in conjunction with custom statuses if ( ! empty($post_status_obj->private) && ! $is_post_author ) //&& $require_all_status_caps ) $caps[] = $post_type_obj->cap->delete_private_posts; if ( ! $is_post_author ) $caps[] = $post_type_obj->cap->delete_others_posts; // The user is trying to delete someone else's post. break; } // end switch // if a capability is defined for this custom status, require it also if ( $require_all_status_caps ) { if ( empty($post_status_obj->_builtin) ) { $status_cap_name = "{$op}_{$post->post_status}_posts"; if ( ! empty( $post_type_obj->cap->$status_cap_name ) ) $caps []= $post_type_obj->cap->$status_cap_name; } } $caps = array_unique( $caps ); return $caps; } ?>