Installer
3 years ago
AdminNotices.php
1 month ago
AjaxHandler.php
1 year ago
Autologin.php
9 months ago
BlockRegistrations.php
10 months ago
BuddyPressBbPress.php
3 years ago
DisableConcurrentLogins.php
2 years ago
EditUserProfile.php
5 months ago
ExtensionManager.php
1 month ago
FileUploader.php
3 months ago
FormPreviewHandler.php
5 months ago
FormRepository.php
1 year ago
FormShortcodeDefaults.php
1 month ago
GDPR.php
3 years ago
Geolocation.php
3 years ago
GlobalSiteAccess.php
3 years ago
ImageUploader.php
1 year ago
LoginAuth.php
1 year ago
Miscellaneous.php
3 years ago
ModifyRedirectDefaultLinks.php
5 months ago
PPRESS_Session.php
1 year ago
PROFILEPRESS_sql.php
1 year ago
PasswordReset.php
1 year ago
ProfileUrlRewrite.php
4 years ago
RegistrationAuth.php
1 week ago
SendEmail.php
3 years ago
ShortcodeThemeFactory.php
5 years ago
UserAvatar.php
1 year ago
UserSignupLocationListingPage.php
3 years ago
UsernameEmailRestrictLogin.php
4 years ago
WPProfileFieldParserTrait.php
1 year ago
WelcomeEmailAfterSignup.php
1 year ago
default-email-template.php
1 year ago
index.php
3 years ago
ProfileUrlRewrite.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Rewrite the profile page URL |
| 7 | * |
| 8 | * Rewrite the page URL to contain the "/profile" slug |
| 9 | */ |
| 10 | class ProfileUrlRewrite |
| 11 | { |
| 12 | /** @type object instance */ |
| 13 | private static $instance; |
| 14 | |
| 15 | public function __construct() |
| 16 | { |
| 17 | add_action('init', array($this, 'rewrite_function'), 10, 0); |
| 18 | } |
| 19 | |
| 20 | public function rewrite_function() |
| 21 | { |
| 22 | // set $page_id to the WordPress page with the profile shortcode |
| 23 | $page_id = apply_filters('ppress_profile_page_id', ppress_get_setting('set_user_profile_shortcode')); |
| 24 | |
| 25 | if ( ! empty($page_id)) { |
| 26 | |
| 27 | $profile_slug = ppress_get_profile_slug(); |
| 28 | |
| 29 | add_rewrite_tag('%who%', '([^&]+)'); |
| 30 | |
| 31 | $regex_1 = apply_filters('ppress_profile_rewrite_regex_1', "^{$profile_slug}/([^/]*)/?", $profile_slug); |
| 32 | $regex_2 = apply_filters('ppress_profile_rewrite_regex_2', "^{$profile_slug}/?$", $profile_slug); |
| 33 | |
| 34 | $query_1 = apply_filters('ppress_profile_rewrite_query_1', 'index.php?page_id=' . $page_id . '&who=$matches[1]', $page_id); |
| 35 | $query_2 = apply_filters('ppress_profile_rewrite_query_2', 'index.php?page_id=' . $page_id, $page_id); |
| 36 | |
| 37 | add_rewrite_rule($regex_1, $query_1, 'top'); |
| 38 | add_rewrite_rule($regex_2, $query_2, 'top'); |
| 39 | |
| 40 | do_action('ppress_after_rewrite_hook_added', $profile_slug, $page_id); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public static function get_instance() |
| 45 | { |
| 46 | if ( ! self::$instance) { |
| 47 | self::$instance = new self(); |
| 48 | } |
| 49 | |
| 50 | return self::$instance; |
| 51 | } |
| 52 | } |