Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter jelux

    (@jelux)

    I’m trying to redirect subscribers to specific private pages, one for each user. However, WordPress doesn’t allow subscribers to be accessed by administrators and editors only. If I assign author privileges, can I prevent users from accessing the backend?

    Thread Starter jelux

    (@jelux)

    ok I solved it using this code

    funzione abilita_pagine_private_sottoscrittori() {
    $subRole = get_role( ‘abbonato’ );

    // Controlla se il ruolo esiste e aggiungi le capacità
    if ( $subRole ) {
        $subRole->add_cap( 'read_private_pages' );
        $subRole->add_cap( 'read_private_posts' );
    }

    }
    add_action( ‘init’, ‘abilita_pagine_private_sottoscrittori’ );

    Thread Starter jelux

    (@jelux)

    for now to solve this I’m using a second plugin for the redirect, I’m just trying to simplify

    Plugin Support Shubhanshu Kandani

    (@shubhanshukandani)

    Hi @jelux 👋

    Thanks for sharing the details and for explaining what you’ve tried so far.

    You’re right by default, private pages are only accessible to admins/editors, which is why your redirect wasn’t working earlier. The solution you found by granting read_private_pages and read_private_posts to subscribers is the correct approach 👍

    Regarding simplifying things and handling redirects with our plugin:

    Currently, there isn’t a built-in option to list private pages directly in the redirect dropdown. However, you can control the redirect behavior using a small snippet via the tlwp_login_redirect filter.

    You can add the following code to your active child theme’s functions.php file or use the Code Snippets plugin:

    <?php
    add_filter('tlwp_login_redirect', 'custom_tlwp_login_redirect', 10, 2);

    function custom_tlwp_login_redirect($url, $temporary_user) {
    // Redirect to a specific private page
    return home_url('/private-page-url/');
    }

    Note:
    Make sure the user role you’re redirecting (e.g. Subscriber) has permission to view private pages otherwise, it will block access of the redirect.

    Thread Starter jelux

    (@jelux)

    Many thanks for your reply. What I need is a personalized link for each user. I don’t know if this is the same thing.

    A private page for each user I register.

    Plugin Contributor Sandhya M

    (@sandhyam)

    Hi @jelux,

    You need to decide when and how the private page for the user should be created.

    Once the page is created, save its link in a user_meta key. Then, retrieve that value inside the above function.

    This will give you the redirect URL, which you can use to perform the redirect.

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.