Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the rewrite rule to work for subfolder WordPress installs #168

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pmpro-member-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,32 +405,30 @@ function pmpromd_filter_profile_fields_for_levels( $profile_fields, $pu ) {
add_filter( 'pmpro_member_profile_fields', 'pmpromd_filter_profile_fields_for_levels', 10, 2 );

/**
* We determine that the URL base is for the profile and then set up the rewrite rule
* Determine what the URL base is for the profile and then set up the rewrite rule.
*/
function pmpromd_custom_rewrite_rules() {

global $pmpro_pages;

if ( empty( $pmpro_pages ) || empty( $pmpro_pages['profile'] ) ) {
return;
}

$profile_permalink = get_the_permalink( $pmpro_pages['profile'] );

$base_site_url = get_site_url();
// Get the profile permalink.
$profile_permalink = get_permalink( $pmpro_pages['profile'] );

$profile_base = str_replace( $base_site_url . '/', '', $profile_permalink );
// Parse the path from the permalink, taking subfolder installations into account.
$profile_base = trim( parse_url( $profile_permalink, PHP_URL_PATH ), '/' );

// Add the rewrite rule.
add_rewrite_rule(
$profile_base.'([^/]+)/?$',
'^' . preg_quote( $profile_base, '#' ) . '/([^/]+)/?$',
'index.php?pagename=' . $profile_base . '&pu=$matches[1]',
'top'
);

}
add_action( 'init', 'pmpromd_custom_rewrite_rules', 10 );


/**
* Adding in the ?pu parameter so that we can retrieve the value from the pretty permalink
*/
Expand Down