AdminNotices.php
5 years ago
AjaxHandler.php
5 years ago
Autologin.php
5 years ago
BuddyPressBbPress.php
5 years ago
EditUserProfile.php
5 years ago
ExtensionManager.php
5 years ago
FileUploader.php
5 years ago
FormPreviewHandler.php
5 years ago
FormRepository.php
5 years ago
FormShortcodeDefaults.php
5 years ago
GDPR.php
5 years ago
GlobalSiteAccess.php
5 years ago
ImageUploader.php
5 years ago
LoginAuth.php
5 years ago
Miscellaneous.php
5 years ago
ModifyRedirectDefaultLinks.php
5 years ago
PPRESS_Session.php
5 years ago
PROFILEPRESS_sql.php
5 years ago
PasswordReset.php
5 years ago
ProfileUrlRewrite.php
5 years ago
RegistrationAuth.php
5 years ago
SendEmail.php
5 years ago
ShortcodeThemeFactory.php
5 years ago
UserAvatar.php
5 years ago
UserSignupLocationListingPage.php
5 years ago
UsernameEmailRestrictLogin.php
5 years ago
WelcomeEmailAfterSignup.php
5 years ago
default-email-template.php
5 years ago
index.php
5 years ago
ProfileUrlRewrite.php
49 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 | $profile_slug = ppress_get_profile_slug(); |
| 26 | |
| 27 | add_rewrite_tag('%who%', '([^&]+)'); |
| 28 | |
| 29 | $regex_1 = apply_filters('ppress_profile_rewrite_regex_1', "^{$profile_slug}/([^/]*)/?", $profile_slug); |
| 30 | $regex_2 = apply_filters('ppress_profile_rewrite_regex_2', "^{$profile_slug}/?$", $profile_slug); |
| 31 | |
| 32 | $query_1 = apply_filters('ppress_profile_rewrite_query_1', 'index.php?page_id=' . $page_id . '&who=$matches[1]', $page_id); |
| 33 | $query_2 = apply_filters('ppress_profile_rewrite_query_2', 'index.php?page_id=' . $page_id, $page_id); |
| 34 | |
| 35 | add_rewrite_rule($regex_1, $query_1, 'top'); |
| 36 | add_rewrite_rule($regex_2, $query_2, 'top'); |
| 37 | |
| 38 | do_action('ppress_after_rewrite_hook_added', $profile_slug, $page_id); |
| 39 | } |
| 40 | |
| 41 | public static function get_instance() |
| 42 | { |
| 43 | if ( ! self::$instance) { |
| 44 | self::$instance = new self(); |
| 45 | } |
| 46 | |
| 47 | return self::$instance; |
| 48 | } |
| 49 | } |