Change WordPress prefix for only one table?

In wp-config.php for your second site, define the following two constants: define(‘CUSTOM_USER_TABLE’, ‘yourfirstprefix_users’); define(‘CUSTOM_USERMETA_TABLE’, ‘yourfirstprefix_usermeta’); You’ll have to add some custom logic to your second site limiting logins by user role.

Query users which have same dynamically generated roles as the current user

To achieve this, you first need to get all the current user roles, X and Y(s)… function get_current_user_roles(){ global $wp_roles; $current_user = wp_get_current_user(); $user_groups = groups_get_user_groups( $current_user->ID ); $user_roles = isset( $current_user->roles[‘X’] ) ? array( ‘X’ ) : array(); // Let’s get all Y dynamic user roles… foreach ( $user_groups[‘groups’] as $id ) { $group … Read more

Modify Database in Multi-Site wp_usermeta table

This Should Work? ALTER TABLE wp_usermeta ADD COLUMN old_user_id bigint(20) unsigned; INSERT INTO wp_usermeta (old_user_id) SELECT u.id FROM wp_users AS u; INSERT INTO wp_usermeta (user_id, meta_key, meta_value) SELECT u.id, ‘wp_2_capabilities’, meta_value JOIN wp_users AS u ON u.user_id = u.old_user_id; ALTER TABLE wp_users DROP COLUMN old_user_id;

create shortcode to list users with specific meta key value

Try this: function thebroker_agents() { global $current_user; $bmail = $current_user->user_email; $user_query = new WP_User_Query( array( ‘meta_key’ => ‘broker_email’, ‘meta_value’ => $bmail, ‘fields’ => ‘all’ ) ); $users = $user_query->get_results(); if (!empty($users)) { $results=”<ul>”; foreach ($users as $user){ $results=”<li>” . $user->display_name . ‘</li>’; } $results=”</ul>”; } else { $results=”No users found”; } wp_reset_postdata(); return $results; } … Read more

Make custom user table column filterable

This process is pretty straightforward. Add the following pieces of code to the current ( preferably child ) theme’s functions.php. Step 1 – add new column to the users table list: function wpse_add_user_table_list_column($column) { $column[‘call_sign’] = ‘Call Sign’; return $column; } add_filter(‘manage_users_columns’, ‘wpse_add_user_table_list_column’); Step 2 – make this new column sortable: function wpse_user_table_list_sortable_columns($columns) { $columns[‘call_sign’] … Read more

How would I hook into `clear_auth_cookie` to return the user’s ID that’s currently being logged out?

That action doesn’t pass that data: function return_user_data_on_logout( $user ) { Here, $user will alway be undefined. Additionally, you need to tell add_action how many parameters the function takes. But.. do_action( ‘clear_auth_cookie’ ); No information is passed to begin with, that’s not how this particular event/action works. So how do we get the current user … Read more