834 | | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
835 | | $post_author_data = get_userdata( $post->post_author ); |
836 | | } else { |
837 | | // No author set yet or post type doesn't support authors, |
838 | | // so default to current user for cap checks. |
839 | | $post_author_data = $author_data; |
840 | | } |
| 831 | if ( 'delete_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) { |
| 832 | $args = array_merge( array( $post_type->cap->delete_post, $user_id ), $args ); |
| 833 | return call_user_func_array( 'map_meta_cap', $args ); |
| 834 | } |
842 | | // If the user is the author... |
843 | | if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) { |
844 | | // If the post is published... |
845 | | if ( 'publish' == $post->post_status ) { |
846 | | $caps[] = $post_type->cap->delete_published_posts; |
847 | | } elseif ( 'trash' == $post->post_status ) { |
848 | | if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) |
| 836 | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
| 837 | $post_author_data = get_userdata( $post->post_author ); |
| 838 | } else { |
| 839 | // No author set yet or post type doesn't support authors, |
| 840 | // so default to current user for cap checks. |
| 841 | $post_author_data = $author_data; |
| 842 | } |
| 843 | |
| 844 | // If the user is the author... |
| 845 | if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) { |
| 846 | // If the post is published... |
| 847 | if ( 'publish' == $post->post_status ) { |
851 | | // If the post is draft... |
852 | | $caps[] = $post_type->cap->delete_posts; |
| 857 | // The user is trying to edit someone else's post. |
| 858 | $caps[] = $post_type->cap->delete_others_posts; |
| 859 | // The post is published, extra cap required. |
| 860 | if ( 'publish' == $post->post_status ) |
| 861 | $caps[] = $post_type->cap->delete_published_posts; |
| 862 | elseif ( 'private' == $post->post_status ) |
| 863 | $caps[] = $post_type->cap->delete_private_posts; |
877 | | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
878 | | $post_author_data = get_userdata( $post->post_author ); |
879 | | } else { |
880 | | // No author set yet or post type doesn't support authors, |
881 | | // so default to current user for cap checks. |
882 | | $post_author_data = $author_data; |
883 | | } |
| 878 | if ( 'edit_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) { |
| 879 | $args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args ); |
| 880 | return call_user_func_array( 'map_meta_cap', $args ); |
| 881 | } |
885 | | //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />"; |
886 | | // If the user is the author... |
887 | | if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) { |
888 | | // If the post is published... |
889 | | if ( 'publish' == $post->post_status ) { |
890 | | $caps[] = $post_type->cap->edit_published_posts; |
891 | | } elseif ( 'trash' == $post->post_status ) { |
892 | | if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) |
| 883 | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
| 884 | $post_author_data = get_userdata( $post->post_author ); |
| 885 | } else { |
| 886 | // No author set yet or post type doesn't support authors, |
| 887 | // so default to current user for cap checks. |
| 888 | $post_author_data = $author_data; |
| 889 | } |
| 890 | |
| 891 | //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />"; |
| 892 | // If the user is the author... |
| 893 | if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) { |
| 894 | // If the post is published... |
| 895 | if ( 'publish' == $post->post_status ) { |
895 | | // If the post is draft... |
896 | | $caps[] = $post_type->cap->edit_posts; |
| 905 | // The user is trying to edit someone else's post. |
| 906 | $caps[] = $post_type->cap->edit_others_posts; |
| 907 | // The post is published, extra cap required. |
| 908 | if ( 'publish' == $post->post_status ) |
| 909 | $caps[] = $post_type->cap->edit_published_posts; |
| 910 | elseif ( 'private' == $post->post_status ) |
| 911 | $caps[] = $post_type->cap->edit_private_posts; |
914 | | if ( 'read_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) { |
915 | | $args = array_merge( array( $post_type->cap->read_post, $user_id ), $args ); |
916 | | return call_user_func_array( 'map_meta_cap', $args ); |
917 | | } |
| 922 | if ( 'read_post' == $cap && $post_type && 'post' != $post_type->capability_type && ! $post_type->map_meta_cap ) { |
| 923 | $args = array_merge( array( $post_type->cap->read_post, $user_id ), $args ); |
| 924 | return call_user_func_array( 'map_meta_cap', $args ); |
| 925 | } |
924 | | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
925 | | $post_author_data = get_userdata( $post->post_author ); |
926 | | } else { |
927 | | // No author set yet or post type doesn't support authors, |
928 | | // so default to current user for cap checks. |
929 | | $post_author_data = $author_data; |
| 932 | if ( '' != $post->post_author && post_type_supports( $post_type->name, 'author' ) ) { |
| 933 | $post_author_data = get_userdata( $post->post_author ); |
| 934 | } else { |
| 935 | // No author set yet or post type doesn't support authors, |
| 936 | // so default to current user for cap checks. |
| 937 | $post_author_data = $author_data; |
| 938 | } |
| 939 | |
| 940 | if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) |
| 941 | $caps[] = $post_type->cap->read; |
| 942 | else |
| 943 | $caps[] = $post_type->cap->read_private_posts; |