Support » Plugin: Groups 404 Redirect » Change Redirect Per Page?

  • Resolved freedomkyle12

    (@freedomkyle12)


    Hello! I’d like to change where the person is redirected based on the page they’re being denied access to.

    For example:

    Person A is in group 1. Group 1 is given access to the “group 1 page”.

    Person B is in group 2. When they go to the “group 1 page” they are redirected to the “join group 1 page”.

    Person C is not in any groups (or not logged in). When they go to the “group 1 page” they are redirected to the “join group 1 page”, and when they go to the “group 2 page” they are redirected to the “join group 2 page”.

    Is there any way to make this happen?

    It’ll probably take some custom code which is fine as long as I have a place to start. Unless you’ve got a pro version of this plugin that offers this feature?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    The plugin has a filter which you can use

    $post_id = apply_filters( 'groups_404_redirect_post_id', $post_id, $current_post_id, $current_url );

    To use it, you can do like in this example:

    add_filter( 'groups_404_redirect_post_id', 'my_groups_404_redirect_post_id', 10, 3 );
    function my_groups_404_redirect_post_id( $post_id, $current_post_id, $current_url ) {
      switch( $current_post_id ) {
        case 123 :
          $post_id = 321;
          break;
        case 456 :
          $post_id = 654;
          break;
      }
      return $post_id;
    }

    I hope this helps and sorry for the delayed reply.

    Cheers

    • This reply was modified 4 years, 3 months ago by Kento. Reason: corrected the example code to be based on the current post ID
    • This reply was modified 4 years, 3 months ago by Kento.

    FYI I’ve just added some more filters to version 1.4.0 which can help to take a more fine-grained decision on where and how to redirect to:

    $redirect_to = apply_filters( 'groups_404_redirect_redirect_to', $redirect_to, $current_post_id, $current_url );
    $post_param  = apply_filters( 'groups_404_redirect_post_param', $post_param, $current_post_id, $current_url );
    $redirect_status = apply_filters( 'groups_404_redirect_redirect_status', $redirect_status, $current_post_id, $current_url );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change Redirect Per Page?’ is closed to new replies.