Search Results for 'hide admin in directory'
-
AuthorSearch Results
-
September 8, 2014 at 2:51 pm #190941
In reply to: Activity Favorite Notification
aghajoonParticipantthis code work for me but java script not work and when user favorite comment user can’t remove notification help me
define("BP_FAVORITE_NOTIFIER_SLUG","fa_notification"); function bp_favorite_setup_globals() { global $bp, $current_blog; $bp->bp_favorite=new stdClass(); $bp->bp_favorite->id = 'bp_favorite'; $bp->bp_favorite->slug = BP_FAVORITE_NOTIFIER_SLUG; $bp->bp_favorite->notification_callback = 'bp_favorite_format_notifications';//show the notification $bp->active_components[$bp->bp_favorite->id] = $bp->bp_favorite->id; do_action( 'bp_favorite_setup_globals' ); } add_action( 'bp_setup_globals', 'bp_favorite_setup_globals' ); function bp_favorite_format_notifications( $action, $activity_id, $secondary_item_id, $total_items,$format='string' ) { $action_checker = explode('_', $action); $activities = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'display_comments' => true) ); $glue = ''; $user_names = array(); $users = find_favorite_involved_persons($activity_id, $action); $total_user = $count = count($users); if($count > 2) { $users = array_slice($users, $count - 2); $count = $count - 2; $glue = ", "; } else if($total_user == 2) { $glue = " and "; } foreach((array)$users as $user_id) { $user_names[] = bp_core_get_user_displayname($user_id); } if(!empty($user_names)) { $favoriting_users = join($glue, $user_names); } switch ( $action ) { case 'new_bp_favorite_'.$activity_id: if($total_user > 2) { $text = $favoriting_users.' and '.$count.' liked: '.substr($activities["activities"][0]->content,0,32).'...'; } else { $text = $favoriting_users." like: ".substr($activities["activities"][0]->content,0,32)."..."; } break; } $url = '<div id="'.$action.'"class="notification"><a href="#" class="social-delete" onclick="deleteAjaxNotification(\''.$action.'\',\''.$activity_id.'\', \''.admin_url( 'admin-ajax.php' ).'\'); return false;">x</a><span class="social-loader"></span></div>'; $link = favorite_activity_get_permalink( $activity_id ); if($format=='string') { return apply_filters( 'bp_activity_multiple_favorite_notifications', '<a href="' . $link. '">' . $text . '</a>'. $url .'' ,$users, $total_user, $count, $glue, $link ); } else { return array( 'link' => $link, 'text' => $text ); } return false; } function find_favorite_involved_persons($activity_id, $action) { global $bp,$wpdb; $table = $wpdb->prefix . 'bp_notifications'; return $wpdb->get_col($wpdb->prepare("select DISTINCT(secondary_item_id) from {$table} where item_id=%d and secondary_item_id!=%d and component_action = %s",$activity_id,$bp->loggedin_user->id, $action)); } function favorite_activity_get_permalink( $activity_id, $activity_obj = false ) { global $bp; if ( !$activity_obj ) $activity_obj = new BP_Activity_Activity( $activity_id ); if ( 'activity_comment' == $activity_obj->type ) $link = bp_get_activity_directory_permalink(). 'p/' . $activity_obj->item_id . '/'; else $link = bp_get_activity_directory_permalink() . 'p/' . $activity_obj->id . '/'; return apply_filters( 'ac_notifier_activity_get_permalink', $link ); } function favorite_notifier_remove_notification($activity ,$has_access){ global $bp; if($has_access) bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->bp_favorite->id, 'new_bp_favorite_'.$activity->id ); } add_action("bp_activity_screen_single_activity_permalink","favorite_notifier_remove_notification", 10,2); function favorite_notification( $activity_id){ global $bp; $activities = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'display_comments' => true) ); $author_id = $activities['activities'][0]->user_id; $user_id = bp_loggedin_user_id(); // if favoriting own activity, dont send notification if( $user_id == $author_id ) { return false; } if ( bp_is_active( 'notifications' ) ) { bp_notifications_add_notification( array( 'user_id' => $author_id, 'item_id' => $activity_id, 'secondary_item_id' => $user_id, 'component_name' => $bp->bp_favorite->id, 'component_action' => 'new_bp_favorite_'.$activity_id, 'date_notified' => bp_core_current_time(), 'is_new' => 1, ) ); } } add_action("bp_activity_add_user_favorite","favorite_notification", 10, 2); function deleteAjaxNotification(){ global $bp; bp_core_delete_notifications_by_item_id ($bp->loggedin_user->id, $bp->bp_favorite->id, 'new_bp_favorite_'.$activity->id); die(); } add_action('wp_ajax_deleteAjaxNotification', 'deleteAjaxNotification' ); function bp_like_add_like_action() { global $bp, $activities_template; if ( bp_activity_can_favorite() ) : $my_fav_count = bp_activity_get_meta( bp_get_activity_comment_id(), 'favorite_count' ); $my_fav_count = "<span>".$my_fav_count."</span>"; $is_favorite = apply_filters( 'bp_get_activity_is_favorite', in_array( bp_get_activity_comment_id(), $activities_template->my_favs ) ); if ( !$is_favorite ) : ?> <a href="<?php echo apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . bp_get_activity_comment_id() . '/' ), 'mark_favorite' ) ); ?>" class="tooltip-trigger fav bp-secondary-action bp-primary-action" title="<?php _e( 'Favorite', 'buddypress' ); ?>" style="position:relative;"><?php _e( 'Favorite', 'buddypress' ); ?><?php echo $my_fav_count; ?></a> <?php else : ?> <a href="<?php echo apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . bp_get_activity_comment_id() . '/' ), 'mark_favorite' ) ); ?>" class="tooltip-trigger unfav bp-secondary-action bp-primary-action" title="<?php _e( 'Remove Favorite', 'buddypress' ); ?>" style="position:relative;"><?php _e( 'Remove Favorite', 'buddypress' ); ?><?php echo $my_fav_count; ?></a> <?php endif; endif; } add_filter( 'bp_activity_comment_options' , 'bp_like_add_like_action', 1000 );
and java code
function deleteAjaxNotification(action_id, activity_id, adminUrl){ jQuery('#'+action_id).children(".social-delete").html(""); jQuery('#'+action_id ).children(".social-loader").show(); jQuery.ajax({ type: 'post', url: adminUrl, data: { action: "deleteAjaxNotification", action_id:action_id, activity_id:activity_id }, success: function(data) { jQuery('#'+action_id).parent().hide(); } }); }
September 7, 2014 at 7:43 pm #190874In reply to: Hide Admin from Members and Activity
danbpModeratorhi @canadadre,
you have to read the mentionnedd topic AND to follow the links if the topic contains some. ๐
i hope for you that you know how to copy/paste, because the above snippets must be added to your child-theme functions.php, or better into bp-custom.php
1. – Deny access to admins profile
// deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 );
2. – Remove admin from the member directory and recount members
// Remove admin from the member directory function bpdev_exclude_users($qs=false,$object=false){ $excluded_user='1'; // Id's to remove, separated by comma if($object != 'members' && $object != 'friends')// hide admin to members & friends return $qs; $args=wp_parse_args($qs); if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude'] = $args['exclude'].','.$excluded_user; else $args['exclude'] = $excluded_user; $qs = build_query($args); return $qs; } add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); // once admin is removed, we must recount the members ! function bpfr_hide_get_total_filter($count){ return $count-1; } add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
3. – Hide admin’s activities from all activity feeds
// hide admin's activities from all activity feeds function bpfr_hide_admin_activity( $a, $activities ) { // ... but allow admin to see his activities! if ( is_site_admin() ) return $activities; foreach ( $activities->activities as $key => $activity ) { // ID's to exclude, separated by commas. ID 1 is always the superadmin if ( $activity->user_id == 1 ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } // Renumber the array keys to account for missing items $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
May this help !
August 26, 2014 at 11:44 am #188500In reply to: [Resolved] Nobody visibility
danbpModeratoroh crossposting ! haven’t seen henry’s answer.
nobody visibility doesn’t exist. This setting is called “only me“. This means that only the member can see this field – and the site admins. Such fields are not for site admins, but for the members !
I don’t really understand what is not working for you, as what you’re looking for doesn’t exist in BuddyPress. Sorry if i’m misunderstanding you.
When you create such a field visibility, you should also set “Enforce the default visibility for all members“, so the member cannot modify it later on his profile settings.
Little weird side effect, when a “only me” field is used and member A wrote hello, this word becames clickabke, by default. When member B write also hello, it becames also clickable. And if A or B clcik on Hello, it shows a list of all members who wrote the same word. In this case A and B !
Not really confidential, isn’t it ? The solution is to remove the clickable link.
Here’s a snippet which let you do that selectively.function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { // Access the field you are going to display value. global $field; // In this array you write the ids of the fields you want to hide the link. $excluded_field_ids = array(2,9,54); // field ID separated by comma // If the id of this $field is in the array, we return the value only and not the link. if (in_array($field->id, $excluded_field_ids)) return $field_value; if ( 'datebox' == $field_type ) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); // If the value is a URL, skip it and just make it clickable. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { $new_values[] = make_clickable( $value ); // Is not clickable } else { // More than 5 spaces if ( count( explode( ' ', $value ) ) > 5 ) { $new_values[] = $value; // Less than 5 spaces } else { $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); $new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>'; } } } $values = implode( ', ', $new_values ); } return $values; } /** * We remove the buddypress filter and add our custom filter. */ function remove_xprofile_links() { // Remove the old filter. remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); // Add your custom filter. add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2); } add_action('bp_setup_globals', 'remove_xprofile_links');
June 20, 2014 at 6:46 am #184252In reply to: Hide admin activity in BP 2.x
nirgaloParticipantHi, I wanted to also hide admin from the “last activity” widget. I did an override of bp-core/bp-core-widget.php in my theme but it was not taken into account. However if I directly modify bp-core-widget.php in the BP plugin directory, then in works. Too bad the override doesn’t work, I guess I need to create my own widget…
January 18, 2014 at 10:43 pm #177164Topic: How to fix profile links, widgets,
in forum How-to & TroubleshootingshallowjeffParticipantHi,
I need help. I’ve managed to get rid of the auto linking default function within the profile section of my members page, but am unable to place anything that has java and/or button qualities. I have a place for “profile widgets” but instead of the actual widget, I get an H-ref ugly link. http://www.poetsatwork.comFor example:
I paste this,<SCRIPT charset=โutf-8โณ type=โtext/javascriptโ src=โhttp://ws-na.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Flovecourses-20%2F8010%2F5a411cc7-5346-4d91-86c2-9808086e235e&Operation=GetScriptTemplateโ> </SCRIPT> <NOSCRIPT>Amazon.com Widgets</NOSCRIPT>
On the page it shows this,
<a-HREF=โhttp://ws-na.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Flovecourses-20%2F8010%2F5a411cc7-5346-4d91-86c2-9808086e235e&Operation=NoScript=โ Amazon.com Widgets
This is the same for all link type images/widgets I place within BP. The stuff I put on the sidebars within wordpress works fine.
Why? I’m sure it’s a filter/function, but not sure where/what to change.
Here is my code:buddypress-xprofile-custom-fields-type/bp-xprofile-custom-fields-type.php
THE CODE I USED TO GET RID OF AUTO LINKING IS ON THE VERY BOTTOM, THANKS http://www.poetsatwork.com/* Plugin Name: Buddypress Xprofile Custom Fields Type Plugin URI: https://github.com/donmik/buddypress-xprofile-custom-fields-type/ Description: Buddypress installation required!! Add more custom fields type to extended profiles in buddypress: Birthdate, Email, Web, Datepicker. If you need more fields type, you are free to add them yourself or request us at miguel@donmik.com. Version: 1.5.8.4 Author: donmik Author URI: http://donmik.com */ //load text domain function bxcft_load_textdomain() { $locale = apply_filters( 'bxcft_load_load_textdomain_get_locale', get_locale() ); // if load .mo file if ( !empty( $locale ) ) { $mofile_default = sprintf( '%slang/%s.mo', plugin_dir_path(__FILE__), $locale ); $mofile = apply_filters( 'bxcft_load_textdomain_mofile', $mofile_default ); if ( file_exists( $mofile ) ) load_textdomain( โbxcftโ, $mofile ); } } add_action ( 'bp_init', 'bxcft_load_textdomain', 2 ); function bxcft_add_new_xprofile_field_type($field_types){ $new_field_types = array('birthdate', 'email', 'web', 'datepicker', 'select_custom_post_type', 'multiselect_custom_post_type', 'checkbox_acceptance', 'image', 'file', 'color', 'number'); $field_types = array_merge($field_types, $new_field_types); return $field_types; } add_filter( 'xprofile_field_types', 'bxcft_add_new_xprofile_field_type' ); function bxcft_admin_render_new_xprofile_field_type($field, $echo = true) { $html = โ; switch ( $field->type ) { case 'number': $html .= '<input type=โnumberโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinput-numberโ />'; break; case 'color': $html .= '<input type=โcolorโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinput-colorโ />'; break; case 'image': case 'file': $html .= '<input type=โfileโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinput-fileโ /> '; break; case 'checkbox_acceptance': $html .= '<input type=โcheckboxโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinput-checkboxโ value=โโ /> '; $html .= $field->description; $field->description = โ; break; case 'select_custom_post_type': $childs = $field->get_children(); if (isset($childs) && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; // Get the posts of custom post type. $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' )); } $select_custom_post_type = BP_XProfile_ProfileData::get_value_byid( $field->id ); $html .= '<select name=โfield_'.$field->id.'โ id=โfield_'.$field->id.'โ>'; if (isset($loop)) { foreach ($loop->posts as $post) { $html .= '<option value=โ'.$post->ID.'โ>'.$post->post_title.'</option>'; } } $html .= '</select>'; break; case โmultiselect_custom_post_typeโ: $childs = $field->get_children(); if (isset($childs) && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; // Get the posts of custom post type. $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' )); } $select_custom_post_type = BP_XProfile_ProfileData::get_value_byid( $field->id ); $html .= '<select name=โfield_'.$field->id.'โ id=โfield_'.$field->id.'โ multiple=โmultipleโ>'; if (isset($loop)) { foreach ($loop->posts as $post) { $html .= '<option value=โ'.$post->ID.'โ>'.$post->post_title.'</option>'; } } $html .= '</select>'; break; case โdatepickerโ: $html .= '<input type=โdateโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinputโ value=โโ />'; break; case โwebโ: $html .= '<input type=โurlโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinputโ placeholder=โ'.__('yourwebsite.com', 'bxcft').'โ value=โโ />'; break; case โemailโ: $html .= '<input type=โemailโ name=โfield_'.$field->id.'โ id=โ'.$field->id.'โ class=โinputโ placeholder=โ'.__('example@mail.com', 'bxcft').'โ value=โโ />'; break; case โbirthdateโ: $date = BP_XProfile_ProfileData::get_value_byid( $field->id ); // Set day, month, year defaults $day = โ; $month = โ; $year = โ; if ( !empty( $date ) ) { // If Unix timestamp if ( is_numeric( $date ) ) { $day = date( 'j', $date ); $month = date( 'F', $date ); $year = date( 'Y', $date ); // If MySQL timestamp } else { $day = mysql2date( 'j', $date ); $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below $year = mysql2date( 'Y', $date ); } } // Check for updated posted values, and errors preventing // them from being saved first time. if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) { if ( $day != $_POST['field_' . $field->id . '_day'] ) { $day = $_POST['field_' . $field->id . '_day']; } } if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) { if ( $month != $_POST['field_' . $field->id . '_month'] ) { $month = $_POST['field_' . $field->id . '_month']; } } if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) { if ( $year != date( โjโ, $_POST['field_' . $field->id . '_year'] ) ) { $year = $_POST['field_' . $field->id . '_year']; } } // Day. $html .= '<select name=โfield_'.$field->id.'_dayโ id=โfield_'.$field->id.'_dayโ>'; $html .= '<option value=โโ' . selected( $day, โ, false ) . '>โ</option>'; for ( $i = 1; $i < 32; ++$i ) { $html .= '<option value=โ' . $i .'โ' . selected( $day, $i, false ) . '>' . $i . '</option>'; } $html .= '</select>'; // Month. $html .= '<select name=โfield_'.$field->id.'_monthโ id=โfield_'.$field->id.'_monthโ>'; $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); $months = array( __( 'January', 'buddypress' ), __( 'February', 'buddypress' ), __( 'March', 'buddypress' ), __( 'April', 'buddypress' ), __( 'May', 'buddypress' ), __( 'June', 'buddypress' ), __( 'July', 'buddypress' ), __( 'August', 'buddypress' ), __( 'September', 'buddypress' ), __( 'October', 'buddypress' ), __( 'November', 'buddypress' ), __( 'December', 'buddypress' ) ); $html .= '<option value=โโ' . selected( $month, โ, false ) . '>โโ</option>'; for ( $i = 0; $i < 12; ++$i ) { $html .= '<option value=โ' . $eng_months[$i] . 'โ' . selected( $month, $eng_months[$i], false ) . '>' . $months[$i] . '</option>'; } $html .= '</select>'; // Year. $html .= '<select name=โfield_'.$field->id.'_yearโ id=โfield_'.$field->id.'_yearโ>'; $html .= '<option value=โโ' . selected( $year, โ, false ) . '>โ-</option>'; for ( $i = date('Y')-1; $i > 1901; $iโ ) { $html .= '<option value=โ' . $i .'โ' . selected( $year, $i, false ) . '>' . $i . '</option>'; } $html .= '</select>'; break; default: // Field type unrecognized. // $html = โ<p>โ.__('Field type unrecognized', 'bxcft').โ</p>โ; break; } if ($echo){ echo $html; return; } else { return $html; } } add_filter( 'xprofile_admin_field', 'bxcft_admin_render_new_xprofile_field_type' ); function bxcft_edit_render_new_xprofile_field($echo = true) { global $field; if (!is_bool($echo)) { $echo = true; } $uploads = wp_upload_dir(); ob_start(); if ( bp_get_the_profile_field_type() == 'birthdate' ) { $date = BP_XProfile_ProfileData::get_value_byid( $field->id ); // Set day, month, year defaults $day = โ; $month = โ; $year = โ; if ( !empty( $date ) ) { // If Unix timestamp if ( is_numeric( $date ) ) { $day = date( 'j', $date ); $month = date( 'F', $date ); $year = date( 'Y', $date ); // If MySQL timestamp } else { $day = mysql2date( 'j', $date ); $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below $year = mysql2date( 'Y', $date ); } } // Check for updated posted values, and errors preventing // them from being saved first time. if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) { if ( $day != $_POST['field_' . $field->id . '_day'] ) { $day = $_POST['field_' . $field->id . '_day']; } } if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) { if ( $month != $_POST['field_' . $field->id . '_month'] ) { $month = $_POST['field_' . $field->id . '_month']; } } if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) { if ( $year != date( โjโ, $_POST['field_' . $field->id . '_year'] ) ) { $year = $_POST['field_' . $field->id . '_year']; } } ?> <div class=โdateboxโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%s_dayโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); // Dropdown => Day of month. $options_day = โ; for ($i=1; $i<32; ++$i) { $options_day .= sprintf('<option value=โ%sโ%s>%s</option>', $i, selected($day, $i, false), $i); } $input = sprintf('<select name=โ%s_dayโ id=โ%s_dayโ%s><option value=โโ%s>โ</option>%s</select>', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?'aria-required=โtrueโ':โ, selected($day, โ, false), $options_day); // Dropdown => Month. $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); $months = array( __( 'January', 'buddypress' ), __( 'February', 'buddypress' ), __( 'March', 'buddypress' ), __( 'April', 'buddypress' ), __( 'May', 'buddypress' ), __( 'June', 'buddypress' ), __( 'July', 'buddypress' ), __( 'August', 'buddypress' ), __( 'September', 'buddypress' ), __( 'October', 'buddypress' ), __( 'November', 'buddypress' ), __( 'December', 'buddypress' ) ); $options_month = โ; for ($i=0; $i<12; ++$i) { $options_month .= sprintf('<option value=โ%sโ%s>%s</option>', $eng_months[$i], selected( $month, $eng_months[$i], false ), $months[$i]); } $input .= sprintf('<select name=โ%s_monthโ id=โ%s_monthโ%s><option value=โโ%s>โโ</option>%s</select>', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?'aria-required=โtrueโ':โ, selected($month, โ, false), $options_month); // Dropdown => Year. $birthdate_start_year = date('Y')-1; $options_year = โ; for ($i=$birthdate_start_year; $i>1901; $iโ) { $options_year .= sprintf('<option value=โ%sโ%s>%s</option>', $i, selected($year, $i, false), $i); } $input .= sprintf('<select name=โ%s_yearโ id=โ%s_yearโ%s><option value=โโ%s>โ-</option>%s</select>', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?'aria-required=โtrueโ required=โrequiredโ':โ, selected($year, โ, false), $options_year); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <?php } elseif ( bp_get_the_profile_field_type() == 'email' ) { ?> <div class=โinput-emailโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โemailโ name=โ%sโ id=โ%sโ%s class=โinputโ value=โ%sโ placeholder=โ%sโ />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, bp_get_the_profile_field_edit_value(), __('example@mail.com', 'bxcft')); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <?php } elseif ( bp_get_the_profile_field_type() == 'web' ) { ?> <div class=โinput-webโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โurlโ name=โ%sโ id=โ%sโ%s class=โinputโ value=โ%sโ placeholder=โ%sโ />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, bp_get_the_profile_field_edit_value(), __('http://yourwebsite.com', 'bxcft')); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <?php } elseif ( bp_get_the_profile_field_type() == 'datepicker' ) { ?> <div class=โinput-datepickerโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โdateโ name=โ%sโ id=โ%sโ%s class=โinputโ value=โ%sโ />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, bp_get_the_profile_field_edit_value()); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <?php } elseif ( bp_get_the_profile_field_type() == 'select_custom_post_type' ) { ?> <div class=โinput-custom-post-typeโ> <?php $custom_post_type_selected = BP_XProfile_ProfileData::get_value_byid( $field->id ); if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != โ ) { if ( !empty( $_POST['field_' . $field->id] ) ) { $custom_post_type_selected = $_POST['field_' . $field->id]; } } if (is_null($custom_post_type_selected)) { $custom_post_type_selected = array(); } // Get field's data. $field_data = new BP_XProfile_Field($field->id); // Get the childs of field $childs = $field_data->get_children(); if (isset($childs) && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; // Get the posts of custom post type. $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' )); $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $options_posts = โ; foreach ($loop->posts as $post) { $options_posts .= sprintf('<option value=โ%sโ%s>%s</option>', $post->ID, ($custom_post_type_selected==$post->ID)?' selected=โselectedโ':โ, $post->post_title); } $input = sprintf('<select name=โ%sโ id=โ%sโ%s class=โselectโ><option value=โโ>%s</option>%s</select>', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, __('Selectโฆ', 'bxcft'), $options_posts); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); } else { _e('There is no custom post type selected.', 'bxcft'); } ?> </div> <?php } elseif ( bp_get_the_profile_field_type() == 'multiselect_custom_post_type' ) { ?> <div class=โinput-custom-post-type-multiโ> <?php $custom_post_type_selected = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid( $field->id )); if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != โ ) { if ( !empty( $_POST['field_' . $field->id] ) ) { $custom_post_type_selected = $_POST['field_' . $field->id]; } } // Get field's data. $field_data = new BP_XProfile_Field($field->id); // Get the childs of field $childs = $field_data->get_children(); if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; // Get the posts of custom post type. $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' )); $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $options_posts = โ; foreach ($loop->posts as $post) { $options_posts .= sprintf('<option value=โ%sโ%s>%s</option>', $post->ID, (!empty($custom_post_type_selected) &&in_array($post->ID, $custom_post_type_selected))?' selected=โselectedโ':โ, $post->post_title); } $input = sprintf('<select name=โ%s[]โ id=โ%sโ%s class=โselectโ multiple=โmultipleโ><option value=โโ>%s</option>%s</select>', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, __('Selectโฆ', 'bxcft'), $options_posts); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); } else { _e('There is no custom post type selected.', 'bxcft'); } ?> </div> <?php } elseif (bp_get_the_profile_field_type() == 'checkbox_acceptance') { ?> <div class=โcheckbox-acceptanceโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โcheckboxโ name=โ%sโ id=โ%sโ%s class=โcheckboxโ value=โ1โณ%s />%s', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, bp_get_the_profile_field_edit_value()?' checked=โcheckedโ':โ, bp_get_the_profile_field_description()); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); $field_description = โ; ?> </div> <?php } elseif (bp_get_the_profile_field_type() == 'image') { ?> <div class=โinput-imageโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); if (bp_get_the_profile_field_edit_value() != โ) { $actual_image = sprintf('%s<label for=โ%s_deleteimgโ><input type=โcheckboxโ name=โ%s_deleteimgโ id=โ%s_deleteimgโ value=โ1โณ />%s</label><input type=โhiddenโ name=โ%s_hiddenimgโ id=โ%s_hiddenimgโ value=โ%sโ />', $uploads['baseurl'].bp_get_the_profile_field_edit_value(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), __('Check this to delete this image', 'bxcft'), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); } else { $actual_image = โ; } $input = sprintf('<input type=โfileโ name=โ%sโ id=โ%sโ%s />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); echo apply_filters('bxcft_field_actual_image', $actual_image, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); ?> <script type=โtext/javascriptโ> jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data'); </script> </div> <?php } elseif (bp_get_the_profile_field_type() == 'file') { ?> <div class=โinput-fileโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); if (bp_get_the_profile_field_edit_value() != โ) { $actual_file = sprintf('%s<label for=โ%s_deletefileโ><input type=โcheckboxโ name=โ%s_deletefileโ id=โ%s_deletefileโ value=โ1โณ />%s</label><input type=โhiddenโ name=โ%s_hiddenfileโ id=โ%s_hiddenfileโ value=โ%sโ />', apply_filters('bxcft_show_download_file_link', '' . __('Download file', 'bxcft') . '', bp_get_the_profile_field_type(), bp_get_the_profile_field_id(), bp_get_the_profile_field_edit_value()), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), __('Check this to delete this file', 'bxcft'), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); } else { $actual_file = โ; } $input = sprintf('<input type=โfileโ name=โ%sโ id=โ%sโ%s />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); echo apply_filters('bxcft_field_actual_file', $actual_file, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); ?> <script type=โtext/javascriptโ> jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data'); </script> </div> <?php } elseif (bp_get_the_profile_field_type() == 'color') { $color_selected = bp_get_the_profile_field_edit_value(); if (strpos($color_selected, '#') === false) { $color_selected = '#'.$color_selected; } ?> <div class=โinput-colorโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โcolorโ name=โ%sโ id=โ%sโ%s class=โinputโ value=โ%sโ />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, $color_selected); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <script> if (!Modernizr.inputtypes.color) { // No html5 field colorpicker => Calling jscolor. jQuery('input#<?php bp_the_profile_field_input_name() ?>').addClass('color'); } </script> <?php } elseif (bp_get_the_profile_field_type() == 'number') { ?> <div class=โinput-numberโ> <?php $label = sprintf('<label class=โlabel-form%sโ for=โ%sโ>%s%s</label>', bp_get_the_profile_field_is_required()?' required':โ, bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):โ); $input = sprintf('<input type=โnumberโ name=โ%sโ id=โ%sโ%s class=โinputโ value=โ%sโ />', bp_get_the_profile_field_input_name(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()?' aria-required=โtrueโ required=โrequiredโ':โ, bp_get_the_profile_field_edit_value()); echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ); echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required()); ?> </div> <?php } $output = ob_get_contents(); ob_end_clean(); if ($echo) { echo $output; return; } return $output; } /* * Buddypress v1.7 has better hook bp_custom_profile_edit_fields_pre_visibility which shows fields before visibility settings. * In case buddypress previous version is installed, we use the other tag bp_custom_profile_edit_fields. */ $version_bp = 0; $data = get_file_data(WP_PLUGIN_DIR . '/buddypress/bp-loader.php', array('Version')); if (isset($data) && count($data) > 0 && $data[0] != โ) $version_bp = (float)$data[0]; if ($version_bp >= 1.7) add_action( 'bp_custom_profile_edit_fields_pre_visibility', 'bxcft_edit_render_new_xprofile_field' ); else add_action( 'bp_custom_profile_edit_fields', 'bxcft_edit_render_new_xprofile_field' ); function bxcft_get_field_value( $value=โ, $type=โ, $id=โ) { $value_to_return = $value; if ($value_to_return == โ) return apply_filters('bxcft_show_field_value', $value_to_return, $type, $id, $value); $uploads = wp_upload_dir(); if ($type == 'birthdate') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $field = new BP_XProfile_Field($id); // Get children. $childs = $field->get_children(); $show_age = false; if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. if ($childs[0]->name == 'show_age') $show_age = true; } if ($value != โ) { if ($show_age) { $value_to_return = '<p>'.floor((time() โ strtotime($value))/31556926).'</p>'; } else { $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>'; } } } elseif ($type == 'datepicker') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>'; } elseif ($type == 'email') { if (strpos($value, 'mailto') === false) { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.$value.'</p>'; } } elseif ($type == 'web') { if (strpos($value, 'href=') === false) { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.$value.'</p>'; } } elseif ($type == 'select_custom_post_type') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); // Get field's data. $field = new BP_XProfile_Field($id); // Get children. $childs = $field->get_children(); if (isset($childs) && count($childs) > 0) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; } $post = get_post($value); if ($post->post_type == $custom_post_type) { $value_to_return = '<p>'.$post->post_title.'</p>'; } else { // Custom post type is not the same. $value_to_return = '<p>โ</p>'; } } elseif ($type == 'multiselect_custom_post_type') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); // Get field's data. $field = new BP_XProfile_Field($id); // Get children. $childs = $field->get_children(); if (isset($childs) && count($childs) > 0 && is_object($childs[0])) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; } else { $custom_post_type = โ; } $values = explode(โ,โ, $value); $cad = โ; foreach ($values as $v) { $post = get_post($v); if ($post->post_type == $custom_post_type) { if ($cad == โ) $cad .= '<ul class=โlist_custom_post_typeโ>'; $cad .= ' '.$post->post_title.' '; } } if ($cad != โ) { $cad .= ''; $value_to_return = '<p>'.$cad.'</p>'; } else { $value_to_return = '<p>โ</p>'; } } elseif ($type == 'checkbox_acceptance') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.(($value==1)?__('yes', 'bxcft'):__('no', 'bxcft')).'</p>'; } elseif ($type == 'image') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p></p>'; } elseif ($type == 'file') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.__('Download file', 'bxcft').'</p>'; } elseif ($type == 'color') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); if (strpos($value, '#') === false) { $value = '#'.$value; } $value_to_return = '<p>'.$value.'</p>'; } // Number nothing to do. return apply_filters('bxcft_show_field_value', $value_to_return, $type, $id, $value); } add_filter( 'bp_get_the_profile_field_value', 'bxcft_get_field_value', 15, 3); /** * Filter for those who use xprofile_get_field_data instead of get_field_value. * @param type $value * @param type $field_id * @param type $user_id * @return string */ function bxcft_get_field_data($value, $field_id) { $value_to_return = $value; $field = new BP_XProfile_Field($field_id); if ($value_to_return == โ) return apply_filters('bxcft_show_field_value', $value_to_return, $field->type, $field_id, $value); $uploads = wp_upload_dir(); if ($field->type == 'birthdate') { // Get children. $childs = $field->get_children(); $show_age = false; if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) { if ($childs[0]->name == 'show_age') $show_age = true; } if ($value != โ) { if ($show_age) { $value_to_return = '<p>'.floor((time() โ strtotime($value))/31556926).'</p>'; } else { $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>'; } } } elseif ($field->type == 'datepicker') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>'; } elseif ($field->type == 'email') { if (strpos($value, 'mailto') === false) { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.$value.'</p>'; } } elseif ($field->type == 'web') { if (strpos($value, 'href=') === false) { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.$value.'</p>'; } } elseif ($field->type == 'select_custom_post_type') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); // Get children. $childs = $field->get_children(); if (isset($childs) && count($childs) > 0) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; } $post = get_post($value); if ($post->post_type == $custom_post_type) { $value_to_return = '<p>'.$post->post_title.'</p>'; } else { // Custom post type is not the same. $value_to_return = '<p>โ</p>'; } } elseif ($field->type == 'multiselect_custom_post_type') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); // Get children. $childs = $field->get_children(); $values = explode(โ,โ, $value); $cad = โ; if (isset($childs) && is_array($childs) && count($childs) > 0) { // Get the name of custom post type. $custom_post_type = $childs[0]->name; foreach ($values as $v) { $post = get_post($v); if ($post->post_type == $custom_post_type) { if ($cad == โ) $cad .= '<ul class=โlist_custom_post_typeโ>'; $cad .= ' '.$post->post_title.' '; } } } if ($cad != โ) { $cad .= ''; $value_to_return = '<p>'.$cad.'</p>'; } else { $value_to_return = '<p>โ</p>'; } } elseif ($field->type == 'checkbox_acceptance') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.(($value==1)?__('yes', 'bxcft'):__('no', 'bxcft')).'</p>'; } elseif ($field->type == 'image') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p></p>'; } elseif ($field->type == 'file') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); $value_to_return = '<p>'.__('Download file', 'bxcft').'</p>'; } elseif ($field->type == 'color') { $value = str_replace(โ<p>โ, โโ, $value); $value = str_replace(โ</p>โ, โโ, $value); if (strpos($value, '#') === false) { $value = '#'.$value; } $value_to_return = '<p>'.$value.'</p>'; } // Number nothing to do. return apply_filters('bxcft_show_field_value', $value_to_return, $field->type, $field_id, $value); } add_filter( 'xprofile_get_field_data', 'bxcft_get_field_data', 15, 2); /** * Function replacing the original buddypress filter. * @param type $field_value * @param type $field_type * @return string */ function bxcft_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { if ( 'datebox' == $field_type || 'email' == $field_type || 'birthdate' == $field_type || 'datepicker' == $field_type || 'web' == $field_type || 'select_custom_post_type' == $field_type || 'multiselect_custom_post_type' == $field_type || 'image' == $field_type || 'file' == $field_type || 'color' == $field_type || 'number' == $field_type) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); // If the value is a URL, skip it and just make it clickable. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { $new_values[] = make_clickable( $value ); // Is not clickable } else { // More than 5 spaces if ( count( explode( ' ', $value ) ) > 5 ) { $new_values[] = $value; // Less than 5 spaces } else { $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); $new_values[] = '' . $value . ''; } } } $values = implode( ', ', $new_values ); } return $values; } /** * Adding js for admin. * @param type $hook * @return type */ function bxcft_add_js($hook) { if ('users_page_bp-profile-setup' != $hook && 'buddypress_page_bp-profile-setup' != $hook) return; wp_enqueue_script( 'bxcft-js', plugins_url('assets/js/addfields.js', __FILE__), array( 'jquery' ), '1.5.7โฒ ); $params = array( 'birthdate' => __('Birthdate', 'bxcft'), 'email' => __('Email', 'bxcft'), 'web' => __('Website', 'bxcft'), 'datepicker' => __('Datepicker', 'bxcft'), 'select_custom_post_type' => __('Custom Post Type Selector', 'bxcft'), 'multiselect_custom_post_type' => __('Custom Post Type Multiselector', 'bxcft'), 'checkbox_acceptance' => __('Checkbox acceptance', 'bxcft'), 'image' => __('Image', 'bxcft'), 'file' => __('File', 'bxcft'), 'color' => __('Color', 'bxcft'), 'number' => __('Number', 'bxcft') ); wp_localize_script('bxcft-js', 'params', $params); } add_action( 'admin_enqueue_scripts', 'bxcft_add_js'); /** * Adding js for edit form. */ function bxcft_add_js_public() { // Modernizr to test html5 fields. wp_enqueue_script( 'bxcft-modernizr', plugins_url('assets/js/modernizr.js', __FILE__), array( 'jquery' ), '2.6.2โฒ ); // Plugin jscolor fallback colorpicker. wp_enqueue_script( 'bxcft-jscolor', plugins_url('assets/js/jscolor/jscolor.js', __FILE__), array( 'bxcft-modernizr' ), '1.4.1โฒ ); } add_action( 'wp_enqueue_scripts', 'bxcft_add_js_public'); function bxcft_save_custom_option($field) { global $bp, $wpdb; if ( 'select_custom_post_type' == $field->type ) { $post_option = !empty( $_POST['select_custom_post_type_option']) ? $_POST['select_custom_post_type_option'] : โ; if ( โ != $post_option ) { if ( !empty( $field->id ) ) { $field_id = $field->id; } else { $field_id = $wpdb->insert_id; } if ( !$wpdb->query( $wpdb->prepare( โINSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'custom_post_type_option', %s, โ, 0, %d, %d)โ, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) { return false; } } } elseif ( 'multiselect_custom_post_type' == $field->type) { $post_option = !empty( $_POST['multiselect_custom_post_type_option']) ? $_POST['multiselect_custom_post_type_option'] : โ; if ( โ != $post_option ) { if ( !empty( $field->id ) ) { $field_id = $field->id; } else { $field_id = $wpdb->insert_id; } if ( !$wpdb->query( $wpdb->prepare( โINSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'multi_custom_post_type_option', %s, โ, 0, %d, %d)โ, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) { return false; } } } elseif ( 'birthdate' == $field->type) { $post_option = !empty( $_POST['birthdate_option']) ? $_POST['birthdate_option'] : โ; if ( โ != $post_option ) { if ( !empty( $field->id ) ) { $field_id = $field->id; } else { $field_id = $wpdb->insert_id; } if ( !$wpdb->query( $wpdb->prepare( โINSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'birthdate_option', %s, โ, 0, %d, %d)โ, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) { return false; } } } } add_action( 'xprofile_field_after_save', 'bxcft_save_custom_option'); function bxcft_delete_field_custom($field) { if ($field->type == 'select_custom_post_type' || $field->type == 'multiselect_custom_post_type' || $field->type == 'birthdate') { $field->delete_children(); } } add_action( 'xprofile_fields_deleted_field', 'bxcft_delete_field_custom'); function bxcft_selected_field($field) { $childs = $field->get_children(); if (isset($childs) && count($childs) > 0 && is_object($childs[0]) && $field->type == 'select_custom_post_type') { $selected_option = $childs[0]->name; } else { $selected_option = null; } if (!empty($_POST['select_custom_post_type_option'])) { $selected_option = $_POST['select_custom_post_type_option']; } ?> <div style=โdisplay: none; margin-left: 15px;โ class=โoptions-boxโ id=โselect_custom_post_typeโ> <h4><?php _e('Please, select custom post type', 'bxcft'); ?></h4> <p> <?php _e('Custom Post Type:', 'bxcft'); ?> <select name=โselect_custom_post_type_optionโ id=โselect_custom_post_type_optionโ> <?php $args = array( 'public' => true, '_builtin' => false ); $custom_post_types = get_post_types($args); foreach ($custom_post_types as $post_type) : ?> <option value=โ<?php echo $post_type; ?>โ <?php if ($selected_option == $post_type): ?>selected=โselectedโ<?php endif; ?>> <?php echo $post_type; ?> </option> <?php endforeach; ?> </select> </p> </div> <?php if (isset($childs) && count($childs) > 0 && is_object($childs[0]) && $field->type == 'multiselect_custom_post_type') { $selected_option = $childs[0]->name; } else { $selected_option = null; } if (!empty($_POST['multiselect_custom_post_type_option'])) { $selected_option = $_POST['multiselect_custom_post_type_option']; } ?> <div style=โdisplay: none; margin-left: 15px;โ class=โoptions-boxโ id=โmultiselect_custom_post_typeโ> <h4><?php _e('Please, select custom post type', 'bxcft'); ?></h4> <p> <?php _e('Custom Post Type:', 'bxcft'); ?> <select name=โmultiselect_custom_post_type_optionโ id=โmultiselect_custom_post_type_optionโ> <?php foreach ($custom_post_types as $post_type) : ?> <option value=โ<?php echo $post_type; ?>โ <?php if ($selected_option == $post_type): ?>selected=โselectedโ<?php endif; ?>> <?php echo $post_type; ?> </option> <?php endforeach; ?> </select> </p> </div> <?php if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0]) && $field->type == 'birthdate') { $selected_option = $childs[0]->name; } else { $selected_option = null; } if (!empty($_POST['birthdate_option'])) { $selected_option = $_POST['birthdate_option']; } ?> <div style=โdisplay: none; margin-left: 15px;โ class=โoptions-boxโ id=โbirthdateโ> <h4><?php _e('Show age (hide birthdate)', 'bxcft'); ?></h4> <p> <?php _e('Check this if you want to show age instead of birthdate:', 'bxcft'); ?> <input type=โcheckboxโ name=โbirthdate_optionโ value=โshow_ageโ id=โbirthdate_optionโ <?php if ($selected_option == 'show_age') : ?>checked=โcheckedโ<?php endif; ?>/> </p> </div> <?php if (!is_null($field->type)) : ?> <script type=โtext/javascriptโ> jQuery(document).ready(function() { bxcft.select('<?php echo $field->type; ?>'); }); </script> <?php endif; } add_action('xprofile_field_additional_options', 'bxcft_selected_field'); /** * This filter add a new level of visibility. Hide this field for everyone. Nobody can see. * @param type $visibility_levels * @return type */ function bxcft_xprofile_get_visibility_levels($visibility_levels) { $visibility_levels['nobody'] = array('id' => 'nobody', 'label' => __('Nobody', 'bxcft')); return $visibility_levels; } add_filter('bp_xprofile_get_visibility_levels', 'bxcft_xprofile_get_visibility_levels', 1); /** * This filter is necessary to hide fields when 'nobody' new visibility is selected. * @param type $hidden_fields * @param type $displayed_user_id * @param type $current_user_id * @return type */ function bxcft_xprofile_get_hidden_fields_for_user($hidden_fields, $displayed_user_id=0, $current_user_id=0) { if ( !$displayed_user_id ) { $displayed_user_id = bp_displayed_user_id(); } if ( !$displayed_user_id ) { return array(); } if ( !$current_user_id ) { $current_user_id = bp_loggedin_user_id(); } // @todo โ This is where you'd swap out for current_user_can() checks $new_hidden_fields = array(); if ( $current_user_id ) { // Current user is logged in if ( $displayed_user_id == $current_user_id ) { // If you're viewing your own profile, nothing's private } elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) { // If the current user and displayed user are friends, so exclude nobody $hidden_levels[] = 'nobody'; $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels ); } else { // current user is logged-in but not friends, so exclude friends-only $hidden_levels[] = 'nobody'; $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels ); } } else { // Current user is not logged in, so exclude friends-only and loggedin $hidden_levels[] = 'nobody'; $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels ); } if (is_array($new_hidden_fields)) $hidden_fields = array_merge($hidden_fields, $new_hidden_fields); return $hidden_fields; } add_filter('bp_xprofile_get_hidden_fields_for_user', 'bxcft_xprofile_get_hidden_fields_for_user', 10, 3); /** * Update profile */ function bxcft_updated_profile($bp_user_id, $posted_field_ids, $errors) { global $bp; // There are errors if ( empty( $errors ) ) { // Reset the errors var $errors = false; // Now we've checked for required fields, lets save the values. foreach ( (array) $posted_field_ids as $field_id ) { // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. if ( empty( $_POST['field_' . $field_id] ) ) $value = array(); else $value = $_POST['field_' . $field_id]; // Handles delete checkbox. $uploads = wp_upload_dir(); $field = new BP_XProfile_Field($field_id); if ($field->type == 'image' && isset($_POST['field_'.$field_id.'_deleteimg']) && $_POST['field_'.$field_id.'_deleteimg']) { if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg'])) { unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg']); } $value = array(); } if ($field->type == 'file' && isset($_POST['field_'.$field_id.'_deletefile']) && $_POST['field_'.$field_id.'_deletefile']) { if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile'])) { unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile']); } $value = array(); } // Handles image field type saving. if (isset($_FILES['field_'.$field_id]) && $_FILES['field_'.$field_id]['size'] > 0) { $field = new BP_XProfile_Field($field_id); if ($field->type == 'image') { $ext_allowed = array('jpg','jpeg','gif','png'); apply_filters('images_ext_allowed', $ext_allowed); } elseif ($field->type == 'file') { $ext_allowed = array('doc','docx','pdf'); apply_filters('files_ext_allowed', $ext_allowed); } $ext = strtolower(substr($_FILES['field_'.$field_id]['name'], strrpos($_FILES['field_'.$field_id]['name'],'.')+1)); if (!in_array($ext, $ext_allowed)) { $errors = true; } else { require_once( ABSPATH . '/wp-admin/includes/file.php' ); add_filter( 'upload_dir', 'bxcft_profile_upload_dir', 10, 1 ); $_POST['action'] = 'wp_handle_upload'; $uploaded_file = wp_handle_upload( $_FILES['field_'.$field_id] ); $uploads = wp_upload_dir(); $value = str_replace($uploads['baseurl'], โ, $uploaded_file['url']); } } else { if ($field->type == 'image' && (!isset($_POST['field_'.$field_id.'_deleteimg']) || !$_POST['field_'.$field_id.'_deleteimg']) && isset($_POST['field_'.$field_id.'_hiddenimg']) && $_POST['field_'.$field_id.'_hiddenimg'] != โ) { $value = $_POST['field_'.$field_id.'_hiddenimg']; } elseif ($field->type == 'file' && (!isset($_POST['field_'.$field_id.'_deletefile']) || !$_POST['field_'.$field_id.'_deletefile']) && isset($_POST['field_'.$field_id.'_hiddenfile']) && $_POST['field_'.$field_id.'_hiddenfile'] != โ) { $value = $_POST['field_'.$field_id.'_hiddenfile']; } } if ( !xprofile_set_field_data( $field_id, $bp_user_id, $value ) ) { $errors = true; } else { do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); } } } } add_action('xprofile_updated_profile', 'bxcft_updated_profile', 10, 3); function bxcft_signup_user($user_id, $user_login, $user_password, $user_email, $usermeta) { // Set any profile data if ( bp_is_active( 'xprofile' ) ) { if ( !empty( $usermeta['profile_field_ids'] ) ) { $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); foreach( (array) $profile_field_ids as $field_id ) { if (!empty($usermeta["field_{$field_id}"])) $value = $usermeta["field_{$field_id}"]; else $value = array(); // Handles delete checkbox. $uploads = wp_upload_dir(); $field = new BP_XProfile_Field($field_id); if ($field->type == 'image' && isset($_POST['field_'.$field_id.'_deleteimg']) && $_POST['field_'.$field_id.'_deleteimg']) { if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg'])) { unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg']); } $value = array(); } if ($field->type == 'file' && isset($_POST['field_'.$field_id.'_deletefile']) && $_POST['field_'.$field_id.'_deletefile']) { if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile'])) { unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile']); } $value = array(); } // Handles image field type saving. if (isset($_FILES['field_'.$field_id]) && $_FILES['field_'.$field_id]['size'] > 0) { $field = new BP_XProfile_Field($field_id); if ($field->type == 'image') { $ext_allowed = array('jpg','jpeg','gif','png'); apply_filters('images_ext_allowed', $ext_allowed); } elseif ($field->type == 'file') { $ext_allowed = array('doc','docx','pdf'); apply_filters('files_ext_allowed', $ext_allowed); } $ext = strtolower(substr($_FILES['field_'.$field_id]['name'], strrpos($_FILES['field_'.$field_id]['name'],'.')+1)); if (in_array($ext, $ext_allowed)) { require_once( ABSPATH . '/wp-admin/includes/file.php' ); add_filter( 'upload_dir', 'bxcft_profile_upload_dir', 10, 1 ); $_POST['action'] = 'wp_handle_upload'; $uploaded_file = wp_handle_upload( $_FILES['field_'.$field_id] ); $destino = str_replace('0โฒ, $user_id, $uploaded_file['file']); $aux = explode(โ/โ, $destino); if (!file_exists(str_replace('/'.$aux[count($aux)-1], โ, $destino))) { mkdir(str_replace('/'.$aux[count($aux)-1], โ, $destino)); } copy($uploaded_file['file'], $destino); unlink($uploaded_file['file']); $value = str_replace($uploads['baseurl'], โ, str_replace('0โฒ, $user_id, $uploaded_file['url'])); } } else { if ($field->type == 'image' && (!isset($_POST['field_'.$field_id.'_deleteimg']) || !$_POST['field_'.$field_id.'_deleteimg']) && isset($_POST['field_'.$field_id.'_hiddenimg']) && $_POST['field_'.$field_id.'_hiddenimg'] != โ) { $value = $_POST['field_'.$field_id.'_hiddenimg']; } elseif ($field->type == 'file' && (!isset($_POST['field_'.$field_id.'_deletefile']) || !$_POST['field_'.$field_id.'_deletefile']) && isset($_POST['field_'.$field_id.'_hiddenfile']) && $_POST['field_'.$field_id.'_hiddenfile'] != โ) { $value = $_POST['field_'.$field_id.'_hiddenfile']; } } xprofile_set_field_data( $field_id, $user_id, $value ); } } } } add_action('bp_core_signup_user', 'bxcft_signup_user', 10, 5); function bxcft_profile_upload_dir( $upload_dir, $user_id=0 ) { if ($user_id == 0) $user_id = bp_displayed_user_id(); $profile_subdir = '/profiles/' . $user_id; $upload_dir['path'] = $upload_dir['basedir'] . $profile_subdir; $upload_dir['url'] = $upload_dir['baseurl'] . $profile_subdir; $upload_dir['subdir'] = $profile_subdir; return $upload_dir; } /** * Replacing the buddypress filter link profile is it has the filter. * If user deactivated the filter, we don't add another filter. */ function bxcft_remove_xprofile_links() { if (has_filter('bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data')) { remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); add_filter( 'bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data', 9, 2); } } add_action( 'bp_setup_globals', 'bxcft_remove_xprofile_links', 9999 ); /** * This function only works if plugin bp-profile search is active. * @global type $bps_options * @param type $type * @return string */ function bxcft_profile_field_type($type) { if (function_exists('is_plugin_active') && is_plugin_active('bp-profile-search/bps-main.php') || in_array( 'bp-profile-search/bps-main.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) { global $bps_options; $id = bp_get_the_profile_field_id (); if ( ((is_admin() && strpos($_SERVER['REQUEST_URI'], 'page=bp-profile-search')) || (isset($bps_options) && $bps_options['agerange'] == $id && isset($_POST['bp_profile_search']) && $_POST['bp_profile_search'])) && $type == 'birthdate') { return 'datebox'; } } return $type; } add_filter('bp_the_profile_field_type', 'bxcft_profile_field_type', 1); add_action('init', 'my_xprofile_links'); function my_xprofile_links() { if (has_filter('bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data')) { remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9 ); } if (has_filter('bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data')) { remove_filter( 'bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data', 9); } add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 10, 2); } function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { if ( 'datebox' == $field_type ) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); $new_values[] = make_clickable( $value ); } $values = implode( ', ', $new_values ); } return $values; }
November 24, 2013 at 12:30 am #174704In reply to: Buddypress on Mobile / Hide admin access
mattg123Participant@pjbursnall yeah that code replicates the notification element only (the only part that is somewhat confusing to replicate) you place the code in the plugins directory in bp-custom.php you may have to create the file yourself.
http://stackoverflow.com/questions/9953482/how-to-make-a-pure-css-based-dropdown-menu – shows you how to create a drop down menu, https://codex.wordpress.org/Function_Reference/get_currentuserinfo get the current users info so you can create links to their profile pages, etc.
Just a note, to add the notifcations to your custom bar your code will look something like
<li><?php bp_notification_badge(); ?></li>
September 20, 2013 at 4:10 am #171569geoffreysfParticipantPutting this in the functions or bp-custom.php files did not work.
I finally managed to get the admin and any other user excluded from the members directory by modifying the bp_had_members query that was already in my members-loop.php file.
<?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ).’&exclude=1,3,25′ . ‘&type=alphabetical&per_page=30’ ) ) : ?> <!– &exclude= user_ids of the people you want to exclude –>
By adding just this, it also removed the users from the total members count.
Note: I do not use friends or activity feeds on my site, so I have no idea if it hides from them, but I suppose it wouldn’t.
I have been looking high and low for the answer to this with my limited PHP knowledge… and wanted to share it back so other people could learn from it too.
And credit where it is due, this post led me to the answer.
https://buddypress.org/support/topic/member-parameters-not-working-with-bp_ajax_querystring/September 20, 2013 at 4:04 am #171568geoffreysfParticipantThis helped me immensely while trying to hide the admin user from the member’s directory.
Thank you!
September 2, 2013 at 5:57 pm #170759In reply to: Feature request: Hide certain members
therandomguy12345ParticipantI want to hide specific users from the “(BuddyPress) Recently Active Members” & “(BuddyPress) Members” widgets (latter one is most important for me), but I don’t want these users from the members directory. So what does the below code exactly do? Does it exclude users from members directory or the widgets? Or both?
<?php // Remove admin from directory add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user='1';//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are listing friends?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } //Remove admin from member count add_filter('bp_get_total_member_count','bpdev_members_correct_count'); function bpdev_members_correct_count($count){ $excluded_users_count=1; //change it to the number of users you want to exclude return $count-$excluded_users_count; } ?>
September 1, 2013 at 3:32 pm #170721In reply to: hide members
@mercimeKeymaster@famous You can limit who views the members directory page to the Site/Super Admin only by surrounding the members directory section using is_super_admin https://codex.wordpress.org/Function_Reference/is_super_admin then either echo message that the section is restricted or just redirect non-Admin users to another page if visitors try to use the members slug in your site.
August 8, 2013 at 12:23 am #169550In reply to: Feature request: Hide certain members
bp-helpParticipant@merosler
If your adding php code I hope you have made a child theme as @philipstancil did because that is the proper way. I would never add custom code to a parent theme’s functions.php because if you update the theme then it may get overwritten. Anyway, make sure whenever you add code to functions.php it always needs to be between opening and closing php tags like this:<?php // Remove admin from directory add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user='1';//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are listing friends?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } //Remove admin from member count add_filter('bp_get_total_member_count','bpdev_members_correct_count'); function bpdev_members_correct_count($count){ $excluded_users_count=1; //change it to the number of users you want to exclude return $count-$excluded_users_count; } ?>
July 31, 2013 at 6:51 am #169148In reply to: Feature request: Hide certain members
philipstancilParticipantCrazy that we both found this old thread within 12 hours of each other. I got it working with this code:
// Remove admin from directory add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user='1';//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are listing friends?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } //Remove admin from member count add_filter('bp_get_total_member_count','bpdev_members_correct_count'); function bpdev_members_correct_count($count){ $excluded_users_count=1; //change it to the number of users you want to exclude return $count-$excluded_users_count; }
February 10, 2013 at 5:34 am #152773Topic: How to hide admin (or specific member)
in forum How-to & Troubleshootingsabya23ParticipantI am using latest wordpress and buddypress. For my project it is necessary to hide admin and some members for security reasons. I have tried Brajesh Singh’s solution (here) but failed.
How can it be possible?
December 4, 2012 at 11:20 pm #146540Topic: There was a problem posting your update
in forum How-to & TroubleshootingtheFebvreParticipantHi,
I just install WordPress 3.4.2 and BuddyPress 1.6.1 on my local machine (Windows 7 64bit, IIS 7.5, MySQL 5.5)I can’t post in the “Activity Streams Directory” and in the “What’s new in Groupe…”
I saw a lot of post in your forum and over internet that are talking about incompatibility with MySQL Strict Mode…
I’ve enabled the DEBUG mode in wordpress and here’s the result when I try to post in the Activity :
===========
WordPress database error: [Incorrect integer value: ” for column ‘item_id’ at row 1]
INSERT INTO wp_bp_activity ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide, is_spam ) VALUES ( 1, ‘activity’, ‘activity_update’, ‘admin posted an update’, ‘test’, ‘http://andre.com/members/admin/’, ‘2012-12-04 23:13:39’, ”, ”, 0, 0 )
-1
===========
NOTE : the domain “andre.com” point to “localhost”I’ve tried to set 0 as a default value for the field ‘item_id’, but still having the same problem.
Can any one point me to the right direction to solve that problem… and in the same time save a lot of trouble to other people to ๐
Thank you!
August 12, 2012 at 12:46 am #139169In reply to: GRA4 – BuddyPress plugin or replacement?
Arrogance is BlissParticipantInteresting ‘plugin’ that GRA4.. it is a connection to their website. A little more than phoning home. Your members get included into their website. Wherever their ‘plugin’ is activated, all the members show up on all the other websites. They have a plugin for oscommerce, phpbb and wordpress and they are working on a plugin for drupal. All members are gathered to their website and you have NO admin privileges. You have NO control over the content on the website and I don’t know for sure, but I think there could be some major security (and privacy) concerns for all of your website members.
They don’t tell you straight out that you aren’t adding functionality to your WordPress website, they are providing a portal to their website, which shows up on your website making it appear like it’s your website. Quite crafty. – A FACADE-
They are using ‘elgg’ social software on their server. They authenticate using cookies and they secretly provide your website with a ‘secret key’ and their coding changes the .htaccess rewrites for your website to redirect your members to their website. The page they tell you to add, is the same name as the directory of their plugin and the rewrite for permalinks makes it appear that your members are looking at a page, but they are looking at another website. The shortcode they tell you to put on the page you create for their plugin calls the function that imports the data from their website to display on that page. So, basically.. it’s an interface with their website gra4.com. Their website shows up on an ip address in the United States, but they are Russian (no prejudice, just an observation), to share the information. Part of their coding calls a another website virturossiya.org/c (which shows up as ‘GRA4SetConfigValue(‘GRA4_remote_url’… in one of the files. That website also shows up on an ip in the USA, but the page title is in Russian and the favicon is a red star. (looking at that last domain name I can see ‘virtual russia’).
In conclusion, from my perspective, it’s a scam. You do NOT get your own social network with their ‘plugin’, you get to include your members into their website, without your members knowing it.. I don’t think that would be consistent with the spirit of WordPress or BuddyPress. I would stick with BuddyPress or one of the other true WordPress plugins that provide social networking within WordPress, unless you want to find yourself answering questions you have no answer for sometime in the future.. Let alone the risk of your own website and hosting information somehow being hacked. The concern I have is, if they are being honest, why hide all of this from WordPress users of their plugin? With their obvious ability to rewrite and redirect, who knows (really) where your website and member information is going?
If they do get back into the WordPress Repository, I would really be careful of these people. Always check to see if a plugin requires a connection with remote servers before you consider using a plugin.
July 23, 2012 at 10:49 pm #137861kraiggParticipantCan anyone help me?
I’m trying to filter the activity stream so that it only displays ‘published’ forum topics and replies.
I’m using bbPressModeration, which marks all forum topics and posts as ‘pending’, until the administrator approves and publishes the content. The problem is that pending content still appears in the activity stream.
I’m using the code below for my custom activity stream.
`
<?php/* = Generate Custom Activity Stream
* Place this function anywhere you want to show your custom stream.
* Should accept any of these parameters:
* https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/
*/my_activity_stream(‘per_page=4&page=1&action=new_forum_post,new_blog_comment,new_blog_post,new_forum_topic’);
/* = Custom Activity Stream
* Place this function in bp-custom.php (in your plugins directory)
*/
function my_activity_stream($args ) {if ( bp_has_activities($args) ) : ?>
<li class="” id=”activity-“>
<a href="”><?php endif;
wp_reset_query();
}
`June 6, 2012 at 7:46 am #135512In reply to: Exclude or Hide admin from Groups Members Directory
oblaxParticipantThanks. I saw it in members php page exclude admin mods should be set to 1.
June 6, 2012 at 7:10 am #135334In reply to: Exclude or Hide admin from Groups Members Directory
@mercimeKeymasterIf you have a bp-default child theme, copy group-header.php file.into your child theme folder as in wp-content/themes/yourchildtheme/groups/single/group-header.php
then delete lines 11-15 of said file. If you also want to delete Group Mods, then delete lines 7-30June 6, 2012 at 5:27 am #29790Topic: Exclude or Hide admin from Groups Members Directory
in forum MiscellaneousoblaxParticipantI am trying to search for a solution on how to hide admin in the Groups member directory. Is there a plugin or hack for this?
May 26, 2012 at 4:29 pm #29610Topic: Cant update user profile
in forum How-to & TroubleshootingfallingupParticipantHi guys,
I am having a problem! When editing a users profile, I click “save changes” and the page simply reloads and no changes take effect, this also seems to be effected on almost all BuddyPress forms(messaging, etc). I am using Gravity Forms for user registration, so users can still sign up that way. I have also tried on the default BP theme.
– Here are some of the questions to what you guys would like to know…
– I am running the Latest version of WordPress and BuddyPress
– WP is installed in the root
– I did just recently upgrade both WordPress(3.X.X to latest) and BuddyPress(1.2.9 to 1.5.5)
WordPress was functioning fine before upgrade, the issue was there before the upgrade, which I hoped was going to fix the problem
– Running BP 1.5.5
– Upgraded from BP 1.2.9
– Other plugins installed are: Advanced Custom Fields, AutoChimp, BackupBuddy, BP Blog Author Profile Links, BP Chat, BP Members Avatar Map, BP User Profile Map, BuddyPress, BuddyPress Album, Front-end Editor, Gravity Forms, Gravity Forms + Custom Post Types, Gravity Forms Directory Add-on, Gravity Forms User Registration Add-on, Lightbox Plus, Members, Remove Dashboard Access for Non-Admins, Simple 301 Redirects, The Events Calendar, The Events Calendar Pro, WordPress Database Backup, WordPress SEO, WP-Users Online
WP Hide Dashboard, WP Maintenance Mode
– I am using a custom theme, though I am getting the same issue on default BP theme.
– I have not modified WP or BP core
– bp-custom.php includes only “define(“BP_DEFAULT_COMPONENT”,”profile”);”
– Not running bbPress
– Do not have access to error log
– Another agency is providing hosting for our “joint client” and they dont like to give us access to anything, I have FTP access only.Let me know if you need anything else!
April 26, 2012 at 2:53 pm #29074Topic: Hide certain blogs from the blog directory?
in forum How-to & TroubleshootingKayLee1000MemberIn buddypress, when you click on blogs, it shows all blogs created on the network…
Is there any way I can exclude all blogs created by “admin”….
Or maybe just exclude certain blogs by id or name or something…
Is it possible at all?I’m on the default buddypress theme… I assume this will be changed in the blogs-loop.php
But I just don’t know how… I only know the basics of php.April 25, 2012 at 7:17 am #29049corbettbarrMemberMy BuddyPress installation sends email notifications for private messages sent via BuddyPress, but it does not send email notifications for @mentions or comments.
I found a similar issue in the BuddyPress forums here, but it was never answered:
Here are some details about my installation.
This is a “private” install where only registered members have access to the site.
1. Which version of WordPress are you running?
latest version of wp – 3.3.22. Did you install WordPress as a directory or subdomain install?
subdirectory of a subdomain3. If a directory install, is it in root or in a subdirectory?
subdirectory4. Did you upgrade from a previous version of WordPress? If so, from which version?
have upgraded regularly for the past year5. Was WordPress functioning properly before installing/upgrading BuddyPress (BP)? e.g. permalinks, creating a new post, commenting.
Yes, other WordPress email notices are sent (registration + lost passwords + bbpress notifications)6. Which version of BP are you running?
1.5.57. Did you upgraded from a previous version of BP? If so, from which version?
No. This is a fresh install8. Do you have any plugins other than BuddyPress installed and activated? If so, which ones?
I have deactivated all other plugins and the issue still exists.9. Are you using the standard BuddyPress themes or customized themes?
Customized based on a WooThemes10. Have you modified the core files in any way?
No.11. Do you have any custom functions in bp-custom.php?
Yes, just to hide the admin bar12. If running bbPress, which version? Or did your BuddyPress install come with a copy of bbPress built-in?
Yes, running 2.0.213. Please provide a list of any errors in your server’s log files.
No errors.14. Which company provides your hosting?
Storm On Demand15. Is your server running Windows, or if Linux; Apache, nginx or something else?
Linux w/ApacheLet me know if you need any other info. Thanks!
March 10, 2012 at 11:41 am #28172Topic: How to hide profile fields
in forum How-to & TroubleshootingmikewelshParticipantHi
I am using latest versions of WP and BP as a directory multisite.
I want students from my conferences to register. I want to include their school and school URL as mandatory registration profile fields, but I do not want these field to display on site so my competitors can harvest my customers addresses.
How can I do this but still have admin access to the hidden fields?
many thanks, Mike
January 29, 2012 at 7:14 am #128781In reply to: hide admin from members list
@mercimeKeymasterYou mean you don’t want the Admin to be included in the list of members in members directory?
October 21, 2011 at 11:17 pm #24968Topic: Hide Admin in Members Directory?
in forum Creating & ExtendingHal.CarletonMemberI’m using the Custom Community theme with BuddyPress.
Is there a way to remove the Admin account from the Members Directory? The account does not represent anyone in the community and is out of place in Members Directory. Having it there looks very unprofessional.
Thanks
-
AuthorSearch Results