$post_author_data = get_userdata( $post->post_author );
} else {
// No author set yet, so default to current user for cap checks.
$post_author_data = $author_data;
}
//echo "current user id : $user_id, post author id: " . $post_author_data->ID . "
";
// If the user is the author...
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status ) {
$caps[] = $post_type->cap->edit_published_posts;
} elseif ( 'trash' == $post->post_status ) {
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
$caps[] = $post_type->cap->edit_published_posts;
} else {
// If the post is draft...
$caps[] = $post_type->cap->edit_posts;
}
} else {
// The user is trying to edit someone else's post.
$caps[] = $post_type->cap->edit_others_posts;
// The post is published, extra cap required.
if ( 'publish' == $post->post_status )
$caps[] = $post_type->cap->edit_published_posts;
elseif ( 'private' == $post->post_status )
$caps[] = $post_type->cap->edit_private_posts;
}
break;
case 'read_post':
case 'read_page':
$author_data = get_userdata( $user_id );
$post = get_post( $args[0] );
if ( 'revision' == $post->post_type ) {
$post = get_post( $post->post_parent );
}
$post_type = get_post_type_object( $post->post_type );
if ( ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
// Prior to 3.1 we would re-call map_meta_cap here.
if ( 'read_post' == $cap )
$cap = $post_type->cap->$cap;
break;
}
if ( 'private' != $post->post_status ) {
$caps[] = $post_type->cap->read;
break;
}
if ( '' != $post->post_author ) {
$post_author_data = get_userdata( $post->post_author );
} else {
// No author set yet, so default to current user for cap checks.
$post_author_data = $author_data;
}
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
$caps[] = $post_type->cap->read;
else
$caps[] = $post_type->cap->read_private_posts;
break;
case 'edit_comment':
$comment = get_comment( $args[0] );
$post = get_post( $comment->comment_post_ID );
$post_type_object = get_post_type_object( $post->post_type );
$caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
break;
case 'unfiltered_upload':
if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) )
$caps[] = $cap;
else
$caps[] = 'do_not_allow';
break;
case 'edit_files':
case 'edit_plugins':
case 'edit_themes':
if ( defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT ) {
$caps[] = 'do_not_allow';
break;
}
// Fall through if not DISALLOW_FILE_EDIT.
case 'update_plugins':
case 'delete_plugins':
case 'install_plugins':
case 'update_themes':
case 'delete_themes':
case 'install_themes':
case 'update_core':
// Disallow anything that creates, deletes, or edits core, plugin, or theme files.
// Files in uploads are excepted.
if ( defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS ) {
$caps[] = 'do_not_allow';
break;
}
// Fall through if not DISALLOW_FILE_MODS.
case 'unfiltered_html':
// Disallow unfiltered_html for all users, even admins and super admins.
if ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) {
$caps[] = 'do_not_allow';
break;
}
// Fall through if not DISALLOW_UNFILTERED_HTML
case 'delete_user':
case 'delete_users':
// If multisite these caps are allowed only for super admins.
if ( is_multisite() && !is_super_admin( $user_id ) ) {
$caps[] = 'do_not_allow';
} else {
if ( 'delete_user' == $cap )
$cap = 'delete_users';
$caps[] = $cap;
}
break;
case 'create_users':
if ( !is_multisite() )
$caps[] = $cap;
elseif ( is_super_admin() || get_site_option( 'add_new_users' ) )
$caps[] = $cap;
else
$caps[] = 'do_not_allow';
break;
default:
// Handle meta capabilities for custom post types.
$post_type_meta_caps = _post_type_meta_capabilities();
if ( isset( $post_type_meta_caps[ $cap ] ) ) {
$args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args );
return call_user_func_array( 'map_meta_cap', $args );
}
// If no meta caps match, return the original cap.
$caps[] = $cap;
}
return apply_filters('map_meta_cap', $caps, $cap, $user_id, $args);
}
/**
* Whether current user has capability or role.
*
* @since 2.0.0
*
* @param string $capability Capability or role name.
* @return bool
*/
function current_user_can( $capability ) {
$current_user = wp_get_current_user();
if ( empty( $current_user ) )
return false;
$args = array_slice( func_get_args(), 1 );
$args = array_merge( array( $capability ), $args );
return call_user_func_array( array( &$current_user, 'has_cap' ), $args );
}
/**
* Whether current user has a capability or role for a given blog.
*
* @since 3.0.0
*
* @param int $blog_id Blog ID
* @param string $capability Capability or role name.
* @return bool
*/
function current_user_can_for_blog( $blog_id, $capability ) {
$current_user = wp_get_current_user();
if ( empty( $current_user ) )
return false;
// Create new object to avoid stomping the global current_user.
$user = new WP_User( $current_user->id) ;
// Set the blog id. @todo add blog id arg to WP_User constructor?
$user->for_blog( $blog_id );
$args = array_slice( func_get_args(), 2 );
$args = array_merge( array( $capability ), $args );
return call_user_func_array( array( &$user, 'has_cap' ), $args );
}
/**
* Whether author of supplied post has capability or role.
*
* @since 2.9.0
*
* @param int|object $post Post ID or post object.
* @param string $capability Capability or role name.
* @return bool
*/
function author_can( $post, $capability ) {
if ( !$post = get_post($post) )
return false;
$author = new WP_User( $post->post_author );
if ( empty( $author->ID ) )
return false;
$args = array_slice( func_get_args(), 2 );
$args = array_merge( array( $capability ), $args );
return call_user_func_array( array( &$author, 'has_cap' ), $args );
}
/**
* Whether a particular user has capability or role.
*
* @since 3.1.0
*
* @param int|object $user User ID or object.
* @param string $capability Capability or role name.
* @return bool
*/
function user_can( $user, $capability ) {
if ( ! is_object( $user ) )
$user = new WP_User( $user );
if ( ! $user || ! $user->ID )
return false;
$args = array_slice( func_get_args(), 2 );
$args = array_merge( array( $capability ), $args );
return call_user_func_array( array( &$user, 'has_cap' ), $args );
}
/**
* Retrieve role object.
*
* @see WP_Roles::get_role() Uses method to retrieve role object.
* @since 2.0.0
*
* @param string $role Role name.
* @return object
*/
function get_role( $role ) {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
return $wp_roles->get_role( $role );
}
/**
* Add role, if it does not exist.
*
* @see WP_Roles::add_role() Uses method to add role.
* @since 2.0.0
*
* @param string $role Role name.
* @param string $display_name Display name for role.
* @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );
* @return null|WP_Role WP_Role object if role is added, null if already exists.
*/
function add_role( $role, $display_name, $capabilities = array() ) {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
return $wp_roles->add_role( $role, $display_name, $capabilities );
}
/**
* Remove role, if it exists.
*
* @see WP_Roles::remove_role() Uses method to remove role.
* @since 2.0.0
*
* @param string $role Role name.
* @return null
*/
function remove_role( $role ) {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
return $wp_roles->remove_role( $role );
}
/**
* Retrieve a list of super admins.
*
* @since 3.0.0
*
* @uses $super_admins Super admins global variable, if set.
*
* @return array List of super admin logins
*/
function get_super_admins() {
global $super_admins;
if ( isset($super_admins) )
return $super_admins;
else
return get_site_option( 'site_admins', array('admin') );
}
/**
* Determine if user is a site admin.
*
* @since 3.0.0
*
* @param int $user_id (Optional) The ID of a user. Defaults to the current user.
* @return bool True if the user is a site admin.
*/
function is_super_admin( $user_id = false ) {
if ( $user_id )
$user = new WP_User( $user_id );
else
$user = wp_get_current_user();
if ( empty( $user->id ) )
return false;
if ( is_multisite() ) {
$super_admins = get_super_admins();
if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) )
return true;
} else {
if ( $user->has_cap('delete_users') )
return true;
}
return false;
}
?>
Fatal error: Call to undefined function add_shortcode() in /export/sd201/www/jp/r/e/gmoserver/6/2/sd0177962/crossculture.jp/wordpress-2.8.2-ja-undernavicontrol/wp-includes/media.php on line 703