· 8 years ago · Apr 09, 2018, 05:06 AM
1<?php
2/**
3 * @package WordPress
4 * @subpackage Kleo
5 * @author SeventhQueen <themesupport@seventhqueen.com>
6 * @since Kleo 1.0
7 */
8
9/**
10 * Kleo Child Theme Functions
11 * Add custom code below
12*/
13
14
15/* Exclude BuddyPress Users from Showing Up Anywhere */
16add_filter( 'bp_after_has_members_parse_args', 'millionairesdigest_exclude_users' );
17function millionairesdigest_exclude_users( $args ) {
18 //do not exclude in admin
19 if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
20 return $args;
21 }
22 $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
23 if( !is_array( $excluded ) ) {
24 $excluded = explode(',', $excluded );
25 }
26 $user_ids = array( 836 ); //user ids
27 $excluded = array_merge( $excluded, $user_ids );
28 $args['exclude'] = $excluded;
29 return $args;
30}
31
32
33/* Add Missing Pending Posts Back to Site */
34function my_custom_post_status(){
35 register_post_status( 'pending-review', array(
36 'label' => _x( 'Pending Review', 'post' ),
37 'public' => true,
38 'exclude_from_search' => false,
39 'show_in_admin_all_list' => true,
40 'show_in_admin_status_list' => true,
41 'label_count' => _n_noop( 'Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>' ),
42 ) );
43}
44add_action( 'init', 'my_custom_post_status' );
45
46
47/* Rename Private Message Button */
48function tweak_button_label ( $args ) {
49 $args[link_text] = 'message';
50 return $args;
51}
52add_filter( 'bp_get_send_message_button_args', 'tweak_button_label', 1, 1 );
53
54
55/* Remove "Like/Unlike" Text from BuddyPress Favorite Button */
56remove_action( 'wp_ajax_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
57remove_action( 'wp_ajax_nopriv_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
58remove_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
59remove_action( 'wp_ajax_nopriv_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
60function custom_like_text(){
61 // Bail if not a POST action
62 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
63 return;
64 if ( bp_activity_add_user_favorite( $_POST['id'] ) )
65 _e( '', 'buddypress' );
66 else
67 _e( '', 'buddypress' );
68 exit;
69}
70function custom_unlike_text(){
71 // Bail if not a POST action
72 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
73 return;
74 if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
75 _e( '', 'buddypress' );
76 else
77 _e( '', 'buddypress' );
78 exit;
79}
80add_action( 'wp_ajax_activity_mark_fav', 'custom_like_text' );
81add_action( 'wp_ajax_nopriv_activity_mark_fav', 'custom_like_text' );
82add_action( 'wp_ajax_activity_mark_unfav', 'custom_unlike_text' );
83add_action( 'wp_ajax_nopriv_activity_mark_unfav', 'custom_unlike_text' );
84
85
86/* Remove Public Message Button */
87add_filter('bp_get_send_public_message_button', '__return_false');
88
89
90/* Add Support for Showing Custom Post Type "Articles" in BuddyPress Activity Streams */
91function article_activity_args() {
92 if ( ! bp_is_active( 'activity' ) ) {
93 return;
94 }
95 add_post_type_support( 'article', 'buddypress-activity' );
96 bp_activity_set_post_type_tracking_args( 'article', array(
97 'component_id' => 'activity',
98 'action_id' => 'new_article',
99 'bp_activity_admin_filter' => __( 'Wrote a new article', 'text-domain' ),
100 'bp_activity_front_filter' => __( 'Articles', 'text-domain' ),
101 'contexts' => array( 'activity', 'member' ),
102 'activity_comment' => true,
103 'bp_activity_new_post' => __( '%1$s wrote a new article, <a href="%2$s">[Article]</a>', 'text-domain' ),
104 'position' => 100,
105 ) );
106}
107add_action( 'init', 'article_activity_args' );
108function article_include_post_type_title( $action, $activity ) {
109 if ( empty( $activity->id ) ) {
110 return $action;
111 }
112 if ( 'new_article' != $activity->type ) {
113 return $action;
114 }
115 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
116 if ( empty( $matches[1][1] ) || '[Article]' != $matches[1][1] ) {
117 return $action;
118 }
119 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
120 if ( empty( $post_type_title ) ) {
121 switch_to_blog( $activity->item_id );
122 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
123 // We have a title save it in activity meta to avoid switching blogs too much
124 if ( ! empty( $post_type_title ) ) {
125 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
126 }
127 restore_current_blog();
128 }
129 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
130}
131add_filter( 'bp_activity_custom_post_type_post_action', 'article_include_post_type_title', 10, 2 );
132
133
134/* Add Support for Showing Custom Post Type "Videos" in BuddyPress Activity Streams */
135function video_activity_args() {
136 if ( ! bp_is_active( 'activity' ) ) {
137 return;
138 }
139 add_post_type_support( 'video', 'buddypress-activity' );
140 bp_activity_set_post_type_tracking_args( 'video', array(
141 'component_id' => 'activity',
142 'action_id' => 'new_video',
143 'bp_activity_admin_filter' => __( 'Uploaded a new video', 'text-domain' ),
144 'bp_activity_front_filter' => __( 'Videos', 'text-domain' ),
145 'contexts' => array( 'activity', 'member' ),
146 'activity_comment' => true,
147 'bp_activity_new_post' => __( '%1$s uploaded a new video, <a href="%2$s">[Video]</a>', 'text-domain' ),
148 'position' => 100,
149 ) );
150}
151add_action( 'init', 'video_activity_args' );
152function video_include_post_type_title( $action, $activity ) {
153 if ( empty( $activity->id ) ) {
154 return $action;
155 }
156 if ( 'new_video' != $activity->type ) {
157 return $action;
158 }
159 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
160 if ( empty( $matches[1][1] ) || '[Video]' != $matches[1][1] ) {
161 return $action;
162 }
163 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
164 if ( empty( $post_type_title ) ) {
165 switch_to_blog( $activity->item_id );
166 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
167 // We have a title save it in activity meta to avoid switching blogs too much
168 if ( ! empty( $post_type_title ) ) {
169 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
170 }
171 restore_current_blog();
172 }
173 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
174}
175add_filter( 'bp_activity_custom_post_type_post_action', 'video_include_post_type_title', 10, 2 );
176
177
178/* Add Support for Showing Custom Post Type "Photos" in BuddyPress Activity Streams */
179function photo_activity_args() {
180 if ( ! bp_is_active( 'activity' ) ) {
181 return;
182 }
183 add_post_type_support( 'photo', 'buddypress-activity' );
184 bp_activity_set_post_type_tracking_args( 'photo', array(
185 'component_id' => 'activity',
186 'action_id' => 'new_photo',
187 'bp_activity_admin_filter' => __( 'Uploaded a new photo', 'text-domain' ),
188 'bp_activity_front_filter' => __( 'Photos', 'text-domain' ),
189 'contexts' => array( 'activity', 'member' ),
190 'activity_comment' => true,
191 'bp_activity_new_post' => __( '%1$s uploaded a new photo, <a href="%2$s">[Photo]</a>', 'text-domain' ),
192 'position' => 100,
193 ) );
194}
195add_action( 'init', 'photo_activity_args' );
196function photo_include_post_type_title( $action, $activity ) {
197 if ( empty( $activity->id ) ) {
198 return $action;
199 }
200 if ( 'new_photo' != $activity->type ) {
201 return $action;
202 }
203 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
204 if ( empty( $matches[1][1] ) || '[Photo]' != $matches[1][1] ) {
205 return $action;
206 }
207 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
208 if ( empty( $post_type_title ) ) {
209 switch_to_blog( $activity->item_id );
210 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
211 // We have a title save it in activity meta to avoid switching blogs too much
212 if ( ! empty( $post_type_title ) ) {
213 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
214 }
215 restore_current_blog();
216 }
217 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
218}
219add_filter( 'bp_activity_custom_post_type_post_action', 'photo_include_post_type_title', 10, 2 );
220
221
222/* Add Support for Showing Custom Post Type "Music" in BuddyPress Activity Streams */
223function audio_activity_args() {
224 if ( ! bp_is_active( 'activity' ) ) {
225 return;
226 }
227 add_post_type_support( 'audio', 'buddypress-activity' );
228 bp_activity_set_post_type_tracking_args( 'audio', array(
229 'component_id' => 'activity',
230 'action_id' => 'new_audio',
231 'bp_activity_admin_filter' => __( 'Uploaded a new song', 'text-domain' ),
232 'bp_activity_front_filter' => __( 'Music', 'text-domain' ),
233 'contexts' => array( 'activity', 'member' ),
234 'activity_comment' => true,
235 'bp_activity_new_post' => __( '%1$s uploaded a new song, <a href="%2$s">[Song]</a>', 'text-domain' ),
236 'position' => 100,
237 ) );
238}
239add_action( 'init', 'audio_activity_args' );
240function audio_include_post_type_title( $action, $activity ) {
241 if ( empty( $activity->id ) ) {
242 return $action;
243 }
244 if ( 'new_audio' != $activity->type ) {
245 return $action;
246 }
247 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
248 if ( empty( $matches[1][1] ) || '[Song]' != $matches[1][1] ) {
249 return $action;
250 }
251 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
252 if ( empty( $post_type_title ) ) {
253 switch_to_blog( $activity->item_id );
254 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
255 // We have a title save it in activity meta to avoid switching blogs too much
256 if ( ! empty( $post_type_title ) ) {
257 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
258 }
259 restore_current_blog();
260 }
261 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
262}
263add_filter( 'bp_activity_custom_post_type_post_action', 'audio_include_post_type_title', 10, 2 );
264
265
266/* Add Support for Allowing Featued Images for Custom Post Type "Articles" to Be Displayed in BuddyPress Activity Streams */
267function article_bp_activity_entry_meta() {
268 if ( bp_get_activity_type() == 'new_article' ) {?>
269 <?php
270 global $wpdb, $post, $bp;
271 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
272 ?>
273 <img src="<?php echo $theimg[0]; ?>" >
274 <?php }
275}
276add_action('bp_activity_excerpt_append_text', 'article_bp_activity_entry_meta');
277
278
279/* Add Support for Allowing Featued Images for Custom Post Type "Photos" to Be Displayed in BuddyPress Activity Streams */
280function photo_bp_activity_entry_meta() {
281 if ( bp_get_activity_type() == 'new_photo' ) {?>
282 <?php
283 global $wpdb, $post, $bp;
284 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
285 ?>
286 <img src="<?php echo $theimg[0]; ?>" >
287 <?php }
288}
289add_action('bp_activity_excerpt_append_text', 'photo_bp_activity_entry_meta');
290
291
292/* Remove Categories & Tag Labels from Author's Statistics Widget */
293add_filter('apsw_taxonomy_category', 'apsw_taxonomy_category');
294 if (!function_exists('apsw_taxonomy_category')) {
295 function apsw_taxonomy_category($categoryList) {
296 return null;
297 }
298 }
299add_filter('apsw_taxonomy_post_tag', 'apsw_taxonomy_post_tag');
300 if (!function_exists('apsw_taxonomy_post_tag')) {
301 function apsw_taxonomy_post_tag($tagList) {
302 return null;
303 }
304 }
305add_filter('apsw_taxonomy_custom', 'apsw_taxonomy_custom');
306 if (!function_exists('apsw_taxonomy_custom')) {
307 function apsw_taxonomy_custom($taxonomyList) {
308 return null;
309 }
310 }
311
312
313/* Add Support for Allowing Custom Post Type "Articles" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
314function generate_article_from_form_submission() {
315 // Get the submitted field values
316 $post_title = af_get_field( 'article_title' );
317 $post_content = af_get_field( 'article_content' );
318 // Set up a form using the values for post title and content
319 // Replace post_type with whatever type of post you want to generate
320 $post_data = array(
321 'post_type' => 'article',
322 'post_status' => 'publish',
323 'post_title' => $post_title,
324 'post_content' => $post_content,
325 );
326 // Create post with the previously retrieved values
327 $post_id = wp_insert_post( $post_data );
328 // Save extra_information field directly to custom field on post
329 af_save_field( '_thumbnail_id', $post_id );
330}
331add_action( 'af/form/submission/key=form_5a6d550fa348b', 'generate_article_from_form_submission', 10 );
332
333
334/* Add Support for Allowing Custom Post Type "Videos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
335function generate_video_from_form_submission() {
336 // Get the submitted field values
337 $post_title = af_get_field( 'video_title' );
338 $post_content = af_get_field( 'video_link' );
339 // Set up a form using the values for post title and content
340 // Replace post_type with whatever type of post you want to generate
341 $post_data = array(
342 'post_type' => 'video',
343 'post_status' => 'publish',
344 'post_title' => $post_title,
345 'post_content' => $post_content,
346 );
347 // Create post with the previously retrieved values
348 $post_id = wp_insert_post( $post_data );
349 // Save extra_information field directly to custom field on post
350 af_save_field( 'video_content', $post_id );
351}
352add_action( 'af/form/submission/key=form_5a7606d26943d', 'generate_video_from_form_submission', 10 );
353
354
355/* Add Support for Allowing Custom Post Type "Photos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
356function generate_photo_from_form_submission() {
357 // Get the submitted field values
358 $post_title = af_get_field( 'photo_title' );
359 $post_content = af_get_field( 'photo_content' );
360 // Set up a form using the values for post title and content
361 // Replace post_type with whatever type of post you want to generate
362 $post_data = array(
363 'post_type' => 'photo',
364 'post_status' => 'publish',
365 'post_title' => $post_title,
366 'post_content' => $post_content,
367 );
368 // Create post with the previously retrieved values
369 $post_id = wp_insert_post( $post_data );
370 // Save extra_information field directly to custom field on post
371 af_save_field( '_thumbnail_id', $post_id );
372}
373add_action( 'af/form/submission/key=form_5a76139d04770', 'generate_photo_from_form_submission', 10 );
374
375
376/* Add Support for Allowing Custom Post Type "Music" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
377function generate_audio_from_form_submission() {
378 // Get the submitted field values
379 $post_title = af_get_field( 'audio_title' );
380 $post_content = af_get_field( 'audio_link' );
381 // Set up a form using the values for post title and content
382 // Replace post_type with whatever type of post you want to generate
383 $post_data = array(
384 'post_type' => 'audio',
385 'post_status' => 'publish',
386 'post_title' => $post_title,
387 'post_content' => $post_content,
388 );
389 // Create post with the previously retrieved values
390 $post_id = wp_insert_post( $post_data );
391 // Save extra_information field directly to custom field on post
392 af_save_field( 'audio_artist', $post_id );
393 af_save_field( 'audio_genre', $post_id );
394 af_save_field( 'audio_content', $post_id );
395}
396add_action( 'af/form/submission/key=form_5a7613a051921', 'generate_audio_from_form_submission', 10 );
397
398
399/* Add Support for Single Line WYSIWYG to Advanced Custom Fields Pro */
400define('MEDIUM_EDITOR_THEME', 'kleo');
401add_filter('medium-editor-theme', 'my_medium_editor_theme_function');
402function my_medium_editor_theme_function($theme) {
403 $theme = 'kleo';
404 return $theme;
405}
406
407
408/* Change Admin Display Name to Founder */
409function change_role_name() {
410 global $wp_roles;
411 if ( ! isset( $wp_roles ) )
412 $wp_roles = new WP_Roles();
413 $wp_roles->roles['administrator']['name'] = 'Founder';
414 $wp_roles->role_names['administrator'] = 'Founder';
415}
416add_action('init', 'change_role_name');
417
418
419/* Add Support for Allowing & Using Shortcodes to Display BuddyPress X-Profile Fields (Example: Use [xprofile field=12] to display a field by default user detection, and [xprofile field="13" user="id#, current, author, displayed"] to display a field based on specific user, currently logged in user, author's post/page currently being viewed, or currently displayed BuddyPress profile. ) And Note: Regardless of whether or not somebody sets a profile field private, friends only, or logged in users only, the shortcode will still display no matter what, and so, until we actually have a way of fixing this, every shortcode we use to display these profile fields with has to be made and set public. */
420add_action('bp_init', 'md_bpxps_init');
421function md_bpxps_init() {
422 add_shortcode('xprofile', 'md_bpxps_xprofile_shortcode');
423}
424function md_bpxps_xprofile_shortcode($attributes) {
425 if(empty($attributes['field'])) return false;
426 extract($attributes);
427 $user_id = (isset($user)) ? $user : false;
428 global $bp;
429 if (!empty($user_id) && intval($user_id)===0) {
430 // shortcode-defined username
431 $user_id = get_user_by( 'slug', $user_id);
432 }
433 if ((isset($user) && $user=='displayed') ||
434 (empty($user_id) && isset($bp->displayed_user->id))) {
435 // On profile page, show the displayed user's information
436 $user_id = $bp->displayed_user->id;
437 }
438 global $post;
439 if ((isset($user) && $user=='author') ||
440 (empty($user_id) && !empty($post->post_author))) {
441 // On author or single post page, show the author's information
442 $user_id = $post->post_author;
443 }
444 if ((isset($user) && $user=='current') ||
445 (empty($user_id) && is_user_logged_in())) {
446 // Show the currently logged in user's information
447 $user_id = get_current_user_id();
448 }
449 if (empty($user_id)) return false;
450 return xprofile_get_field_data($field, $user_id);
451}
452
453
454/* Add Support for Allowing Featued Images to Be Set fo Video Posts Note: At the point where it says, "Handle the upload of a new image...," remove this entire part to do a test to see if it removes the problem as to why the video image displays on the single post page. */
455/* If a YouTube or Vimeo video is added in the post content, grab its thumbnail and set it as the featured image. */
456function millionairesdigest_set_media_as_featured_image( $post_id, $post ) {
457
458 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
459 return;
460 }
461 if ( wp_is_post_revision( $post_id ) ) {
462 return;
463 }
464 $content = isset( $post->post_content ) ? $post->post_content : '';
465 // Only check the first 800 characters of our post.
466 $content = substr( $content, 0, 800 );
467 // Allow developers to filter the content to allow for searching in postmeta or other places.
468 $content = apply_filters( 'millionairesdigest_featured_images_from_video_filter_content', $content );
469 // Props to @rzen for lending his massive brain smarts to help with the regex.
470 $do_video_thumbnail = (
471 $post_id
472 && ! has_post_thumbnail( $post_id )
473 && $content
474 // Get the video and thumb URLs if they exist.
475 && ( preg_match( '/\/\/(www\.)?(youtu|youtube)\.(com|be)\/(watch|embed)?\/?(\?v=)?([a-zA-Z0-9\-\_]+)/', $content, $youtube_matches )
476 || preg_match( '#https?://(.+\.)?vimeo\.com/.*#i', $content, $vimeo_matches ) )
477 );
478 if ( ! $do_video_thumbnail ) {
479 return update_post_meta( $post_id, '_is_video', false );
480 }
481 $video_thumbnail_url = false;
482 $youtube_id = ! empty( $youtube_matches ) ? $youtube_matches[6] : '';
483 $vimeo_id = ! empty( $vimeo_matches ) ? preg_replace( "/[^0-9]/", "", $vimeo_matches[0] ) : '';
484 if ( $youtube_id ) {
485 // Check to see if our max-res image exists.
486 $remote_headers = wp_remote_head( 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' );
487 $is_404 = ( 404 === wp_remote_retrieve_response_code( $remote_headers ) );
488 $video_thumbnail_url = ( ! $is_404 ) ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
489 } elseif ( $vimeo_id ) {
490 $vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $vimeo_id ) . '.php' );
491 if ( isset( $vimeo_data['response']['code'] ) && '200' == $vimeo_data['response']['code'] ){
492 $response = unserialize( $vimeo_data['body'] );
493 $video_thumbnail_url = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false;
494 }
495 }
496 // If we found an image...
497 $attachment_id = $video_thumbnail_url && ! is_wp_error( $video_thumbnail_url )
498 // Then sideload it.
499 ? millionairesdigest_ms_media_sideload_image_with_new_filename( $video_thumbnail_url, $post_id, sanitize_title( preg_replace( "/[^a-zA-Z0-9\s]/", "-", get_the_title() ) ) )
500 // No thumbnail url found.
501 : 0;
502 // If attachment wasn't created, bail.
503 if ( ! $attachment_id ) {
504 return;
505 }
506 // Woot! we got an image, so set it as the post thumbnail.
507 set_post_thumbnail( $post_id, $attachment_id );
508 update_post_meta( $post_id, '_is_video', true );
509}
510add_action( 'save_post', 'millionairesdigest_set_media_as_featured_image', 10, 2 );
511/**
512 * Handle the upload of a new image.
513 *
514 * @since 1.0.0
515 *
516 * @param string $url URL to sideload.
517 * @param int $post_id Post ID to attach to.
518 * @param string|null $filename Filename to use.
519 * @return mixed
520 */
521function millionairesdigest_ms_media_sideload_image_with_new_filename( $url, $post_id, $filename = null ) {
522 if ( ! $url || ! $post_id ) {
523 return new WP_Error( 'missing', __( 'Need a valid URL and post ID...', 'automatic-featured-images-from-videos' ) );
524 }
525 require_once( ABSPATH . 'wp-admin/includes/file.php' );
526 // Download file to temp location, returns full server path to temp file, ex; /home/user/public_html/mysite/wp-content/26192277_640.tmp.
527 $tmp = download_url( $url );
528 // If error storing temporarily, unlink.
529 if ( is_wp_error( $tmp ) ) {
530 // Clean up.
531 @unlink( $file_array['tmp_name'] );
532 $file_array['tmp_name'] = '';
533 // And output wp_error.
534 return $tmp;
535 }
536 // Fix file filename for query strings.
537 preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
538 // Extract filename from url for title.
539 $url_filename = basename($matches[0]);
540 // Determine file type (ext and mime/type).
541 $url_type = wp_check_filetype($url_filename);
542 // Override filename if given, reconstruct server path.
543 if ( !empty( $filename ) ) {
544 $filename = sanitize_file_name( $filename );
545 // Extract path parts.
546 $tmppath = pathinfo( $tmp );
547 // Build new path.
548 $new = $tmppath['dirname'] . '/'. $filename . '.' . $tmppath['extension'];
549 // Renames temp file on server.
550 rename($tmp, $new);
551 // Push new filename (in path) to be used in file array later.
552 $tmp = $new;
553 }
554 /* Assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). */
555 // Full server path to temp file.
556 $file_array['tmp_name'] = $tmp;
557 if ( !empty( $filename ) ) {
558 // User given filename for title, add original URL extension.
559 $file_array['name'] = $filename . '.' . $url_type['ext'];
560 } else {
561 // Just use original URL filename.
562 $file_array['name'] = $url_filename;
563 }
564 $post_data = array(
565 // Just use the original filename (no extension).
566 'post_title' => get_the_title( $post_id ),
567 // Make sure gets tied to parent.
568 'post_parent' => $post_id,
569 );
570 // Required libraries for media_handle_sideload.
571 require_once( ABSPATH . 'wp-admin/includes/file.php' );
572 require_once( ABSPATH . 'wp-admin/includes/media.php' );
573 require_once( ABSPATH . 'wp-admin/includes/image.php' );
574 // Do the validation and storage stuff.
575 // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status.
576 $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
577 // If error storing permanently, unlink.
578 if ( is_wp_error( $att_id ) ) {
579 // Clean up.
580 @unlink( $file_array['tmp_name'] );
581 // And output wp_error.
582 return $att_id;
583 }
584 return $att_id;
585}
586
587
588/* Add Support for Allowing Users to Receive Comment Notifications Left on Their Posts. Note: This includes all post types. */
589class BDBP_Blog_Comment_Notifier {
590 private static $instance;
591 private $id = 'blog_comment_notifier';
592 private function __construct() {
593 $this->setup();
594 }
595 public static function get_instance() {
596 if ( ! isset( self::$instance ) ) {
597 self::$instance = new self();
598 }
599 return self::$instance;
600 }
601 public function setup() {
602 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ) );
603 //On New comment
604 add_action( 'comment_post', array( $this, 'comment_posted' ), 15, 2 );
605 //on delete post, we should delete all notifications for the comment on that post
606 //add_action( 'delete_post', array( $this, 'post_deleted' ), 10, 2 );
607 // Monitor actions on existing comments
608 add_action( 'deleted_comment', array( $this, 'comment_deleted' ) );
609 //add_action( 'trashed_comment', array( $this, 'comment_deleted' ) );
610 //add_action( 'spam_comment', array( $this, 'comment_deleted' ) );
611 //should we do something on the action untrash_comment & unspam_comment
612 add_action( 'wp_set_comment_status', array( $this, 'comment_status_changed' ) );
613 // Load plugin text domain
614 add_action( 'bp_init', array( $this, 'load_textdomain' ) );
615 add_action( 'template_redirect', array( $this, 'mark_read' ) );
616 }
617 public function load_textdomain() {
618 load_plugin_textdomain( 'bp-notify-post-author-on-blog-comment', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
619 }
620 public function setup_globals() {
621 if ( ! defined( 'BD_BLOG_NOTIFIER_SLUG' ) ) {
622 define( 'BD_BLOG_NOTIFIER_SLUG', 'bd-blog-notifier' );
623 }
624 $bp = buddypress();
625 $bp->blog_comment_notifier = new stdClass();
626 $bp->blog_comment_notifier->id = $this->id;//I asume others are not going to use this is
627 $bp->blog_comment_notifier->slug = BD_BLOG_NOTIFIER_SLUG;
628 $bp->blog_comment_notifier->notification_callback = array( $this, 'format_notifications' );//show the notification
629 $bp->active_components[ $bp->blog_comment_notifier->id ] = $bp->blog_comment_notifier->id;
630 do_action( 'blog_comment_notifier_setup_globals' );
631 }
632 public function comment_posted( $comment_id = 0, $comment_status = 0 ) {
633 if ( ! $this->is_bp_active() ) {
634 return ;
635 }
636 $comment = get_comment( $comment_id );
637 if ( empty( $comment ) || $comment->comment_approved == 'spam' ) {
638 return ;
639 }
640 if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
641 return ;
642 }
643 $post_id = $comment->comment_post_ID;
644 $post = get_post( $post_id );
645 if ( $post->post_author == $comment->user_id ) {
646 return ;
647 }
648 if ( ! user_can( $post->post_author, 'moderate_comments' ) && $comment->comment_approved == 0 ) {
649 return;
650 }
651 $this->notify( $post->post_author, $comment );
652 }
653 public function comment_status_changed( $comment_id = 0, $comment_status = 0 ) {
654 if ( ! $this->is_bp_active() ) {
655 return ;
656 }
657 $comment = get_comment( $comment_id );
658 if ( empty( $comment ) ) {
659 return ;
660 }
661 if ( $comment->comment_approved == 'spam' || $comment->comment_approve == 'trash' ) {
662 if ( $this->is_notified( $comment_id ) ) {
663 $this->comment_deleted( $comment_id );
664 }
665 return;
666 }
667 if ( $comment->comment_approve == 0 && $this->is_notified( $comment_id ) ) {
668 $this->comment_deleted( $comment_id );
669 return ;
670 }
671 if ( $comment->comment_approve == 1 ) {
672 $post = get_post( $comment->comment_post_ID );
673 if ( get_current_user_id() == $post->post_author ) {
674 if ( $this->is_notified( $comment_id ) ) {
675 $this->comment_deleted ( $comment_id );
676 }
677 return ;
678 } else {
679 $this->notify( $post->post_author, $comment );
680 }
681 }
682 }
683 public function comment_deleted( $comment_id ) {
684 if ( ! $this->is_bp_active() ) {
685 return;
686 }
687 bp_notifications_delete_all_notifications_by_type( $comment_id, $this->id );
688 $this->unmark_notified( $comment_id );
689 }
690 public function format_notifications( $action, $comment_id, $secondary_item_id, $total_items, $format = 'string', $notification_id = 0 ) {
691 $bp = buddypress();
692 $switched = false;
693 $blog_id = bp_notifications_get_meta( $notification_id, '_blog_id' );
694 if ( $blog_id && get_current_blog_id() != $blog_id ) {
695 switch_to_blog( $blog_id );
696 $switched = true;
697 }
698 $comment = get_comment( $comment_id );
699 $post = get_post( $comment->comment_post_ID);
700 $link = $text = $name = $post_title = $comment_content ='';
701 if ( $comment->user_id ) {
702 $name = bp_core_get_user_displayname ( $comment->user_id );
703 } else {
704 $name = $comment->comment_author;
705 }
706 $post_title = $post->post_title;
707 $comment_content = wp_trim_words( $comment->comment_content, 12, ' ...' );
708 $text = sprintf(
709 __( '%s commented on <strong>%s</strong>: <em>%s</em>', 'bp-notify-post-author-on-blog-comment' ),
710 $name,
711 $post_title,
712 $comment_content
713 );
714 if ( $comment->comment_approved == 1 ) {
715 $link = get_comment_link ( $comment );
716 } else {
717 $link =admin_url( 'comment.php?action=approve&c=' . $comment_id );
718 }
719 if( $switched ) {
720 restore_current_blog();
721 }
722 if ( $format == 'string' ) {
723 return apply_filters( 'bp_blog_notieifier_new_comment_notification_string', '<a href="' . $link . '">' . $text . '</a>' );
724 }else{
725 return array(
726 'link' => $link,
727 'text' => $text);
728 }
729 return false;
730 }
731 public function is_bp_active() {
732 if ( function_exists( 'buddypress' ) ) {
733 return true;
734 }
735 return false;
736 }
737 public function is_notified( $comment_id ) {
738 return get_comment_meta( $comment_id, 'bd_post_author_notified', true );
739 }
740 public function mark_notified( $comment_id ) {
741 update_comment_meta( $comment_id, 'bd_post_author_notified', 1 );
742 }
743 public function unmark_notified( $comment_id ) {
744 delete_comment_meta( $comment_id, 'bd_post_author_notified' );
745 }
746 public function notify( $user_id, $comment ) {
747 $comment_id = $comment->comment_ID;
748 $notificatin_id = bp_notifications_add_notification( array(
749 'item_id' => $comment_id,
750 'user_id' => $user_id,
751 'component_name' => $this->id,
752 'component_action' => 'new_blog_comment_'. $comment_id,
753 'secondary_item_id' => $comment->comment_post_ID,
754 ));
755 if ( $notificatin_id && is_multisite() ) {
756 bp_notifications_add_meta( $notificatin_id, '_blog_id', get_current_blog_id() );
757 }
758 $this->mark_notified( $comment_id );
759 }
760 public function mark_read() {
761 if ( ! $this->is_bp_active() || ! is_singular() ) {
762 return ;
763 }
764 $post_id = get_queried_object_id();
765 if ( ! $post_id ) {
766 return ;
767 }
768 return BP_Notifications_Notification::update(
769 array( 'is_new' => 0 ),
770 array( 'secondary_item_id' => $post_id,
771 'component_name' => $this->id,
772 'user_id' => get_current_user_id(),
773 )
774 );
775 }
776}
777BDBP_Blog_Comment_Notifier::get_instance();
778
779
780/* Hide the "Add Friend" Button on All of the Following User's Profiles Who have the Following Member Types so that They Cannot Be Added as a Friend, or Be Sent a Friend Request by All Other Users */
781function millionairesdigest_hide_add_friend_button( $button ) {
782 $displayed_user_id = bp_displayed_user_id();
783 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
784 $member_type = bp_get_member_type( $user_id );
785 // Do Not Display the "Add Friend" Button for the Following Member Types
786 $not_in = array( 'brand', 'famous-people', 'organization' );
787 if ( ! in_array( $member_type, $not_in, true ) ) {
788 return $button;
789 }
790 return '';
791}
792add_filter('bp_get_add_friend_button', 'millionairesdigest_hide_add_friend_button');
793
794
795/* Hide the "Add Friend" Button for All of the Following Logged-In Users who have the Following Member Types so that They Cannot Add Any Users as "Friends" to Their Account */
796function md_hide_add_friend_button( $button ) {
797 if ( is_super_admin() ) {
798 return $button;
799 }
800 $displayed_user_id = bp_loggedin_user_id();
801 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
802 $member_type = bp_get_member_type( $user_id );
803 // Do Not Display the "Add Friend" Button for the Following Member Types
804 $not_in = array( 'brand', 'famous-person', 'organization' );
805 if ( ! in_array( $member_type, $not_in, true ) ) {
806 return $button;
807 }
808 return '';
809}
810add_filter('bp_get_add_friend_button', 'md_hide_add_friend_button');
811
812
813/* Hide the "Follow" Button on All of the Displayed User's Profiles Who have the Following Member Types so that They Cannot and Do Not Have Followers for Their Account */
814function millionairesdigest_hide_add_follow_button( $button ) {
815 $displayed_user_id = bp_displayed_user_id();
816 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
817 $member_type = bp_get_member_type( $user_id );
818 // Do Not Display the "Follow" Button for the Following Member Types
819 $not_in = array( 'user' );
820 if ( ! in_array( $member_type, $not_in, true ) ) {
821 return $button;
822 }
823 return '';
824}
825add_filter('bp_follow_get_add_follow_button', 'millionairesdigest_hide_add_follow_button');
826
827
828/* Hide the Profile Subnav Tab "Mutual Friends" for All of the Logged-In "Brands" and "Organizations" Member Type Users who are On or Viewing a User's Profile (or Anybody's Profile), so that the "Mutual Friends" Tab Does Not Show for Them */
829function millionairesdigest_remove_mutual_friends() {
830 if ( is_super_admin() ) {
831 return;
832 }
833 if ( ! bp_is_user() ) {
834 return;
835 }
836 $user_id = bp_loggedin_user_id();
837 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'famous-person' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) ) {
838 bp_core_remove_nav_item( 'mutual-friends' );
839 }
840}
841add_action( 'bp_setup_nav', 'millionairesdigest_remove_mutual_friends', 1001 );
842
843
844/* Hide the Profile Subnav Tab "Mutual Friends" on All of the Displayed "Brands" and "Organizations" Profiles that Any Logged in User is Viewing, so that the "Mutual Friends" Tab Does Not Show */
845function millionairedigest_remove_mutual_friends() {
846 if ( is_super_admin() ) {
847 return;
848 }
849 if ( ! bp_is_user() ) {
850 return;
851 }
852 $user_id = bp_displayed_user_id();
853 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'famous-person' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) ) {
854 bp_core_remove_nav_item( 'mutual-friends' );
855 }
856}
857add_action( 'bp_setup_nav', 'millionairedigest_remove_mutual_friends', 1001 );
858
859
860/* Hide the Profile Subnav Tab "Followers" on All of the User's Profiles Except for the Users Who have the Following Member Types so that the Followers Tab Does Not Show */
861function millionairesdigest_remove_followers() {
862 if ( ! bp_is_user() ) {
863 return;
864 }
865 $user_id = bp_displayed_user_id();
866 if ( ! bp_has_member_type( $user_id, 'brand' ) && ( ! bp_has_member_type( $user_id, 'famous-person' ) && ( ! bp_has_member_type( $user_id, 'organization' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) ) ) {
867 bp_core_remove_nav_item( 'followers' );
868 }
869}
870add_action( 'bp_setup_nav', 'millionairesdigest_remove_followers', 1001 );
871
872
873/* Hide the Profile Subnav Tab "Friends" on All of the Displayed "Brands," "Organizations," and "Famous Peoples" Accounts, so that the "Friends" Tab Does Not Show */
874function millionairedigest_remove_friends() {
875 if ( is_super_admin() ) {
876 return;
877 }
878 if ( ! bp_is_user() ) {
879 return;
880 }
881 $user_id = bp_displayed_user_id();
882 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) {
883 bp_core_remove_nav_item( 'friends' );
884 }
885}
886add_action( 'bp_setup_nav', 'millionairedigest_remove_friends', 1001 );
887
888
889
890/* Add a Profile Nav Tab "Articles" to User's Profiles so That When They Write and Publish Them, They Can See All of the Articles They've Written, as Well as Show Others the Articles They've Written as Well. And Note: This does not include being added to the backend dashboad admin bar as you would still need to write out that function if you would like to include that. */
891function add_profile_articles_tab() {
892 global $bp;
893 $post_count_query = new WP_Query(
894 array(
895 'author' => bp_displayed_user_id(),
896 'post_type' => 'article',
897 'posts_per_page' => 1,
898 'post_status' => 'publish'
899 ) );
900 $profile_articles_post_count = $post_count_query->found_posts;
901 wp_reset_postdata();
902//Add Menu Item
903$nav_item = array(
904 'name' => apply_filters( 'profile_articles_blog_name',sprintf( __( 'Articles <span class="count">%s</span>', 'bp-user-blog' ),
905 $profile_articles_post_count )),
906 'slug' => 'articles',
907 'default_subnav_slug' => 'articles',
908 'screen_function' => 'profile_articles',
909 'position' => 60,
910 'item_css_id' => 'profile-articles',
911);
912 bp_core_new_nav_item($nav_item);
913}
914add_action( 'bp_setup_nav', 'add_profile_articles_tab', 1000 );
915//Add Support for Content
916function profile_articles() {
917 add_action( 'bp_template_title', 'profile_articles_title' );
918 add_action( 'bp_template_content', 'profile_articles_content' );
919 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
920}
921//Add Title
922function profile_articles_title() {
923 echo 'Articles';
924}
925//Add Content
926function profile_articles_content() {
927 echo do_shortcode( '[activity-stream title=0 pagination=1 for=displayed action=new_article]' );
928}
929
930
931/* Add a Profile Nav Tab "Videos" to User's Profiles so That When They Upload and Share Them, They Can See All of the Videos They've Uploaded, as Well as Show Others the Videos They've Uploaded as Well. And Note: This does not include being added to the backend dashboad admin bar as you would still need to write out that function if you would like to include that. */
932function add_profile_videos_tab() {
933 global $bp;
934 $post_count_query = new WP_Query(
935 array(
936 'author' => bp_displayed_user_id(),
937 'post_type' => 'video',
938 'posts_per_page' => 1,
939 'post_status' => 'publish'
940 ) );
941 $profile_videos_post_count = $post_count_query->found_posts;
942 wp_reset_postdata();
943//Add Menu Item
944$nav_item = array(
945 'name' => apply_filters( 'profile_videos_blog_name',sprintf( __( 'Videos <span class="count">%s</span>', 'bp-user-blog' ),
946 $profile_videos_post_count )),
947 'slug' => 'videos',
948 'default_subnav_slug' => 'videos',
949 'screen_function' => 'profile_videos',
950 'position' => 70,
951 'item_css_id' => 'profile-videos',
952);
953 bp_core_new_nav_item($nav_item);
954}
955add_action( 'bp_setup_nav', 'add_profile_videos_tab', 1000 );
956//Add Support for Content
957function profile_videos() {
958 add_action( 'bp_template_title', 'profile_videos_title' );
959 add_action( 'bp_template_content', 'profile_videos_content' );
960 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
961}
962//Add Title
963function profile_videos_title() {
964 echo 'Videos';
965}
966//Add Content
967function profile_videos_content() {
968 echo do_shortcode( '[activity-stream title=0 pagination=1 for=displayed action=new_video]' );
969}
970
971
972/* Add a Profile Nav Tab "Photos" to User's Profiles so That When They Upload and Share Them, They Can See All of the Photos They've Uploaded, as Well as Show Others the Photos They've Uploaded as Well. And Note: This does not include being added to the backend dashboad admin bar as you would still need to write out that function if you would like to include that. */
973function add_profile_photos_tab() {
974 global $bp;
975 $post_count_query = new WP_Query(
976 array(
977 'author' => bp_displayed_user_id(),
978 'post_type' => 'photo',
979 'posts_per_page' => 1,
980 'post_status' => 'publish'
981 ) );
982 $profile_photos_post_count = $post_count_query->found_posts;
983 wp_reset_postdata();
984//Add Menu Item
985$nav_item = array(
986 'name' => apply_filters( 'profile_photos_blog_name',sprintf( __( 'Photos <span class="count">%s</span>', 'bp-user-blog' ),
987 $profile_photos_post_count )),
988 'slug' => 'photos',
989 'default_subnav_slug' => 'photos',
990 'screen_function' => 'profile_photos',
991 'position' => 80,
992 'item_css_id' => 'profile-photos',
993);
994 bp_core_new_nav_item($nav_item);
995}
996add_action( 'bp_setup_nav', 'add_profile_photos_tab', 1000 );
997//Add Support for Content
998function profile_photos() {
999 add_action( 'bp_template_title', 'profile_photos_title' );
1000 add_action( 'bp_template_content', 'profile_photos_content' );
1001 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1002}
1003//Add Title
1004function profile_photos_title() {
1005 echo 'Photos';
1006}
1007//Add Content
1008function profile_photos_content() {
1009 echo do_shortcode( '[activity-stream title=0 pagination=1 for=displayed action=new_photo]' );
1010}
1011
1012
1013/* Add a Profile Nav Tab "Music" to User's Profiles so That When They Upload and Share Them, They Can See All of the Songs They've Uploaded, as Well as Show Others the Songs They've Uploaded as Well. And Note: This does not include being added to the backend dashboad admin bar as you would still need to write out that function if you would like to include that. */
1014function add_profile_music_tab() {
1015 global $bp;
1016 $post_count_query = new WP_Query(
1017 array(
1018 'author' => bp_displayed_user_id(),
1019 'post_type' => 'audio',
1020 'posts_per_page' => 1,
1021 'post_status' => 'publish'
1022 ) );
1023 $profile_music_post_count = $post_count_query->found_posts;
1024 wp_reset_postdata();
1025//Add Menu Item
1026$nav_item = array(
1027 'name' => apply_filters( 'profile_music_blog_name',sprintf( __( 'Music <span class="count">%s</span>', 'bp-user-blog' ),
1028 $profile_music_post_count )),
1029 'slug' => 'music',
1030 'default_subnav_slug' => 'music',
1031 'screen_function' => 'profile_music',
1032 'position' => 90,
1033 'item_css_id' => 'profile-music',
1034);
1035 bp_core_new_nav_item($nav_item);
1036}
1037add_action( 'bp_setup_nav', 'add_profile_music_tab', 1000 );
1038//Add Support for Content
1039function profile_music() {
1040 add_action( 'bp_template_title', 'profile_music_title' );
1041 add_action( 'bp_template_content', 'profile_music_content' );
1042 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1043}
1044//Add Title
1045function profile_music_title() {
1046 echo 'Music';
1047}
1048//Add Content
1049function profile_music_content() {
1050 echo do_shortcode( '[activity-stream title=0 pagination=1 for=displayed action=new_audio]' );
1051}
1052
1053
1054/* Add a "Brands I've Added to My Feed" Widget to All User's Profiles */
1055class BP_Brands_Following_Widget extends WP_Widget {
1056 function __construct() {
1057 // Set up optional widget args.
1058 $widget_ops = array(
1059 'classname' => 'widget_bp_brands_following_widget widget buddypress',
1060 'description' => __( "Show a list of brand accounts that the displayed user has added to their feed.", 'buddypress-followers' )
1061 );
1062 // Set up the widget.
1063 parent::__construct(
1064 false,
1065 __( "(BP Follow) Brands I've Added to My Feeds", 'buddypress-followers' ),
1066 $widget_ops
1067 );
1068 }
1069 //Displays the widget.
1070 function widget( $args, $instance, $member_args ) {
1071 if ( empty( $instance['max_users'] ) ) {
1072 $instance['max_users'] = 16;
1073 }
1074 // If the displayed user hasn't added any brand accounts, then hide the widget.
1075 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1076 return false;
1077 }
1078 // If the displayed user has added brand accounts to their feed, then show the profile photos of the brand accounts.
1079 if ( bp_has_members( array(
1080 'include' => $following,
1081 'max' => $instance['max_users'],
1082 'populate_extras' => false,
1083 'type' => 'active',
1084 'member_type' => 'brand'
1085 ) ) ) {
1086 do_action( 'bp_before_following_widget' );
1087 echo $args['before_widget'];
1088 echo $args['before_title']
1089 . $instance['title']
1090 . $args['after_title'];
1091 ?>
1092 <div class="avatar-block">
1093 <?php while ( bp_members() ) : bp_the_member(); ?>
1094 <div class="item-avatar">
1095 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1096 </div>
1097 <?php endwhile; ?>
1098 </div>
1099 <?php echo $args['after_widget']; ?>
1100 <?php do_action( 'bp_after_following_widget' ); ?>
1101 <?php
1102 }
1103 }
1104 //Callback to save widget settings.
1105 function update( $new_instance, $old_instance ) {
1106 $instance = $old_instance;
1107 $instance['title'] = strip_tags( $new_instance['title'] );
1108 $instance['max_users'] = (int) $new_instance['max_users'];
1109 return $instance;
1110 }
1111 //Widget settings form.
1112 function form( $instance ) {
1113 $instance = wp_parse_args( (array) $instance, array(
1114 'title' => __( "Brand Accounts I've Added to My Feeds", 'buddypress-followers' ),
1115 'max_users' => 16
1116 ) );
1117 ?>
1118 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1119 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
1120 <p><label for="bp-follow-widget-users-max"><?php _e('Max members to show:', 'buddypress-followers'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo esc_attr( (int) $instance['max_users'] ); ?>" style="width: 30%" /></label></p>
1121 <p><small><?php _e( 'Note: This widget will only be displayed if the displayed user has added at least one brand account to their feeds.', 'buddypress-followers' ); ?></small></p>
1122 <?php
1123 }
1124}
1125add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Brands_Following_Widget");' ) );
1126
1127
1128/* Add a "Famous People I've Added to My Feed" Widget to All User's Profiles */
1129class BP_Famous_People_Following_Widget extends WP_Widget {
1130 function __construct() {
1131 // Set up optional widget args.
1132 $widget_ops = array(
1133 'classname' => 'widget_bp_famous_people_following_widget widget buddypress',
1134 'description' => __( "Show a list of famous people accounts that the displayed user has added to their feed.", 'buddypress-followers' )
1135 );
1136 // Set up the widget.
1137 parent::__construct(
1138 false,
1139 __( "(BP Follow) Famous People I've Added to My Feeds", 'buddypress-followers' ),
1140 $widget_ops
1141 );
1142 }
1143 //Displays the widget.
1144 function widget( $args, $instance, $member_args ) {
1145 if ( empty( $instance['max_users'] ) ) {
1146 $instance['max_users'] = 16;
1147 }
1148 // If the displayed user hasn't added any famous people accounts, then hide the widget.
1149 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1150 return false;
1151 }
1152 // If the displayed user has added famous people accounts to their feed, then show the profile photos of the famous people accounts.
1153 if ( bp_has_members( array(
1154 'include' => $following,
1155 'max' => $instance['max_users'],
1156 'populate_extras' => false,
1157 'type' => 'active',
1158 'member_type' => 'famous-person'
1159 ) ) ) {
1160 do_action( 'bp_before_following_widget' );
1161 echo $args['before_widget'];
1162 echo $args['before_title']
1163 . $instance['title']
1164 . $args['after_title'];
1165 ?>
1166 <div class="avatar-block">
1167 <?php while ( bp_members() ) : bp_the_member(); ?>
1168 <div class="item-avatar">
1169 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1170 </div>
1171 <?php endwhile; ?>
1172 </div>
1173 <?php echo $args['after_widget']; ?>
1174 <?php do_action( 'bp_after_following_widget' ); ?>
1175 <?php
1176 }
1177 }
1178 //Callback to save widget settings.
1179 function update( $new_instance, $old_instance ) {
1180 $instance = $old_instance;
1181 $instance['title'] = strip_tags( $new_instance['title'] );
1182 $instance['max_users'] = (int) $new_instance['max_users'];
1183 return $instance;
1184 }
1185 //Widget settings form.
1186 function form( $instance ) {
1187 $instance = wp_parse_args( (array) $instance, array(
1188 'title' => __( "Famous People Accounts I've Added to My Feeds", 'buddypress-followers' ),
1189 'max_users' => 16
1190 ) );
1191 ?>
1192 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1193 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
1194 <p><label for="bp-follow-widget-users-max"><?php _e('Max members to show:', 'buddypress-followers'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo esc_attr( (int) $instance['max_users'] ); ?>" style="width: 30%" /></label></p>
1195 <p><small><?php _e( 'Note: This widget will only be displayed if the displayed user has added at least one famous person to their feeds.', 'buddypress-followers' ); ?></small></p>
1196 <?php
1197 }
1198}
1199add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Famous_People_Following_Widget");' ) );
1200
1201
1202/* Add an "Organizations I've Added to My Feed" Widget to All User's Profiles */
1203class BP_Organizations_Following_Widget extends WP_Widget {
1204 function __construct() {
1205 // Set up optional widget args.
1206 $widget_ops = array(
1207 'classname' => 'widget_bp_organizations_following_widget widget buddypress',
1208 'description' => __( "Show a list of organization accounts that the displayed user has added to their feed.", 'buddypress-followers' )
1209 );
1210 // Set up the widget.
1211 parent::__construct(
1212 false,
1213 __( "(BP Follow) Organizations I've Added to My Feeds", 'buddypress-followers' ),
1214 $widget_ops
1215 );
1216 }
1217 //Displays the widget.
1218 function widget( $args, $instance, $member_args ) {
1219 if ( empty( $instance['max_users'] ) ) {
1220 $instance['max_users'] = 16;
1221 }
1222 // If the displayed user hasn't added any organization accounts, then hide the widget.
1223 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1224 return false;
1225 }
1226 // If the displayed user has added organization accounts to their feed, then show the profile photos of the organization accounts.
1227 if ( bp_has_members( array(
1228 'include' => $following,
1229 'max' => $instance['max_users'],
1230 'populate_extras' => false,
1231 'type' => 'active',
1232 'member_type' => 'organization'
1233 ) ) ) {
1234 do_action( 'bp_before_following_widget' );
1235 echo $args['before_widget'];
1236 echo $args['before_title']
1237 . $instance['title']
1238 . $args['after_title'];
1239 ?>
1240 <div class="avatar-block">
1241 <?php while ( bp_members() ) : bp_the_member(); ?>
1242 <div class="item-avatar">
1243 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1244 </div>
1245 <?php endwhile; ?>
1246 </div>
1247 <?php echo $args['after_widget']; ?>
1248 <?php do_action( 'bp_after_following_widget' ); ?>
1249 <?php
1250 }
1251 }
1252 //Callback to save widget settings.
1253 function update( $new_instance, $old_instance ) {
1254 $instance = $old_instance;
1255 $instance['title'] = strip_tags( $new_instance['title'] );
1256 $instance['max_users'] = (int) $new_instance['max_users'];
1257 return $instance;
1258 }
1259 //Widget settings form.
1260 function form( $instance ) {
1261 $instance = wp_parse_args( (array) $instance, array(
1262 'title' => __( "Organization Accounts I've Added to My Feeds", 'buddypress-followers' ),
1263 'max_users' => 16
1264 ) );
1265 ?>
1266 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1267 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
1268 <p><label for="bp-follow-widget-users-max"><?php _e('Max members to show:', 'buddypress-followers'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo esc_attr( (int) $instance['max_users'] ); ?>" style="width: 30%" /></label></p>
1269 <p><small><?php _e( 'Note: This widget will only be displayed if the displayed user has added at least one organization account to their feeds.', 'buddypress-followers' ); ?></small></p>
1270 <?php
1271 }
1272}
1273add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Organizations_Following_Widget");' ) );
1274
1275
1276/* Add a "Millionaire's Digest Accounts I've Added to My Feed" Widget to All User's Profiles */
1277class BP_Millionaires_Digest_Following_Widget extends WP_Widget {
1278 function __construct() {
1279 // Set up optional widget args.
1280 $widget_ops = array(
1281 'classname' => 'widget_bp_millionaires_digest_following_widget widget buddypress',
1282 'description' => __( "Show a list of Millionaire's Digest accounts that the displayed user has added to their feed.", 'buddypress-followers' )
1283 );
1284 // Set up the widget.
1285 parent::__construct(
1286 false,
1287 __( "(BP Follow) Millionaire's Digest Accounts I've Added to My Feeds", 'buddypress-followers' ),
1288 $widget_ops
1289 );
1290 }
1291 //Displays the widget.
1292 function widget( $args, $instance, $member_args ) {
1293 if ( empty( $instance['max_users'] ) ) {
1294 $instance['max_users'] = 16;
1295 }
1296 // If the displayed user hasn't added any brand accounts, then hide the widget.
1297 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1298 return false;
1299 }
1300 // If the displayed user has added Millionaire's Digest accounts to their feed, then show the profile photos of the Millionaire's Digest accounts.
1301 if ( bp_has_members( array(
1302 'include' => $following,
1303 'max' => $instance['max_users'],
1304 'populate_extras' => false,
1305 'type' => 'active',
1306 'member_type' => 'millionaires-digest'
1307 ) ) ) {
1308 do_action( 'bp_before_following_widget' );
1309 echo $args['before_widget'];
1310 echo $args['before_title']
1311 . $instance['title']
1312 . $args['after_title'];
1313 ?>
1314 <div class="avatar-block">
1315 <?php while ( bp_members() ) : bp_the_member(); ?>
1316 <div class="item-avatar">
1317 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1318 </div>
1319 <?php endwhile; ?>
1320 </div>
1321 <?php echo $args['after_widget']; ?>
1322 <?php do_action( 'bp_after_following_widget' ); ?>
1323 <?php
1324 }
1325 }
1326 //Callback to save widget settings.
1327 function update( $new_instance, $old_instance ) {
1328 $instance = $old_instance;
1329 $instance['title'] = strip_tags( $new_instance['title'] );
1330 $instance['max_users'] = (int) $new_instance['max_users'];
1331 return $instance;
1332 }
1333 //Widget settings form.
1334 function form( $instance ) {
1335 $instance = wp_parse_args( (array) $instance, array(
1336 'title' => __( "Millionaire's Digest Accounts I've Added to My Feeds", 'buddypress-followers' ),
1337 'max_users' => 16
1338 ) );
1339 ?>
1340 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1341 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
1342 <p><label for="bp-follow-widget-users-max"><?php _e('Max members to show:', 'buddypress-followers'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo esc_attr( (int) $instance['max_users'] ); ?>" style="width: 30%" /></label></p>
1343 <p><small><?php _e( 'Note: This widget will only be displayed if the displayed user has added at least one Millionaires Digest account to their feeds.', 'buddypress-followers' ); ?></small></p>
1344 <?php
1345 }
1346}
1347add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Millionaires_Digest_Following_Widget");' ) );
1348
1349
1350/* Hide All of the Following Profile Nav Tabs on ALL Users Profiles That Way It is Less Confusing to All of Our Users as We have Added them in Other Places That They Can Access and Find Them */
1351function millionairesdigest_hide_profile_nav_tabs() {
1352 global $bp;
1353 if ( bp_is_user() && !is_super_admin() ) {
1354 unset($bp->bp_nav['settings']);
1355 unset($bp->bp_nav['messages']);
1356 unset($bp->bp_nav['notifications']);
1357 unset($bp->bp_nav['checkin']);
1358 unset($bp->bp_nav['following']);
1359 unset($bp->bp_nav['profile-privacy']);
1360 unset($bp->bp_options_nav['activity']['following']);
1361 unset($bp->bp_options_nav['activity']['news-feed']);
1362 }
1363}
1364add_action('bp_setup_nav', 'millionairesdigest_hide_profile_nav_tabs', 201);
1365
1366
1367/* Completely Remove All of the Following Profile Nav Tabs so That Any Logged Out Users Cannot See nor Access the Users Pesonal Links/Tabs (And Note: This is Purposely Added to Allow and Give Our Users More Privacy from the People Outside of Our Site Who Really Don't have Any Business Seeing What it is They have Posted in the First Place.) */
1368function millionairesdigest_remove_profile_nav_tabs() {
1369 if( bp_is_active( 'xprofile' ) ) :
1370 if ( bp_is_user() && !is_user_logged_in() ) {
1371 bp_core_remove_nav_item( 'checkin' );
1372 bp_core_remove_subnav_item( 'activity', 'following' );
1373 bp_core_remove_subnav_item( 'activity', 'news-feed' );
1374 }
1375 endif;
1376}
1377add_action( 'bp_setup_nav', 'millionairesdigest_remove_profile_nav_tabs', 15 );
1378
1379
1380/* Remove/Hide the Prices for ALL the Free Magazines and Magazine Subscriptions (And Note: Keep in Mind that We Can Use a Stategy Here Where, Instead of Listing and Saying to Everyone that Our Magazine is Free (Because in reality, it really is not), We Can Show Them the Original Price, but Say, "Paid For by the Millionaire's Digest Founder & CEO.") */
1381function wholeseller_role_cat( $q ) {
1382
1383 // Get the current user
1384 $current_user = wp_get_current_user();
1385
1386 // Displaying only "Wholesale" category products to "whole seller" user role
1387 if ( in_array( 'author', $current_user->roles ) ) {
1388 // Set here the ID for Wholesale category
1389 $q->set( 'tax_query', array(
1390 array(
1391 'taxonomy' => 'product_cat',
1392 'field' => 'term_id',
1393 'terms' => '586965239', // your category ID
1394 )
1395 ) );
1396
1397 // Displaying All products (except "Wholesale" category products)
1398 // to all other users roles (except "wholeseller" user role)
1399 // and to non logged user.
1400 } else {
1401 // Set here the ID for Wholesale category
1402 $q->set( 'tax_query', array(
1403 array(
1404 'taxonomy' => 'product_cat',
1405 'field' => 'term_id',
1406 'terms' => '586965239', // your category ID
1407 'operator' => 'NOT IN'
1408 )
1409 ) );
1410 }
1411}
1412add_action( 'woocommerce_product_query', 'wholeseller_role_cat' );
1413
1414
1415/* Change the "Proceed To Checkout" Button Text */
1416function woocommerce_button_proceed_to_checkout() {
1417 $checkout_url = WC()->cart->get_checkout_url();
1418 ?>
1419 <a href="<?php echo $checkout_url; ?>" class="checkout-button button alt wc-forward"><?php _e( 'Check On Out', 'woocommerce' ); ?></a>
1420 <?php
1421 }
1422
1423
1424/* Remove/Hide the Prices for ALL the Free Magazines and Magazine Subscriptions (And Note: Keep in Mind that We Can Use a Stategy Here Where, Instead of Listing and Saying to Everyone that Our Magazine is Free (Because in reality, it really is not), We Can Show Them the Original Price, but Say, "Paid For by the Millionaire's Digest Founder & CEO.") */
1425add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
1426 if ( is_admin() ) return $price;
1427 // Hide for these category slugs / IDs
1428 $hide_for_categories = array( '586965238', 'free-magazine-subscription' );
1429 // Don't show price when its in one of the categories
1430 if ( has_term( $hide_for_categories, 'product_cat', $product->get_id() ) ) {
1431 return '';
1432 }
1433 return $price; // Return original price
1434}, 10, 2 );
1435add_filter( 'woocommerce_cart_item_price', '__return_false' );
1436add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
1437
1438
1439/* Remove the "Related Products" Area After the Single Magazine Pages */
1440remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 10 );
1441
1442
1443/* Remove/Hide the Prices for ALL Types of Magazines and Magazine Subsciptions for the Following Roles (And Note: When on the Checkout Page, This Does Not Hide the Prices There, so if You Want to Hide Them There Also, Then You'll Need to Add Another Function or CSS.) */
1444add_filter( 'woocommerce_get_price_html', function( $price ) {
1445 if ( is_admin() ) return $price;
1446 $user = wp_get_current_user();
1447 $hide_for_roles = array( 'author', 'contributor', 'editor' );
1448 // If one of the user roles is in the list of roles to hide for.
1449 if ( array_intersect( $user->roles, $hide_for_roles ) ) {
1450 return ''; // Return empty string to hide.
1451 }
1452 return $price; // Return original price
1453} );
1454add_filter( 'woocommerce_cart_item_price', '__return_false' );
1455add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
1456
1457
1458/* Remove WooCommerce Quanity Field (And Note: Keep In Mind that if You Plan on Selling These to Businesses with the Option of Bulk Buying, We Need to Set This Up to Where It's Only Visible to These Roles/Account Types Only) */
1459function wc_remove_all_quantity_fields( $return, $product ) {
1460 return true;
1461}
1462add_filter( 'woocommerce_is_sold_individually', 'wc_remove_all_quantity_fields', 10, 2 );
1463
1464
1465/* Remove Jetpack Related Posts on Custom Post Type "Products" and on the Custom Post Type's Single Page */
1466function millionairesdigest_jetpack_archive_no_related_posts( $options ) {
1467 if ( is_post_type_archive( 'product' ) ) {
1468 $options['enabled'] = false;
1469 }
1470 return $options;
1471}
1472add_filter( 'jetpack_relatedposts_filter_options', 'millionairesdigest_jetpack_archive_no_related_posts' );
1473function millionairesdigest_jetpack_singular_no_related_posts( $options ) {
1474 if ( is_singular( 'product' ) ) {
1475 $options['enabled'] = false;
1476 }
1477 return $options;
1478}
1479add_filter( 'jetpack_relatedposts_filter_options', 'millionairesdigest_jetpack_singular_no_related_posts' );
1480
1481
1482/* Add an Extended Widget's Option on ALL Widgets for Giving Us the Ability to Choose Whether or Not to Hide or Display the Widget(s) Based on the Current BuddyPress Group, Profile, or BuddyPress Page a User is Viewing */
1483function bpew_load(){
1484 // Display our own fields
1485 add_action('in_widget_form', 'bpew_extend_form', 10, 3);
1486 // Save our new things
1487 add_filter('widget_update_callback', 'bpew_extend_update', 10, 4);
1488 // Display content if needed
1489 add_filter('widget_display_callback', 'bpew_extend_display', 10, 3);
1490}
1491function bpew_extend_form($class, $return, $instance){
1492 echo '<hr /><p>'.__('Display the widget if it satisfies one or more of the BuddyPress-specific options below:','bpew').'</p>';
1493 if(!isset($instance['bp_component_type']))
1494 $instance['bp_component_type'] = '';
1495 if(!isset($instance['bp_component_ids']))
1496 $instance['bp_component_ids'] = '';
1497 echo '<p>
1498 <input '.checked($instance['bp_component_type'], '', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value=""/> '.__('Do not apply', 'bpew').'<br />
1499 <input '.checked($instance['bp_component_type'], 'member_typea', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typea"/> '.__('Member Type: User', 'bpew').'<br />
1500 <input '.checked($instance['bp_component_type'], 'member_typeb', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typeb"/> '.__('Member Type: Brand', 'bpew').'<br />
1501 <input '.checked($instance['bp_component_type'], 'member_typec', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typec"/> '.__('Member Type: Famous Person', 'bpew').'<br />
1502 <input '.checked($instance['bp_component_type'], 'member_typed', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typed"/> '.__('Member Type: Organization', 'bpew').'<br />
1503 <input '.checked($instance['bp_component_type'], 'member_typee', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typee"/> '.__('Member Type: Millonaires Digest', 'bpew').'<br />
1504 <input '.checked($instance['bp_component_type'], 'member_typef', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="member_typef"/> '.__('Member Type: Government', 'bpew').'<br />
1505 <input '.checked($instance['bp_component_type'], 'members', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="members"/> '.__('Members (Single)', 'bpew').'<br />
1506 <input '.checked($instance['bp_component_type'], 'members_dir', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="members_dir"/> '.__('Members Directory', 'bpew').'<br />
1507 <input '.checked($instance['bp_component_type'], 'groups', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="groups"/> '.__('Groups (Single)', 'bpew').'<br />
1508 <input '.checked($instance['bp_component_type'], 'groups_dir', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="groups_dir"/> '.__('Groups Directory', 'bpew').'
1509 </p>';
1510 echo '<p>
1511 <label id="'.$class->get_field_id('bp_component_ids').'">'.__('IDs','bpew').':</label>
1512 <input id="'.$class->get_field_id('bp_component_ids').'" type="text" name="'.$class->get_field_name('bp_component_ids').'" value="'.$instance['bp_component_ids'].'"/><br />
1513 <span class="description">'.__('Use commas to separate; No spaces.','bpew').'</span>
1514 </p>';
1515 add_action('bpew_extend_form', $class, $return, $instance);
1516 return $return;
1517}
1518function bpew_extend_update($instance, $new_instance, $old_instance, $this){
1519 $new_instance = apply_filters('bpew_extend_update', $new_instance, $old_instance, $instance, $this);
1520 return $new_instance;
1521}
1522function bpew_extend_display($instance, $this, $args){
1523 if(empty($instance['bp_component_type']))
1524 return $instance;
1525 global $bp;
1526 $user_id = bp_displayed_user_id();
1527 // Display on profile pages with the "User" member type
1528 if($instance['bp_component_type'] == 'member_typea' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'user' )
1529 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1530 return $instance;
1531 }
1532 // Display on profile pages with the "Brand" member type
1533 if($instance['bp_component_type'] == 'member_typeb' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'brand' )
1534 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1535 return $instance;
1536 }
1537 // Display on profile pages with the "Famous Person" member type
1538 if($instance['bp_component_type'] == 'member_typec' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'famous-person' )
1539 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1540 return $instance;
1541 }
1542 // Display on profile pages with the "Organization" member type
1543 if($instance['bp_component_type'] == 'member_typed' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'organization' )
1544 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1545 return $instance;
1546 }
1547 // Display on profile pages with the "Millionaire's Digest" member type
1548 if($instance['bp_component_type'] == 'member_typee' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'millionaires-digest' )
1549 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1550 return $instance;
1551 }
1552 // Display on profile pages with the "Government" member type
1553 if($instance['bp_component_type'] == 'member_typef' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'government' )
1554 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1555 return $instance;
1556 }
1557 // Display on specific profile pages
1558 if($instance['bp_component_type'] == 'members' && bp_displayed_user_id()
1559 && in_array(bp_displayed_user_id(), explode(',', $instance['bp_component_ids']))){
1560 return $instance;
1561 }
1562 if($instance['bp_component_type'] == 'members_dir' && bp_is_directory() && bp_current_component() == BP_MEMBERS_SLUG){
1563 return $instance;
1564 }
1565 // Display on groups pages only
1566 $group_id = $bp->groups->current_group->id;
1567 if($instance['bp_component_type'] == 'groups' && !empty($group_id)
1568 && in_array($group_id, explode(',', str_replace(' ', '', trim($instance['bp_component_ids']))))){
1569 return $instance;
1570 }
1571 if($instance['bp_component_type'] == 'groups_dir' && bp_is_directory() && bp_current_component() == BP_GROUPS_SLUG){
1572 return $instance;
1573 }
1574 return false;
1575}
1576add_action('bp_init', 'bpew_load');
1577
1578
1579/* Add a "BuddyPress Total Friends Count" Widget */
1580class Total_Friends_Widget extends WP_Widget {
1581 public function __construct() {
1582 $widget_ops = array('classname' => 'Total_Friends_Widget', 'description' => 'Display the total number of friends a user has on their profile.' );
1583 $this->WP_Widget('Total_Friends_Widget', 'BuddyPress Total Friends Count', $widget_ops);
1584 }
1585 function widget($args, $instance) {
1586 // PART 1: Extracting the arguments + getting the values
1587 extract($args, EXTR_SKIP);
1588 $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
1589 $text = empty($instance['text']) ? '' : $instance['text'];
1590 // Before widget code, if any
1591 echo (isset($before_widget)?$before_widget:'');
1592 // PART 2: The title and the text output
1593 if (!empty($title))
1594 echo $before_title . $title . $after_title;;
1595 if (!empty($text))
1596 $count = friends_get_friend_count_for_user( bp_displayed_user_id() );
1597 echo '<h4/>' . $count . ' '. $text . '<h4/>';
1598 // After widget code, if any
1599 echo (isset($after_widget)?$after_widget:'');
1600 }
1601 public function form( $instance ) {
1602 // PART 1: Extract the data from the instance variable
1603 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
1604 $title = $instance['title'];
1605 $text = $instance['text'];
1606 // PART 2-3: Display the fields
1607 ?>
1608 <!-- PART 2: Widget Title field START -->
1609 <p>
1610 <label for="<?php echo $this->get_field_id('title'); ?>">Title:
1611 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
1612 name="<?php echo $this->get_field_name('title'); ?>" type="text"
1613 value="<?php echo attribute_escape($title); ?>" />
1614 </label>
1615 </p>
1616 <!-- Widget Title field END -->
1617 <!-- PART 3: Widget Text field START -->
1618 <p>
1619 <label for="<?php echo $this->get_field_id('text'); ?>">Label:
1620 <input class="widefat" id="<?php echo $this->get_field_id('text'); ?>"
1621 name="<?php echo $this->get_field_name('text'); ?>" type="text"
1622 value="<?php echo attribute_escape($text); ?>" />
1623 </label>
1624 </p>
1625 <!-- Widget Text field END -->
1626 <?php
1627 }
1628 function update($new_instance, $old_instance) {
1629 $instance = $old_instance;
1630 $instance['title'] = $new_instance['title'];
1631 $instance['text'] = $new_instance['text'];
1632 return $instance;
1633 }
1634}
1635add_action( 'widgets_init', create_function('', 'return register_widget("Total_Friends_Widget");') );
1636
1637
1638/* Add a "BuddyPress Total Followers Count" Widget */
1639class Total_Followers_Widget extends WP_Widget {
1640 public function __construct() {
1641 $widget_ops = array('classname' => 'Total_Followers_Widget', 'description' => 'Display the total number of followers a user has on their profile.' );
1642 $this->WP_Widget('Total_Followers_Widget', 'BuddyPress Total Followers Count', $widget_ops);
1643 }
1644 function widget($args, $instance) {
1645 // PART 1: Extracting the arguments + getting the values
1646 extract($args, EXTR_SKIP);
1647 $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
1648 $text = empty($instance['text']) ? '' : $instance['text'];
1649 // Before widget code, if any
1650 echo (isset($before_widget)?$before_widget:'');
1651 // PART 2: The title and the text output
1652 if (!empty($title))
1653 echo $before_title . $title . $after_title;;
1654 if (!empty($text))
1655 $count = bp_follow_total_follow_counts( array(
1656 'user_id' =>bp_displayed_user_id() ) );
1657 echo '<h4/>' . $count['followers'] . ' '. $text . '<h4/>';
1658 // After widget code, if any
1659 echo (isset($after_widget)?$after_widget:'');
1660 }
1661 public function form( $instance ) {
1662 // PART 1: Extract the data from the instance variable
1663 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
1664 $title = $instance['title'];
1665 $text = $instance['text'];
1666 // PART 2-3: Display the fields
1667 ?>
1668 <!-- PART 2: Widget Title field START -->
1669 <p>
1670 <label for="<?php echo $this->get_field_id('title'); ?>">Title:
1671 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
1672 name="<?php echo $this->get_field_name('title'); ?>" type="text"
1673 value="<?php echo attribute_escape($title); ?>" />
1674 </label>
1675 </p>
1676 <!-- Widget Title field END -->
1677 <!-- PART 3: Widget Text field START -->
1678 <p>
1679 <label for="<?php echo $this->get_field_id('text'); ?>">Label:
1680 <input class="widefat" id="<?php echo $this->get_field_id('text'); ?>"
1681 name="<?php echo $this->get_field_name('text'); ?>" type="text"
1682 value="<?php echo attribute_escape($text); ?>" />
1683 </label>
1684 </p>
1685 <!-- Widget Text field END -->
1686 <?php
1687 }
1688 function update($new_instance, $old_instance) {
1689 $instance = $old_instance;
1690 $instance['title'] = $new_instance['title'];
1691 $instance['text'] = $new_instance['text'];
1692 return $instance;
1693 }
1694}
1695add_action( 'widgets_init', create_function('', 'return register_widget("Total_Followers_Widget");') );
1696
1697
1698/* Add BuddyPress Profile Fields to Member Directoy (And Note: This Right Here is Going to Be One of the Most Powerful & Strongest Strategies for Beating All the Other Social Networking Sites and Getting People to Love Our Site More Over Theirs, so Make It the Best You Can, and Don't Screw It Up! ) */
1699//Add the "About Me Bio" Profile Field to the Member Directoy
1700function my_directory() {
1701if ( bp_is_active( 'xprofile' ) )
1702 if ( $aboutme = xprofile_get_field_data( 'About Me', bp_get_member_user_id() ) ) :
1703 echo '<br/><div class="About_Me">';
1704 echo $aboutme;
1705 echo '</div>';
1706 endif;
1707}
1708add_filter ( 'bp_directory_members_item', 'my_directory' );
1709
1710
1711/* Add a BuddyPess Profile Fields Widget for Allowing Us to Display User's Profile Fields as a Widget */
1712class BPDev_BPProfile_Widget extends WP_Widget {
1713 public function __construct() {
1714 parent::__construct( false, $name = __( 'BuddyPress User Info', 'bp-profile-widget-for-blogs' ) );
1715 }
1716 public function widget( $args, $instance ) {
1717 echo $before_widget;
1718 echo $before_title
1719 . $instance['title']
1720 . $after_title;
1721 self::show_blog_profile( $instance );
1722 echo $after_widget;
1723 }
1724 public function update( $new_instance, $old_instance ) {
1725 $instance = $old_instance;
1726 foreach ( $new_instance as $key => $val ) {
1727 $instance[ $key ] = $val;//update the instance
1728 }
1729 return $instance;
1730 }
1731 public function form( $instance ) {
1732 $instance = wp_parse_args( (array) $instance, array(
1733 'title' => __( '', 'bp-profile-widget-for-blogs' )
1734 ) );
1735 $title = strip_tags( $instance['title'] );
1736 extract( $instance, EXTR_SKIP );
1737 ?>
1738 <p>
1739 <label for="bpdev-widget-title">
1740 <?php _e( 'Title:', 'bp-profile-widget-for-blogs' ); ?>
1741 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( stripslashes( $title ) ); ?>"/>
1742 </label>
1743 </p>
1744 <?php
1745 //get all xprofile fields and ask user whether to show them or not
1746 ?>
1747 <h3><?php _e( 'Profile Fields Visibility', 'bp-profile-widget-for-blogs' ); ?></h3>
1748 <table>
1749 <?php if ( function_exists( 'bp_has_profile' ) ) : if ( bp_has_profile() ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
1750 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
1751 <?php $fld_name = bp_get_the_profile_field_input_name();
1752 $fld_val = isset( ${$fld_name} ) ? ${$fld_name} : 'no';
1753 ?>
1754 <tr>
1755 <td>
1756 <label for="<?php echo $fld_name; ?>"><?php bp_the_profile_field_name() ?></label>
1757 </td>
1758 <td>
1759 <input type="radio" id="<?php echo $this->get_field_id( $fld_name ); ?>" name="<?php echo $this->get_field_name( $fld_name ); ?>" value="yes" <?php checked( $fld_val, 'yes' ); ?> >Show
1760 <input type="radio" id="<?php echo $this->get_field_id( $fld_name ); ?>" name="<?php echo $this->get_field_name( $fld_name ); ?>" value="no" <?php checked( $fld_val, 'no' ); ?>>Hide
1761 </td>
1762 </tr>
1763 <?php endwhile;
1764 endwhile;
1765 endif;
1766 endif; ?>
1767 </table>
1768 <?php
1769 }
1770 public static function get_users( $user_role = null ) {
1771 $bp_displayed_user_id = bp_displayed_user_id();
1772 return $bp_displayed_user_id;
1773 }
1774 public static function show_blog_profile( $instance ) {
1775 //if buddypress is not active, return
1776 if ( ! function_exists( 'buddypress' ) ) {
1777 return;
1778 }
1779 unset( $instance['title'] );//unset the title of the widget,because we will be iterating over the instance fields
1780 if ( bp_is_user() ) {
1781 $bp_displayed_user_id = array( bp_displayed_user_id() );
1782 }
1783 if ( empty( $bp_displayed_user_id ) ) {
1784 return;
1785 //Do not display the widget if profile field is empty
1786 }
1787 foreach ( $bp_displayed_user_id as $user ) {
1788 $user_id = $user;//["user_id"];
1789 $op = "<table class='my-blog-profile bp-blog-user-profile bp-blog-user-profile-{$user}'>";
1790 //bad approach, because buddypress does not allow to fetch the field name from field key
1791 if ( function_exists( 'bp_has_profile' ) ) :
1792 if ( bp_has_profile( 'user_id=' . $user_id ) ) :
1793 while ( bp_profile_groups() ) : bp_the_profile_group();
1794 while ( bp_profile_fields() ) : bp_the_profile_field();
1795 $fld_name = bp_get_the_profile_field_input_name();
1796 if ( array_key_exists( $fld_name, $instance ) && $instance[ $fld_name ] == 'yes' ) {
1797 $op .= '<tr><h4>' . bp_get_the_profile_field_name() . '</h4><p>' .xprofile_get_field_data( bp_get_the_profile_field_id(),$user_id, 'comma' ) . '</p></tr>';
1798 }
1799 endwhile;
1800 endwhile;
1801 endif;
1802 endif;
1803 $op .= "</table>";
1804 echo $op;
1805 }
1806 }
1807}
1808/** Let us register the widget*/
1809function bpdev_register_bpprofile_for_blogs_widgets() {
1810 register_widget( 'BPDev_BPProfile_Widget' );
1811}
1812add_action( 'bp_widgets_init', 'bpdev_register_bpprofile_for_blogs_widgets' );
1813
1814
1815
1816/* Redirect All New Users, Writers, and Company Members Based on Each Role to Their Following Welcome Pages I Specifically Created for Them, After They Confirm/Log into Their Account for the First Time (And Note: For Brands, Organizations, Famous People, Etc. Type of Accounts, The Roles are Still Not Synced with Their Member Type, so Keep This in Mind. Also, When it Comes to "Platform Authors," We Need a Seperate Redirect Because the Only Way Anyone Becomes an Author is After They've Been a Contributor, and Since They Would Have Already Logged In and Had Activity from Their Account After Updating Their Role, We Would Need a Seperate Rediect or Message of Some Kind That Let's Them Know About the Page We Created for Them that Allows Them to Know All the Cool Features We Have for Them and That They Have Access to. */
1817function millionairesdigest_redirect_on_first_login( $url, $request, $user ) {
1818 $last_activity = bp_get_user_last_activity( $user->ID );
1819 if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
1820 if( $user->has_cap( 'user' ) && empty( $last_activity ) ) {
1821 $url = home_url('/users-welcome-page/');
1822 } else {
1823 if( $user->has_cap( 'contributor' ) && empty( $last_activity ) ) {
1824 $url = home_url('/welcome-contributors-page/');
1825 } else {
1826 if( $user->has_cap( 'author' ) && empty( $last_activity ) ) {
1827 $url = home_url('/welcome-authors-page/');
1828 } else {
1829 if( $user->has_cap( 'editor' ) && empty( $last_activity ) ) {
1830 $url = home_url('/welcome-editor-page/');
1831 } else {
1832 if( $user->has_cap( 'photographer' ) && empty( $last_activity ) ) {
1833 $url = home_url('/welcome-photographers-page/');
1834 } else {
1835 if( $user->has_cap( 'publisher' ) && empty( $last_activity ) ) {
1836 $url = home_url('/welcome-publishers-page/');
1837 } else {
1838 if( $user->has_cap( 'magazine-author' ) && empty( $last_activity ) ) {
1839 $url = home_url('/welcome-magazine-authors-page/');
1840 } else {
1841 if( $user->has_cap( 'magazine-editor' ) && empty( $last_activity ) ) {
1842 $url = home_url('/welcome-magazine-editors-page/');
1843 } else {
1844 if( $user->has_cap( 'magazine-photographer' ) && empty( $last_activity ) ) {
1845 $url = home_url('/welcome-magazine-photographers-page/');
1846 } else {
1847 if( $user->has_cap( 'magazine-designer' ) && empty( $last_activity ) ) {
1848 $url = home_url('/welcome-magazine-designers-page/');
1849 } else {
1850 if( $user->has_cap( 'magazine-publisher' ) && empty( $last_activity ) ) {
1851 $url = home_url('/welcome-magazine-publishers-page/');
1852 } else {
1853 if( $user->has_cap( 'brand-account' ) && empty( $last_activity ) ) {
1854 $url = home_url('/welcome-brand-accounts-page/');
1855 } else {
1856 if( $user->has_cap( 'famous-person-account' ) && empty( $last_activity ) ) {
1857 $url = home_url('/welcome-famous-people-accounts-page/');
1858 } else {
1859 if( $user->has_cap( 'organization-account' ) && empty( $last_activity ) ) {
1860 $url = home_url('/welcome-organization-accounts-page/');
1861 } else {
1862 $url = home_url('/activity-wall/');
1863 }
1864 }
1865 }
1866 }
1867 }
1868 }
1869 }
1870 }
1871 }
1872 }
1873 }
1874 }
1875 }
1876 }
1877 }
1878 return $url;
1879}
1880add_filter('login_redirect', 'millionairesdigest_redirect_on_first_login', 10, 3 );
1881
1882
1883/* Redirect All Logouts to the Login/Home Page (And Note: When Hovering Over the Logout Button, It Still Shows the Original WordPress Redirect Link in the Link Itself, So Keep This in Mind as We Still Need to Fix This) */
1884add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();' ) );
1885
1886
1887/* Automatically Set Everybody Who Creates an Account Through the "Create an Account" Page to the Member Type "User" Once They Activate Their Account and Log In for the First Time */
1888function set_default_member_type( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
1889 bp_set_member_type( $user_id, 'user' );
1890}
1891add_action( 'bp_core_signup_user', 'set_default_member_type', 10, 5 );
1892
1893
1894/* Add a Profile Nav Tab Called "Platform Writers" to the Millionaire's Digest Profile ONLY */
1895function add_platform_writers_tab() {
1896 global $bp;
1897 bp_core_new_nav_item( array(
1898 'name' => 'Platform Writers',
1899 'slug' => 'platform-writers',
1900 'parent_url' => $bp->displayed_user->domain,
1901 'parent_slug' => $bp->profile->slug,
1902 'screen_function' => 'platform_writers_screen',
1903 'position' => 40,
1904 'default_subnav_slug' => 'writers'
1905 ) );
1906 bp_core_new_subnav_item( array(
1907 'name' => 'All',
1908 'slug' => 'all',
1909 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
1910 'parent_slug' => 'platform-writers',
1911 'screen_function' => 'platform_writers_all_screen',
1912 'position' => 10,
1913 'user_has_access' => bp_is_my_profile()
1914 ) );
1915 bp_core_new_subnav_item( array(
1916 'name' => 'Authors',
1917 'slug' => 'authors',
1918 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
1919 'parent_slug' => 'platform-writers',
1920 'screen_function' => 'platform_writers_authors_screen',
1921 'position' => 20,
1922 'user_has_access' => bp_is_my_profile()
1923 ) );
1924}
1925add_action( 'bp_setup_nav', 'add_platform_writers_tab', 100 );
1926function platform_writers_screen() {
1927 add_action( 'bp_template_title', 'platform_writers_screen_title' );
1928 add_action( 'bp_template_content', 'platform_writers_screen_content' );
1929 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1930}
1931function platform_writers_screen_title() {
1932 echo '<h4>Platform Writers</h4>';
1933}
1934function platform_writers_screen_content() {
1935 echo do_shortcode( '[members-listing include_member_role="author,contributor"]' );
1936}
1937function platform_writers_all_screen() {
1938 add_action( 'bp_template_title', 'platform_writers_all_screen_title' );
1939 add_action( 'bp_template_content', 'platform_writers_all_screen_content' );
1940 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1941}
1942function platform_writers_all_screen_title() {
1943 echo '<h4>All Platform Writers</h4>';
1944}
1945function platform_writers_all_screen_content() {
1946 echo do_shortcode( '[members-listing include_member_role="author,contributor"]' );
1947}
1948function platform_writers_authors_screen() {
1949 add_action( 'bp_template_content', 'platform_writers_authors_screen_title' );
1950 add_action( 'bp_template_content', 'platform_writers_authors_screen_content' );
1951 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1952}
1953function platform_writers_authors_screen_title() {
1954 echo '<h4>Authors</h4>';
1955}
1956function platform_writers_authors_screen_content() {
1957 echo do_shortcode( '[members-listing include_member_role="author"]' );
1958}
1959
1960
1961/* Add a Profile Nav Tab Called "Magazine Writers" to the Millionaire's Digest Profile ONLY */
1962function add_magazine_writers_tab() {
1963 global $bp;
1964 bp_core_new_nav_item( array(
1965 'name' => 'Magazine Writers',
1966 'slug' => 'magazine-writers',
1967 'parent_url' => $bp->displayed_user->domain,
1968 'parent_slug' => $bp->profile->slug,
1969 'screen_function' => 'magazine_writers_screen',
1970 'position' => 50,
1971 'default_subnav_slug' => 'writers'
1972 ) );
1973 bp_core_new_subnav_item( array(
1974 'name' => 'All',
1975 'slug' => 'all',
1976 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'magazine-writers' ),
1977 'parent_slug' => 'magazine-writers',
1978 'screen_function' => 'magazine_writers_all_screen',
1979 'position' => 10,
1980 'user_has_access' => bp_is_my_profile()
1981 ) );
1982 bp_core_new_subnav_item( array(
1983 'name' => 'Authors',
1984 'slug' => 'authors',
1985 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
1986 'parent_slug' => 'magazine-writers',
1987 'screen_function' => 'magazine_writers_authors_screen',
1988 'position' => 20,
1989 'user_has_access' => bp_is_my_profile()
1990 ) );
1991}
1992add_action( 'bp_setup_nav', 'add_magazine_writers_tab', 100 );
1993function magazine_writers_screen() {
1994 add_action( 'bp_template_title', 'magazine_writers_screen_title' );
1995 add_action( 'bp_template_content', 'magazine_writers_screen_content' );
1996 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1997}
1998function magazine_writers_screen_title() {
1999 echo '<h4>Magazine Writers</h4>';
2000}
2001function magazine_writers_screen_content() {
2002 echo do_shortcode( '[members-listing include_member_role="magazine-author"]' );
2003}
2004function magazine_writers_all_screen() {
2005 add_action( 'bp_template_title', 'magazine_writers_all_screen_title' );
2006 add_action( 'bp_template_content', 'magazine_writers_all_screen_content' );
2007 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
2008}
2009function magazine_writers_all_screen_title() {
2010 echo '<h4>All Magazine Writers</h4>';
2011}
2012function magazine_writers_all_screen_content() {
2013 echo do_shortcode( '[members-listing include_member_role="magazine-author"]' );
2014}
2015function magazine_writers_authors_screen() {
2016 add_action( 'bp_template_content', 'magazine_writers_authors_screen_title' );
2017 add_action( 'bp_template_content', 'magazine_writers_authors_screen_content' );
2018 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
2019}
2020function magazine_writers_authors_screen_title() {
2021 echo '<h4>Authors</h4>';
2022}
2023function magazine_writers_authors_screen_content() {
2024 echo do_shortcode( '[members-listing include_member_role="author"]' );
2025}
2026
2027
2028/* Now that We've Created the Profile Nav Tabs "Platform Writers" and "Magazine Writers," Only Allow It to Be Displayed on the Millionaire's Digest Profile ONLY */
2029function millionairedigest_remove_platform_writers_tab() {
2030 if ( bp_displayed_user_id() == 1 ) {
2031 return;
2032 }
2033 bp_core_remove_nav_item( 'platform-writers' );
2034 bp_core_remove_nav_item( 'magazine-writers' );
2035}
2036add_action( 'bp_setup_nav', 'millionairedigest_remove_magazine_writers_tab', 1001 );
2037
2038
2039/* Auto Join All New Team & Company Members to Groups Based on Their Role After Creating Their Account and Logging in for the First Time */
2040function auto_join_contributors_to_groups( $user_id, $role, $old_roles ) {
2041 if( $role == 'contributor' ) {
2042 groups_accept_invite( $user_id, 1 );
2043 groups_accept_invite( $user_id, 11 );
2044 groups_accept_invite( $user_id, 12 );
2045 }
2046}
2047add_action( 'set_user_role', 'auto_join_contributors_to_groups', 11, 3 );
2048function auto_join_photographers_to_groups( $user_id, $role, $old_roles ) {
2049 if( $role == 'photographer' ) {
2050 groups_accept_invite( $user_id, 2 );
2051 groups_accept_invite( $user_id, 11 );
2052 groups_accept_invite( $user_id, 12 );
2053 }
2054}
2055add_action( 'set_user_role', 'auto_join_photographers_to_groups', 11, 3 );
2056function auto_join_authors_to_groups( $user_id, $role, $old_roles ) {
2057 if( $role == 'author' ) {
2058 groups_accept_invite( $user_id, 3 );
2059 groups_accept_invite( $user_id, 11 );
2060 groups_accept_invite( $user_id, 12 );
2061 }
2062}
2063add_action( 'set_user_role', 'auto_join_authors_to_groups', 11, 3 );
2064function auto_join_editors_to_groups( $user_id, $role, $old_roles ) {
2065 if( $role == 'editor' ) {
2066 groups_accept_invite( $user_id, 4 );
2067 groups_accept_invite( $user_id, 11 );
2068 groups_accept_invite( $user_id, 12 );
2069 }
2070}
2071add_action( 'set_user_role', 'auto_join_editors_to_groups', 11, 3 );
2072function auto_join_publishers_to_groups( $user_id, $role, $old_roles ) {
2073 if( $role == 'publisher' ) {
2074 groups_accept_invite( $user_id, 5 );
2075 groups_accept_invite( $user_id, 11 );
2076 groups_accept_invite( $user_id, 12 );
2077 }
2078}
2079add_action( 'set_user_role', 'auto_join_publishers_to_groups', 11, 3 );
2080function auto_join_magazine_authors_to_groups( $user_id, $role, $old_roles ) {
2081 if( $role == 'magazine-author' ) {
2082 groups_accept_invite( $user_id, 6 );
2083 groups_accept_invite( $user_id, 11 );
2084 groups_accept_invite( $user_id, 13 );
2085 }
2086}
2087add_action( 'set_user_role', 'auto_join_magazine_authors_to_groups', 11, 3 );
2088function auto_join_magazine_photographers_to_groups( $user_id, $role, $old_roles ) {
2089 if( $role == 'magazine-photographer' ) {
2090 groups_accept_invite( $user_id, 7 );
2091 groups_accept_invite( $user_id, 11 );
2092 groups_accept_invite( $user_id, 13 );
2093 }
2094}
2095add_action( 'set_user_role', 'auto_join_magazine_photographers_to_groups', 11, 3 );
2096function auto_join_magazine_editors_to_groups( $user_id, $role, $old_roles ) {
2097 if( $role == 'magazine-editor' ) {
2098 groups_accept_invite( $user_id, 8 );
2099 groups_accept_invite( $user_id, 11 );
2100 groups_accept_invite( $user_id, 13 );
2101 }
2102}
2103add_action( 'set_user_role', 'auto_join_magazine_editors_to_groups', 11, 3 );
2104function auto_join_magazine_designers_to_groups( $user_id, $role, $old_roles ) {
2105 if( $role == 'magazine-designer' ) {
2106 groups_accept_invite( $user_id, 9 );
2107 groups_accept_invite( $user_id, 11 );
2108 groups_accept_invite( $user_id, 13 );
2109 }
2110}
2111add_action( 'set_user_role', 'auto_join_magazine_designers_to_groups', 11, 3 );
2112function auto_join_magazine_publishers_to_groups( $user_id, $role, $old_roles ) {
2113 if( $role == 'magazine-publisher' ) {
2114 groups_accept_invite( $user_id, 10 );
2115 groups_accept_invite( $user_id, 11 );
2116 groups_accept_invite( $user_id, 13 );
2117 }
2118}
2119add_action( 'set_user_role', 'auto_join_magazine_publishers_to_groups', 11, 3 );
2120
2121
2122/* Redirect Any and All Logged Out Users Who Try to Access the Member Directory Page to the Homepage as the Memeber Directory Isn't Something That People Should Be Able to Access Freely Because It Gives People the Ability to See Eveyone and Eveything When the Point of the Member Directory is to Give People the Power to Find Friends & Matches Based on Their Pofile */
2123function bpfr_guest_redirect() {
2124 global $bp;
2125 // Enter the slug or component conditional here
2126 if ( bp_is_members_directory() ) {
2127 // Not logged in user are redirected to - comment/uncomment or add/remove to your need
2128 if( !is_user_logged_in() ) {
2129 wp_redirect( get_option('siteurl') ); //back to homepage
2130 }
2131 }
2132}
2133add_filter( 'get_header', 'bpfr_guest_redirect', 1 );
2134
2135
2136/* Rename All of the Following Subnav Tabs in User's Messages */
2137function change_profile_submenu_tabs(){
2138 global $bp;
2139 $bp->bp_options_nav['messages']['inbox']['name'] = 'All Messages';
2140 $bp->bp_options_nav['messages']['starred']['name'] = 'Liked Messages';
2141 $bp->bp_options_nav['messages']['sentbox']['name'] = 'Sent Messages';
2142 $bp->bp_options_nav['messages']['compose']['name'] = 'New Message';
2143
2144}
2145add_action('bp_setup_nav', 'change_profile_submenu_tabs', 999);
2146
2147
2148/* Remove the "Sent" Messages Subnav Tab in Users Profiles as It is Not Neccessary and Helps Keep the Inbox More Clear for Our Users */
2149function md_remove_sent_messages_subnav_tab() {
2150 if ( is_super_admin() ) {
2151 return;
2152 }
2153 global $bp;
2154 if ( $bp->current_component == $bp->messages->slug ) {
2155 bp_core_remove_subnav_item( $bp->messages->slug, 'sentbox' );
2156 }
2157}
2158add_action( 'wp', 'md_remove_sent_messages_subnav_tab', 2 );
2159
2160
2161/* Add the "Matchmaker Bio" Profile Field to Users Profiles in the Member Directory for the Purpose of Giving People the Ability to Connect More */
2162function show_extra_profile_fields_in_members_directory() {
2163 $bio = bp_get_member_profile_data('field=Bio');
2164 if ($bio) {
2165 echo '<div class="mdetcenter">'. $bio . '</div>';
2166 }
2167}
2168add_action('bp_directory_members_item', 'show_extra_profile_fields_in_members_directory');
2169
2170
2171/* Disable the WYSIWYG Editor From User's Profile Fields */
2172function bp_disable_richtext($enabled, $field_id) {
2173 $enabled = false;
2174 return $enabled;
2175}
2176add_filter('bp_xprofile_is_richtext_enabled_for_field', 'bp_disable_richtext', 10, 2);