Advertisement
Guest User

Groups 404 Redirect to page/post with original url

a guest
Mar 31st, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.51 KB | None | 0 0
  1. Index: wp-content/plugins/groups-404-redirect/groups-404-redirect.php
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- wp-content/plugins/groups-404-redirect/groups-404-redirect.php  (date 1459415116000)
  7. +++ wp-content/plugins/groups-404-redirect/groups-404-redirect.php  (revision )
  8. @@ -129,6 +129,12 @@
  9.                 Groups_Options::delete_option( 'groups-404-redirect-post-id' );
  10.             }
  11.  
  12. +           if ( !empty( $_POST['post_param'] ) ) {
  13. +               Groups_Options::update_option( 'groups-404-redirect-post-param', $_POST['post_param'] );
  14. +           } else {
  15. +               Groups_Options::delete_option( 'groups-404-redirect-post-param' );
  16. +           }
  17. +
  18.             Groups_Options::update_option( 'groups-404-redirect-restricted-terms', !empty( $_POST['redirect_restricted_terms'] ) );
  19.  
  20.             if ( key_exists( $_POST['status'], $http_status_codes ) ) {
  21. @@ -143,6 +149,7 @@
  22.  
  23.         $redirect_to     = Groups_Options::get_option( 'groups-404-redirect-to', 'post' );
  24.         $post_id         = Groups_Options::get_option( 'groups-404-redirect-post-id', '' );
  25. +       $post_param      = Groups_Options::get_option( 'groups-404-redirect-post-param', '' );
  26.         $redirect_status = Groups_Options::get_option( 'groups-404-redirect-status', '301' );
  27.         $redirect_restricted_terms = Groups_Options::get_option( 'groups-404-redirect-restricted-terms', false );
  28.  
  29. @@ -188,6 +195,16 @@
  30.         echo __( 'If the <strong>Redirect to the WordPress login</strong> option is chosen instead, visitors who are logged in but may not access a requested page, can be redirected to a specific page by setting the Page or Post ID here.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN );
  31.         echo '</p>';
  32.  
  33. +       echo '<label>';
  34. +       echo __( 'Parameter name', GROUPS_404_REDIRECT_PLUGIN_DOMAIN );
  35. +       echo ' ';
  36. +       echo sprintf( '<input type="text" name="post_param" value="%s" />', $post_param );
  37. +       echo '</label>';
  38. +
  39. +       echo '<p class="description">';
  40. +       echo __( 'Indicate the parameter name which gets the original url requested when redirecting to given page or post.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN );
  41. +       echo '</p>';
  42. +
  43.         echo '</div>';
  44.  
  45.         echo '<br/>';
  46. @@ -281,6 +298,7 @@
  47.             if ( self::groups_is_active() ) {
  48.                 $redirect_to     = Groups_Options::get_option( 'groups-404-redirect-to', 'post' );
  49.                 $post_id         = Groups_Options::get_option( 'groups-404-redirect-post-id', '' );
  50. +               $post_param      = Groups_Options::get_option( 'groups-404-redirect-post-param', '' );
  51.                 $redirect_status = intval( Groups_Options::get_option( 'groups-404-redirect-status', '301' ) );
  52.  
  53.                 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  54. @@ -328,15 +346,19 @@
  55.  
  56.                             default: // 'post'
  57.                                 if ( empty( $post_id ) ) {
  58. -                                   wp_redirect( get_home_url(), $redirect_status );
  59. +                                   $redirect_url = get_home_url();
  60.                                 } else {
  61.                                     $post_id = apply_filters( 'groups_404_redirect_post_id', $post_id, $current_post_id, $current_url );
  62.                                     if ( $post_id != $current_post_id ) {
  63. -                                       wp_redirect( get_permalink( $post_id ), $redirect_status );
  64. +                                       $redirect_url = get_permalink( $post_id );
  65.                                     } else {
  66.                                         return;
  67.                                     }
  68.                                 }
  69. +                               if ( !empty( $post_param ) ) {
  70. +                                   $redirect_url .= (parse_url($redirect_url, PHP_URL_QUERY) ? '&' : '?') . $post_param . '=' . rawurlencode($current_url);
  71. +                               }
  72. +                               wp_redirect( $redirect_url, $redirect_status );
  73.                                 exit;
  74.  
  75.                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement