本文整理汇总了PHP中user_can函数的典型用法代码示例。如果您正苦于以下问题:PHP user_can函数的具体用法?PHP user_can怎么用?PHP user_can使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_can函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verify_cookie
public static function verify_cookie($value)
{
if ($old_user_id = wp_validate_auth_cookie($value, 'logged_in')) {
return user_can($old_user_id, 'view_query_monitor');
}
return false;
}
示例2: pg_get_user_replies_created
function pg_get_user_replies_created($user_id = 0)
{
// Validate user
$user_id2 = bbp_get_user_id($user_id);
$current_user = wp_get_current_user()->ID;
if (empty($user_id)) {
return false;
}
if (bbp_is_user_keymaster()) {
$limit = 'n';
}
if (user_can($current_user, 'moderate')) {
$check = get_user_meta($current_user, 'private_group', true);
if ($check == '') {
$limit = 'n';
}
}
if ($limit != 'n') {
global $wpdb;
$reply = bbp_get_reply_post_type();
$post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$reply}'");
//check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
$allowed_posts = check_private_groups_reply_ids($post_ids);
}
// The default reply query with allowed topic and reply ids array added
// Try to get the topics
$query = bbp_has_replies(array('post_type' => bbp_get_reply_post_type(), 'order' => 'DESC', 'author' => $user_id2, 'post__in' => $allowed_posts));
return apply_filters('pg_get_user_replies_created', $query, $user_id);
}
示例3: save
public function save($id = null)
{
$this->load->helper('memberspace/authorization');
$this->load->helper('flashmessages/flashmessages');
$this->load->model('memberspace/user');
$this->load->helper('form');
$datas = array();
if (isset($_POST) && isset($_POST['save-user'])) {
$datas = $_POST;
unset($_POST['save-user']);
if (isset($_POST['id']) && $_POST['id']) {
if (!user_can('update', 'user', $_POST['id'])) {
add_error(translate('Vous ne pouvez pas modifier cet utilisateur'));
}
} else {
if (!user_can('add', 'user', $_POST['id'])) {
add_error(translate('Vous ne pouvez pas ajouter d\'utilisateur'));
}
}
if ($this->user->fromPost() !== false) {
add_success(translate('L\'utilisateur a bien été ajouté'));
redirect('bo/users/all');
} else {
add_error($this->form_validation->error_string());
}
} else {
if ($id) {
$datas = $this->user->getId($id, 'array');
}
}
return $datas;
}
示例4: dwqa_single_postclass
function dwqa_single_postclass($post_class)
{
global $post, $current_user;
if (get_post_type($post) == 'dwqa-answer') {
$post_class[] = 'dwqa-answer';
$post_class[] = 'dwqa-status-' . get_post_status($post->ID);
if (dwqa_is_answer_flag($post->ID)) {
$post_class[] = 'answer-flagged-content';
}
if (user_can($post->post_author, 'edit_published_posts')) {
$post_class[] = 'staff';
}
$question_id = get_post_meta($post->ID, '_question', true);
$best_answer_id = dwqa_get_the_best_answer($question_id);
if ($best_answer_id && $best_answer_id == $post->ID) {
$post_class[] = 'best-answer';
}
if (!is_user_logged_in() || $current_user->ID != $post->ID || !current_user_can('edit_posts')) {
$post_class[] = 'dwqa-no-click';
}
}
if (get_post_type($post) == 'dwqa-answer' && get_post_type($post) == 'dwqa-question') {
if (in_array('hentry', $post_class)) {
unset($post_class);
}
}
return $post_class;
}
示例5: check_follow
function check_follow($matches)
{
#support of "meta=follow" option for admins. disabled by default to minify processing.
if (!$this->options['dont_mask_admin_follow']) {
return false;
}
$id = array(get_comment_ID(), get_the_ID());
//it is either page or post
if ($id[0]) {
$this->debug_info('It is a comment. id ' . $id[0]);
} elseif ($id[1]) {
$this->debug_info('It is a page. id ' . $id[1]);
}
$author = false;
if ($id[0]) {
$author = get_comment_author($id[0]);
} else {
if ($id[1]) {
$author = get_the_author_meta('ID');
}
}
if (!$author) {
$this->debug_info('it is neither post or page, applying usual rules');
} elseif (user_can($author, 'manage_options') && (stripos($matches[0], 'rel="follow"') !== FALSE || stripos($matches[0], "rel='follow'") !== FALSE)) {
$this->debug_info('This link has a follow atribute and is posted by admin, not masking it.');
#wordpress adds rel="nofollow" by itself when posting new link in comments. get rid of it! Also, remove our follow attibute - it is unneccesary.
return str_ireplace(array('rel="follow"', "rel='follow'", 'rel="nofollow"'), '', $matches[0]);
} else {
$this->debug_info('it does not have rel follow or is not posted by admin, masking it');
}
return false;
}
示例6: user_can_translate
/**
* Checks whether the input user is allowed to edit this job
*
* @param stdClass|WP_User $user
*
* @return bool
*/
public function user_can_translate($user)
{
$translator_id = $this->get_translator_id();
$user_can_take_this_job = $translator_id === 0 || $translator_id === (int) $user->ID;
$translator_has_job_language_pairs = $this->blog_translators->is_translator($user->ID, array('lang_from' => $this->get_source_language_code(), 'lang_to' => $this->get_language_code()));
return $user_can_take_this_job && $translator_has_job_language_pairs || method_exists($user, 'has_cap') && $user->has_cap('manage_options') || !method_exists($user, 'has_cap') && user_can($user->ID, 'manage_options');
}
示例7: fes_22_upgrade_vendor_permissions
/**
* Upgrades vendor permissions
*
* @since 2.2
* @return void
*/
function fes_22_upgrade_vendor_permissions()
{
$fes_version = get_option('fes_db_version', '2.1');
if (version_compare($fes_version, '2.2', '>=')) {
return;
}
ignore_user_abort(true);
if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
set_time_limit(0);
}
$step = isset($_GET['step']) ? absint($_GET['step']) : 1;
$offset = $step == 1 ? 0 : $step * 100;
$users = new WP_User_Query(array('fields' => 'ID', 'number' => 100, 'offset' => $offset));
$users = $users->results;
if ($users && count($users) > 0) {
foreach ($users as $user => $id) {
if (user_can($id, 'fes_is_vendor') && !user_can($id, 'fes_is_admin') && !user_can($id, 'administrator') && !user_can($id, 'editor')) {
$user = new WP_User($id);
$user->add_role('frontend_vendor');
}
}
// Keys found so upgrade them
$step++;
$redirect = add_query_arg(array('page' => 'fes-upgrades', 'edd_upgrade' => 'upgrade_vendor_permissions', 'step' => $step), admin_url('index.php'));
wp_redirect($redirect);
exit;
} else {
// No more keys found, update the DB version and finish up
update_option('fes_db_version', fes_plugin_version);
wp_redirect(admin_url('admin.php?page=fes-about'));
exit;
}
}
示例8: testTranslatorCaps
function testTranslatorCaps()
{
global $wp_roles;
$this->assertTrue($wp_roles->is_role('translator'));
# Translators can manage translation jobs:
$this->assertTrue(user_can($this->translator->ID, 'edit_bbl_jobs'));
}
示例9: force_2fa
function force_2fa()
{
// Allows WP.com login to a local account if it matches the local account.
add_filter('jetpack_sso_match_by_email', '__return_true', 9999);
// multisite
if (is_multisite()) {
// Hide the login form
add_filter('jetpack_remove_login_form', '__return_true', 9999);
add_filter('jetpack_sso_bypass_login_forward_wpcom', '__return_true', 9999);
add_filter('jetpack_sso_display_disclaimer', '__return_false', 9999);
add_filter('wp_authenticate_user', function () {
return new WP_Error('wpcom-required', "Local login disabled for this site.");
}, 9999);
add_filter('jetpack_sso_require_two_step', '__return_true');
add_filter('allow_password_reset', '__return_false');
} else {
// Completely disable the standard login form for admins.
add_filter('wp_authenticate_user', function ($user) {
if ($user->has_cap($this->role)) {
return new WP_Error('wpcom-required', "Local login disabled for this account.", $user->user_login);
}
return $user;
}, 9999);
add_filter('allow_password_reset', function ($allow, $user_id) {
if (user_can($user_id, $this->role)) {
return false;
}
return $allow;
}, 9999, 2);
add_action('jetpack_sso_pre_handle_login', array($this, 'jetpack_set_two_step_for_admins'));
}
}
示例10: bogo_get_user_locale
function bogo_get_user_locale($user_id = 0)
{
global $current_user;
$default_locale = bogo_get_default_locale();
$user_id = absint($user_id);
if (!$user_id) {
if (function_exists('wp_get_current_user') && !empty($current_user)) {
$user_id = get_current_user_id();
} elseif (!($user_id = apply_filters('determine_current_user', false))) {
return $default_locale;
}
}
$locale = get_user_option('locale', $user_id);
if (bogo_is_available_locale($locale) && user_can($user_id, 'bogo_access_locale', $locale)) {
return $locale;
}
if (user_can($user_id, 'bogo_access_locale', $default_locale)) {
return $default_locale;
}
foreach ((array) bogo_available_locales() as $locale) {
if (user_can($user_id, 'bogo_access_locale', $locale)) {
return $locale;
}
}
return $default_locale;
}
示例11: pg_has_topics
function pg_has_topics($args = '')
{
//check if being called by subscriptions and if so skip filtering (as you can only subscribe to forums you can already see)
if ($args['post__in']) {
return $args;
}
$default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
if ($default_post_parent == 'any') {
if (bbp_is_user_keymaster()) {
return $args;
}
$user_id = wp_get_current_user()->ID;
if (user_can($user_id, 'moderate')) {
$check = get_user_meta($user_id, 'private_group', true);
if ($check == '') {
return $args;
}
}
global $wpdb;
$topic = bbp_get_topic_post_type();
$post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$topic}'");
//check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
$allowed_posts = check_private_groups_topic_ids($post_ids);
$args['post__in'] = $allowed_posts;
}
return $args;
}
示例12: save
public function save($userModel = 'memberspace/user', $mailRedirect = 'memberspace/confirmation/confirm', $redirect = null)
{
$post = $this->input->post();
$modelName = pathinfo($userModel)['filename'];
if (!$post || !isset($post['save-' . $modelName])) {
return array();
}
unset($_POST['save-' . $modelName]);
$this->load->library('form_validation');
if (isset($post['id']) && !user_can('update', $userModel, $post['id'])) {
return $post;
}
$this->load->model($userModel);
$userId = $this->{$modelName}->fromPost();
if ($userId === false) {
add_error($this->form_validation->error_string());
return $post;
}
if (!isset($post['id'])) {
$this->sendMailConfirmation($userId, $mailRedirect);
add_success('Vous avez bien été inscrit !');
} else {
add_success('Vous avez bien mis à jour vos informations');
}
if ($redirect) {
redirect($redirect);
}
return $post;
}
示例13: schoolpress_admin_check
function schoolpress_admin_check()
{
global $user_ID;
if (!user_can($user_ID, 'administrator')) {
wp_redirect(site_url());
}
}
示例14: jr_process_login_form
function jr_process_login_form()
{
global $posted;
if (isset($_REQUEST['redirect_to'])) {
$redirect_to = $_REQUEST['redirect_to'];
} else {
$redirect_to = admin_url();
}
if (is_ssl() && force_ssl_login() && !force_ssl_admin() && 0 !== strpos($redirect_to, 'https') && 0 === strpos($redirect_to, 'http')) {
$secure_cookie = false;
} else {
$secure_cookie = '';
}
$user = wp_signon('', $secure_cookie);
$redirect_to = apply_filters('login_redirect', $redirect_to, isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '', $user);
if (!is_wp_error($user)) {
if (user_can($user, 'manage_options')) {
$redirect_to = admin_url();
}
wp_safe_redirect($redirect_to);
exit;
}
$errors = $user;
return $errors;
}
示例15: _save_search
private static function _save_search($args)
{
extract($args);
if (!empty($user) && !empty($hash)) {
if (!user_can($user->ID, self::$_capabilities['save_search']) || user_can($user->ID, self::$_capabilities['view_leads'])) {
return 'User does not have the capability to save searches.';
}
if (empty($name_exists)) {
$saved_searches = !empty($user->{self::$_meta_keys['lead']['saved_searches']}) ? $user->{self::$_meta_keys['lead']['saved_searches']} : array();
$this_search = array('hash' => $hash, 'name' => $search_name);
if (!empty($user->{self::$_meta_keys['api_user_id']})) {
$saved_search_criteria = DispletRetsIdxResidentialsModel::get_search_criteria_from_hash($hash);
$saved_search_id = DispletRetsIdxUsersApiController::create_saved_search($user->{self::$_meta_keys['api_user_id']}, $search_name, $saved_search_criteria);
if (isset($saved_search_id)) {
$this_search['api_id'] = $saved_search_id;
}
}
$saved_searches[] = $this_search;
update_user_meta($user->ID, self::$_meta_keys['lead']['saved_searches'], $saved_searches);
new DispletRetsIdxEmail('saved_search', array('agent_id' => DispletRetsIdxLeadsModel::get_assigned_agent_id($user->ID), 'lender_id' => DispletRetsIdxLeadsModel::get_assigned_lender_id($user->ID), 'search_url' => trailingslashit(get_permalink(self::$_options['search_results_page_id'])) . $hash, 'user_email' => $user->user_email, 'user_name' => $user->display_name, 'user_phone' => $user->{self::$_meta_keys['lead']['phone']}));
do_action('displetretsidx_post_lead_saved_search', $user->ID, $this_search);
return 'Saved Search';
}
}
}