Example #1
0
function mpp_get_user_link($user_id, $no_anchor = false, $just_link = false)
{
    if (function_exists('bp_core_get_userlink')) {
        return bp_core_get_userlink($user_id, $no_anchor, $just_link);
    }
    $display_name = mpp_get_user_display_name($user_id);
    if (empty($display_name)) {
        return false;
    }
    if (!empty($no_anchor)) {
        return $display_name;
    }
    if (!($url = mpp_get_user_url($user_id))) {
        return false;
    }
    if (!empty($just_link)) {
        return $url;
    }
    return apply_filters('mpp_get_user_link', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id);
}
/**
 * Adds a new comment to the database.
 * A copy of wp_new_comment()
 * @see wp_new_comment()
 */
function mpp_add_comment($commentdata)
{
    //basic fields
    //set to default
    $user_id = get_current_user_id();
    if (empty($commentdata['comment_author'])) {
        $commentdata['comment_author'] = mpp_get_user_display_name($user_id);
    }
    if (empty($commentdata['comment_author_email'])) {
        $commentdata['comment_author_email'] = mpp_get_user_email($user_id);
    }
    if (empty($commentdata['comment_author_url'])) {
        $commentdata['comment_author_url'] = mpp_get_user_url($user_id);
    }
    /**
     * Filter a comment's data before it is sanitized and inserted into the database.
     *
     * @since 1.5.0
     *
     * @param array $commentdata Comment data.
     */
    $commentdata = apply_filters('preprocess_comment', $commentdata);
    $commentdata['comment_post_ID'] = (int) $commentdata['post_id'];
    //media Id or Gallery ID
    if (isset($commentdata['user_ID'])) {
        $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    } elseif (isset($commentdata['user_id'])) {
        $commentdata['user_id'] = (int) $commentdata['user_id'];
    }
    $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
    //$parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
    $commentdata['comment_parent'] = $commentdata['comment_parent'] > 0 ? $commentdata['comment_parent'] : 0;
    $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
    $commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '';
    $commentdata['comment_date'] = current_time('mysql');
    $commentdata['comment_date_gmt'] = current_time('mysql', 1);
    $commentdata = wp_filter_comment($commentdata);
    $commentdata['comment_approved'] = 1;
    //make approved by default wp_allow_comment($commentdata);
    $comment_ID = wp_insert_comment($commentdata);
    do_action('mpp_comment_added', $comment_ID, $commentdata['comment_approved']);
    return $comment_ID;
}