当前位置: 首页>>代码示例>>PHP>>正文


PHP map_meta_cap函数代码示例

本文整理汇总了PHP中map_meta_cap函数的典型用法代码示例。如果您正苦于以下问题:PHP map_meta_cap函数的具体用法?PHP map_meta_cap怎么用?PHP map_meta_cap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了map_meta_cap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wpcf_access_exceptions_check

/**
 * Filters cap.
 * 
 * @param type $capability_requested
 * @return string 
 */
function wpcf_access_exceptions_check()
{
    $args = func_get_args();
    $capability_requested = $args[0][0];
    $parse_args = $args[0][1];
    $args = $args[0][2];
    $found = wpcf_access_search_cap($capability_requested);
    // Allow filtering
    list($capability_requested, $parse_args, $args) = apply_filters('wpcf_access_exceptions', array($capability_requested, $parse_args, $args, $found));
    switch ($capability_requested) {
        case 'edit_comment':
            $capability_requested = 'edit_posts';
            $parse_args['caps'] = array('edit_published_posts', 'edit_comment');
            break;
        case 'moderate_comments':
            $capability_requested = 'edit_others_posts';
            $parse_args['caps'] = array('edit_published_posts', 'edit_comment');
            break;
            //        case 'delete_post':
            //        case 'edit_post':
        //        case 'delete_post':
        //        case 'edit_post':
        default:
            // TODO Wachout for more!
            if (isset($args[1]) && isset($args[2])) {
                $user = get_userdata(intval($args[1]));
                $post_id = intval($args[2]);
                $post = get_post($post_id);
                if (!empty($user->ID) && !empty($post)) {
                    $parse_args_clone = $parse_args;
                    $args_clone = $args;
                    // check post id is valid, avoid capabilities warning
                    if (intval($post->ID) > 0) {
                        $map = map_meta_cap($capability_requested, $user->ID, $post->ID);
                        if (is_array($map) && !empty($map[0])) {
                            foreach ($map as $cap) {
                                $args_clone = array($cap);
                                $result = wpcf_access_check($parse_args_clone['allcaps'], $map, $args_clone, false);
                                if (!$result) {
                                    $parse_args['caps'] = array();
                                }
                            }
                        }
                    }
                    // Not sure why we didn't use this mapping before
                    $capability_requested = wpcf_access_map_cap($capability_requested, $post_id);
                }
                if (WPCF_ACCESS_DEBUG) {
                    global $wpcf_access;
                    $wpcf_access->debug_hooks_with_args[$capability_requested][] = array('args' => $args);
                }
            }
            break;
    }
    return array($capability_requested, $parse_args, $args);
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:62,代码来源:exceptions.php

示例2: r21138_xmlrpc_edit_posts

 function r21138_xmlrpc_edit_posts($caps, $cap, $user_id, $args)
 {
     if (!isset($args[0]) || isset($args[1]) && $args[1] === 'hotfixed') {
         return $caps;
     }
     foreach (get_post_types(array(), 'objects') as $post_type_object) {
         if ($cap === $post_type_object->cap->edit_posts) {
             return map_meta_cap($post_type_object->cap->edit_post, $user_id, $args[0], 'hotfixed');
         }
     }
     return $caps;
 }
开发者ID:roblarsen,项目名称:jquery-wp-content,代码行数:12,代码来源:class.vaultpress-hotfixes.php

示例3: _pp_flt_map_media_meta_cap

function _pp_flt_map_media_meta_cap($caps, $cap, $user_id, $args)
{
    if (!empty($args[0])) {
        $post = is_object($args[0]) ? $args[0] : get_post($args[0]);
        if ($post && 'attachment' == $post->post_type) {
            if (!empty($post->post_parent)) {
                $post_status = get_post_status($post->ID);
            } elseif ('inherit' == $post->post_status) {
                $post_status = pp_get_option('unattached_files_private') ? 'private' : 'publish';
            } else {
                $post_status = $post->post_status;
            }
            $post_type = get_post_type_object($post->post_type);
            $post_author_id = $post->post_author;
            $caps = array_diff($caps, (array) $cap);
            switch ($cap) {
                case 'read_post':
                case 'read_page':
                    $status_obj = get_post_status_object($post_status);
                    if ($status_obj->public || $status_obj->private && $user_id == $post_author_id) {
                        $caps[] = $post_type->cap->read;
                        break;
                    }
                    // If no author set yet, default to current user for cap checks.
                    if (!$post_author_id) {
                        $post_author_id = $user_id;
                    }
                    if ($status_obj->private) {
                        $caps[] = $post_type->cap->read_private_posts;
                    } else {
                        $caps = map_meta_cap('edit_post', $user_id, $post->ID);
                    }
                    $caps = apply_filters('pp_map_attachment_read_caps', $caps, $post, $user_id);
                    break;
                default:
                    require_once dirname(__FILE__) . '/media-edit-metacap-workaround_pp.php';
                    $args = array_merge($args, compact('post', 'post_status', 'post_type', 'post_author_id'));
                    $caps = _ppff_flt_map_media_edit_meta_cap($caps, $cap, $user_id, $args);
            }
        }
    }
    return $caps;
}
开发者ID:severnrescue,项目名称:web,代码行数:43,代码来源:media-metacap-workaround_pp.php

示例4: wpcf_access_files_override

/**
 * WP 3.5 This is fix for inserting to editor.
 * 
 * New GUI checks if current use can 'edit_post' with certain ID
 * even if attachment is in question.
 * 
 * Access logic requires that attachment in this case can be inserted
 * in parent post if user can edit parent post_type.
 * 
 * @param type $null
 * @param type $parse_args
 * @return type 
 */
function wpcf_access_files_override($null, $parse_args)
{
    // To check if on media upload screen use
    // either basename($_SERVER['SCRIPT_NAME']) == 'async-upload.php'
    // or strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/async-upload.php') !== false
    // Fix types upload
    if ($parse_args['cap'] == 'upload_files' && !isset($_REQUEST['action']) && isset($_POST['post_id']) && isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/async-upload.php') !== false) {
        // This should be the end of a types image upload
        // temporarily set the $_REQUEST['action'] and process the same as send-attachment-to-editor
        $_REQUEST['action'] = 'types-end-image-upload';
    }
    if ($parse_args['cap'] == 'upload_files' && isset($_REQUEST['fetch']) && isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], '/wp-admin/async-upload.php') !== false) {
        // This should be the crunching part types image upload
        // We assume that if we got here then this request is ok.
        return wpcf_access_parse_caps(true, $parse_args);
    }
    // Fix ending to editor
    if (isset($_REQUEST['action'])) {
        $action = strval($_REQUEST['action']);
        switch ($action) {
            case 'send-attachment-to-editor':
            case 'types-end-image-upload':
                if ($_REQUEST['action'] == 'types-end-image-upload') {
                    // remove the temporary action.
                    unset($_REQUEST['action']);
                }
                $parent_id = intval($_POST['post_id']);
                // If user can edit parent post
                // than he can edit attachment too (at least in this case)
                $map = map_meta_cap($parse_args['cap'], get_current_user_id(), $parent_id);
                $result = wpcf_access_check($parse_args['allcaps'], $map, $parse_args['args'], false);
                if (!$result) {
                    return wpcf_access_parse_caps(false, $parse_args);
                } else {
                    return wpcf_access_parse_caps(true, $parse_args);
                }
                break;
            default:
                break;
        }
    }
    return $null;
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:56,代码来源:upload_files.php

示例5: wpcf_access_map_cap

/**
 * Maps capability according to current user and post_id.
 * 
 * @param type $parse_args
 * @param type $post_id
 * @return type 
 */
function wpcf_access_map_cap($cap, $post_id)
{
    $current_user = wp_get_current_user();
    // do check for 0 post id
    if (intval($post_id) > 0) {
        $map = map_meta_cap($cap, $current_user->ID, $post_id);
        if (is_array($map) && !empty($map[0])) {
            return $map[0];
        }
    }
    return $cap;
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:19,代码来源:plus.php

示例6: test_require_edit_others_posts_if_post_type_doesnt_exist

 /**
  * @ticket 16956
  */
 function test_require_edit_others_posts_if_post_type_doesnt_exist()
 {
     register_post_type('existed');
     $post_id = self::factory()->post->create(array('post_type' => 'existed'));
     _unregister_post_type('existed');
     $subscriber_id = self::$users['subscriber']->ID;
     $editor_id = self::$users['editor']->ID;
     $this->setExpectedIncorrectUsage('map_meta_cap');
     foreach (array('delete_post', 'edit_post', 'read_post', 'publish_post') as $cap) {
         wp_set_current_user($subscriber_id);
         $this->assertSame(array('edit_others_posts'), map_meta_cap($cap, $subscriber_id, $post_id));
         $this->assertFalse(current_user_can($cap, $post_id));
         wp_set_current_user($editor_id);
         $this->assertSame(array('edit_others_posts'), map_meta_cap($cap, $editor_id, $post_id));
         $this->assertTrue(current_user_can($cap, $post_id));
     }
 }
开发者ID:aaronjorbin,项目名称:WordPress,代码行数:20,代码来源:capabilities.php

示例7: map_meta_cap

/**
 * Map meta capabilities to primitive capabilities.
 *
 * This does not actually compare whether the user ID has the actual capability,
 * just what the capability or capabilities are. Meta capability list value can
 * be 'delete_user', 'edit_user', 'remove_user', 'promote_user', 'delete_post',
 * 'delete_page', 'edit_post', 'edit_page', 'read_post', or 'read_page'.
 *
 * @since 2.0.0
 *
 * @param string $cap Capability name.
 * @param int $user_id User ID.
 * @return array Actual capabilities for meta capability.
 */
function map_meta_cap( $cap, $user_id ) {
	$args = array_slice( func_get_args(), 2 );
	$caps = array();

	switch ( $cap ) {
	case 'remove_user':
		$caps[] = 'remove_users';
		break;
	case 'promote_user':
		$caps[] = 'promote_users';
		break;
	case 'edit_user':
	case 'edit_users':
		// Allow user to edit itself
		if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] )
			break;

		// If multisite these caps are allowed only for super admins.
		if ( is_multisite() && !is_super_admin( $user_id ) )
			$caps[] = 'do_not_allow';
		else
			$caps[] = 'edit_users'; // edit_user maps to edit_users.
		break;
	case 'delete_post':
	case 'delete_page':
		$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 ( 'delete_post' == $cap )
				$cap = $post_type->cap->$cap;
			break;
		}

		$post_author_id = $post->post_author;

		// If no author set yet, default to current user for cap checks.
		if ( ! $post_author_id )
			$post_author_id = $user_id;

		// If the user is the author...
		if ( $user_id == $post_author_id ) {
			// If the post is published...
			if ( 'publish' == $post->post_status ) {
				$caps[] = $post_type->cap->delete_published_posts;
			} elseif ( 'trash' == $post->post_status ) {
				if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
					$caps[] = $post_type->cap->delete_published_posts;
			} else {
				// If the post is draft...
				$caps[] = $post_type->cap->delete_posts;
			}
		} else {
			// The user is trying to edit someone else's post.
			$caps[] = $post_type->cap->delete_others_posts;
			// The post is published, extra cap required.
			if ( 'publish' == $post->post_status )
				$caps[] = $post_type->cap->delete_published_posts;
			elseif ( 'private' == $post->post_status )
				$caps[] = $post_type->cap->delete_private_posts;
		}
		break;
		// edit_post breaks down to edit_posts, edit_published_posts, or
		// edit_others_posts
	case 'edit_post':
	case 'edit_page':
		$post = get_post( $args[0] );
		if ( empty( $post ) )
			break;

		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.
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:capabilities.php

示例8: test_file_edit_caps_not_reliant_on_unfiltered_html_constant

	/**
	 * @ticket 20488
	 */
	function test_file_edit_caps_not_reliant_on_unfiltered_html_constant() {
		if ( defined( 'DISALLOW_FILE_MODS' ) || defined( 'DISALLOW_FILE_EDIT' ) )
			$this->markTestSkipped('DISALLOW_FILE_MODS or DISALLOW_FILE_EDIT is defined.');

		if ( defined( 'DISALLOW_UNFILTERED_HTML' ) ) {
			if ( ! DISALLOW_UNFILTERED_HTML )
				$this->markTestSkipped( 'DISALLOW_UNFILTERED_HTML is defined.' );
		} else {
			define( 'DISALLOW_UNFILTERED_HTML', true );
		}

		$this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', $this->user_id ) );
		$this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', $this->user_id ) );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:17,代码来源:mapMetaCap.php

示例9: wp_event_calendar_meta_caps


//.........这里部分代码省略.........
                // The post is published or scheduled, extra cap required.
                if (in_array($post->post_status, array('publish', 'future'), true)) {
                    $caps = array('delete_published_posts');
                } elseif ('private' === $post->post_status) {
                    $caps = array('delete_private_posts');
                }
            }
            break;
            // Editing
        // Editing
        case 'edit_event':
            $post = get_post($args[0]);
            if (empty($post)) {
                $caps = array('do_not_allow');
                break;
            }
            if ('revision' === $post->post_type) {
                $post = get_post($post->post_parent);
                if (empty($post)) {
                    $caps = array('do_not_allow');
                    break;
                }
            }
            // If the post author is set and the user is the author...
            if ((int) $user_id === (int) $post->post_author) {
                // If the post is published or scheduled...
                if (in_array($post->post_status, array('publish', 'future'), true)) {
                    $caps = array('edit_published_posts');
                } elseif ('trash' === $post->post_status) {
                    $status = get_post_meta($post->ID, '_wp_trash_meta_status', true);
                    if (in_array($status, array('publish', 'future'), true)) {
                        $caps = array('edit_published_posts');
                    } else {
                        $caps = array('edit_posts');
                    }
                    // If the post is draft...
                } else {
                    $caps = array('edit_posts');
                }
                // The user is trying to edit someone else's post.
            } else {
                $caps = array('edit_others_posts');
                // The post is published or scheduled, extra cap required.
                if (in_array($post->post_status, array('publish', 'future'), true)) {
                    $caps = array('edit_published_posts');
                } elseif ('private' === $post->post_status) {
                    $caps = array('edit_private_posts');
                }
            }
            break;
            // Reading
        // Reading
        case 'read_event':
            $post = get_post($args[0]);
            if (empty($post)) {
                $caps = array('do_not_allow');
                break;
            }
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
                if (empty($post)) {
                    $caps = 'do_not_allow';
                    break;
                }
            }
            $status_obj = get_post_status_object($post->post_status);
            if (true === $status_obj->public) {
                $caps = array('read');
                break;
            }
            if ((int) $user_id === $post->post_author) {
                $caps = array('read');
            } elseif (true === $status_obj->private) {
                $caps = array('read_private_posts');
            } else {
                $caps = map_meta_cap('edit_post', $user_id, $post->ID);
            }
            break;
            // Remap
        // Remap
        case 'delete_events':
            $caps = array('delete_posts');
            break;
        case 'delete_others_events':
            $caps = array('delete_others_events');
            break;
        case 'create_events':
        case 'edit_events':
        case 'read_calendar':
            $caps = array('edit_posts');
            break;
        case 'edit_others_events':
            $caps = array('edit_others_posts');
            break;
        case 'publish_events':
            $caps = array('publish_posts');
            break;
    }
    return apply_filters('wp_event_calendar_meta_caps', $caps, $cap, $user_id, $args);
}
开发者ID:stuttter,项目名称:wp-event-calendar,代码行数:101,代码来源:capabilities.php

示例10: draw_exceptions_ui

    function draw_exceptions_ui($box, $args)
    {
        if (!isset($box['args'])) {
            return;
        }
        extract($box['args'], EXTR_SKIP);
        // $op
        extract($args, EXTR_SKIP);
        // $for_item_source, for_item_type, via_item_source
        global $wp_roles, $pp_current_user;
        $is_draft_post = false;
        if ('post' == $via_item_source) {
            if ('read' == $op) {
                global $post;
                $status_obj = get_post_status_object($post->post_status);
                if (!$status_obj || !$status_obj->public && !$status_obj->private) {
                    $is_draft_post = true;
                }
            }
            $hierarchical = is_post_type_hierarchical($via_item_type);
        } else {
            $hierarchical = is_taxonomy_hierarchical($via_item_type);
        }
        if ($hierarchical = apply_filters('pp_do_assign_for_children_ui', $hierarchical, $via_item_type, $args)) {
            $type_obj = 'post' == $via_item_source ? get_post_type_object($via_item_type) : get_taxonomy($via_item_type);
        }
        $agent_types['wp_role'] = (object) array('labels' => (object) array('name' => __('WP Roles', 'pp'), 'singular_name' => __('WP Role', 'pp')));
        $agent_types = apply_filters('pp_list_group_types', array_merge($agent_types, pp_get_group_types(array(), 'object')));
        $agent_types['user'] = (object) array('labels' => (object) array('name' => __('Users'), 'singular_name' => __('User')));
        //if ( ! $skip_user_validation && ! $pp_admin->user_can_admin_role($role_name, $item_id, $src_name, $object_type) )
        //	return;
        static $drew_itemroles_marker;
        if (empty($drew_itemroles_marker)) {
            echo "<input type='hidden' name='pp_post_exceptions' value='true' />";
            $drew_itemroles_marker = true;
        }
        $current_exceptions = isset($this->data->current_exceptions[$for_item_type]) ? $this->data->current_exceptions[$for_item_type] : array();
        // ========== OBJECT / TERM EXCEPTION DROPDOWNS ============
        $toggle_agents = count($agent_types) > 1;
        if ($toggle_agents) {
            global $is_ID;
            $class_selected = 'agp-selected_agent agp-agent';
            $class_unselected = 'agp-unselected_agent agp-agent';
            $bottom_margin = !empty($is_IE) ? '-0.7em' : 0;
            $default_agent_type = 'wp_role';
            echo "<div class='hide-if-not-js' style='margin:0 0 {$bottom_margin} 0'>" . "<ul class='pp-list_horiz' style='margin-bottom:-0.1em'>";
            foreach ($agent_types as $agent_type => $gtype_obj) {
                $label = !empty($current_exceptions[$op][$agent_type]) ? sprintf(__('%1$s (%2$s)', 'pp'), $gtype_obj->labels->name, count($current_exceptions[$op][$agent_type])) : $gtype_obj->labels->name;
                $class = $default_agent_type == $agent_type ? "class='{$class_selected}'" : "class='{$class_unselected}'";
                echo "<li {$class}><a href='javascript:void(0)' class='{$op}-{$for_item_type}-{$agent_type}'>" . $label . '</a></li>';
            }
            echo '</ul></div>';
        }
        $class = "class='pp-agents pp-exceptions'";
        //need effective line break here if not IE
        echo "<div style='clear:both;margin:0 0 0.3em 0' {$class}>";
        $pp_agents_ui = pp_init_agents_ui();
        foreach (array_keys($agent_types) as $agent_type) {
            $hide_class = $toggle_agents && $agent_type != $default_agent_type ? ' class="hide-if-js"' : '';
            echo "\r\n<div id='{$op}-{$for_item_type}-{$agent_type}' {$hide_class} style='overflow-x:auto'>";
            $this->render->set_options($agent_type);
            // list all WP roles
            if ('wp_role' == $agent_type) {
                if (!isset($current_exceptions[$op][$agent_type])) {
                    $current_exceptions[$op][$agent_type] = array();
                }
                foreach ($this->data->agent_info['wp_role'] as $agent_id => $role) {
                    if (in_array($role->metagroup_id, array('wp_anon', 'wp_all')) && !defined('PP_ALL_ANON_FULL_EXCEPTIONS') && ('read' != $op || pp_get_option('anonymous_unfiltered'))) {
                        continue;
                    }
                    if (!isset($current_exceptions[$op][$agent_type][$agent_id])) {
                        $current_exceptions[$op][$agent_type][$agent_id] = array();
                    }
                }
                if (!$is_draft_post && 'post' == $via_item_source && 'attachment' != $via_item_type && in_array($op, array('read', 'edit', 'delete'))) {
                    $reqd_caps = map_meta_cap("{$op}_post", 0, $item_id);
                } else {
                    $reqd_caps = false;
                }
            }
            global $wp_roles;
            ?>
			
			<table class="pp-item-exceptions-ui pp-exc-<?php 
            echo $agent_type;
            ?>
" style="width:100%"><tr>
			<?php 
            if ('wp_role' != $agent_type) {
                ?>
				<td class="pp-select-exception-agents" style="display:none;">
				<?php 
                // Select Groups / Users UI
                echo '<div>';
                echo '<div class="pp-agent-select">';
                $args = array_merge($args, array('suppress_extra_prefix' => true, 'ajax_selection' => true, 'display_stored_selections' => false, 'create_dropdowns' => true, 'op' => $op, 'via_item_type' => $via_item_type));
                $pp_agents_ui = pp_init_agents_ui();
                $pp_agents_ui->agents_ui($agent_type, array(), "{$op}:{$for_item_type}:{$agent_type}", array(), $args);
                echo '</div>';
                echo '</div>';
//.........这里部分代码省略.........
开发者ID:severnrescue,项目名称:web,代码行数:101,代码来源:item-exceptions-ui_pp.php

示例11: _cr_user_can

function _cr_user_can($reqd_caps, $object_id = 0, $user_id = 0, $meta_flags = array())
{
    // $meta_flags currently used for 'skip_revision_allowance', 'skip_any_object_check', 'skip_any_term_check', 'skip_id_generation', 'require_full_object_role'
    // For now, skip array_merge with defaults, for perf
    if ($user_id) {
        $user = new WP_User($user_id);
    } else {
        $user = wp_get_current_user();
    }
    if (empty($user)) {
        return false;
    }
    $reqd_caps = (array) $reqd_caps;
    $check_caps = $reqd_caps;
    foreach ($check_caps as $cap_name) {
        if ($meta_caps = map_meta_cap($cap_name, $user->ID, $object_id)) {
            $reqd_caps = array_diff($reqd_caps, array($cap_name));
            $reqd_caps = array_unique(array_merge($reqd_caps, $meta_caps));
        }
    }
    if ('blog' === $object_id) {
        // legacy API support
        $meta_flags['skip_any_object_check'] = true;
        $meta_flags['skip_any_term_check'] = true;
        $meta_flags['skip_id_generation'] = true;
    } elseif (!$object_id) {
        $meta_flags['skip_id_generation'] = true;
    }
    if ($meta_flags) {
        // handle special case revisionary flag
        if (!empty($meta_flags['skip_revision_allowance'])) {
            if (defined('RVY_VERSION')) {
                global $revisionary;
                $revisionary->skip_revision_allowance = true;
                // this will affect the behavior of Role Scoper's user_has_cap filter
            }
            unset($meta_flags['skip_revision_allowance']);
            // no need to set this flag on cap_interceptor
        }
        // set temporary flags for use by our user_has_cap filter
        global $cap_interceptor;
        if (isset($cap_interceptor)) {
            foreach ($meta_flags as $flag => $value) {
                $cap_interceptor->{$flag} = $value;
            }
        } else {
            $meta_flags = array();
        }
    }
    $capabilities = apply_filters('user_has_cap', $user->allcaps, $reqd_caps, array($reqd_caps, $user->ID, $object_id));
    if ($meta_flags) {
        // clear temporary flags
        foreach ($meta_flags as $flag => $value) {
            $cap_interceptor->{$flag} = false;
        }
    }
    if (!empty($revisionary)) {
        $revisionary->skip_revision_allowance = false;
    }
    foreach ($reqd_caps as $cap_name) {
        if (empty($capabilities[$cap_name]) || !$capabilities[$cap_name]) {
            // if we're about to fail due to a missing create_child_pages cap, honor edit_pages cap as equivalent
            // TODO: abstract this with cap_defs property
            if ('create_child_pages' == $cap_name) {
                $alternate_cap_name = 'edit_pages';
                $_args = array(array($alternate_cap_name), $user->ID, $object_id);
                $capabilities = apply_filters('user_has_cap', $user->allcaps, array($alternate_cap_name), $_args);
                if (empty($capabilities[$alternate_cap_name]) || !$capabilities[$alternate_cap_name]) {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:77,代码来源:cap-interceptor_rs.php

示例12: test_authorless_posts_capabilties

 /**
  * Test a post without an author.
  *
  * @ticket 27020
  */
 function test_authorless_posts_capabilties()
 {
     $post_id = $this->factory->post->create(array('post_author' => 0, 'post_type' => 'post', 'post_status' => 'publish'));
     $editor = $this->factory->user->create(array('role' => 'editor'));
     $this->assertEquals(array('edit_others_posts', 'edit_published_posts'), map_meta_cap('edit_post', $editor, $post_id));
     $this->assertEquals(array('delete_others_posts', 'delete_published_posts'), map_meta_cap('delete_post', $editor, $post_id));
 }
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:12,代码来源:mapMetaCap.php

示例13: pp_map_meta_cap

function pp_map_meta_cap($cap_name, $user_id = 0, $post_id = 0, $args = array())
{
    if ($post_id) {
        return map_meta_cap($cap_name, $user_id, $post_id);
    }
    $defaults = array('is_author' => false, 'post_type' => '', 'status' => '', 'query_contexts' => array());
    extract(array_merge($defaults, $args), EXTR_SKIP);
    global $current_user;
    if (!$post_type) {
        // sanity check
        return (array) $cap_name;
    }
    if (!$user_id) {
        $user_id = $current_user->ID;
    }
    // force desired status caps and others caps by passing a fake post into map_meta_cap
    $post_author = $is_author ? $user_id : -1;
    if (!$status) {
        $status = in_array($cap_name, array('read_post', 'read_page')) ? 'publish' : 'draft';
    } elseif ('auto-draft' == $status) {
        $status = 'draft';
    }
    $_post = (object) array('ID' => -1, 'post_type' => $post_type, 'post_status' => $status, 'filter' => 'raw', 'post_author' => $post_author, 'query_contexts' => $query_contexts);
    wp_cache_add(-1, $_post, 'posts');
    // prevent querying for fake post
    $return = array_diff(map_meta_cap($cap_name, $user_id, $_post), array(null));
    // post types which leave some basic cap properties undefined result in nulls
    wp_cache_delete(-1, 'posts');
    return $return;
}
开发者ID:severnrescue,项目名称:web,代码行数:30,代码来源:query-interceptor_pp.php

示例14: test_only_users_who_can_manage_options_can_delete_page_for_posts

 /**
  * Test deleting posts page.
  *
  * @ticket 37580
  */
 function test_only_users_who_can_manage_options_can_delete_page_for_posts()
 {
     $post_id = self::factory()->post->create(array('post_type' => 'page', 'post_status' => 'publish'));
     update_option('page_for_posts', $post_id);
     $caps = map_meta_cap('delete_page', $this->user_id, $post_id);
     delete_option('page_for_posts');
     $this->assertEquals(array('manage_options'), $caps);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:13,代码来源:mapMetaCap.php

示例15: map_meta_cap

/**
 * Map meta capabilities to primitive capabilities.
 *
 * This does not actually compare whether the user ID has the actual capability,
 * just what the capability or capabilities are. Meta capability list value can
 * be 'delete_user', 'edit_user', 'remove_user', 'promote_user', 'delete_post',
 * 'delete_page', 'edit_post', 'edit_page', 'read_post', or 'read_page'.
 *
 * @since 2.0.0
 *
 * @global array $post_type_meta_caps Used to get post type meta capabilities.
 *
 * @param string $cap       Capability name.
 * @param int    $user_id   User ID.
 * @param int    $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap.
 *                          "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used
 *                          by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts',
 *                          'edit_others_posts', etc. The parameter is accessed via func_get_args().
 * @return array Actual capabilities for meta capability.
 */
function map_meta_cap($cap, $user_id)
{
    $args = array_slice(func_get_args(), 2);
    $caps = array();
    switch ($cap) {
        case 'remove_user':
            // In multisite the user must be a super admin to remove themselves.
            if (isset($args[0]) && $user_id == $args[0] && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'remove_users';
            }
            break;
        case 'promote_user':
        case 'add_users':
            $caps[] = 'promote_users';
            break;
        case 'edit_user':
        case 'edit_users':
            // Allow user to edit itself
            if ('edit_user' == $cap && isset($args[0]) && $user_id == $args[0]) {
                break;
            }
            // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin.
            if (is_multisite() && (!is_super_admin($user_id) && 'edit_user' === $cap && is_super_admin($args[0]) || !user_can($user_id, 'manage_network_users'))) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'edit_users';
                // edit_user maps to edit_users.
            }
            break;
        case 'delete_post':
        case 'delete_page':
            $post = get_post($args[0]);
            if (!$post) {
                $caps[] = 'do_not_allow';
                break;
            }
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
                if (!$post) {
                    $caps[] = 'do_not_allow';
                    break;
                }
            }
            if (get_option('page_for_posts') == $post->ID || get_option('page_on_front') == $post->ID) {
                $caps[] = 'manage_options';
                break;
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type) {
                /* translators: 1: post type, 2: capability name */
                _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0');
                $caps[] = 'edit_others_posts';
                break;
            }
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('delete_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            // If the post author is set and the user is the author...
            if ($post->post_author && $user_id == $post->post_author) {
                // If the post is published or scheduled...
                if (in_array($post->post_status, array('publish', 'future'), true)) {
                    $caps[] = $post_type->cap->delete_published_posts;
                } elseif ('trash' == $post->post_status) {
                    $status = get_post_meta($post->ID, '_wp_trash_meta_status', true);
                    if (in_array($status, array('publish', 'future'), true)) {
                        $caps[] = $post_type->cap->delete_published_posts;
                    } else {
                        $caps[] = $post_type->cap->delete_posts;
                    }
                } else {
                    // If the post is draft...
                    $caps[] = $post_type->cap->delete_posts;
                }
//.........这里部分代码省略.........
开发者ID:CompositeUK,项目名称:clone.WordPress-Core,代码行数:101,代码来源:capabilities.php


注:本文中的map_meta_cap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。