· 8 years ago · Mar 16, 2018, 06:18 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
1700//Add the "About Me Bio" Profile Field to the Member Directoy
1701function my_directory() {
1702if ( bp_is_active( 'xprofile' ) )
1703 if ( $aboutme = xprofile_get_field_data( 'About Me', bp_get_member_user_id() ) ) :
1704 echo '<br/><div class="About_Me">';
1705 echo $aboutme;
1706 echo '</div>';
1707 endif;
1708}
1709add_filter ( 'bp_directory_members_item', 'my_directory' );
1710
1711
1712
1713/* 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 */
1714
1715
1716class BuddyPress_Profile_Field_Widget extends WP_Widget {
1717/* Sets up the widgets name etc */
1718 public function __construct() {
1719 $widget_ops = array('classname' => 'BuddyPress_Profile_Field_Widget', 'description' => 'Display any profile field if on a users profile as a widget.' );
1720 $this->WP_Widget('BuddyPress_Profile_Field_Widget', 'BuddyPress Profile Field Widget', $widget_ops);
1721 }
1722 //Outputs the content of the widget
1723 public function widget( $args, $instance ) {
1724 extract( $args );
1725 echo $before_widget;
1726 echo $before_title
1727 . $instance['title']
1728 . $after_title;
1729 self::show_blog_profile( $instance );
1730 echo $after_widget;
1731 }
1732 //Ouputs the options form on admin
1733 public function form( $instance ) {
1734 $instance = wp_parse_args( (array) $instance, array(
1735 'title' => __( '', 'bp-profile-widget-for-blogs' ),
1736 'show_avatar' => 'no',
1737 'user_role' => 'loggedin'
1738 ) );
1739 $title = strip_tags( $instance['title'] );
1740 extract( $instance, EXTR_SKIP );
1741 ?>
1742<p>
1743 <label for="bpdev-widget-title">
1744 <?php _e( 'Title:', 'bp-profile-widget-for-blogs' ); ?>
1745 <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 ) ); ?>"/>
1746 </label>
1747</p>
1748<p>
1749 <label for="bpdev-widget-role">
1750 <?php _e( 'List profiles for:', 'bp-profile-widget-for-blogs' ); ?>
1751 <select id="<?php echo $this->get_field_id( 'user_role' ); ?>"
1752 name="<?php echo $this->get_field_name( 'user_role' ); ?>">
1753 <?php wp_dropdown_roles( $user_role ); ?>
1754 <option value="loggedin" <?php selected( $user_role, 'loggedin' ); ?>><?php _e( 'Displayed User', 'bp-profile-widget-for-blogs' ); ?></option>
1755 </select>
1756 </label>
1757</p>
1758<p>
1759 <label for="bpdev-widget-show-avatar"><?php _e( 'Show Avatar', 'bp-profile-widget-for-blogs' ); ?>
1760 <input type="radio" id="<?php echo $this->get_field_id( 'show_avatar' ); ?>" name="<?php echo $this->get_field_name( 'show_avatar' ); ?>" value="yes" <?php checked( $show_avatar, 'yes' ); ?>>Yes
1761 <input type="radio" id="<?php echo $this->get_field_id( 'show_avatar' ); ?>" name="<?php echo $this->get_field_name( 'show_avatar' ); ?>" value="no" <?php checked( $show_avatar, 'no' ); ?>>No
1762 </label>
1763</p>
1764<?php
1765 //get all xprofile fields and ask user whether to show them or not
1766 //?>
1767<h3><?php _e( 'Profile Fields Visibility', 'bp-profile-widget-for-blogs' ); ?></h3>
1768<table>
1769 <?php if ( function_exists( 'bp_has_profile' ) ) : if ( bp_has_profile() ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
1770 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
1771 <?php $fld_name = bp_get_the_profile_field_input_name();
1772 $fld_val = isset( ${$fld_name} ) ? ${$fld_name} : 'no';
1773 ?>
1774 <tr>
1775 <p>
1776 <label for="<?php echo $fld_name; ?>"><?php bp_the_profile_field_name() ?></label>
1777 </p>
1778 <p>
1779 <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
1780 <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
1781 </p>
1782 </tr>
1783 <?php endwhile;
1784 endwhile;
1785 endif;
1786 endif;
1787 ?>
1788</table>
1789<?php
1790 }
1791 public static function get_users( $user_role = null ) {
1792 $users = get_users( array( 'role' => $user_role, 'blog_id' => get_current_blog_id(), 'fields' => 'ID' ) );
1793 return $users;
1794 }
1795 public static function show_blog_profile( $instance ) {
1796 //if buddypress is not active, return
1797 if ( ! function_exists( 'buddypress' ) ) {
1798 return;
1799 }
1800 $show_avatar = $instance['show_avatar'];//we need to preserve for multi admin
1801 $user_role = $instance['user_role'];
1802 unset( $instance['show_avatar'] );
1803 unset( $instance['title'] );//unset the title of the widget,because we will be iterating over the instance fields
1804 unset( $instance['user_role'] );//unset the title of the widget,because we will be iterating over the instance fields
1805 if ( $user_role == 'loggedin' ) {
1806 $users = array( bp_displayed_user_id() );
1807 } else {
1808 $users = apply_filters( 'bp_blog_profile_for_users', self::get_users( $user_role ) );//may be we can improve it too
1809 }
1810 if ( empty( $users ) ) {
1811 return;
1812 }
1813 foreach ( $users as $user ) {
1814 echo $args[ 'before_widget' ];
1815 if ( empty( $user_id ) )
1816 echo $args['before_title'] . $title . $args['after_title'];
1817 $user_id = $user;//["user_id"];
1818 $op = "<div class='my-blog-profile bp-blog-user-profile bp-blog-user-profile-{$user}'>";
1819 if ( $show_avatar == 'yes' ) {
1820 $op .= "<tr class='user-avatar'>";
1821 $op .= "<p>" . bp_core_get_userlink( $user_id ) . "</p>";
1822 $op .= "<p>" . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb' ) ) . "</p>";
1823 $op .= "</tr>";
1824 }
1825 //bad approach, because buddypress does not allow to fetch the field name from field key
1826 if ( function_exists( 'bp_has_profile' ) ) :
1827 if ( bp_has_profile( 'user_id=' . $user_id ) ) :
1828 while ( bp_profile_groups() ) : bp_the_profile_group();
1829 while ( bp_profile_fields() ) : bp_the_profile_field();
1830 $fld_name = bp_get_the_profile_field_input_name();
1831 if ( array_key_exists( $fld_name, $instance ) && $instance[ $fld_name ] == 'yes' ) {
1832 $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>';
1833 }
1834 endwhile;
1835 endwhile;
1836 endif;
1837 endif;
1838 $op .= "</div>";
1839 echo $op;
1840 }
1841 }
1842 //Process widget to save options
1843 public function update( $new_instance, $old_instance ) {
1844 $instance = $old_instance;
1845 foreach ( $new_instance as $key => $val ) {
1846 $instance[ $key ] = $val;//update the instance
1847 }
1848 return $instance;
1849 }
1850}
1851add_action( 'widgets_init', create_function('', 'return register_widget("BuddyPress_Profile_Field_Widget");') );
1852
1853
1854/* 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. */
1855function millionairesdigest_redirect_on_first_login( $url, $request, $user ) {
1856 $last_activity = bp_get_user_last_activity( $user->ID );
1857 if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
1858 if( $user->has_cap( 'user' ) && empty( $last_activity ) ) {
1859 $url = home_url('/users-welcome-page/');
1860 } else {
1861 if( $user->has_cap( 'contributor' ) && empty( $last_activity ) ) {
1862 $url = home_url('/welcome-contributors-page/');
1863 } else {
1864 if( $user->has_cap( 'author' ) && empty( $last_activity ) ) {
1865 $url = home_url('/welcome-authors-page/');
1866 } else {
1867 if( $user->has_cap( 'editor' ) && empty( $last_activity ) ) {
1868 $url = home_url('/welcome-editor-page/');
1869 } else {
1870 if( $user->has_cap( 'photographer' ) && empty( $last_activity ) ) {
1871 $url = home_url('/welcome-photographers-page/');
1872 } else {
1873 if( $user->has_cap( 'publisher' ) && empty( $last_activity ) ) {
1874 $url = home_url('/welcome-publishers-page/');
1875 } else {
1876 if( $user->has_cap( 'magazine-author' ) && empty( $last_activity ) ) {
1877 $url = home_url('/welcome-magazine-authors-page/');
1878 } else {
1879 if( $user->has_cap( 'magazine-editor' ) && empty( $last_activity ) ) {
1880 $url = home_url('/welcome-magazine-editors-page/');
1881 } else {
1882 if( $user->has_cap( 'magazine-photographer' ) && empty( $last_activity ) ) {
1883 $url = home_url('/welcome-magazine-photographers-page/');
1884 } else {
1885 if( $user->has_cap( 'magazine-designer' ) && empty( $last_activity ) ) {
1886 $url = home_url('/welcome-magazine-designers-page/');
1887 } else {
1888 if( $user->has_cap( 'magazine-publisher' ) && empty( $last_activity ) ) {
1889 $url = home_url('/welcome-magazine-publishers-page/');
1890 } else {
1891 if( $user->has_cap( 'brand-account' ) && empty( $last_activity ) ) {
1892 $url = home_url('/welcome-brand-accounts-page/');
1893 } else {
1894 if( $user->has_cap( 'famous-person-account' ) && empty( $last_activity ) ) {
1895 $url = home_url('/welcome-famous-people-accounts-page/');
1896 } else {
1897 if( $user->has_cap( 'organization-account' ) && empty( $last_activity ) ) {
1898 $url = home_url('/welcome-organization-accounts-page/');
1899 } else {
1900 $url = home_url('/activity-wall/');
1901 }
1902 }
1903 }
1904 }
1905 }
1906 }
1907 }
1908 }
1909 }
1910 }
1911 }
1912 }
1913 }
1914 }
1915 }
1916 return $url;
1917}
1918add_filter('login_redirect', 'millionairesdigest_redirect_on_first_login', 10, 3 );
1919
1920
1921/* 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) */
1922add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();' ) );
1923
1924
1925/* 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 */
1926function set_default_member_type( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
1927 bp_set_member_type( $user_id, 'user' );
1928}
1929add_action( 'bp_core_signup_user', 'set_default_member_type', 10, 5 );
1930
1931
1932/* Add a Profile Nav Tab Called "Platform Writers" to the Millionaire's Digest Profile ONLY */
1933function add_platform_writers_tab() {
1934 global $bp;
1935 bp_core_new_nav_item( array(
1936 'name' => 'Platform Writers',
1937 'slug' => 'platform-writers',
1938 'parent_url' => $bp->displayed_user->domain,
1939 'parent_slug' => $bp->profile->slug,
1940 'screen_function' => 'platform_writers_screen',
1941 'position' => 40,
1942 'default_subnav_slug' => 'writers'
1943 ) );
1944 bp_core_new_subnav_item( array(
1945 'name' => 'All',
1946 'slug' => 'all',
1947 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
1948 'parent_slug' => 'platform-writers',
1949 'screen_function' => 'platform_writers_all_screen',
1950 'position' => 10,
1951 'user_has_access' => bp_is_my_profile()
1952 ) );
1953 bp_core_new_subnav_item( array(
1954 'name' => 'Authors',
1955 'slug' => 'authors',
1956 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
1957 'parent_slug' => 'platform-writers',
1958 'screen_function' => 'platform_writers_authors_screen',
1959 'position' => 20,
1960 'user_has_access' => bp_is_my_profile()
1961 ) );
1962}
1963add_action( 'bp_setup_nav', 'add_platform_writers_tab', 100 );
1964function platform_writers_screen() {
1965 add_action( 'bp_template_title', 'platform_writers_screen_title' );
1966 add_action( 'bp_template_content', 'platform_writers_screen_content' );
1967 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1968}
1969function platform_writers_screen_title() {
1970 echo '<h4>Platform Writers</h4>';
1971}
1972function platform_writers_screen_content() {
1973 echo do_shortcode( '[members-listing include_member_role="author,contributor"]' );
1974}
1975function platform_writers_all_screen() {
1976 add_action( 'bp_template_title', 'platform_writers_all_screen_title' );
1977 add_action( 'bp_template_content', 'platform_writers_all_screen_content' );
1978 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1979}
1980function platform_writers_all_screen_title() {
1981 echo '<h4>All Platform Writers</h4>';
1982}
1983function platform_writers_all_screen_content() {
1984 echo do_shortcode( '[members-listing include_member_role="author,contributor"]' );
1985}
1986function platform_writers_authors_screen() {
1987 add_action( 'bp_template_content', 'platform_writers_authors_screen_title' );
1988 add_action( 'bp_template_content', 'platform_writers_authors_screen_content' );
1989 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
1990}
1991function platform_writers_authors_screen_title() {
1992 echo '<h4>Authors</h4>';
1993}
1994function platform_writers_authors_screen_content() {
1995 echo do_shortcode( '[members-listing include_member_role="author"]' );
1996}
1997
1998
1999/* Add a Profile Nav Tab Called "Magazine Writers" to the Millionaire's Digest Profile ONLY */
2000function add_magazine_writers_tab() {
2001 global $bp;
2002 bp_core_new_nav_item( array(
2003 'name' => 'Magazine Writers',
2004 'slug' => 'magazine-writers',
2005 'parent_url' => $bp->displayed_user->domain,
2006 'parent_slug' => $bp->profile->slug,
2007 'screen_function' => 'magazine_writers_screen',
2008 'position' => 50,
2009 'default_subnav_slug' => 'writers'
2010 ) );
2011 bp_core_new_subnav_item( array(
2012 'name' => 'All',
2013 'slug' => 'all',
2014 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'magazine-writers' ),
2015 'parent_slug' => 'magazine-writers',
2016 'screen_function' => 'magazine_writers_all_screen',
2017 'position' => 10,
2018 'user_has_access' => bp_is_my_profile()
2019 ) );
2020 bp_core_new_subnav_item( array(
2021 'name' => 'Authors',
2022 'slug' => 'authors',
2023 'parent_url' => trailingslashit( bp_displayed_user_domain() . 'platform-writers' ),
2024 'parent_slug' => 'magazine-writers',
2025 'screen_function' => 'magazine_writers_authors_screen',
2026 'position' => 20,
2027 'user_has_access' => bp_is_my_profile()
2028 ) );
2029}
2030add_action( 'bp_setup_nav', 'add_magazine_writers_tab', 100 );
2031function magazine_writers_screen() {
2032 add_action( 'bp_template_title', 'magazine_writers_screen_title' );
2033 add_action( 'bp_template_content', 'magazine_writers_screen_content' );
2034 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
2035}
2036function magazine_writers_screen_title() {
2037 echo '<h4>Magazine Writers</h4>';
2038}
2039function magazine_writers_screen_content() {
2040 echo do_shortcode( '[members-listing include_member_role="magazine-author"]' );
2041}
2042function magazine_writers_all_screen() {
2043 add_action( 'bp_template_title', 'magazine_writers_all_screen_title' );
2044 add_action( 'bp_template_content', 'magazine_writers_all_screen_content' );
2045 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
2046}
2047function magazine_writers_all_screen_title() {
2048 echo '<h4>All Magazine Writers</h4>';
2049}
2050function magazine_writers_all_screen_content() {
2051 echo do_shortcode( '[members-listing include_member_role="magazine-author"]' );
2052}
2053function magazine_writers_authors_screen() {
2054 add_action( 'bp_template_content', 'magazine_writers_authors_screen_title' );
2055 add_action( 'bp_template_content', 'magazine_writers_authors_screen_content' );
2056 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
2057}
2058function magazine_writers_authors_screen_title() {
2059 echo '<h4>Authors</h4>';
2060}
2061function magazine_writers_authors_screen_content() {
2062 echo do_shortcode( '[members-listing include_member_role="author"]' );
2063}
2064
2065
2066/* 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 */
2067function millionairedigest_remove_platform_writers_tab() {
2068 if ( bp_displayed_user_id() == 428) {
2069 return;
2070 }
2071 bp_core_remove_nav_item( 'platform-writers' );
2072 bp_core_remove_nav_item( 'magazine-writers' );
2073}
2074add_action( 'bp_setup_nav', 'millionairedigest_remove_magazine_writers_tab', 1001 );
2075
2076
2077/* Auto Join All New Team & Company Members to Groups Based on Their Role After Creating Their Account and Logging in for the First Time */
2078function auto_join_contributors_to_groups( $user_id, $role, $old_roles ) {
2079 if( $role == 'contributor' ) {
2080 groups_accept_invite( $user_id, 1 );
2081 groups_accept_invite( $user_id, 39 );
2082 groups_accept_invite( $user_id, 38 );
2083 }
2084}
2085add_action( 'set_user_role', 'auto_join_contributors_to_groups', 11, 3 );
2086function auto_join_authors_to_groups( $user_id, $role, $old_roles ) {
2087 if( $role == 'author' ) {
2088 groups_accept_invite( $user_id, 2 );
2089 groups_accept_invite( $user_id, 39 );
2090 groups_accept_invite( $user_id, 38 );
2091 }
2092}
2093add_action( 'set_user_role', 'auto_join_authors_to_groups', 11, 3 );
2094function auto_join_editors_to_groups( $user_id, $role, $old_roles ) {
2095 if( $role == 'editor' ) {
2096 groups_accept_invite( $user_id, 3 );
2097 groups_accept_invite( $user_id, 39 );
2098 groups_accept_invite( $user_id, 38 );
2099 }
2100}
2101add_action( 'set_user_role', 'auto_join_editors_to_groups', 11, 3 );
2102function auto_join_photographers_to_groups( $user_id, $role, $old_roles ) {
2103 if( $role == 'photographer' ) {
2104 groups_accept_invite( $user_id, 4 );
2105 groups_accept_invite( $user_id, 39 );
2106 groups_accept_invite( $user_id, 38 );
2107 }
2108}
2109add_action( 'set_user_role', 'auto_join_photographers_to_groups', 11, 3 );
2110function auto_join_publishers_to_groups( $user_id, $role, $old_roles ) {
2111 if( $role == 'publisher' ) {
2112 groups_accept_invite( $user_id, 5 );
2113 groups_accept_invite( $user_id, 39 );
2114 groups_accept_invite( $user_id, 38 );
2115 }
2116}
2117add_action( 'set_user_role', 'auto_join_publishers_to_groups', 11, 3 );
2118function auto_join_magazine_authors_to_groups( $user_id, $role, $old_roles ) {
2119 if( $role == 'magazine-author' ) {
2120 groups_accept_invite( $user_id, 7 );
2121 groups_accept_invite( $user_id, 40 );
2122 groups_accept_invite( $user_id, 38 );
2123 }
2124}
2125add_action( 'set_user_role', 'auto_join_magazine_authors_to_groups', 11, 3 );
2126function auto_join_magazine_editors_to_groups( $user_id, $role, $old_roles ) {
2127 if( $role == 'magazine-editor' ) {
2128 groups_accept_invite( $user_id, 8 );
2129 groups_accept_invite( $user_id, 40 );
2130 groups_accept_invite( $user_id, 38 );
2131 }
2132}
2133add_action( 'set_user_role', 'auto_join_magazine_editors_to_groups', 11, 3 );
2134function auto_join_magazine_photographers_to_groups( $user_id, $role, $old_roles ) {
2135 if( $role == 'magazine-photographer' ) {
2136 groups_accept_invite( $user_id, 9 );
2137 groups_accept_invite( $user_id, 40 );
2138 groups_accept_invite( $user_id, 38 );
2139 }
2140}
2141add_action( 'set_user_role', 'auto_join_magazine_photographers_to_groups', 11, 3 );
2142function auto_join_magazine_designers_to_groups( $user_id, $role, $old_roles ) {
2143 if( $role == 'magazine-designer' ) {
2144 groups_accept_invite( $user_id, 10 );
2145 groups_accept_invite( $user_id, 40 );
2146 groups_accept_invite( $user_id, 38 );
2147 }
2148}
2149add_action( 'set_user_role', 'auto_join_magazine_designers_to_groups', 11, 3 );
2150function auto_join_magazine_publishers_to_groups( $user_id, $role, $old_roles ) {
2151 if( $role == 'magazine-publisher' ) {
2152 groups_accept_invite( $user_id, 11 );
2153 groups_accept_invite( $user_id, 40 );
2154 groups_accept_invite( $user_id, 38 );
2155 }
2156}
2157add_action( 'set_user_role', 'auto_join_magazine_publishers_to_groups', 11, 3 );