*/
class UsersWP_Profile {
/**
* Prints the profile page header section.
*
* @since 1.0.0
* @package userswp
* @param object $user The User ID.
*/
public function get_profile_header($user) {
$banner = uwp_get_usermeta($user->ID, 'uwp_account_banner_thumb', '');
$avatar = uwp_get_usermeta($user->ID, 'uwp_account_avatar_thumb', '');
add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
$uploads = wp_upload_dir();
remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
$upload_url = $uploads['baseurl'];
if (is_user_logged_in() && get_current_user_id() == $user->ID && is_uwp_profile_page()) {
$trigger_class = "uwp-profile-modal-form-trigger";
} else {
$trigger_class = "";
}
if (empty($banner)) {
$banner = uwp_get_option('profile_default_banner', '');
if(empty($banner)){
$banner = USERSWP_PLUGIN_URL."/public/assets/images/banner.png";
} else {
$banner = wp_get_attachment_url($banner);
}
} else {
$banner = $upload_url.$banner;
}
if (empty($avatar)) {
$avatar = get_avatar($user->user_email, 150);
} else {
// check the image is not a full url before adding the local upload url
if (strpos($avatar, 'http:') === false && strpos($avatar, 'https:') === false) {
$avatar = $upload_url.$avatar;
}
$avatar = '
';
}
?>
get_profile_tabs($user) as $tab_id => $tab ) {
$tab_url = uwp_build_profile_tab_url($user->ID, $tab_id, false);
$active = $active_tab == $tab_id ? ' active' : '';
?>
-
ID);
?>
ID) && $can_user_edit_account) { ?>
get_profile_extra($user);
echo $extra;
}
/**
* Prints the profile page "posts" tab content.
*
* @since 1.0.0
* @package userswp
* @param object $user The User ID.
* @return void
*/
public function get_profile_posts($user) {
$allowed_tabs = uwp_get_option('enable_profile_tabs', array());
if (!is_array($allowed_tabs)) {
$allowed_tabs = array();
}
if (!in_array('posts', $allowed_tabs)) {
return;
}
uwp_generic_tab_content($user, 'post', __('Posts', 'userswp'));
}
/**
* Prints the profile page "comments" tab content.
*
* @since 1.0.0
* @package userswp
* @param object $user The User ID.
* @return void
*/
public function get_profile_comments($user) {
$allowed_tabs = uwp_get_option('enable_profile_tabs', array());
if (!is_array($allowed_tabs)) {
$allowed_tabs = array();
}
if (!in_array('comments', $allowed_tabs)) {
return;
}
?>
ID);
$maximum_pages = ceil($total_comments / $number);
$args = array(
'number' => $number,
'offset' => $offset,
'author_email' => $user->user_email,
'paged' => $paged,
'post_type' => 'post',
);
// The Query
$the_query = new WP_Comment_Query();
$comments = $the_query->query( $args );
// The Loop
if ($comments) {
echo '
flush_rules( false );
delete_option('uwp_flush_rewrite');
}
}
}
/**
* Adds profile page query variables.
*
* @since 1.0.0
* @package userswp
* @param array $query_vars Query variables.
* @return array Modified Query variables array.
*/
public function profile_query_vars($query_vars) {
$query_vars[] = 'uwp_profile';
$query_vars[] = 'uwp_tab';
$query_vars[] = 'uwp_subtab';
return $query_vars;
}
/**
* Returns user profile link based on user id.
*
* @since 1.0.0
* @package userswp
* @param string $link Unmodified link.
* @param int $user_id User id.
* @return string Modified link.
*/
public function get_profile_link($link, $user_id) {
$page_id = uwp_get_page_id('profile_page', false);
if ($page_id) {
$link = get_permalink($page_id);
} else {
$link = '';
}
if ($link != '') {
if (isset($_REQUEST['page_id'])) {
$permalink_structure = 'DEFAULT';
} else {
$permalink_structure = 'CUSTOM';
// Add forward slash if not available
$link = rtrim($link, '/') . '/';
}
$url_type = apply_filters('uwp_profile_url_type', 'slug');
if ($url_type && 'id' == $url_type) {
if ('DEFAULT' == $permalink_structure) {
return add_query_arg(array('viewuser' => $user_id), $link);
} else {
return $link . $user_id;
}
} else {
$user = get_userdata($user_id);
if ( !empty($user->user_nicename) ) {
$username = $user->user_nicename;
} else {
$username = $user->user_login;
}
if ('DEFAULT' == $permalink_structure) {
return add_query_arg(array('username' => $username), $link);
} else {
return $link . $username;
}
}
} else {
return '';
}
}
/**
* Modifies profile page title to include username.
*
* @since 1.0.0
* @package userswp
* @param string $title Original title
* @param int|null $id Page id.
* @return string Modified page title.
*/
public function modify_profile_page_title( $title, $id = null ) {
global $wp_query;
$page_id = uwp_get_page_id('profile_page', false);
if ($page_id == $id && isset($wp_query->query_vars['uwp_profile']) && in_the_loop()) {
$url_type = apply_filters('uwp_profile_url_type', 'slug');
$author_slug = $wp_query->query_vars['uwp_profile'];
if ($url_type == 'id') {
$user = get_user_by('id', $author_slug);
} else {
$user = get_user_by('slug', $author_slug);
}
$title = $user->display_name;
}
return $title;
}
/**
* Returns json content for image crop.
*
* @since 1.0.0
* @package userswp
* @param string $image_url Image url
* @param string $type popup type. Avatar or Banner
* @return string Json
*/
public function uwp_image_crop_popup($image_url, $type) {
add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
$uploads = wp_upload_dir();
remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
$upload_url = $uploads['baseurl'];
$upload_path = $uploads['basedir'];
$image_path = str_replace($upload_url, $upload_path, $image_url);
$image = apply_filters( 'uwp_'.$type.'_cropper_image', getimagesize( $image_path ) );
if ( empty( $image ) ) {
return "";
}
// Get avatar full width and height.
if ($type == 'avatar') {
$full_width = apply_filters('uwp_avatar_image_width', 150);
$full_height = apply_filters('uwp_avatar_image_height', 150);
} else {
$full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
$full_height = apply_filters('uwp_banner_image_height', 300);
}
$values = array(
'error' => '',
'image_url' => $image_url,
'uwp_popup_type' => $type,
'uwp_full_width' => $full_width,
'uwp_full_height' => $full_height,
'uwp_true_width' => $image[0],
'uwp_true_height' => $image[1],
'uwp_popup_content' => $this->uwp_image_crop_modal_html($type, $image_url, $full_width, $full_height),
);
$json = json_encode($values);
return $json;
}
/**
* Initializes image crop js.
*
* @since 1.0.0
* @package userswp
* @param object $user The User ID.
*/
public function uwp_image_crop_init($user) {
if (is_user_logged_in()) {
add_action( 'wp_footer', array($this,'uwp_modal_loading_html'));
add_action( 'wp_footer', array($this,'uwp_modal_close_js'));
if(is_admin()) {
add_action('admin_footer', array($this, 'uwp_modal_loading_html'));
add_action('admin_footer', array($this, 'uwp_modal_close_js'));
}
}
}
/**
* Returns modal content loading html.
*
* @since 1.0.0
* @package userswp
* @return string Modal loding html.
*/
public function uwp_modal_loading_html() {
ob_start();
?>