Пример #1
0
 /**
  * Actions to run after posting a comment
  * @param  object|array $comment Comment object.
  */
 public function publish_comment($comment)
 {
     if (ap_is_profile_active()) {
         $comment = (object) $comment;
         $post = get_post($comment->comment_post_ID);
         if ($post->post_type == 'question') {
             ap_insert_notification($comment->user_id, $post->post_author, 'comment_on_question', array('post_id' => $post->ID, 'comment_id' => $comment->comment_ID));
         } elseif ($post->post_type == 'answer') {
             ap_insert_notification($comment->user_id, $post->post_author, 'comment_on_answer', array('post_id' => $post->ID, 'comment_id' => $comment->comment_ID));
         }
     }
 }
Пример #2
0
 /**
  * Register user page in AnsPress
  */
 public function user_page()
 {
     // Return if user profile is not active
     if (!ap_is_profile_active()) {
         return;
     }
     global $ap_user_query;
     if (ap_get_displayed_user_id() == 0 && !is_user_logged_in()) {
         ap_get_template_part('login-signup');
         return;
     }
     $ap_user_query = ap_has_users(array('ID' => ap_get_displayed_user_id()));
     if ($ap_user_query->has_users()) {
         include ap_get_theme_location('user/user.php');
     } else {
         _e('No user found', 'anspress-question-answer');
     }
 }
Пример #3
0
 /**
  * Add user dropdown and notification menu
  * @param  string  $o        		   Menu html.
  * @param  object  $item               Menu item object.
  * @param  integer $depth              Menu depth.
  * @param  object  $args 			   Menu args.
  * @return string
  */
 public function walker_nav_menu_start_el($o, $item, $depth, $args)
 {
     if (!is_user_logged_in() && (ap_is_notification_menu($item) || ap_is_profile_menu($item))) {
         $o = '';
     }
     if (!ap_is_profile_active() && (ap_is_notification_menu($item) || ap_is_profile_menu($item))) {
         return '';
     }
     if (in_array('anspress-page-profile', $item->classes) && is_user_logged_in()) {
         $menus = ap_get_user_menu(get_current_user_id());
         $active_user_page = get_query_var('user_page') ? esc_attr(get_query_var('user_page')) : 'about';
         $o = '<a id="ap-user-menu-anchor" class="ap-dropdown-toggle" href="#">';
         $o .= get_avatar(get_current_user_id(), 80);
         $o .= '<span class="name">' . ap_user_display_name(get_current_user_id()) . '</span>';
         $o .= ap_icon('chevron-down', true);
         $o .= '</a>';
         $o .= '<ul id="ap-user-menu-link" class="ap-dropdown-menu ap-user-dropdown-menu">';
         foreach ($menus as $m) {
             $class = !empty($m['class']) ? ' ' . $m['class'] : '';
             $o .= '<li' . ($active_user_page == $m['slug'] ? ' class="active"' : '') . '>';
             $o .= '<a href="' . $m['link'] . '" class="ap-user-link-' . $m['slug'] . $class . '">';
             $o .= $m['title'] . '</a>';
             $o .= '</li>';
         }
         $o .= '</ul>';
     } elseif (in_array('anspress-page-notification', $item->classes) && is_user_logged_in()) {
         $o = '<a id="ap-user-notification-anchor" class="ap-dropdown-toggle ap-sidetoggle ' . ap_icon('globe') . '" href="#">' . ap_get_the_total_unread_notification(false, false) . '</a>';
         global $ap_activities;
         $ap_activities = ap_get_activities(array('per_page' => 20, 'notification' => true, 'user_id' => ap_get_displayed_user_id()));
         ob_start();
         ap_get_template_part('user/notification-dropdown');
         $o .= ob_get_clean();
     }
     return $o;
 }
Пример #4
0
/**
 * Check if user can edit their profile
 */
function ap_user_can_edit_profile()
{
    // Return false if profile is not active.
    if (!ap_is_profile_active()) {
        return false;
    }
    if (is_super_admin() || current_user_can('ap_edit_profile')) {
        return true;
    }
    return false;
}
Пример #5
0
/**
 * Return Link to user pages
 * @param  boolean|integer $user_id    user id
 * @param  string          $sub        page slug
 * @return string
 * @since  unknown
 */
function ap_user_link($user_id = false, $sub = false)
{
    if (false === $user_id) {
        $user_id = get_the_author_meta('ID');
    }
    if ($user_id < 1) {
        return '#AnonymousUser';
    }
    if (function_exists('bp_core_get_userlink') && !ap_is_profile_active()) {
        return bp_core_get_userlink($user_id, false, true);
    } elseif (!ap_is_profile_active()) {
        return apply_filters('ap_user_custom_profile_link', $user_id, $sub);
    }
    if (0 == $user_id) {
        return false;
    }
    $user = get_user_by('id', $user_id);
    if (get_option('permalink_structure') != '') {
        if (!ap_opt('base_before_user_perma')) {
            $base = home_url('/' . ap_get_user_page_slug() . '/');
        } else {
            $base = ap_get_link_to(ap_get_user_page_slug());
        }
        if ($sub === false) {
            $link = $base . $user->user_login . '/';
        } elseif (is_array($sub)) {
            $link = $base . $user->user_login . '/';
            if (!empty($sub)) {
                foreach ($sub as $s) {
                    $link .= $s . '/';
                }
            }
        } elseif (!is_array($sub)) {
            $link = $base . $user->user_login . '/' . $sub . '/';
        }
    } else {
        if ($sub === false) {
            $sub = array('ap_page' => 'user', 'ap_user' => $user->user_login);
        } elseif (is_array($sub)) {
            $sub['ap_page'] = 'user';
            $sub['ap_user'] = $user->user_login;
        } elseif (!is_array($sub)) {
            $sub = array('ap_page' => 'user', 'ap_user' => $user->user_login, 'user_page' => $sub);
        }
        $link = ap_get_link_to($sub);
    }
    return apply_filters('ap_user_link', $link, $user_id);
}