/** * Get the base url for the component gallery home page * e.g http://site.com/members/user-name/gallery //without any trailing slash * * @param type $component * @return type * * @todo In future, avoid dependecy on BuddyPress * */ function mpp_get_gallery_base_url($component, $component_id) { $base_url = ''; if ($component == 'members') { $base_url = mpp_get_user_url($component_id) . MPP_GALLERY_SLUG; } elseif ($component == 'groups' && function_exists('bp_get_group_permalink')) { $base_url = bp_get_group_permalink(new BP_Groups_Group($component_id)) . MPP_GALLERY_SLUG; } //for admin new/edit gallery, specially new gallery if (!$base_url && (empty($component) || empty($component_id))) { $base_url = mpp_get_user_url(get_current_user_id()) . MPP_GALLERY_SLUG; } return apply_filters('mpp_get_gallery_base_url', untrailingslashit($base_url), $component, $component_id); }
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; }