/** * Get the user that is logged in */ public function get_logged_in_user() { global $user_ID; if (is_user_logged_in()) { // this refers to the global method not local $loggedIn = (bool) true; } else { $loggedIn = (bool) false; } $avatarURL = get_avatar($user_ID); $user = get_userdata($user_ID); $dom = new DOMDocument(); $dom->loadHTML($avatarURL); $avatarURL = $dom->getElementsByTagName('img')->item(0)->getAttribute('src'); $result = array('id' => $user_ID, 'displayName' => "", 'loggedIn' => $loggedIn, 'avatar' => $avatarURL); if ($user) { $result['displayName'] = $user->data->display_name; $result['contact'] = $user->data->user_email; } if (is_multisite()) { $user_blogs = get_blogs_of_user($user_ID); $result['blogs'] = $user_blogs; } return $result; }
public function initialize() { $this->user = new stdClass(); if (is_user_logged_in()) { /* Populate settings we need for the menu based on the current user. */ $this->user->blogs = get_blogs_of_user(get_current_user_id()); if (is_multisite()) { $this->user->active_blog = get_active_blog_for_user(get_current_user_id()); $this->user->domain = empty($this->user->active_blog) ? user_admin_url() : trailingslashit(get_home_url($this->user->active_blog->blog_id)); $this->user->account_domain = $this->user->domain; } else { $this->user->active_blog = $this->user->blogs[get_current_blog_id()]; $this->user->domain = trailingslashit(home_url()); $this->user->account_domain = $this->user->domain; } } add_action('wp_head', 'wp_admin_bar_header'); add_action('admin_head', 'wp_admin_bar_header'); if (current_theme_supports('admin-bar')) { $admin_bar_args = get_theme_support('admin-bar'); // add_theme_support( 'admin-bar', array( 'callback' => '__return_false') ); $header_callback = $admin_bar_args[0]['callback']; } if (empty($header_callback)) { $header_callback = '_admin_bar_bump_cb'; } add_action('wp_head', $header_callback); wp_enqueue_script('admin-bar'); wp_enqueue_style('admin-bar'); do_action('admin_bar_init'); }
/** * @access public */ public function initialize() { $this->user = new stdClass(); if (is_user_logged_in()) { /* Populate settings we need for the menu based on the current user. */ $this->user->blogs = get_blogs_of_user(get_current_user_id()); $this->user->active_blog = $this->user->blogs[get_current_blog_id()]; $this->user->domain = trailingslashit(home_url()); $this->user->account_domain = $this->user->domain; } add_action('wp_head', 'wp_admin_bar_header'); add_action('admin_head', 'wp_admin_bar_header'); if (current_theme_supports('admin-bar')) { /** * To remove the default padding styles from WordPress for the Toolbar, use the following code: * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); */ $admin_bar_args = get_theme_support('admin-bar'); $header_callback = $admin_bar_args[0]['callback']; } if (empty($header_callback)) { $header_callback = '_admin_bar_bump_cb'; } add_action('wp_head', $header_callback); wp_enqueue_script('admin-bar'); wp_enqueue_style('admin-bar'); /** * Fires after WP_Admin_Bar is initialized. * * @since 3.1.0 */ do_action('admin_bar_init'); }
/** * The content for the content section. * * @since Client Dash 1.4 */ public function block_output() { // Set up current user information $current_user = wp_get_current_user(); // Get the blogs this current user has access to $blogs = get_blogs_of_user($current_user->ID); ?> <table class="widefat fixed"> <tbody> <?php // Construct a table row for each blog owned by user $i = 0; foreach ($blogs as $blog) { $i++; // Every other row is alternate for coloring if ($i % 2 == 0) { echo '<tr class="alternate">'; } else { echo '<tr>'; } echo '<td valign="top" style="border-right: 1px solid #ccc;">'; echo '<h3>' . $blog->blogname . '</h3>'; echo '<p><a href="' . $blog->siteurl . '">Visit</a> | '; echo '<a href="' . $blog->siteurl . '/wp-admin/">Dashboard</a></p>'; echo '</td>'; echo '</tr>'; } ?> </tbody> </table> <?php }
protected function handle_private_loggedin_multisite($options) { if (is_multisite() && $options['aioi_ms_requiremember'] && !is_network_admin()) { // Need to check logged-in user is a member of this sub-site $blogs = get_blogs_of_user(get_current_user_id()); if (!wp_list_filter($blogs, array('userblog_id' => get_current_blog_id()))) { // Not a member $blog_name = get_bloginfo('name'); $output = '<p>' . esc_html(sprintf('You attempted to access the "%1$s" sub-site, but you are not currently a member of this site. If you believe you should be able to access "%1$s", please contact your network administrator.', $blog_name)) . '</p>'; if (!empty($blogs)) { $output .= '<p>You <i>are</i> a member of the following sites:</p>'; $output .= '<table>'; foreach ($blogs as $blog) { $output .= "<tr>"; $output .= "<td valign='top'>"; $output .= "<a href='" . esc_url(get_home_url($blog->userblog_id)) . "'>" . esc_html($blog->blogname) . "</a>"; $output .= "</td>"; $output .= "</tr>"; } $output .= '</table>'; } wp_die($output); } } }
function hide_dashboard() { global $blog, $current_user, $id, $parent_file, $wphd_user_capability; if (!current_user_can('' . $wphd_user_capability . '')) { /* First, let's get rid of the Help menu, Update nag, Personal Options section */ echo "\n" . '<style type="text/css" media="screen">#your-profile { display: none; } .update-nag, #contextual-help-wrap, #contextual-help-link-wrap { display: none !important; }</style>'; echo "\n" . '<script type="text/javascript">jQuery(document).ready(function($) { $(\'form#your-profile > h3:first\').hide(); $(\'form#your-profile > table:first\').hide(); $(\'form#your-profile\').show(); });</script>' . "\n"; /* Now, let's fix the sidebar admin menu - go away, Dashboard link. */ /* If Multisite, check whether they are in the User Dashboard before removing links */ $user_id = get_current_user_id(); $blogs = get_blogs_of_user($user_id); if (is_multisite() && is_admin() && empty($blogs)) { return; } else { remove_menu_page('index.php'); /* Hides Dashboard menu */ remove_menu_page('separator1'); /* Hides separator under Dashboard menu*/ } /* Last, but not least, let's redirect folks to their profile when they login or if they try to access the Dashboard via direct URL */ if (is_multisite() && is_admin() && empty($blogs)) { return; } else { if ($parent_file == 'index.php') { if (headers_sent()) { echo '<meta http-equiv="refresh" content="0;url=' . admin_url('profile.php') . '">'; echo '<script type="text/javascript">document.location.href="' . admin_url('profile.php') . '"</script>'; } else { wp_redirect(admin_url('profile.php')); exit; } } } } }
/** * Prepare a single user output for response * * @param object $user User object. * @param WP_REST_Request $request Request object. * @return WP_REST_Response Response data. */ public function prepare_item_for_response($user, $request) { $roles = $user->roles; if (empty($roles)) { $isadmin = false; } else { $isadmin = hash_equals($roles[0], 'administrator'); } $user_id = $user->ID; $user_blogs = get_blogs_of_user($user_id); $site = urldecode($request['site']); $data = array('id' => $user->ID, 'username' => $user->user_login, 'name' => $user->display_name, 'email' => $user->user_email, 'admin' => $isadmin, 'role' => $roles[0], 'site' => $_SERVER['SERVER_NAME'], 'host' => $_SERVER['HTTP_HOST'], 'blogs' => $user_blogs); $context = !empty($request['context']) ? $request['context'] : 'embed'; $data = $this->filter_response_by_context($data, $context); $data = $this->add_additional_fields_to_object($data, $request); // Wrap the data in a response object $response = rest_ensure_response($data); //$response->add_links( $this->prepare_links( $user ) ); /** * Filter user data returned from the REST API. * * @param WP_REST_Response $response The response object. * @param object $user User object used to create response. * @param WP_REST_Request $request Request object. */ return apply_filters('rest_prepare_user', $response, $user, $request); }
function projects_page() { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $user_blogs = get_blogs_of_user($user_id); foreach ($user_blogs as $user_blog) { if ($user_blog->path == '/') { # do nothing } else { $user_blog_id = $user_blog->userblog_id; } } $output = ''; if (current_user_can_for_blog($user_blog_id, 'administrator') || current_user_can_for_blog($user_blog_id, 'das_designer')) { $output .= '<div class="das-project-admin-wrap-main">'; $output .= '<a class="buy-extensions-btn" href="http://www.slickremix.com/downloads/category/design-approval-system/" target="_blank">' . __('Get Extensions Here!', 'design-approval-system') . '</a>'; $output .= '<h2 class="project-board-header">' . __('Project Board', 'design-approval-system') . '</h2>'; $output .= '<div class="use-of-plugin">' . __('Below are your Clients and their Projects. Learn how it all works ', 'design-approval-system') . '<a href="http://www.slickremix.com/design-approval-system-docs" target="_blank">' . __('here', 'design-approval-system') . '</a>.</div>'; // echo our short code for the Public Board $output .= do_shortcode('[DASPublicBoard]'); $output .= '</div><!--das-project-admin-wrap-main-->'; } else { $output .= '<div class="das-project-admin-wrap-main">'; $output .= '<h2 class="project-board-header">' . __('Project Board', 'design-approval-system') . '</h2>'; // echo our short code for the Private Board $output .= do_shortcode('[DASPrivateBoard]'); $output .= '<br class="clear"/></div><!--das-project-admin-wrap-main-->'; } // end if admin or das user can echo $output; }
/** * Change redirect upon login to user's My Catalog page * * @param string $redirect_to * @param string $request_redirect_to * @param \WP_User $user * * @return string */ function login($redirect_to, $request_redirect_to, $user) { if (false === is_a($user, 'WP_User')) { // Unknown user, bail with default return $redirect_to; } if (is_super_admin($user->ID)) { // This is an admin, don't mess return $redirect_to; } $blogs = get_blogs_of_user($user->ID); if (array_key_exists(get_current_blog_id(), $blogs)) { // Yes, user has access to this blog return $redirect_to; } if ($user->primary_blog) { // Force redirect the user to their blog or, if they have more than one, to their catalog, bypass wp_safe_redirect() if (count($blogs) > 1) { $redirect = get_blogaddress_by_id($user->primary_blog) . 'wp-admin/index.php?page=pb_catalog'; } else { $redirect = get_blogaddress_by_id($user->primary_blog) . 'wp-admin/'; } location($redirect); } // User has no primary_blog? Make them sign-up for one return network_site_url('/wp-signup.php'); }
function custom_redirect_filter($redirect_to, $request, $user) { $user_blogs = get_blogs_of_user($user->ID); foreach ($user_blogs as $user_blog) { $user_blog->path; return site_url($user_blog->path); } return site_url(); }
function wp_ozh_adminmenu_blogswitch_init() { global $current_user, $current_blog; $blogs = get_blogs_of_user($current_user->ID); if (!$blogs) { return; } add_action('admin_menu', 'wp_ozh_adminmenu_blogswitch_ob_start'); add_action('dashmenu', 'blogswitch_markup'); }
/** * @ticket 38355 */ public function test_get_active_blog_for_user_without_primary_site() { $sites = get_blogs_of_user(self::$user_id); $site_ids = array_keys($sites); $primary_site_id = $site_ids[0]; delete_user_meta(self::$user_id, 'primary_blog'); $result = get_active_blog_for_user(self::$user_id); wpmu_delete_blog($primary_site_id, true); $this->assertEquals($primary_site_id, $result->id); }
public static function get_blog($user_id) { $blogs = get_blogs_of_user($user_id); // if the user is associated with more than one site, we should assume it's an internal administrator(with no API keys), rather than a site user if (count($blogs) != 1) { wp_die(__("This user is associated with more than 1 site. Can't create API keys for these users")); } $blog = array_values($blogs)[0]; return $blog; }
/** * The default view of the 'Compare' admin menu page. */ public function admin_page_step_1() { $user_id = get_current_user_id(); $user_sites = get_blogs_of_user($user_id); ?> <h1>Compare Site Plugins</h1> <form action="plugins.php?page=bpp-compare-site-plugins" method="post"> <label for="plugins">Paste the <strong>Plugin Code</strong> from another site running this plugin</label> <textarea name="plugins" id="plugins" rows="5" cols="70"></textarea> <?php if (is_multisite() && $user_sites) { global $blog_id; ?> <p class="or">Or</p> <label>Select a Site</label> <select name="site_id"> <option value=""></option> <?php foreach ($user_sites as $site) { if ($site->userblog_id != $blog_id) { ?> <option value="<?php echo intval($site->userblog_id); ?> "><?php echo $site->blogname; ?> </option> <?php } } ?> </select> <?php } ?> <?php wp_nonce_field($user_id, 'nonce'); ?> <input type="submit" class="button button-primary" value="Compare plugins"> <label>Copy the following <strong>Plugin Code</strong> to compare the plugins on this site to another site</label> <textarea onclick="this.select()" rows="2" cols="70"><?php echo base64_encode(serialize($this->sites_plugins)); ?> </textarea> </form> <?php }
/** * Render the primary-site metabox for user profile screen * * @since 0.1.0 * * @param WP_User $user The WP_User object to be edited. */ function wp_user_profiles_primary_site_metabox($user = null) { // Get sites $sites = (array) get_blogs_of_user($user->ID); $primary = (int) get_user_meta($user->ID, 'primary_blog', true); // If there is only 1 site, maybe do some clean-up if (count($sites) === 1) { $site = reset($sites); // Reset the primary site if it's out of sync if ($primary !== $site->userblog_id) { update_user_meta($user->ID, 'primary_blog', $site->userblog_id); } } ?> <table class="form-table"> <tr> <th scope="row"> <label for="primary_blog"> <?php _e('Primary Site', 'wp-user-profiles'); ?> </label> </th> <td><?php if (!empty($sites)) { // Sites ?> <select name="primary_blog" id="primary_blog"><?php foreach ($sites as $site) { ?> <option value="<?php echo esc_attr($site->userblog_id); ?> " <?php selected($primary, $site->userblog_id); ?> ><?php echo esc_url(get_home_url($site->userblog_id)); ?> </option><?php } ?> </select><?php // No sites } else { $user->ID === get_current_user_id() ? esc_html_e('You are not a member of any sites.', 'wp-user-profiles') : esc_html_e('This user is not a member of any sites.', 'wp-user-profiles'); } ?> </td> </tr> </table> <?php }
function ub_rdluws_remove_wpms_dashboard_link() { $user_blogs = get_blogs_of_user(get_current_user_id()); if (count($user_blogs) == 0) { remove_menu_page('index.php'); $current_url = ub_rdluws_get_admin_current_page_url(); if (preg_match("/user\\//", $current_url) && !preg_match("/profile.php/", $current_url)) { wp_redirect('profile.php'); } } }
function rl_show_password_fields_filter($show, $profileuser) { if (is_super_admin()) { return true; } elseif (IS_PROFILE_PAGE) { return true; } elseif (count(get_blogs_of_user($profileuser->ID)) > 1) { return true; } else { return false; } }
/** * Test that usermeta cache is cleared after user deletion. * * @ticket 19500 */ function test_get_blogs_of_user() { // Logged out users don't have blogs. $this->assertEquals(array(), get_blogs_of_user(0)); $user_id = self::factory()->user->create(array('role' => 'subscriber')); $blogs = get_blogs_of_user($user_id); $this->assertEquals(array(1), array_keys($blogs)); // Non-existent users don't have blogs. self::delete_user($user_id); $user = new WP_User($user_id); $this->assertFalse($user->exists(), 'WP_User->exists'); $this->assertEquals(array(), get_blogs_of_user($user_id)); }
function redirect_to_selected_admin() { check_admin_referer('multisite-switcher'); // Comme sécurité basique (et limite inutile), on vérifie que le blog sélectioné existe et est géré par l'utilisteur courant global $current_user; $blogs = get_blogs_of_user($current_user->id, true); foreach ($blogs as $blog) { if ($blog->siteurl . '/wp-admin/' == $_POST['multisiteswitcher']) { wp_redirect($_POST['multisiteswitcher']); exit; } } }
/** * Generates an array of site information that can be used for the +mentions autocomplete feature * * @return array Site Information. */ public function site_suggestions() { if (!empty($this->blog_suggestions[get_current_blog_id()])) { return $this->blog_suggestions[get_current_blog_id()]; } $this->blog_suggestions[get_current_blog_id()] = array(); // @todo convert to MS-compatible, using the subdomain OR the path, depending on the configuration of the site // @todo move blavatar stuff into wpcom.php filter $suggestions = array(); $user_blogs = get_blogs_of_user(get_current_user_id()); foreach ($user_blogs as $_blog_id => $details) { $blavatar = ''; if (function_exists('get_blavatar')) { $blavatar = get_blavatar($details->siteurl, 32, 'https://i2.wp.com/wordpress.com/wp-content/themes/h4/tabs/images/defaultavatar.png'); } $suggestions[$_blog_id] = array('blog_id' => $_blog_id, 'title' => $details->blogname, 'siteurl' => $details->siteurl, 'subdomain' => str_replace('.wordpress.com', '', $details->domain), 'blavatar' => $blavatar); } $combined_suggestions = apply_filters('o2_xposts_site_list', $suggestions); // Enforce rules for what can/cannot be listed $this_privacy = get_option('blog_public'); $this_id = get_current_blog_id(); foreach ($combined_suggestions as $_id => $blog) { // Never include the current blog in the list if ($_id == $this_id) { continue; } switch_to_blog($_id); // Must be able to post on the receiving blog if (!current_user_can('edit_posts')) { restore_current_blog(); continue; } // Receiving blog must have the same privacy settings as the source blog if (get_option('blog_public') !== $this_privacy) { restore_current_blog(); continue; } // Receiving blog must also be running o2 (to handle the xpost properly) // @todo Obviously this is WPCOM only if (!wpcom_o2_is_enabled() || !wpcom_theme_supports_o2()) { restore_current_blog(); continue; } restore_current_blog(); // This is OK to include in our suggestions list $this->blog_suggestions[get_current_blog_id()][$_id] = $blog; // Cache a list of subdomains, based on full blog list, for matching purposes $this->subdomains[get_current_blog_id()][] = $blog['subdomain']; } return $this->blog_suggestions[get_current_blog_id()]; }
/** * Assists in multisite User authentication. * * @package s2Member\Login_Checks * @since 131025 * * @attaches-to ``add_filter('wp_authenticate_user');`` * * @param WP_User|WP_Error Expects either a WP_User or WP_Error object passed in by the Filter. * * @return WP_User|WP_Error WP_User or WP_Error object (if there was a problem). */ public static function ms_wp_authenticate_user($user_or_wp_error) { if (!is_multisite()) { return $user_or_wp_error; } foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_ms_wp_authenticate_user', get_defined_vars()); unset($__refs, $__v); if (is_a($user_or_wp_error, 'WP_User') && ($user = $user_or_wp_error) && $user->ID && !is_super_admin($user->ID) && !in_array(get_current_blog_id(), array_keys(get_blogs_of_user($user->ID)), TRUE)) { $user_or_wp_error = new WP_Error('invalid_username', _x('<strong>ERROR</strong>: Invalid username for this site.', 's2member-front', 's2member')); } return apply_filters('ws_plugin__s2member_ms_wp_authenticate_user', $user_or_wp_error, get_defined_vars()); }
/** * Test that usermeta cache is cleared after user deletion. * * @ticket 19500 */ function test_get_blogs_of_user() { // Logged out users don't have blogs. $this->assertEquals(array(), get_blogs_of_user(0)); $user_id = $this->factory->user->create(array('role' => 'subscriber')); $blogs = get_blogs_of_user($user_id); $this->assertEquals(array(1), array_keys($blogs)); // Non-existent users don't have blogs. if (is_multisite()) { wpmu_delete_user($user_id); } else { wp_delete_user($user_id); } $user = new WP_User($user_id); $this->assertFalse($user->exists(), 'WP_User->exists'); $this->assertEquals(array(), get_blogs_of_user($user_id)); }
function __construct($user, $is_network_admin = false) { $this->code = md5(uniqid(mt_rand(), true)); $this->user_email = $user->user_email; $this->user_id = $user->ID; $this->created_at = time(); $sites = get_blogs_of_user($user->ID); if ($is_network_admin || count($sites) == 0) { $site = array_shift($sites); switch_to_blog($site->userblog_id); $this->site_name = get_bloginfo('name'); $this->login_url = wp_login_url(); restore_current_blog(); } else { $this->site_name = get_bloginfo('name'); $this->login_url = wp_login_url(); } }
function generateNerdGallery() { global $wp_query; if (isset($wp_query->query_vars[NN_BOSS_Q_VAR])) { $soughtBoss = $wp_query->query_vars[NN_BOSS_Q_VAR]; } $content = '<div id="nerd-gallery">'; /** * Add chris manually */ $content .= userphoto__get_userphoto(6, USERPHOTO_FULL_SIZE, "<div class='nerdpic' >", "<div class='nerd-caption'>Chris Balakrishnan<br/>Nerd Nite Founder</div></div>", "", ""); $wp_user_search = new WP_User_Query(array('role' => 'City_Boss')); $bosses = $wp_user_search->get_results(); foreach ($bosses as $boss) { $cities = get_blogs_of_user($boss->ID); $city = null; foreach ($cities as $cityObject) { if ($cityObject->userblog_id == 1) { continue; } else { $cityName = getCityName($cityObject); if (!isHiddenCity($cityObject)) { if (isset($city)) { $city = "{$city} & {$cityName}"; } else { $city = $cityName; } } } } $boss_name = isset($boss->display_name) ? $boss->display_name : $boss->user_login; $user_photo = userphoto__get_userphoto($boss->ID, USERPHOTO_FULL_SIZE, "<div class='nerdpic' >", "<div class='nerd-caption'>{$boss_name}<br/>Nerd Nite {$city} Boss</div></div>", "", ""); $content .= $user_photo; } /** * Add dan manually */ $content .= userphoto__get_userphoto(9, USERPHOTO_FULL_SIZE, "<div class='nerdpic' >", "<div class='nerd-caption'>Dan Rumney<br/> Webmaster and Podcaster</div></div>", "", ""); $content .= '</div>'; return $content; }
/** * Add role * @param int $user_id * @param array $roles * @param boolean $all_sites * @return void */ public function add_role($user_id, $roles = array(), $all_sites = FALSE) { // sanitize roles $roles = array_map(array($this, 'sanitize_role'), $roles); // make sure that the roles are editable if (!function_exists('get_editable_roles')) { require_once ABSPATH . '/wp-admin/includes/user.php'; } $roles = $this->get_editable_roles($roles); if (!empty($roles)) { // current blog id $current_blog_id = get_current_blog_id(); // get list of blogs user is member of $blogs = get_blogs_of_user($user_id); if ($all_sites === FALSE) { // remove current site from list unset($blogs[$current_blog_id]); } // loop through blogs foreach ($blogs as $blog) { // switch to blog switch_to_blog($blog->userblog_id); // get user info $site_user = get_user_by('id', $user_id); // remove roles if (!empty($site_user->roles)) { foreach ($site_user->roles as $role) { $site_user->remove_role($role); } } // loop through roles foreach ($roles as $role) { // add role $site_user->add_role($role); } } // switch back to orgininal blog switch_to_blog($current_blog_id); } }
/** * Render the sites metabox for user profile screen * * @since 1.0.0 * * @param WP_User $user The WP_User object to be edited. */ function wp_user_profiles_sites_metabox($user = null) { // Get sites for user $sites = get_blogs_of_user($user->ID, true); $screen = get_current_screen(); // Force screen to setup list table set_current_screen('network-sites'); $wp_list_table = _get_list_table('WP_MS_Sites_List_Table'); // Override sites query if (!empty($sites)) { $GLOBALS['wp_user_profiles_site_in'] = array_keys($sites); add_filter('ms_sites_list_table_query_args', 'wp_user_profiles_filter_sites_table_query_args'); // Get the list table & items $wp_list_table->prepare_items(); // Reset sites query remove_filter('ms_sites_list_table_query_args', 'wp_user_profiles_filter_sites_table_query_args'); unset($GLOBALS['wp_user_profiles_site_in']); } // Reset screen set_current_screen($screen->id); // No bulk actions $wp_list_table->_actions = false; // Start ob_start(); // Before do_action('wp_user_profiles_sites_metabox_before', $user); // Filter action links add_filter('manage_sites_action_links', 'wp_user_profiles_filter_sites_action_links'); add_filter('wpmu_blogs_columns', 'wp_user_profiles_filter_sites_columns'); // Output list table $wp_list_table->display(); // Unfilter action links remove_filter('manage_sites_action_links', 'wp_user_profiles_filter_sites_action_links'); remove_filter('wpmu_blogs_columns', 'wp_user_profiles_filter_sites_columns'); // After do_action('wp_user_profiles_sites_metabox_after', $user); // Output the buffer echo ob_get_clean(); }
function rt_wp_nginx_helper_install() { global $wp_roles, $rt_wp_nginx_helper; if (!current_user_can('activate_plugins')) { return; } $role = get_role('administrator'); if (empty($role)) { update_site_option("rt_wp_nginx_helper_init_check", __('Sorry, you need to be an administrator to use Nginx Helper', "rt_wp_nginx_helper")); return; } $role->add_cap('Nginx Helper | Config'); $role->add_cap('Nginx Helper | Purge cache'); $rt_wp_nginx_helper_get_options = get_site_option('rt_wp_nginx_helper_global_options'); if (empty($rt_wp_nginx_helper_get_options)) { $rt_wp_nginx_helper_get_options = rt_wp_nginx_helper_get_options(); update_site_option("rt_wp_nginx_helper_global_options", $rt_wp_nginx_helper_get_options); } if (is_multisite()) { $blogs = get_blogs_of_user(true); foreach ($blogs as $b) { $rt_wp_nginx_helper_options = get_blog_option($b->userblog_id, 'rt_wp_nginx_helper_options'); if (empty($rt_wp_nginx_helper_options)) { $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options(); update_blog_option($b->userblog_id, "rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options); } } } else { $rt_wp_nginx_helper_options = get_option('rt_wp_nginx_helper_options'); if (empty($rt_wp_nginx_helper_options)) { $rt_wp_nginx_helper_options = rt_wp_nginx_helper_get_options(); update_option("rt_wp_nginx_helper_options", $rt_wp_nginx_helper_options); } } wp_schedule_event(time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily'); }
/** * Get the URL to the user's dashboard. * * If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site, * the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's * primary blog is returned. * * @since 3.1.0 * * @param int $user_id Optional. User ID. Defaults to current user. * @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins. * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Dashboard url link with optional path appended. */ function get_dashboard_url($user_id = 0, $path = '', $scheme = 'admin') { $user_id = $user_id ? (int) $user_id : get_current_user_id(); $blogs = get_blogs_of_user($user_id); if (!is_super_admin() && empty($blogs)) { $url = user_admin_url($path, $scheme); } elseif (!is_multisite()) { $url = admin_url($path, $scheme); } else { $current_blog = get_current_blog_id(); if ($current_blog && (is_super_admin($user_id) || in_array($current_blog, array_keys($blogs)))) { $url = admin_url($path, $scheme); } else { $active = get_active_blog_for_user($user_id); if ($active) { $url = get_admin_url($active->blog_id, $path, $scheme); } else { $url = user_admin_url($path, $scheme); } } } /** * Filter the dashboard URL for a user. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param int $user_id The user ID. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ return apply_filters('user_dashboard_url', $url, $user_id, $path, $scheme); }
/** * Takes a user ID and cancels any subscriptions that user has on any site in a WordPress network * * @uses wp_parse_args To allow only part of a subscription's details to be updated, like status. * @param $user_id int The ID of the user for whom subscription details should be updated * @since 1.3.8 */ public static function cancel_users_subscriptions_for_network($user_id) { $sites = get_blogs_of_user($user_id); if (!empty($sites)) { foreach ($sites as $site) { switch_to_blog($site->userblog_id); self::cancel_users_subscriptions($user_id); restore_current_blog(); } } do_action('cancelled_users_subscriptions_for_network', $user_id); }
/** * My Sites dashboard. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ require_once dirname(__FILE__) . '/admin.php'; if (!is_multisite()) { wp_die(__('Multisite support is not enabled.')); } if (!current_user_can('read')) { wp_die(__('You do not have sufficient permissions to view this page.')); } $action = isset($_POST['action']) ? $_POST['action'] : 'splash'; $blogs = get_blogs_of_user($current_user->ID); $updated = false; if ('updateblogsettings' == $action && isset($_POST['primary_blog'])) { check_admin_referer('update-my-sites'); $blog = get_blog_details((int) $_POST['primary_blog']); if ($blog && isset($blog->domain)) { update_user_option($current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true); $updated = true; } else { wp_die(__('The primary site you chose does not exist.')); } } $title = __('My Sites'); $parent_file = 'index.php'; get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen shows an individual user all of their sites in this network, and also allows that user to set a primary site. He or she can use the links under each site to visit either the frontend or the dashboard for that site.') . '</p>' . '<p>' . __('Up until WordPress version 3.0, what is now called a Multisite Network had to be installed separately as WordPress MU (multi-user).') . '</p>')); get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Dashboard_My_Sites_Screen" target="_blank">Documentation on My Sites</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');