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


PHP current_user_can_for_blog函数代码示例

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


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

示例1: callback

 function callback($path = '', $blog_id = 0, $user_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     if (!current_user_can_for_blog($blog_id, 'list_users')) {
         return new WP_Error('unauthorized', 'User cannot view users for specified site', 403);
     }
     // Get the user by ID or login
     $get_by = false !== strpos($path, '/users/login:') ? 'login' : 'id';
     $user = get_user_by($get_by, $user_id);
     if (!$user) {
         return new WP_Error('unknown_user', 'Unknown user', 404);
     }
     if (!is_user_member_of_blog($user->ID, $blog_id)) {
         return new WP_Error('unknown_user_for_site', 'Unknown user for site', 404);
     }
     if ('GET' === $this->api->method) {
         return $this->get_user($user->ID);
     } else {
         if ('POST' === $this->api->method) {
             if (!current_user_can_for_blog($blog_id, 'promote_users')) {
                 return new WP_Error('unauthorized', 'User cannot promote users for specified site', 403);
             }
             if (get_current_user_id() == $user_id) {
                 return new WP_Error('unauthorized', 'You cannot change your own role', 403);
             }
             return $this->update_user($user_id);
         } else {
             return new WP_Error('bad_request', 'An unsupported request method was used.');
         }
     }
 }
开发者ID:StefanBonilla,项目名称:CoupSoup,代码行数:34,代码来源:class.wpcom-json-api-site-user-endpoint.php

示例2: callback

 function callback($path = '', $blog_id = 0, $user_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     if (!current_user_can_for_blog($blog_id, 'list_users')) {
         return new WP_Error('unauthorized', 'User cannot view users for specified site', 403);
     }
     if (!is_user_member_of_blog($user_id, $blog_id)) {
         return new WP_Error('unauthorized', 'User cannot view users for specified site', 403);
     }
     if ('GET' === $this->api->method) {
         return $this->get_user($user_id);
     } else {
         if ('POST' === $this->api->method) {
             if (!current_user_can_for_blog($blog_id, 'promote_users')) {
                 return new WP_Error('unauthorized', 'User cannot promote users for specified site', 403);
             }
             if (get_current_user_id() == $user_id) {
                 return new WP_Error('unauthorized', 'You cannot change your own role', 403);
             }
             return $this->update_user($user_id);
         } else {
             return new WP_Error('bad_request', 'An unsupported request method was used.');
         }
     }
 }
开发者ID:popthestack,项目名称:jetpack,代码行数:28,代码来源:class.wpcom-json-api-site-user-endpoint.php

示例3: init

 static function init()
 {
     if (current_user_can_for_blog(get_current_blog_id(), 'switch_themes')) {
         self::get_steps();
         if (!(defined('DOING_AJAX') && DOING_AJAX)) {
             if (apply_filters('jetpack_start_render_wizard', true)) {
                 add_action('admin_init', array(__CLASS__, 'render_wizard'), 100);
             }
         }
     }
 }
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:11,代码来源:class.jetpack-start.php

示例4: require_capability

/**
 * Check current user for a capability, throw an exception if not allowed
 **/
function require_capability($cap, $kwargs = null)
{
    if (!empty($kwargs['blogid'])) {
        $answer = current_user_can_for_blog($kwargs['blogid'], $cap);
    } else {
        $answer = current_user_can($cap);
    }
    if (!$answer) {
        if (!empty($kwargs['ajax'])) {
            throw new AjaxHttp500("You can't do that");
        } else {
            throw new Exception("You can't do that");
        }
    }
    return true;
}
开发者ID:newsapps,项目名称:wordpress-mtv,代码行数:19,代码来源:shortcuts.php

示例5: can_install

 /**
  * If current user can:
  * - install extensions
  * - delete extensions
  * @return bool
  */
 public function can_install()
 {
     static $can_install = null;
     if ($can_install === null) {
         $capability = 'install_plugins';
         if (is_multisite()) {
             // only network admin can change files that affects the entire network
             $can_install = current_user_can_for_blog(get_current_blog_id(), $capability);
         } else {
             $can_install = current_user_can($capability);
         }
         if ($can_install) {
             // also you can use this method to get the capability
             $can_install = $capability;
         }
     }
     return $can_install;
 }
开发者ID:northpen,项目名称:northpen,代码行数:24,代码来源:class--fw-extensions-manager.php

示例6: __construct

 function __construct()
 {
     global $blog_id;
     $this->current_blog_id = $blog_id;
     /* copied from depricated get_blog_list */
     global $wpdb;
     $blogs = $wpdb->get_results($wpdb->prepare("SELECT blog_id, domain, path FROM {$wpdb->blogs} WHERE site_id = %d AND public = '1' AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A);
     $this->blogs = array();
     $sort_array = array();
     foreach ((array) $blogs as $details) {
         if (!current_user_can_for_blog($details['blog_id'], 'upload_files') || $details['blog_id'] == $this->current_blog_id) {
             continue;
         }
         $details['name'] = get_blog_option($details['blog_id'], 'blogname');
         $this->blogs[] = $details;
         $sort_array[] = strtolower($details['name']);
     }
     array_multisort($sort_array, SORT_ASC, $this->blogs);
 }
开发者ID:Buooy,项目名称:wp_network_shared_media,代码行数:19,代码来源:network_shared_media.php

示例7: setup_nav

 function setup_nav()
 {
     global $blog_id;
     //check multisite or normal mode for correct permission checking
     if (is_multisite() && $blog_id != BP_ROOT_BLOG) {
         //FIXME MS mode doesn't seem to recognize cross subsite caps, using the proper functions, for now we use switch_blog.
         $current_blog = $blog_id;
         switch_to_blog(BP_ROOT_BLOG);
         $can_manage_events = current_user_can_for_blog(BP_ROOT_BLOG, 'edit_events');
         $can_manage_locations = current_user_can_for_blog(BP_ROOT_BLOG, 'edit_locations');
         $can_manage_bookings = current_user_can_for_blog(BP_ROOT_BLOG, 'manage_bookings');
         switch_to_blog($current_blog);
     } else {
         $can_manage_events = current_user_can('edit_events');
         $can_manage_locations = current_user_can('edit_locations');
         $can_manage_bookings = current_user_can('manage_bookings');
     }
     /* Add 'Events' to the main user profile navigation */
     $main_nav = array('name' => __('Events', 'dbem'), 'slug' => em_bp_get_slug(), 'position' => 80, 'screen_function' => 'bp_em_events', 'default_subnav_slug' => 'profile');
     $em_link = trailingslashit(bp_loggedin_user_domain() . em_bp_get_slug());
     /* Create SubNav Items */
     $sub_nav[] = array('name' => __('My Profile', 'dbem'), 'slug' => 'profile', 'parent_slug' => em_bp_get_slug(), 'parent_url' => $em_link, 'screen_function' => 'bp_em_events', 'position' => 10);
     $sub_nav[] = array('name' => __('Events I\'m Attending', 'dbem'), 'slug' => 'attending', 'parent_slug' => em_bp_get_slug(), 'parent_url' => $em_link, 'screen_function' => 'bp_em_attending', 'position' => 20, 'user_has_access' => bp_is_my_profile());
     if ($can_manage_events) {
         $sub_nav[] = array('name' => __('My Events', 'dbem'), 'slug' => 'my-events', 'parent_slug' => em_bp_get_slug(), 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_events', 'position' => 30, 'user_has_access' => bp_is_my_profile());
     }
     if ($can_manage_locations && get_option('dbem_locations_enabled')) {
         $sub_nav[] = array('name' => __('My Locations', 'dbem'), 'slug' => 'my-locations', 'parent_slug' => em_bp_get_slug(), 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_locations', 'position' => 40, 'user_has_access' => bp_is_my_profile());
     }
     if ($can_manage_bookings && get_option('dbem_rsvp_enabled')) {
         $sub_nav[] = array('name' => __('My Event Bookings', 'dbem'), 'slug' => 'my-bookings', 'parent_slug' => em_bp_get_slug(), 'parent_url' => $em_link, 'screen_function' => 'bp_em_my_bookings', 'position' => 50, 'user_has_access' => bp_is_my_profile());
     }
     if (bp_is_active('groups')) {
         /* Create Profile Group Sub-Nav */
         $sub_nav[] = array('name' => __('Events', 'dbem'), 'slug' => 'group-events', 'parent_slug' => bp_get_groups_slug(), 'parent_url' => trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug()), 'screen_function' => 'bp_em_my_group_events', 'position' => 60, 'user_has_access' => bp_is_my_profile());
     }
     parent::setup_nav($main_nav, $sub_nav);
     add_action('bp_init', array(&$this, 'setup_group_nav'));
 }
开发者ID:rajankz,项目名称:webspace,代码行数:39,代码来源:bp-em-core.php

示例8: jps_start

function jps_start()
{
    if (current_user_can_for_blog(get_current_blog_id(), 'switch_themes')) {
        if (isset($_GET['jps_wizard_end'])) {
            add_option('jpstart_wizard_has_run', true);
            wp_safe_redirect(remove_query_arg('jps_wizard_end'));
            die;
        }
        if (!get_option('jpstart_wizard_has_run') || isset($_GET['jps_wizard_start'])) {
            // Hack to get sure  the welcome panel gets shown.
            update_user_meta(get_current_user_id(), 'show_welcome_panel', true);
            require_once plugin_dir_path(__FILE__) . 'class.jetpack-start.php';
            if (isset($_GET['jps_wizard_start'])) {
                delete_option('jpstart_wizard_has_run');
                wp_safe_redirect(admin_url());
            }
            Jetpack_Start::init();
        }
        require_once plugin_dir_path(__FILE__) . 'class.jetpack-start-welcome-panel.php';
        Jetpack_Start_Welcome_Panel::init();
    }
}
开发者ID:kevinaxu,项目名称:99boulders,代码行数:22,代码来源:jetpack-start.php

示例9: current_user_can_for_blog

 /**
  * Wrapper for the native WP current_user_can_for_blog() method.
  * This is provided as a handy method for a couple things:
  * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to write those filters wherever current_user_can is called).
  * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
  *
  * @since 4.5.0
  *
  * @param int      $blog_id The blog id that is being checked for.
  * @param string $cap     The cap being checked.
  * @param string $context The context where the current_user_can is being called from.
  * @param int    $id          Optional. Id for item where current_user_can is being called from (used in map_meta_cap() filters.
  *
  * @return bool  Whether user can or not.
  */
 public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
 {
     $user_can = !empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap);
     //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
     $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, $blog_id, $cap, $id);
     $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, $blog_id, $cap, $id);
     return $user_can;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:23,代码来源:EE_Capabilities.core.php

示例10: setup_admin_bar

 function setup_admin_bar()
 {
     global $bp, $blog_id;
     // Prevent debug notices
     $wp_admin_nav = array();
     // Menus for logged in user
     if (is_user_logged_in()) {
         //check multisite or normal mode for correct permission checking
         if (is_multisite() && $blog_id != BP_ROOT_BLOG) {
             //FIXME MS mode doesn't seem to recognize cross subsite caps, using the proper functions, for now we use switch_blog.
             $current_blog = $blog_id;
             switch_to_blog(BP_ROOT_BLOG);
             $can_manage_events = current_user_can_for_blog(BP_ROOT_BLOG, 'edit_events');
             $can_manage_locations = current_user_can_for_blog(BP_ROOT_BLOG, 'edit_locations');
             $can_manage_bookings = current_user_can_for_blog(BP_ROOT_BLOG, 'manage_bookings');
             switch_to_blog($current_blog);
         } else {
             $can_manage_events = current_user_can('edit_events');
             $can_manage_locations = current_user_can('edit_locations');
             $can_manage_bookings = current_user_can('manage_bookings');
         }
         $em_link = trailingslashit(bp_loggedin_user_domain() . em_bp_get_slug());
         /* Add 'Events' to the main user profile navigation */
         $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-em-' . $this->id, 'title' => __('Events', 'dbem'), 'href' => $em_link);
         /* Create SubNav Items */
         $wp_admin_nav[] = array('parent' => 'my-em-' . $this->id, 'id' => 'my-em-' . $this->id . '-profile', 'title' => __('My Profile', 'dbem'), 'href' => $em_link . 'profile/');
         $wp_admin_nav[] = array('parent' => 'my-em-' . $this->id, 'id' => 'my-em-' . $this->id . '-attending', 'title' => __('Events I\'m Attending', 'dbem'), 'href' => $em_link . 'attending/');
         if ($can_manage_events) {
             $wp_admin_nav[] = array('parent' => 'my-em-' . $this->id, 'id' => 'my-em-' . $this->id . '-my-events', 'title' => __('My Events', 'dbem'), 'href' => $em_link . 'my-events/');
         }
         if ($can_manage_locations && get_option('dbem_locations_enabled')) {
             $wp_admin_nav[] = array('parent' => 'my-em-' . $this->id, 'id' => 'my-em-' . $this->id . '-my-locations', 'title' => __('My Locations', 'dbem'), 'href' => $em_link . 'my-locations/');
         }
         if ($can_manage_bookings && get_option('dbem_rsvp_enabled')) {
             $wp_admin_nav[] = array('parent' => 'my-em-' . $this->id, 'id' => 'my-em-' . $this->id . '-my-bookings', 'title' => __('My Event Bookings', 'dbem'), 'href' => $em_link . 'my-bookings/');
         }
         if (bp_is_active('groups')) {
             /* Create Profile Group Sub-Nav */
             $wp_admin_nav[] = array('parent' => 'my-account-groups', 'id' => 'my-account-groups-' . $this->id, 'title' => __('Events', 'dbem'), 'href' => trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug()) . 'group-events/');
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
开发者ID:batruji,项目名称:metareading,代码行数:43,代码来源:bp-em-core.php

示例11: is_translatable_by_user

 /**
  * Check if the current user has the appropriate capabilities to edit the given post.
  *
  * @param WP_Post $post
  * @param int     $blog_id
  *
  * @return bool
  */
 private function is_translatable_by_user(WP_Post $post, $blog_id)
 {
     $blog_id = absint($blog_id);
     $remote_post = $this->data->get_remote_post($post, $blog_id);
     if (isset($remote_post->dummy) && $remote_post->dummy === true) {
         return current_user_can_for_blog($blog_id, 'edit_posts');
     }
     return current_user_can_for_blog($blog_id, 'edit_post', $remote_post->ID);
 }
开发者ID:aloisia,项目名称:multilingual-press,代码行数:17,代码来源:Mlp_Translation_Metabox.php

示例12: get

 /**
  * Fetch next, previous or first post
  *
  * @param string $what prev, next or first
  *
  * @return string URL of requested post
  */
 static function get($what = 'next')
 {
     if ('first' == $what) {
         return static::getFirst();
     }
     global $blog_id;
     global $post;
     $current_post_id = $post->ID;
     $book_structure = static::getBookStructure();
     $order = $book_structure['__order'];
     $pos = array_keys($order);
     $what = $what == 'next' ? 'next' : 'prev';
     // Move internal pointer to correct position
     reset($pos);
     while ($find_me = current($pos)) {
         if ($find_me == $current_post_id) {
             break;
         } else {
             next($pos);
         }
     }
     // Get next/previous
     $what($pos);
     while ($post_id = current($pos)) {
         if ($order[$post_id]['post_status'] == 'publish') {
             break;
         } elseif (current_user_can_for_blog($blog_id, 'read')) {
             break;
         } else {
             $what($pos);
         }
     }
     return empty($post_id) ? '/' : get_permalink($post_id);
 }
开发者ID:Emaratilicious,项目名称:oddibooks,代码行数:41,代码来源:class-pb-book.php

示例13: nxt_admin_bar_my_sites_menu

/**
 * Add the "My Sites/[Site Name]" menu and all submenus.
 *
 * @since 3.1.0
 */
function nxt_admin_bar_my_sites_menu($nxt_admin_bar)
{
    global $nxtdb;
    // Don't show for logged out users or single site mode.
    if (!is_user_logged_in() || !is_multisite()) {
        return;
    }
    // Show only when the user has at least one site, or they're a super admin.
    if (count($nxt_admin_bar->user->blogs) < 1 && !is_super_admin()) {
        return;
    }
    $nxt_admin_bar->add_menu(array('id' => 'my-sites', 'title' => __('My Sites'), 'href' => admin_url('my-sites.php')));
    if (is_super_admin()) {
        $nxt_admin_bar->add_group(array('parent' => 'my-sites', 'id' => 'my-sites-super-admin'));
        $nxt_admin_bar->add_menu(array('parent' => 'my-sites-super-admin', 'id' => 'network-admin', 'title' => __('Network Admin'), 'href' => network_admin_url()));
        $nxt_admin_bar->add_menu(array('parent' => 'network-admin', 'id' => 'network-admin-d', 'title' => __('Dashboard'), 'href' => network_admin_url()));
        $nxt_admin_bar->add_menu(array('parent' => 'network-admin', 'id' => 'network-admin-s', 'title' => __('Sites'), 'href' => network_admin_url('sites.php')));
        $nxt_admin_bar->add_menu(array('parent' => 'network-admin', 'id' => 'network-admin-u', 'title' => __('Users'), 'href' => network_admin_url('users.php')));
        $nxt_admin_bar->add_menu(array('parent' => 'network-admin', 'id' => 'network-admin-v', 'title' => __('Visit Network'), 'href' => network_home_url()));
    }
    // Add site links
    $nxt_admin_bar->add_group(array('parent' => 'my-sites', 'id' => 'my-sites-list', 'meta' => array('class' => is_super_admin() ? 'ab-sub-secondary' : '')));
    $blue_nxt_logo_url = includes_url('images/nxtmini-blue.png');
    foreach ((array) $nxt_admin_bar->user->blogs as $blog) {
        // @todo Replace with some favicon lookup.
        //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $blue_nxt_logo_url ) ) . '" alt="Blavatar" width="16" height="16" />';
        $blavatar = '<img src="' . esc_url($blue_nxt_logo_url) . '" alt="' . esc_attr__('Blavatar') . '" width="16" height="16" class="blavatar"/>';
        $blogname = empty($blog->blogname) ? $blog->domain : $blog->blogname;
        $menu_id = 'blog-' . $blog->userblog_id;
        $nxt_admin_bar->add_menu(array('parent' => 'my-sites-list', 'id' => $menu_id, 'title' => $blavatar . $blogname, 'href' => get_admin_url($blog->userblog_id)));
        $nxt_admin_bar->add_menu(array('parent' => $menu_id, 'id' => $menu_id . '-d', 'title' => __('Dashboard'), 'href' => get_admin_url($blog->userblog_id)));
        if (current_user_can_for_blog($blog->userblog_id, 'edit_posts')) {
            $nxt_admin_bar->add_menu(array('parent' => $menu_id, 'id' => $menu_id . '-n', 'title' => __('New Post'), 'href' => get_admin_url($blog->userblog_id, 'post-new.php')));
            $nxt_admin_bar->add_menu(array('parent' => $menu_id, 'id' => $menu_id . '-c', 'title' => __('Manage Comments'), 'href' => get_admin_url($blog->userblog_id, 'edit-comments.php')));
        }
        $nxt_admin_bar->add_menu(array('parent' => $menu_id, 'id' => $menu_id . '-v', 'title' => __('Visit Site'), 'href' => get_home_url($blog->userblog_id, '/')));
    }
}
开发者ID:nxtclass,项目名称:NXTClass,代码行数:43,代码来源:admin-bar.php

示例14: test_borked_current_user_can_for_blog

	function test_borked_current_user_can_for_blog() {
		if ( ! is_multisite() ) {
			$this->markTestSkipped( 'Test only runs in multisite' );
			return;
		}

		$orig_blog_id = get_current_blog_id();
		$blog_id = $this->factory->blog->create();

		$this->_nullify_current_user();

		add_action( 'switch_blog', array( $this, '_nullify_current_user_and_keep_nullifying_user' ) );

		current_user_can_for_blog( $blog_id, 'edit_posts' );

		$this->assertEquals( $orig_blog_id, get_current_blog_id() );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:17,代码来源:capabilities.php

示例15: bp_current_user_can

/**
 * Whether current user has a capability or role. Can be passed blog ID, or will
 * use the root blod by default
 *
 * @since BuddyPress (1.6)
 *
 * @param string $capability Capability or role name.
 * @param int $blog_id Blog ID
 * @return bool
 */
function bp_current_user_can($capability, $blog_id = 0)
{
    // Use root blog if no ID passed
    if (empty($blog_id)) {
        $blog_id = bp_get_root_blog_id();
    }
    $retval = current_user_can_for_blog($blog_id, $capability);
    return (bool) apply_filters('bp_current_user_can', $retval, $capability, $blog_id);
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:19,代码来源:bp-core-caps.php


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