Redirect user role to a specific page on login in a multisite network?

Here’s the solution if anyone’s interested: add_filter(‘login_redirect’, function( $url, $query, $user ) { $user_info = get_userdata($user->ID); return get_blogaddress_by_id($user_info->primary_blog) . ‘wp-admin/?login=1’; }, 10, 3); add_action(‘current_screen’, function ( $user ) { $userID = get_current_user_id(); $user_info = get_userdata($userID); if ($_GET[‘login’] == 1 && $user_info->primary_blog) { $primary_url = get_blogaddress_by_id($user_info->primary_blog) . ‘wp-admin/edit.php?post_type=visitor’; $site_id = $user_info->primary_blog; if (!current_user_can_for_blog($site_id, ‘create_users’)) { wp_redirect( … Read more

How to make a “page-option” in WordPress

You can define a specific page template for the specific widget then you can select template page as on your navigation menu. <?php /* Template Name: page one */ get_header(); ?> <div class=”main-wrap “> <?php if (is_active_sidebar( “widgetName” )) { dynamic_sidebar( “widgetName” ); } ?> </div> <?php get_footer(); ?>

Create form which redirects to site in network?

You could perform a validation through get_blog_id_from_url($domain, $path) function, assuming you are using directories and NOT subdomains. Otherwise, $path is not required. See code and comments below. <?php if ( ! empty( $_POST[‘sitename’] ) ) { $main_site_url = network_site_url( “https://wordpress.stackexchange.com/” ); $domain = preg_replace( “/^https?:\/\/(www)?/”, ”, $main_site_url ); $path = preg_replace( “/\//”, ”, trim( $_POST[‘sitename’] … Read more

How to auto-generate random numbers in username?

This function would generate a unique user login slug: function my_unique_user_slug( $slug ) { global $wpdb; $check_sql = “SELECT user_login FROM $wpdb->users WHERE user_login = %s LIMIT 1”; if ( ! $wpdb->get_var( $wpdb->prepare( $check_sql, $slug ) ) ) { return $slug; } $suffix = 2; do { $alt_slug = $slug . $suffix; $user_slug_check = $wpdb->get_var( … Read more