2024-09-24 13:18:48 +03:00
|
|
|
<?php
|
|
|
|
|
namespace um\frontend;
|
|
|
|
|
|
2025-09-05 12:08:19 +03:00
|
|
|
use WP_Comment;
|
|
|
|
|
|
2024-09-24 13:18:48 +03:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! class_exists( 'um\frontend\User_Profile' ) ) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class User_Profile
|
|
|
|
|
*
|
|
|
|
|
* @package um\frontend
|
|
|
|
|
*/
|
|
|
|
|
class User_Profile {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* User_Profile constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
|
|
|
|
add_action( 'template_redirect', array( $this, 'handle_edit_screen' ), 10000 );
|
2025-09-05 12:08:19 +03:00
|
|
|
add_filter( 'get_edit_user_link', array( $this, 'change_edit_user_link' ), 10, 2 );
|
|
|
|
|
add_filter( 'get_comment_author_url', array( $this, 'change_comment_author_url' ), 10, 3 );
|
2024-09-24 13:18:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check edit profile action and set edit mode or redirect if there aren't capabilities to edit.
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function handle_edit_screen() {
|
|
|
|
|
if ( ! is_user_logged_in() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 12:24:10 +03:00
|
|
|
// phpcs:disable WordPress.Security.NonceVerification
|
2024-09-24 13:18:48 +03:00
|
|
|
if ( ! isset( $_REQUEST['um_action'] ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$action = sanitize_key( $_REQUEST['um_action'] );
|
|
|
|
|
|
|
|
|
|
if ( 'edit' !== $action ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$uid = 0;
|
|
|
|
|
if ( isset( $_REQUEST['uid'] ) ) {
|
|
|
|
|
$uid = absint( $_REQUEST['uid'] );
|
|
|
|
|
}
|
2025-07-30 12:24:10 +03:00
|
|
|
// phpcs:enable WordPress.Security.NonceVerification
|
2024-09-24 13:18:48 +03:00
|
|
|
|
|
|
|
|
if ( ! empty( $uid ) && ! UM()->common()->users()::user_exists( $uid ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $uid ) && is_super_admin( $uid ) ) {
|
|
|
|
|
wp_die( esc_html__( 'Super administrators can not be modified.', 'ultimate-member' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UM()->fields()->editing = true;
|
|
|
|
|
|
|
|
|
|
if ( ! um_is_myprofile() && ! UM()->roles()->um_current_user_can( 'edit', um_profile_id() ) ) {
|
|
|
|
|
um_safe_redirect( UM()->permalinks()->get_current_url( true ) );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 19:45:48 +03:00
|
|
|
if ( um_is_myprofile() && ! um_can_edit_my_profile() ) {
|
2024-09-24 13:18:48 +03:00
|
|
|
um_safe_redirect( um_edit_my_profile_cancel_uri() );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-30 12:24:10 +03:00
|
|
|
|
2025-09-05 12:08:19 +03:00
|
|
|
/**
|
|
|
|
|
* Returns the user profile edit link using Ultimate Member plugin.
|
|
|
|
|
*
|
|
|
|
|
* @param string $link The default edit user link.
|
|
|
|
|
* @param int $user_id The ID of the user.
|
|
|
|
|
*
|
|
|
|
|
* @return string The customized user profile edit link.
|
|
|
|
|
*/
|
|
|
|
|
public function change_edit_user_link( $link, $user_id ) {
|
2025-07-30 12:24:10 +03:00
|
|
|
return um_edit_profile_url( $user_id );
|
|
|
|
|
}
|
2025-08-26 09:59:53 +03:00
|
|
|
|
2025-09-05 12:08:19 +03:00
|
|
|
/**
|
|
|
|
|
* Retrieves the user profile URL for the given comment author.
|
|
|
|
|
*
|
2025-10-03 13:59:40 +03:00
|
|
|
* @param string $comment_author_url The URL of the comment author.
|
|
|
|
|
* @param int $comment_id The ID of the comment.
|
|
|
|
|
* @param WP_Comment|null $comment The comment object.
|
2025-09-05 12:08:19 +03:00
|
|
|
*
|
|
|
|
|
* @return string The user profile URL for the comment author.
|
|
|
|
|
*/
|
|
|
|
|
public function change_comment_author_url( $comment_author_url, $comment_id, $comment ) {
|
2025-10-03 13:59:40 +03:00
|
|
|
if ( ! is_null( $comment ) ) {
|
|
|
|
|
return um_user_profile_url( $comment->user_id );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $comment_author_url;
|
2025-08-26 09:59:53 +03:00
|
|
|
}
|
2024-09-24 13:18:48 +03:00
|
|
|
}
|
|
|
|
|
}
|